@liquid-af/sdk 0.4.1 → 0.5.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.
- package/dist/client.d.ts +7 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -3
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/events/parser.d.ts +8 -3
- package/dist/events/parser.d.ts.map +1 -1
- package/dist/events/parser.js +72 -17
- package/dist/events/parser.js.map +1 -1
- package/dist/idl/index.d.ts +12 -1
- package/dist/idl/index.d.ts.map +1 -1
- package/dist/idl/index.js +12 -1
- package/dist/idl/index.js.map +1 -1
- package/dist/idl/liquid.d.ts +7116 -2254
- package/dist/idl/liquid.d.ts.map +1 -1
- package/dist/idl/liquid.json +7200 -2338
- package/dist/idl/liquid_events.d.ts +3118 -0
- package/dist/idl/liquid_events.d.ts.map +1 -0
- package/dist/idl/liquid_events.js +2 -0
- package/dist/idl/liquid_events.js.map +1 -0
- package/dist/idl/liquid_events.json +3111 -0
- package/dist/idl/liquid_fees.d.ts +539 -0
- package/dist/idl/liquid_fees.d.ts.map +1 -1
- package/dist/idl/liquid_fees.json +539 -0
- package/dist/idl/liquid_state.d.ts +350 -0
- package/dist/idl/liquid_state.d.ts.map +1 -1
- package/dist/idl/liquid_state.json +350 -0
- package/dist/idl/liquid_swap.d.ts +1334 -17
- package/dist/idl/liquid_swap.d.ts.map +1 -1
- package/dist/idl/liquid_swap.json +1334 -17
- package/dist/idl/patch-idl.d.ts.map +1 -1
- package/dist/idl/patch-idl.js +1 -0
- package/dist/idl/patch-idl.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instructions/index.d.ts +4 -4
- package/dist/instructions/index.d.ts.map +1 -1
- package/dist/instructions/index.js +2 -2
- package/dist/instructions/index.js.map +1 -1
- package/dist/instructions/liquid-fees.d.ts +12 -0
- package/dist/instructions/liquid-fees.d.ts.map +1 -1
- package/dist/instructions/liquid-fees.js +17 -0
- package/dist/instructions/liquid-fees.js.map +1 -1
- package/dist/instructions/liquid.d.ts +15 -1
- package/dist/instructions/liquid.d.ts.map +1 -1
- package/dist/instructions/liquid.js +32 -2
- package/dist/instructions/liquid.js.map +1 -1
- package/dist/pda/index.d.ts +2 -2
- package/dist/pda/index.d.ts.map +1 -1
- package/dist/pda/index.js +2 -2
- package/dist/pda/index.js.map +1 -1
- package/dist/pda/liquid-fees.d.ts +7 -0
- package/dist/pda/liquid-fees.d.ts.map +1 -1
- package/dist/pda/liquid-fees.js +10 -0
- package/dist/pda/liquid-fees.js.map +1 -1
- package/dist/pda/liquid.d.ts +10 -3
- package/dist/pda/liquid.d.ts.map +1 -1
- package/dist/pda/liquid.js +14 -5
- package/dist/pda/liquid.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +14 -2
- package/src/config.ts +8 -0
- package/src/events/parser.ts +88 -19
- package/src/idl/index.ts +26 -1
- package/src/idl/liquid.json +7200 -2338
- package/src/idl/liquid.ts +7200 -2338
- package/src/idl/liquid_events.json +3111 -0
- package/src/idl/liquid_events.ts +3117 -0
- package/src/idl/liquid_fees.json +539 -0
- package/src/idl/liquid_fees.ts +539 -0
- package/src/idl/liquid_state.json +350 -0
- package/src/idl/liquid_state.ts +350 -0
- package/src/idl/liquid_swap.json +1334 -17
- package/src/idl/liquid_swap.ts +1334 -17
- package/src/idl/patch-idl.ts +1 -0
- package/src/index.ts +3 -0
- package/src/instructions/index.ts +4 -0
- package/src/instructions/liquid-fees.ts +26 -0
- package/src/instructions/liquid.ts +70 -1
- package/src/pda/index.ts +2 -0
- package/src/pda/liquid-fees.ts +13 -0
- package/src/pda/liquid.ts +21 -9
package/src/idl/patch-idl.ts
CHANGED
|
@@ -14,6 +14,7 @@ function buildReplacementMap(config: LiquidConfig): ProgramReplacement[] {
|
|
|
14
14
|
[MAINNET_CONFIG.liquidSwapProgramId, config.liquidSwapProgramId],
|
|
15
15
|
[MAINNET_CONFIG.liquidFeesProgramId, config.liquidFeesProgramId],
|
|
16
16
|
[MAINNET_CONFIG.liquidStateProgramId, config.liquidStateProgramId],
|
|
17
|
+
[MAINNET_CONFIG.liquidEventsProgramId, config.liquidEventsProgramId],
|
|
17
18
|
];
|
|
18
19
|
return pairs
|
|
19
20
|
.filter(([mainnet, target]) => !mainnet.equals(target))
|
package/src/index.ts
CHANGED
|
@@ -90,15 +90,18 @@ export type {
|
|
|
90
90
|
LiquidSwap,
|
|
91
91
|
LiquidFees,
|
|
92
92
|
LiquidState,
|
|
93
|
+
LiquidEvents,
|
|
93
94
|
} from "./idl/index.js";
|
|
94
95
|
export {
|
|
95
96
|
getLiquidProgram,
|
|
96
97
|
getLiquidSwapProgram,
|
|
97
98
|
getLiquidFeesProgram,
|
|
98
99
|
getLiquidStateProgram,
|
|
100
|
+
getLiquidEventsProgram,
|
|
99
101
|
liquidIdl,
|
|
100
102
|
liquidSwapIdl,
|
|
101
103
|
liquidFeesIdl,
|
|
102
104
|
liquidStateIdl,
|
|
105
|
+
liquidEventsIdl,
|
|
103
106
|
patchIdl,
|
|
104
107
|
} from "./idl/index.js";
|
|
@@ -8,6 +8,7 @@ export {
|
|
|
8
8
|
buildMigrateNative,
|
|
9
9
|
buildInitializeNativeReferralVault,
|
|
10
10
|
buildWithdrawReferralRewards,
|
|
11
|
+
buildWithdrawReferralTokenRewards,
|
|
11
12
|
buildExecuteBuybackNative,
|
|
12
13
|
buildExecuteBuybackToken,
|
|
13
14
|
// Stable curve builders
|
|
@@ -28,6 +29,7 @@ export type {
|
|
|
28
29
|
BuildMigrateNativeParams,
|
|
29
30
|
BuildInitializeNativeReferralVaultParams,
|
|
30
31
|
BuildWithdrawReferralRewardsParams,
|
|
32
|
+
BuildWithdrawReferralTokenRewardsParams,
|
|
31
33
|
BuildExecuteBuybackNativeParams,
|
|
32
34
|
BuildExecuteBuybackTokenParams,
|
|
33
35
|
// Stable curve param types
|
|
@@ -57,6 +59,7 @@ export type {
|
|
|
57
59
|
} from "./liquid-swap.js";
|
|
58
60
|
|
|
59
61
|
export {
|
|
62
|
+
buildInitializeGlobalConfig,
|
|
60
63
|
buildUpdateFeeConfig,
|
|
61
64
|
buildRevokeFeeConfig,
|
|
62
65
|
buildDistributeFees,
|
|
@@ -66,6 +69,7 @@ export {
|
|
|
66
69
|
deriveRecipientVaultPairs,
|
|
67
70
|
} from "./liquid-fees.js";
|
|
68
71
|
export type {
|
|
72
|
+
BuildInitializeGlobalConfigParams,
|
|
69
73
|
BuildUpdateFeeConfigParams,
|
|
70
74
|
BuildRevokeFeeConfigParams,
|
|
71
75
|
BuildDistributeFeesParams,
|
|
@@ -260,6 +260,32 @@ export function buildClaimTokenFees(
|
|
|
260
260
|
.instruction();
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
export interface BuildInitializeGlobalConfigParams {
|
|
264
|
+
admin: PublicKey;
|
|
265
|
+
config: LiquidConfig;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Builds an initializeGlobalConfig instruction.
|
|
270
|
+
* Creates the global configuration PDA for the liquid-fees program.
|
|
271
|
+
*
|
|
272
|
+
* @param params - {@link BuildInitializeGlobalConfigParams}
|
|
273
|
+
* @returns Transaction instruction
|
|
274
|
+
*/
|
|
275
|
+
export function buildInitializeGlobalConfig(
|
|
276
|
+
params: BuildInitializeGlobalConfigParams,
|
|
277
|
+
): Promise<TransactionInstruction> {
|
|
278
|
+
const { admin, config } = params;
|
|
279
|
+
const program = getCachedFeesProgram(config);
|
|
280
|
+
|
|
281
|
+
return program.methods
|
|
282
|
+
.initializeGlobalConfig()
|
|
283
|
+
.accounts({
|
|
284
|
+
admin,
|
|
285
|
+
})
|
|
286
|
+
.instruction();
|
|
287
|
+
}
|
|
288
|
+
|
|
263
289
|
/**
|
|
264
290
|
* Helper: derives recipient vault PDA pairs for use with buildDistributeTokenFees.
|
|
265
291
|
*
|
|
@@ -12,6 +12,7 @@ import { WSOL_MINT, type LiquidConfig } from "../config.js";
|
|
|
12
12
|
import {
|
|
13
13
|
getBondingCurvePDA,
|
|
14
14
|
getBondingCurveTokenAccount,
|
|
15
|
+
getBuybackVaultPDA,
|
|
15
16
|
getStableBondingCurvePDA,
|
|
16
17
|
} from "../pda/liquid.js";
|
|
17
18
|
import {
|
|
@@ -404,6 +405,42 @@ export function buildWithdrawReferralRewards(
|
|
|
404
405
|
.instruction();
|
|
405
406
|
}
|
|
406
407
|
|
|
408
|
+
export interface BuildWithdrawReferralTokenRewardsParams {
|
|
409
|
+
user: PublicKey;
|
|
410
|
+
quoteMint: PublicKey;
|
|
411
|
+
config: LiquidConfig;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Builds a withdrawReferralTokenRewards instruction.
|
|
416
|
+
* Transfers all accrued token referral rewards from the PDA vault to the user's token account.
|
|
417
|
+
*
|
|
418
|
+
* @param params - {@link BuildWithdrawReferralTokenRewardsParams}
|
|
419
|
+
* @returns Transaction instruction
|
|
420
|
+
*/
|
|
421
|
+
export function buildWithdrawReferralTokenRewards(
|
|
422
|
+
params: BuildWithdrawReferralTokenRewardsParams,
|
|
423
|
+
): Promise<TransactionInstruction> {
|
|
424
|
+
const { user, quoteMint, config } = params;
|
|
425
|
+
const program = getCachedLiquidProgram(config);
|
|
426
|
+
|
|
427
|
+
const userTokenAccount = getAssociatedTokenAddressSync(
|
|
428
|
+
quoteMint,
|
|
429
|
+
user,
|
|
430
|
+
false,
|
|
431
|
+
TOKEN_PROGRAM_ID,
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
return program.methods
|
|
435
|
+
.withdrawReferralTokenRewards()
|
|
436
|
+
.accounts({
|
|
437
|
+
user,
|
|
438
|
+
userTokenAccount,
|
|
439
|
+
quoteMint,
|
|
440
|
+
})
|
|
441
|
+
.instruction();
|
|
442
|
+
}
|
|
443
|
+
|
|
407
444
|
export interface BuildExecuteBuybackNativeParams {
|
|
408
445
|
payer: PublicKey;
|
|
409
446
|
mint: PublicKey;
|
|
@@ -454,12 +491,22 @@ export function buildExecuteBuybackToken(
|
|
|
454
491
|
const { payer, mint, quoteMint, config } = params;
|
|
455
492
|
const program = getCachedLiquidProgram(config);
|
|
456
493
|
|
|
494
|
+
const [bondingCurve] = getStableBondingCurvePDA(
|
|
495
|
+
mint,
|
|
496
|
+
config.liquidProgramId,
|
|
497
|
+
);
|
|
498
|
+
const [buybackVault] = getBuybackVaultPDA(
|
|
499
|
+
bondingCurve,
|
|
500
|
+
config.liquidProgramId,
|
|
501
|
+
);
|
|
502
|
+
|
|
457
503
|
return program.methods
|
|
458
504
|
.executeBuybackToken()
|
|
459
505
|
.accountsPartial({
|
|
460
506
|
payer,
|
|
461
507
|
mint,
|
|
462
508
|
quoteMint,
|
|
509
|
+
buybackVault,
|
|
463
510
|
})
|
|
464
511
|
.instruction();
|
|
465
512
|
}
|
|
@@ -557,6 +604,15 @@ export function buildBuyStable(
|
|
|
557
604
|
config.liquidStateProgramId,
|
|
558
605
|
);
|
|
559
606
|
|
|
607
|
+
const [bondingCurve] = getStableBondingCurvePDA(
|
|
608
|
+
mint,
|
|
609
|
+
config.liquidProgramId,
|
|
610
|
+
);
|
|
611
|
+
const [buybackVault] = getBuybackVaultPDA(
|
|
612
|
+
bondingCurve,
|
|
613
|
+
config.liquidProgramId,
|
|
614
|
+
);
|
|
615
|
+
|
|
560
616
|
return program.methods
|
|
561
617
|
.buyStable(amountIn, minAmountOut)
|
|
562
618
|
.accountsPartial({
|
|
@@ -567,6 +623,7 @@ export function buildBuyStable(
|
|
|
567
623
|
creatorUserProperties,
|
|
568
624
|
creatorReferralVault: creatorReferralVault ?? null,
|
|
569
625
|
traderReferralVault: traderReferralVault ?? null,
|
|
626
|
+
buybackVault,
|
|
570
627
|
liquidState: {
|
|
571
628
|
user,
|
|
572
629
|
tokenMint: mint,
|
|
@@ -647,6 +704,15 @@ export function buildSellStable(
|
|
|
647
704
|
config.liquidStateProgramId,
|
|
648
705
|
);
|
|
649
706
|
|
|
707
|
+
const [bondingCurve] = getStableBondingCurvePDA(
|
|
708
|
+
mint,
|
|
709
|
+
config.liquidProgramId,
|
|
710
|
+
);
|
|
711
|
+
const [buybackVault] = getBuybackVaultPDA(
|
|
712
|
+
bondingCurve,
|
|
713
|
+
config.liquidProgramId,
|
|
714
|
+
);
|
|
715
|
+
|
|
650
716
|
return program.methods
|
|
651
717
|
.sellStable(amountIn, minAmountOut)
|
|
652
718
|
.accountsPartial({
|
|
@@ -657,6 +723,7 @@ export function buildSellStable(
|
|
|
657
723
|
creatorUserProperties,
|
|
658
724
|
creatorReferralVault: creatorReferralVault ?? null,
|
|
659
725
|
traderReferralVault: traderReferralVault ?? null,
|
|
726
|
+
buybackVault,
|
|
660
727
|
liquidState: {
|
|
661
728
|
user,
|
|
662
729
|
tokenMint: mint,
|
|
@@ -749,6 +816,7 @@ export function buildMigrateStable(
|
|
|
749
816
|
quoteMint,
|
|
750
817
|
config.liquidSwapProgramId,
|
|
751
818
|
);
|
|
819
|
+
|
|
752
820
|
return program.methods
|
|
753
821
|
.migrateStable()
|
|
754
822
|
.accounts({
|
|
@@ -820,9 +888,10 @@ export interface BuildInitializeReferralTokenVaultParams {
|
|
|
820
888
|
|
|
821
889
|
/**
|
|
822
890
|
* Builds an initializeReferralTokenVault instruction.
|
|
823
|
-
* Creates a
|
|
891
|
+
* Creates a program-owned PDA token vault for the user for a specific quote mint.
|
|
824
892
|
* Users must call this for each quote mint they want to receive referral rewards for.
|
|
825
893
|
* If not initialized, referral fees will be redirected to protocol fees.
|
|
894
|
+
* This operation is idempotent — safe to call multiple times.
|
|
826
895
|
*
|
|
827
896
|
* @param params - {@link BuildInitializeReferralTokenVaultParams}
|
|
828
897
|
* @returns Transaction instruction
|
package/src/pda/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
getBondingCurveTokenAccount,
|
|
6
6
|
getReferralVaultPDA,
|
|
7
7
|
getReferralTokenVault,
|
|
8
|
+
getReferralTokenVaultPDA,
|
|
8
9
|
getBuybackVaultPDA,
|
|
9
10
|
getStableBondingCurvePDA,
|
|
10
11
|
} from "./liquid.js";
|
|
@@ -23,6 +24,7 @@ export {
|
|
|
23
24
|
|
|
24
25
|
export {
|
|
25
26
|
getFeeConfigPDA,
|
|
27
|
+
getFeeGlobalConfigPDA,
|
|
26
28
|
getFeeVaultPDA,
|
|
27
29
|
getRecipientVaultPDA,
|
|
28
30
|
} from "./liquid-fees.js";
|
package/src/pda/liquid-fees.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
2
2
|
|
|
3
3
|
const SEED_FEE_CONFIG = Buffer.from("fee_config");
|
|
4
4
|
const SEED_FEE_VAULT = Buffer.from("fee_vault");
|
|
5
|
+
const SEED_GLOBAL_CONFIG = Buffer.from("global_config");
|
|
5
6
|
const SEED_RECIPIENT_VAULT = Buffer.from("recipient_vault");
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -21,6 +22,18 @@ export const getFeeConfigPDA = (
|
|
|
21
22
|
);
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Derives the global config PDA for the liquid-fees program.
|
|
27
|
+
*
|
|
28
|
+
* @param programId - Liquid Fees program ID
|
|
29
|
+
* @returns Tuple of [PDA address, bump seed]
|
|
30
|
+
*/
|
|
31
|
+
export const getFeeGlobalConfigPDA = (
|
|
32
|
+
programId: PublicKey,
|
|
33
|
+
): [PublicKey, number] => {
|
|
34
|
+
return PublicKey.findProgramAddressSync([SEED_GLOBAL_CONFIG], programId);
|
|
35
|
+
};
|
|
36
|
+
|
|
24
37
|
/**
|
|
25
38
|
* Derives the fee vault PDA for a fee config.
|
|
26
39
|
*
|
package/src/pda/liquid.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import {
|
|
3
3
|
getAssociatedTokenAddressSync,
|
|
4
|
-
TOKEN_PROGRAM_ID,
|
|
5
4
|
TOKEN_2022_PROGRAM_ID,
|
|
6
5
|
} from "@solana/spl-token";
|
|
7
6
|
|
|
@@ -76,22 +75,35 @@ export const getReferralVaultPDA = (
|
|
|
76
75
|
};
|
|
77
76
|
|
|
78
77
|
/**
|
|
79
|
-
* Derives the referral token vault
|
|
78
|
+
* Derives the referral token vault PDA for stable curve referral rewards.
|
|
79
|
+
* The vault is a program-owned PDA token account (not a user-owned ATA).
|
|
80
80
|
*
|
|
81
81
|
* @param referrer - Referrer's public key
|
|
82
82
|
* @param quoteMint - Quote token mint address
|
|
83
|
-
* @
|
|
83
|
+
* @param programId - Liquid program ID
|
|
84
|
+
* @returns Tuple of [PDA address, bump seed]
|
|
85
|
+
*/
|
|
86
|
+
export const getReferralTokenVaultPDA = (
|
|
87
|
+
referrer: PublicKey,
|
|
88
|
+
quoteMint: PublicKey,
|
|
89
|
+
programId: PublicKey,
|
|
90
|
+
): [PublicKey, number] => {
|
|
91
|
+
return PublicKey.findProgramAddressSync(
|
|
92
|
+
[SEED_REFERRAL_VAULT, referrer.toBuffer(), quoteMint.toBuffer()],
|
|
93
|
+
programId,
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @deprecated Use {@link getReferralTokenVaultPDA} instead. Token referral vaults
|
|
99
|
+
* are now program-owned PDAs, not user-owned ATAs.
|
|
84
100
|
*/
|
|
85
101
|
export const getReferralTokenVault = (
|
|
86
102
|
referrer: PublicKey,
|
|
87
103
|
quoteMint: PublicKey,
|
|
104
|
+
programId: PublicKey,
|
|
88
105
|
): PublicKey => {
|
|
89
|
-
return
|
|
90
|
-
quoteMint,
|
|
91
|
-
referrer,
|
|
92
|
-
false,
|
|
93
|
-
TOKEN_PROGRAM_ID,
|
|
94
|
-
);
|
|
106
|
+
return getReferralTokenVaultPDA(referrer, quoteMint, programId)[0];
|
|
95
107
|
};
|
|
96
108
|
|
|
97
109
|
/**
|