Nexera-Fi SDKUsage Examples

Initializing Adapters

Nexera-Fi Adapters feature an initialize function for storing essential operational data in specific storage slots. Each Adapter posseses its own unique identifier for specifying the associated storage slot. Orchestrator instances leverage their initializeAdapter function, employing delegatecall, to invoke whitelisted Adapters' initialize function. This allows an Orchestrator to configure Adapters within its own storage context. Although delegatecall executes code in the Adapter's context, changes are stored in the Orchestrator's storage in specific slots dedicated to each Adapter.

Ensuring seamless collaboration between Orchestrator instances and Adapters, it is imperative that the Adapters be initialized, a crucial step that enables the Orchestrator to effectively leverage their functionalities within its storage context.

The forthcoming example demonstrates how to initialize Adapters within your Orchestrator using the
Nexera-Fi SDK.

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

Initializing Adapters in Orchestrators

Typescript Example

Connect to your Orchestrator instance.

const orchestratorAddress = "0x...."; // Replace with the address of your Orchestrator
const Orchestrator = nexeraFiSdk.getOrchestrator(orchestratorAddress, wallet_signer);

Get the target Adapters.

const chainId = 1; // Replace with the target chain ID
const adapters = nexeraFiSdk.getAdapters(chainId);
 
// e.g. Compound & Uniswap Adapter
const CompoundAdapter = adapters.CompoundAdapter;
const UniswapAdapter = adapters.UniswapAdapter;

Note: The target Adapters must be whitelisted in your Orchestrator before initialization can take place.

Ensure you have already whitelisted the target Adapters by calling the isWhitelistedAdapter view function of your Orchestrator instance. Else, whitelist them by calling the addWhitelistedAdapters function.

await Orchestrator.addWhitelistedAdapters([CompoundAdapter.address, UniswapAdapter.address]);
 
console.log(await Orchestrator.isWhitelistedAdapter(CompoundAdapter.address)); // Output: `true`

Finally, initialize each Adapter by calling the initializeAdapter function of your Orchestrator instance.

// Initialize `CompoundAdapter`
await Orchestrator.initializeAdapter(CompoundAdapter.address, CompoundAdapter.initializeData);
// Initialize `UniswapAdapter`
await Orchestrator.initializeAdapter(UniswapAdapter.address, UniswapAdapter.initializeData);

Python Example

Get Orchestrator instance

orchestrator_address = "0x...." # Replace with the address of your Orchestrator
Orchestrator = get_orchestrator(orchestrator_address, w3)

Get the target Adapters address & initialize data.

chain_id = 1 # Replace with the target chain ID
adapter_addresses = get_adapter_addresses(chain_id)
init_data = get_adapter_initialize_data(chain_id)
 
# e.g. Compound & Uniswap Adapter
Uniswap_Adapter_address = adapter_addresses.UniswapAdapter.address
Compound_Adapter_address = adapter_addresses.CompoundAdapter.address
 
Compound_Adapter_init_data = init_data.CompoundAdapter.initialize_data
Uniswap_Adapter_init_data = init_data.UniswapAdapter.initialize_data

Note: The target Adapters must be whitelisted in your Orchestrator before initialization can take place.

Ensure you have already whitelisted the target Adapters by calling the isWhitelistedAdapter view function of your Orchestrator instance. Else, whitelist them by calling the addWhitelistedAdapters function.

Orchestrator.functions.addWhitelistedAdapters([Compound_Adapter_address, Uniswap_Adapter_address]).transact()
 
print(Orchestrator.functions.isWhitelistedAdapter(Compound_Adapter_address).call()) # Output: `True`

Finally, initialize each Adapter by calling the initializeAdapter function of your Orchestrator instance.

# Initialize `CompoundAdapter`
Orchestrator.functions.initializeAdapter(Compound_Adapter_address, Compound_Adapter_init_data).transact()
# Initialize `UniswapAdapter`
Orchestrator.functions.initializeAdapter(Uniswap_Adapter_address, Uniswap_Adapter_init_data).transact()

Note: After successful initialization, the Orchestrator can effectively utilize the respective Adapters, provided they remain whitelisted for continued collaboration.

On this page