@liquid-af/sdk 0.11.11 → 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 (63) 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 +6 -10
  8. package/dist/client.js.map +1 -1
  9. package/dist/events/parser.d.ts.map +1 -1
  10. package/dist/events/parser.js.map +1 -1
  11. package/dist/events/types.d.ts +4 -7
  12. package/dist/events/types.d.ts.map +1 -1
  13. package/dist/helpers/cashback.d.ts +1 -1
  14. package/dist/helpers/cashback.d.ts.map +1 -1
  15. package/dist/helpers/cashback.js +2 -3
  16. package/dist/helpers/cashback.js.map +1 -1
  17. package/dist/helpers/preview.d.ts +8 -20
  18. package/dist/helpers/preview.d.ts.map +1 -1
  19. package/dist/helpers/preview.js +26 -19
  20. package/dist/helpers/preview.js.map +1 -1
  21. package/dist/idl/liquid.d.ts +139 -396
  22. package/dist/idl/liquid.d.ts.map +1 -1
  23. package/dist/idl/liquid.json +140 -397
  24. package/dist/idl/liquid_events.d.ts +3 -28
  25. package/dist/idl/liquid_events.d.ts.map +1 -1
  26. package/dist/idl/liquid_events.json +3 -28
  27. package/dist/instructions/index.d.ts +2 -2
  28. package/dist/instructions/index.d.ts.map +1 -1
  29. package/dist/instructions/index.js +1 -1
  30. package/dist/instructions/index.js.map +1 -1
  31. package/dist/instructions/liquid.d.ts +7 -22
  32. package/dist/instructions/liquid.d.ts.map +1 -1
  33. package/dist/instructions/liquid.js +13 -37
  34. package/dist/instructions/liquid.js.map +1 -1
  35. package/dist/lut.d.ts.map +1 -1
  36. package/dist/lut.js +2 -2
  37. package/dist/lut.js.map +1 -1
  38. package/dist/math/cashback.d.ts.map +1 -1
  39. package/dist/math/cashback.js +3 -1
  40. package/dist/math/cashback.js.map +1 -1
  41. package/dist/oracle.d.ts +0 -28
  42. package/dist/oracle.d.ts.map +1 -1
  43. package/dist/oracle.js +0 -35
  44. package/dist/oracle.js.map +1 -1
  45. package/dist/types.d.ts +9 -10
  46. package/dist/types.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/accounts/liquid.ts +4 -4
  49. package/src/client.ts +14 -29
  50. package/src/events/parser.ts +12 -20
  51. package/src/events/types.ts +4 -7
  52. package/src/helpers/cashback.ts +12 -5
  53. package/src/helpers/preview.ts +41 -40
  54. package/src/idl/liquid.json +140 -397
  55. package/src/idl/liquid.ts +140 -397
  56. package/src/idl/liquid_events.json +3 -28
  57. package/src/idl/liquid_events.ts +3 -28
  58. package/src/instructions/index.ts +0 -2
  59. package/src/instructions/liquid.ts +22 -53
  60. package/src/lut.ts +4 -10
  61. package/src/math/cashback.ts +3 -1
  62. package/src/oracle.ts +0 -46
  63. 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,
@@ -113,11 +112,7 @@ import {
113
112
  } from "./helpers/preview.js";
114
113
 
115
114
  // PDA helpers (used internally by buildDeposit/buildWithdraw)
116
- import {
117
- getPoolPDA,
118
- getPoolLpMintPDA,
119
- getPoolVaultPDA,
120
- } from "./pda/index.js";
115
+ import { getPoolPDA, getPoolLpMintPDA, getPoolVaultPDA } from "./pda/index.js";
121
116
 
122
117
  // Utility
123
118
  import { resolveTokenProgram as resolveTokenProgramFn } from "./helpers/user.js";
@@ -159,7 +154,6 @@ export class LiquidClient {
159
154
  buildCreateNativeCurve(params: {
160
155
  creator: PublicKey;
161
156
  mint: PublicKey;
162
- pythPriceFeed: PublicKey;
163
157
  name: string;
164
158
  symbol: string;
165
159
  uri: string;
@@ -167,17 +161,17 @@ export class LiquidClient {
167
161
  return buildCreateNativeCurve({ ...params, config: this.config });
168
162
  }
169
163
 
170
- /** Builds a buyNative instruction. Requires the creator address and Pyth price feed. */
164
+ /** Builds a buyNative instruction. Requires the creator address. */
171
165
  buildBuyExactInNative(params: {
172
166
  user: PublicKey;
173
167
  mint: PublicKey;
174
168
  creator: PublicKey;
175
- pythPriceFeed: PublicKey;
176
169
  amountIn: BN;
177
170
  minAmountOut: BN;
178
171
  feeRecipient: PublicKey;
179
172
  creatorReferralVault?: PublicKey | null;
180
173
  traderReferralVault?: PublicKey | null;
174
+ pythPriceFeed?: PublicKey;
181
175
  }): Promise<TransactionInstruction> {
182
176
  return buildBuyExactInNative({ ...params, config: this.config });
183
177
  }
@@ -188,12 +182,12 @@ export class LiquidClient {
188
182
  buildBuyExactInNativeAutoResolve(params: {
189
183
  user: PublicKey;
190
184
  mint: PublicKey;
191
- pythPriceFeed: PublicKey;
192
185
  amountIn: BN;
193
186
  minAmountOut: BN;
194
187
  feeRecipient: PublicKey;
195
188
  creatorReferralVault?: PublicKey | null;
196
189
  traderReferralVault?: PublicKey | null;
190
+ pythPriceFeed?: PublicKey;
197
191
  }): Promise<TransactionInstruction> {
198
192
  return buildBuyExactInNativeAutoResolve(this.connection, {
199
193
  ...params,
@@ -201,17 +195,17 @@ export class LiquidClient {
201
195
  });
202
196
  }
203
197
 
204
- /** Builds a sellNative instruction. Requires the creator address and Pyth price feed. */
198
+ /** Builds a sellNative instruction. Requires the creator address. */
205
199
  buildSellExactInNative(params: {
206
200
  user: PublicKey;
207
201
  mint: PublicKey;
208
202
  creator: PublicKey;
209
- pythPriceFeed: PublicKey;
210
203
  amountIn: BN;
211
204
  minAmountOut: BN;
212
205
  feeRecipient: PublicKey;
213
206
  creatorReferralVault?: PublicKey | null;
214
207
  traderReferralVault?: PublicKey | null;
208
+ pythPriceFeed?: PublicKey;
215
209
  }): Promise<TransactionInstruction> {
216
210
  return buildSellExactInNative({ ...params, config: this.config });
217
211
  }
@@ -222,12 +216,12 @@ export class LiquidClient {
222
216
  buildSellExactInNativeAutoResolve(params: {
223
217
  user: PublicKey;
224
218
  mint: PublicKey;
225
- pythPriceFeed: PublicKey;
226
219
  amountIn: BN;
227
220
  minAmountOut: BN;
228
221
  feeRecipient: PublicKey;
229
222
  creatorReferralVault?: PublicKey | null;
230
223
  traderReferralVault?: PublicKey | null;
224
+ pythPriceFeed?: PublicKey;
231
225
  }): Promise<TransactionInstruction> {
232
226
  return buildSellExactInNativeAutoResolve(this.connection, {
233
227
  ...params,
@@ -240,12 +234,12 @@ export class LiquidClient {
240
234
  user: PublicKey;
241
235
  mint: PublicKey;
242
236
  creator: PublicKey;
243
- pythPriceFeed: PublicKey;
244
237
  exactAmountOut: BN;
245
238
  maxAmountIn: BN;
246
239
  feeRecipient: PublicKey;
247
240
  creatorReferralVault?: PublicKey | null;
248
241
  traderReferralVault?: PublicKey | null;
242
+ pythPriceFeed?: PublicKey;
249
243
  }): Promise<TransactionInstruction> {
250
244
  return buildBuyExactOutNative({ ...params, config: this.config });
251
245
  }
@@ -254,12 +248,12 @@ export class LiquidClient {
254
248
  buildBuyExactOutNativeAutoResolve(params: {
255
249
  user: PublicKey;
256
250
  mint: PublicKey;
257
- pythPriceFeed: PublicKey;
258
251
  exactAmountOut: BN;
259
252
  maxAmountIn: BN;
260
253
  feeRecipient: PublicKey;
261
254
  creatorReferralVault?: PublicKey | null;
262
255
  traderReferralVault?: PublicKey | null;
256
+ pythPriceFeed?: PublicKey;
263
257
  }): Promise<TransactionInstruction> {
264
258
  return buildBuyExactOutNativeAutoResolve(this.connection, {
265
259
  ...params,
@@ -272,12 +266,12 @@ export class LiquidClient {
272
266
  user: PublicKey;
273
267
  mint: PublicKey;
274
268
  creator: PublicKey;
275
- pythPriceFeed: PublicKey;
276
269
  exactAmountOut: BN;
277
270
  maxAmountIn: BN;
278
271
  feeRecipient: PublicKey;
279
272
  creatorReferralVault?: PublicKey | null;
280
273
  traderReferralVault?: PublicKey | null;
274
+ pythPriceFeed?: PublicKey;
281
275
  }): Promise<TransactionInstruction> {
282
276
  return buildSellExactOutNative({ ...params, config: this.config });
283
277
  }
@@ -286,12 +280,12 @@ export class LiquidClient {
286
280
  buildSellExactOutNativeAutoResolve(params: {
287
281
  user: PublicKey;
288
282
  mint: PublicKey;
289
- pythPriceFeed: PublicKey;
290
283
  exactAmountOut: BN;
291
284
  maxAmountIn: BN;
292
285
  feeRecipient: PublicKey;
293
286
  creatorReferralVault?: PublicKey | null;
294
287
  traderReferralVault?: PublicKey | null;
288
+ pythPriceFeed?: PublicKey;
295
289
  }): Promise<TransactionInstruction> {
296
290
  return buildSellExactOutNativeAutoResolve(this.connection, {
297
291
  ...params,
@@ -339,7 +333,7 @@ export class LiquidClient {
339
333
  buildExecuteBuybackNative(params: {
340
334
  payer: PublicKey;
341
335
  mint: PublicKey;
342
- pythPriceFeed: PublicKey;
336
+ pythPriceFeed?: PublicKey;
343
337
  }): Promise<TransactionInstruction> {
344
338
  return buildExecuteBuybackNative({ ...params, config: this.config });
345
339
  }
@@ -353,14 +347,6 @@ export class LiquidClient {
353
347
  return buildExecuteBuybackToken({ ...params, config: this.config });
354
348
  }
355
349
 
356
- /** Builds a bumpNative instruction. Re-evaluates a native curve's market cap against the oracle. */
357
- buildBumpNative(params: {
358
- mint: PublicKey;
359
- pythPriceFeed: PublicKey;
360
- }): Promise<TransactionInstruction> {
361
- return buildBumpNative({ ...params, config: this.config });
362
- }
363
-
364
350
  /** Builds a createStableCurve instruction for launching a new token on a quote-token bonding curve. */
365
351
  buildCreateStableCurve(params: {
366
352
  creator: PublicKey;
@@ -945,7 +931,6 @@ export class LiquidClient {
945
931
  return buildInitializeUser({ ...params, config: this.config });
946
932
  }
947
933
 
948
-
949
934
  /** Builds a setCashbackMode instruction. Toggles between earning and spending mode. */
950
935
  buildSetCashbackMode(params: {
951
936
  user: PublicKey;
@@ -1083,7 +1068,7 @@ export class LiquidClient {
1083
1068
  *
1084
1069
  * @param mint - Token mint address
1085
1070
  * @param amountInQuote - Quote token amount to spend (lamports for SOL, smallest unit for stables)
1086
- * @param options - Native (`{ solPriceUsd }`) or stable (`{ quoteMint }`) curve options
1071
+ * @param options - Native (`{}`) or stable (`{ quoteMint }`) curve options
1087
1072
  * @returns Buy preview with `tokensOut`, `fees`, `priceImpactBps`, `newReserves`, and `willComplete`
1088
1073
  */
1089
1074
  previewBuyOnCurve(
@@ -1105,7 +1090,7 @@ export class LiquidClient {
1105
1090
  *
1106
1091
  * @param mint - Token mint address
1107
1092
  * @param amountInTokens - Token amount to sell (smallest unit, 6 decimals)
1108
- * @param options - Native (`{ solPriceUsd }`) or stable (`{ quoteMint }`) curve options
1093
+ * @param options - Native (`{}`) or stable (`{ quoteMint }`) curve options
1109
1094
  * @returns Sell preview with `quoteOut`, `quoteOutNet`, `fees`, `priceImpactBps`, and `newReserves`
1110
1095
  */
1111
1096
  previewSellOnCurve(
@@ -12,14 +12,12 @@ export interface ParsedEvent<T = unknown> {
12
12
  /** Minimal transaction shape needed for event parsing. */
13
13
  export interface TransactionForEventParsing {
14
14
  meta: {
15
- innerInstructions?:
16
- | Array<{
17
- instructions: Array<{
18
- programIdIndex: number;
19
- data: string;
20
- }>;
21
- }>
22
- | null;
15
+ innerInstructions?: Array<{
16
+ instructions: Array<{
17
+ programIdIndex: number;
18
+ data: string;
19
+ }>;
20
+ }> | null;
23
21
  } | null;
24
22
  transaction: {
25
23
  message:
@@ -137,10 +135,7 @@ export const parseTransactionEvents = (
137
135
  * @returns Object containing the trigger result and the captured event data
138
136
  * @throws If the event is not received within the timeout period
139
137
  */
140
- export async function waitForEvent<
141
- N extends LiquidEventName,
142
- TResult = string,
143
- >(
138
+ export async function waitForEvent<N extends LiquidEventName, TResult = string>(
144
139
  program: Program<LiquidEvents>,
145
140
  eventName: N,
146
141
  trigger: () => Promise<TResult>,
@@ -151,13 +146,10 @@ export async function waitForEvent<
151
146
 
152
147
  // Subscribe to logs to capture the transaction signature
153
148
  // (invoke/exit logs are always present even without emit!)
154
- const subscriptionId = connection.onLogs(
155
- program.programId,
156
- (logInfo) => {
157
- if (logInfo.err) return;
158
- capturedSignature = logInfo.signature;
159
- },
160
- );
149
+ const subscriptionId = connection.onLogs(program.programId, (logInfo) => {
150
+ if (logInfo.err) return;
151
+ capturedSignature = logInfo.signature;
152
+ });
161
153
 
162
154
  try {
163
155
  const result = await trigger();
@@ -193,7 +185,7 @@ export async function waitForEvent<
193
185
  if (!event) {
194
186
  throw new Error(
195
187
  `Event '${eventName}' not found in transaction ${capturedSignature}. ` +
196
- `Found events: [${events.map((e) => e.name).join(", ")}]`,
188
+ `Found events: [${events.map((e) => e.name).join(", ")}]`,
197
189
  );
198
190
  }
199
191
 
@@ -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
 
@@ -1,9 +1,13 @@
1
1
  import type { Connection, PublicKey } from "@solana/web3.js";
2
2
  import type { LiquidConfig } from "../config.js";
3
- import type { CashbackBreakdown } from "../math/cashback.js";
4
- import { getCashbackBreakdown } from "../math/cashback.js";
5
- import { fetchUserProperties } from "../accounts/liquid-state.js";
6
- import { fetchCashbackConfig } from "../accounts/liquid-state.js";
3
+ import {
4
+ getCashbackBreakdown,
5
+ type CashbackBreakdown,
6
+ } from "../math/cashback.js";
7
+ import {
8
+ fetchUserProperties,
9
+ fetchCashbackConfig,
10
+ } from "../accounts/liquid-state.js";
7
11
 
8
12
  /**
9
13
  * Fetches a user's cashback balance and config from chain, then computes
@@ -24,5 +28,8 @@ export async function fetchCashbackBreakdown(
24
28
  fetchCashbackConfig(connection, config),
25
29
  ]);
26
30
 
27
- return getCashbackBreakdown(userProps.cashbackCredits, cashbackConfig.ranges);
31
+ return getCashbackBreakdown(
32
+ userProps.cashbackCredits,
33
+ cashbackConfig.ranges,
34
+ );
28
35
  }
@@ -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 { calculateVirtualSolReserves } 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
- * Include `initialVirtualReserveUsd` when previewing native curves without
89
- * a prefetched `bondingCurve` (needed to compute virtual SOL reserves).
90
- */
85
+ /** Fee configuration from the global config account. */
91
86
  globalConfig?: {
92
87
  protocolFeeBasisPoints: number;
93
88
  creatorFeeBasisPoints: number;
94
89
  creatorReferralRewardBasisPoints: number;
95
90
  traderReferralRewardBasisPoints: number;
96
- initialVirtualReserveUsd?: BN;
97
91
  };
98
92
  /**
99
93
  * Bonding curve reserves.
100
- * For native curves, `virtualQuoteReserves` must already be oracle-adjusted
101
- * (i.e. computed via `calculateVirtualSolReserves`).
94
+ * Virtual quote = `initialVirtualQuoteReserves + realQuoteReserves`.
95
+ * Both native and stable curves store `initialVirtualQuoteReserves` directly.
102
96
  */
103
97
  bondingCurve?: {
104
- virtualQuoteReserves: BN;
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
  */
@@ -423,15 +411,21 @@ async function resolveNativeCurve(
423
411
  : fetchNativeBondingCurve(connection, mint, config),
424
412
  ]);
425
413
 
426
- const virtualSolReserves = calculateVirtualSolReserves(
427
- BigInt(globalConfig.initialVirtualReserveUsd!.toString()),
428
- BigInt(options.solPriceUsd.toString()),
429
- );
430
-
431
- const bondingCurve = pre?.bondingCurve ?? {
432
- virtualQuoteReserves: new BN(virtualSolReserves.toString()),
414
+ const src = pre?.bondingCurve ?? {
415
+ realQuoteReserves: nativeCurve!.realQuoteReserves,
433
416
  virtualTokenReserves: nativeCurve!.virtualTokenReserves,
434
417
  realTokenReserves: nativeCurve!.realTokenReserves,
418
+ initialVirtualQuoteReserves: nativeCurve!.initialVirtualQuoteReserves,
419
+ };
420
+
421
+ const virtualQuoteReserves = src.initialVirtualQuoteReserves.add(
422
+ src.realQuoteReserves,
423
+ );
424
+
425
+ const bondingCurve = {
426
+ virtualQuoteReserves,
427
+ virtualTokenReserves: src.virtualTokenReserves,
428
+ realTokenReserves: src.realTokenReserves,
435
429
  };
436
430
 
437
431
  return { globalConfig, bondingCurve };
@@ -441,8 +435,8 @@ async function resolveNativeCurve(
441
435
  * Resolves {@link CurvePreviewState} for stable (e.g. USDC) curves.
442
436
  *
443
437
  * Fetches the global config and stable bonding curve in parallel (skipping
444
- * any that are prefetched). `virtualQuoteReserves` is read directly from
445
- * the on-chain account.
438
+ * any that are prefetched). Virtual quote reserves are computed as
439
+ * `initialVirtualQuoteReserves + realQuoteReserves`.
446
440
  *
447
441
  * @param connection - Solana RPC connection
448
442
  * @param mint - Token mint address of the stable bonding curve
@@ -465,10 +459,21 @@ async function resolveStableCurve(
465
459
  : fetchStableBondingCurve(connection, mint, config),
466
460
  ]);
467
461
 
468
- const bondingCurve = pre?.bondingCurve ?? {
469
- virtualQuoteReserves: stableCurve!.virtualQuoteReserves,
462
+ const src = pre?.bondingCurve ?? {
463
+ realQuoteReserves: stableCurve!.realQuoteReserves,
470
464
  virtualTokenReserves: stableCurve!.virtualTokenReserves,
471
465
  realTokenReserves: stableCurve!.realTokenReserves,
466
+ initialVirtualQuoteReserves: stableCurve!.initialVirtualQuoteReserves,
467
+ };
468
+
469
+ const virtualQuoteReserves = src.initialVirtualQuoteReserves.add(
470
+ src.realQuoteReserves,
471
+ );
472
+
473
+ const bondingCurve = {
474
+ virtualQuoteReserves,
475
+ virtualTokenReserves: src.virtualTokenReserves,
476
+ realTokenReserves: src.realTokenReserves,
472
477
  };
473
478
 
474
479
  return { globalConfig, bondingCurve };
@@ -522,9 +527,7 @@ function resolveCurveState(
522
527
  *
523
528
  * @example Native SOL curve
524
529
  * ```ts
525
- * const preview = await previewBuyOnCurve(connection, mint, new BN(100_000_000), config, {
526
- * solPriceUsd: new BN(150_000_000), // $150
527
- * });
530
+ * const preview = await previewBuyOnCurve(connection, mint, new BN(100_000_000), config, {});
528
531
  * ```
529
532
  *
530
533
  * @example Stable (USDC) curve
@@ -565,9 +568,7 @@ export async function previewBuyOnCurve(
565
568
  *
566
569
  * @example Native SOL curve
567
570
  * ```ts
568
- * const preview = await previewSellOnCurve(connection, mint, new BN(5_000_000), config, {
569
- * solPriceUsd: new BN(150_000_000),
570
- * });
571
+ * const preview = await previewSellOnCurve(connection, mint, new BN(5_000_000), config, {});
571
572
  * ```
572
573
  *
573
574
  * @see {@link calculateSellCurvePreview} for pure offline calculations with pre-built state