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

Add Wormhole SDK Page #9

Merged
merged 76 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
9a56529
initial setup
themacexpert Aug 2, 2024
b0a3717
grammarly overhaul
themacexpert Aug 2, 2024
e87feec
prettify all code snippets
themacexpert Aug 2, 2024
a0f1336
in progress
themacexpert Aug 2, 2024
0697e78
additions
themacexpert Aug 2, 2024
fb1e5a6
revisions
themacexpert Aug 3, 2024
12f9b02
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
7127c26
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
ae8d03d
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
ac2e106
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
d2cc237
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
28acee0
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
78ae923
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
759d1e1
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 6, 2024
127533e
change warning to admonition
themacexpert Aug 6, 2024
7faabcf
rev
themacexpert Aug 6, 2024
2aa20eb
rev'
themacexpert Aug 6, 2024
e1a8c30
revisions
themacexpert Aug 6, 2024
06d7ab9
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 8, 2024
c8b61f1
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 8, 2024
1aab200
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 8, 2024
9c85726
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 8, 2024
3e02832
import eco
themacexpert Aug 8, 2024
89a419a
run prettier
themacexpert Aug 8, 2024
e016e9b
Merge branch 'themacexpert/buildMulti' of https://github.com/wormhole…
themacexpert Aug 8, 2024
fefa23b
rev
themacexpert Aug 9, 2024
991f5fa
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
172c19b
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
ba6a051
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
fb2d561
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
c046980
Update .snippets/code/build/build-multichain-applications/wormhole-sd…
themacexpert Aug 9, 2024
49cd0d2
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
844f2f7
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
20eb5e3
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
3b030b7
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
0236cc5
rev
themacexpert Aug 9, 2024
8a34a4f
Merge branch 'themacexpert/buildMulti' of https://github.com/wormhole…
themacexpert Aug 9, 2024
dc2f5ee
rev
themacexpert Aug 9, 2024
17ddf5b
rev
themacexpert Aug 9, 2024
12f3ed2
rev
themacexpert Aug 9, 2024
13452e0
rev
themacexpert Aug 9, 2024
eadd665
rev
themacexpert Aug 9, 2024
bb1eb4d
rev
themacexpert Aug 9, 2024
ac5b8ab
rev
themacexpert Aug 9, 2024
be232ca
rev
themacexpert Aug 9, 2024
99c76dc
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
baf4b3a
Update build/build-multichain-applications/wormhole-sdk.md
themacexpert Aug 9, 2024
38247e0
rev
themacexpert Aug 9, 2024
ea35466
Merge branch 'themacexpert/buildMulti' of https://github.com/wormhole…
themacexpert Aug 9, 2024
22460ba
rev
themacexpert Aug 9, 2024
c1578d7
rev
themacexpert Aug 9, 2024
72735bc
rev
themacexpert Aug 9, 2024
f0c3b0d
rev
themacexpert Aug 10, 2024
203d23d
rev
themacexpert Aug 10, 2024
ca4f42d
rev
themacexpert Aug 10, 2024
07aa1cd
Update .snippets/code/build/build-apps/wormhole-sdk/cctp.ts
themacexpert Aug 13, 2024
ec1fe0b
comment capitalization
themacexpert Aug 13, 2024
d7834b2
rev
themacexpert Aug 13, 2024
3b132dd
Update .snippets/code/build/build-apps/wormhole-sdk/cctp.ts
themacexpert Aug 13, 2024
0d99dce
Update build/build-apps/wormhole-sdk.md
themacexpert Aug 13, 2024
cba9d1a
rev
themacexpert Aug 13, 2024
7d59712
Update build/build-apps/wormhole-sdk.md
themacexpert Aug 13, 2024
9e95244
rev
themacexpert Aug 13, 2024
787ed06
rev
themacexpert Aug 13, 2024
ecc5aae
revise
themacexpert Aug 13, 2024
4939bf2
revise
themacexpert Aug 13, 2024
58d2178
rev
themacexpert Aug 13, 2024
dc972ee
rev
themacexpert Aug 13, 2024
66551bb
revise
themacexpert Aug 13, 2024
bc93e07
revise
themacexpert Aug 13, 2024
63fab26
revise
themacexpert Aug 13, 2024
7feb80e
revise
themacexpert Aug 13, 2024
f8c9bbc
Update build/build-apps/wormhole-sdk.md
themacexpert Aug 19, 2024
bbac961
Update build/build-apps/wormhole-sdk.md
themacexpert Aug 19, 2024
a1a2ab7
Update build/build-apps/wormhole-sdk.md
themacexpert Aug 19, 2024
d423942
delete unneeded snippet
themacexpert Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Its possible to convert a string address to its Native address
// It's possible to convert a string address to its Native address
const ethAddr: NativeAddress<'Evm'> = toNative('Ethereum', '0xbeef...');

// A common type in the SDK is the `ChainAddress` which provides
// the additional context of the `Chain` this address is relevant for.
// the additional context of the `Chain` this address is relevant for
const senderAddress: ChainAddress = Wormhole.chainAddress(
'Ethereum',
'0xbeef...'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
const xfer = await wh.circleTransfer(
// amount as bigint (base units)
req.amount,
// sender chain/address
src.address,
// receiver chain/address
dst.address,
// automatic delivery boolean
req.automatic,
// payload to be sent with the transfer
undefined,
// If automatic, native gas can be requested to be sent to the receiver
req.nativeGas
);

// Note, if the transfer is requested to be Automatic, a fee for performing the relay
// will be present in the quote. The fee comes out of the amount requested to be sent.
// If the user wants to receive 1.0 on the destination, the amount to send should be 1.0 + fee.
// The same applies for native gas dropoff
const quote = await CircleTransfer.quoteTransfer(
src.chain,
dst.chain,
Expand All @@ -34,8 +24,6 @@ if (req.automatic) {
return;
}

// Note: Depending on chain finality, this timeout may need to be increased.
// See https://developers.circle.com/stablecoin/docs/cctp-technical-reference#mainnet for more
console.log('Waiting for Attestation');
const attestIds = await xfer.fetchAttestation(60_000);
console.log(`Got Attestation: `, attestIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
Wormhole,
amount,
wormhole,
} from "@wormhole-foundation/sdk";
import evm from "@wormhole-foundation/sdk/evm";
import solana from "@wormhole-foundation/sdk/solana";
import { SignerStuff, getSigner, waitForRelay } from "./helpers/index.js";
} from '@wormhole-foundation/sdk';
import evm from '@wormhole-foundation/sdk/evm';
import solana from '@wormhole-foundation/sdk/solana';
import { SignerStuff, getSigner, waitForRelay } from './helpers/index.js';

/*
Notes:
Expand All @@ -24,19 +24,19 @@ AutoRelayer takes a 0.1usdc fee when xfering to any chain beside goerli, which i
(async function () {
// init Wormhole object, passing config for which network
// to use (e.g. Mainnet/Testnet) and what Platforms to support
const wh = await wormhole("Testnet", [evm, solana]);
const wh = await wormhole('Testnet', [evm, solana]);

// Grab chain Contexts
const sendChain = wh.getChain("Avalanche");
const rcvChain = wh.getChain("Solana");
const sendChain = wh.getChain('Avalanche');
const rcvChain = wh.getChain('Solana');

// Get signer from local key but anything that implements
// Signer interface (e.g. wrapper around web wallet) should work
const source = await getSigner(sendChain);
const destination = await getSigner(rcvChain);

// 6 decimals for USDC (except for bsc, so check decimals before using this)
const amt = amount.units(amount.parse("0.2", 6));
const amt = amount.units(amount.parse('0.2', 6));

// Choose whether or not to have the attestation delivered for you
const automatic = false;
Expand All @@ -45,7 +45,7 @@ AutoRelayer takes a 0.1usdc fee when xfering to any chain beside goerli, which i
// during redemption, the receiver gets some amount of native gas transferred to them
// so that they may pay for subsequent transactions
// The amount specified here is denominated in the token being transferred (USDC here)
const nativeGas = automatic ? amount.units(amount.parse("0.0", 6)) : 0n;
const nativeGas = automatic ? amount.units(amount.parse('0.0', 6)) : 0n;

await cctpTransfer(wh, source, destination, {
amount: amt,
Expand Down Expand Up @@ -75,7 +75,7 @@ async function cctpTransfer<N extends Network>(
amount: bigint;
automatic: boolean;
nativeGas?: bigint;
},
}
) {
// EXAMPLE_CCTP_TRANSFER
const xfer = await wh.circleTransfer(
Expand All @@ -90,17 +90,21 @@ async function cctpTransfer<N extends Network>(
// payload to be sent with the transfer
undefined,
// If automatic, native gas can be requested to be sent to the receiver
req.nativeGas,
req.nativeGas
);

// Note, if the transfer is requested to be Automatic, a fee for performing the relay
// will be present in the quote. The fee comes out of the amount requested to be sent.
// If the user wants to receive 1.0 on the destination, the amount to send should be 1.0 + fee.
// The same applies for native gas dropoff
const quote = await CircleTransfer.quoteTransfer(src.chain, dst.chain, xfer.transfer);
console.log("Quote", quote);
const quote = await CircleTransfer.quoteTransfer(
src.chain,
dst.chain,
xfer.transfer
);
console.log('Quote', quote);

console.log("Starting Transfer");
console.log('Starting Transfer');
const srcTxids = await xfer.initiateTransfer(src.signer);
console.log(`Started Transfer: `, srcTxids);

Expand All @@ -112,11 +116,11 @@ async function cctpTransfer<N extends Network>(

// Note: Depending on chain finality, this timeout may need to be increased.
// See https://developers.circle.com/stablecoin/docs/cctp-technical-reference#mainnet for more
console.log("Waiting for Attestation");
console.log('Waiting for Attestation');
const attestIds = await xfer.fetchAttestation(60_000);
console.log(`Got Attestation: `, attestIds);

console.log("Completing Transfer");
console.log('Completing Transfer');
const dstTxids = await xfer.completeTransfer(dst.signer);
console.log(`Completed Transfer: `, dstTxids);
// EXAMPLE_CCTP_TRANSFER
Expand All @@ -125,16 +129,16 @@ async function cctpTransfer<N extends Network>(
export async function completeTransfer(
wh: Wormhole<Network>,
txid: TransactionId,
signer: Signer,
signer: Signer
): Promise<void> {
// EXAMPLE_RECOVER_TRANSFER
// Rebuild the transfer from the source txid
const xfer = await CircleTransfer.from(wh, txid);

const attestIds = await xfer.fetchAttestation(60 * 60 * 1000);
console.log("Got attestation: ", attestIds);
console.log('Got attestation: ', attestIds);

const dstTxIds = await xfer.completeTransfer(signer);
console.log("Completed transfer: ", dstTxIds);
console.log('Completed transfer: ', dstTxIds);
// EXAMPLE_RECOVER_TRANSFER
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Pass a partial WormholeConfig object to override specific
// fields in the default config
const wh = await wormhole('Testnet', [solana], {
chains: {
Solana: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { wormhole } from "@wormhole-foundation/sdk";
import solana from "@wormhole-foundation/sdk/solana";
import { wormhole } from '@wormhole-foundation/sdk';
import solana from '@wormhole-foundation/sdk/solana';
(async function () {
// EXAMPLE_CONFIG_OVERRIDE
// Pass a partial WormholeConfig object to override specific
// fields in the default config
const wh = await wormhole("Testnet", [solana], {
const wh = await wormhole('Testnet', [solana], {
chains: {
Solana: {
contracts: {
coreBridge: "11111111111111111111111111111",
coreBridge: '11111111111111111111111111111',
},
rpc: "https://api.devnet.solana.com",
rpc: 'https://api.devnet.solana.com',
},
},
});
// EXAMPLE_CONFIG_OVERRIDE
console.log(wh.config.chains.Solana);
})();
})();
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const wh = await wormhole('Testnet', [solana]);

const chain = wh.getChain('Solana');
const { signer, address } = await getSigner(chain);

// Get a reference to the core messaging bridge
const coreBridge = await chain.getWormholeCore();

// Generate transactions, sign and send them
Expand All @@ -12,31 +9,23 @@ const publishTxs = coreBridge.publishMessage(
address.address,
// Message to send (payload in VAA)
encoding.bytes.encode('lol'),
// Nonce (user defined, no requirement for a specific value, useful to provide a unique identifier for the message)
// Nonce (user defined, no requirement for a specific value)
0,
// ConsistencyLevel (ie finality of the message, see wormhole docs for more)
// ConsistencyLevel (ie finality of the message)
0
);
// Send the transaction(s) to publish the message
const txids = await signSendWait(chain, publishTxs, signer);

// Take the last txid in case multiple were sent
// the last one should be the one containing the relevant
// event or log info
const txid = txids[txids.length - 1];

// Grab the wormhole message id from the transaction logs or storage
const [whm] = await chain.parseTransaction(txid!.txid);

// Or pull the full message content as an Unsigned VAA
// const msgs = await coreBridge.parseMessages(txid!.txid);
// console.log(msgs);

// Wait for the vaa to be signed and available with a timeout
const vaa = await wh.getVaa(whm!, 'Uint8Array', 60_000);
console.log(vaa);
// Also possible to search by txid but it takes longer to show up
// console.log(await wh.getVaaByTxHash(txid!.txid, "Uint8Array"));

const verifyTxs = coreBridge.verifyMessage(address.address, vaa!);
console.log(await signSendWait(chain, verifyTxs, signer));
Loading
Loading