Estimate USDC fees using avocado RPC

All Avocado transactions pay two types of fees:

  • the underlying network gas fee
  • a small up-charge on top for using the Avocado platform

For estimating those fees, no signature is required (can already do this before user has to interact).

interface IEstimatedFeeData {
  fee: string; // estimated total gas fee in USDC (in 10**18 and hex!!)
  multiplier: string; // in hex! fee divided by multiplier (fee / multiplier) will give the absolute minimum expected fee amount
  discount: IEstimatedDiscount;
}

interface IEstimatedDiscount {
  amount: number;
  transactionCount: number;
  program: string;
  name: string;
  description: string;
}

const data: IEstimatedFeeData = await avocadoProvider.send("txn_multisigEstimateFeeWithoutSignature", [
  {
    message: txPayload, // transaction payload as built in previous step
    owner: ownerAddress, // avocado owner EOA address
    safe: avocadoAddress, // avocado address
    index: index,
    targetChainId: chainId,
  },
]);

// convert from hex and 1e18:
console.log("estimate", Number(data.fee) / 1e18);

The fee amount will be returned in USDC (๐Ÿ˜Ž) and refers to the total maximum fee (gas cost + Avocado charge-up).

!! ย  Attention ย  !!: the fee is returned in hex and 10**18 format!