@@ -2,11 +2,18 @@ import { IdlAccounts, Program } from "@coral-xyz/anchor";
2
2
import { Connection } from "@solana/web3.js" ;
3
3
import { _1_0_0 , _2_0_0 } from "./anchor-idl/index.js" ;
4
4
5
+ export interface IdlBinding < V extends IdlVersion > {
6
+ idl : {
7
+ ntt : NttBindings . NativeTokenTransfer < V > ;
8
+ quoter : NttBindings . Quoter < V > ;
9
+ } ;
10
+ }
11
+
5
12
export const IdlVersions = {
6
13
"1.0.0" : _1_0_0 ,
7
14
"2.0.0" : _2_0_0 ,
8
- default : _2_0_0 ,
9
15
} as const ;
16
+
10
17
export type IdlVersion = keyof typeof IdlVersions ;
11
18
12
19
export namespace NttBindings {
@@ -22,43 +29,38 @@ export namespace NttBindings {
22
29
NttBindings . NativeTokenTransfer < V >
23
30
> ;
24
31
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" ] ;
29
34
}
30
35
31
- function loadIdlVersion < const V extends IdlVersion > (
32
- version : V
33
- ) : ( typeof IdlVersions ) [ V ] {
36
+ function loadIdlVersion < V extends IdlVersion > ( version : V ) : IdlBinding < V > {
34
37
if ( ! ( version in IdlVersions ) )
35
38
throw new Error ( `Unknown IDL version: ${ version } ` ) ;
36
- return IdlVersions [ version ] ;
39
+ return IdlVersions [ version ] as unknown as IdlBinding < V > ;
37
40
}
38
41
39
- export function getNttProgram < const V extends IdlVersion > (
42
+ export function getNttProgram < V extends IdlVersion > (
40
43
connection : Connection ,
41
44
address : string ,
42
45
version : V
43
46
) : 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
+ } ) ;
50
53
}
51
54
52
- export function getQuoterProgram < const V extends IdlVersion > (
55
+ export function getQuoterProgram < V extends IdlVersion > (
53
56
connection : Connection ,
54
57
address : string ,
55
58
version : V
56
59
) {
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
+ } ) ;
64
66
}
0 commit comments