1
1
import { IdlAccounts , Program } from "@coral-xyz/anchor" ;
2
2
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" ;
4
4
5
5
export const IdlVersions = {
6
6
"1.0.0" : _1_0_0 ,
@@ -10,52 +10,55 @@ export const IdlVersions = {
10
10
export type IdlVersion = keyof typeof IdlVersions ;
11
11
12
12
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 ;
24
20
25
- export type InboxItem < V extends IdlVersion = "default" > = IdlAccounts <
21
+ type ProgramAccounts < V extends IdlVersion > = IdlAccounts <
26
22
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" ] ;
28
29
}
29
30
30
- function loadIdlVersion < V extends IdlVersion > (
31
+ function loadIdlVersion < const V extends IdlVersion > (
31
32
version : V
32
33
) : ( typeof IdlVersions ) [ V ] {
33
34
if ( ! ( version in IdlVersions ) )
34
35
throw new Error ( `Unknown IDL version: ${ version } ` ) ;
35
36
return IdlVersions [ version ] ;
36
37
}
37
38
38
- export const getNttProgram = (
39
+ export function getNttProgram < const V extends IdlVersion > (
39
40
connection : Connection ,
40
41
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
45
46
loadIdlVersion ( version ) . idl . ntt ,
46
47
address ,
47
48
{ connection }
48
49
) ;
50
+ }
49
51
50
- export const getQuoterProgram = (
52
+ export function getQuoterProgram < const V extends IdlVersion > (
51
53
connection : Connection ,
52
54
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 > > (
56
58
loadIdlVersion ( version ) . idl . quoter ,
57
59
address ,
58
60
{
59
61
connection,
60
62
}
61
63
) ;
64
+ }
0 commit comments