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

Transfer failed with Error: AlreadyInitialized | Insufficient funds #808

Open
theunravelghoul opened this issue Feb 28, 2025 · 1 comment

Comments

@theunravelghoul
Copy link

Transfer fails, funds are locked and can be restored with the restore flow though.
Have no idea why is it happening, I've been able to do a few successful transfers with the same code.

Logs:

20:42:50 0|core   | [2025-02-28T20:42:50.134] [INFO] default - Starting transfer
20:42:53 0|core   | [2025-02-28T20:42:53.254] [ERROR] default - [
20:42:53 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
20:42:53 0|core   |   'Program log: Instruction: Approve',
20:42:53 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2903 of 98122 compute units',
20:42:53 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
20:42:53 0|core   |   'Program wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb invoke [1]',
20:42:53 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
20:42:53 0|core   |   'Program log: Instruction: Burn',
20:42:53 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4790 of 60873 compute units',
20:42:53 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
20:42:53 0|core   |   'Program 11111111111111111111111111111111 invoke [2]',
20:42:53 0|core   |   'Program 11111111111111111111111111111111 success',
20:42:53 0|core   |   'Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth invoke [2]',
20:42:53 0|core   |   'Program log: Error: AlreadyInitialized(8YQ66n6RAvf6kwDzzxxVaBDT2Qx3T3jhL4aUBCLDyVVp)',
20:42:53 0|core   |   'Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth consumed 19087 of 45330 compute units',
20:42:53 0|core   |   'Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth failed: custom program error: 0x0',
20:42:53 0|core   |   'Program wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb consumed 68976 of 95219 compute units',
20:42:53 0|core   |   'Program wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb failed: custom program error: 0x0'
20:42:53 0|core   | ]

I'm using a bit modified code from the docs & examples:

async function tokenTransfer<N extends Network>(
  wh: Wormhole<N>,
  route: {
    token: TokenId;
    amount: bigint;
    source: SignerStuff<N, Chain>;
    destination: SignerStuff<N, Chain>;
    delivery?: {
      automatic: boolean;
      nativeGas?: bigint;
    };
    payload?: Uint8Array;
  },
  roundTrip?: boolean,
): Promise<TokenTransfer<N>> {
  // Create a TokenTransfer object to track the state of the transfer over time
  const xfer = await wh.tokenTransfer(
    route.token,
    route.amount,
    route.source.address,
    route.destination.address,
    route.delivery?.automatic ?? false,
    route.payload,
    route.delivery?.nativeGas,
  );

  logger.info("transfer:", xfer.transfer);
  logger.info("route", route);

  const quote = await TokenTransfer.quoteTransfer(
    wh,
    route.source.chain,
    route.destination.chain,
    xfer.transfer,
  );
  logger.info("quote:", quote);

  if (xfer.transfer.automatic && quote.destinationToken.amount < 0)
    throw "The amount requested is too low to cover the fee and any native gas requested.";

  // 1) Submit the transactions to the source chain, passing a signer to sign any txns
  logger.info("Starting transfer");

  try {
    const srcTxids = await xfer.initiateTransfer(route.source.signer);
    logger.info(`Started transfer: `, srcTxids);
  } catch (e) {
    if (e instanceof SendTransactionError) {
      logger.error(await e.getLogs(connection));
    } else {
      logger.error(e);
    }
    throw new Error("Transfer failed");
  }

  // If automatic, we're done
  if (route.delivery?.automatic) return xfer;

  // 2) Wait for the VAA to be signed and ready (not required for auto transfer)
  logger.info("Getting Attestation");
  const attestIds = await xfer.fetchAttestation(120000);
  logger.info(`Got Attestation: `, attestIds);

Wormholescan example:
https://wormholescan.io/#/tx/5UgiE2AXbFbzNsQUJ6f5Adn1eEWxavBR4Jec2ZH4UL5mUzA6NApujwzo3kkXCCmtw5K1SZZbNYpGP7E7YRYhxWTR

Sometimes I get another error (funds are still transferred & can be claimed):

20:47:38 0|core   |   'Program log: Instruction: Burn',
20:47:38 0|core   |   'Program log: Error: insufficient funds',
20:47:38 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4197 of 60873 compute units',
20:47:38 0|core   |   'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: custom program error: 0x1',
20:47:38 0|core   |   'Program wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb consumed 38543 of 95219 compute units',
20:47:38 0|core   |   'Program wormDTUJ6AWPNvk59vGQbDvGJmqbDTdgWgAqcLBCgUb failed: custom program error: 0x1'

Wormholescan example (I've recovered this one):
https://wormholescan.io/#/tx/41xdAqrqBYLKGJghFooM7Mx2GeT8SLrnaT4vGnzERqM4ypQy5hjSHbQ39omSaK4UppG2NVNN8by27cDhfVXvGstD

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

2 participants
@theunravelghoul and others