@sanctumso/inf1 0.0.1-dev-2 → 0.0.1-dev-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -16
- package/index.d.ts +77 -63
- package/index.js +107 -98
- package/index_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,8 +6,9 @@ Typescript + WASM SDK for Sanctum Infinity program V1.
|
|
|
6
6
|
|
|
7
7
|
```ts
|
|
8
8
|
import {
|
|
9
|
+
assertAccountsExist,
|
|
9
10
|
createSolanaRpc,
|
|
10
|
-
|
|
11
|
+
fetchEncodedAccounts,
|
|
11
12
|
type Address,
|
|
12
13
|
type IInstruction,
|
|
13
14
|
type Rpc,
|
|
@@ -52,22 +53,14 @@ async function fetchAccountMap(
|
|
|
52
53
|
rpc: Rpc<SolanaRpcApi>,
|
|
53
54
|
accounts: string[]
|
|
54
55
|
): Promise<AccountMap> {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.send();
|
|
63
|
-
const acc = accountInfo.value!;
|
|
64
|
-
map.set(account, {
|
|
65
|
-
data: new Uint8Array(getBase64Encoder().encode(acc.data[0])),
|
|
66
|
-
owner: acc.owner,
|
|
67
|
-
});
|
|
68
|
-
})
|
|
56
|
+
const fetched = await fetchEncodedAccounts(rpc, accounts);
|
|
57
|
+
assertAccountsExist(fetched);
|
|
58
|
+
return new Map(
|
|
59
|
+
fetched.map(({ address, data, programAddress }) => [
|
|
60
|
+
address,
|
|
61
|
+
{ data, owner: programAddress },
|
|
62
|
+
])
|
|
69
63
|
);
|
|
70
|
-
return map;
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
|
package/index.d.ts
CHANGED
|
@@ -9,27 +9,31 @@ export function tradeExactInIx(inf: Inf, arg1: TradeArgs): Instruction;
|
|
|
9
9
|
*/
|
|
10
10
|
export function tradeExactOutIx(inf: Inf, arg1: TradeArgs): Instruction;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* a new {@link Inf} object
|
|
12
|
+
* Add SPL LSTs auxiliary data to support new SPL LSTs that may have previously not been covered
|
|
14
13
|
*/
|
|
15
|
-
export function
|
|
14
|
+
export function appendSplLsts(inf: Inf, arg1: SplPoolAccounts): void;
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
16
|
+
* Returns if the given SPL LST mints have their {@link SplPoolAccounts} present in the object.
|
|
18
17
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* Returns a byte array where ret[i] corresponds to the result for `mints[i]`.
|
|
19
|
+
* 0 - false, 1 - true.
|
|
21
20
|
*
|
|
22
|
-
* @
|
|
21
|
+
* If false is returned, then the data needs to be added via {@link appendSplLsts}
|
|
22
|
+
*
|
|
23
|
+
* This fn returns a byte array instead of `boolean` array because wasm_bindgen's type
|
|
24
|
+
* conversion doesnt work with bool arrays.
|
|
23
25
|
*/
|
|
24
|
-
export function
|
|
26
|
+
export function hasSplData(inf: Inf, mints: Bs58Array[]): Uint8Array;
|
|
25
27
|
/**
|
|
26
|
-
*
|
|
28
|
+
* Returned accounts are deduped
|
|
29
|
+
*
|
|
30
|
+
* @throws
|
|
27
31
|
*/
|
|
28
|
-
export function
|
|
32
|
+
export function accountsToUpdateForTrade(inf: Inf, arg1: PkPair): Bs58Array[];
|
|
29
33
|
/**
|
|
30
|
-
* @throws
|
|
34
|
+
* @throws
|
|
31
35
|
*/
|
|
32
|
-
export function
|
|
36
|
+
export function updateForTrade(inf: Inf, arg1: PkPair, arg2: AccountMap): void;
|
|
33
37
|
/**
|
|
34
38
|
* @throws
|
|
35
39
|
*/
|
|
@@ -39,31 +43,31 @@ export function quoteTradeExactIn(inf: Inf, arg1: QuoteArgs): Quote;
|
|
|
39
43
|
*/
|
|
40
44
|
export function quoteTradeExactOut(inf: Inf, arg1: QuoteArgs): Quote;
|
|
41
45
|
/**
|
|
42
|
-
*
|
|
46
|
+
* Returns the array of all possible {@link InfErr}s
|
|
43
47
|
*/
|
|
44
|
-
export function
|
|
48
|
+
export function allInfErrs(): AllInfErrs;
|
|
45
49
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* Returns a byte array where ret[i] corresponds to the result for `mints[i]`.
|
|
49
|
-
* 0 - false, 1 - true.
|
|
50
|
-
*
|
|
51
|
-
* If false is returned, then the data needs to be added via {@link appendSplLsts}
|
|
52
|
-
*
|
|
53
|
-
* This fn returns a byte array instead of `boolean` array because wasm_bindgen's type
|
|
54
|
-
* conversion doesnt work with bool arrays.
|
|
50
|
+
* @throws if not valid PDA found
|
|
55
51
|
*/
|
|
56
|
-
export function
|
|
52
|
+
export function findPoolReservesAta(arg0: Bs58Array): FoundPda;
|
|
57
53
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @throws
|
|
54
|
+
* @throws if not valid PDA found
|
|
61
55
|
*/
|
|
62
|
-
export function
|
|
56
|
+
export function findProtocolFeeAccumulatorAta(arg0: Bs58Array): FoundPda;
|
|
63
57
|
/**
|
|
58
|
+
* Returns the pubkeys of the accounts that need ot be fetched to initialize
|
|
59
|
+
* a new {@link Inf} object
|
|
60
|
+
*/
|
|
61
|
+
export function initPks(): Bs58Array[];
|
|
62
|
+
/**
|
|
63
|
+
* Initialize a new {@link Inf} object.
|
|
64
|
+
*
|
|
65
|
+
* The returned object must be updated for a mint pair before it is ready to
|
|
66
|
+
* quote and operate for trades involving that pair
|
|
67
|
+
*
|
|
64
68
|
* @throws
|
|
65
69
|
*/
|
|
66
|
-
export function
|
|
70
|
+
export function init(arg0: AccountMap, arg1: SplPoolAccounts): Inf;
|
|
67
71
|
export interface TradeArgs {
|
|
68
72
|
amt: bigint;
|
|
69
73
|
limit: bigint;
|
|
@@ -72,33 +76,6 @@ export interface TradeArgs {
|
|
|
72
76
|
tokenAccs: PkPair;
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
export type FoundPda = [B58PK, number];
|
|
76
|
-
|
|
77
|
-
export interface Pair<T> {
|
|
78
|
-
inp: T;
|
|
79
|
-
out: T;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type PkPair = Pair<B58PK>;
|
|
83
|
-
|
|
84
|
-
export interface AccountMeta {
|
|
85
|
-
address: B58PK;
|
|
86
|
-
/**
|
|
87
|
-
* Represents the role of an account in a transaction:
|
|
88
|
-
* - Readonly: 0
|
|
89
|
-
* - Writable: 1
|
|
90
|
-
* - ReadonlySigner: 2
|
|
91
|
-
* - WritableSigner: 3
|
|
92
|
-
*/
|
|
93
|
-
role: 0 | 1 | 2 | 3;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface Instruction {
|
|
97
|
-
data: Uint8Array;
|
|
98
|
-
accounts: AccountMeta[];
|
|
99
|
-
programAddress: B58PK;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
79
|
export type FeeMint = "inp" | "out";
|
|
103
80
|
|
|
104
81
|
export interface QuoteArgs {
|
|
@@ -139,6 +116,13 @@ export interface Quote {
|
|
|
139
116
|
mints: PkPair;
|
|
140
117
|
}
|
|
141
118
|
|
|
119
|
+
export interface Pair<T> {
|
|
120
|
+
inp: T;
|
|
121
|
+
out: T;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type PkPair = Pair<B58PK>;
|
|
125
|
+
|
|
142
126
|
export interface Account {
|
|
143
127
|
data: Uint8Array;
|
|
144
128
|
owner: B58PK;
|
|
@@ -157,6 +141,35 @@ export type AccountMap = Map<B58PK, Account>;
|
|
|
157
141
|
|
|
158
142
|
export type B58PK = Bs58Array;
|
|
159
143
|
|
|
144
|
+
/**
|
|
145
|
+
* All {@link Error} objects thrown by SDK functions will start with
|
|
146
|
+
* `{InfErr}:`, so that the `InfErr` error code can be
|
|
147
|
+
* extracted by splitting on the first colon `:`
|
|
148
|
+
*/
|
|
149
|
+
export type InfErr = "AccDeserErr" | "InternalErr" | "MissingAccErr" | "MissingSplDataErr" | "MissingSvcDataErr" | "NoValidPdaErr" | "PoolErr" | "UnknownSvcErr" | "UnsupportedMintErr" | "UserErr";
|
|
150
|
+
|
|
151
|
+
export type AllInfErrs = InfErr[];
|
|
152
|
+
|
|
153
|
+
export type FoundPda = [B58PK, number];
|
|
154
|
+
|
|
155
|
+
export interface AccountMeta {
|
|
156
|
+
address: B58PK;
|
|
157
|
+
/**
|
|
158
|
+
* Represents the role of an account in a transaction:
|
|
159
|
+
* - Readonly: 0
|
|
160
|
+
* - Writable: 1
|
|
161
|
+
* - ReadonlySigner: 2
|
|
162
|
+
* - WritableSigner: 3
|
|
163
|
+
*/
|
|
164
|
+
role: 0 | 1 | 2 | 3;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface Instruction {
|
|
168
|
+
data: Uint8Array;
|
|
169
|
+
accounts: AccountMeta[];
|
|
170
|
+
programAddress: B58PK;
|
|
171
|
+
}
|
|
172
|
+
|
|
160
173
|
export type Bs58Array = string
|
|
161
174
|
|
|
162
175
|
export class Inf {
|
|
@@ -170,25 +183,26 @@ export interface InitOutput {
|
|
|
170
183
|
readonly memory: WebAssembly.Memory;
|
|
171
184
|
readonly tradeExactInIx: (a: number, b: any) => [number, number, number];
|
|
172
185
|
readonly tradeExactOutIx: (a: number, b: any) => [number, number, number];
|
|
173
|
-
readonly initPks: () => [number, number];
|
|
174
|
-
readonly init: (a: any, b: any) => [number, number, number];
|
|
175
|
-
readonly findPoolReservesAta: (a: any) => [number, number, number];
|
|
176
|
-
readonly findProtocolFeeAccumulatorAta: (a: any) => [number, number, number];
|
|
177
|
-
readonly quoteTradeExactIn: (a: number, b: any) => [number, number, number];
|
|
178
|
-
readonly quoteTradeExactOut: (a: number, b: any) => [number, number, number];
|
|
179
186
|
readonly appendSplLsts: (a: number, b: any) => void;
|
|
180
187
|
readonly hasSplData: (a: number, b: number, c: number) => [number, number];
|
|
181
188
|
readonly accountsToUpdateForTrade: (a: number, b: any) => [number, number, number, number];
|
|
182
189
|
readonly updateForTrade: (a: number, b: any, c: any) => [number, number];
|
|
190
|
+
readonly quoteTradeExactIn: (a: number, b: any) => [number, number, number];
|
|
191
|
+
readonly quoteTradeExactOut: (a: number, b: any) => [number, number, number];
|
|
183
192
|
readonly __wbg_inf_free: (a: number, b: number) => void;
|
|
193
|
+
readonly allInfErrs: () => any;
|
|
194
|
+
readonly findPoolReservesAta: (a: any) => [number, number, number];
|
|
195
|
+
readonly findProtocolFeeAccumulatorAta: (a: any) => [number, number, number];
|
|
196
|
+
readonly initPks: () => [number, number];
|
|
197
|
+
readonly init: (a: any, b: any) => [number, number, number];
|
|
184
198
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
185
199
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
186
200
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
187
201
|
readonly __externref_table_alloc: () => number;
|
|
188
202
|
readonly __wbindgen_export_4: WebAssembly.Table;
|
|
189
203
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
190
|
-
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
191
204
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
205
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
192
206
|
readonly __wbindgen_start: () => void;
|
|
193
207
|
}
|
|
194
208
|
|