Nexera-Fi SDKUsage ExamplesSupported Adapters

Aave Adapter Showcase

In this demonstration, we'll highlight the application of the Aave V3 Adapter within the Nexera-Fi SDK for executing a token deposit operation, assuming that the strategy Orchestrator instance is already deployed and configured.
(see Deployment & Configuration Guide, Initializing Adapters)

Specifically, we will deposit WETH tokens for minting aWETH in return.

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

const chainId: ChainId = 43114; // Avalanche C-Chain
 
// Target Assets
// Note: Assets at play should be already whitelisted in the `Orchestrator`   
const WETH = "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB"; // Token in balance
const AWETH = "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7"; // Target asset (aWETH)
 
// Target Adapter (i.e. AaveAdapter)
const AaveAdapter = nexeraFiSdk.getAdapters(chainId).AaveAdapter;
 
// Connect to your Orchestrator instance
// Note: `AaveAdapter` should be already whitelisted and properly initialized in the `Orchestrator`  
const orchestratorAddress = "..."; // Replace with the address of the instance you own
const Orchestrator = nexeraFiSdk.getOrchestrator(orchestratorAddress, wallet_signer);
 
// Get nonce for Tx
let nonce_ = await wallet_signer.getTransactionCount();
 
// Send WETH to Orchestrator
// (Adapters can only manage assets that are allocated to the Orchestrator)
await WethContract.connect(wallet_signer).transfer(
    Orchestrator.address,
    ethers.utils.parseEther("100"), // 100 WETH
    {nonce: nonce_}
);
 
/* ------------------- Construct `out` & `expectedIn` token compositions, and `extraData` ------------------- */
// Tokens to send (i.e. 100 WETH)
const out = [
    { 
        token: WETH,
        amount: ethers.utils.parseEther("100")
    },
];
 
// Token to receive (i.e. aWETH)
// `amount` field is for Minimum amount of tokens expected to be received (set to "0" for no limit indication)
const expectedIn = [
    { token: AWETH, amount: "0" }
];
 
// Extra data contains extra arguments used by the function (i.e Type of operation)
const extraData = ethers.utils.defaultAbiCoder.encode(["tuple(uint)"], [[AaveAdapter.operations.DEPOSIT.SUPPLY]]);
 
// Use `callStatic` to simulate the Tx and acquire what is received (asset-wise) by the Orchestrator
const totalReceived = await Orchestrator.callStatic.execute(
    [{
        adapter: AaveAdapter.address,
        op: Operation.DEPOSIT,  // `Operation` enum is exported by the NexeraFi-SDK package
        send: out,
        minReceive: expectedIn,
        extraData: extraData
    }]
);
 
nonce_ = await wallet_signer.getTransactionCount(); // Get nonce for Tx
 
// Execute Deposit action
await Orchestrator.execute(
    [{
        adapter: AaveAdapter.address,
        op: Operation.DEPOSIT,
        send: out,
        minReceive: expectedIn,
        extraData: extraData
    }],
    {nonce: nonce_}
);
 
nonce_ = await wallet_signer.getTransactionCount(); // Get nonce for Tx
 
// Withdraw specified assets from the Orchestrator and transfer them to a designated receiver
await Orchestrator.withdraw(AWETH, totalReceived[0][0].amount, wallet_signer.address, {nonce: nonce_});