@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.
- package/dist/accounts/liquid.d.ts +18 -24
- package/dist/accounts/liquid.d.ts.map +1 -1
- package/dist/accounts/liquid.js +4 -4
- package/dist/accounts/liquid.js.map +1 -1
- package/dist/client.d.ts +31 -43
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -9
- package/dist/client.js.map +1 -1
- package/dist/events/types.d.ts +4 -7
- package/dist/events/types.d.ts.map +1 -1
- package/dist/helpers/preview.d.ts +7 -19
- package/dist/helpers/preview.d.ts.map +1 -1
- package/dist/helpers/preview.js +13 -18
- package/dist/helpers/preview.js.map +1 -1
- package/dist/idl/liquid.d.ts +139 -396
- package/dist/idl/liquid.d.ts.map +1 -1
- package/dist/idl/liquid.json +140 -397
- package/dist/idl/liquid_events.d.ts +3 -28
- package/dist/idl/liquid_events.d.ts.map +1 -1
- package/dist/idl/liquid_events.json +3 -28
- package/dist/instructions/index.d.ts +2 -2
- package/dist/instructions/index.d.ts.map +1 -1
- package/dist/instructions/index.js +1 -1
- package/dist/instructions/index.js.map +1 -1
- package/dist/instructions/liquid.d.ts +7 -22
- package/dist/instructions/liquid.d.ts.map +1 -1
- package/dist/instructions/liquid.js +13 -37
- package/dist/instructions/liquid.js.map +1 -1
- package/dist/oracle.d.ts +0 -25
- package/dist/oracle.d.ts.map +1 -1
- package/dist/oracle.js +0 -32
- package/dist/oracle.js.map +1 -1
- package/dist/types.d.ts +9 -10
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/accounts/liquid.ts +4 -4
- package/src/client.ts +13 -23
- package/src/events/types.ts +4 -7
- package/src/helpers/preview.ts +20 -37
- package/src/idl/liquid.json +140 -397
- package/src/idl/liquid.ts +140 -397
- package/src/idl/liquid_events.json +3 -28
- package/src/idl/liquid_events.ts +3 -28
- package/src/instructions/index.ts +0 -2
- package/src/instructions/liquid.ts +22 -53
- package/src/oracle.ts +0 -43
- package/src/types.ts +9 -8
|
@@ -2037,22 +2037,6 @@
|
|
|
2037
2037
|
],
|
|
2038
2038
|
"type": "u64"
|
|
2039
2039
|
},
|
|
2040
|
-
{
|
|
2041
|
-
"name": "market_cap_usd",
|
|
2042
|
-
"docs": [
|
|
2043
|
-
"Market cap in USD at migration (6 decimals)."
|
|
2044
|
-
],
|
|
2045
|
-
"type": "u64"
|
|
2046
|
-
},
|
|
2047
|
-
{
|
|
2048
|
-
"name": "sol_price_usd",
|
|
2049
|
-
"docs": [
|
|
2050
|
-
"SOL price in USD at migration (6 decimals). None for stable curves."
|
|
2051
|
-
],
|
|
2052
|
-
"type": {
|
|
2053
|
-
"option": "u64"
|
|
2054
|
-
}
|
|
2055
|
-
},
|
|
2056
2040
|
{
|
|
2057
2041
|
"name": "buyback_amount_migrated",
|
|
2058
2042
|
"docs": [
|
|
@@ -2558,7 +2542,7 @@
|
|
|
2558
2542
|
}
|
|
2559
2543
|
},
|
|
2560
2544
|
{
|
|
2561
|
-
"name": "
|
|
2545
|
+
"name": "initial_virtual_reserves",
|
|
2562
2546
|
"docs": [
|
|
2563
2547
|
"Initial virtual reserves in USD (6 decimals)."
|
|
2564
2548
|
],
|
|
@@ -2592,15 +2576,6 @@
|
|
|
2592
2576
|
],
|
|
2593
2577
|
"type": "pubkey"
|
|
2594
2578
|
},
|
|
2595
|
-
{
|
|
2596
|
-
"name": "sol_price_usd",
|
|
2597
|
-
"docs": [
|
|
2598
|
-
"SOL price in USD at creation (6 decimals). None for stable curves."
|
|
2599
|
-
],
|
|
2600
|
-
"type": {
|
|
2601
|
-
"option": "u64"
|
|
2602
|
-
}
|
|
2603
|
-
},
|
|
2604
2579
|
{
|
|
2605
2580
|
"name": "timestamp",
|
|
2606
2581
|
"docs": [
|
|
@@ -2833,9 +2808,9 @@
|
|
|
2833
2808
|
"type": "u64"
|
|
2834
2809
|
},
|
|
2835
2810
|
{
|
|
2836
|
-
"name": "
|
|
2811
|
+
"name": "total_usd_volume",
|
|
2837
2812
|
"docs": [
|
|
2838
|
-
"Total
|
|
2813
|
+
"Total USD volume (6 decimals)."
|
|
2839
2814
|
],
|
|
2840
2815
|
"type": "u128"
|
|
2841
2816
|
},
|
package/src/idl/liquid_events.ts
CHANGED
|
@@ -2043,22 +2043,6 @@ export type LiquidEvents = {
|
|
|
2043
2043
|
],
|
|
2044
2044
|
"type": "u64"
|
|
2045
2045
|
},
|
|
2046
|
-
{
|
|
2047
|
-
"name": "marketCapUsd",
|
|
2048
|
-
"docs": [
|
|
2049
|
-
"Market cap in USD at migration (6 decimals)."
|
|
2050
|
-
],
|
|
2051
|
-
"type": "u64"
|
|
2052
|
-
},
|
|
2053
|
-
{
|
|
2054
|
-
"name": "solPriceUsd",
|
|
2055
|
-
"docs": [
|
|
2056
|
-
"SOL price in USD at migration (6 decimals). None for stable curves."
|
|
2057
|
-
],
|
|
2058
|
-
"type": {
|
|
2059
|
-
"option": "u64"
|
|
2060
|
-
}
|
|
2061
|
-
},
|
|
2062
2046
|
{
|
|
2063
2047
|
"name": "buybackAmountMigrated",
|
|
2064
2048
|
"docs": [
|
|
@@ -2564,7 +2548,7 @@ export type LiquidEvents = {
|
|
|
2564
2548
|
}
|
|
2565
2549
|
},
|
|
2566
2550
|
{
|
|
2567
|
-
"name": "
|
|
2551
|
+
"name": "initialVirtualReserves",
|
|
2568
2552
|
"docs": [
|
|
2569
2553
|
"Initial virtual reserves in USD (6 decimals)."
|
|
2570
2554
|
],
|
|
@@ -2598,15 +2582,6 @@ export type LiquidEvents = {
|
|
|
2598
2582
|
],
|
|
2599
2583
|
"type": "pubkey"
|
|
2600
2584
|
},
|
|
2601
|
-
{
|
|
2602
|
-
"name": "solPriceUsd",
|
|
2603
|
-
"docs": [
|
|
2604
|
-
"SOL price in USD at creation (6 decimals). None for stable curves."
|
|
2605
|
-
],
|
|
2606
|
-
"type": {
|
|
2607
|
-
"option": "u64"
|
|
2608
|
-
}
|
|
2609
|
-
},
|
|
2610
2585
|
{
|
|
2611
2586
|
"name": "timestamp",
|
|
2612
2587
|
"docs": [
|
|
@@ -2839,9 +2814,9 @@ export type LiquidEvents = {
|
|
|
2839
2814
|
"type": "u64"
|
|
2840
2815
|
},
|
|
2841
2816
|
{
|
|
2842
|
-
"name": "
|
|
2817
|
+
"name": "totalUsdVolume",
|
|
2843
2818
|
"docs": [
|
|
2844
|
-
"Total
|
|
2819
|
+
"Total USD volume (6 decimals)."
|
|
2845
2820
|
],
|
|
2846
2821
|
"type": "u128"
|
|
2847
2822
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export {
|
|
2
2
|
buildCreateNativeCurve,
|
|
3
|
-
buildBumpNative,
|
|
4
3
|
buildBuyExactInNative,
|
|
5
4
|
buildBuyExactInNativeAutoResolve,
|
|
6
5
|
buildSellExactInNative,
|
|
@@ -31,7 +30,6 @@ export {
|
|
|
31
30
|
} from "./liquid.js";
|
|
32
31
|
export type {
|
|
33
32
|
BuildCreateNativeCurveParams,
|
|
34
|
-
BuildBumpNativeParams,
|
|
35
33
|
BuildBuyExactInNativeParams,
|
|
36
34
|
BuildSellExactInNativeParams,
|
|
37
35
|
BuildBuyExactOutNativeParams,
|
|
@@ -9,7 +9,11 @@ import {
|
|
|
9
9
|
TOKEN_2022_PROGRAM_ID,
|
|
10
10
|
} from "@solana/spl-token";
|
|
11
11
|
import type BN from "bn.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
PYTH_SOL_USD_PRICE_FEED,
|
|
14
|
+
WSOL_MINT,
|
|
15
|
+
type LiquidConfig,
|
|
16
|
+
} from "../config.js";
|
|
13
17
|
import {
|
|
14
18
|
getBondingCurvePDA,
|
|
15
19
|
getBondingCurveTokenAccount,
|
|
@@ -38,7 +42,6 @@ import {
|
|
|
38
42
|
export interface BuildCreateNativeCurveParams {
|
|
39
43
|
creator: PublicKey;
|
|
40
44
|
mint: PublicKey;
|
|
41
|
-
pythPriceFeed: PublicKey;
|
|
42
45
|
name: string;
|
|
43
46
|
symbol: string;
|
|
44
47
|
uri: string;
|
|
@@ -58,7 +61,7 @@ export interface BuildCreateNativeCurveParams {
|
|
|
58
61
|
export function buildCreateNativeCurve(
|
|
59
62
|
params: BuildCreateNativeCurveParams,
|
|
60
63
|
): Promise<TransactionInstruction> {
|
|
61
|
-
const { creator, mint,
|
|
64
|
+
const { creator, mint, name, symbol, uri, config } = params;
|
|
62
65
|
const program = getCachedLiquidProgram(config);
|
|
63
66
|
|
|
64
67
|
const bondingCurveTokenAccount = getBondingCurveTokenAccount(
|
|
@@ -74,58 +77,28 @@ export function buildCreateNativeCurve(
|
|
|
74
77
|
.accounts({
|
|
75
78
|
creator,
|
|
76
79
|
mint,
|
|
77
|
-
pythPriceFeed,
|
|
78
80
|
bondingCurveTokenAccount,
|
|
79
81
|
})
|
|
80
82
|
.instruction();
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
export interface BuildBumpNativeParams {
|
|
84
|
-
mint: PublicKey;
|
|
85
|
-
pythPriceFeed: PublicKey;
|
|
86
|
-
config: LiquidConfig;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Builds a bumpNative instruction.
|
|
91
|
-
* Re-evaluates a native bonding curve's market cap against the current oracle price
|
|
92
|
-
* and marks it as complete if the threshold is exceeded. Permissionless.
|
|
93
|
-
*
|
|
94
|
-
* @param params - {@link BuildBumpNativeParams}
|
|
95
|
-
* @returns Transaction instruction
|
|
96
|
-
*/
|
|
97
|
-
export function buildBumpNative(
|
|
98
|
-
params: BuildBumpNativeParams,
|
|
99
|
-
): Promise<TransactionInstruction> {
|
|
100
|
-
const { mint, pythPriceFeed, config } = params;
|
|
101
|
-
const program = getCachedLiquidProgram(config);
|
|
102
|
-
|
|
103
|
-
return program.methods
|
|
104
|
-
.bumpNative()
|
|
105
|
-
.accounts({
|
|
106
|
-
mint,
|
|
107
|
-
pythPriceFeed,
|
|
108
|
-
})
|
|
109
|
-
.instruction();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
85
|
export interface BuildBuyExactInNativeParams {
|
|
113
86
|
user: PublicKey;
|
|
114
87
|
mint: PublicKey;
|
|
115
88
|
creator: PublicKey;
|
|
116
|
-
pythPriceFeed: PublicKey;
|
|
117
89
|
amountIn: BN;
|
|
118
90
|
minAmountOut: BN;
|
|
119
91
|
feeRecipient: PublicKey;
|
|
120
92
|
creatorReferralVault?: PublicKey | null;
|
|
121
93
|
traderReferralVault?: PublicKey | null;
|
|
122
94
|
userTokenAccount?: PublicKey;
|
|
95
|
+
pythPriceFeed?: PublicKey;
|
|
123
96
|
config: LiquidConfig;
|
|
124
97
|
}
|
|
125
98
|
|
|
126
99
|
/**
|
|
127
100
|
* Builds a buyNative instruction.
|
|
128
|
-
* Requires the bonding curve creator
|
|
101
|
+
* Requires the bonding curve creator to be known.
|
|
129
102
|
*
|
|
130
103
|
* @param params - {@link BuildBuyExactInNativeParams}
|
|
131
104
|
* @returns Transaction instruction
|
|
@@ -137,13 +110,13 @@ export function buildBuyExactInNative(
|
|
|
137
110
|
user,
|
|
138
111
|
mint,
|
|
139
112
|
creator,
|
|
140
|
-
pythPriceFeed,
|
|
141
113
|
amountIn,
|
|
142
114
|
minAmountOut,
|
|
143
115
|
feeRecipient,
|
|
144
116
|
creatorReferralVault,
|
|
145
117
|
traderReferralVault,
|
|
146
118
|
userTokenAccount,
|
|
119
|
+
pythPriceFeed,
|
|
147
120
|
config,
|
|
148
121
|
} = params;
|
|
149
122
|
|
|
@@ -165,7 +138,7 @@ export function buildBuyExactInNative(
|
|
|
165
138
|
user,
|
|
166
139
|
feeRecipient,
|
|
167
140
|
mint,
|
|
168
|
-
pythPriceFeed,
|
|
141
|
+
pythPriceFeed: pythPriceFeed ?? PYTH_SOL_USD_PRICE_FEED,
|
|
169
142
|
creatorUserProperties,
|
|
170
143
|
userTokenAccount: resolvedUserTokenAccount,
|
|
171
144
|
creatorReferralVault: creatorReferralVault ?? null,
|
|
@@ -198,7 +171,6 @@ export async function buildBuyExactInNativeAutoResolve(
|
|
|
198
171
|
return buildBuyExactInNative({
|
|
199
172
|
...params,
|
|
200
173
|
creator: curve.creator,
|
|
201
|
-
pythPriceFeed: params.pythPriceFeed,
|
|
202
174
|
});
|
|
203
175
|
}
|
|
204
176
|
|
|
@@ -206,19 +178,19 @@ export interface BuildSellExactInNativeParams {
|
|
|
206
178
|
user: PublicKey;
|
|
207
179
|
mint: PublicKey;
|
|
208
180
|
creator: PublicKey;
|
|
209
|
-
pythPriceFeed: PublicKey;
|
|
210
181
|
amountIn: BN;
|
|
211
182
|
minAmountOut: BN;
|
|
212
183
|
feeRecipient: PublicKey;
|
|
213
184
|
creatorReferralVault?: PublicKey | null;
|
|
214
185
|
traderReferralVault?: PublicKey | null;
|
|
215
186
|
userTokenAccount?: PublicKey;
|
|
187
|
+
pythPriceFeed?: PublicKey;
|
|
216
188
|
config: LiquidConfig;
|
|
217
189
|
}
|
|
218
190
|
|
|
219
191
|
/**
|
|
220
192
|
* Builds a sellNative instruction.
|
|
221
|
-
* Requires the bonding curve creator
|
|
193
|
+
* Requires the bonding curve creator to be known.
|
|
222
194
|
*
|
|
223
195
|
* @param params - {@link BuildSellExactInNativeParams}
|
|
224
196
|
* @returns Transaction instruction
|
|
@@ -230,13 +202,13 @@ export function buildSellExactInNative(
|
|
|
230
202
|
user,
|
|
231
203
|
mint,
|
|
232
204
|
creator,
|
|
233
|
-
pythPriceFeed,
|
|
234
205
|
amountIn,
|
|
235
206
|
minAmountOut,
|
|
236
207
|
feeRecipient,
|
|
237
208
|
creatorReferralVault,
|
|
238
209
|
traderReferralVault,
|
|
239
210
|
userTokenAccount,
|
|
211
|
+
pythPriceFeed,
|
|
240
212
|
config,
|
|
241
213
|
} = params;
|
|
242
214
|
|
|
@@ -258,7 +230,7 @@ export function buildSellExactInNative(
|
|
|
258
230
|
user,
|
|
259
231
|
feeRecipient,
|
|
260
232
|
mint,
|
|
261
|
-
pythPriceFeed,
|
|
233
|
+
pythPriceFeed: pythPriceFeed ?? PYTH_SOL_USD_PRICE_FEED,
|
|
262
234
|
creatorUserProperties,
|
|
263
235
|
userTokenAccount: resolvedUserTokenAccount,
|
|
264
236
|
creatorReferralVault: creatorReferralVault ?? null,
|
|
@@ -291,7 +263,6 @@ export async function buildSellExactInNativeAutoResolve(
|
|
|
291
263
|
return buildSellExactInNative({
|
|
292
264
|
...params,
|
|
293
265
|
creator: curve.creator,
|
|
294
|
-
pythPriceFeed: params.pythPriceFeed,
|
|
295
266
|
});
|
|
296
267
|
}
|
|
297
268
|
|
|
@@ -299,13 +270,13 @@ export interface BuildBuyExactOutNativeParams {
|
|
|
299
270
|
user: PublicKey;
|
|
300
271
|
mint: PublicKey;
|
|
301
272
|
creator: PublicKey;
|
|
302
|
-
pythPriceFeed: PublicKey;
|
|
303
273
|
exactAmountOut: BN;
|
|
304
274
|
maxAmountIn: BN;
|
|
305
275
|
feeRecipient: PublicKey;
|
|
306
276
|
creatorReferralVault?: PublicKey | null;
|
|
307
277
|
traderReferralVault?: PublicKey | null;
|
|
308
278
|
userTokenAccount?: PublicKey;
|
|
279
|
+
pythPriceFeed?: PublicKey;
|
|
309
280
|
config: LiquidConfig;
|
|
310
281
|
}
|
|
311
282
|
|
|
@@ -323,13 +294,13 @@ export function buildBuyExactOutNative(
|
|
|
323
294
|
user,
|
|
324
295
|
mint,
|
|
325
296
|
creator,
|
|
326
|
-
pythPriceFeed,
|
|
327
297
|
exactAmountOut,
|
|
328
298
|
maxAmountIn,
|
|
329
299
|
feeRecipient,
|
|
330
300
|
creatorReferralVault,
|
|
331
301
|
traderReferralVault,
|
|
332
302
|
userTokenAccount,
|
|
303
|
+
pythPriceFeed,
|
|
333
304
|
config,
|
|
334
305
|
} = params;
|
|
335
306
|
|
|
@@ -350,7 +321,7 @@ export function buildBuyExactOutNative(
|
|
|
350
321
|
user,
|
|
351
322
|
feeRecipient,
|
|
352
323
|
mint,
|
|
353
|
-
pythPriceFeed,
|
|
324
|
+
pythPriceFeed: pythPriceFeed ?? PYTH_SOL_USD_PRICE_FEED,
|
|
354
325
|
creatorUserProperties,
|
|
355
326
|
userTokenAccount: resolvedUserTokenAccount,
|
|
356
327
|
creatorReferralVault: creatorReferralVault ?? null,
|
|
@@ -383,7 +354,6 @@ export async function buildBuyExactOutNativeAutoResolve(
|
|
|
383
354
|
return buildBuyExactOutNative({
|
|
384
355
|
...params,
|
|
385
356
|
creator: curve.creator,
|
|
386
|
-
pythPriceFeed: params.pythPriceFeed,
|
|
387
357
|
});
|
|
388
358
|
}
|
|
389
359
|
|
|
@@ -391,13 +361,13 @@ export interface BuildSellExactOutNativeParams {
|
|
|
391
361
|
user: PublicKey;
|
|
392
362
|
mint: PublicKey;
|
|
393
363
|
creator: PublicKey;
|
|
394
|
-
pythPriceFeed: PublicKey;
|
|
395
364
|
exactAmountOut: BN;
|
|
396
365
|
maxAmountIn: BN;
|
|
397
366
|
feeRecipient: PublicKey;
|
|
398
367
|
creatorReferralVault?: PublicKey | null;
|
|
399
368
|
traderReferralVault?: PublicKey | null;
|
|
400
369
|
userTokenAccount?: PublicKey;
|
|
370
|
+
pythPriceFeed?: PublicKey;
|
|
401
371
|
config: LiquidConfig;
|
|
402
372
|
}
|
|
403
373
|
|
|
@@ -415,13 +385,13 @@ export function buildSellExactOutNative(
|
|
|
415
385
|
user,
|
|
416
386
|
mint,
|
|
417
387
|
creator,
|
|
418
|
-
pythPriceFeed,
|
|
419
388
|
exactAmountOut,
|
|
420
389
|
maxAmountIn,
|
|
421
390
|
feeRecipient,
|
|
422
391
|
creatorReferralVault,
|
|
423
392
|
traderReferralVault,
|
|
424
393
|
userTokenAccount,
|
|
394
|
+
pythPriceFeed,
|
|
425
395
|
config,
|
|
426
396
|
} = params;
|
|
427
397
|
|
|
@@ -442,7 +412,7 @@ export function buildSellExactOutNative(
|
|
|
442
412
|
user,
|
|
443
413
|
feeRecipient,
|
|
444
414
|
mint,
|
|
445
|
-
pythPriceFeed,
|
|
415
|
+
pythPriceFeed: pythPriceFeed ?? PYTH_SOL_USD_PRICE_FEED,
|
|
446
416
|
creatorUserProperties,
|
|
447
417
|
userTokenAccount: resolvedUserTokenAccount,
|
|
448
418
|
creatorReferralVault: creatorReferralVault ?? null,
|
|
@@ -475,7 +445,6 @@ export async function buildSellExactOutNativeAutoResolve(
|
|
|
475
445
|
return buildSellExactOutNative({
|
|
476
446
|
...params,
|
|
477
447
|
creator: curve.creator,
|
|
478
|
-
pythPriceFeed: params.pythPriceFeed,
|
|
479
448
|
});
|
|
480
449
|
}
|
|
481
450
|
|
|
@@ -643,7 +612,7 @@ export function buildWithdrawReferralTokenRewards(
|
|
|
643
612
|
export interface BuildExecuteBuybackNativeParams {
|
|
644
613
|
payer: PublicKey;
|
|
645
614
|
mint: PublicKey;
|
|
646
|
-
pythPriceFeed
|
|
615
|
+
pythPriceFeed?: PublicKey;
|
|
647
616
|
config: LiquidConfig;
|
|
648
617
|
}
|
|
649
618
|
|
|
@@ -665,7 +634,7 @@ export function buildExecuteBuybackNative(
|
|
|
665
634
|
.accountsPartial({
|
|
666
635
|
payer,
|
|
667
636
|
mint,
|
|
668
|
-
pythPriceFeed,
|
|
637
|
+
pythPriceFeed: pythPriceFeed ?? PYTH_SOL_USD_PRICE_FEED,
|
|
669
638
|
})
|
|
670
639
|
.instruction();
|
|
671
640
|
}
|
package/src/oracle.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* (mainnet, devnet, testnet, and localnet). Feed IDs are asset pair identifiers,
|
|
6
6
|
* not account addresses. The actual price feed accounts differ per network, but all
|
|
7
7
|
* contain data for this feed ID.
|
|
8
|
-
*
|
|
9
|
-
* Must match the constant in programs/liquid/src/instructions/shared/oracle.rs
|
|
10
8
|
*/
|
|
11
9
|
export const SOL_USD_FEED_ID =
|
|
12
10
|
"0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d";
|
|
@@ -21,47 +19,6 @@ export const PYTH_EXPONENT = -8;
|
|
|
21
19
|
*/
|
|
22
20
|
export const USD_DECIMALS = 6;
|
|
23
21
|
|
|
24
|
-
/**
|
|
25
|
-
* Calculates the initial virtual SOL reserves from the USD-denominated config value for a given virtual reserve value and SOL price.
|
|
26
|
-
*
|
|
27
|
-
* @param initialVirtualReserveUsd - Initial virtual reserve value in USD (6 decimals)
|
|
28
|
-
* @param solPriceUsd - SOL price in USD (6 decimals)
|
|
29
|
-
* @returns Initial virtual SOL reserves in lamports
|
|
30
|
-
*/
|
|
31
|
-
export function calculateInitialVirtualSolReserves(
|
|
32
|
-
initialVirtualReserveUsd: bigint,
|
|
33
|
-
solPriceUsd: bigint,
|
|
34
|
-
): bigint {
|
|
35
|
-
// virtual_sol (lamports) = initial_virtual_reserve_usd / sol_price_usd * 10^9
|
|
36
|
-
return (initialVirtualReserveUsd * BigInt(1_000_000_000)) / solPriceUsd;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Calculates the market cap of a token in USD for native curves.
|
|
41
|
-
*
|
|
42
|
-
* Formula: market_cap_usd = (virtual_sol * sol_price / LAMPORTS_PER_SOL) * supply / virtual_token
|
|
43
|
-
*
|
|
44
|
-
* Uses a combined formula to avoid intermediate truncation that causes
|
|
45
|
-
* coarse step granularity in a multi-step approach.
|
|
46
|
-
*
|
|
47
|
-
* @param virtualSolReserves - Virtual SOL reserves in lamports
|
|
48
|
-
* @param virtualTokenReserves - Virtual token reserves (6 decimals)
|
|
49
|
-
* @param tokenTotalSupply - Total supply of tokens (6 decimals)
|
|
50
|
-
* @param solPriceUsd - SOL price in USD (6 decimals)
|
|
51
|
-
* @returns Market cap in USD (6 decimals)
|
|
52
|
-
*/
|
|
53
|
-
export function calculateNativeMarketCapUsd(
|
|
54
|
-
virtualSolReserves: bigint,
|
|
55
|
-
virtualTokenReserves: bigint,
|
|
56
|
-
tokenTotalSupply: bigint,
|
|
57
|
-
solPriceUsd: bigint,
|
|
58
|
-
): bigint {
|
|
59
|
-
// Convert virtual SOL reserves to USD value, then compute FDV
|
|
60
|
-
const virtualSolUsd =
|
|
61
|
-
(virtualSolReserves * solPriceUsd) / BigInt(1_000_000_000);
|
|
62
|
-
return (virtualSolUsd * tokenTotalSupply) / virtualTokenReserves;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
22
|
/**
|
|
66
23
|
* Calculates the market cap of a token in USD for stable curves.
|
|
67
24
|
*
|
package/src/types.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type CurveStatus = (typeof CurveStatus)[keyof typeof CurveStatus];
|
|
|
13
13
|
/** Anchor-serialized curve status representation */
|
|
14
14
|
export type CurveStatusAnchor =
|
|
15
15
|
| { active: Record<string, never> }
|
|
16
|
-
| { complete:
|
|
16
|
+
| { complete: Record<string, never> }
|
|
17
17
|
| { migrated: Record<string, never> };
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -75,8 +75,8 @@ export const feeModeEquals = (
|
|
|
75
75
|
/** Global configuration for the bonding curve program */
|
|
76
76
|
export interface GlobalConfiguration {
|
|
77
77
|
adminAuthority: PublicKey;
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
initialVirtualUsdReserves: BN;
|
|
79
|
+
initialVirtualSolReserves: BN;
|
|
80
80
|
initialVirtualTokenReserves: BN;
|
|
81
81
|
initialRealTokenReserves: BN;
|
|
82
82
|
tokenTotalSupply: BN;
|
|
@@ -85,22 +85,23 @@ export interface GlobalConfiguration {
|
|
|
85
85
|
traderReferralRewardBasisPoints: number;
|
|
86
86
|
protocolFeeBasisPoints: number;
|
|
87
87
|
feeRecipients: PublicKey[];
|
|
88
|
-
quoteMints: PublicKey[];
|
|
89
88
|
solUsdPriceFeed: PublicKey;
|
|
89
|
+
quoteMints: PublicKey[];
|
|
90
90
|
pendingAdmin: PublicKey | null;
|
|
91
|
-
bump: number;
|
|
92
91
|
paused: boolean;
|
|
92
|
+
bump: number;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
/**
|
|
95
|
+
/** Unified bonding curve account state (native SOL and stable token curves) */
|
|
96
96
|
export interface BondingCurveState {
|
|
97
97
|
creator: PublicKey;
|
|
98
98
|
tokenMint: PublicKey;
|
|
99
|
+
quoteMint: PublicKey | null;
|
|
99
100
|
realTokenReserves: BN;
|
|
100
101
|
virtualTokenReserves: BN;
|
|
101
|
-
|
|
102
|
+
realQuoteReserves: BN;
|
|
103
|
+
initialVirtualQuoteReserves: BN;
|
|
102
104
|
tokenTotalSupply: BN;
|
|
103
|
-
initialVirtualReserveUsd: BN;
|
|
104
105
|
status: CurveStatusAnchor;
|
|
105
106
|
bump: number;
|
|
106
107
|
}
|