@liquid-af/sdk 0.5.9 → 0.6.1
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/events/types.d.ts +14 -13
- package/dist/events/types.d.ts.map +1 -1
- package/dist/idl/liquid.d.ts +2507 -2507
- package/dist/idl/liquid.d.ts.map +1 -1
- package/dist/idl/liquid.json +2507 -2507
- package/dist/idl/liquid_events.d.ts +58 -47
- package/dist/idl/liquid_events.d.ts.map +1 -1
- package/dist/idl/liquid_events.json +58 -47
- package/dist/idl/liquid_fees.d.ts +6 -6
- package/dist/idl/liquid_fees.json +6 -6
- 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 +1765 -801
- package/dist/idl/liquid_swap.d.ts.map +1 -1
- package/dist/idl/liquid_swap.json +1765 -801
- package/dist/instructions/index.d.ts +4 -4
- package/dist/instructions/index.d.ts.map +1 -1
- package/dist/instructions/index.js +3 -3
- package/dist/instructions/index.js.map +1 -1
- package/dist/instructions/liquid-swap.d.ts +40 -0
- package/dist/instructions/liquid-swap.d.ts.map +1 -1
- package/dist/instructions/liquid-swap.js +62 -0
- package/dist/instructions/liquid-swap.js.map +1 -1
- package/dist/instructions/liquid.d.ts +116 -0
- package/dist/instructions/liquid.d.ts.map +1 -1
- package/dist/instructions/liquid.js +176 -0
- package/dist/instructions/liquid.js.map +1 -1
- package/package.json +1 -1
- package/src/events/types.ts +17 -14
- package/src/idl/liquid.json +2507 -2507
- package/src/idl/liquid.ts +2507 -2507
- package/src/idl/liquid_events.json +58 -47
- package/src/idl/liquid_events.ts +58 -47
- package/src/idl/liquid_fees.json +6 -6
- package/src/idl/liquid_fees.ts +6 -6
- package/src/idl/liquid_state.json +72 -72
- package/src/idl/liquid_state.ts +72 -72
- package/src/idl/liquid_swap.json +1765 -801
- package/src/idl/liquid_swap.ts +1765 -801
- package/src/instructions/index.ts +16 -0
- package/src/instructions/liquid-swap.ts +144 -0
- package/src/instructions/liquid.ts +366 -0
|
@@ -5,6 +5,10 @@ export {
|
|
|
5
5
|
buildBuyNativeAutoResolve,
|
|
6
6
|
buildSellNative,
|
|
7
7
|
buildSellNativeAutoResolve,
|
|
8
|
+
buildBuyExactNative,
|
|
9
|
+
buildBuyExactNativeAutoResolve,
|
|
10
|
+
buildSellExactOutNative,
|
|
11
|
+
buildSellExactOutNativeAutoResolve,
|
|
8
12
|
buildMigrateNative,
|
|
9
13
|
buildInitializeNativeReferralVault,
|
|
10
14
|
buildWithdrawReferralRewards,
|
|
@@ -17,6 +21,10 @@ export {
|
|
|
17
21
|
buildBuyStableAutoResolve,
|
|
18
22
|
buildSellStable,
|
|
19
23
|
buildSellStableAutoResolve,
|
|
24
|
+
buildBuyExactStable,
|
|
25
|
+
buildBuyExactStableAutoResolve,
|
|
26
|
+
buildSellExactOutStable,
|
|
27
|
+
buildSellExactOutStableAutoResolve,
|
|
20
28
|
buildMigrateStable,
|
|
21
29
|
buildInitializeFeeRecipientVaults,
|
|
22
30
|
buildInitializeReferralTokenVault,
|
|
@@ -26,6 +34,8 @@ export type {
|
|
|
26
34
|
BuildBumpNativeParams,
|
|
27
35
|
BuildBuyNativeParams,
|
|
28
36
|
BuildSellNativeParams,
|
|
37
|
+
BuildBuyExactNativeParams,
|
|
38
|
+
BuildSellExactOutNativeParams,
|
|
29
39
|
BuildMigrateNativeParams,
|
|
30
40
|
BuildInitializeNativeReferralVaultParams,
|
|
31
41
|
BuildWithdrawReferralRewardsParams,
|
|
@@ -36,6 +46,8 @@ export type {
|
|
|
36
46
|
BuildCreateStableCurveParams,
|
|
37
47
|
BuildBuyStableParams,
|
|
38
48
|
BuildSellStableParams,
|
|
49
|
+
BuildBuyExactStableParams,
|
|
50
|
+
BuildSellExactOutStableParams,
|
|
39
51
|
BuildMigrateStableParams,
|
|
40
52
|
BuildInitializeFeeRecipientVaultsParams,
|
|
41
53
|
BuildInitializeReferralTokenVaultParams,
|
|
@@ -45,6 +57,8 @@ export {
|
|
|
45
57
|
buildCreatePool,
|
|
46
58
|
buildSwapBuy,
|
|
47
59
|
buildSwapSell,
|
|
60
|
+
buildSwapBuyExact,
|
|
61
|
+
buildSwapSellExactOut,
|
|
48
62
|
buildDeposit,
|
|
49
63
|
buildWithdraw,
|
|
50
64
|
buildSwapExecuteBuyback,
|
|
@@ -53,6 +67,8 @@ export type {
|
|
|
53
67
|
BuildCreatePoolParams,
|
|
54
68
|
BuildSwapBuyParams,
|
|
55
69
|
BuildSwapSellParams,
|
|
70
|
+
BuildSwapBuyExactParams,
|
|
71
|
+
BuildSwapSellExactOutParams,
|
|
56
72
|
BuildDepositParams,
|
|
57
73
|
BuildWithdrawParams,
|
|
58
74
|
BuildSwapExecuteBuybackParams,
|
|
@@ -214,6 +214,150 @@ export function buildSwapSell(
|
|
|
214
214
|
.instruction();
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
export interface BuildSwapBuyExactParams {
|
|
218
|
+
payer: PublicKey;
|
|
219
|
+
creator: PublicKey;
|
|
220
|
+
baseMint: PublicKey;
|
|
221
|
+
quoteMint: PublicKey;
|
|
222
|
+
baseTokenProgram: PublicKey;
|
|
223
|
+
quoteTokenProgram: PublicKey;
|
|
224
|
+
amountIn: BN;
|
|
225
|
+
minimumAmountOut: BN;
|
|
226
|
+
feeRecipient: PublicKey;
|
|
227
|
+
oraclePriceFeed?: PublicKey;
|
|
228
|
+
config: LiquidConfig;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Builds a buyExact swap instruction (exact quote input -> base output).
|
|
233
|
+
*
|
|
234
|
+
* @param params - {@link BuildSwapBuyExactParams}
|
|
235
|
+
* @returns Transaction instruction
|
|
236
|
+
*/
|
|
237
|
+
export function buildSwapBuyExact(
|
|
238
|
+
params: BuildSwapBuyExactParams,
|
|
239
|
+
): Promise<TransactionInstruction> {
|
|
240
|
+
const {
|
|
241
|
+
payer,
|
|
242
|
+
creator,
|
|
243
|
+
baseMint,
|
|
244
|
+
quoteMint,
|
|
245
|
+
baseTokenProgram,
|
|
246
|
+
quoteTokenProgram,
|
|
247
|
+
amountIn,
|
|
248
|
+
minimumAmountOut,
|
|
249
|
+
feeRecipient,
|
|
250
|
+
oraclePriceFeed,
|
|
251
|
+
config,
|
|
252
|
+
} = params;
|
|
253
|
+
|
|
254
|
+
const program = getCachedSwapProgram(config);
|
|
255
|
+
|
|
256
|
+
const baseTokenAccount = getAssociatedTokenAddressSync(
|
|
257
|
+
baseMint,
|
|
258
|
+
payer,
|
|
259
|
+
false,
|
|
260
|
+
baseTokenProgram,
|
|
261
|
+
);
|
|
262
|
+
const quoteTokenAccount = getAssociatedTokenAddressSync(
|
|
263
|
+
quoteMint,
|
|
264
|
+
payer,
|
|
265
|
+
false,
|
|
266
|
+
quoteTokenProgram,
|
|
267
|
+
);
|
|
268
|
+
return program.methods
|
|
269
|
+
.buyExact(amountIn, minimumAmountOut)
|
|
270
|
+
.accountsPartial({
|
|
271
|
+
payer,
|
|
272
|
+
creator,
|
|
273
|
+
baseTokenAccount,
|
|
274
|
+
quoteTokenAccount,
|
|
275
|
+
baseTokenProgram,
|
|
276
|
+
quoteTokenProgram,
|
|
277
|
+
baseMint,
|
|
278
|
+
quoteMint,
|
|
279
|
+
feeRecipient,
|
|
280
|
+
liquidState: {
|
|
281
|
+
user: payer,
|
|
282
|
+
tokenMint: baseMint,
|
|
283
|
+
},
|
|
284
|
+
...(oraclePriceFeed ? { oraclePriceFeed } : {}),
|
|
285
|
+
})
|
|
286
|
+
.instruction();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export interface BuildSwapSellExactOutParams {
|
|
290
|
+
payer: PublicKey;
|
|
291
|
+
creator: PublicKey;
|
|
292
|
+
baseMint: PublicKey;
|
|
293
|
+
quoteMint: PublicKey;
|
|
294
|
+
baseTokenProgram: PublicKey;
|
|
295
|
+
quoteTokenProgram: PublicKey;
|
|
296
|
+
maxAmountIn: BN;
|
|
297
|
+
exactAmountOut: BN;
|
|
298
|
+
feeRecipient: PublicKey;
|
|
299
|
+
oraclePriceFeed?: PublicKey;
|
|
300
|
+
config: LiquidConfig;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Builds a sellExactOut swap instruction (base input -> exact quote output).
|
|
305
|
+
*
|
|
306
|
+
* @param params - {@link BuildSwapSellExactOutParams}
|
|
307
|
+
* @returns Transaction instruction
|
|
308
|
+
*/
|
|
309
|
+
export function buildSwapSellExactOut(
|
|
310
|
+
params: BuildSwapSellExactOutParams,
|
|
311
|
+
): Promise<TransactionInstruction> {
|
|
312
|
+
const {
|
|
313
|
+
payer,
|
|
314
|
+
creator,
|
|
315
|
+
baseMint,
|
|
316
|
+
quoteMint,
|
|
317
|
+
baseTokenProgram,
|
|
318
|
+
quoteTokenProgram,
|
|
319
|
+
maxAmountIn,
|
|
320
|
+
exactAmountOut,
|
|
321
|
+
feeRecipient,
|
|
322
|
+
oraclePriceFeed,
|
|
323
|
+
config,
|
|
324
|
+
} = params;
|
|
325
|
+
|
|
326
|
+
const program = getCachedSwapProgram(config);
|
|
327
|
+
|
|
328
|
+
const baseTokenAccount = getAssociatedTokenAddressSync(
|
|
329
|
+
baseMint,
|
|
330
|
+
payer,
|
|
331
|
+
false,
|
|
332
|
+
baseTokenProgram,
|
|
333
|
+
);
|
|
334
|
+
const quoteTokenAccount = getAssociatedTokenAddressSync(
|
|
335
|
+
quoteMint,
|
|
336
|
+
payer,
|
|
337
|
+
false,
|
|
338
|
+
quoteTokenProgram,
|
|
339
|
+
);
|
|
340
|
+
return program.methods
|
|
341
|
+
.sellExactOut(maxAmountIn, exactAmountOut)
|
|
342
|
+
.accountsPartial({
|
|
343
|
+
payer,
|
|
344
|
+
creator,
|
|
345
|
+
baseTokenAccount,
|
|
346
|
+
quoteTokenAccount,
|
|
347
|
+
baseTokenProgram,
|
|
348
|
+
quoteTokenProgram,
|
|
349
|
+
baseMint,
|
|
350
|
+
quoteMint,
|
|
351
|
+
feeRecipient,
|
|
352
|
+
liquidState: {
|
|
353
|
+
user: payer,
|
|
354
|
+
tokenMint: baseMint,
|
|
355
|
+
},
|
|
356
|
+
...(oraclePriceFeed ? { oraclePriceFeed } : {}),
|
|
357
|
+
})
|
|
358
|
+
.instruction();
|
|
359
|
+
}
|
|
360
|
+
|
|
217
361
|
export interface BuildDepositParams {
|
|
218
362
|
owner: PublicKey;
|
|
219
363
|
poolAddress: PublicKey;
|
|
@@ -280,6 +280,176 @@ export async function buildSellNativeAutoResolve(
|
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
export interface BuildBuyExactNativeParams {
|
|
284
|
+
user: PublicKey;
|
|
285
|
+
mint: PublicKey;
|
|
286
|
+
creator: PublicKey;
|
|
287
|
+
pythPriceFeed: PublicKey;
|
|
288
|
+
exactAmountOut: BN;
|
|
289
|
+
maxAmountIn: BN;
|
|
290
|
+
feeRecipient: PublicKey;
|
|
291
|
+
creatorReferralVault?: PublicKey | null;
|
|
292
|
+
traderReferralVault?: PublicKey | null;
|
|
293
|
+
config: LiquidConfig;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Builds a buyExactNative instruction.
|
|
298
|
+
* Buys an exact amount of tokens from the bonding curve, paying SOL.
|
|
299
|
+
*
|
|
300
|
+
* @param params - {@link BuildBuyExactNativeParams}
|
|
301
|
+
* @returns Transaction instruction
|
|
302
|
+
*/
|
|
303
|
+
export function buildBuyExactNative(
|
|
304
|
+
params: BuildBuyExactNativeParams,
|
|
305
|
+
): Promise<TransactionInstruction> {
|
|
306
|
+
const {
|
|
307
|
+
user,
|
|
308
|
+
mint,
|
|
309
|
+
creator,
|
|
310
|
+
pythPriceFeed,
|
|
311
|
+
exactAmountOut,
|
|
312
|
+
maxAmountIn,
|
|
313
|
+
feeRecipient,
|
|
314
|
+
creatorReferralVault,
|
|
315
|
+
traderReferralVault,
|
|
316
|
+
config,
|
|
317
|
+
} = params;
|
|
318
|
+
|
|
319
|
+
const program = getCachedLiquidProgram(config);
|
|
320
|
+
|
|
321
|
+
const [creatorUserProperties] = getUserPropertiesPDA(
|
|
322
|
+
creator,
|
|
323
|
+
config.liquidStateProgramId,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
return program.methods
|
|
327
|
+
.buyExactNative(exactAmountOut, maxAmountIn)
|
|
328
|
+
.accountsPartial({
|
|
329
|
+
user,
|
|
330
|
+
feeRecipient,
|
|
331
|
+
mint,
|
|
332
|
+
pythPriceFeed,
|
|
333
|
+
creatorUserProperties,
|
|
334
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
335
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
336
|
+
liquidState: {
|
|
337
|
+
user,
|
|
338
|
+
tokenMint: mint,
|
|
339
|
+
},
|
|
340
|
+
})
|
|
341
|
+
.instruction();
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Builds a buyExactNative instruction, automatically fetching the bonding curve
|
|
346
|
+
* creator from chain. Convenience wrapper around `buildBuyExactNative`.
|
|
347
|
+
*
|
|
348
|
+
* @param connection - Solana RPC connection
|
|
349
|
+
* @param params - {@link BuildBuyExactNativeParams} without `creator`
|
|
350
|
+
* @returns Transaction instruction
|
|
351
|
+
*/
|
|
352
|
+
export async function buildBuyExactNativeAutoResolve(
|
|
353
|
+
connection: Connection,
|
|
354
|
+
params: Omit<BuildBuyExactNativeParams, "creator">,
|
|
355
|
+
): Promise<TransactionInstruction> {
|
|
356
|
+
const curve = await fetchNativeBondingCurve(
|
|
357
|
+
connection,
|
|
358
|
+
params.mint,
|
|
359
|
+
params.config,
|
|
360
|
+
);
|
|
361
|
+
return buildBuyExactNative({
|
|
362
|
+
...params,
|
|
363
|
+
creator: curve.creator,
|
|
364
|
+
pythPriceFeed: params.pythPriceFeed,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface BuildSellExactOutNativeParams {
|
|
369
|
+
user: PublicKey;
|
|
370
|
+
mint: PublicKey;
|
|
371
|
+
creator: PublicKey;
|
|
372
|
+
pythPriceFeed: PublicKey;
|
|
373
|
+
exactAmountOut: BN;
|
|
374
|
+
maxAmountIn: BN;
|
|
375
|
+
feeRecipient: PublicKey;
|
|
376
|
+
creatorReferralVault?: PublicKey | null;
|
|
377
|
+
traderReferralVault?: PublicKey | null;
|
|
378
|
+
config: LiquidConfig;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Builds a sellExactOutNative instruction.
|
|
383
|
+
* Sells tokens to receive an exact amount of SOL from the bonding curve.
|
|
384
|
+
*
|
|
385
|
+
* @param params - {@link BuildSellExactOutNativeParams}
|
|
386
|
+
* @returns Transaction instruction
|
|
387
|
+
*/
|
|
388
|
+
export function buildSellExactOutNative(
|
|
389
|
+
params: BuildSellExactOutNativeParams,
|
|
390
|
+
): Promise<TransactionInstruction> {
|
|
391
|
+
const {
|
|
392
|
+
user,
|
|
393
|
+
mint,
|
|
394
|
+
creator,
|
|
395
|
+
pythPriceFeed,
|
|
396
|
+
exactAmountOut,
|
|
397
|
+
maxAmountIn,
|
|
398
|
+
feeRecipient,
|
|
399
|
+
creatorReferralVault,
|
|
400
|
+
traderReferralVault,
|
|
401
|
+
config,
|
|
402
|
+
} = params;
|
|
403
|
+
|
|
404
|
+
const program = getCachedLiquidProgram(config);
|
|
405
|
+
|
|
406
|
+
const [creatorUserProperties] = getUserPropertiesPDA(
|
|
407
|
+
creator,
|
|
408
|
+
config.liquidStateProgramId,
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
return program.methods
|
|
412
|
+
.sellExactOutNative(exactAmountOut, maxAmountIn)
|
|
413
|
+
.accountsPartial({
|
|
414
|
+
user,
|
|
415
|
+
feeRecipient,
|
|
416
|
+
mint,
|
|
417
|
+
pythPriceFeed,
|
|
418
|
+
creatorUserProperties,
|
|
419
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
420
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
421
|
+
liquidState: {
|
|
422
|
+
user,
|
|
423
|
+
tokenMint: mint,
|
|
424
|
+
},
|
|
425
|
+
})
|
|
426
|
+
.instruction();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Builds a sellExactOutNative instruction, automatically fetching the bonding curve
|
|
431
|
+
* creator from chain. Convenience wrapper around `buildSellExactOutNative`.
|
|
432
|
+
*
|
|
433
|
+
* @param connection - Solana RPC connection
|
|
434
|
+
* @param params - {@link BuildSellExactOutNativeParams} without `creator`
|
|
435
|
+
* @returns Transaction instruction
|
|
436
|
+
*/
|
|
437
|
+
export async function buildSellExactOutNativeAutoResolve(
|
|
438
|
+
connection: Connection,
|
|
439
|
+
params: Omit<BuildSellExactOutNativeParams, "creator">,
|
|
440
|
+
): Promise<TransactionInstruction> {
|
|
441
|
+
const curve = await fetchNativeBondingCurve(
|
|
442
|
+
connection,
|
|
443
|
+
params.mint,
|
|
444
|
+
params.config,
|
|
445
|
+
);
|
|
446
|
+
return buildSellExactOutNative({
|
|
447
|
+
...params,
|
|
448
|
+
creator: curve.creator,
|
|
449
|
+
pythPriceFeed: params.pythPriceFeed,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
283
453
|
export interface BuildMigrateNativeParams {
|
|
284
454
|
migrator: PublicKey;
|
|
285
455
|
mint: PublicKey;
|
|
@@ -752,6 +922,202 @@ export async function buildSellStableAutoResolve(
|
|
|
752
922
|
return buildSellStable({ ...params, creator: curve.creator });
|
|
753
923
|
}
|
|
754
924
|
|
|
925
|
+
export interface BuildBuyExactStableParams {
|
|
926
|
+
user: PublicKey;
|
|
927
|
+
mint: PublicKey;
|
|
928
|
+
quoteMint: PublicKey;
|
|
929
|
+
creator: PublicKey;
|
|
930
|
+
exactAmountOut: BN;
|
|
931
|
+
maxAmountIn: BN;
|
|
932
|
+
feeRecipient: PublicKey;
|
|
933
|
+
creatorReferralVault?: PublicKey | null;
|
|
934
|
+
traderReferralVault?: PublicKey | null;
|
|
935
|
+
config: LiquidConfig;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Builds a buyExactStable instruction.
|
|
940
|
+
* Buys an exact amount of tokens from a token-based bonding curve using quote tokens.
|
|
941
|
+
*
|
|
942
|
+
* @param params - {@link BuildBuyExactStableParams}
|
|
943
|
+
* @returns Transaction instruction
|
|
944
|
+
*/
|
|
945
|
+
export function buildBuyExactStable(
|
|
946
|
+
params: BuildBuyExactStableParams,
|
|
947
|
+
): Promise<TransactionInstruction> {
|
|
948
|
+
const {
|
|
949
|
+
user,
|
|
950
|
+
mint,
|
|
951
|
+
quoteMint,
|
|
952
|
+
creator,
|
|
953
|
+
exactAmountOut,
|
|
954
|
+
maxAmountIn,
|
|
955
|
+
feeRecipient,
|
|
956
|
+
creatorReferralVault,
|
|
957
|
+
traderReferralVault,
|
|
958
|
+
config,
|
|
959
|
+
} = params;
|
|
960
|
+
|
|
961
|
+
const program = getCachedLiquidProgram(config);
|
|
962
|
+
|
|
963
|
+
const feeRecipientQuoteAccount = getAssociatedTokenAddressSync(
|
|
964
|
+
quoteMint,
|
|
965
|
+
feeRecipient,
|
|
966
|
+
true,
|
|
967
|
+
TOKEN_PROGRAM_ID,
|
|
968
|
+
);
|
|
969
|
+
|
|
970
|
+
const [creatorUserProperties] = getUserPropertiesPDA(
|
|
971
|
+
creator,
|
|
972
|
+
config.liquidStateProgramId,
|
|
973
|
+
);
|
|
974
|
+
|
|
975
|
+
const [bondingCurve] = getStableBondingCurvePDA(
|
|
976
|
+
mint,
|
|
977
|
+
config.liquidProgramId,
|
|
978
|
+
);
|
|
979
|
+
const [buybackVault] = getBuybackVaultPDA(
|
|
980
|
+
bondingCurve,
|
|
981
|
+
config.liquidProgramId,
|
|
982
|
+
);
|
|
983
|
+
|
|
984
|
+
return program.methods
|
|
985
|
+
.buyExactStable(exactAmountOut, maxAmountIn)
|
|
986
|
+
.accountsPartial({
|
|
987
|
+
user,
|
|
988
|
+
mint,
|
|
989
|
+
quoteMint,
|
|
990
|
+
feeRecipient: feeRecipientQuoteAccount,
|
|
991
|
+
creatorUserProperties,
|
|
992
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
993
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
994
|
+
buybackVault,
|
|
995
|
+
liquidState: {
|
|
996
|
+
user,
|
|
997
|
+
tokenMint: mint,
|
|
998
|
+
},
|
|
999
|
+
})
|
|
1000
|
+
.instruction();
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Builds a buyExactStable instruction, automatically fetching the bonding curve
|
|
1005
|
+
* creator from chain. Convenience wrapper around `buildBuyExactStable`.
|
|
1006
|
+
*
|
|
1007
|
+
* @param connection - Solana RPC connection
|
|
1008
|
+
* @param params - {@link BuildBuyExactStableParams} without `creator`
|
|
1009
|
+
* @returns Transaction instruction
|
|
1010
|
+
*/
|
|
1011
|
+
export async function buildBuyExactStableAutoResolve(
|
|
1012
|
+
connection: Connection,
|
|
1013
|
+
params: Omit<BuildBuyExactStableParams, "creator">,
|
|
1014
|
+
): Promise<TransactionInstruction> {
|
|
1015
|
+
const curve = await fetchStableBondingCurve(
|
|
1016
|
+
connection,
|
|
1017
|
+
params.mint,
|
|
1018
|
+
params.config,
|
|
1019
|
+
);
|
|
1020
|
+
return buildBuyExactStable({ ...params, creator: curve.creator });
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
export interface BuildSellExactOutStableParams {
|
|
1024
|
+
user: PublicKey;
|
|
1025
|
+
mint: PublicKey;
|
|
1026
|
+
quoteMint: PublicKey;
|
|
1027
|
+
creator: PublicKey;
|
|
1028
|
+
exactAmountOut: BN;
|
|
1029
|
+
maxAmountIn: BN;
|
|
1030
|
+
feeRecipient: PublicKey;
|
|
1031
|
+
creatorReferralVault?: PublicKey | null;
|
|
1032
|
+
traderReferralVault?: PublicKey | null;
|
|
1033
|
+
config: LiquidConfig;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Builds a sellExactOutStable instruction.
|
|
1038
|
+
* Sells tokens to receive an exact amount of quote tokens from a token-based bonding curve.
|
|
1039
|
+
*
|
|
1040
|
+
* @param params - {@link BuildSellExactOutStableParams}
|
|
1041
|
+
* @returns Transaction instruction
|
|
1042
|
+
*/
|
|
1043
|
+
export function buildSellExactOutStable(
|
|
1044
|
+
params: BuildSellExactOutStableParams,
|
|
1045
|
+
): Promise<TransactionInstruction> {
|
|
1046
|
+
const {
|
|
1047
|
+
user,
|
|
1048
|
+
mint,
|
|
1049
|
+
quoteMint,
|
|
1050
|
+
creator,
|
|
1051
|
+
exactAmountOut,
|
|
1052
|
+
maxAmountIn,
|
|
1053
|
+
feeRecipient,
|
|
1054
|
+
creatorReferralVault,
|
|
1055
|
+
traderReferralVault,
|
|
1056
|
+
config,
|
|
1057
|
+
} = params;
|
|
1058
|
+
|
|
1059
|
+
const program = getCachedLiquidProgram(config);
|
|
1060
|
+
|
|
1061
|
+
const feeRecipientQuoteAccount = getAssociatedTokenAddressSync(
|
|
1062
|
+
quoteMint,
|
|
1063
|
+
feeRecipient,
|
|
1064
|
+
true,
|
|
1065
|
+
TOKEN_PROGRAM_ID,
|
|
1066
|
+
);
|
|
1067
|
+
|
|
1068
|
+
const [creatorUserProperties] = getUserPropertiesPDA(
|
|
1069
|
+
creator,
|
|
1070
|
+
config.liquidStateProgramId,
|
|
1071
|
+
);
|
|
1072
|
+
|
|
1073
|
+
const [bondingCurve] = getStableBondingCurvePDA(
|
|
1074
|
+
mint,
|
|
1075
|
+
config.liquidProgramId,
|
|
1076
|
+
);
|
|
1077
|
+
const [buybackVault] = getBuybackVaultPDA(
|
|
1078
|
+
bondingCurve,
|
|
1079
|
+
config.liquidProgramId,
|
|
1080
|
+
);
|
|
1081
|
+
|
|
1082
|
+
return program.methods
|
|
1083
|
+
.sellExactOutStable(exactAmountOut, maxAmountIn)
|
|
1084
|
+
.accountsPartial({
|
|
1085
|
+
user,
|
|
1086
|
+
mint,
|
|
1087
|
+
quoteMint,
|
|
1088
|
+
feeRecipient: feeRecipientQuoteAccount,
|
|
1089
|
+
creatorUserProperties,
|
|
1090
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
1091
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
1092
|
+
buybackVault,
|
|
1093
|
+
liquidState: {
|
|
1094
|
+
user,
|
|
1095
|
+
tokenMint: mint,
|
|
1096
|
+
},
|
|
1097
|
+
})
|
|
1098
|
+
.instruction();
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* Builds a sellExactOutStable instruction, automatically fetching the bonding curve
|
|
1103
|
+
* creator from chain. Convenience wrapper around `buildSellExactOutStable`.
|
|
1104
|
+
*
|
|
1105
|
+
* @param connection - Solana RPC connection
|
|
1106
|
+
* @param params - {@link BuildSellExactOutStableParams} without `creator`
|
|
1107
|
+
* @returns Transaction instruction
|
|
1108
|
+
*/
|
|
1109
|
+
export async function buildSellExactOutStableAutoResolve(
|
|
1110
|
+
connection: Connection,
|
|
1111
|
+
params: Omit<BuildSellExactOutStableParams, "creator">,
|
|
1112
|
+
): Promise<TransactionInstruction> {
|
|
1113
|
+
const curve = await fetchStableBondingCurve(
|
|
1114
|
+
connection,
|
|
1115
|
+
params.mint,
|
|
1116
|
+
params.config,
|
|
1117
|
+
);
|
|
1118
|
+
return buildSellExactOutStable({ ...params, creator: curve.creator });
|
|
1119
|
+
}
|
|
1120
|
+
|
|
755
1121
|
export interface BuildMigrateStableParams {
|
|
756
1122
|
migrator: PublicKey;
|
|
757
1123
|
mint: PublicKey;
|