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

SDK: Solana TS deduplication #442

Merged
merged 14 commits into from
May 8, 2024
8 changes: 3 additions & 5 deletions sdk/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ async function deployEvm(ctx: Ctx): Promise<Ctx> {
async function deploySolana(ctx: Ctx): Promise<Ctx> {
const { signer, nativeSigner: keypair } = ctx.signers as Signers<"Solana">;
const connection = (await ctx.context.getRpc()) as Connection;
const address = new PublicKey(signer.address());
const sender = Wormhole.chainAddress("Solana", signer.address());
const address = sender.address.toNative("Solana").unwrap();
console.log(`Using public key: ${address}`);

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

const initTxs = manager.initialize({
payer: keypair,
owner: keypair,
chain: "Solana",
const initTxs = manager.initialize(sender.address, {
mint,
outboundLimit: 1000000000n,
mode: ctx.mode,
Expand Down
30 changes: 24 additions & 6 deletions sdk/examples/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
TransactionId,
Wormhole,
amount,
signSendWait,
} from "@wormhole-foundation/sdk";
import evm from "@wormhole-foundation/sdk/platforms/evm";
Expand All @@ -13,28 +14,41 @@ import "@wormhole-foundation/sdk-solana-ntt";
import { TEST_NTT_SPL22_TOKENS, TEST_NTT_TOKENS } from "./consts.js";
import { getSigner } from "./helpers.js";

// EVM 1.0.0, Solana 1.0.0
const TOKEN_CONTRACTS = TEST_NTT_TOKENS;
// EVM 1.0.0 Solana 2.0.0
// const TOKEN_CONTRACTS = TEST_NTT_SPL22_TOKENS;

// Recover an in-flight transfer by setting txids here from output of previous run
const recoverTxids: TransactionId[] = [
//{ chain: "Solana", txid: "hZXRs9TEvMWnSAzcgmrEuHsq1C5rbcompy63vkJ2SrXv4a7u6ZBEaJAkBMXKAfScCooDNhN36Jt4PMcDhN8yGjP", },
//{ chain: "Sepolia", txid: "0x9f2b1a8124f8377d77deb5c85f165c290669587b494c598beacea60a4d9a00fd", },
//{ chain: "Sepolia", txid: "0x7c60e520f807593d27702427666e5c72aa282a3f14fe59ec934c5f9de9558609", },
// Unused and staged
//{chain: "Sepolia", txid: "0x1aff02ed4bf9d51a424626187e3e331304229fc0d422b7abfe8025452b166180"}
];

(async function () {
const wh = new Wormhole("Testnet", [solana.Platform, evm.Platform]);
const src = wh.getChain("Solana");
const dst = wh.getChain("Sepolia");
const src = wh.getChain("Sepolia");
const dst = wh.getChain("Solana");

const srcSigner = await getSigner(src);
const dstSigner = await getSigner(dst);

const srcNtt = await src.getProtocol("Ntt", {
ntt: TEST_NTT_SPL22_TOKENS[src.chain],
ntt: TOKEN_CONTRACTS[src.chain],
});
const dstNtt = await dst.getProtocol("Ntt", {
ntt: TEST_NTT_SPL22_TOKENS[dst.chain],
ntt: TOKEN_CONTRACTS[dst.chain],
});

const amt = amount.units(
amount.parse("0.01", await srcNtt.getTokenDecimals())
);

const xfer = () =>
srcNtt.transfer(srcSigner.address.address, 1_000n, dstSigner.address, {
srcNtt.transfer(srcSigner.address.address, amt, dstSigner.address, {
queue: false,
automatic: false,
gasDropoff: 0n,
Expand All @@ -47,7 +61,11 @@ const recoverTxids: TransactionId[] = [
: recoverTxids;
console.log("Source txs", txids);

const vaa = await wh.getVaa(txids[0]!.txid, "Ntt:WormholeTransfer");
const vaa = await wh.getVaa(
txids[0]!.txid,
"Ntt:WormholeTransfer",
25 * 60 * 1000
);
console.log(vaa);

const dstTxids = await signSendWait(
Expand Down
3 changes: 3 additions & 0 deletions sdk/route/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
"@wormhole-foundation/sdk-evm-ntt": "0.0.1-beta.1",
"@wormhole-foundation/sdk-connect": "0.6.5"
},
"peerDependencies": {
"@wormhole-foundation/sdk-connect": "^0.6"
},
"type": "module",
"exports": {
".": {
Expand Down
53 changes: 17 additions & 36 deletions solana/tests/anchor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ describe("example-native-token-transfers", () => {
let ntt: SolanaNtt<"Devnet", "Solana">;
let signer: Signer;
let sender: AccountAddress<"Solana">;
let tokenAddress: string;

beforeAll(async () => {
try {
Expand Down Expand Up @@ -189,15 +190,14 @@ describe("example-native-token-transfers", () => {
TOKEN_PROGRAM
);

tokenAddress = mint.publicKey.toBase58();
// Create our contract client
ntt = new SolanaNtt("Devnet", "Solana", connection, {
...ctx.config.contracts,
ntt: {
token: mint.publicKey.toBase58(),
token: tokenAddress,
manager: NTT_ADDRESS,
transceiver: {
wormhole: NTT_ADDRESS,
},
transceiver: { wormhole: NTT_ADDRESS },
},
});
} catch (e) {
Expand All @@ -222,10 +222,7 @@ describe("example-native-token-transfers", () => {
);

// init
const initTxs = ntt.initialize({
payer,
owner: payer,
chain: "Solana",
const initTxs = ntt.initialize(sender, {
mint: mint.publicKey,
outboundLimit: 1000000n,
mode: "burning",
Expand Down Expand Up @@ -322,20 +319,6 @@ describe("example-native-token-transfers", () => {
// get from balance
const balance = await connection.getTokenAccountBalance(tokenAccount);
expect(balance.value.amount).toBe("9900000");

// grab logs
//await connection.confirmTransaction(redeemTx, "confirmed");
//const tx = await anchor
// .getProvider()
// .connection.getParsedTransaction(redeemTx, {
// commitment: "confirmed",
// });
// console.log(tx);
// const log = tx.meta.logMessages[1];
// const message = log.substring(log.indexOf(':') + 1);
// console.log(message);
// TODO: assert other stuff in the message
// console.log(nttManagerMessage);
});

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

// expect(released).to.equal(true);
// expect(released).toEqual(true);
expect((await counterValue()).toString()).toEqual("2");
});
});

describe("Static Checks", () => {
const wh = new Wormhole("Testnet", [SolanaPlatform]);

const wh = new Wormhole("Devnet", [SolanaPlatform]);
const ctx = wh.getChain("Solana");
const overrides = {
Solana: {
token: "EetppHswYvV1jjRWoQKC1hejdeBDHR9NNzNtCyRQfrrQ",
manager: "NTtAaoDJhkeHeaVUHnyhwbPNAN6WgBpHkHBTc6d7vLK",
transceiver: {
wormhole: "ExVbjD8inGXkt7Cx8jVr4GF175sQy1MeqgfaY53Ah8as",
},
token: tokenAddress,
manager: NTT_ADDRESS,
transceiver: { wormhole: NTT_ADDRESS },
},
};

describe("ABI Versions Test", function () {
const ctx = wh.getChain("Solana");
test("It initializes from Rpc", async function () {
const ntt = await SolanaNtt.fromRpc(await ctx.getRpc(), {
const ntt = await SolanaNtt.fromRpc(connection, {
Solana: {
...ctx.config,
contracts: {
...ctx.config.contracts,
...{ ntt: overrides["Solana"] },
ntt: overrides["Solana"],
},
},
});
expect(ntt).toBeTruthy();
});

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

test("It gets the correct version", async function () {
const version = await SolanaNtt.getVersion(
await ctx.getRpc(),
connection,
{ ntt: overrides["Solana"] },
new SolanaAddress(payer.publicKey.toBase58())
);
expect(version).toBe("1.0.0");
expect(version).toBe("2.0.0");
});
});
});
Expand Down
Loading
Loading