Nexera-Fi SDK

Nexera-Fi SDK Usage Guide

This section provides a step-by-step guide for initializing the Nexera-Fi SDK and covers fundamental configurations needed for TypeScript and Python projects.

Typescript SDK Usage

In TypeScript projects, start by configuring your Ethers.js Provider and Signer instances. Afterward, proceed to create an instance of the NexeraFiSDK class.

import { NexeraFiSDK, ChainId, Operation } from "@nexeraprotocol/nexera-fi-sdk";
import { ethers } from "ethers"; // Ethers.js library
 
const chainId: ChainId = 5; // Replace with the target chain ID
const node_rpc_url: string = "..." // Replace with the rpc url  
 
const provider = new ethers.providers.JsonRpcProvider(node_rpc_url); // Create a `Provider` instance
const wallet_signer = new ethers.Wallet(process.env.privateKey, provider); // Create a `Signer` instance
 
// Initialize NexeraFiSDK by creating an instance 
const nexeraFiSdk = new NexeraFiSDK();

General Methods

getAdapters

Returns a collection of Nexera-Fi Adapters. The collection provides a structured way to access each Adapter's following data:

  • Adapter's address (for the blockchain specified by chainId)
  • Adapter's set of basic operations (if available)
  • Adapter's set of extra operations (if available)
  • ABI encoded data necessary for initializing the Adapter (example)
// Get collection of Adapters
const adapters = nexeraFiSdk.getAdapters(chainId);
 
// Extract Adapaters from the collection in a type-safe manner (e.g. Balancer & Uniswap Adapter)
const BalancerAdapter = adapters.BalancerAdapter;
const UniswapAdapter = adapters.UniswapAdapter;
 
// Get address of Adapters (e.g. `BalanerAdapter` address)
const address = BalancerAdapter.address;
 
// Get available basic operations
const operations = BalancerAdapter.operations;
 
// Get available extra opertations
const extraOperations = BalancerAdapter.extraOperations;
 
// Get ABI encoded data required for initialization
const initData = BalancerAdapter.initializeData;

getOrchestrator

To interact with your Orchestrator instance, ensure proper configuration of getOrchestrator by specifying:

  • The address of the target Orchestrator contract.
  • Either an Ethers.js Provider for read-only operations or a Signer for both read and transactional operations.
const deploymentAddress = "0x123....78f"; // Replace with the actual address
 
// Get a strongly typed `Orchestrator` instance connected to your wallet 
const Orchestrator = nexeraFiSdk.getOrchestrator(deploymentAddress, wallet_signer);
 
// Example: Interact with your Orchestrator in a type-safe manner
await Orchestrator.setExecutor(wallet_signer.address);

deployOrchestrator

Provides a function to seamlessly deploy your Orchestrator on-chain.

For a detailed example of how to use this function, see here.

const deployOrchestratorFunction = nexeraFiSdk.deployOrchestrator();

executeInMicroservice

Returns a function for executing a set of on-chain actions through an Orchestrator instance in a single transaction, with transaction delegation to an external microservice.

For a detailed example of how to use this function, see here.

const executeInMicroserviceFunction = nexeraFiSdk.executeInMicroservice();

getSubgraph - Subgraph Client

To access the Nexera-Fi Subgraphs API, ensure proper configuration of getSubgraph by specifying:

  • The chain ID of the target blockchain.
const chainId: ChainId = 5; // Replace with the target chain ID
 
// Get the Subgraph GraphQL API client for your desired blockchain.
const subgraph = nexeraFiSdk.getSubgraph(chainId);

You can now consume the Subgraph API through the client-side queries to access on-chain data and event-driven entities.

// Fetch indexed on-chain data related to Nexera-Fi contracts in a type-safe manner
// Example: `FactoryOrchestratorsDeployed` query
const result = await subgraph.FactoryOrchestratorsDeployed();
 
console.log(result);
 
/* Output:
{
  [
    {
      id: '0xb013...00',
      orchestrator: '0x891...e64',
      owner: '0x10e..4E',
      blockNumber: '252..',
      blockTimestamp: '16928...',
      transactionHash: '0xb013...b16'
    },
    {
      ...
    },
    ...
  ]
}
*/

Python SDK Usage

For Python projects, start by importing the NexeraFi_SDK package and configuring your Web3.py HTTP Provider.

from NexeraFi_SDK import *
from web3 import Web3
 
chain_id = 5 # Replace with the target chain ID
 
# Replace with the rpc server url
rpc_server_url = "https://....."
 
# Instantiate a Web3 HTTP Provider to connect to a blockchain node
w3 = Web3(Web3.HTTPProvider(rpc_server_url)) 

General Methods

get_adapter_names

Returns a list of strings containing the names of the supported Adapters.

adapter_names = get_adapter_names()
 
for name in adapter_names:
    print(name)
 
"""
Output:
AaveAdapter
AuraAdapter
BalancerAdapter
CompoundAdapter
...
UniswapAdapter
WrappedNativeTokenAdapter
"""

get_supported_chain_ids

Returns a list of integers representing the supported chain IDs.

chain_ids = get_supported_chain_ids()
 
for id in chain_ids:
  print(id)
 
"""
Output:
1
5
56
97
137
42161
43113
43114
80001
421613
"""

get_operations

Returns an enumeration of Orchestrator base operations.

operations = get_operations()
 
for op in operations:
  print(op.name, op.value)
 
"""
Output:
DEPOSIT 0
WITHDRAW 1
SWAP 2
COLLECT 3
OPERATE 4
"""

get_base_operations_for_adapters

Returns an enumeration of base operations specific to each supported Adapter.

adapter_ops = get_base_operations_for_adapters()
 
# Example: Compound Adapter Operations for WITHDRAW Orchestrator Operation
comp_adapter_withdraw_ops = adapter_ops.CompoundAdapter.WITHDRAW
 
for op in comp_adapter_withdraw_ops:
  print(op, op.value)
 
"""
Output:
CompoundWithdrawOperation.BORROW 0
CompoundWithdrawOperation.REDEEM 1
CompoundWithdrawOperation.REDEEM_UNDERLYING 2
"""

get_extra_operations_for_adapters

Returns an enumeration of extra operations specific to each supported Adapter

adapter_extra_ops = get_extra_operations_for_adapters()
 
# Example: Balancer Adapter extra Operations for Joining Weighted Pools
balancer_adapter_join_ops = adapter_extra_ops.BalancerAdapter.JOIN_KIND
 
for op in balancer_adapter_join_ops:
  print(op, op.value)
 
"""
Output:
BalancerWeightedPoolJoinKind.INIT 0
BalancerWeightedPoolJoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT 1
BalancerWeightedPoolJoinKind.TOKEN_IN_FOR_EXACT_BPT_OUT 2
BalancerWeightedPoolJoinKind.ALL_TOKENS_IN_FOR_EXACT_BPT_OUT 3
BalancerWeightedPoolJoinKind.ADD_TOKEN 4
"""

get_adapter_initialize_data

Returns Adapters' ABI encoded initialize data for a given chain ID.

data = get_adapter_initialize_data(chain_id)
 
# Example: Uniswap Adapter Intialize Data 
uniswap_adapter_init_data = data.UniswapAdapter.initialize_data

get_adapter_addresses

Returns Adapters' addresses for a given chain ID.

adapter_addresses = get_adapter_addresses(chain_id)
 
# Example: Maverick Adapter Address for `chain_id` 
maverick_adapter_address = adapter_addresses.MaverickAdapter.address
 
print(maverick_adapter_address)
 
"""
Output:
0xCE0287AaEB962418586dA3C7eB2A1078Ffe0aA64
"""

get_orchestrator

Returns a Web3 contract instance of the Orchestrator configured at the provided address.

deployment_address = "0x...." # Replace with the actual address of your Orchestrator
 
# Get `Orchestrator` instance
Orchestrator = get_orchestrator(orchestrator_address=deployment_address, web3_provider=w3)
 
# Example: Interact with your Orchestrator
result = Orchestrator.functions.isWhitelistedAdapter("0xCE0287AaEB962418586dA3C7eB2A1078Ffe0aA64").call()

get_orchestrator_factory

Returns a Web3 contract instance of the OrchestratorFactory configured at the address linked to the provided chain ID.

Orchestrator_Factory = get_orchestrator_factory(chain_id=chain_id, web3_provider=w3)
 
# Example: Interact with your OrchestratorFactory
Orchestrator_Factory.functions.deployOrchestrator([], []).transact()