@liquid-af/sdk 0.11.6 → 0.11.8
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/dist/client.d.ts +5 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -0
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -2
- package/dist/config.js.map +1 -1
- package/dist/idl/liquid.d.ts +2490 -2490
- package/dist/idl/liquid.d.ts.map +1 -1
- package/dist/idl/liquid.json +2490 -2490
- package/dist/idl/liquid_events.d.ts +1 -1
- package/dist/idl/liquid_events.json +1 -1
- package/dist/idl/liquid_fees.d.ts +8 -8
- package/dist/idl/liquid_fees.json +8 -8
- package/dist/idl/liquid_state.d.ts +72 -72
- package/dist/idl/liquid_state.d.ts.map +1 -1
- package/dist/idl/liquid_state.json +72 -72
- package/dist/idl/liquid_swap.d.ts +998 -998
- package/dist/idl/liquid_swap.d.ts.map +1 -1
- package/dist/idl/liquid_swap.json +998 -998
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lut.d.ts +71 -5
- package/dist/lut.d.ts.map +1 -1
- package/dist/lut.js +139 -9
- package/dist/lut.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +22 -0
- package/src/config.ts +6 -2
- package/src/idl/liquid.json +2490 -2490
- package/src/idl/liquid.ts +2490 -2490
- package/src/idl/liquid_events.json +1 -1
- package/src/idl/liquid_events.ts +1 -1
- package/src/idl/liquid_fees.json +8 -8
- package/src/idl/liquid_fees.ts +8 -8
- package/src/idl/liquid_state.json +72 -72
- package/src/idl/liquid_state.ts +72 -72
- package/src/idl/liquid_swap.json +998 -998
- package/src/idl/liquid_swap.ts +998 -998
- package/src/index.ts +1 -0
- package/src/lut.ts +290 -6
package/src/index.ts
CHANGED
package/src/lut.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AddressLookupTableProgram,
|
|
2
3
|
ComputeBudgetProgram,
|
|
3
4
|
PublicKey,
|
|
5
|
+
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
4
6
|
SystemProgram,
|
|
5
7
|
type Connection,
|
|
6
8
|
type AddressLookupTableAccount,
|
|
9
|
+
type TransactionInstruction,
|
|
7
10
|
} from "@solana/web3.js";
|
|
8
11
|
import {
|
|
9
12
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
10
13
|
TOKEN_2022_PROGRAM_ID,
|
|
11
14
|
TOKEN_PROGRAM_ID,
|
|
15
|
+
getAssociatedTokenAddressSync,
|
|
12
16
|
} from "@solana/spl-token";
|
|
13
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
type LiquidConfig,
|
|
19
|
+
REFERRER_COSIGNER,
|
|
20
|
+
WSOL_MINT,
|
|
21
|
+
} from "./config.js";
|
|
14
22
|
import {
|
|
15
23
|
getSwapAuthorityPDA,
|
|
16
24
|
getSwapGlobalConfigPDA,
|
|
@@ -19,8 +27,22 @@ import {
|
|
|
19
27
|
getGlobalAmmVolumePDA,
|
|
20
28
|
getGlobalCurveVolumePDA,
|
|
21
29
|
getCashbackConfigPDA,
|
|
30
|
+
getUserPropertiesPDA,
|
|
31
|
+
getTokenVolumePDA,
|
|
22
32
|
} from "./pda/liquid-state.js";
|
|
23
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
getLiquidGlobalConfigPDA,
|
|
35
|
+
getBondingCurvePDA,
|
|
36
|
+
getBondingCurveSolVaultPDA,
|
|
37
|
+
getBuybackVaultPDA,
|
|
38
|
+
getBondingCurveTokenAccount,
|
|
39
|
+
getStableBondingCurvePDA,
|
|
40
|
+
} from "./pda/liquid.js";
|
|
41
|
+
import {
|
|
42
|
+
getFeeConfigPDA,
|
|
43
|
+
getFeeVaultPDA,
|
|
44
|
+
getFeeGlobalConfigPDA
|
|
45
|
+
} from "./pda/liquid-fees.js";
|
|
24
46
|
import { fetchAmmConfig } from "./accounts/liquid-swap.js";
|
|
25
47
|
|
|
26
48
|
const SEED_CPI_AUTHORITY = Buffer.from("cpi_authority");
|
|
@@ -37,17 +59,18 @@ function getCpiAuthorityPDA(programId: PublicKey): PublicKey {
|
|
|
37
59
|
}
|
|
38
60
|
|
|
39
61
|
/**
|
|
40
|
-
* Returns the
|
|
62
|
+
* Returns the 26 account addresses for the global LUT.
|
|
41
63
|
*
|
|
42
|
-
* Programs (
|
|
64
|
+
* Programs (10): System, SPL Token, Token-2022, ATA, ComputeBudget, Liquid, State, Events, Fees, Swap
|
|
43
65
|
* Liquid PDAs (2): global_config, cpi_authority
|
|
44
66
|
* Swap PDAs (3): authority, global_config, cpi_authority
|
|
45
67
|
* State PDAs (4): global_amm_volume, global_curve_volume, cashback_config, cpi_authority
|
|
46
|
-
*
|
|
68
|
+
* Fees PDAs (2): global_config, cpi_authority
|
|
69
|
+
* Constants (5): WSOL mint, oracle price feed, instructions sysvar, referrer cosigner, USDC mint
|
|
47
70
|
*
|
|
48
71
|
* @param config - Liquid protocol configuration
|
|
49
72
|
* @param connection - Solana RPC connection (for fetching oracle price feed)
|
|
50
|
-
* @returns Array of
|
|
73
|
+
* @returns Array of 26 public keys to populate the LUT
|
|
51
74
|
*/
|
|
52
75
|
export async function getLutAccounts(
|
|
53
76
|
config: LiquidConfig,
|
|
@@ -79,6 +102,12 @@ export async function getLutAccounts(
|
|
|
79
102
|
const [cashbackConfig] = getCashbackConfigPDA(config.liquidStateProgramId);
|
|
80
103
|
const stateCpiAuthority = getCpiAuthorityPDA(config.liquidStateProgramId);
|
|
81
104
|
|
|
105
|
+
// Fees PDAs
|
|
106
|
+
const [feeGlobalConfig] = getFeeGlobalConfigPDA(
|
|
107
|
+
config.liquidFeesProgramId,
|
|
108
|
+
);
|
|
109
|
+
const feesCpiAuthority = getCpiAuthorityPDA(config.liquidFeesProgramId);
|
|
110
|
+
|
|
82
111
|
return [
|
|
83
112
|
// Programs
|
|
84
113
|
SystemProgram.programId,
|
|
@@ -86,6 +115,7 @@ export async function getLutAccounts(
|
|
|
86
115
|
TOKEN_2022_PROGRAM_ID,
|
|
87
116
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
88
117
|
ComputeBudgetProgram.programId,
|
|
118
|
+
config.liquidProgramId,
|
|
89
119
|
config.liquidStateProgramId,
|
|
90
120
|
config.liquidEventsProgramId,
|
|
91
121
|
config.liquidFeesProgramId,
|
|
@@ -102,9 +132,15 @@ export async function getLutAccounts(
|
|
|
102
132
|
globalCurveVolume,
|
|
103
133
|
cashbackConfig,
|
|
104
134
|
stateCpiAuthority,
|
|
135
|
+
// Fees global PDAs
|
|
136
|
+
feeGlobalConfig,
|
|
137
|
+
feesCpiAuthority,
|
|
105
138
|
// Constants
|
|
106
139
|
WSOL_MINT,
|
|
107
140
|
oraclePriceFeed,
|
|
141
|
+
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
142
|
+
REFERRER_COSIGNER,
|
|
143
|
+
config.usdcMint,
|
|
108
144
|
];
|
|
109
145
|
}
|
|
110
146
|
|
|
@@ -121,4 +157,252 @@ export async function fetchLut(
|
|
|
121
157
|
): Promise<AddressLookupTableAccount | null> {
|
|
122
158
|
const result = await connection.getAddressLookupTable(lutAddress);
|
|
123
159
|
return result.value;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface GetNativeTokenLutAccountsParams {
|
|
163
|
+
/** Token mint address */
|
|
164
|
+
mint: PublicKey;
|
|
165
|
+
/** Trading user's public key */
|
|
166
|
+
user: PublicKey;
|
|
167
|
+
/** Bonding curve creator's public key */
|
|
168
|
+
creator: PublicKey;
|
|
169
|
+
/** Protocol configuration */
|
|
170
|
+
config: LiquidConfig;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Returns the per-token + per-user addresses for a native (SOL) bonding curve LUT.
|
|
175
|
+
* These supplement the global LUT — no global accounts are included.
|
|
176
|
+
*
|
|
177
|
+
* Token PDAs (9): mint, bondingCurve, solVault, buybackVault, bondingCurveTokenAccount,
|
|
178
|
+
* feeConfig, feeVault, feeVaultTokenAccount, tokenVolume
|
|
179
|
+
* User PDAs (3): userProperties, creatorUserProperties, userTokenAccount
|
|
180
|
+
*/
|
|
181
|
+
export function getNativeTokenLutAccounts(
|
|
182
|
+
params: GetNativeTokenLutAccountsParams,
|
|
183
|
+
): PublicKey[] {
|
|
184
|
+
const { mint, user, creator, config } = params;
|
|
185
|
+
|
|
186
|
+
// Token PDAs
|
|
187
|
+
const [bondingCurve] = getBondingCurvePDA(mint, config.liquidProgramId);
|
|
188
|
+
const [solVault] = getBondingCurveSolVaultPDA(
|
|
189
|
+
bondingCurve,
|
|
190
|
+
config.liquidProgramId,
|
|
191
|
+
);
|
|
192
|
+
const [buybackVault] = getBuybackVaultPDA(
|
|
193
|
+
bondingCurve,
|
|
194
|
+
config.liquidProgramId,
|
|
195
|
+
);
|
|
196
|
+
const bondingCurveTokenAccount = getBondingCurveTokenAccount(
|
|
197
|
+
mint,
|
|
198
|
+
config.liquidProgramId,
|
|
199
|
+
);
|
|
200
|
+
const [feeConfig] = getFeeConfigPDA(
|
|
201
|
+
mint,
|
|
202
|
+
WSOL_MINT,
|
|
203
|
+
config.liquidFeesProgramId,
|
|
204
|
+
);
|
|
205
|
+
const [feeVault] = getFeeVaultPDA(feeConfig, config.liquidFeesProgramId);
|
|
206
|
+
const feeVaultTokenAccount = getAssociatedTokenAddressSync(
|
|
207
|
+
WSOL_MINT,
|
|
208
|
+
feeVault,
|
|
209
|
+
true,
|
|
210
|
+
TOKEN_PROGRAM_ID,
|
|
211
|
+
);
|
|
212
|
+
const [tokenVolume] = getTokenVolumePDA(mint, config.liquidStateProgramId);
|
|
213
|
+
|
|
214
|
+
// User PDAs
|
|
215
|
+
const [userProperties] = getUserPropertiesPDA(
|
|
216
|
+
user,
|
|
217
|
+
config.liquidStateProgramId,
|
|
218
|
+
);
|
|
219
|
+
const [creatorUserProperties] = getUserPropertiesPDA(
|
|
220
|
+
creator,
|
|
221
|
+
config.liquidStateProgramId,
|
|
222
|
+
);
|
|
223
|
+
const userTokenAccount = getAssociatedTokenAddressSync(
|
|
224
|
+
mint,
|
|
225
|
+
user,
|
|
226
|
+
true,
|
|
227
|
+
TOKEN_2022_PROGRAM_ID,
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
return [
|
|
231
|
+
// Token PDAs
|
|
232
|
+
mint,
|
|
233
|
+
bondingCurve,
|
|
234
|
+
solVault,
|
|
235
|
+
buybackVault,
|
|
236
|
+
bondingCurveTokenAccount,
|
|
237
|
+
feeConfig,
|
|
238
|
+
feeVault,
|
|
239
|
+
feeVaultTokenAccount,
|
|
240
|
+
tokenVolume,
|
|
241
|
+
// User PDAs
|
|
242
|
+
userProperties,
|
|
243
|
+
creatorUserProperties,
|
|
244
|
+
userTokenAccount,
|
|
245
|
+
];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface GetStableTokenLutAccountsParams {
|
|
249
|
+
/** Token mint address */
|
|
250
|
+
mint: PublicKey;
|
|
251
|
+
/** Quote token mint address (e.g. USDC) */
|
|
252
|
+
quoteMint: PublicKey;
|
|
253
|
+
/** Trading user's public key */
|
|
254
|
+
user: PublicKey;
|
|
255
|
+
/** Bonding curve creator's public key */
|
|
256
|
+
creator: PublicKey;
|
|
257
|
+
/** Protocol configuration */
|
|
258
|
+
config: LiquidConfig;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Returns the per-token + per-user addresses for a stable (quote token) bonding curve LUT.
|
|
263
|
+
* These supplement the global LUT — no global accounts are included.
|
|
264
|
+
*
|
|
265
|
+
* Token PDAs (10): mint, quoteMint, bondingCurve, bondingCurveQuoteVault,
|
|
266
|
+
* bondingCurveTokenAccount, buybackVault, feeConfig, feeVault, feeVaultTokenAccount, tokenVolume
|
|
267
|
+
* User PDAs (4): userProperties, creatorUserProperties, userTokenAccount, userQuoteAccount
|
|
268
|
+
*/
|
|
269
|
+
export function getStableTokenLutAccounts(
|
|
270
|
+
params: GetStableTokenLutAccountsParams,
|
|
271
|
+
): PublicKey[] {
|
|
272
|
+
const { mint, quoteMint, user, creator, config } = params;
|
|
273
|
+
|
|
274
|
+
// Token PDAs
|
|
275
|
+
const [bondingCurve] = getStableBondingCurvePDA(
|
|
276
|
+
mint,
|
|
277
|
+
config.liquidProgramId,
|
|
278
|
+
);
|
|
279
|
+
const bondingCurveQuoteVault = getAssociatedTokenAddressSync(
|
|
280
|
+
quoteMint,
|
|
281
|
+
bondingCurve,
|
|
282
|
+
true,
|
|
283
|
+
TOKEN_PROGRAM_ID,
|
|
284
|
+
);
|
|
285
|
+
const bondingCurveTokenAccount = getAssociatedTokenAddressSync(
|
|
286
|
+
mint,
|
|
287
|
+
bondingCurve,
|
|
288
|
+
true,
|
|
289
|
+
TOKEN_2022_PROGRAM_ID,
|
|
290
|
+
);
|
|
291
|
+
const [buybackVault] = getBuybackVaultPDA(
|
|
292
|
+
bondingCurve,
|
|
293
|
+
config.liquidProgramId,
|
|
294
|
+
);
|
|
295
|
+
const [feeConfig] = getFeeConfigPDA(
|
|
296
|
+
mint,
|
|
297
|
+
quoteMint,
|
|
298
|
+
config.liquidFeesProgramId,
|
|
299
|
+
);
|
|
300
|
+
const [feeVault] = getFeeVaultPDA(feeConfig, config.liquidFeesProgramId);
|
|
301
|
+
const feeVaultTokenAccount = getAssociatedTokenAddressSync(
|
|
302
|
+
quoteMint,
|
|
303
|
+
feeVault,
|
|
304
|
+
true,
|
|
305
|
+
TOKEN_PROGRAM_ID,
|
|
306
|
+
);
|
|
307
|
+
const [tokenVolume] = getTokenVolumePDA(mint, config.liquidStateProgramId);
|
|
308
|
+
|
|
309
|
+
// User PDAs
|
|
310
|
+
const [userProperties] = getUserPropertiesPDA(
|
|
311
|
+
user,
|
|
312
|
+
config.liquidStateProgramId,
|
|
313
|
+
);
|
|
314
|
+
const [creatorUserProperties] = getUserPropertiesPDA(
|
|
315
|
+
creator,
|
|
316
|
+
config.liquidStateProgramId,
|
|
317
|
+
);
|
|
318
|
+
const userTokenAccount = getAssociatedTokenAddressSync(
|
|
319
|
+
mint,
|
|
320
|
+
user,
|
|
321
|
+
true,
|
|
322
|
+
TOKEN_2022_PROGRAM_ID,
|
|
323
|
+
);
|
|
324
|
+
const userQuoteAccount = getAssociatedTokenAddressSync(
|
|
325
|
+
quoteMint,
|
|
326
|
+
user,
|
|
327
|
+
true,
|
|
328
|
+
TOKEN_PROGRAM_ID,
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
return [
|
|
332
|
+
// Token PDAs
|
|
333
|
+
mint,
|
|
334
|
+
bondingCurve,
|
|
335
|
+
bondingCurveQuoteVault,
|
|
336
|
+
bondingCurveTokenAccount,
|
|
337
|
+
buybackVault,
|
|
338
|
+
feeConfig,
|
|
339
|
+
feeVault,
|
|
340
|
+
feeVaultTokenAccount,
|
|
341
|
+
tokenVolume,
|
|
342
|
+
// User PDAs
|
|
343
|
+
userProperties,
|
|
344
|
+
creatorUserProperties,
|
|
345
|
+
userTokenAccount,
|
|
346
|
+
userQuoteAccount,
|
|
347
|
+
];
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface BuildCreateTokenLutParams {
|
|
351
|
+
/** Solana RPC connection (to fetch a recent slot) */
|
|
352
|
+
connection: Connection;
|
|
353
|
+
/** Payer/authority public key for the LUT */
|
|
354
|
+
payer: PublicKey;
|
|
355
|
+
/** Addresses to populate the LUT with */
|
|
356
|
+
addresses: PublicKey[];
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface CreateTokenLutResult {
|
|
360
|
+
/** The derived LUT address */
|
|
361
|
+
lutAddress: PublicKey;
|
|
362
|
+
/** Create + extend instructions to include in a transaction */
|
|
363
|
+
instructions: TransactionInstruction[];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Builds instructions to create an Address Lookup Table and populate it
|
|
368
|
+
* with the given addresses. Handles deduplication.
|
|
369
|
+
*
|
|
370
|
+
* The caller is responsible for including these instructions in a transaction,
|
|
371
|
+
* signing, and sending. The LUT must be active for at least 1 slot before
|
|
372
|
+
* it can be used in subsequent transactions.
|
|
373
|
+
*
|
|
374
|
+
* @returns The derived LUT address and the instructions to create + extend it
|
|
375
|
+
*/
|
|
376
|
+
export async function buildCreateTokenLut(
|
|
377
|
+
params: BuildCreateTokenLutParams,
|
|
378
|
+
): Promise<CreateTokenLutResult> {
|
|
379
|
+
const { connection, payer, addresses } = params;
|
|
380
|
+
|
|
381
|
+
// Deduplicate addresses
|
|
382
|
+
const seen = new Set<string>();
|
|
383
|
+
const unique: PublicKey[] = [];
|
|
384
|
+
for (const addr of addresses) {
|
|
385
|
+
const key = addr.toBase58();
|
|
386
|
+
if (!seen.has(key)) {
|
|
387
|
+
seen.add(key);
|
|
388
|
+
unique.push(addr);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const slot = await connection.getSlot();
|
|
393
|
+
|
|
394
|
+
const [createIx, lutAddress] = AddressLookupTableProgram.createLookupTable({
|
|
395
|
+
authority: payer,
|
|
396
|
+
payer,
|
|
397
|
+
recentSlot: slot,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const extendIx = AddressLookupTableProgram.extendLookupTable({
|
|
401
|
+
lookupTable: lutAddress,
|
|
402
|
+
authority: payer,
|
|
403
|
+
payer,
|
|
404
|
+
addresses: unique,
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
return { lutAddress, instructions: [createIx, extendIx] };
|
|
124
408
|
}
|