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

Base send To Solana Stuck in VAA EMITTED, How can I solve #752

Open
0xMMorty opened this issue Dec 11, 2024 · 4 comments
Open

Base send To Solana Stuck in VAA EMITTED, How can I solve #752

0xMMorty opened this issue Dec 11, 2024 · 4 comments

Comments

@0xMMorty
Copy link

https://wormholescan.io/#/tx/0x30db7fe6924efdf5ec534a535c72ff920b26ce47487cdd673832c1c676ae90ae

image

Sending ERC20 tokens from base to Solana, Wormhole will wait for about 20 minutes until the "VAA signed by wormhole guardians" status is reached, after which it will not proceed further.

const transfer = {
            sendChain: 'Base',
            rcvChain: 'Solana',
            tokenId: Wormhole.tokenId('Base', '0x4f9fd6be4a90f2620860d680c0d4d5fb53d1a825'),
            amount: '0.01',  
            automatic: false,
            execute: true
        };

const result = await startbridge(transfer);
        
 console.log('\nTransfer Result:');

const {
  TokenTransfer,
  Wormhole,
  amount,
  isTokenId,
  routes,
  signSendWait,
  wormhole
} = require('@wormhole-foundation/sdk');

const evm = require('@wormhole-foundation/sdk/evm').default;
const solana = require('@wormhole-foundation/sdk/solana').default;
const solanasign = require("@wormhole-foundation/sdk/platforms/solana").default;
const evmSign = require("@wormhole-foundation/sdk/platforms/evm").default;
const solsign = require("@wormhole-foundation/sdk-solana");
const dotenv = require('dotenv');
dotenv.config();

const SIGNER_CONFIG = {
  solana: {
    debug: true,
    priorityFee: {
      percentile: 0.5,
      percentileMultiple: 2,
      min: 1,
      max: 20,
    }
  },
  evm: {
    debug: true,
    maxGasLimit: amount.units(amount.parse("0.01", 18))
  }
};

async function initializeSigner(chain, rpc, privateKey) {
  let signer;
  let signerConfig;
  
  switch (chain) {
    case "Solana":
      signerConfig = SIGNER_CONFIG.solana;
      signer = await solanasign.getSigner(rpc, privateKey, signerConfig);
      break;
      
    case "Base":
    case "Ethereum":
      signerConfig = SIGNER_CONFIG.evm;
      signer = await evmSign.getSigner(rpc, privateKey, signerConfig);
      break;
      
      
    default:
      throw new Error(`Unsupported chain: ${chain}`);
  }
  
  return signer;
}

async function createChainContext(wh, chainType) {
  // 获取私钥
  let key;
  switch (chainType) {
    case "Solana":
      key = process.env.SOL_PRIVATE_KEY;
      break;
    case "Base":
    case "Ethereum":
      key = process.env.BASE_PRIVATE_KEY;
      break;
    default:
      throw new Error(`Unsupported chain type: ${chainType}`);
  }
  
  const chain = wh.getChain(chainType);
  const signer = await initializeSigner(chainType, await chain.getRpc(), key );
  
  return {
    chain,
    signer,
    address: Wormhole.chainAddress(chain.chain, signer.address())
  };
}

async function checkTokenWrappingStatus(chain, tokenId) {
  try {
    const tb = await chain.getTokenBridge();
    const wrapped = await tb.getWrappedAsset(tokenId);
    console.log(`Token wrapped status on chain:`, wrapped);
    return wrapped;
  } catch (e) {
    console.log(`Token not yet wrapped on chain:`, e.message);
    return null;
  }
}

async function handleTokenAttestation(sendChain, tokenId, sourceSigner) {
  const tb = await sendChain.getTokenBridge();
  try {
    const txGenerator = tb.createAttestation(tokenId);
    const txids = await signSendWait(sendChain, txGenerator, sourceSigner);
    console.log('Token attestation completed:', txids);
    return txids;
  } catch(e) {
    console.log(`Token attestation failed:`, e.message);
    return null;
  }
}

async function executeAutomaticTransfer(xfer, source) {
  try {
    const srcTxids = await xfer.initiateTransfer(source.signer);
    console.log('Source chain transaction IDs (automatic mode):', srcTxids);
    return { sourceChainTxs: srcTxids };
  } catch (error) {
    console.warn('Automatic transfer failed:', error.message);
    return null;
  }
}

async function executeManualTransfer(xfer, source, destination) {
  const srcTxids = await xfer.initiateTransfer(source.signer);
  console.log('Source transaction initiated:', srcTxids);
  
  console.log('Waiting for attestation...');
  const attestIds = await xfer.fetchAttestation(180_000);
  console.log('Attestation received:', attestIds);
  
  console.log('Completing transfer on destination chain...');
  const destTxids = await xfer.completeTransfer(destination.signer);
  console.log('Destination transaction completed:', destTxids);
  
  return {
    sourceChainTxs: srcTxids,
    attestation: attestIds,
    destinationChainTxs: destTxids
  };
}

async function executeTransfer(xfer, source, destination, quote) {
  try {
    let result;
    
    if (xfer.transfer.automatic) {
      result = await executeAutomaticTransfer(xfer, source);
      if (result) {
        return { ...result, quote };
      }
      console.log('Falling back to manual transfer mode...');
      xfer.transfer.automatic = false;
    }
    
    result = await executeManualTransfer(xfer, source, destination);
    return { ...result, quote };
    
  } catch (error) {
    console.error('Transfer execution failed:', error);
    throw error;
  }
}

async function startbridge(options) {
  try {
    console.log('Initializing Wormhole bridge...');
    const wh = await wormhole('Mainnet', [solana, evm]);

     console.log('Setting up chain contexts...');
     const source = await createChainContext(
       wh,
       options.sendChain
     );
 
     const destination = await createChainContext(
       wh,
       options.rcvChain
     );
 

    console.log('Checking token wrapping status...');
    const wrappedStatus = await checkTokenWrappingStatus(destination.chain, options.tokenId);
    if (!wrappedStatus) {
      console.log('Initiating token attestation...');
      await handleTokenAttestation(source.chain, options.tokenId, source.signer);
    }

    console.log('Getting token decimals...');
    const decimals = isTokenId(options.tokenId)
      ? Number(await wh.getDecimals(options.tokenId.chain, options.tokenId.address))
      : source.chain.config.nativeTokenDecimals;

    console.log('Token decimals:', decimals);
    console.log('Input amount:', options.amount);

    console.log('Creating transfer object...');
    const xfer = await wh.tokenTransfer(
      options.tokenId,
      amount.units(amount.parse(options.amount, decimals)),
      source.address,
      destination.address,
      options.automatic ?? false,
      undefined,
      undefined
    );

    console.log('Getting transfer quote...');
    const quote = await TokenTransfer.quoteTransfer(
      wh,
      source.chain,
      destination.chain,
      xfer.transfer
    );
    console.log('Transfer quote:', quote);

    if (!options.execute) {
      console.log('Quote only mode, returning quote');
      return quote;
    }

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

    console.log('Executing transfer...');
    return await executeTransfer(xfer, source, destination, quote);

  } catch (error) {
    console.error('Error in bridge transfer:', error);
    throw error;
  }
}

module.exports = {
  startbridge
};

and the cosole result is :

Retrying Wormholescan:GetVaaBytes, attempt 88/90
Retrying Wormholescan:GetVaaBytes, attempt 89/90
Transfer execution failed: Error: VAA not found
at TokenTransfer.fetchAttestation (/Users/apple/Downloads/binance/node_modules/@wormhole-foundation/sdk-connect/dist/cjs/protocols/tokenBridge/tokenTransfer.js:139:23)
at async executeManualTransfer (/Users/apple/Downloads/binance/src/strategies/worm.strategy.js:157:21)
at async executeTransfer (/Users/apple/Downloads/binance/src/strategies/worm.strategy.js:185:14)
at async startbridge (/Users/apple/Downloads/binance/src/strategies/worm.strategy.js:262:12)
at async testWormholeTransfer2 (/Users/apple/Downloads/binance/scripts/test-wormhole.js:78:24)
Error in bridge transfer: Error: VAA not found
at TokenTransfer.fetchAttestation (/Users/apple/Downloads/binance/node_modules/@wormhole-foundation/sdk-connect/dist/cjs/protocols/tokenBridge/tokenTransfer.js:139:23)
at async executeManualTransfer (/Users/apple/Downloads/binance/src/strategies/worm.strategy.js:157:21)
at async executeTransfer (/Users/apple/Downloads/binance/src/strategies/worm.strategy.js:185:14)
at async startbridge (/Users/apple/Downloads/binance/src/strategies/worm.strategy.js:262:12)
at async testWormholeTransfer2 (/Users/apple/Downloads/binance/scripts/test-wormhole.js:78:24)

Error during transfer: VAA not found
Stack trace: Error: VAA not found

@0xMMorty
Copy link
Author

0xMMorty commented Dec 11, 2024

Solana send to Base is OK, but Base send to Solana always stuck, https://wormholescan.io/#/tx/2m5bnUvQHyag5QA8ot4QYGrMxreedSBk1YxixuHkybSAWf3M9FEXQxgJDiuoaTkvonrZtRh1ZraEZfgWJ3ufmWP?network=Mainnet such as this one.

@0xMMorty
Copy link
Author

const attestIds = await xfer.fetchAttestation(180_000);

I changed this time for a long time and has a new error

Submitting transactions 
Waiting for confirmation for:  [
  '5RcoHNpi8KNMZ7YDRT1GXaCxSx48Zx5fvFaFcNR4wKxvHQr9k5ngTsxBRfcSk7u7AkX7rpjnDLfg4PMzoBMNHG5q',
  '4QWWWZkKhDYNLEnsiAZnX73zZazgPSaLELCTBthePCZxja7F8R4TdKQp3XWMVYZD4UVU1NkZXop7frkbRFRDD1kr'
]
Signing: Core.PostVAA for 8Vgk7VB4cycRSi8xnYG7571MogFri9kQC5FZYtWifMUt
Error simulating Solana transaction: [object Object]
[]
PublicKey [PublicKey(8Vgk7VB4cycRSi8xnYG7571MogFri9kQC5FZYtWifMUt)] {
  _bn: <BN: 6f5b025067dcac4adfcfc4d83a707036f41257884fc2cfc36d0b9ee225ff2201>
}
Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth
Data:  02010400000057765967000000001e000000000000000000000000008d2de8d2f73f1f4cab472ac9a881c9b123c7962767f801000000000001850000000100000000000000000000000000000000000000000000000000000000000f42400000000000000000000000004f9fd6be4a90f2620860d680c0d4d5fb53d1a825001ef7366aa8fe7af92cbd21b77619e75fd6558e9f6efb648003c76f2d0f901b66ec00010000000000000000000000000000000000000000000000000000000000000000
Keys:  [
  [
    {
      pubkey: [PublicKey [PublicKey(AFEXK4A1BU7BZfi8niAmker98LH9EARB544wKGPXwMyy)]],
      isWritable: false,
      isSigner: false
    },
    'AFEXK4A1BU7BZfi8niAmker98LH9EARB544wKGPXwMyy'
  ],
  [
    {
      pubkey: [PublicKey [PublicKey(2yVjuQwpsvdsrywzsJJVs9Ueh4zayyo5DYJbBNc3DDpn)]],
      isWritable: false,
      isSigner: false
    },
    '2yVjuQwpsvdsrywzsJJVs9Ueh4zayyo5DYJbBNc3DDpn'
  ],
  [
    {
      pubkey: [PublicKey [PublicKey(GYUqShobAQwQT39ErYcxWQ5GChuPHUdbpR7kE6q4sqTG)]],
      isWritable: false,
      isSigner: false
    },
    'GYUqShobAQwQT39ErYcxWQ5GChuPHUdbpR7kE6q4sqTG'
  ],
  [
    {
      pubkey: [PublicKey [PublicKey(oywRtFqLy1jhZLDK6DxzcwiyytFKbVsytSvMax1jHgp)]],
      isWritable: true,
      isSigner: false
    },
    'oywRtFqLy1jhZLDK6DxzcwiyytFKbVsytSvMax1jHgp'
  ],
  [
    {
      pubkey: [PublicKey [PublicKey(8Vgk7VB4cycRSi8xnYG7571MogFri9kQC5FZYtWifMUt)]],
      isWritable: true,
      isSigner: true
    },
    '8Vgk7VB4cycRSi8xnYG7571MogFri9kQC5FZYtWifMUt'
  ],
  [
    {
      pubkey: [PublicKey [PublicKey(SysvarC1ock11111111111111111111111111111111)]],
      isWritable: false,
      isSigner: false
    },
    'SysvarC1ock11111111111111111111111111111111'
  ],
  [
    {
      pubkey: [PublicKey [PublicKey(SysvarRent111111111111111111111111111111111)]],
      isWritable: false,
      isSigner: false
    },
    'SysvarRent111111111111111111111111111111111'
  ],
  [
    {
      pubkey: [PublicKey [PublicKey(11111111111111111111111111111111)]],
      isWritable: false,
      isSigner: false
    },
    '11111111111111111111111111111111'
  ]
]
Submitting transactions 
Transfer failed: SendTransactionError: Simulation failed. 
Message: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0. 
Logs: 
[
  "Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth invoke [1]",
  "Program log: Error: Custom(13)",
  "Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth consumed 68086 of 81703 compute units",
  "Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth failed: custom program error: 0x0"
]. 

@0xMMorty
Copy link
Author

amount: '0.01',
when I change this amount to 10

Error in bridge transfer: SendTransactionError: Simulation failed. Message: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0. Logs: [ "Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth invoke [1]", "Program log: Error: Custom(13)", "Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth consumed 68086 of 81703 compute units", "Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth failed: custom program error: 0x0" ]. Catch theSendTransactionErrorand callgetLogs()on it for full details. at Connection.sendEncodedTransaction (/Users/smile/Desktop/binance-notice/node_modules/@solana/web3.js/lib/index.cjs.js:8214:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Connection.sendRawTransaction (/Users/smile/Desktop/binance-notice/node_modules/@solana/web3.js/lib/index.cjs.js:8179:20) at async SolanaPlatform.sendTxWithRetry (/Users/smile/Desktop/binance-notice/node_modules/@wormhole-foundation/sdk-solana/dist/cjs/platform.js:103:27) at async SolanaSendSigner.signAndSend (/Users/smile/Desktop/binance-notice/node_modules/@wormhole-foundation/sdk-solana/dist/cjs/signer.js:130:43) at async ssw (/Users/smile/Desktop/binance-notice/node_modules/@wormhole-foundation/sdk-connect/dist/cjs/common.js:44:28) at async signSendWait (/Users/smile/Desktop/binance-notice/node_modules/@wormhole-foundation/sdk-connect/dist/cjs/common.js:11:22) at async TokenTransfer.completeTransfer (/Users/smile/Desktop/binance-notice/node_modules/@wormhole-foundation/sdk-connect/dist/cjs/protocols/tokenBridge/tokenTransfer.js:162:29) at async startbridge (/Users/smile/Desktop/binance-notice/src/strategies/worm.strategy.js:135:25) at async testWormholeTransfer2 (/Users/smile/Desktop/binance-notice/scripts/test-wormhole.js:78:24) { signature: '', transactionMessage: 'Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0', transactionLogs: [ 'Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth invoke [1]', 'Program log: Error: Custom(13)', 'Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth consumed 68086 of 81703 compute units', 'Program worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth failed: custom program error: 0x0' ] }

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

3 participants
@0xMMorty and others