Nexera-Fi SDKUsage ExamplesSupported Adapters

Convex Adapter Showcase

In this demonstration, we'll highlight the application of the Convex 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 3CRv Curve's 3Pool LP tokens for minting cvx3Crv in return.

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

const chainId: ChainId = 1; // Ethereum Mainnet
 
// Target Assets
// Note: Assets at play should be already whitelisted in the `Orchestrator`  
const CURVE_LP = "0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490"; // Token in balance
const POOL_TOKEN = "0x30D9410ED1D5DA1F6C8391af5338C93ab8d4035C"; // Target asset (Pool Token)
 
// Pool ID
const POOL_ID = 9;
 
// Target Adapter (i.e. ConvexAdapter)
const ConvexAdapter = nexeraFiSdk.getAdapters(chainId).ConvexAdapter;
 
// Connect to your Orchestrator instance
// Note: `ConvexAdapter` 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 CURVE_LP to Orchestrator
// (Adapters can only manage assets that are allocated to the Orchestrator)
await CurveLpContract.connect(wallet_signer).transfer(
    Orchestrator.address,
    ethers.utils.parseEther("10"), // 10 CURVE_LP
    {nonce: nonce_}
);
 
/* ------------------- Construct `out` & `expectedIn` token compositions, and `extraData` ------------------- */
// Tokens to send (i.e. 10 CURVE_LP)
const out = [
    { 
        token: CURVE_LP,
        amount: ethers.utils.parseEther("10")
    },
];
 
// Token to receive (i.e. POOL_TOKEN)
// `amount` field is for Minimum amount of tokens expected to be received (set to "0" for no limit indication)
const expectedIn = [
    { token: POOL_TOKEN, amount: "0" }
];
 
// Extra data contains extra arguments used by the function (i.e. Pool ID and if stake)
const extraData = ethers.utils.defaultAbiCoder.encode(['uint256', 'bool'], [[POOL_ID, false]]);
 
// Use `callStatic` to simulate the Tx and acquire what is received (asset-wise) by the Orchestrator
const totalReceived = await Orchestrator.callStatic.execute(
    [{
        adapter: ConvexAdapter.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: ConvexAdapter.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(POOL_TOKEN, totalReceived[0][0].amount, wallet_signer.address, {nonce: nonce_});