Skip to content

Commit f0f5549

Browse files
committed
Move bindings to lib, refactor instruction creation utils
1 parent 80c00d8 commit f0f5549

File tree

11 files changed

+490
-983
lines changed

11 files changed

+490
-983
lines changed

sdk/__tests__/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,8 @@ async function deploySolana(ctx: Ctx): Promise<Ctx> {
535535
);
536536

537537
const initTxs = manager.initialize({
538-
payer: keypair,
539-
owner: keypair,
538+
payer: keypair.publicKey,
539+
owner: keypair.publicKey,
540540
chain: "Solana",
541541
mint,
542542
outboundLimit: 1000000000n,

solana/tests/anchor.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ describe("example-native-token-transfers", () => {
223223

224224
// init
225225
const initTxs = ntt.initialize({
226-
payer,
227-
owner: payer,
226+
payer: payer.publicKey,
227+
owner: payer.publicKey,
228228
chain: "Solana",
229229
mint: mint.publicKey,
230230
outboundLimit: 1000000n,
File renamed without changes.
File renamed without changes.
File renamed without changes.

solana/ts/sdk/bindings.ts solana/ts/lib/bindings.ts

+26-24
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@ import { IdlAccounts, Program } from "@coral-xyz/anchor";
22
import { Connection } from "@solana/web3.js";
33
import { _1_0_0, _2_0_0 } from "./anchor-idl/index.js";
44

5+
export interface IdlBinding<V extends IdlVersion> {
6+
idl: {
7+
ntt: NttBindings.NativeTokenTransfer<V>;
8+
quoter: NttBindings.Quoter<V>;
9+
};
10+
}
11+
512
export const IdlVersions = {
613
"1.0.0": _1_0_0,
714
"2.0.0": _2_0_0,
8-
default: _2_0_0,
915
} as const;
16+
1017
export type IdlVersion = keyof typeof IdlVersions;
1118

1219
export namespace NttBindings {
@@ -22,43 +29,38 @@ export namespace NttBindings {
2229
NttBindings.NativeTokenTransfer<V>
2330
>;
2431

25-
export type Config<V extends IdlVersion = IdlVersion> =
26-
ProgramAccounts<V>["config"];
27-
export type InboxItem<V extends IdlVersion = IdlVersion> =
28-
ProgramAccounts<V>["inboxItem"];
32+
export type Config<V extends IdlVersion> = ProgramAccounts<V>["config"];
33+
export type InboxItem<V extends IdlVersion> = ProgramAccounts<V>["inboxItem"];
2934
}
3035

31-
function loadIdlVersion<const V extends IdlVersion>(
32-
version: V
33-
): (typeof IdlVersions)[V] {
36+
function loadIdlVersion<V extends IdlVersion>(version: V): IdlBinding<V> {
3437
if (!(version in IdlVersions))
3538
throw new Error(`Unknown IDL version: ${version}`);
36-
return IdlVersions[version];
39+
return IdlVersions[version] as unknown as IdlBinding<V>;
3740
}
3841

39-
export function getNttProgram<const V extends IdlVersion>(
42+
export function getNttProgram<V extends IdlVersion>(
4043
connection: Connection,
4144
address: string,
4245
version: V
4346
): Program<NttBindings.NativeTokenTransfer<V>> {
44-
return new Program<NttBindings.NativeTokenTransfer<V>>(
45-
//@ts-ignore
46-
loadIdlVersion(version).idl.ntt,
47-
address,
48-
{ connection }
49-
);
47+
const {
48+
idl: { ntt },
49+
} = loadIdlVersion(version);
50+
return new Program<NttBindings.NativeTokenTransfer<V>>(ntt, address, {
51+
connection,
52+
});
5053
}
5154

52-
export function getQuoterProgram<const V extends IdlVersion>(
55+
export function getQuoterProgram<V extends IdlVersion>(
5356
connection: Connection,
5457
address: string,
5558
version: V
5659
) {
57-
return new Program<NttBindings.Quoter<V>>(
58-
loadIdlVersion(version).idl.quoter,
59-
address,
60-
{
61-
connection,
62-
}
63-
);
60+
const {
61+
idl: { quoter },
62+
} = loadIdlVersion(version);
63+
return new Program<NttBindings.Quoter<V>>(quoter, address, {
64+
connection,
65+
});
6466
}

solana/ts/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./ntt.js";
22
export * from "./quoter.js";
3+
export * from "./bindings.js";

0 commit comments

Comments
 (0)