Migrating with same base token

Move your USDC lending position from Aave to Compound while keeping the same underlying asset. Bundle Mechanics:
  • redeem existing USDC collateral on AAVE
  • deposit retreived USDC to Compound CUSDC position
const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
const USDC_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const AUSDC_ADDRESS = "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c";
const CUSDC_ADDRESS = "0xc3d688B66703497DAA19211EEdff47f25384cdc3";
const AAVE_V3 = "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2";

const aUsdcAmountIn = parseUnits("5000", 6).toString(); // 5,000 aUSDC to withdraw

const chainId = 1;

const bundle = await client.getBundleData(
  {
    chainId,
    fromAddress,
    routingStrategy: "delegate",
  },
  // Migrate USDC lending position from Aave to Compound
  [
    {
      protocol: "aave-v3",
      action: "redeem",
      args: {
        tokenIn: AUSDC_ADDRESS,
        tokenOut: USDC_ADDRESS,
        amountIn: aUsdcAmountIn,
        primaryAddress: AAVE_V3,
      },
    },
    {
      protocol: "compound-v3",
      action: "deposit",
      args: {
        tokenIn: USDC_ADDRESS,
        tokenOut: CUSDC_ADDRESS,
        amountIn: aUsdcAmountIn,
        primaryAddress: CUSDC_ADDRESS,
      },
    },
  ]
);
console.log(JSON.stringify(bundle.bundle, null, 2));
await sendSmartWallet(bundle.tx, bundle.tx);

Migrating to different base position

Switch Aave lending position from USDC collateral to WETH collateral in a single transaction. Bundle design:
  • redeem existing USDC collateral on AAVE
  • swap USDC to WETH using route action
  • deposit resulting WETH to AAVE (using the {useOutputOfCallAt: 1} to reference the swap)

const fromAddress = "0xd8da6bf26964af9d7eed9e03e53415d37aa96045";
const USDC_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const AUSDC_ADDRESS = "0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c";
const WETH_ADDRESS = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
const AWETH_ADDRESS = "0x4d5F47FA6A74757f35C14fD3a6Ef8E3C9BC514E8";
const AAVE_V3 = "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2";

const aUsdcAmountIn = parseUnits("3000", 6).toString(); 

const chainId = 1;

const bundle = await client.getBundleData(
  {
    chainId,
    fromAddress,
    routingStrategy: "delegate",
  },
  // Switch collateral within Aave from USDC to WETH
  [
    {
      protocol: "aave-v3",
      action: "redeem",
      args: {
        tokenIn: AUSDC_ADDRESS,
        tokenOut: USDC_ADDRESS,
        amountIn: aUsdcAmountIn,
        primaryAddress: AAVE_V3,
      },
    },
    {
      protocol: "enso",
      action: "route",
      args: {
        tokenIn: USDC_ADDRESS,
        tokenOut: WETH_ADDRESS,
        amountIn: aUsdcAmountIn, 
      },
    },
    {
      protocol: "aave-v3",
      action: "deposit",
      args: {
        tokenIn: WETH_ADDRESS,
        tokenOut: AWETH_ADDRESS,
        amountIn: {useOutputOfCallAt: 1},
        primaryAddress: AAVE_V3,
      },
    },
  ]
);

console.log(JSON.stringify(bundle.bundle, null, 2));
await sendSmartWallet(bundle.tx, bundle.tx);