Nexera-Fi SDKUsage Examples

Orchestrator Deployment

Interaction with Adapters is consistently facilitated through Orchestrator contracts, serving as the primary gatekeepers. Thus, each interaction with a DeFi protocol is initiated from a configured Orchestrator instance and directed through the designated Adapter, guided by the supplied operation data.

The forthcoming example demonstrates the deployment and configuration of an Orchestrator contract via the OrchestratorFactory using the Nexera-Fi SDK.

Make sure you've appropriately initialized the NexeraFiSDK, covering configurations essential for further interactions.

Deploying & Configuring an Orchestrator Instance

Typescript Example

Begin by specifying the Adapters and Assets to whitelist in your Orchestrator.

Notably, this step is optional for the deployment process, as the whitelisting of Adapters and/or Assets can be accomplished after deployment by interacting directly with the Orchestrator instance.

const chainId = 1; // Replace with the target chain ID
 
// Target Adapter (e.g. WrappedNativeTokenAdapter)
const WrappedNativeTokenAdapter = nexeraFiSdk.getAdapters(chainId).WrappedNativeTokenAdapter;
 
// Target asset (e.g. WETH)
const WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";

Next, obtain the utility function for deploying an Orchestrator by calling the deployOrchestrator method. Provide the necessary arguments when executing the deployment function:

  • chainId: The chain ID of the target blockchain
  • signer: An Ethers.js Signer (The address of this wallet will be the owner of the Orchestrator)
  • adaptersToWhitelist: Array of Adapter addresses to whitelist (or empty array to skip)
  • assetsToWhitelist: Array of token addresses to whitelist (or empty array to skip)
// Get the deployment function 
const deployFunction = nexeraFiSdk.deployOrchestrator();
 
// Execute the deployment function
const deploymentResult = await deployFunction(
    chainId,
    wallet_signer,
    [WrappedNativeTokenAdapter.address],
    [WETH]
);
 
console.log(deploymentResult);
 
/* Output:
{
    deploymentAddress : "0x.....", 
    txHash: "0x...."
}
*/

You can now connect to the deployed Orchestrator instance using the obtained deployment address.

const Orchestrator = nexeraFiSdk.getOrchestrator(deploymentResult.deploymentAddress, wallet_signer);

Python Example

Begin by specifying the Adapters and Assets to whitelist in your Orchestrator.

Notably, this step is optional for the deployment process, as the whitelisting of Adapters and/or Assets can be accomplished after deployment by interacting directly with the Orchestrator instance.

chain_id = 1 # Replace with the target chain ID
 
# Target Adapter (e.g. WrappedNativeTokenAdapter)
WrappedNativeToken_Adapter = get_adapter_addresses(chain_id).WrappedNativeTokenAdapter
 
# Target asset (e.g. WETH)
WETH = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"

Get OrchestratorFactory Web3 contract instance

Orchestrator_Factory = get_orchestrator_factory(chain_id=chain_id, web3_provider=w3)

Simulate Tx to get the deployment address of the Orchestrator

orchestrator_deployment_address = Orchestrator_Factory.functions.deployOrchestrator(
    [WrappedNativeToken_Adapter.address],
    [WETH]
).call()

Execute the transaction

Orchestrator_Factory.functions.deployOrchestrator(
    [WrappedNativeToken_Adapter.address],
    [WETH]
).transact()

You can now connect to the deployed Orchestrator instance using the obtained deployment address.

Orchestrator = get_orchestrator(orchestrator_deployment_address, w3)

Further Configuration of an Orchestrator

Continuing from the above example, this section demonstrates how to further configure or reconfigure your Orchestrator.

Typescript Example

// .....
 
// 1. Set Executor for your Orchestrator
await Orchestrator.setExecutor(wallet_signer.address);
 
// 2.1 Employ available Adapters in your strategies by whitelisting them
const adapters = nexeraFiSdk.getAdapters(chainId);
await Orchestrator.addWhitelistedAdapters([adapters.CompoundAdapter.address, adapters.UniswapAdapter.address]);
 
// 2.2 Remove whitelisted Adapters from your Orchestrator (Only whitelisted Adapters can be employed)
await Orchestrator.removeWhitelistedAdapters([adapters.CompoundAdapter.address]);
 
// 3.1 Whitelist assets to be leveraged in your strategies
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
const USDT = "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"
await Orchestrator.addWhitelistedTokens([USDC, USDT]);
 
// 3.2 Remove whitelisted assets from your Orchestrator (Only whitelisted Assets can be employed)
await Orchestrator.removeWhitelistedTokens([USDC]);
 
// 4. Transfer ownership of your Orchestrator
const newOwner = "0xf14.....547"
await Orchestrator.transferOwnership(newOwner);

Python Example

# ....
 
# 1. Set Executor for your Orchestrator
Orchestrator.functions.setExecutor("0x123....abc").transact()
 
# 2.1 Employ available Adapters in your strategies by whitelisting them
adapters = get_adapter_addresses(chain_id)
Orchestrator.functions.addWhitelistedAdapters(
    [adapters.CompoundAdapter.address, adapters.UniswapAdapter.address]
).transact()
 
# 2.2 Remove whitelisted Adapters from your Orchestrator (Only whitelisted Adapters can be employed)
Orchestrator.functions.removeWhitelistedAdapters([adapters.CompoundAdapter.address]).transact()
 
# 3.1 Whitelist assets to be leveraged in your strategies
USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
USDT = "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"
Orchestrator.functions.addWhitelistedTokens([USDC, USDT]).transact()
 
# 3.2 Remove whitelisted assets from your Orchestrator (Only whitelisted Assets can be employed)
Orchestrator.functions.removeWhitelistedTokens([USDC]).transact()
 
# 4. Transfer ownership of your Orchestrator
new_owner = "0xf14.....547"
Orchestrator.functions.transferOwnership(new_owner).transact()

On this page