Skip to content

Commit d579f6c

Browse files
committed
SDK: Solana TS deduplication (#442)
1 parent 0e3712d commit d579f6c

File tree

16 files changed

+786
-2367
lines changed

16 files changed

+786
-2367
lines changed

sdk/__tests__/utils.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ async function deployEvm(ctx: Ctx): Promise<Ctx> {
481481
async function deploySolana(ctx: Ctx): Promise<Ctx> {
482482
const { signer, nativeSigner: keypair } = ctx.signers as Signers<"Solana">;
483483
const connection = (await ctx.context.getRpc()) as Connection;
484-
const address = new PublicKey(signer.address());
484+
const sender = Wormhole.chainAddress("Solana", signer.address());
485+
const address = sender.address.toNative("Solana").unwrap();
485486
console.log(`Using public key: ${address}`);
486487

487488
const mint = await spl.createMint(connection, keypair, address, null, 9);
@@ -534,10 +535,7 @@ async function deploySolana(ctx: Ctx): Promise<Ctx> {
534535
manager.pdas.tokenAuthority().toString()
535536
);
536537

537-
const initTxs = manager.initialize({
538-
payer: keypair,
539-
owner: keypair,
540-
chain: "Solana",
538+
const initTxs = manager.initialize(sender.address, {
541539
mint,
542540
outboundLimit: 1000000000n,
543541
mode: ctx.mode,

sdk/examples/src/index.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
TransactionId,
33
Wormhole,
4+
amount,
45
signSendWait,
56
} from "@wormhole-foundation/sdk";
67
import evm from "@wormhole-foundation/sdk/platforms/evm";
@@ -13,28 +14,41 @@ import "@wormhole-foundation/sdk-solana-ntt";
1314
import { TEST_NTT_SPL22_TOKENS, TEST_NTT_TOKENS } from "./consts.js";
1415
import { getSigner } from "./helpers.js";
1516

17+
// EVM 1.0.0, Solana 1.0.0
18+
const TOKEN_CONTRACTS = TEST_NTT_TOKENS;
19+
// EVM 1.0.0 Solana 2.0.0
20+
// const TOKEN_CONTRACTS = TEST_NTT_SPL22_TOKENS;
21+
1622
// Recover an in-flight transfer by setting txids here from output of previous run
1723
const recoverTxids: TransactionId[] = [
1824
//{ chain: "Solana", txid: "hZXRs9TEvMWnSAzcgmrEuHsq1C5rbcompy63vkJ2SrXv4a7u6ZBEaJAkBMXKAfScCooDNhN36Jt4PMcDhN8yGjP", },
25+
//{ chain: "Sepolia", txid: "0x9f2b1a8124f8377d77deb5c85f165c290669587b494c598beacea60a4d9a00fd", },
26+
//{ chain: "Sepolia", txid: "0x7c60e520f807593d27702427666e5c72aa282a3f14fe59ec934c5f9de9558609", },
27+
// Unused and staged
28+
//{chain: "Sepolia", txid: "0x1aff02ed4bf9d51a424626187e3e331304229fc0d422b7abfe8025452b166180"}
1929
];
2030

2131
(async function () {
2232
const wh = new Wormhole("Testnet", [solana.Platform, evm.Platform]);
23-
const src = wh.getChain("Solana");
24-
const dst = wh.getChain("Sepolia");
33+
const src = wh.getChain("Sepolia");
34+
const dst = wh.getChain("Solana");
2535

2636
const srcSigner = await getSigner(src);
2737
const dstSigner = await getSigner(dst);
2838

2939
const srcNtt = await src.getProtocol("Ntt", {
30-
ntt: TEST_NTT_SPL22_TOKENS[src.chain],
40+
ntt: TOKEN_CONTRACTS[src.chain],
3141
});
3242
const dstNtt = await dst.getProtocol("Ntt", {
33-
ntt: TEST_NTT_SPL22_TOKENS[dst.chain],
43+
ntt: TOKEN_CONTRACTS[dst.chain],
3444
});
3545

46+
const amt = amount.units(
47+
amount.parse("0.01", await srcNtt.getTokenDecimals())
48+
);
49+
3650
const xfer = () =>
37-
srcNtt.transfer(srcSigner.address.address, 1_000n, dstSigner.address, {
51+
srcNtt.transfer(srcSigner.address.address, amt, dstSigner.address, {
3852
queue: false,
3953
automatic: false,
4054
gasDropoff: 0n,
@@ -47,7 +61,11 @@ const recoverTxids: TransactionId[] = [
4761
: recoverTxids;
4862
console.log("Source txs", txids);
4963

50-
const vaa = await wh.getVaa(txids[0]!.txid, "Ntt:WormholeTransfer");
64+
const vaa = await wh.getVaa(
65+
txids[0]!.txid,
66+
"Ntt:WormholeTransfer",
67+
25 * 60 * 1000
68+
);
5169
console.log(vaa);
5270

5371
const dstTxids = await signSendWait(

sdk/route/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
"@wormhole-foundation/sdk-evm-ntt": "0.0.1-beta.1",
5252
"@wormhole-foundation/sdk-connect": "0.6.5"
5353
},
54+
"peerDependencies": {
55+
"@wormhole-foundation/sdk-connect": "^0.6"
56+
},
5457
"type": "module",
5558
"exports": {
5659
".": {

solana/tests/anchor.test.ts

+17-36
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ describe("example-native-token-transfers", () => {
122122
let ntt: SolanaNtt<"Devnet", "Solana">;
123123
let signer: Signer;
124124
let sender: AccountAddress<"Solana">;
125+
let tokenAddress: string;
125126

126127
beforeAll(async () => {
127128
try {
@@ -189,15 +190,14 @@ describe("example-native-token-transfers", () => {
189190
TOKEN_PROGRAM
190191
);
191192

193+
tokenAddress = mint.publicKey.toBase58();
192194
// Create our contract client
193195
ntt = new SolanaNtt("Devnet", "Solana", connection, {
194196
...ctx.config.contracts,
195197
ntt: {
196-
token: mint.publicKey.toBase58(),
198+
token: tokenAddress,
197199
manager: NTT_ADDRESS,
198-
transceiver: {
199-
wormhole: NTT_ADDRESS,
200-
},
200+
transceiver: { wormhole: NTT_ADDRESS },
201201
},
202202
});
203203
} catch (e) {
@@ -222,10 +222,7 @@ describe("example-native-token-transfers", () => {
222222
);
223223

224224
// init
225-
const initTxs = ntt.initialize({
226-
payer,
227-
owner: payer,
228-
chain: "Solana",
225+
const initTxs = ntt.initialize(sender, {
229226
mint: mint.publicKey,
230227
outboundLimit: 1000000n,
231228
mode: "burning",
@@ -322,20 +319,6 @@ describe("example-native-token-transfers", () => {
322319
// get from balance
323320
const balance = await connection.getTokenAccountBalance(tokenAccount);
324321
expect(balance.value.amount).toBe("9900000");
325-
326-
// grab logs
327-
//await connection.confirmTransaction(redeemTx, "confirmed");
328-
//const tx = await anchor
329-
// .getProvider()
330-
// .connection.getParsedTransaction(redeemTx, {
331-
// commitment: "confirmed",
332-
// });
333-
// console.log(tx);
334-
// const log = tx.meta.logMessages[1];
335-
// const message = log.substring(log.indexOf(':') + 1);
336-
// console.log(message);
337-
// TODO: assert other stuff in the message
338-
// console.log(nttManagerMessage);
339322
});
340323

341324
it("Can receive tokens", async () => {
@@ -385,40 +368,38 @@ describe("example-native-token-transfers", () => {
385368
throw e;
386369
}
387370

388-
// expect(released).to.equal(true);
371+
// expect(released).toEqual(true);
372+
expect((await counterValue()).toString()).toEqual("2");
389373
});
390374
});
391375

392376
describe("Static Checks", () => {
393-
const wh = new Wormhole("Testnet", [SolanaPlatform]);
394-
377+
const wh = new Wormhole("Devnet", [SolanaPlatform]);
378+
const ctx = wh.getChain("Solana");
395379
const overrides = {
396380
Solana: {
397-
token: "EetppHswYvV1jjRWoQKC1hejdeBDHR9NNzNtCyRQfrrQ",
398-
manager: "NTtAaoDJhkeHeaVUHnyhwbPNAN6WgBpHkHBTc6d7vLK",
399-
transceiver: {
400-
wormhole: "ExVbjD8inGXkt7Cx8jVr4GF175sQy1MeqgfaY53Ah8as",
401-
},
381+
token: tokenAddress,
382+
manager: NTT_ADDRESS,
383+
transceiver: { wormhole: NTT_ADDRESS },
402384
},
403385
};
404386

405387
describe("ABI Versions Test", function () {
406-
const ctx = wh.getChain("Solana");
407388
test("It initializes from Rpc", async function () {
408-
const ntt = await SolanaNtt.fromRpc(await ctx.getRpc(), {
389+
const ntt = await SolanaNtt.fromRpc(connection, {
409390
Solana: {
410391
...ctx.config,
411392
contracts: {
412393
...ctx.config.contracts,
413-
...{ ntt: overrides["Solana"] },
394+
ntt: overrides["Solana"],
414395
},
415396
},
416397
});
417398
expect(ntt).toBeTruthy();
418399
});
419400

420401
test("It initializes from constructor", async function () {
421-
const ntt = new SolanaNtt("Testnet", "Solana", await ctx.getRpc(), {
402+
const ntt = new SolanaNtt("Devnet", "Solana", connection, {
422403
...ctx.config.contracts,
423404
...{ ntt: overrides["Solana"] },
424405
});
@@ -427,11 +408,11 @@ describe("example-native-token-transfers", () => {
427408

428409
test("It gets the correct version", async function () {
429410
const version = await SolanaNtt.getVersion(
430-
await ctx.getRpc(),
411+
connection,
431412
{ ntt: overrides["Solana"] },
432413
new SolanaAddress(payer.publicKey.toBase58())
433414
);
434-
expect(version).toBe("1.0.0");
415+
expect(version).toBe("2.0.0");
435416
});
436417
});
437418
});

0 commit comments

Comments
 (0)