Squid Dev Documentation
Ask or search…
K

Using the full ERC20 or Native balance in a call

The Squid Multicall can update the value of a param on-chain before or after the Swap or bridge has occurred. This lets you do the following:
  • Send the remainder of tokens to the user's address, after minting or buying something at a fixed price
  • Stake the full amount received from a swap
  • Unstake, then swap the full amount across chains
This is designated by using a different callType
export enum SquidCallType {
DEFAULT = 0,
FULL_TOKEN_BALANCE = 1,
FULL_NATIVE_BALANCE = 2,
COLLECT_TOKEN_BALANCE = 3, // unused in hooks
}
DEFAULT
FULL_ERC20_BALANCE
FULL_NATIVE_BALANCE
const repayLoanCall = {
callType: SquidCallType.DEFAULT, 0
target: aavePoolAddress,
value: '0',
callData: repayEncodedData,
estimatedGas: '50000',
payload: {
tokenAddress: repayAsset,
inputPos: 1,
}
const sendRemainderToUserCall = {
callType: SquidCallType.FULL_TOKEN_BALANCE, // transfer any remaining MAGIC to the user's account
target: magicToken,
value: "0",
callData: transferMagicEncodeData,
payload: {
tokenAddress: magicToken,
inputPos: 1,
},
estimatedGas: "50000",
},
const mintLoanWithFullNativeBalanceCall = {
callType: SquidCallType.FULL_NATIVE_BALANCE,
target: moonwellGlmrAddress,
value: "0", // this will be replaced by the full native balance of the multicall after the swap
callData: mintEncodeData,
payload: {
tokenAddress: "0x", // unused in callType 2, dummy value
inputPos: 1, // unused
},
estimatedGas: "250000",
},