Skip to content

Commit 7f112c9

Browse files
committed
update bindings to work for both versions (#439)
1 parent 36e1da8 commit 7f112c9

19 files changed

+510
-386
lines changed

package-lock.json

+175-175
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"sync": "tsx syncVersion.ts && npm install && npm run build"
2121
},
2222
"devDependencies": {
23-
"@wormhole-foundation/sdk": "0.6.3",
23+
"@wormhole-foundation/sdk": "0.6.5",
2424
"@solana/spl-token": "0.3.9",
2525
"@solana/web3.js": "1.91.7",
2626
"@types/jest": "^29.5.12",

sdk/definitions/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
},
5151
"dependencies": {
5252
"@noble/hashes": "^1.3.1",
53-
"@wormhole-foundation/sdk-base": "0.6.3",
54-
"@wormhole-foundation/sdk-definitions": "0.6.3"
53+
"@wormhole-foundation/sdk-base": "0.6.5",
54+
"@wormhole-foundation/sdk-definitions": "0.6.5"
5555
},
5656
"type": "module"
5757
}

sdk/definitions/src/ntt.ts

-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,6 @@ export interface Ntt<N extends Network, C extends Chain> {
176176
payer?: AccountAddress<C>
177177
): AsyncGenerator<UnsignedTransaction<N, C>>;
178178

179-
/** Get the interface version */
180-
getVersion(payer?: AccountAddress<C>): Promise<string>;
181-
182179
/** Get the address for the account that custodies locked tokens */
183180
getCustodyAddress(): Promise<string>;
184181

sdk/evm/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
"test": "jest --config ./jest.config.ts"
4646
},
4747
"dependencies": {
48-
"@wormhole-foundation/sdk-connect": "0.6.3",
48+
"@wormhole-foundation/sdk-connect": "0.6.5",
4949
"@wormhole-foundation/sdk-definitions-ntt": "0.0.1-beta.1",
50-
"@wormhole-foundation/sdk-evm": "0.6.3",
51-
"@wormhole-foundation/sdk-evm-core": "0.6.3",
50+
"@wormhole-foundation/sdk-evm": "0.6.5",
51+
"@wormhole-foundation/sdk-evm-core": "0.6.5",
5252
"ethers": "^6.5.1"
5353
},
5454
"devDependencies": {

sdk/evm/src/ntt.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
} from "@wormhole-foundation/sdk-definitions-ntt";
3030
import { Contract, type Provider, type TransactionRequest } from "ethers";
3131
import {
32-
AbiVersion,
3332
NttBindings,
3433
NttManagerBindings,
3534
NttTransceiverBindings,
@@ -99,7 +98,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
9998
readonly chain: C,
10099
readonly provider: Provider,
101100
readonly contracts: Contracts & { ntt?: Ntt.Contracts },
102-
readonly abiVersion: AbiVersion = "default"
101+
readonly version: string = "default"
103102
) {
104103
if (!contracts.ntt) throw new Error("No Ntt Contracts provided");
105104

@@ -111,7 +110,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
111110
this.tokenAddress = contracts.ntt.token;
112111
this.managerAddress = contracts.ntt.manager;
113112

114-
const abiBindings = loadAbiVersion(this.abiVersion);
113+
const abiBindings = loadAbiVersion(this.version);
115114

116115
this.manager = abiBindings.NttManager.connect(
117116
contracts.ntt.manager,
@@ -175,9 +174,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
175174
if (conf.network !== network)
176175
throw new Error(`Network mismatch: ${conf.network} != ${network}`);
177176

178-
const { ntt } = conf.contracts as { ntt: Ntt.Contracts };
179-
180-
const version = await EvmNtt._getVersion(ntt.manager, provider);
177+
const version = await EvmNtt.getVersion(provider, conf.contracts);
181178
return new EvmNtt(network as N, chain, provider, conf.contracts, version);
182179
}
183180

@@ -192,13 +189,12 @@ export class EvmNtt<N extends Network, C extends EvmChains>
192189
return ixs;
193190
}
194191

195-
async getVersion(): Promise<string> {
196-
return EvmNtt._getVersion(this.managerAddress, this.provider);
197-
}
198-
199-
static async _getVersion(address: string, provider: Provider) {
192+
static async getVersion(
193+
provider: Provider,
194+
contracts: Contracts & { ntt?: Ntt.Contracts }
195+
) {
200196
const contract = new Contract(
201-
address,
197+
contracts.ntt!.manager,
202198
["function NTT_MANAGER_VERSION() public view returns (string)"],
203199
provider
204200
);
@@ -212,7 +208,7 @@ export class EvmNtt<N extends Network, C extends EvmChains>
212208
return abiVersion;
213209
} catch (e) {
214210
console.error(
215-
`Failed to get NTT_MANAGER_VERSION from contract ${address}`
211+
`Failed to get NTT_MANAGER_VERSION from contract ${contracts.ntt?.manager}`
216212
);
217213
throw e;
218214
}

sdk/examples/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"tsx": "^4.7.2"
4444
},
4545
"dependencies": {
46-
"@wormhole-foundation/sdk": "0.6.3",
46+
"@wormhole-foundation/sdk": "0.6.5",
4747
"@wormhole-foundation/sdk-definitions-ntt": "0.0.1-beta.1",
4848
"@wormhole-foundation/sdk-evm-ntt": "0.0.1-beta.1",
4949
"@wormhole-foundation/sdk-solana-ntt": "0.0.1-beta.1",

sdk/examples/src/consts.ts

+16
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ export const TEST_NTT_TOKENS: NttContracts = {
4848
},
4949
};
5050

51+
export const TEST_NTT_SPL22_TOKENS: NttContracts = {
52+
Sepolia: {
53+
token: "0x3a84364d27ed3d16022da0f603f3e0f74826c707",
54+
manager: "0x46475d067f7c2a388a7bb7fd5a9A4a68D7fA45c5",
55+
transceiver: {
56+
wormhole: "0x24cb9E1FEcaa40f07feBC0E32Ce16C0bb3ed6443",
57+
},
58+
},
59+
Solana: {
60+
token: "BAn1Zcr48bmaK5SmzBDjoju6csFe8AT6bot4ACBJvVwU",
61+
manager: "NtTnpY76eiMYqYX9xkag2CSXk9cGi6hinMWbMLMDYUP",
62+
transceiver: { wormhole: "NtTnpY76eiMYqYX9xkag2CSXk9cGi6hinMWbMLMDYUP" },
63+
quoter: "Nqd6XqA8LbsCuG8MLWWuP865NV6jR1MbXeKxD4HLKDJ",
64+
},
65+
};
66+
5167
// Reformat NTT contracts to fit TokenConfig for Route
5268
function reformat(contracts: NttContracts) {
5369
return Object.entries(TEST_NTT_TOKENS).map(([chain, contracts]) => {

sdk/examples/src/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export async function getSigner<N extends Network, C extends Chain>(
4141
case "Solana":
4242
signer = await solana.getSigner(
4343
await chain.getRpc(),
44-
getEnv("SOL_PRIVATE_KEY", DEVNET_SOL_PRIVATE_KEY),
45-
{ debug: true }
44+
getEnv("OTHER_SOL_PRIVATE_KEY", DEVNET_SOL_PRIVATE_KEY),
45+
{ debug: false }
4646
);
4747
break;
4848
case "Evm":

sdk/examples/src/index.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,31 @@ import solana from "@wormhole-foundation/sdk/platforms/solana";
1010
import "@wormhole-foundation/sdk-evm-ntt";
1111
import "@wormhole-foundation/sdk-solana-ntt";
1212

13-
import { TEST_NTT_TOKENS } from "./consts.js";
13+
import { TEST_NTT_SPL22_TOKENS, TEST_NTT_TOKENS } from "./consts.js";
1414
import { getSigner } from "./helpers.js";
1515

1616
// Recover an in-flight transfer by setting txids here from output of previous run
1717
const recoverTxids: TransactionId[] = [
18-
// { chain: "Solana", txid: "hZXRs9TEvMWnSAzcgmrEuHsq1C5rbcompy63vkJ2SrXv4a7u6ZBEaJAkBMXKAfScCooDNhN36Jt4PMcDhN8yGjP", },
18+
//{ chain: "Solana", txid: "hZXRs9TEvMWnSAzcgmrEuHsq1C5rbcompy63vkJ2SrXv4a7u6ZBEaJAkBMXKAfScCooDNhN36Jt4PMcDhN8yGjP", },
1919
];
2020

2121
(async function () {
2222
const wh = new Wormhole("Testnet", [solana.Platform, evm.Platform]);
2323
const src = wh.getChain("Solana");
24-
const dst = wh.getChain("ArbitrumSepolia");
24+
const dst = wh.getChain("Sepolia");
2525

2626
const srcSigner = await getSigner(src);
2727
const dstSigner = await getSigner(dst);
2828

2929
const srcNtt = await src.getProtocol("Ntt", {
30-
ntt: TEST_NTT_TOKENS[src.chain],
30+
ntt: TEST_NTT_SPL22_TOKENS[src.chain],
3131
});
3232
const dstNtt = await dst.getProtocol("Ntt", {
33-
ntt: TEST_NTT_TOKENS[dst.chain],
33+
ntt: TEST_NTT_SPL22_TOKENS[dst.chain],
3434
});
3535

36-
console.log("Source signer", srcSigner.address.address);
37-
3836
const xfer = () =>
39-
srcNtt.transfer(srcSigner.address.address, 1000n, dstSigner.address, {
37+
srcNtt.transfer(srcSigner.address.address, 1_000n, dstSigner.address, {
4038
queue: false,
4139
automatic: false,
4240
gasDropoff: 0n,
@@ -54,7 +52,7 @@ const recoverTxids: TransactionId[] = [
5452

5553
const dstTxids = await signSendWait(
5654
dst,
57-
dstNtt.redeem([vaa!]),
55+
dstNtt.redeem([vaa!], dstSigner.address.address),
5856
dstSigner.signer
5957
);
6058
console.log("dstTxids", dstTxids);

sdk/route/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@wormhole-foundation/sdk-definitions-ntt": "0.0.1-beta.1",
5050
"@wormhole-foundation/sdk-solana-ntt": "0.0.1-beta.1",
5151
"@wormhole-foundation/sdk-evm-ntt": "0.0.1-beta.1",
52-
"@wormhole-foundation/sdk-connect": "0.6.3"
52+
"@wormhole-foundation/sdk-connect": "0.6.5"
5353
},
5454
"type": "module",
5555
"exports": {

solana/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
"@solana/spl-token": "0.4.0",
5555
"@solana/web3.js": "1.91.7",
5656
"bn.js":"5.2.1",
57-
"@wormhole-foundation/sdk-connect": "0.6.3",
58-
"@wormhole-foundation/sdk-solana": "0.6.3",
59-
"@wormhole-foundation/sdk-solana-core": "0.6.3"
57+
"@wormhole-foundation/sdk-connect": "0.6.5",
58+
"@wormhole-foundation/sdk-solana": "0.6.5",
59+
"@wormhole-foundation/sdk-solana-core": "0.6.5"
6060
},
6161
"type": "module",
6262
"exports": {

solana/tests/anchor.test.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ describe("example-native-token-transfers", () => {
166166

167167
transaction.feePayer = payer.publicKey;
168168
transaction.recentBlockhash = blockhash;
169-
console.log(transaction);
170169

171170
const txid = await connection.sendTransaction(transaction, [payer, mint]);
172171
await connection.confirmTransaction(txid, "confirmed");
@@ -205,7 +204,6 @@ describe("example-native-token-transfers", () => {
205204
},
206205
});
207206
} catch (e) {
208-
console.error(e);
209207
throw e;
210208
}
211209
});
@@ -255,7 +253,6 @@ describe("example-native-token-transfers", () => {
255253
const setPeerTxs = ntt.setPeer(remoteMgr, 18, 1000000n, sender);
256254
await signSendWait(ctx, setPeerTxs, signer);
257255
} catch (e) {
258-
console.error(e);
259256
throw e;
260257
}
261258
});
@@ -430,12 +427,9 @@ describe("example-native-token-transfers", () => {
430427
});
431428

432429
test("It gets the correct version", async function () {
433-
// TODO: need valida address with lamports on network
434-
435-
const { manager } = overrides["Solana"];
436-
const version = await SolanaNtt._getVersion(
437-
manager,
430+
const version = await SolanaNtt.getVersion(
438431
await ctx.getRpc(),
432+
{ ntt: overrides["Solana"] },
439433
new SolanaAddress(payer.publicKey.toBase58())
440434
);
441435
expect(version).toBe("1.0.0");

solana/ts/sdk/anchor-idl/1_0_0.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { IDL as governance } from "../../idl/1_0_0/ts/wormhole_governance.js";
77

88
export namespace _1_0_0 {
99
export const idl = { ntt, quoter, governance };
10-
1110
export type RawExampleNativeTokenTransfers = ExampleNativeTokenTransfers;
1211
export type RawNttQuoter = NttQuoter;
1312
export type RawWormholeGovernance = WormholeGovernance;

solana/ts/sdk/anchor-idl/2_0_0.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { IDL as governance } from "../../idl/2_0_0/ts/wormhole_governance.js";
77

88
export namespace _2_0_0 {
99
export const idl = { ntt, quoter, governance };
10-
1110
export type RawExampleNativeTokenTransfers = ExampleNativeTokenTransfers;
1211
export type RawNttQuoter = NttQuoter;
1312
export type RawWormholeGovernance = WormholeGovernance;

solana/ts/sdk/anchor-idl/index.ts

-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
11
export * from "./1_0_0.js";
22
export * from "./2_0_0.js";
3-
4-
// This is a workaround for the fact that the anchor idl doesn't support generics
5-
// yet. This type is used to remove the generics from the idl types.
6-
export type OmitGenerics<T> = {
7-
[P in keyof T]: T[P] extends Record<"generics", any>
8-
? never
9-
: T[P] extends object
10-
? OmitGenerics<T[P]>
11-
: T[P];
12-
};

solana/ts/sdk/bindings.ts

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IdlAccounts, Program } from "@coral-xyz/anchor";
22
import { Connection } from "@solana/web3.js";
3-
import { OmitGenerics, _1_0_0, _2_0_0 } from "./anchor-idl/index.js";
3+
import { _1_0_0, _2_0_0 } from "./anchor-idl/index.js";
44

55
export const IdlVersions = {
66
"1.0.0": _1_0_0,
@@ -10,52 +10,55 @@ export const IdlVersions = {
1010
export type IdlVersion = keyof typeof IdlVersions;
1111

1212
export namespace NttBindings {
13-
export type NativeTokenTransfer<V extends IdlVersion = "default"> =
14-
V extends "1.0.0"
15-
? OmitGenerics<_1_0_0.RawExampleNativeTokenTransfers>
16-
: OmitGenerics<_2_0_0.RawExampleNativeTokenTransfers>;
17-
export type Quoter<V extends IdlVersion = "default"> = V extends "1.0.0"
18-
? OmitGenerics<_1_0_0.RawNttQuoter>
19-
: OmitGenerics<_2_0_0.RawNttQuoter>;
20-
21-
export type Config<V extends IdlVersion = "default"> = IdlAccounts<
22-
NttBindings.NativeTokenTransfer<V>
23-
>["config"];
13+
export type NativeTokenTransfer<V extends IdlVersion> = V extends "1.0.0"
14+
? _1_0_0.RawExampleNativeTokenTransfers
15+
: _2_0_0.RawExampleNativeTokenTransfers;
16+
17+
export type Quoter<V extends IdlVersion> = V extends "1.0.0"
18+
? _1_0_0.RawNttQuoter
19+
: _2_0_0.RawNttQuoter;
2420

25-
export type InboxItem<V extends IdlVersion = "default"> = IdlAccounts<
21+
type ProgramAccounts<V extends IdlVersion> = IdlAccounts<
2622
NttBindings.NativeTokenTransfer<V>
27-
>["inboxItem"];
23+
>;
24+
25+
export type Config<V extends IdlVersion = IdlVersion> =
26+
ProgramAccounts<V>["config"];
27+
export type InboxItem<V extends IdlVersion = IdlVersion> =
28+
ProgramAccounts<V>["inboxItem"];
2829
}
2930

30-
function loadIdlVersion<V extends IdlVersion>(
31+
function loadIdlVersion<const V extends IdlVersion>(
3132
version: V
3233
): (typeof IdlVersions)[V] {
3334
if (!(version in IdlVersions))
3435
throw new Error(`Unknown IDL version: ${version}`);
3536
return IdlVersions[version];
3637
}
3738

38-
export const getNttProgram = (
39+
export function getNttProgram<const V extends IdlVersion>(
3940
connection: Connection,
4041
address: string,
41-
version: IdlVersion = "default"
42-
) =>
43-
new Program<NttBindings.NativeTokenTransfer>(
44-
// @ts-ignore
42+
version: V
43+
): Program<NttBindings.NativeTokenTransfer<V>> {
44+
return new Program<NttBindings.NativeTokenTransfer<V>>(
45+
//@ts-ignore
4546
loadIdlVersion(version).idl.ntt,
4647
address,
4748
{ connection }
4849
);
50+
}
4951

50-
export const getQuoterProgram = (
52+
export function getQuoterProgram<const V extends IdlVersion>(
5153
connection: Connection,
5254
address: string,
53-
version: IdlVersion = "default"
54-
) =>
55-
new Program<NttBindings.Quoter<typeof version>>(
55+
version: V
56+
) {
57+
return new Program<NttBindings.Quoter<V>>(
5658
loadIdlVersion(version).idl.quoter,
5759
address,
5860
{
5961
connection,
6062
}
6163
);
64+
}

0 commit comments

Comments
 (0)