@liquid-af/sdk 0.1.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/README.md +776 -0
- package/dist/accounts/index.d.ts +5 -0
- package/dist/accounts/index.d.ts.map +1 -0
- package/dist/accounts/index.js +5 -0
- package/dist/accounts/index.js.map +1 -0
- package/dist/accounts/liquid-fees.d.ts +63 -0
- package/dist/accounts/liquid-fees.d.ts.map +1 -0
- package/dist/accounts/liquid-fees.js +27 -0
- package/dist/accounts/liquid-fees.js.map +1 -0
- package/dist/accounts/liquid-state.d.ts +112 -0
- package/dist/accounts/liquid-state.d.ts.map +1 -0
- package/dist/accounts/liquid-state.js +92 -0
- package/dist/accounts/liquid-state.js.map +1 -0
- package/dist/accounts/liquid-swap.d.ts +97 -0
- package/dist/accounts/liquid-swap.d.ts.map +1 -0
- package/dist/accounts/liquid-swap.js +54 -0
- package/dist/accounts/liquid-swap.js.map +1 -0
- package/dist/accounts/liquid.d.ts +175 -0
- package/dist/accounts/liquid.d.ts.map +1 -0
- package/dist/accounts/liquid.js +66 -0
- package/dist/accounts/liquid.js.map +1 -0
- package/dist/client.d.ts +621 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +511 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +56 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +63 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/parser.d.ts +40 -0
- package/dist/events/parser.d.ts.map +1 -0
- package/dist/events/parser.js +67 -0
- package/dist/events/parser.js.map +1 -0
- package/dist/events/types.d.ts +286 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +2 -0
- package/dist/events/types.js.map +1 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/preview.d.ts +259 -0
- package/dist/helpers/preview.d.ts.map +1 -0
- package/dist/helpers/preview.js +458 -0
- package/dist/helpers/preview.js.map +1 -0
- package/dist/helpers/user.d.ts +11 -0
- package/dist/helpers/user.d.ts.map +1 -0
- package/dist/helpers/user.js +20 -0
- package/dist/helpers/user.js.map +1 -0
- package/dist/idl/index.d.ts +53 -0
- package/dist/idl/index.d.ts.map +1 -0
- package/dist/idl/index.js +64 -0
- package/dist/idl/index.js.map +1 -0
- package/dist/idl/liquid.d.ts +10523 -0
- package/dist/idl/liquid.d.ts.map +1 -0
- package/dist/idl/liquid.js +2 -0
- package/dist/idl/liquid.js.map +1 -0
- package/dist/idl/liquid.json +10516 -0
- package/dist/idl/liquid_fees.d.ts +1520 -0
- package/dist/idl/liquid_fees.d.ts.map +1 -0
- package/dist/idl/liquid_fees.js +2 -0
- package/dist/idl/liquid_fees.js.map +1 -0
- package/dist/idl/liquid_fees.json +1513 -0
- package/dist/idl/liquid_state.d.ts +2936 -0
- package/dist/idl/liquid_state.d.ts.map +1 -0
- package/dist/idl/liquid_state.js +2 -0
- package/dist/idl/liquid_state.js.map +1 -0
- package/dist/idl/liquid_state.json +2929 -0
- package/dist/idl/liquid_swap.d.ts +5849 -0
- package/dist/idl/liquid_swap.d.ts.map +1 -0
- package/dist/idl/liquid_swap.js +2 -0
- package/dist/idl/liquid_swap.js.map +1 -0
- package/dist/idl/liquid_swap.json +5842 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions/index.d.ts +9 -0
- package/dist/instructions/index.d.ts.map +1 -0
- package/dist/instructions/index.js +9 -0
- package/dist/instructions/index.js.map +1 -0
- package/dist/instructions/liquid-fees.d.ts +111 -0
- package/dist/instructions/liquid-fees.d.ts.map +1 -0
- package/dist/instructions/liquid-fees.js +169 -0
- package/dist/instructions/liquid-fees.js.map +1 -0
- package/dist/instructions/liquid-state.d.ts +173 -0
- package/dist/instructions/liquid-state.d.ts.map +1 -0
- package/dist/instructions/liquid-state.js +194 -0
- package/dist/instructions/liquid-state.js.map +1 -0
- package/dist/instructions/liquid-swap.d.ts +122 -0
- package/dist/instructions/liquid-swap.d.ts.map +1 -0
- package/dist/instructions/liquid-swap.js +167 -0
- package/dist/instructions/liquid-swap.js.map +1 -0
- package/dist/instructions/liquid.d.ts +297 -0
- package/dist/instructions/liquid.d.ts.map +1 -0
- package/dist/instructions/liquid.js +483 -0
- package/dist/instructions/liquid.js.map +1 -0
- package/dist/instructions/program-cache.d.ts +35 -0
- package/dist/instructions/program-cache.d.ts.map +1 -0
- package/dist/instructions/program-cache.js +68 -0
- package/dist/instructions/program-cache.js.map +1 -0
- package/dist/math/amm.d.ts +42 -0
- package/dist/math/amm.d.ts.map +1 -0
- package/dist/math/amm.js +109 -0
- package/dist/math/amm.js.map +1 -0
- package/dist/math/bonding-curve.d.ts +34 -0
- package/dist/math/bonding-curve.d.ts.map +1 -0
- package/dist/math/bonding-curve.js +80 -0
- package/dist/math/bonding-curve.js.map +1 -0
- package/dist/math/constants.d.ts +14 -0
- package/dist/math/constants.d.ts.map +1 -0
- package/dist/math/constants.js +14 -0
- package/dist/math/constants.js.map +1 -0
- package/dist/math/fees.d.ts +88 -0
- package/dist/math/fees.d.ts.map +1 -0
- package/dist/math/fees.js +135 -0
- package/dist/math/fees.js.map +1 -0
- package/dist/math/index.d.ts +8 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +6 -0
- package/dist/math/index.js.map +1 -0
- package/dist/math/tiered-fees.d.ts +80 -0
- package/dist/math/tiered-fees.d.ts.map +1 -0
- package/dist/math/tiered-fees.js +129 -0
- package/dist/math/tiered-fees.js.map +1 -0
- package/dist/oracle.d.ts +53 -0
- package/dist/oracle.d.ts.map +1 -0
- package/dist/oracle.js +70 -0
- package/dist/oracle.js.map +1 -0
- package/dist/pda/index.d.ts +89 -0
- package/dist/pda/index.d.ts.map +1 -0
- package/dist/pda/index.js +127 -0
- package/dist/pda/index.js.map +1 -0
- package/dist/pda/liquid-fees.d.ts +27 -0
- package/dist/pda/liquid-fees.d.ts.map +1 -0
- package/dist/pda/liquid-fees.js +36 -0
- package/dist/pda/liquid-fees.js.map +1 -0
- package/dist/pda/liquid-state.d.ts +56 -0
- package/dist/pda/liquid-state.d.ts.map +1 -0
- package/dist/pda/liquid-state.js +79 -0
- package/dist/pda/liquid-state.js.map +1 -0
- package/dist/pda/liquid-swap.d.ts +76 -0
- package/dist/pda/liquid-swap.d.ts.map +1 -0
- package/dist/pda/liquid-swap.js +103 -0
- package/dist/pda/liquid-swap.js.map +1 -0
- package/dist/pda/liquid.d.ts +67 -0
- package/dist/pda/liquid.d.ts.map +1 -0
- package/dist/pda/liquid.js +91 -0
- package/dist/pda/liquid.js.map +1 -0
- package/dist/provider.d.ts +26 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +47 -0
- package/dist/provider.js.map +1 -0
- package/dist/transaction/builder.d.ts +30 -0
- package/dist/transaction/builder.d.ts.map +1 -0
- package/dist/transaction/builder.js +48 -0
- package/dist/transaction/builder.js.map +1 -0
- package/dist/transaction/index.d.ts +3 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +3 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/send.d.ts +25 -0
- package/dist/transaction/send.d.ts.map +1 -0
- package/dist/transaction/send.js +52 -0
- package/dist/transaction/send.js.map +1 -0
- package/dist/types.d.ts +311 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +46 -0
- package/dist/types.js.map +1 -0
- package/package.json +112 -0
- package/src/accounts/index.ts +26 -0
- package/src/accounts/liquid-fees.ts +38 -0
- package/src/accounts/liquid-state.ts +134 -0
- package/src/accounts/liquid-swap.ts +79 -0
- package/src/accounts/liquid.ts +100 -0
- package/src/client.ts +1001 -0
- package/src/config.ts +91 -0
- package/src/errors.ts +94 -0
- package/src/events/index.ts +42 -0
- package/src/events/parser.ts +90 -0
- package/src/events/types.ts +310 -0
- package/src/helpers/index.ts +23 -0
- package/src/helpers/preview.ts +798 -0
- package/src/helpers/user.ts +24 -0
- package/src/idl/index.ts +94 -0
- package/src/idl/liquid.json +10516 -0
- package/src/idl/liquid.ts +10522 -0
- package/src/idl/liquid_fees.json +1513 -0
- package/src/idl/liquid_fees.ts +1519 -0
- package/src/idl/liquid_state.json +2929 -0
- package/src/idl/liquid_state.ts +2935 -0
- package/src/idl/liquid_swap.json +5842 -0
- package/src/idl/liquid_swap.ts +5848 -0
- package/src/index.ts +98 -0
- package/src/instructions/index.ts +109 -0
- package/src/instructions/liquid-fees.ts +289 -0
- package/src/instructions/liquid-state.ts +336 -0
- package/src/instructions/liquid-swap.ts +414 -0
- package/src/instructions/liquid.ts +884 -0
- package/src/instructions/program-cache.ts +106 -0
- package/src/math/amm.ts +146 -0
- package/src/math/bonding-curve.ts +122 -0
- package/src/math/constants.ts +19 -0
- package/src/math/fees.ts +191 -0
- package/src/math/index.ts +40 -0
- package/src/math/tiered-fees.ts +165 -0
- package/src/oracle.ts +97 -0
- package/src/pda/index.ts +331 -0
- package/src/pda/liquid-fees.ts +58 -0
- package/src/pda/liquid-state.ts +123 -0
- package/src/pda/liquid-swap.ts +162 -0
- package/src/pda/liquid.ts +152 -0
- package/src/provider.ts +60 -0
- package/src/transaction/builder.ts +80 -0
- package/src/transaction/index.ts +6 -0
- package/src/transaction/send.ts +72 -0
- package/src/types.ts +354 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export { LiquidClient } from "./client.js";
|
|
2
|
+
export type { LiquidClientConfig } from "./client.js";
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
ReadonlyWallet,
|
|
6
|
+
createReadonlyProvider,
|
|
7
|
+
createStubProvider,
|
|
8
|
+
} from "./provider.js";
|
|
9
|
+
|
|
10
|
+
export { LiquidError, LiquidErrorCode } from "./errors.js";
|
|
11
|
+
|
|
12
|
+
export type { LiquidConfig } from "./config.js";
|
|
13
|
+
export {
|
|
14
|
+
MAINNET_CONFIG,
|
|
15
|
+
DEVNET_CONFIG,
|
|
16
|
+
LOCALNET_CONFIG,
|
|
17
|
+
WSOL_MINT,
|
|
18
|
+
BPS_DENOMINATOR,
|
|
19
|
+
NUM_FEE_RECIPIENTS,
|
|
20
|
+
MAX_FEE_RECIPIENTS_FEES,
|
|
21
|
+
MAX_QUOTE_MINTS,
|
|
22
|
+
MAX_CASHBACK_RANGES,
|
|
23
|
+
MIN_MULTIPLIER_BPS,
|
|
24
|
+
MAX_MULTIPLIER_BPS,
|
|
25
|
+
MIN_VAULT_BALANCE,
|
|
26
|
+
LIMITS,
|
|
27
|
+
} from "./config.js";
|
|
28
|
+
|
|
29
|
+
export type {
|
|
30
|
+
GlobalConfiguration,
|
|
31
|
+
BondingCurveState,
|
|
32
|
+
AmmConfig,
|
|
33
|
+
FeeTier,
|
|
34
|
+
PoolState,
|
|
35
|
+
Observation,
|
|
36
|
+
ObservationState,
|
|
37
|
+
UnifiedFeeConfiguration,
|
|
38
|
+
UserProperties,
|
|
39
|
+
ReferrerInfo,
|
|
40
|
+
UserSnapshot,
|
|
41
|
+
Deal,
|
|
42
|
+
AdminUpdateUserArgs,
|
|
43
|
+
TokenVolumeAccumulator,
|
|
44
|
+
GlobalCurveVolume,
|
|
45
|
+
GlobalAmmVolume,
|
|
46
|
+
CashbackRange,
|
|
47
|
+
CashbackConfiguration,
|
|
48
|
+
FeeDistribution,
|
|
49
|
+
BondingCurveBuyResult,
|
|
50
|
+
BondingCurveSellResult,
|
|
51
|
+
SwapFees,
|
|
52
|
+
AmmSellOutput,
|
|
53
|
+
AmmBuyInput,
|
|
54
|
+
LpTokenAmounts,
|
|
55
|
+
DistributionResult,
|
|
56
|
+
PoolInfo,
|
|
57
|
+
BuyCurvePreview,
|
|
58
|
+
SellCurvePreview,
|
|
59
|
+
SwapPreview,
|
|
60
|
+
FeeRecipient,
|
|
61
|
+
FeeModeAnchor,
|
|
62
|
+
CurveStatusAnchor,
|
|
63
|
+
} from "./types.js";
|
|
64
|
+
export {
|
|
65
|
+
FeeMode,
|
|
66
|
+
toAnchorFeeMode,
|
|
67
|
+
feeModeEquals,
|
|
68
|
+
CurveStatus,
|
|
69
|
+
curveStatusEquals,
|
|
70
|
+
} from "./types.js";
|
|
71
|
+
|
|
72
|
+
export * from "./pda/index.js";
|
|
73
|
+
|
|
74
|
+
export * from "./math/index.js";
|
|
75
|
+
|
|
76
|
+
export * from "./accounts/index.js";
|
|
77
|
+
|
|
78
|
+
export * from "./instructions/index.js";
|
|
79
|
+
|
|
80
|
+
export * from "./helpers/index.js";
|
|
81
|
+
|
|
82
|
+
export * from "./events/index.js";
|
|
83
|
+
|
|
84
|
+
export * from "./transaction/index.js";
|
|
85
|
+
|
|
86
|
+
export * from "./oracle.js";
|
|
87
|
+
|
|
88
|
+
export type { Liquid, LiquidSwap, LiquidFees, LiquidState } from "./idl/index.js";
|
|
89
|
+
export {
|
|
90
|
+
getLiquidProgram,
|
|
91
|
+
getLiquidSwapProgram,
|
|
92
|
+
getLiquidFeesProgram,
|
|
93
|
+
getLiquidStateProgram,
|
|
94
|
+
liquidIdl,
|
|
95
|
+
liquidSwapIdl,
|
|
96
|
+
liquidFeesIdl,
|
|
97
|
+
liquidStateIdl,
|
|
98
|
+
} from "./idl/index.js";
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export {
|
|
2
|
+
buildCreateNativeCurve,
|
|
3
|
+
buildBumpNative,
|
|
4
|
+
buildBuyNative,
|
|
5
|
+
buildBuyNativeAutoResolve,
|
|
6
|
+
buildSellNative,
|
|
7
|
+
buildSellNativeAutoResolve,
|
|
8
|
+
buildMigrateNative,
|
|
9
|
+
buildInitializeNativeReferralVault,
|
|
10
|
+
buildWithdrawReferralRewards,
|
|
11
|
+
buildExecuteBuybackNative,
|
|
12
|
+
buildExecuteBuybackToken,
|
|
13
|
+
// Stable curve builders
|
|
14
|
+
buildCreateStableCurve,
|
|
15
|
+
buildBuyStable,
|
|
16
|
+
buildBuyStableAutoResolve,
|
|
17
|
+
buildSellStable,
|
|
18
|
+
buildSellStableAutoResolve,
|
|
19
|
+
buildMigrateStable,
|
|
20
|
+
// Admin builders
|
|
21
|
+
buildSetFeeRecipients,
|
|
22
|
+
buildInitializeFeeRecipientVaults,
|
|
23
|
+
buildInitializeReferralTokenVault,
|
|
24
|
+
} from "./liquid.js";
|
|
25
|
+
export type {
|
|
26
|
+
BuildCreateNativeCurveParams,
|
|
27
|
+
BuildBumpNativeParams,
|
|
28
|
+
BuildBuyNativeParams,
|
|
29
|
+
BuildSellNativeParams,
|
|
30
|
+
BuildMigrateNativeParams,
|
|
31
|
+
BuildInitializeNativeReferralVaultParams,
|
|
32
|
+
BuildWithdrawReferralRewardsParams,
|
|
33
|
+
BuildExecuteBuybackNativeParams,
|
|
34
|
+
BuildExecuteBuybackTokenParams,
|
|
35
|
+
// Stable curve param types
|
|
36
|
+
BuildCreateStableCurveParams,
|
|
37
|
+
BuildBuyStableParams,
|
|
38
|
+
BuildSellStableParams,
|
|
39
|
+
BuildMigrateStableParams,
|
|
40
|
+
// Admin param types
|
|
41
|
+
BuildSetFeeRecipientsParams,
|
|
42
|
+
BuildInitializeFeeRecipientVaultsParams,
|
|
43
|
+
BuildInitializeReferralTokenVaultParams,
|
|
44
|
+
} from "./liquid.js";
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
buildCreatePool,
|
|
48
|
+
buildSwapBuy,
|
|
49
|
+
buildSwapSell,
|
|
50
|
+
buildDeposit,
|
|
51
|
+
buildWithdraw,
|
|
52
|
+
buildSwapExecuteBuyback,
|
|
53
|
+
} from "./liquid-swap.js";
|
|
54
|
+
export type {
|
|
55
|
+
BuildCreatePoolParams,
|
|
56
|
+
BuildSwapBuyParams,
|
|
57
|
+
BuildSwapSellParams,
|
|
58
|
+
BuildDepositParams,
|
|
59
|
+
BuildWithdrawParams,
|
|
60
|
+
BuildSwapExecuteBuybackParams,
|
|
61
|
+
} from "./liquid-swap.js";
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
buildUpdateFeeConfig,
|
|
65
|
+
buildRevokeFeeConfig,
|
|
66
|
+
buildDistributeFees,
|
|
67
|
+
buildDistributeTokenFees,
|
|
68
|
+
buildClaimFees,
|
|
69
|
+
buildClaimTokenFees,
|
|
70
|
+
deriveRecipientVaultPairs,
|
|
71
|
+
} from "./liquid-fees.js";
|
|
72
|
+
export type {
|
|
73
|
+
BuildUpdateFeeConfigParams,
|
|
74
|
+
BuildRevokeFeeConfigParams,
|
|
75
|
+
BuildDistributeFeesParams,
|
|
76
|
+
BuildDistributeTokenFeesParams,
|
|
77
|
+
BuildClaimFeesParams,
|
|
78
|
+
BuildClaimTokenFeesParams,
|
|
79
|
+
RecipientVaultPair,
|
|
80
|
+
} from "./liquid-fees.js";
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
buildInitializeUser,
|
|
84
|
+
buildSetReferrer,
|
|
85
|
+
buildSetCashbackMode,
|
|
86
|
+
buildTransferAdmin,
|
|
87
|
+
buildAcceptAdmin,
|
|
88
|
+
buildCancelAdminTransfer,
|
|
89
|
+
buildCreateDeal,
|
|
90
|
+
buildUpdateDeal,
|
|
91
|
+
buildCloseDeal,
|
|
92
|
+
buildRedeemDeal,
|
|
93
|
+
buildTakeSnapshot,
|
|
94
|
+
buildAdminUpdateUser,
|
|
95
|
+
} from "./liquid-state.js";
|
|
96
|
+
export type {
|
|
97
|
+
BuildInitializeUserParams,
|
|
98
|
+
BuildSetReferrerParams,
|
|
99
|
+
BuildSetCashbackModeParams,
|
|
100
|
+
BuildTransferAdminParams,
|
|
101
|
+
BuildAcceptAdminParams,
|
|
102
|
+
BuildCancelAdminTransferParams,
|
|
103
|
+
BuildCreateDealParams,
|
|
104
|
+
BuildUpdateDealParams,
|
|
105
|
+
BuildCloseDealParams,
|
|
106
|
+
BuildRedeemDealParams,
|
|
107
|
+
BuildTakeSnapshotParams,
|
|
108
|
+
BuildAdminUpdateUserParams,
|
|
109
|
+
} from "./liquid-state.js";
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
|
3
|
+
import type { LiquidConfig } from "../config.js";
|
|
4
|
+
import type { FeeRecipient } from "../types.js";
|
|
5
|
+
import { getCachedFeesProgram } from "./program-cache.js";
|
|
6
|
+
import {
|
|
7
|
+
getFeeConfigPDA,
|
|
8
|
+
getFeeVaultPDA,
|
|
9
|
+
getRecipientVaultPDA,
|
|
10
|
+
} from "../pda/liquid-fees.js";
|
|
11
|
+
|
|
12
|
+
export interface BuildUpdateFeeConfigParams {
|
|
13
|
+
authority: PublicKey;
|
|
14
|
+
tokenMint: PublicKey;
|
|
15
|
+
recipients?: FeeRecipient[] | null;
|
|
16
|
+
newUpdateAuthority?: PublicKey | null;
|
|
17
|
+
/** Required when changing recipients to verify token fee vault is drained. */
|
|
18
|
+
quoteMint?: PublicKey;
|
|
19
|
+
config: LiquidConfig;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds an updateFeeConfig instruction.
|
|
24
|
+
* Cannot change to Revoked mode (use revokeFeeConfig instead).
|
|
25
|
+
*
|
|
26
|
+
* @param params - {@link BuildUpdateFeeConfigParams}
|
|
27
|
+
* @returns Transaction instruction
|
|
28
|
+
*/
|
|
29
|
+
export function buildUpdateFeeConfig(
|
|
30
|
+
params: BuildUpdateFeeConfigParams
|
|
31
|
+
): Promise<TransactionInstruction> {
|
|
32
|
+
const {
|
|
33
|
+
authority,
|
|
34
|
+
tokenMint,
|
|
35
|
+
recipients,
|
|
36
|
+
newUpdateAuthority,
|
|
37
|
+
quoteMint,
|
|
38
|
+
config,
|
|
39
|
+
} = params;
|
|
40
|
+
const program = getCachedFeesProgram(config);
|
|
41
|
+
|
|
42
|
+
const formattedRecipients =
|
|
43
|
+
recipients?.map((r) => ({
|
|
44
|
+
pubkey: r.pubkey,
|
|
45
|
+
basisPoints: r.basisPoints,
|
|
46
|
+
})) ?? null;
|
|
47
|
+
|
|
48
|
+
// When changing recipients, the token fee vault must be passed to verify it's drained
|
|
49
|
+
let tokenFeeVault: PublicKey | null = null;
|
|
50
|
+
if (recipients && quoteMint) {
|
|
51
|
+
const [feeConfig] = getFeeConfigPDA(
|
|
52
|
+
tokenMint,
|
|
53
|
+
config.liquidFeesProgramId
|
|
54
|
+
);
|
|
55
|
+
const [feeVault] = getFeeVaultPDA(feeConfig, config.liquidFeesProgramId);
|
|
56
|
+
tokenFeeVault = getAssociatedTokenAddressSync(
|
|
57
|
+
quoteMint,
|
|
58
|
+
feeVault,
|
|
59
|
+
true
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return program.methods
|
|
64
|
+
.updateFeeConfig({
|
|
65
|
+
recipients: formattedRecipients,
|
|
66
|
+
newUpdateAuthority: newUpdateAuthority ?? null,
|
|
67
|
+
})
|
|
68
|
+
.accounts({
|
|
69
|
+
authority,
|
|
70
|
+
tokenMint,
|
|
71
|
+
tokenFeeVault
|
|
72
|
+
})
|
|
73
|
+
.instruction();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface BuildRevokeFeeConfigParams {
|
|
77
|
+
authority: PublicKey;
|
|
78
|
+
tokenMint: PublicKey;
|
|
79
|
+
/** Quote mint for token fee vault ATA derivation. */
|
|
80
|
+
quoteMint: PublicKey;
|
|
81
|
+
config: LiquidConfig;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Builds a revokeFeeConfig instruction.
|
|
86
|
+
* Permanently sets fee mode to Revoked (buyback-and-burn). Irreversible.
|
|
87
|
+
*
|
|
88
|
+
* @param params - {@link BuildRevokeFeeConfigParams}
|
|
89
|
+
* @returns Transaction instruction
|
|
90
|
+
*/
|
|
91
|
+
export function buildRevokeFeeConfig(
|
|
92
|
+
params: BuildRevokeFeeConfigParams
|
|
93
|
+
): Promise<TransactionInstruction> {
|
|
94
|
+
const { authority, tokenMint, quoteMint, config } = params;
|
|
95
|
+
const program = getCachedFeesProgram(config);
|
|
96
|
+
|
|
97
|
+
// Derive token fee vault ATA (fee_vault's ATA for quote_mint)
|
|
98
|
+
const [feeConfig] = getFeeConfigPDA(tokenMint, config.liquidFeesProgramId);
|
|
99
|
+
const [feeVault] = getFeeVaultPDA(feeConfig, config.liquidFeesProgramId);
|
|
100
|
+
const tokenFeeVault = getAssociatedTokenAddressSync(
|
|
101
|
+
quoteMint,
|
|
102
|
+
feeVault,
|
|
103
|
+
true
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return program.methods
|
|
107
|
+
.revokeFeeConfig()
|
|
108
|
+
.accounts({
|
|
109
|
+
authority,
|
|
110
|
+
tokenMint,
|
|
111
|
+
tokenFeeVault,
|
|
112
|
+
})
|
|
113
|
+
.instruction();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface BuildDistributeFeesParams {
|
|
117
|
+
payer: PublicKey;
|
|
118
|
+
tokenMint: PublicKey;
|
|
119
|
+
recipientVaults: PublicKey[];
|
|
120
|
+
config: LiquidConfig;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Builds a distributeFees instruction.
|
|
125
|
+
* Permissionless — anyone can trigger fee distribution for Recipients tokens.
|
|
126
|
+
* Recipient vaults must be recipient vault PDAs (derived via getRecipientVaultPDA),
|
|
127
|
+
* passed in the same order as fee_config.recipients.
|
|
128
|
+
*
|
|
129
|
+
* @param params - {@link BuildDistributeFeesParams}
|
|
130
|
+
* @returns Transaction instruction
|
|
131
|
+
*/
|
|
132
|
+
export function buildDistributeFees(
|
|
133
|
+
params: BuildDistributeFeesParams
|
|
134
|
+
): Promise<TransactionInstruction> {
|
|
135
|
+
const { payer, tokenMint, recipientVaults, config } = params;
|
|
136
|
+
const program = getCachedFeesProgram(config);
|
|
137
|
+
|
|
138
|
+
return program.methods
|
|
139
|
+
.distributeFees()
|
|
140
|
+
.accounts({
|
|
141
|
+
payer,
|
|
142
|
+
tokenMint,
|
|
143
|
+
})
|
|
144
|
+
.remainingAccounts(
|
|
145
|
+
recipientVaults.map((vault) => ({
|
|
146
|
+
pubkey: vault,
|
|
147
|
+
isSigner: false,
|
|
148
|
+
isWritable: true,
|
|
149
|
+
}))
|
|
150
|
+
)
|
|
151
|
+
.instruction();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface RecipientVaultPair {
|
|
155
|
+
vaultPda: PublicKey;
|
|
156
|
+
vaultAta: PublicKey;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface BuildDistributeTokenFeesParams {
|
|
160
|
+
payer: PublicKey;
|
|
161
|
+
tokenMint: PublicKey;
|
|
162
|
+
quoteMint: PublicKey;
|
|
163
|
+
recipientVaultPairs: RecipientVaultPair[];
|
|
164
|
+
config: LiquidConfig;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Builds a distributeTokenFees instruction.
|
|
169
|
+
* Permissionless — anyone can trigger token fee distribution for Recipients tokens.
|
|
170
|
+
* Remaining accounts must be pairs of (recipient_vault_pda, recipient_vault_token_account)
|
|
171
|
+
* in the same order as fee_config.recipients.
|
|
172
|
+
*
|
|
173
|
+
* @param params - {@link BuildDistributeTokenFeesParams}
|
|
174
|
+
* @returns Transaction instruction
|
|
175
|
+
*/
|
|
176
|
+
export function buildDistributeTokenFees(
|
|
177
|
+
params: BuildDistributeTokenFeesParams
|
|
178
|
+
): Promise<TransactionInstruction> {
|
|
179
|
+
const { payer, tokenMint, quoteMint, recipientVaultPairs, config } = params;
|
|
180
|
+
const program = getCachedFeesProgram(config);
|
|
181
|
+
|
|
182
|
+
// Flatten pairs into interleaved remaining accounts: [pda1, ata1, pda2, ata2, ...]
|
|
183
|
+
const remainingAccounts = recipientVaultPairs.flatMap((pair) => [
|
|
184
|
+
{ pubkey: pair.vaultPda, isSigner: false, isWritable: false },
|
|
185
|
+
{ pubkey: pair.vaultAta, isSigner: false, isWritable: true },
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
return program.methods
|
|
189
|
+
.distributeTokenFees()
|
|
190
|
+
.accountsPartial({
|
|
191
|
+
payer,
|
|
192
|
+
tokenMint,
|
|
193
|
+
quoteMint
|
|
194
|
+
})
|
|
195
|
+
.remainingAccounts(remainingAccounts)
|
|
196
|
+
.instruction();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface BuildClaimFeesParams {
|
|
200
|
+
recipient: PublicKey;
|
|
201
|
+
tokenMint: PublicKey;
|
|
202
|
+
config: LiquidConfig;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Builds a claimFees instruction.
|
|
207
|
+
* Allows a recipient to claim accumulated SOL fees from their vault PDA.
|
|
208
|
+
*
|
|
209
|
+
* @param params - {@link BuildClaimFeesParams}
|
|
210
|
+
* @returns Transaction instruction
|
|
211
|
+
*/
|
|
212
|
+
export function buildClaimFees(
|
|
213
|
+
params: BuildClaimFeesParams
|
|
214
|
+
): Promise<TransactionInstruction> {
|
|
215
|
+
const { recipient, tokenMint, config } = params;
|
|
216
|
+
const program = getCachedFeesProgram(config);
|
|
217
|
+
const [feeConfig] = getFeeConfigPDA(tokenMint, config.liquidFeesProgramId);
|
|
218
|
+
|
|
219
|
+
return program.methods
|
|
220
|
+
.claimFees()
|
|
221
|
+
.accounts({
|
|
222
|
+
recipient,
|
|
223
|
+
feeConfig,
|
|
224
|
+
})
|
|
225
|
+
.instruction();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface BuildClaimTokenFeesParams {
|
|
229
|
+
recipient: PublicKey;
|
|
230
|
+
tokenMint: PublicKey;
|
|
231
|
+
quoteMint: PublicKey;
|
|
232
|
+
config: LiquidConfig;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Builds a claimTokenFees instruction.
|
|
237
|
+
* Allows a recipient to claim accumulated token fees from their vault ATA.
|
|
238
|
+
* Closes the vault ATA after claiming to reclaim rent.
|
|
239
|
+
*
|
|
240
|
+
* @param params - {@link BuildClaimTokenFeesParams}
|
|
241
|
+
* @returns Transaction instruction
|
|
242
|
+
*/
|
|
243
|
+
export function buildClaimTokenFees(
|
|
244
|
+
params: BuildClaimTokenFeesParams
|
|
245
|
+
): Promise<TransactionInstruction> {
|
|
246
|
+
const { recipient, tokenMint, quoteMint, config } = params;
|
|
247
|
+
const program = getCachedFeesProgram(config);
|
|
248
|
+
const [feeConfig] = getFeeConfigPDA(tokenMint, config.liquidFeesProgramId);
|
|
249
|
+
|
|
250
|
+
return program.methods
|
|
251
|
+
.claimTokenFees()
|
|
252
|
+
.accounts({
|
|
253
|
+
recipient,
|
|
254
|
+
feeConfig,
|
|
255
|
+
quoteMint,
|
|
256
|
+
})
|
|
257
|
+
.instruction();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Helper: derives recipient vault PDA pairs for use with buildDistributeTokenFees.
|
|
262
|
+
*
|
|
263
|
+
* @param tokenMint - Token mint address
|
|
264
|
+
* @param recipients - Array of recipient public keys in fee_config order
|
|
265
|
+
* @param quoteMint - Quote mint for ATA derivation
|
|
266
|
+
* @param config - Liquid protocol config
|
|
267
|
+
* @returns Array of RecipientVaultPair for remaining accounts
|
|
268
|
+
*/
|
|
269
|
+
export function deriveRecipientVaultPairs(
|
|
270
|
+
tokenMint: PublicKey,
|
|
271
|
+
recipients: PublicKey[],
|
|
272
|
+
quoteMint: PublicKey,
|
|
273
|
+
config: LiquidConfig
|
|
274
|
+
): RecipientVaultPair[] {
|
|
275
|
+
const [feeConfig] = getFeeConfigPDA(tokenMint, config.liquidFeesProgramId);
|
|
276
|
+
return recipients.map((recipient) => {
|
|
277
|
+
const [vaultPda] = getRecipientVaultPDA(
|
|
278
|
+
feeConfig,
|
|
279
|
+
recipient,
|
|
280
|
+
config.liquidFeesProgramId
|
|
281
|
+
);
|
|
282
|
+
const vaultAta = getAssociatedTokenAddressSync(
|
|
283
|
+
quoteMint,
|
|
284
|
+
vaultPda,
|
|
285
|
+
true
|
|
286
|
+
);
|
|
287
|
+
return { vaultPda, vaultAta };
|
|
288
|
+
});
|
|
289
|
+
}
|