@sanctumso/inf1 0.0.1-dev-1 → 0.0.1-dev-2
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 +16 -9
- package/index.d.ts +144 -41
- package/index.js +448 -334
- package/index_bg.wasm +0 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "@solana/kit";
|
|
16
16
|
import {
|
|
17
17
|
accountsToUpdateForTrade,
|
|
18
|
+
init,
|
|
18
19
|
initPks,
|
|
19
20
|
quoteTradeExactIn,
|
|
20
21
|
tradeExactInIx,
|
|
@@ -22,14 +23,23 @@ import {
|
|
|
22
23
|
type AccountMap,
|
|
23
24
|
type SplPoolAccounts,
|
|
24
25
|
} from "@sanctumso/inf1";
|
|
26
|
+
import initSdk from "@sanctumso/inf1";
|
|
27
|
+
|
|
28
|
+
// The SDK needs to be initialized once globally before it can be used (idempotent).
|
|
29
|
+
// For nodejs environments, use
|
|
30
|
+
// `import { initSyncEmbed } from "@sanctumso/inf1"; initSyncEmbed();`
|
|
31
|
+
// instead
|
|
32
|
+
await initSdk();
|
|
25
33
|
|
|
26
34
|
const LAINESOL = "LAinEtNLgpmCP9Rvsf5Hn8W6EhNiKLZQti1xfWMLy6X";
|
|
27
35
|
const WSOL = "So11111111111111111111111111111111111111112";
|
|
28
|
-
const SPL_POOL_ACCOUNTS: SplPoolAccounts = {
|
|
36
|
+
const SPL_POOL_ACCOUNTS: SplPoolAccounts = new Map(Object.entries({
|
|
29
37
|
[LAINESOL]: "2qyEeSAWKfU18AFthrF7JA8z8ZCi1yt76Tqs917vwQTV",
|
|
30
38
|
// ...populate rest of `spl lst mint: stake pool addr` data
|
|
31
|
-
// for every
|
|
32
|
-
|
|
39
|
+
// for every spl lst mints in the INF pool (all 3 spl program deploys).
|
|
40
|
+
// To support SPL LSTs that are added later on, the `appendSplLsts` fn
|
|
41
|
+
// can be used to add data
|
|
42
|
+
}));
|
|
33
43
|
|
|
34
44
|
// If out === INF mint, then below code will work the same,
|
|
35
45
|
// but the quote and instruction will be for AddLiquidity instead of SwapExactIn.
|
|
@@ -63,13 +73,10 @@ async function fetchAccountMap(
|
|
|
63
73
|
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
|
|
64
74
|
|
|
65
75
|
// init
|
|
66
|
-
const
|
|
67
|
-
const initAccs = await fetchAccountMap(rpc,
|
|
76
|
+
const ipks = initPks();
|
|
77
|
+
const initAccs = await fetchAccountMap(rpc, ipks);
|
|
68
78
|
const inf = init(
|
|
69
|
-
|
|
70
|
-
poolState: initAccs.get(poolStateAddr)!,
|
|
71
|
-
lstStateList: initAccs.get(lstStateListAddr)!,
|
|
72
|
-
},
|
|
79
|
+
initAccs,
|
|
73
80
|
SPL_POOL_ACCOUNTS
|
|
74
81
|
);
|
|
75
82
|
|
package/index.d.ts
CHANGED
|
@@ -1,18 +1,68 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* @throws
|
|
5
|
+
*/
|
|
3
6
|
export function tradeExactInIx(inf: Inf, arg1: TradeArgs): Instruction;
|
|
7
|
+
/**
|
|
8
|
+
* @throws
|
|
9
|
+
*/
|
|
4
10
|
export function tradeExactOutIx(inf: Inf, arg1: TradeArgs): Instruction;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the pubkeys of the accounts that need ot be fetched to initialize
|
|
13
|
+
* a new {@link Inf} object
|
|
14
|
+
*/
|
|
15
|
+
export function initPks(): Bs58Array[];
|
|
16
|
+
/**
|
|
17
|
+
* Initialize a new {@link Inf} object.
|
|
18
|
+
*
|
|
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
|
|
21
|
+
*
|
|
22
|
+
* @throws
|
|
23
|
+
*/
|
|
24
|
+
export function init(arg0: AccountMap, arg1: SplPoolAccounts): Inf;
|
|
25
|
+
/**
|
|
26
|
+
* @throws if not valid PDA found
|
|
27
|
+
*/
|
|
5
28
|
export function findPoolReservesAta(arg0: Bs58Array): FoundPda;
|
|
29
|
+
/**
|
|
30
|
+
* @throws if not valid PDA found
|
|
31
|
+
*/
|
|
6
32
|
export function findProtocolFeeAccumulatorAta(arg0: Bs58Array): FoundPda;
|
|
7
|
-
export function initPks(): InitPks;
|
|
8
|
-
export function init(arg0: InitAccounts, arg1: SplPoolAccounts): Inf;
|
|
9
33
|
/**
|
|
10
|
-
*
|
|
34
|
+
* @throws
|
|
11
35
|
*/
|
|
12
|
-
export function updateSplLsts(inf: Inf, arg1: SplPoolAccounts): void;
|
|
13
36
|
export function quoteTradeExactIn(inf: Inf, arg1: QuoteArgs): Quote;
|
|
14
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @throws
|
|
39
|
+
*/
|
|
40
|
+
export function quoteTradeExactOut(inf: Inf, arg1: QuoteArgs): Quote;
|
|
41
|
+
/**
|
|
42
|
+
* Add SPL LSTs auxiliary data to support new SPL LSTs that may have previously not been covered
|
|
43
|
+
*/
|
|
44
|
+
export function appendSplLsts(inf: Inf, arg1: SplPoolAccounts): void;
|
|
45
|
+
/**
|
|
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.
|
|
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.
|
|
55
|
+
*/
|
|
56
|
+
export function hasSplData(inf: Inf, mints: Bs58Array[]): Uint8Array;
|
|
57
|
+
/**
|
|
58
|
+
* Returned accounts are deduped
|
|
59
|
+
*
|
|
60
|
+
* @throws
|
|
61
|
+
*/
|
|
15
62
|
export function accountsToUpdateForTrade(inf: Inf, arg1: PkPair): Bs58Array[];
|
|
63
|
+
/**
|
|
64
|
+
* @throws
|
|
65
|
+
*/
|
|
16
66
|
export function updateForTrade(inf: Inf, arg1: PkPair, arg2: AccountMap): void;
|
|
17
67
|
export interface TradeArgs {
|
|
18
68
|
amt: bigint;
|
|
@@ -22,6 +72,15 @@ export interface TradeArgs {
|
|
|
22
72
|
tokenAccs: PkPair;
|
|
23
73
|
}
|
|
24
74
|
|
|
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
|
+
|
|
25
84
|
export interface AccountMeta {
|
|
26
85
|
address: B58PK;
|
|
27
86
|
/**
|
|
@@ -40,42 +99,6 @@ export interface Instruction {
|
|
|
40
99
|
programAddress: B58PK;
|
|
41
100
|
}
|
|
42
101
|
|
|
43
|
-
export type FoundPda = [B58PK, number];
|
|
44
|
-
|
|
45
|
-
export interface Account {
|
|
46
|
-
data: Uint8Array;
|
|
47
|
-
owner: B58PK;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Map of `mint: stake pool account` for spl (all deploys) LSTs.
|
|
52
|
-
*
|
|
53
|
-
* This data is required to determine how to properly initialize the corresponding
|
|
54
|
-
* sol value calculator data since which stake pool account corresponds to which mint
|
|
55
|
-
* is not available onchain (yet)
|
|
56
|
-
*/
|
|
57
|
-
export type SplPoolAccounts = Map<B58PK, B58PK>;
|
|
58
|
-
|
|
59
|
-
export type AccountMap = Map<B58PK, Account>;
|
|
60
|
-
|
|
61
|
-
export type B58PK = Bs58Array;
|
|
62
|
-
|
|
63
|
-
export interface Pair<T> {
|
|
64
|
-
inp: T;
|
|
65
|
-
out: T;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export type PkPair = Pair<B58PK>;
|
|
69
|
-
|
|
70
|
-
export interface Init<T> {
|
|
71
|
-
poolState: T;
|
|
72
|
-
lstStateList: T;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export type InitPks = Init<B58PK>;
|
|
76
|
-
|
|
77
|
-
export type InitAccounts = Init<Account>;
|
|
78
|
-
|
|
79
102
|
export type FeeMint = "inp" | "out";
|
|
80
103
|
|
|
81
104
|
export interface QuoteArgs {
|
|
@@ -116,9 +139,89 @@ export interface Quote {
|
|
|
116
139
|
mints: PkPair;
|
|
117
140
|
}
|
|
118
141
|
|
|
142
|
+
export interface Account {
|
|
143
|
+
data: Uint8Array;
|
|
144
|
+
owner: B58PK;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Map of `mint: stake pool account` for spl (all deploys) LSTs.
|
|
149
|
+
*
|
|
150
|
+
* This data is required to determine how to properly initialize the corresponding
|
|
151
|
+
* sol value calculator data since which stake pool account corresponds to which mint
|
|
152
|
+
* is not available onchain (yet)
|
|
153
|
+
*/
|
|
154
|
+
export type SplPoolAccounts = Map<B58PK, B58PK>;
|
|
155
|
+
|
|
156
|
+
export type AccountMap = Map<B58PK, Account>;
|
|
157
|
+
|
|
158
|
+
export type B58PK = Bs58Array;
|
|
159
|
+
|
|
119
160
|
export type Bs58Array = string
|
|
120
161
|
|
|
121
162
|
export class Inf {
|
|
122
163
|
private constructor();
|
|
123
164
|
free(): void;
|
|
124
165
|
}
|
|
166
|
+
|
|
167
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
168
|
+
|
|
169
|
+
export interface InitOutput {
|
|
170
|
+
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];
|
|
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
|
+
readonly appendSplLsts: (a: number, b: any) => void;
|
|
180
|
+
readonly hasSplData: (a: number, b: number, c: number) => [number, number];
|
|
181
|
+
readonly accountsToUpdateForTrade: (a: number, b: any) => [number, number, number, number];
|
|
182
|
+
readonly updateForTrade: (a: number, b: any, c: any) => [number, number];
|
|
183
|
+
readonly __wbg_inf_free: (a: number, b: number) => void;
|
|
184
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
185
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
186
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
187
|
+
readonly __externref_table_alloc: () => number;
|
|
188
|
+
readonly __wbindgen_export_4: WebAssembly.Table;
|
|
189
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
190
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
191
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
192
|
+
readonly __wbindgen_start: () => void;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
196
|
+
/**
|
|
197
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
198
|
+
* a precompiled `WebAssembly.Module`.
|
|
199
|
+
*
|
|
200
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
201
|
+
*
|
|
202
|
+
* @returns {InitOutput}
|
|
203
|
+
*/
|
|
204
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
208
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
209
|
+
*
|
|
210
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
211
|
+
*
|
|
212
|
+
* @returns {Promise<InitOutput>}
|
|
213
|
+
*/
|
|
214
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Instantiates this `module` using the embedded
|
|
218
|
+
* {@link WASM_BIN_B64}. This is what works for nodejs envs.
|
|
219
|
+
*
|
|
220
|
+
* @returns {InitOutput}
|
|
221
|
+
*/
|
|
222
|
+
export function initSyncEmbed(): InitOutput;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Embedded base64-encoded wasm binary bytes
|
|
226
|
+
*/
|
|
227
|
+
export const WASM_BIN_B64: string;
|