Build a postHook

After the swap or bridge is executed, the resulting tokens will be left on the Squid Multicall contract. From there the postHooks calls will be executed.

Create contract interfaces for the posthook

// Creating Contract interfaces
// Approve the lending contract to spend the erc20
const erc20Interface = new ethers.utils.Interface(erc20Abi);
const approvalerc20 = erc20Interface.encodeFunctionData("approve", [
  radiantLendingPoolAddress,
  ethers.constants.MaxUint256,
]);

// Create contract interface and encode deposit function for Radiant lending pool
const radiantLendingPoolInterface = new ethers.utils.Interface(
  radiantLendingPoolAbi
);
const depositEncodedData = radiantLendingPoolInterface.encodeFunctionData(
  "deposit",
  [
    usdcArbitrumAddress,
    "0", // Placeholder for dynamic balance
    signer.address,
    0,
  ]
);

Create postHook


// Set up parameters for swapping tokens and depositing into Radiant lending pool
const params = {
  fromAddress: signer.address,
  fromChain: fromChainId,
  fromToken: fromToken,
  fromAmount: amount,
  toChain: toChainId,
  toToken: usdcArbitrumAddress,
  toAddress: signer.address,
  slippage: 1,
  quoteOnly: false,
  enableBoost: true,
  slippage: 1, //OPTIONAL to set slippage, it will be set dynamically if not included
  postHook: {
    chainType: ChainType.EVM,
    calls: [
      {
        chainType: ChainType.EVM, 
        callType: 1,// SquidCallType.FULL_TOKEN_BALANCE
        target: usdcArbitrumAddress,
        value: "0", // this will be replaced by the full native balance of the multicall after the swap
        callData: approvalerc20,
        payload: {
          tokenAddress: usdcArbitrumAddress,
          inputPos: 1,
        },
        estimatedGas: "50000",
      },
      {
        chainType: ChainType.EVM,
        callType: 1, // SquidCallType.FULL_TOKEN_BALANCE
        target: radiantLendingPoolAddress,
        value: "0",
        callData: depositEncodedData,
        payload: {
          tokenAddress: usdcArbitrumAddress,
          inputPos: 1,
        },
        estimatedGas: "50000",
      },
    ],
    provider: "Integration Test", //This should be the name of your product or application that is triggering the hook
    description: "Wrap native ETH",
    logoURI: "https://pbs.twimg.com/profile_images/1548647667135291394/W2WOtKUq_400x400.jpg", //Add your logo here
  },
};

Last updated