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
},
};
Import the ABIs and create the contract interface
// Import Radiant lending pool ABI
import radiantLendingPoolAbi from "../abi/radiantLendingPoolAbi";
// Import erc20 contract ABI
import erc20Abi from "../abi/erc20Abi";
// Set up JSON RPC provider and signer
const provider = new ethers.providers.JsonRpcProvider(FROM_CHAIN_RPC);
const signer = new ethers.Wallet(privateKey, provider);
// 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,
]
);
Build the parameters to including the postHook
params = {
fromAddress: signer.address,
fromChain: fromChainId,
fromToken: fromToken,
fromAmount: amount,
toChain: toChainId,
toToken: usdcArbitrumAddress,
toAddress: signer.address,
slippage: 1,
slippageConfig: {
autoMode: 1,
},
postHook: {
chainType: "evm",
//fundAmount: amount, //only required for prehooks
//fundToken: usdcArbitrumAddress, //only required for prehooks
calls: [
{
callType: 1,
target: usdcArbitrumAddress,
value: "0", // this will be replaced by the full native balance of the multicall after the swap
callData: approvalerc20,
payload: {
tokenAddress: usdcArbitrumAddress, // unused in callType 2, dummy value
inputPos: "1", // unused
},
estimatedGas: "50000",
chainType: "evm",
},
{
callType: 1, // SquidCallType.FULL_TOKEN_BALANCE
target: radiantLendingPoolAddress,
value: "0",
callData: depositEncodedData,
payload: {
tokenAddress: usdcArbitrumAddress,
inputPos: "1",
},
estimatedGas: "50000",
chainType: "evm",
},
],
description: "",
},
};
Last updated