@liquid-af/sdk 0.11.12 → 1.0.0

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 (47) 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/oracle.d.ts +0 -25
  30. package/dist/oracle.d.ts.map +1 -1
  31. package/dist/oracle.js +0 -32
  32. package/dist/oracle.js.map +1 -1
  33. package/dist/types.d.ts +9 -10
  34. package/dist/types.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/accounts/liquid.ts +4 -4
  37. package/src/client.ts +13 -23
  38. package/src/events/types.ts +4 -7
  39. package/src/helpers/preview.ts +20 -37
  40. package/src/idl/liquid.json +140 -397
  41. package/src/idl/liquid.ts +140 -397
  42. package/src/idl/liquid_events.json +3 -28
  43. package/src/idl/liquid_events.ts +3 -28
  44. package/src/instructions/index.ts +0 -2
  45. package/src/instructions/liquid.ts +22 -53
  46. package/src/oracle.ts +0 -43
  47. package/src/types.ts +9 -8
@@ -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