Nexera-Fi SDKUsage ExamplesSupported Adapters

Idle Adapter Showcase

In this demonstration, we'll highlight the application of the Idle V2 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 USDC tokens for minting IdleUSDC shares 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 USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // Token in balance
const IDLE_USDC = "0x5274891bEC421B39D23760c04A6755eCB444797C"; // Target asset
 
// Target Adapter (i.e. IdleAdapter)
const IdleAdapter = nexeraFiSdk.getAdapters(chainId).IdleAdapter;
 
// Connect to your Orchestrator instance
// Note: `IdleAdapter` 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 USDC to Orchestrator
// (Adapters can only manage assets that are allocated to the Orchestrator)
await UsdcContract.connect(wallet_signer).transfer(
    Orchestrator.address,
    ethers.utils.parseUnits("1000", "6"), // 1000 USDC
    {nonce: nonce_}
);
 
/* ------------------- Construct `out` & `expectedIn` token compositions, and `extraData` ------------------- */
// Tokens to send (i.e. 1000 USDC)
const out = [
    { 
        token: USDC,
        amount: ethers.utils.parseUnits("1000", "6")
    },
];
 
// Token to receive (i.e. IDLE_USDC)
// `amount` field is for Minimum amount of tokens expected to be received (set to "0" for no limit indication)
const expectedIn = [
    { token: IDLE_USDC, amount: "0" }
];
 
// Extra data contains extra arguments used by the function (i.e Type of operation, referral and idleCDO)
const extraData = ethers.utils.defaultAbiCoder.encode(
    ["tuple(uint,address,address)"],
    [[IdleAdapter.operations.DEPOSIT.MINT_IDLE_TOKEN, Orchestrator.address, ethers.constants.AddressZero]]
);
 
// Use `callStatic` to simulate the Tx and acquire what is received (asset-wise) by the Orchestrator
const totalReceived = await Orchestrator.callStatic.execute(
    [{
        adapter: IdleAdapter.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: IdleAdapter.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(IDLE_USDC, totalReceived[0][0].amount, wallet_signer.address, {nonce: nonce_});