-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
96 lines (80 loc) · 3.65 KB
/
index.js
File metadata and controls
96 lines (80 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const wormholeSdk = require('@certusone/wormhole-sdk');
const contracts = require('./contracts.json');
const ethers = require('ethers');
const { extractCctpMessages } = require('./cctp');
const inspect = require('util').inspect;
const PRIVATE_KEY = '0x...'; // Replace with your private key
const destinationChainProvider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID'); // Replace with your RPC endpoint
const wallet = new ethers.Wallet(PRIVATE_KEY, destinationChainProvider);
function getTargetRelayerContractAddress(targetChainId) {
const targetContractAddress = contracts.find(
(contract) => contract.chainId === targetChainId
).address;
if (!targetContractAddress) {
throw new Error(`No relayer contract found for chain ID ${targetChainId}`);
}
return targetContractAddress;
}
async function main() {
const base64VAA = 'AgAAAA...'; // Replace with your actual base64-encoded VAA
const targetWormholeChainId = 1; // Replace with the target Wormhole chain ID
const signedVaa = Buffer.from(base64VAA, 'base64');
const targetRelayerSmartContractAddress = getTargetRelayerContractAddress(targetWormholeChainId);
const wormholeRelayerSmartContract = wormholeSdk.ethers_relayer_contracts.WormholeRelayer__factory.connect(
targetRelayerSmartContractAddress,
targetWormholeChainId
);
/**
* Supported messages: VAA and CCTP Messages.
* @type {(wormholeSdk.SignedVaa | string)[]}
*/
const additionalMessages = [];
// // Fetch CCTP messages and their attestations for the source transaction hash included in the VAA
// if (true) {
// const sourceTxHash = '0x...'; // Replace with the source transaction hash containing the CCTP message
// const vaaEmitterChainId = 1; // Replace with the Wormhole chain ID of the VAA emitter
// const deliveryMessageKeys = [
// // Replace with the actual delivery message keys from the DeliveryInstruction
// {
// keyType: wormholeSdk.relayer.KeyType.CCTP,
// key: '0x...', // Replace with the actual key
// },
// ];
// const sourceChainProvider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID'); // Replace with the RPC endpoint of the source chain
// const cctpMessages = await extractCctpMessages(sourceChainProvider, sourceTxHash, vaaEmitterChainId, deliveryMessageKeys);
// additionalMessages.push(...cctpMessages);
// }
/**
* You can override internal gas limit here
* @type {wormholeSdk.relayer.DeliveryOverrideArgs}
*/
const deliveryOverrides = undefined;
const gasUnitEstimate = await wormholeRelayerSmartContract.estimateGas.deliver(
additionalMessages,
signedVaa,
wallet.address,
deliveryOverrides ? wormholeSdk.relayer.packOverrides(deliveryOverrides) : [],
undefined
);
/**
* @type {ethers.PayableOverrides}
*/
const overrides = {
gasLimit: gasUnitEstimate
}
const txWithCallData = await wormholeRelayerSmartContract.populateTransaction.deliver(
additionalMessages,
signedVaa,
wallet.address,
deliveryOverrides ? wormholeSdk.relayer.packOverrides(deliveryOverrides) : [],
overrides
);
const txWithMetadata = await wallet.populateTransaction(txWithCallData);
const txReceipt = await wallet.sendTransaction(txWithMetadata);
await txReceipt.wait(2);
console.log('Transaction receipt:', inspect(txReceipt));
}
main().catch((error) => {
console.error('Error:', error);
process.exit(1);
});