@liquid-af/sdk 0.3.0 → 0.4.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 +2 -3
- package/dist/accounts/liquid.d.ts.map +1 -1
- package/dist/accounts/liquid.js +3 -4
- package/dist/accounts/liquid.js.map +1 -1
- package/dist/client.d.ts +4 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +6 -6
- package/dist/client.js.map +1 -1
- package/dist/helpers/preview.d.ts.map +1 -1
- package/dist/helpers/preview.js +1 -1
- package/dist/helpers/preview.js.map +1 -1
- package/dist/idl/index.d.ts +1 -0
- package/dist/idl/index.d.ts.map +1 -1
- package/dist/idl/index.js +15 -4
- package/dist/idl/index.js.map +1 -1
- package/dist/idl/liquid.d.ts +0 -20
- package/dist/idl/liquid.d.ts.map +1 -1
- package/dist/idl/liquid.json +0 -20
- package/dist/idl/patch-idl.d.ts +10 -0
- package/dist/idl/patch-idl.d.ts.map +1 -0
- package/dist/idl/patch-idl.js +62 -0
- package/dist/idl/patch-idl.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instructions/liquid.d.ts.map +1 -1
- package/dist/instructions/liquid.js +3 -3
- package/dist/instructions/liquid.js.map +1 -1
- package/dist/instructions/program-cache.d.ts.map +1 -1
- package/dist/instructions/program-cache.js +10 -6
- package/dist/instructions/program-cache.js.map +1 -1
- package/dist/pda/index.d.ts.map +1 -1
- package/dist/pda/index.js +1 -1
- package/dist/pda/index.js.map +1 -1
- package/dist/pda/liquid.d.ts +2 -3
- package/dist/pda/liquid.d.ts.map +1 -1
- package/dist/pda/liquid.js +3 -4
- package/dist/pda/liquid.js.map +1 -1
- package/package.json +4 -4
- package/src/accounts/liquid-fees.ts +2 -2
- package/src/accounts/liquid-state.ts +7 -7
- package/src/accounts/liquid-swap.ts +4 -4
- package/src/accounts/liquid.ts +7 -10
- package/src/client.ts +33 -36
- package/src/config.ts +10 -10
- package/src/errors.ts +6 -6
- package/src/events/parser.ts +5 -5
- package/src/helpers/preview.ts +31 -32
- package/src/helpers/user.ts +1 -1
- package/src/idl/index.ts +31 -8
- package/src/idl/liquid.json +0 -20
- package/src/idl/liquid.ts +0 -20
- package/src/idl/patch-idl.ts +80 -0
- package/src/index.ts +1 -0
- package/src/instructions/liquid-fees.ts +14 -14
- package/src/instructions/liquid-state.ts +4 -4
- package/src/instructions/liquid-swap.ts +18 -18
- package/src/instructions/liquid.ts +47 -50
- package/src/instructions/program-cache.ts +18 -9
- package/src/math/amm.ts +3 -3
- package/src/math/bonding-curve.ts +6 -6
- package/src/math/fees.ts +9 -9
- package/src/math/tiered-fees.ts +5 -5
- package/src/oracle.ts +3 -3
- package/src/pda/index.ts +27 -28
- package/src/pda/liquid-fees.ts +6 -6
- package/src/pda/liquid-state.ts +13 -13
- package/src/pda/liquid-swap.ts +16 -16
- package/src/pda/liquid.ts +17 -19
- package/src/provider.ts +2 -2
- package/src/transaction/builder.ts +4 -4
- package/src/transaction/send.ts +4 -4
- package/src/types.ts +2 -2
package/src/math/fees.ts
CHANGED
|
@@ -42,7 +42,7 @@ export const calculateFees = (
|
|
|
42
42
|
amount: BN,
|
|
43
43
|
config: FeeConfig,
|
|
44
44
|
hasCreatorRef: boolean,
|
|
45
|
-
hasTraderRef: boolean
|
|
45
|
+
hasTraderRef: boolean,
|
|
46
46
|
): FeeDistribution => {
|
|
47
47
|
const baseProtocolFee = calcBps(amount, config.protocolFeeBps);
|
|
48
48
|
const creatorFee = calcBps(amount, config.creatorFeeBps);
|
|
@@ -80,7 +80,7 @@ export const calculateFees = (
|
|
|
80
80
|
*/
|
|
81
81
|
export const calculateDistribution = (
|
|
82
82
|
vaultBalance: number,
|
|
83
|
-
recipients: FeeRecipient[]
|
|
83
|
+
recipients: FeeRecipient[],
|
|
84
84
|
): DistributionResult[] => {
|
|
85
85
|
const distributable = Math.max(0, vaultBalance - MIN_VAULT_BALANCE);
|
|
86
86
|
return recipients.map((r) => ({
|
|
@@ -98,11 +98,11 @@ export const calculateDistribution = (
|
|
|
98
98
|
*/
|
|
99
99
|
export const calculateTotalDistribution = (
|
|
100
100
|
vaultBalance: number,
|
|
101
|
-
recipients: FeeRecipient[]
|
|
101
|
+
recipients: FeeRecipient[],
|
|
102
102
|
): number => {
|
|
103
103
|
return calculateDistribution(vaultBalance, recipients).reduce(
|
|
104
104
|
(sum, r) => sum + r.amount,
|
|
105
|
-
0
|
|
105
|
+
0,
|
|
106
106
|
);
|
|
107
107
|
};
|
|
108
108
|
|
|
@@ -115,12 +115,12 @@ export const calculateTotalDistribution = (
|
|
|
115
115
|
*/
|
|
116
116
|
export const calculateDistributionDust = (
|
|
117
117
|
vaultBalance: number,
|
|
118
|
-
recipients: FeeRecipient[]
|
|
118
|
+
recipients: FeeRecipient[],
|
|
119
119
|
): number => {
|
|
120
120
|
const distributable = Math.max(0, vaultBalance - MIN_VAULT_BALANCE);
|
|
121
121
|
const totalDistributed = calculateTotalDistribution(
|
|
122
122
|
vaultBalance,
|
|
123
|
-
recipients
|
|
123
|
+
recipients,
|
|
124
124
|
);
|
|
125
125
|
return distributable - totalDistributed;
|
|
126
126
|
};
|
|
@@ -134,7 +134,7 @@ export const calculateDistributionDust = (
|
|
|
134
134
|
*/
|
|
135
135
|
export const createRecipients = (
|
|
136
136
|
pubkeys: PublicKey[],
|
|
137
|
-
bpsArray: number[]
|
|
137
|
+
bpsArray: number[],
|
|
138
138
|
): FeeRecipient[] => {
|
|
139
139
|
if (pubkeys.length !== bpsArray.length) {
|
|
140
140
|
throw new Error("pubkeys and bpsArray must have the same length");
|
|
@@ -154,11 +154,11 @@ export const createRecipients = (
|
|
|
154
154
|
*/
|
|
155
155
|
export const createEqualRecipients = (
|
|
156
156
|
count: number,
|
|
157
|
-
pubkeys: PublicKey[]
|
|
157
|
+
pubkeys: PublicKey[],
|
|
158
158
|
): FeeRecipient[] => {
|
|
159
159
|
if (pubkeys.length < count) {
|
|
160
160
|
throw new Error(
|
|
161
|
-
`Need at least ${count} pubkeys, got ${pubkeys.length}
|
|
161
|
+
`Need at least ${count} pubkeys, got ${pubkeys.length}`,
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
const bpsPerRecipient = Math.floor(BPS_DENOMINATOR / count);
|
package/src/math/tiered-fees.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { FeeTier } from "../types.js";
|
|
|
4
4
|
|
|
5
5
|
/** WSOL mint address (native SOL wrapped as SPL token) */
|
|
6
6
|
export const WSOL_MINT = new PublicKey(
|
|
7
|
-
"So11111111111111111111111111111111111111112"
|
|
7
|
+
"So11111111111111111111111111111111111111112",
|
|
8
8
|
);
|
|
9
9
|
|
|
10
10
|
/** Lamports per SOL constant */
|
|
@@ -47,7 +47,7 @@ export function calculatePoolMarketCap(
|
|
|
47
47
|
baseVaultAmount: BN,
|
|
48
48
|
baseTotalSupply: BN,
|
|
49
49
|
solPriceUsd: BN,
|
|
50
|
-
quoteMint: PublicKey
|
|
50
|
+
quoteMint: PublicKey,
|
|
51
51
|
): BN {
|
|
52
52
|
// Prevent division by zero
|
|
53
53
|
if (baseVaultAmount.isZero()) {
|
|
@@ -108,7 +108,7 @@ export function calculatePoolMarketCap(
|
|
|
108
108
|
*/
|
|
109
109
|
export function lookupFeeTier(
|
|
110
110
|
marketCapUsd: BN,
|
|
111
|
-
tiers: FeeTier[]
|
|
111
|
+
tiers: FeeTier[],
|
|
112
112
|
): [number, number, number] {
|
|
113
113
|
if (tiers.length === 0) {
|
|
114
114
|
throw new Error("No fee tiers configured");
|
|
@@ -151,14 +151,14 @@ export function calculateFeesForPool(
|
|
|
151
151
|
baseTotalSupply: BN,
|
|
152
152
|
solPriceUsd: BN,
|
|
153
153
|
quoteMint: PublicKey,
|
|
154
|
-
tiers: FeeTier[]
|
|
154
|
+
tiers: FeeTier[],
|
|
155
155
|
): [number, number, number] {
|
|
156
156
|
const marketCap = calculatePoolMarketCap(
|
|
157
157
|
quoteVaultAmount,
|
|
158
158
|
baseVaultAmount,
|
|
159
159
|
baseTotalSupply,
|
|
160
160
|
solPriceUsd,
|
|
161
|
-
quoteMint
|
|
161
|
+
quoteMint,
|
|
162
162
|
);
|
|
163
163
|
|
|
164
164
|
return lookupFeeTier(marketCap, tiers);
|
package/src/oracle.ts
CHANGED
|
@@ -31,7 +31,7 @@ export const USD_DECIMALS = 6;
|
|
|
31
31
|
*/
|
|
32
32
|
export function calculateVirtualSolReserves(
|
|
33
33
|
initialVirtualReserveUsd: bigint,
|
|
34
|
-
solPriceUsd: bigint
|
|
34
|
+
solPriceUsd: bigint,
|
|
35
35
|
): bigint {
|
|
36
36
|
// virtual_sol (lamports) = initial_virtual_reserve_usd / sol_price_usd * 10^9
|
|
37
37
|
return (initialVirtualReserveUsd * BigInt(1_000_000_000)) / solPriceUsd;
|
|
@@ -56,7 +56,7 @@ export function calculateNativeMarketCapUsd(
|
|
|
56
56
|
virtualSolReserves: bigint,
|
|
57
57
|
virtualTokenReserves: bigint,
|
|
58
58
|
tokenTotalSupply: bigint,
|
|
59
|
-
solPriceUsd: bigint
|
|
59
|
+
solPriceUsd: bigint,
|
|
60
60
|
): bigint {
|
|
61
61
|
// Convert virtual SOL reserves to USD value, then compute FDV
|
|
62
62
|
const virtualSolUsd =
|
|
@@ -83,7 +83,7 @@ export function calculateStableMarketCapUsd(
|
|
|
83
83
|
virtualQuoteReserves: bigint,
|
|
84
84
|
virtualTokenReserves: bigint,
|
|
85
85
|
tokenTotalSupply: bigint,
|
|
86
|
-
quoteDecimals: number = 6
|
|
86
|
+
quoteDecimals: number = 6,
|
|
87
87
|
): bigint {
|
|
88
88
|
const raw =
|
|
89
89
|
(virtualQuoteReserves * tokenTotalSupply) / virtualTokenReserves;
|
package/src/pda/index.ts
CHANGED
|
@@ -81,26 +81,26 @@ export interface BondingCurvePDAs {
|
|
|
81
81
|
export const getAllBondingCurvePDAs = (
|
|
82
82
|
mint: PublicKey,
|
|
83
83
|
creator: PublicKey,
|
|
84
|
-
config: LiquidConfig
|
|
84
|
+
config: LiquidConfig,
|
|
85
85
|
): BondingCurvePDAs => {
|
|
86
86
|
const [bondingCurve] = getBondingCurvePDA(mint, config.liquidProgramId);
|
|
87
87
|
const [bondingCurveSolVault] = getBondingCurveSolVaultPDA(
|
|
88
88
|
bondingCurve,
|
|
89
|
-
config.liquidProgramId
|
|
89
|
+
config.liquidProgramId,
|
|
90
90
|
);
|
|
91
91
|
const [referralVault] = getReferralVaultPDA(
|
|
92
92
|
creator,
|
|
93
|
-
config.liquidProgramId
|
|
93
|
+
config.liquidProgramId,
|
|
94
94
|
);
|
|
95
95
|
const [buybackVault] = getBuybackVaultPDA(
|
|
96
96
|
bondingCurve,
|
|
97
|
-
config.liquidProgramId
|
|
97
|
+
config.liquidProgramId,
|
|
98
98
|
);
|
|
99
99
|
const [feeConfig] = getFeeConfigPDA(mint, config.liquidFeesProgramId);
|
|
100
100
|
const [feeVault] = getFeeVaultPDA(feeConfig, config.liquidFeesProgramId);
|
|
101
101
|
const [userProperties] = getUserPropertiesPDA(
|
|
102
102
|
creator,
|
|
103
|
-
config.liquidStateProgramId
|
|
103
|
+
config.liquidStateProgramId,
|
|
104
104
|
);
|
|
105
105
|
const [tokenVolume] = getTokenVolumePDA(mint, config.liquidStateProgramId);
|
|
106
106
|
|
|
@@ -140,34 +140,34 @@ export interface PoolPDAs {
|
|
|
140
140
|
export const getAllPoolPDAs = (
|
|
141
141
|
baseMint: PublicKey,
|
|
142
142
|
quoteMint: PublicKey,
|
|
143
|
-
config: LiquidConfig
|
|
143
|
+
config: LiquidConfig,
|
|
144
144
|
): PoolPDAs => {
|
|
145
145
|
const [poolState] = getPoolPDA(
|
|
146
146
|
baseMint,
|
|
147
147
|
quoteMint,
|
|
148
|
-
config.liquidSwapProgramId
|
|
148
|
+
config.liquidSwapProgramId,
|
|
149
149
|
);
|
|
150
150
|
const [lpMint] = getPoolLpMintPDA(poolState, config.liquidSwapProgramId);
|
|
151
151
|
const [baseVault] = getPoolVaultPDA(
|
|
152
152
|
poolState,
|
|
153
153
|
baseMint,
|
|
154
|
-
config.liquidSwapProgramId
|
|
154
|
+
config.liquidSwapProgramId,
|
|
155
155
|
);
|
|
156
156
|
const [quoteVault] = getPoolVaultPDA(
|
|
157
157
|
poolState,
|
|
158
158
|
quoteMint,
|
|
159
|
-
config.liquidSwapProgramId
|
|
159
|
+
config.liquidSwapProgramId,
|
|
160
160
|
);
|
|
161
161
|
const [observation] = getObservationPDA(
|
|
162
162
|
poolState,
|
|
163
|
-
config.liquidSwapProgramId
|
|
163
|
+
config.liquidSwapProgramId,
|
|
164
164
|
);
|
|
165
165
|
const [ammConfig] = getSwapGlobalConfigPDA(config.liquidSwapProgramId);
|
|
166
166
|
const [ammAuthority] = getSwapAuthorityPDA(config.liquidSwapProgramId);
|
|
167
167
|
const [feeConfig] = getFeeConfigPDA(baseMint, config.liquidFeesProgramId);
|
|
168
168
|
const [tokenVolume] = getTokenVolumePDA(
|
|
169
169
|
baseMint,
|
|
170
|
-
config.liquidStateProgramId
|
|
170
|
+
config.liquidStateProgramId,
|
|
171
171
|
);
|
|
172
172
|
|
|
173
173
|
return {
|
|
@@ -205,41 +205,41 @@ export interface NativeMigrationPDAs {
|
|
|
205
205
|
*/
|
|
206
206
|
export const getNativeMigrationPDAs = (
|
|
207
207
|
tokenMint: PublicKey,
|
|
208
|
-
config: LiquidConfig = MAINNET_CONFIG
|
|
208
|
+
config: LiquidConfig = MAINNET_CONFIG,
|
|
209
209
|
): NativeMigrationPDAs => {
|
|
210
210
|
const [bondingCurve] = getBondingCurvePDA(
|
|
211
211
|
tokenMint,
|
|
212
|
-
config.liquidProgramId
|
|
212
|
+
config.liquidProgramId,
|
|
213
213
|
);
|
|
214
214
|
const [ammPoolState] = getPoolPDA(
|
|
215
215
|
tokenMint,
|
|
216
216
|
WSOL_MINT,
|
|
217
|
-
config.liquidSwapProgramId
|
|
217
|
+
config.liquidSwapProgramId,
|
|
218
218
|
);
|
|
219
219
|
const [ammLpMint] = getPoolLpMintPDA(
|
|
220
220
|
ammPoolState,
|
|
221
|
-
config.liquidSwapProgramId
|
|
221
|
+
config.liquidSwapProgramId,
|
|
222
222
|
);
|
|
223
223
|
const [ammBaseVault] = getPoolVaultPDA(
|
|
224
224
|
ammPoolState,
|
|
225
225
|
tokenMint,
|
|
226
|
-
config.liquidSwapProgramId
|
|
226
|
+
config.liquidSwapProgramId,
|
|
227
227
|
);
|
|
228
228
|
const [ammQuoteVault] = getPoolVaultPDA(
|
|
229
229
|
ammPoolState,
|
|
230
230
|
WSOL_MINT,
|
|
231
|
-
config.liquidSwapProgramId
|
|
231
|
+
config.liquidSwapProgramId,
|
|
232
232
|
);
|
|
233
233
|
const [ammObservation] = getObservationPDA(
|
|
234
234
|
ammPoolState,
|
|
235
|
-
config.liquidSwapProgramId
|
|
235
|
+
config.liquidSwapProgramId,
|
|
236
236
|
);
|
|
237
237
|
const [ammConfig] = getSwapGlobalConfigPDA(config.liquidSwapProgramId);
|
|
238
238
|
const [ammAuthority] = getSwapAuthorityPDA(config.liquidSwapProgramId);
|
|
239
239
|
const [ammBuybackVault] = getSwapBuybackVaultPDA(
|
|
240
240
|
ammPoolState,
|
|
241
241
|
WSOL_MINT,
|
|
242
|
-
config.liquidSwapProgramId
|
|
242
|
+
config.liquidSwapProgramId,
|
|
243
243
|
);
|
|
244
244
|
|
|
245
245
|
return {
|
|
@@ -279,42 +279,41 @@ export interface StableMigrationPDAs {
|
|
|
279
279
|
export const getStableMigrationPDAs = (
|
|
280
280
|
tokenMint: PublicKey,
|
|
281
281
|
quoteMint: PublicKey,
|
|
282
|
-
config: LiquidConfig
|
|
282
|
+
config: LiquidConfig,
|
|
283
283
|
): StableMigrationPDAs => {
|
|
284
284
|
const [bondingCurve] = getStableBondingCurvePDA(
|
|
285
285
|
tokenMint,
|
|
286
|
-
|
|
287
|
-
config.liquidProgramId
|
|
286
|
+
config.liquidProgramId,
|
|
288
287
|
);
|
|
289
288
|
const [ammPoolState] = getPoolPDA(
|
|
290
289
|
tokenMint,
|
|
291
290
|
quoteMint,
|
|
292
|
-
config.liquidSwapProgramId
|
|
291
|
+
config.liquidSwapProgramId,
|
|
293
292
|
);
|
|
294
293
|
const [ammLpMint] = getPoolLpMintPDA(
|
|
295
294
|
ammPoolState,
|
|
296
|
-
config.liquidSwapProgramId
|
|
295
|
+
config.liquidSwapProgramId,
|
|
297
296
|
);
|
|
298
297
|
const [ammBaseVault] = getPoolVaultPDA(
|
|
299
298
|
ammPoolState,
|
|
300
299
|
tokenMint,
|
|
301
|
-
config.liquidSwapProgramId
|
|
300
|
+
config.liquidSwapProgramId,
|
|
302
301
|
);
|
|
303
302
|
const [ammQuoteVault] = getPoolVaultPDA(
|
|
304
303
|
ammPoolState,
|
|
305
304
|
quoteMint,
|
|
306
|
-
config.liquidSwapProgramId
|
|
305
|
+
config.liquidSwapProgramId,
|
|
307
306
|
);
|
|
308
307
|
const [ammObservation] = getObservationPDA(
|
|
309
308
|
ammPoolState,
|
|
310
|
-
config.liquidSwapProgramId
|
|
309
|
+
config.liquidSwapProgramId,
|
|
311
310
|
);
|
|
312
311
|
const [ammConfig] = getSwapGlobalConfigPDA(config.liquidSwapProgramId);
|
|
313
312
|
const [ammAuthority] = getSwapAuthorityPDA(config.liquidSwapProgramId);
|
|
314
313
|
const [ammBuybackVault] = getSwapBuybackVaultPDA(
|
|
315
314
|
ammPoolState,
|
|
316
315
|
quoteMint,
|
|
317
|
-
config.liquidSwapProgramId
|
|
316
|
+
config.liquidSwapProgramId,
|
|
318
317
|
);
|
|
319
318
|
|
|
320
319
|
return {
|
package/src/pda/liquid-fees.ts
CHANGED
|
@@ -13,11 +13,11 @@ const SEED_RECIPIENT_VAULT = Buffer.from("recipient_vault");
|
|
|
13
13
|
*/
|
|
14
14
|
export const getFeeConfigPDA = (
|
|
15
15
|
tokenMint: PublicKey,
|
|
16
|
-
programId: PublicKey
|
|
16
|
+
programId: PublicKey,
|
|
17
17
|
): [PublicKey, number] => {
|
|
18
18
|
return PublicKey.findProgramAddressSync(
|
|
19
19
|
[SEED_FEE_CONFIG, tokenMint.toBuffer()],
|
|
20
|
-
programId
|
|
20
|
+
programId,
|
|
21
21
|
);
|
|
22
22
|
};
|
|
23
23
|
|
|
@@ -30,11 +30,11 @@ export const getFeeConfigPDA = (
|
|
|
30
30
|
*/
|
|
31
31
|
export const getFeeVaultPDA = (
|
|
32
32
|
feeConfig: PublicKey,
|
|
33
|
-
programId: PublicKey
|
|
33
|
+
programId: PublicKey,
|
|
34
34
|
): [PublicKey, number] => {
|
|
35
35
|
return PublicKey.findProgramAddressSync(
|
|
36
36
|
[SEED_FEE_VAULT, feeConfig.toBuffer()],
|
|
37
|
-
programId
|
|
37
|
+
programId,
|
|
38
38
|
);
|
|
39
39
|
};
|
|
40
40
|
|
|
@@ -49,10 +49,10 @@ export const getFeeVaultPDA = (
|
|
|
49
49
|
export const getRecipientVaultPDA = (
|
|
50
50
|
feeConfig: PublicKey,
|
|
51
51
|
recipient: PublicKey,
|
|
52
|
-
programId: PublicKey
|
|
52
|
+
programId: PublicKey,
|
|
53
53
|
): [PublicKey, number] => {
|
|
54
54
|
return PublicKey.findProgramAddressSync(
|
|
55
55
|
[SEED_RECIPIENT_VAULT, feeConfig.toBuffer(), recipient.toBuffer()],
|
|
56
|
-
programId
|
|
56
|
+
programId,
|
|
57
57
|
);
|
|
58
58
|
};
|
package/src/pda/liquid-state.ts
CHANGED
|
@@ -17,11 +17,11 @@ const SEED_DEAL = Buffer.from("deal");
|
|
|
17
17
|
*/
|
|
18
18
|
export const getUserPropertiesPDA = (
|
|
19
19
|
user: PublicKey,
|
|
20
|
-
programId: PublicKey
|
|
20
|
+
programId: PublicKey,
|
|
21
21
|
): [PublicKey, number] => {
|
|
22
22
|
return PublicKey.findProgramAddressSync(
|
|
23
23
|
[SEED_USER_PROPERTIES, user.toBuffer()],
|
|
24
|
-
programId
|
|
24
|
+
programId,
|
|
25
25
|
);
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -32,11 +32,11 @@ export const getUserPropertiesPDA = (
|
|
|
32
32
|
* @returns Tuple of [PDA address, bump seed]
|
|
33
33
|
*/
|
|
34
34
|
export const getGlobalCurveVolumePDA = (
|
|
35
|
-
programId: PublicKey
|
|
35
|
+
programId: PublicKey,
|
|
36
36
|
): [PublicKey, number] => {
|
|
37
37
|
return PublicKey.findProgramAddressSync(
|
|
38
38
|
[SEED_GLOBAL_CURVE_VOLUME],
|
|
39
|
-
programId
|
|
39
|
+
programId,
|
|
40
40
|
);
|
|
41
41
|
};
|
|
42
42
|
|
|
@@ -47,11 +47,11 @@ export const getGlobalCurveVolumePDA = (
|
|
|
47
47
|
* @returns Tuple of [PDA address, bump seed]
|
|
48
48
|
*/
|
|
49
49
|
export const getGlobalAmmVolumePDA = (
|
|
50
|
-
programId: PublicKey
|
|
50
|
+
programId: PublicKey,
|
|
51
51
|
): [PublicKey, number] => {
|
|
52
52
|
return PublicKey.findProgramAddressSync(
|
|
53
53
|
[SEED_GLOBAL_AMM_VOLUME],
|
|
54
|
-
programId
|
|
54
|
+
programId,
|
|
55
55
|
);
|
|
56
56
|
};
|
|
57
57
|
|
|
@@ -64,11 +64,11 @@ export const getGlobalAmmVolumePDA = (
|
|
|
64
64
|
*/
|
|
65
65
|
export const getTokenVolumePDA = (
|
|
66
66
|
mint: PublicKey,
|
|
67
|
-
programId: PublicKey
|
|
67
|
+
programId: PublicKey,
|
|
68
68
|
): [PublicKey, number] => {
|
|
69
69
|
return PublicKey.findProgramAddressSync(
|
|
70
70
|
[SEED_TOKEN_VOLUME, mint.toBuffer()],
|
|
71
|
-
programId
|
|
71
|
+
programId,
|
|
72
72
|
);
|
|
73
73
|
};
|
|
74
74
|
|
|
@@ -79,7 +79,7 @@ export const getTokenVolumePDA = (
|
|
|
79
79
|
* @returns Tuple of [PDA address, bump seed]
|
|
80
80
|
*/
|
|
81
81
|
export const getCashbackConfigPDA = (
|
|
82
|
-
programId: PublicKey
|
|
82
|
+
programId: PublicKey,
|
|
83
83
|
): [PublicKey, number] => {
|
|
84
84
|
return PublicKey.findProgramAddressSync([SEED_CASHBACK_CONFIG], programId);
|
|
85
85
|
};
|
|
@@ -95,13 +95,13 @@ export const getCashbackConfigPDA = (
|
|
|
95
95
|
export const getUserSnapshotPDA = (
|
|
96
96
|
user: PublicKey,
|
|
97
97
|
index: number,
|
|
98
|
-
programId: PublicKey
|
|
98
|
+
programId: PublicKey,
|
|
99
99
|
): [PublicKey, number] => {
|
|
100
100
|
const indexBuffer = Buffer.alloc(4);
|
|
101
101
|
indexBuffer.writeUInt32LE(index);
|
|
102
102
|
return PublicKey.findProgramAddressSync(
|
|
103
103
|
[SEED_USER_SNAPSHOT, user.toBuffer(), indexBuffer],
|
|
104
|
-
programId
|
|
104
|
+
programId,
|
|
105
105
|
);
|
|
106
106
|
};
|
|
107
107
|
|
|
@@ -114,10 +114,10 @@ export const getUserSnapshotPDA = (
|
|
|
114
114
|
*/
|
|
115
115
|
export const getDealPDA = (
|
|
116
116
|
owner: PublicKey,
|
|
117
|
-
programId: PublicKey
|
|
117
|
+
programId: PublicKey,
|
|
118
118
|
): [PublicKey, number] => {
|
|
119
119
|
return PublicKey.findProgramAddressSync(
|
|
120
120
|
[SEED_DEAL, owner.toBuffer()],
|
|
121
|
-
programId
|
|
121
|
+
programId,
|
|
122
122
|
);
|
|
123
123
|
};
|
package/src/pda/liquid-swap.ts
CHANGED
|
@@ -17,7 +17,7 @@ const SEED_BUYBACK_VAULT = Buffer.from("buyback_vault");
|
|
|
17
17
|
* @returns Tuple of [PDA address, bump seed]
|
|
18
18
|
*/
|
|
19
19
|
export const getSwapGlobalConfigPDA = (
|
|
20
|
-
programId: PublicKey
|
|
20
|
+
programId: PublicKey,
|
|
21
21
|
): [PublicKey, number] => {
|
|
22
22
|
return PublicKey.findProgramAddressSync([SEED_GLOBAL_CONFIG], programId);
|
|
23
23
|
};
|
|
@@ -29,7 +29,7 @@ export const getSwapGlobalConfigPDA = (
|
|
|
29
29
|
* @returns Tuple of [PDA address, bump seed]
|
|
30
30
|
*/
|
|
31
31
|
export const getSwapAuthorityPDA = (
|
|
32
|
-
programId: PublicKey
|
|
32
|
+
programId: PublicKey,
|
|
33
33
|
): [PublicKey, number] => {
|
|
34
34
|
return PublicKey.findProgramAddressSync([AUTH_SEED], programId);
|
|
35
35
|
};
|
|
@@ -45,11 +45,11 @@ export const getSwapAuthorityPDA = (
|
|
|
45
45
|
export const getPoolPDA = (
|
|
46
46
|
baseMint: PublicKey,
|
|
47
47
|
quoteMint: PublicKey,
|
|
48
|
-
programId: PublicKey
|
|
48
|
+
programId: PublicKey,
|
|
49
49
|
): [PublicKey, number] => {
|
|
50
50
|
return PublicKey.findProgramAddressSync(
|
|
51
51
|
[POOL_SEED, baseMint.toBuffer(), quoteMint.toBuffer()],
|
|
52
|
-
programId
|
|
52
|
+
programId,
|
|
53
53
|
);
|
|
54
54
|
};
|
|
55
55
|
|
|
@@ -62,11 +62,11 @@ export const getPoolPDA = (
|
|
|
62
62
|
*/
|
|
63
63
|
export const getPoolLpMintPDA = (
|
|
64
64
|
poolState: PublicKey,
|
|
65
|
-
programId: PublicKey
|
|
65
|
+
programId: PublicKey,
|
|
66
66
|
): [PublicKey, number] => {
|
|
67
67
|
return PublicKey.findProgramAddressSync(
|
|
68
68
|
[POOL_LP_MINT_SEED, poolState.toBuffer()],
|
|
69
|
-
programId
|
|
69
|
+
programId,
|
|
70
70
|
);
|
|
71
71
|
};
|
|
72
72
|
|
|
@@ -81,11 +81,11 @@ export const getPoolLpMintPDA = (
|
|
|
81
81
|
export const getPoolVaultPDA = (
|
|
82
82
|
poolState: PublicKey,
|
|
83
83
|
mint: PublicKey,
|
|
84
|
-
programId: PublicKey
|
|
84
|
+
programId: PublicKey,
|
|
85
85
|
): [PublicKey, number] => {
|
|
86
86
|
return PublicKey.findProgramAddressSync(
|
|
87
87
|
[POOL_VAULT_SEED, poolState.toBuffer(), mint.toBuffer()],
|
|
88
|
-
programId
|
|
88
|
+
programId,
|
|
89
89
|
);
|
|
90
90
|
};
|
|
91
91
|
|
|
@@ -98,11 +98,11 @@ export const getPoolVaultPDA = (
|
|
|
98
98
|
*/
|
|
99
99
|
export const getObservationPDA = (
|
|
100
100
|
poolState: PublicKey,
|
|
101
|
-
programId: PublicKey
|
|
101
|
+
programId: PublicKey,
|
|
102
102
|
): [PublicKey, number] => {
|
|
103
103
|
return PublicKey.findProgramAddressSync(
|
|
104
104
|
[OBSERVATION_SEED, poolState.toBuffer()],
|
|
105
|
-
programId
|
|
105
|
+
programId,
|
|
106
106
|
);
|
|
107
107
|
};
|
|
108
108
|
|
|
@@ -117,11 +117,11 @@ export const getObservationPDA = (
|
|
|
117
117
|
export const getProtocolFeeVaultPDA = (
|
|
118
118
|
feeRecipient: PublicKey,
|
|
119
119
|
quoteMint: PublicKey,
|
|
120
|
-
programId: PublicKey
|
|
120
|
+
programId: PublicKey,
|
|
121
121
|
): [PublicKey, number] => {
|
|
122
122
|
return PublicKey.findProgramAddressSync(
|
|
123
123
|
[GLOBAL_FEE_SEED, feeRecipient.toBuffer(), quoteMint.toBuffer()],
|
|
124
|
-
programId
|
|
124
|
+
programId,
|
|
125
125
|
);
|
|
126
126
|
};
|
|
127
127
|
|
|
@@ -134,11 +134,11 @@ export const getProtocolFeeVaultPDA = (
|
|
|
134
134
|
*/
|
|
135
135
|
export const getTempWsolPDA = (
|
|
136
136
|
poolState: PublicKey,
|
|
137
|
-
programId: PublicKey
|
|
137
|
+
programId: PublicKey,
|
|
138
138
|
): [PublicKey, number] => {
|
|
139
139
|
return PublicKey.findProgramAddressSync(
|
|
140
140
|
[SEED_TEMP_WSOL, poolState.toBuffer()],
|
|
141
|
-
programId
|
|
141
|
+
programId,
|
|
142
142
|
);
|
|
143
143
|
};
|
|
144
144
|
|
|
@@ -153,10 +153,10 @@ export const getTempWsolPDA = (
|
|
|
153
153
|
export const getSwapBuybackVaultPDA = (
|
|
154
154
|
poolState: PublicKey,
|
|
155
155
|
quoteMint: PublicKey,
|
|
156
|
-
programId: PublicKey
|
|
156
|
+
programId: PublicKey,
|
|
157
157
|
): [PublicKey, number] => {
|
|
158
158
|
return PublicKey.findProgramAddressSync(
|
|
159
159
|
[SEED_BUYBACK_VAULT, poolState.toBuffer(), quoteMint.toBuffer()],
|
|
160
|
-
programId
|
|
160
|
+
programId,
|
|
161
161
|
);
|
|
162
162
|
};
|
package/src/pda/liquid.ts
CHANGED
|
@@ -19,7 +19,7 @@ const SEED_TOKEN_BONDING_CURVE = Buffer.from("token_bonding_curve");
|
|
|
19
19
|
* @returns Tuple of [PDA address, bump seed]
|
|
20
20
|
*/
|
|
21
21
|
export const getLiquidGlobalConfigPDA = (
|
|
22
|
-
programId: PublicKey
|
|
22
|
+
programId: PublicKey,
|
|
23
23
|
): [PublicKey, number] => {
|
|
24
24
|
return PublicKey.findProgramAddressSync([SEED_GLOBAL_CONFIG], programId);
|
|
25
25
|
};
|
|
@@ -33,11 +33,11 @@ export const getLiquidGlobalConfigPDA = (
|
|
|
33
33
|
*/
|
|
34
34
|
export const getBondingCurvePDA = (
|
|
35
35
|
mint: PublicKey,
|
|
36
|
-
programId: PublicKey
|
|
36
|
+
programId: PublicKey,
|
|
37
37
|
): [PublicKey, number] => {
|
|
38
38
|
return PublicKey.findProgramAddressSync(
|
|
39
39
|
[SEED_BONDING_CURVE, mint.toBuffer()],
|
|
40
|
-
programId
|
|
40
|
+
programId,
|
|
41
41
|
);
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -50,11 +50,11 @@ export const getBondingCurvePDA = (
|
|
|
50
50
|
*/
|
|
51
51
|
export const getBondingCurveSolVaultPDA = (
|
|
52
52
|
bondingCurve: PublicKey,
|
|
53
|
-
programId: PublicKey
|
|
53
|
+
programId: PublicKey,
|
|
54
54
|
): [PublicKey, number] => {
|
|
55
55
|
return PublicKey.findProgramAddressSync(
|
|
56
56
|
[SEED_BONDING_CURVE_SOL_VAULT, bondingCurve.toBuffer()],
|
|
57
|
-
programId
|
|
57
|
+
programId,
|
|
58
58
|
);
|
|
59
59
|
};
|
|
60
60
|
|
|
@@ -67,11 +67,11 @@ export const getBondingCurveSolVaultPDA = (
|
|
|
67
67
|
*/
|
|
68
68
|
export const getReferralVaultPDA = (
|
|
69
69
|
referrer: PublicKey,
|
|
70
|
-
programId: PublicKey
|
|
70
|
+
programId: PublicKey,
|
|
71
71
|
): [PublicKey, number] => {
|
|
72
72
|
return PublicKey.findProgramAddressSync(
|
|
73
73
|
[SEED_REFERRAL_VAULT, referrer.toBuffer()],
|
|
74
|
-
programId
|
|
74
|
+
programId,
|
|
75
75
|
);
|
|
76
76
|
};
|
|
77
77
|
|
|
@@ -84,13 +84,13 @@ export const getReferralVaultPDA = (
|
|
|
84
84
|
*/
|
|
85
85
|
export const getReferralTokenVault = (
|
|
86
86
|
referrer: PublicKey,
|
|
87
|
-
quoteMint: PublicKey
|
|
87
|
+
quoteMint: PublicKey,
|
|
88
88
|
): PublicKey => {
|
|
89
89
|
return getAssociatedTokenAddressSync(
|
|
90
90
|
quoteMint,
|
|
91
91
|
referrer,
|
|
92
92
|
false,
|
|
93
|
-
TOKEN_PROGRAM_ID
|
|
93
|
+
TOKEN_PROGRAM_ID,
|
|
94
94
|
);
|
|
95
95
|
};
|
|
96
96
|
|
|
@@ -103,30 +103,28 @@ export const getReferralTokenVault = (
|
|
|
103
103
|
*/
|
|
104
104
|
export const getBuybackVaultPDA = (
|
|
105
105
|
bondingCurve: PublicKey,
|
|
106
|
-
programId: PublicKey
|
|
106
|
+
programId: PublicKey,
|
|
107
107
|
): [PublicKey, number] => {
|
|
108
108
|
return PublicKey.findProgramAddressSync(
|
|
109
109
|
[SEED_BUYBACK_VAULT, bondingCurve.toBuffer()],
|
|
110
|
-
programId
|
|
110
|
+
programId,
|
|
111
111
|
);
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
* Derives the token-based bonding curve PDA for a token mint
|
|
115
|
+
* Derives the token-based bonding curve PDA for a token mint.
|
|
116
116
|
*
|
|
117
117
|
* @param mint - Token mint address
|
|
118
|
-
* @param quoteMint - Quote token mint address
|
|
119
118
|
* @param programId - Liquid program ID
|
|
120
119
|
* @returns Tuple of [PDA address, bump seed]
|
|
121
120
|
*/
|
|
122
121
|
export const getStableBondingCurvePDA = (
|
|
123
122
|
mint: PublicKey,
|
|
124
|
-
|
|
125
|
-
programId: PublicKey
|
|
123
|
+
programId: PublicKey,
|
|
126
124
|
): [PublicKey, number] => {
|
|
127
125
|
return PublicKey.findProgramAddressSync(
|
|
128
|
-
[SEED_TOKEN_BONDING_CURVE, mint.toBuffer()
|
|
129
|
-
programId
|
|
126
|
+
[SEED_TOKEN_BONDING_CURVE, mint.toBuffer()],
|
|
127
|
+
programId,
|
|
130
128
|
);
|
|
131
129
|
};
|
|
132
130
|
|
|
@@ -140,13 +138,13 @@ export const getStableBondingCurvePDA = (
|
|
|
140
138
|
*/
|
|
141
139
|
export const getBondingCurveTokenAccount = (
|
|
142
140
|
mint: PublicKey,
|
|
143
|
-
programId: PublicKey
|
|
141
|
+
programId: PublicKey,
|
|
144
142
|
): PublicKey => {
|
|
145
143
|
const [bondingCurve] = getBondingCurvePDA(mint, programId);
|
|
146
144
|
return getAssociatedTokenAddressSync(
|
|
147
145
|
mint,
|
|
148
146
|
bondingCurve,
|
|
149
147
|
true,
|
|
150
|
-
TOKEN_2022_PROGRAM_ID
|
|
148
|
+
TOKEN_2022_PROGRAM_ID,
|
|
151
149
|
);
|
|
152
150
|
};
|
package/src/provider.ts
CHANGED
|
@@ -16,14 +16,14 @@ export class ReadonlyWallet {
|
|
|
16
16
|
|
|
17
17
|
/** @throws Always throws — signing is not supported on a read-only wallet. */
|
|
18
18
|
async signTransaction<T extends Transaction | VersionedTransaction>(
|
|
19
|
-
_tx: T
|
|
19
|
+
_tx: T,
|
|
20
20
|
): Promise<T> {
|
|
21
21
|
throw new Error("Cannot sign with a readonly provider");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/** @throws Always throws — signing is not supported on a read-only wallet. */
|
|
25
25
|
async signAllTransactions<T extends Transaction | VersionedTransaction>(
|
|
26
|
-
_txs: T[]
|
|
26
|
+
_txs: T[],
|
|
27
27
|
): Promise<T[]> {
|
|
28
28
|
throw new Error("Cannot sign with a readonly provider");
|
|
29
29
|
}
|