Nexera-Fi SDKUsage ExamplesSupported Adapters

Compound Adapter Showcase

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