@liquid-af/sdk 0.11.12 → 1.0.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.
Files changed (57) hide show
  1. package/dist/accounts/liquid.d.ts +18 -24
  2. package/dist/accounts/liquid.d.ts.map +1 -1
  3. package/dist/accounts/liquid.js +4 -4
  4. package/dist/accounts/liquid.js.map +1 -1
  5. package/dist/client.d.ts +31 -43
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +5 -9
  8. package/dist/client.js.map +1 -1
  9. package/dist/events/types.d.ts +4 -7
  10. package/dist/events/types.d.ts.map +1 -1
  11. package/dist/helpers/preview.d.ts +7 -19
  12. package/dist/helpers/preview.d.ts.map +1 -1
  13. package/dist/helpers/preview.js +13 -18
  14. package/dist/helpers/preview.js.map +1 -1
  15. package/dist/idl/liquid.d.ts +139 -396
  16. package/dist/idl/liquid.d.ts.map +1 -1
  17. package/dist/idl/liquid.json +140 -397
  18. package/dist/idl/liquid_events.d.ts +3 -28
  19. package/dist/idl/liquid_events.d.ts.map +1 -1
  20. package/dist/idl/liquid_events.json +3 -28
  21. package/dist/instructions/index.d.ts +2 -2
  22. package/dist/instructions/index.d.ts.map +1 -1
  23. package/dist/instructions/index.js +1 -1
  24. package/dist/instructions/index.js.map +1 -1
  25. package/dist/instructions/liquid.d.ts +7 -22
  26. package/dist/instructions/liquid.d.ts.map +1 -1
  27. package/dist/instructions/liquid.js +13 -37
  28. package/dist/instructions/liquid.js.map +1 -1
  29. package/dist/math/index.d.ts +1 -0
  30. package/dist/math/index.d.ts.map +1 -1
  31. package/dist/math/index.js +1 -0
  32. package/dist/math/index.js.map +1 -1
  33. package/dist/math/market-cap.d.ts +42 -0
  34. package/dist/math/market-cap.d.ts.map +1 -0
  35. package/dist/math/market-cap.js +55 -0
  36. package/dist/math/market-cap.js.map +1 -0
  37. package/dist/oracle.d.ts +0 -40
  38. package/dist/oracle.d.ts.map +1 -1
  39. package/dist/oracle.js +0 -55
  40. package/dist/oracle.js.map +1 -1
  41. package/dist/types.d.ts +9 -10
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/src/accounts/liquid.ts +4 -4
  45. package/src/client.ts +13 -23
  46. package/src/events/types.ts +4 -7
  47. package/src/helpers/preview.ts +20 -37
  48. package/src/idl/liquid.json +140 -397
  49. package/src/idl/liquid.ts +140 -397
  50. package/src/idl/liquid_events.json +3 -28
  51. package/src/idl/liquid_events.ts +3 -28
  52. package/src/instructions/index.ts +0 -2
  53. package/src/instructions/liquid.ts +22 -53
  54. package/src/math/index.ts +6 -0
  55. package/src/math/market-cap.ts +70 -0
  56. package/src/oracle.ts +0 -70
  57. package/src/types.ts +9 -8
package/src/client.ts CHANGED
@@ -20,7 +20,6 @@ import {
20
20
  // Instruction builders
21
21
  import {
22
22
  buildCreateNativeCurve,
23
- buildBumpNative,
24
23
  buildBuyExactInNative,
25
24
  buildBuyExactInNativeAutoResolve,
26
25
  buildSellExactInNative,
@@ -155,7 +154,6 @@ export class LiquidClient {
155
154
  buildCreateNativeCurve(params: {
156
155
  creator: PublicKey;
157
156
  mint: PublicKey;
158
- pythPriceFeed: PublicKey;
159
157
  name: string;
160
158
  symbol: string;
161
159
  uri: string;
@@ -163,17 +161,17 @@ export class LiquidClient {
163
161
  return buildCreateNativeCurve({ ...params, config: this.config });
164
162
  }
165
163
 
166
- /** Builds a buyNative instruction. Requires the creator address and Pyth price feed. */
164
+ /** Builds a buyNative instruction. Requires the creator address. */
167
165
  buildBuyExactInNative(params: {
168
166
  user: PublicKey;
169
167
  mint: PublicKey;
170
168
  creator: PublicKey;
171
- pythPriceFeed: PublicKey;
172
169
  amountIn: BN;
173
170
  minAmountOut: BN;
174
171
  feeRecipient: PublicKey;
175
172
  creatorReferralVault?: PublicKey | null;
176
173
  traderReferralVault?: PublicKey | null;
174
+ pythPriceFeed?: PublicKey;
177
175
  }): Promise<TransactionInstruction> {
178
176
  return buildBuyExactInNative({ ...params, config: this.config });
179
177
  }
@@ -184,12 +182,12 @@ export class LiquidClient {
184
182
  buildBuyExactInNativeAutoResolve(params: {
185
183
  user: PublicKey;
186
184
  mint: PublicKey;
187
- pythPriceFeed: PublicKey;
188
185
  amountIn: BN;
189
186
  minAmountOut: BN;
190
187
  feeRecipient: PublicKey;
191
188
  creatorReferralVault?: PublicKey | null;
192
189
  traderReferralVault?: PublicKey | null;
190
+ pythPriceFeed?: PublicKey;
193
191
  }): Promise<TransactionInstruction> {
194
192
  return buildBuyExactInNativeAutoResolve(this.connection, {
195
193
  ...params,
@@ -197,17 +195,17 @@ export class LiquidClient {
197
195
  });
198
196
  }
199
197
 
200
- /** Builds a sellNative instruction. Requires the creator address and Pyth price feed. */
198
+ /** Builds a sellNative instruction. Requires the creator address. */
201
199
  buildSellExactInNative(params: {
202
200
  user: PublicKey;
203
201
  mint: PublicKey;
204
202
  creator: PublicKey;
205
- pythPriceFeed: PublicKey;
206
203
  amountIn: BN;
207
204
  minAmountOut: BN;
208
205
  feeRecipient: PublicKey;
209
206
  creatorReferralVault?: PublicKey | null;
210
207
  traderReferralVault?: PublicKey | null;
208
+ pythPriceFeed?: PublicKey;
211
209
  }): Promise<TransactionInstruction> {
212
210
  return buildSellExactInNative({ ...params, config: this.config });
213
211
  }
@@ -218,12 +216,12 @@ export class LiquidClient {
218
216
  buildSellExactInNativeAutoResolve(params: {
219
217
  user: PublicKey;
220
218
  mint: PublicKey;
221
- pythPriceFeed: PublicKey;
222
219
  amountIn: BN;
223
220
  minAmountOut: BN;
224
221
  feeRecipient: PublicKey;
225
222
  creatorReferralVault?: PublicKey | null;
226
223
  traderReferralVault?: PublicKey | null;
224
+ pythPriceFeed?: PublicKey;
227
225
  }): Promise<TransactionInstruction> {
228
226
  return buildSellExactInNativeAutoResolve(this.connection, {
229
227
  ...params,
@@ -236,12 +234,12 @@ export class LiquidClient {
236
234
  user: PublicKey;
237
235
  mint: PublicKey;
238
236
  creator: PublicKey;
239
- pythPriceFeed: PublicKey;
240
237
  exactAmountOut: BN;
241
238
  maxAmountIn: BN;
242
239
  feeRecipient: PublicKey;
243
240
  creatorReferralVault?: PublicKey | null;
244
241
  traderReferralVault?: PublicKey | null;
242
+ pythPriceFeed?: PublicKey;
245
243
  }): Promise<TransactionInstruction> {
246
244
  return buildBuyExactOutNative({ ...params, config: this.config });
247
245
  }
@@ -250,12 +248,12 @@ export class LiquidClient {
250
248
  buildBuyExactOutNativeAutoResolve(params: {
251
249
  user: PublicKey;
252
250
  mint: PublicKey;
253
- pythPriceFeed: PublicKey;
254
251
  exactAmountOut: BN;
255
252
  maxAmountIn: BN;
256
253
  feeRecipient: PublicKey;
257
254
  creatorReferralVault?: PublicKey | null;
258
255
  traderReferralVault?: PublicKey | null;
256
+ pythPriceFeed?: PublicKey;
259
257
  }): Promise<TransactionInstruction> {
260
258
  return buildBuyExactOutNativeAutoResolve(this.connection, {
261
259
  ...params,
@@ -268,12 +266,12 @@ export class LiquidClient {
268
266
  user: PublicKey;
269
267
  mint: PublicKey;
270
268
  creator: PublicKey;
271
- pythPriceFeed: PublicKey;
272
269
  exactAmountOut: BN;
273
270
  maxAmountIn: BN;
274
271
  feeRecipient: PublicKey;
275
272
  creatorReferralVault?: PublicKey | null;
276
273
  traderReferralVault?: PublicKey | null;
274
+ pythPriceFeed?: PublicKey;
277
275
  }): Promise<TransactionInstruction> {
278
276
  return buildSellExactOutNative({ ...params, config: this.config });
279
277
  }
@@ -282,12 +280,12 @@ export class LiquidClient {
282
280
  buildSellExactOutNativeAutoResolve(params: {
283
281
  user: PublicKey;
284
282
  mint: PublicKey;
285
- pythPriceFeed: PublicKey;
286
283
  exactAmountOut: BN;
287
284
  maxAmountIn: BN;
288
285
  feeRecipient: PublicKey;
289
286
  creatorReferralVault?: PublicKey | null;
290
287
  traderReferralVault?: PublicKey | null;
288
+ pythPriceFeed?: PublicKey;
291
289
  }): Promise<TransactionInstruction> {
292
290
  return buildSellExactOutNativeAutoResolve(this.connection, {
293
291
  ...params,
@@ -335,7 +333,7 @@ export class LiquidClient {
335
333
  buildExecuteBuybackNative(params: {
336
334
  payer: PublicKey;
337
335
  mint: PublicKey;
338
- pythPriceFeed: PublicKey;
336
+ pythPriceFeed?: PublicKey;
339
337
  }): Promise<TransactionInstruction> {
340
338
  return buildExecuteBuybackNative({ ...params, config: this.config });
341
339
  }
@@ -349,14 +347,6 @@ export class LiquidClient {
349
347
  return buildExecuteBuybackToken({ ...params, config: this.config });
350
348
  }
351
349
 
352
- /** Builds a bumpNative instruction. Re-evaluates a native curve's market cap against the oracle. */
353
- buildBumpNative(params: {
354
- mint: PublicKey;
355
- pythPriceFeed: PublicKey;
356
- }): Promise<TransactionInstruction> {
357
- return buildBumpNative({ ...params, config: this.config });
358
- }
359
-
360
350
  /** Builds a createStableCurve instruction for launching a new token on a quote-token bonding curve. */
361
351
  buildCreateStableCurve(params: {
362
352
  creator: PublicKey;
@@ -1078,7 +1068,7 @@ export class LiquidClient {
1078
1068
  *
1079
1069
  * @param mint - Token mint address
1080
1070
  * @param amountInQuote - Quote token amount to spend (lamports for SOL, smallest unit for stables)
1081
- * @param options - Native (`{ solPriceUsd }`) or stable (`{ quoteMint }`) curve options
1071
+ * @param options - Native (`{}`) or stable (`{ quoteMint }`) curve options
1082
1072
  * @returns Buy preview with `tokensOut`, `fees`, `priceImpactBps`, `newReserves`, and `willComplete`
1083
1073
  */
1084
1074
  previewBuyOnCurve(
@@ -1100,7 +1090,7 @@ export class LiquidClient {
1100
1090
  *
1101
1091
  * @param mint - Token mint address
1102
1092
  * @param amountInTokens - Token amount to sell (smallest unit, 6 decimals)
1103
- * @param options - Native (`{ solPriceUsd }`) or stable (`{ quoteMint }`) curve options
1093
+ * @param options - Native (`{}`) or stable (`{ quoteMint }`) curve options
1104
1094
  * @returns Sell preview with `quoteOut`, `quoteOutNet`, `fees`, `priceImpactBps`, and `newReserves`
1105
1095
  */
1106
1096
  previewSellOnCurve(
@@ -12,12 +12,11 @@ export interface TokenCreatedEvent {
12
12
  bondingCurve: PublicKey;
13
13
  creator: PublicKey;
14
14
  creatorReferrer: PublicKey | null;
15
- initialVirtualReserveUsd: BN;
15
+ initialVirtualReserves: BN;
16
16
  initialVirtualTokenReserves: BN;
17
17
  initialRealTokenReserves: BN;
18
18
  totalTokenSupply: BN;
19
19
  tokenProgram: PublicKey;
20
- solPriceUsd: BN | null;
21
20
  timestamp: BN;
22
21
  }
23
22
 
@@ -64,13 +63,13 @@ export interface TradeEvent {
64
63
  virtualQuoteReserves: BN;
65
64
  realTokenReserves: BN;
66
65
  realQuoteReserves: BN;
67
- totalQuoteVolume: BN;
66
+ totalUsdVolume: BN;
68
67
  totalTokenVolume: BN;
69
- timestamp: BN;
70
- solPriceUsd: BN | null;
71
68
  marketCapUsd: BN;
69
+ solPriceUsd: BN | null;
72
70
  buybackVaultBalance: BN;
73
71
  isCurveComplete: boolean;
72
+ timestamp: BN;
74
73
  }
75
74
 
76
75
  /** Event emitted after a successful migration to AMM */
@@ -87,8 +86,6 @@ export interface MigrationCompletedEvent {
87
86
  multiplier: number;
88
87
  lpMint: PublicKey;
89
88
  lpTokensMinted: BN;
90
- marketCapUsd: BN;
91
- solPriceUsd: BN | null;
92
89
  buybackAmountMigrated: BN;
93
90
  }
94
91
 
@@ -18,7 +18,6 @@ import {
18
18
  } from "../math/bonding-curve.js";
19
19
  import { calculateAmmSellOutput, calculateAmmBuyInput } from "../math/amm.js";
20
20
  import { BPS_DENOMINATOR } from "../math/constants.js";
21
- import { calculateInitialVirtualSolReserves } from "../oracle.js";
22
21
  import { getAccount, getMint } from "@solana/spl-token";
23
22
  import { calculateFeesForPool } from "../math/tiered-fees.js";
24
23
 
@@ -83,27 +82,23 @@ export interface CurvePreviewOptions {
83
82
  * fetched automatically from chain.
84
83
  */
85
84
  export interface CurvePrefetchedState {
86
- /**
87
- * Fee configuration from the global config account.
88
- * `initialVirtualReserveUsd` is required to compute virtual quote reserves.
89
- */
85
+ /** Fee configuration from the global config account. */
90
86
  globalConfig?: {
91
87
  protocolFeeBasisPoints: number;
92
88
  creatorFeeBasisPoints: number;
93
89
  creatorReferralRewardBasisPoints: number;
94
90
  traderReferralRewardBasisPoints: number;
95
- initialVirtualReserveUsd?: BN;
96
91
  };
97
92
  /**
98
93
  * Bonding curve reserves.
99
- * Virtual quote reserves are always recomputed as
100
- * `initialVirtualReserveUsd + realQuoteReserves` (with oracle conversion
101
- * for native curves).
94
+ * Virtual quote = `initialVirtualQuoteReserves + realQuoteReserves`.
95
+ * Both native and stable curves store `initialVirtualQuoteReserves` directly.
102
96
  */
103
97
  bondingCurve?: {
104
98
  realQuoteReserves: BN;
105
99
  virtualTokenReserves: BN;
106
100
  realTokenReserves: BN;
101
+ initialVirtualQuoteReserves: BN;
107
102
  };
108
103
  }
109
104
 
@@ -120,13 +115,10 @@ interface CurveOptionsBase {
120
115
  /**
121
116
  * Options for native SOL bonding curve previews.
122
117
  *
123
- * Requires `solPriceUsd` to compute virtual SOL reserves from the on-chain
124
- * USD-denominated initial reserve value.
118
+ * Virtual SOL reserves are stored directly on-chain — no oracle needed.
125
119
  */
126
120
  export interface NativeCurveOptions extends CurveOptionsBase {
127
121
  quoteMint?: never;
128
- /** Current SOL price in USD (6 decimals, e.g. 150_000_000 = $150). */
129
- solPriceUsd: BN;
130
122
  }
131
123
 
132
124
  /**
@@ -137,7 +129,6 @@ export interface NativeCurveOptions extends CurveOptionsBase {
137
129
  export interface StableCurveOptions extends CurveOptionsBase {
138
130
  /** Quote token mint address (e.g. USDC mint). */
139
131
  quoteMint: PublicKey;
140
- solPriceUsd?: never;
141
132
  }
142
133
 
143
134
  /**
@@ -377,21 +368,18 @@ export function calculateSwapSellPreview(
377
368
  *
378
369
  * @param connection - Solana RPC connection
379
370
  * @param config - Liquid protocol configuration (provides the program ID)
380
- * @returns Fee basis-point fields plus `initialVirtualReserveUsd` for native reserve computation
371
+ * @returns Fee basis-point fields for preview calculations
381
372
  */
382
373
  async function fetchCurveGlobalConfig(
383
374
  connection: Connection,
384
375
  config: LiquidConfig,
385
- ): Promise<
386
- CurvePreviewState["globalConfig"] & { initialVirtualReserveUsd: BN }
387
- > {
376
+ ): Promise<CurvePreviewState["globalConfig"]> {
388
377
  const raw = await fetchLiquidGlobalConfig(connection, config);
389
378
  return {
390
379
  protocolFeeBasisPoints: raw.protocolFeeBasisPoints,
391
380
  creatorFeeBasisPoints: raw.creatorFeeBasisPoints,
392
381
  creatorReferralRewardBasisPoints: raw.creatorReferralRewardBasisPoints,
393
382
  traderReferralRewardBasisPoints: raw.traderReferralRewardBasisPoints,
394
- initialVirtualReserveUsd: raw.initialVirtualReserveUsd,
395
383
  };
396
384
  }
397
385
 
@@ -399,12 +387,12 @@ async function fetchCurveGlobalConfig(
399
387
  * Resolves {@link CurvePreviewState} for native SOL curves.
400
388
  *
401
389
  * Fetches the global config and native bonding curve in parallel (skipping
402
- * any that are prefetched), then computes `virtualQuoteReserves` from
403
- * `initialVirtualReserveUsd` and `solPriceUsd`.
390
+ * any that are prefetched), then computes `virtualQuoteReserves` from the
391
+ * stored `initialVirtualQuoteReserves` + `realQuoteReserves`.
404
392
  *
405
393
  * @param connection - Solana RPC connection
406
394
  * @param mint - Token mint address of the native bonding curve
407
- * @param options - Native curve options containing `solPriceUsd` and optional `prefetched` state
395
+ * @param options - Native curve options with optional `prefetched` state
408
396
  * @param config - Liquid protocol configuration
409
397
  * @returns Resolved curve preview state ready for pure-math preview calculations
410
398
  */
@@ -424,20 +412,18 @@ async function resolveNativeCurve(
424
412
  ]);
425
413
 
426
414
  const src = pre?.bondingCurve ?? {
427
- realQuoteReserves: nativeCurve!.realSolReserves,
415
+ realQuoteReserves: nativeCurve!.realQuoteReserves,
428
416
  virtualTokenReserves: nativeCurve!.virtualTokenReserves,
429
417
  realTokenReserves: nativeCurve!.realTokenReserves,
418
+ initialVirtualQuoteReserves: nativeCurve!.initialVirtualQuoteReserves,
430
419
  };
431
420
 
432
- const initialVirtualSolReserves = calculateInitialVirtualSolReserves(
433
- BigInt(globalConfig.initialVirtualReserveUsd!.toString()),
434
- BigInt(options.solPriceUsd.toString()),
421
+ const virtualQuoteReserves = src.initialVirtualQuoteReserves.add(
422
+ src.realQuoteReserves,
435
423
  );
436
- const virtualSolReserves =
437
- initialVirtualSolReserves + BigInt(src.realQuoteReserves.toString());
438
424
 
439
425
  const bondingCurve = {
440
- virtualQuoteReserves: new BN(virtualSolReserves.toString()),
426
+ virtualQuoteReserves,
441
427
  virtualTokenReserves: src.virtualTokenReserves,
442
428
  realTokenReserves: src.realTokenReserves,
443
429
  };
@@ -450,7 +436,7 @@ async function resolveNativeCurve(
450
436
  *
451
437
  * Fetches the global config and stable bonding curve in parallel (skipping
452
438
  * any that are prefetched). Virtual quote reserves are computed as
453
- * `initialVirtualReserveUsd + realQuoteReserves`.
439
+ * `initialVirtualQuoteReserves + realQuoteReserves`.
454
440
  *
455
441
  * @param connection - Solana RPC connection
456
442
  * @param mint - Token mint address of the stable bonding curve
@@ -477,9 +463,10 @@ async function resolveStableCurve(
477
463
  realQuoteReserves: stableCurve!.realQuoteReserves,
478
464
  virtualTokenReserves: stableCurve!.virtualTokenReserves,
479
465
  realTokenReserves: stableCurve!.realTokenReserves,
466
+ initialVirtualQuoteReserves: stableCurve!.initialVirtualQuoteReserves,
480
467
  };
481
468
 
482
- const virtualQuoteReserves = globalConfig.initialVirtualReserveUsd!.add(
469
+ const virtualQuoteReserves = src.initialVirtualQuoteReserves.add(
483
470
  src.realQuoteReserves,
484
471
  );
485
472
 
@@ -540,9 +527,7 @@ function resolveCurveState(
540
527
  *
541
528
  * @example Native SOL curve
542
529
  * ```ts
543
- * const preview = await previewBuyOnCurve(connection, mint, new BN(100_000_000), config, {
544
- * solPriceUsd: new BN(150_000_000), // $150
545
- * });
530
+ * const preview = await previewBuyOnCurve(connection, mint, new BN(100_000_000), config, {});
546
531
  * ```
547
532
  *
548
533
  * @example Stable (USDC) curve
@@ -583,9 +568,7 @@ export async function previewBuyOnCurve(
583
568
  *
584
569
  * @example Native SOL curve
585
570
  * ```ts
586
- * const preview = await previewSellOnCurve(connection, mint, new BN(5_000_000), config, {
587
- * solPriceUsd: new BN(150_000_000),
588
- * });
571
+ * const preview = await previewSellOnCurve(connection, mint, new BN(5_000_000), config, {});
589
572
  * ```
590
573
  *
591
574
  * @see {@link calculateSellCurvePreview} for pure offline calculations with pre-built state