Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in handling Token Transfers with nearly identical amount and Relayer fee in Wormhole SDK #693

Open
ilariae opened this issue Sep 10, 2024 · 0 comments

Comments

@ilariae
Copy link

ilariae commented Sep 10, 2024

We are encountering a precision error in the Wormhole SDK when executing TokenTransfer.from. The issue arises for USDC transactions where the token transfer amount is nearly identical to the relayer fee.

The function that was failing:

export async function getWhTokenTransferByTxID() {
  const txId = '0xd26c5b36d1125f031f44eee7a98989aae10e9df39809d5124a1dc6f43bfbf1ce';
  const wh = new Wormhole('Mainnet', [EvmPlatform]);

  try {
    const vaa = await TokenTransfer.getTransferVaa(wh, txId);
    if (!vaa) {
      throw new Error(`VAA not found for txId ${txId}`);
    }
    const tokenTransfer = await TokenTransfer.from(wh, {
      chain: vaa.emitterChain,
      txid: txId,
    }); // THIS IS FALING
  } catch (e) {
    console.error(e);
    throw new Error((e as Error).message);
  }
}

The error happens during the execution of TokenTransfer.from
Error message:

scaleAmount({"amount":"1423266","decimals":8}, 6) would result in altered amount. Use truncateAmount first if you intended to truncate it. 

After inspection of the VAA we saw the token amount (1423266) and the relayer fee (1423265) are almost identical, this could be causing a precision or scaling issue within the SDK

After increasing the amount sent the transaction went through: https://wormholescan.io/#/tx/0xe82f5a9aaf54935dd74ae9e6a29554ebeec0cbbb3adebc79753dd4f395c48345?network=Mainnet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant