Nexera-Fi SDKUsage ExamplesSupported Adapters

Maverick Adapter Showcase

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

Specifically, we will swap DAI tokens for USDC.

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 USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // Target asset
 
// Target Pool Address
const DAI_USDC_POOL = "0x53dc703B78794b61281812f3a901918253BeeFee";
 
// Target Adapter (i.e. MaverickAdapter)
const MaverickAdapter = nexeraFiSdk.getAdapters(chainId).MaverickAdapter;
 
// Connect to your Orchestrator instance
// Note: `MaverickAdapter` 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. USDC)
// `amount` field is for Minimum amount of tokens expected to be received (set to "0" for no limit indication)
const expectedIn = [
    { token: BAL, amount: "0" }
];
 
// Data to protocol function (`path` and `deadline`)
// Note: For `EXACT_OUTPUT` SWAP, ensure that the `path` begins with the token to be taken out of the pool
const path = MaverickAdapter.encodePath([USDC, DAI_USDC_POOL, DAI]);
 
const operationData = ethers.utils.defaultAbiCoder.encode(
    ["tuple(bytes)"],
    [[path]]
);
 
let deadline = "1111111111111111111"; // A big value
 
const typeOfExtraSwapData = "tuple(uint256,bytes)";
const extraSwapData = [deadline, operationData];
 
// Extra data contains extra arguments used by the function (i.e Type of operation or data to protocol function)
const extraData = ethers.utils.defaultAbiCoder.encode(
    ["tuple(uint256," + typeOfExtraSwapData + ")"],
    [[MaverickAdapter.operations.SWAP.EXACT_OUTPUT, extraSwapData]]
);
 
// Use `callStatic` to simulate the Tx and acquire what is received (asset-wise) by the Orchestrator
const totalReceived = await Orchestrator.callStatic.execute(
    [{
        adapter: MaverickAdapter.address,
        op: Operation.SWAP,   // `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 Swap action
await Orchestrator.execute(
    [{
        adapter: MaverickAdapter.address,
        op: Operation.SWAP,
        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(USDC, totalReceived[0][0].amount, wallet_signer.address, {nonce: nonce_});