@sanctumso/inf1 0.0.1-dev-2 → 0.0.1-dev-4

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 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
- getBase64Encoder,
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 map = new Map<string, Account>();
56
- await Promise.all(
57
- accounts.map(async (account) => {
58
- const accountInfo = await rpc
59
- .getAccountInfo(account as Address, {
60
- encoding: "base64",
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
@@ -1,35 +1,43 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
- * @throws
4
+ * Returns the array of all possible {@link InfErr}s
5
5
  */
6
- export function tradeExactInIx(inf: Inf, arg1: TradeArgs): Instruction;
6
+ export function allInfErrs(): AllInfErrs;
7
7
  /**
8
- * @throws
8
+ * @throws if no valid PDA found
9
9
  */
10
- export function tradeExactOutIx(inf: Inf, arg1: TradeArgs): Instruction;
10
+ export function findPoolReservesAta(arg0: Bs58Array): FoundPda;
11
11
  /**
12
- * Returns the pubkeys of the accounts that need ot be fetched to initialize
13
- * a new {@link Inf} object
12
+ * @throws if no valid PDA found
14
13
  */
15
- export function initPks(): Bs58Array[];
14
+ export function findProtocolFeeAccumulatorAta(arg0: Bs58Array): FoundPda;
16
15
  /**
17
- * Initialize a new {@link Inf} object.
16
+ * Add SPL LSTs auxiliary data to support new SPL LSTs that may have previously not been covered
17
+ */
18
+ export function appendSplLsts(inf: Inf, arg1: SplPoolAccounts): void;
19
+ /**
20
+ * Returns if the given SPL LST mints have their {@link SplPoolAccounts} present in the object.
18
21
  *
19
- * The returned object must be updated for a mint pair before it is ready to
20
- * quote and operate for trades involving that pair
22
+ * Returns a byte array where ret[i] corresponds to the result for `mints[i]`.
23
+ * 0 - false, 1 - true.
21
24
  *
22
- * @throws
25
+ * If false is returned, then the data needs to be added via {@link appendSplLsts}
26
+ *
27
+ * This fn returns a byte array instead of `boolean` array because wasm_bindgen's type
28
+ * conversion doesnt work with bool arrays.
23
29
  */
24
- export function init(arg0: AccountMap, arg1: SplPoolAccounts): Inf;
30
+ export function hasSplData(inf: Inf, mints: Bs58Array[]): Uint8Array;
25
31
  /**
26
- * @throws if not valid PDA found
32
+ * Returned accounts are deduped
33
+ *
34
+ * @throws
27
35
  */
28
- export function findPoolReservesAta(arg0: Bs58Array): FoundPda;
36
+ export function accountsToUpdateForTrade(inf: Inf, arg1: PkPair): Bs58Array[];
29
37
  /**
30
- * @throws if not valid PDA found
38
+ * @throws
31
39
  */
32
- export function findProtocolFeeAccumulatorAta(arg0: Bs58Array): FoundPda;
40
+ export function updateForTrade(inf: Inf, arg1: PkPair, account_map: AccountMap): void;
33
41
  /**
34
42
  * @throws
35
43
  */
@@ -39,47 +47,56 @@ export function quoteTradeExactIn(inf: Inf, arg1: QuoteArgs): Quote;
39
47
  */
40
48
  export function quoteTradeExactOut(inf: Inf, arg1: QuoteArgs): Quote;
41
49
  /**
42
- * Add SPL LSTs auxiliary data to support new SPL LSTs that may have previously not been covered
50
+ * Returns the pubkeys of the accounts that need ot be fetched to initialize
51
+ * a new {@link Inf} object
43
52
  */
44
- export function appendSplLsts(inf: Inf, arg1: SplPoolAccounts): void;
53
+ export function initPks(): Bs58Array[];
45
54
  /**
46
- * Returns if the given SPL LST mints have their {@link SplPoolAccounts} present in the object.
47
- *
48
- * Returns a byte array where ret[i] corresponds to the result for `mints[i]`.
49
- * 0 - false, 1 - true.
55
+ * Initialize a new {@link Inf} object.
50
56
  *
51
- * If false is returned, then the data needs to be added via {@link appendSplLsts}
57
+ * The returned object must be updated for a mint pair before it is ready to
58
+ * quote and operate for trades involving that pair
52
59
  *
53
- * This fn returns a byte array instead of `boolean` array because wasm_bindgen's type
54
- * conversion doesnt work with bool arrays.
60
+ * @throws
55
61
  */
56
- export function hasSplData(inf: Inf, mints: Bs58Array[]): Uint8Array;
62
+ export function init(arg0: AccountMap, arg1: SplPoolAccounts): Inf;
57
63
  /**
58
- * Returned accounts are deduped
59
- *
60
64
  * @throws
61
65
  */
62
- export function accountsToUpdateForTrade(inf: Inf, arg1: PkPair): Bs58Array[];
66
+ export function tradeExactInIx(inf: Inf, arg1: TradeArgs): Instruction;
63
67
  /**
64
68
  * @throws
65
69
  */
66
- export function updateForTrade(inf: Inf, arg1: PkPair, arg2: AccountMap): void;
67
- export interface TradeArgs {
68
- amt: bigint;
69
- limit: bigint;
70
- mints: PkPair;
71
- signer: B58PK;
72
- tokenAccs: PkPair;
73
- }
70
+ export function tradeExactOutIx(inf: Inf, arg1: TradeArgs): Instruction;
74
71
 
75
- export type FoundPda = [B58PK, number];
72
+ export type ERR_CODE_MSG_SEP = ":";
76
73
 
77
- export interface Pair<T> {
78
- inp: T;
79
- out: T;
80
- }
74
+ /**
75
+ * All {@link Error} objects thrown by the SDK have messages of this format
76
+ */
77
+ export type InfErrMsg = `${InfErr}${ERR_CODE_MSG_SEP}${string}`;
81
78
 
82
- export type PkPair = Pair<B58PK>;
79
+
80
+ /**
81
+ * All {@link Error} objects thrown by SDK functions will start with
82
+ * `{InfErr}:`, so that the `InfErr` error code can be
83
+ * extracted by splitting on the first colon `:`
84
+ */
85
+ export type InfErr = "AccDeserErr" | "InternalErr" | "MissingAccErr" | "MissingSplDataErr" | "MissingSvcDataErr" | "NoValidPdaErr" | "PoolErr" | "UnknownPpErr" | "UnknownSvcErr" | "UnsupportedMintErr" | "SizeTooSmallErr" | "SizeTooLargeErr";
86
+
87
+ export type AllInfErrs = [
88
+ "AccDeserErr",
89
+ "InternalErr",
90
+ "MissingAccErr",
91
+ "MissingSplDataErr",
92
+ "MissingSvcDataErr",
93
+ "NoValidPdaErr",
94
+ "PoolErr",
95
+ "UnknownSvcErr",
96
+ "UnsupportedMintErr",
97
+ "SizeTooSmallErr",
98
+ "SizeTooLargeErr",
99
+ ];
83
100
 
84
101
  export interface AccountMeta {
85
102
  address: B58PK;
@@ -139,6 +156,16 @@ export interface Quote {
139
156
  mints: PkPair;
140
157
  }
141
158
 
159
+ export type FoundPda = [B58PK, number];
160
+
161
+ export interface TradeArgs {
162
+ amt: bigint;
163
+ limit: bigint;
164
+ mints: PkPair;
165
+ signer: B58PK;
166
+ tokenAccs: PkPair;
167
+ }
168
+
142
169
  export interface Account {
143
170
  data: Uint8Array;
144
171
  owner: B58PK;
@@ -155,6 +182,11 @@ export type SplPoolAccounts = Map<B58PK, B58PK>;
155
182
 
156
183
  export type AccountMap = Map<B58PK, Account>;
157
184
 
185
+ export interface PkPair {
186
+ inp: B58PK;
187
+ out: B58PK;
188
+ }
189
+
158
190
  export type B58PK = Bs58Array;
159
191
 
160
192
  export type Bs58Array = string
@@ -168,18 +200,19 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
168
200
 
169
201
  export interface InitOutput {
170
202
  readonly memory: WebAssembly.Memory;
171
- readonly tradeExactInIx: (a: number, b: any) => [number, number, number];
172
- readonly tradeExactOutIx: (a: number, b: any) => [number, number, number];
173
- readonly initPks: () => [number, number];
174
- readonly init: (a: any, b: any) => [number, number, number];
203
+ readonly allInfErrs: () => any;
175
204
  readonly findPoolReservesAta: (a: any) => [number, number, number];
176
205
  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
206
  readonly appendSplLsts: (a: number, b: any) => void;
180
207
  readonly hasSplData: (a: number, b: number, c: number) => [number, number];
181
208
  readonly accountsToUpdateForTrade: (a: number, b: any) => [number, number, number, number];
182
209
  readonly updateForTrade: (a: number, b: any, c: any) => [number, number];
210
+ readonly quoteTradeExactIn: (a: number, b: any) => [number, number, number];
211
+ readonly quoteTradeExactOut: (a: number, b: any) => [number, number, number];
212
+ readonly initPks: () => [number, number];
213
+ readonly init: (a: any, b: any) => [number, number, number];
214
+ readonly tradeExactInIx: (a: number, b: any) => [number, number, number];
215
+ readonly tradeExactOutIx: (a: number, b: any) => [number, number, number];
183
216
  readonly __wbg_inf_free: (a: number, b: number) => void;
184
217
  readonly __wbindgen_malloc: (a: number, b: number) => number;
185
218
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -187,8 +220,8 @@ export interface InitOutput {
187
220
  readonly __externref_table_alloc: () => number;
188
221
  readonly __wbindgen_export_4: WebAssembly.Table;
189
222
  readonly __externref_table_dealloc: (a: number) => void;
190
- readonly __externref_drop_slice: (a: number, b: number) => void;
191
223
  readonly __wbindgen_free: (a: number, b: number, c: number) => void;
224
+ readonly __externref_drop_slice: (a: number, b: number) => void;
192
225
  readonly __wbindgen_start: () => void;
193
226
  }
194
227