@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.
Files changed (225) hide show
  1. package/README.md +776 -0
  2. package/dist/accounts/index.d.ts +5 -0
  3. package/dist/accounts/index.d.ts.map +1 -0
  4. package/dist/accounts/index.js +5 -0
  5. package/dist/accounts/index.js.map +1 -0
  6. package/dist/accounts/liquid-fees.d.ts +63 -0
  7. package/dist/accounts/liquid-fees.d.ts.map +1 -0
  8. package/dist/accounts/liquid-fees.js +27 -0
  9. package/dist/accounts/liquid-fees.js.map +1 -0
  10. package/dist/accounts/liquid-state.d.ts +112 -0
  11. package/dist/accounts/liquid-state.d.ts.map +1 -0
  12. package/dist/accounts/liquid-state.js +92 -0
  13. package/dist/accounts/liquid-state.js.map +1 -0
  14. package/dist/accounts/liquid-swap.d.ts +97 -0
  15. package/dist/accounts/liquid-swap.d.ts.map +1 -0
  16. package/dist/accounts/liquid-swap.js +54 -0
  17. package/dist/accounts/liquid-swap.js.map +1 -0
  18. package/dist/accounts/liquid.d.ts +175 -0
  19. package/dist/accounts/liquid.d.ts.map +1 -0
  20. package/dist/accounts/liquid.js +66 -0
  21. package/dist/accounts/liquid.js.map +1 -0
  22. package/dist/client.d.ts +621 -0
  23. package/dist/client.d.ts.map +1 -0
  24. package/dist/client.js +511 -0
  25. package/dist/client.js.map +1 -0
  26. package/dist/config.d.ts +56 -0
  27. package/dist/config.d.ts.map +1 -0
  28. package/dist/config.js +44 -0
  29. package/dist/config.js.map +1 -0
  30. package/dist/errors.d.ts +39 -0
  31. package/dist/errors.d.ts.map +1 -0
  32. package/dist/errors.js +63 -0
  33. package/dist/errors.js.map +1 -0
  34. package/dist/events/index.d.ts +4 -0
  35. package/dist/events/index.d.ts.map +1 -0
  36. package/dist/events/index.js +2 -0
  37. package/dist/events/index.js.map +1 -0
  38. package/dist/events/parser.d.ts +40 -0
  39. package/dist/events/parser.d.ts.map +1 -0
  40. package/dist/events/parser.js +67 -0
  41. package/dist/events/parser.js.map +1 -0
  42. package/dist/events/types.d.ts +286 -0
  43. package/dist/events/types.d.ts.map +1 -0
  44. package/dist/events/types.js +2 -0
  45. package/dist/events/types.js.map +1 -0
  46. package/dist/helpers/index.d.ts +4 -0
  47. package/dist/helpers/index.d.ts.map +1 -0
  48. package/dist/helpers/index.js +3 -0
  49. package/dist/helpers/index.js.map +1 -0
  50. package/dist/helpers/preview.d.ts +259 -0
  51. package/dist/helpers/preview.d.ts.map +1 -0
  52. package/dist/helpers/preview.js +458 -0
  53. package/dist/helpers/preview.js.map +1 -0
  54. package/dist/helpers/user.d.ts +11 -0
  55. package/dist/helpers/user.d.ts.map +1 -0
  56. package/dist/helpers/user.js +20 -0
  57. package/dist/helpers/user.js.map +1 -0
  58. package/dist/idl/index.d.ts +53 -0
  59. package/dist/idl/index.d.ts.map +1 -0
  60. package/dist/idl/index.js +64 -0
  61. package/dist/idl/index.js.map +1 -0
  62. package/dist/idl/liquid.d.ts +10523 -0
  63. package/dist/idl/liquid.d.ts.map +1 -0
  64. package/dist/idl/liquid.js +2 -0
  65. package/dist/idl/liquid.js.map +1 -0
  66. package/dist/idl/liquid.json +10516 -0
  67. package/dist/idl/liquid_fees.d.ts +1520 -0
  68. package/dist/idl/liquid_fees.d.ts.map +1 -0
  69. package/dist/idl/liquid_fees.js +2 -0
  70. package/dist/idl/liquid_fees.js.map +1 -0
  71. package/dist/idl/liquid_fees.json +1513 -0
  72. package/dist/idl/liquid_state.d.ts +2936 -0
  73. package/dist/idl/liquid_state.d.ts.map +1 -0
  74. package/dist/idl/liquid_state.js +2 -0
  75. package/dist/idl/liquid_state.js.map +1 -0
  76. package/dist/idl/liquid_state.json +2929 -0
  77. package/dist/idl/liquid_swap.d.ts +5849 -0
  78. package/dist/idl/liquid_swap.d.ts.map +1 -0
  79. package/dist/idl/liquid_swap.js +2 -0
  80. package/dist/idl/liquid_swap.js.map +1 -0
  81. package/dist/idl/liquid_swap.json +5842 -0
  82. package/dist/index.d.ts +19 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +15 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/instructions/index.d.ts +9 -0
  87. package/dist/instructions/index.d.ts.map +1 -0
  88. package/dist/instructions/index.js +9 -0
  89. package/dist/instructions/index.js.map +1 -0
  90. package/dist/instructions/liquid-fees.d.ts +111 -0
  91. package/dist/instructions/liquid-fees.d.ts.map +1 -0
  92. package/dist/instructions/liquid-fees.js +169 -0
  93. package/dist/instructions/liquid-fees.js.map +1 -0
  94. package/dist/instructions/liquid-state.d.ts +173 -0
  95. package/dist/instructions/liquid-state.d.ts.map +1 -0
  96. package/dist/instructions/liquid-state.js +194 -0
  97. package/dist/instructions/liquid-state.js.map +1 -0
  98. package/dist/instructions/liquid-swap.d.ts +122 -0
  99. package/dist/instructions/liquid-swap.d.ts.map +1 -0
  100. package/dist/instructions/liquid-swap.js +167 -0
  101. package/dist/instructions/liquid-swap.js.map +1 -0
  102. package/dist/instructions/liquid.d.ts +297 -0
  103. package/dist/instructions/liquid.d.ts.map +1 -0
  104. package/dist/instructions/liquid.js +483 -0
  105. package/dist/instructions/liquid.js.map +1 -0
  106. package/dist/instructions/program-cache.d.ts +35 -0
  107. package/dist/instructions/program-cache.d.ts.map +1 -0
  108. package/dist/instructions/program-cache.js +68 -0
  109. package/dist/instructions/program-cache.js.map +1 -0
  110. package/dist/math/amm.d.ts +42 -0
  111. package/dist/math/amm.d.ts.map +1 -0
  112. package/dist/math/amm.js +109 -0
  113. package/dist/math/amm.js.map +1 -0
  114. package/dist/math/bonding-curve.d.ts +34 -0
  115. package/dist/math/bonding-curve.d.ts.map +1 -0
  116. package/dist/math/bonding-curve.js +80 -0
  117. package/dist/math/bonding-curve.js.map +1 -0
  118. package/dist/math/constants.d.ts +14 -0
  119. package/dist/math/constants.d.ts.map +1 -0
  120. package/dist/math/constants.js +14 -0
  121. package/dist/math/constants.js.map +1 -0
  122. package/dist/math/fees.d.ts +88 -0
  123. package/dist/math/fees.d.ts.map +1 -0
  124. package/dist/math/fees.js +135 -0
  125. package/dist/math/fees.js.map +1 -0
  126. package/dist/math/index.d.ts +8 -0
  127. package/dist/math/index.d.ts.map +1 -0
  128. package/dist/math/index.js +6 -0
  129. package/dist/math/index.js.map +1 -0
  130. package/dist/math/tiered-fees.d.ts +80 -0
  131. package/dist/math/tiered-fees.d.ts.map +1 -0
  132. package/dist/math/tiered-fees.js +129 -0
  133. package/dist/math/tiered-fees.js.map +1 -0
  134. package/dist/oracle.d.ts +53 -0
  135. package/dist/oracle.d.ts.map +1 -0
  136. package/dist/oracle.js +70 -0
  137. package/dist/oracle.js.map +1 -0
  138. package/dist/pda/index.d.ts +89 -0
  139. package/dist/pda/index.d.ts.map +1 -0
  140. package/dist/pda/index.js +127 -0
  141. package/dist/pda/index.js.map +1 -0
  142. package/dist/pda/liquid-fees.d.ts +27 -0
  143. package/dist/pda/liquid-fees.d.ts.map +1 -0
  144. package/dist/pda/liquid-fees.js +36 -0
  145. package/dist/pda/liquid-fees.js.map +1 -0
  146. package/dist/pda/liquid-state.d.ts +56 -0
  147. package/dist/pda/liquid-state.d.ts.map +1 -0
  148. package/dist/pda/liquid-state.js +79 -0
  149. package/dist/pda/liquid-state.js.map +1 -0
  150. package/dist/pda/liquid-swap.d.ts +76 -0
  151. package/dist/pda/liquid-swap.d.ts.map +1 -0
  152. package/dist/pda/liquid-swap.js +103 -0
  153. package/dist/pda/liquid-swap.js.map +1 -0
  154. package/dist/pda/liquid.d.ts +67 -0
  155. package/dist/pda/liquid.d.ts.map +1 -0
  156. package/dist/pda/liquid.js +91 -0
  157. package/dist/pda/liquid.js.map +1 -0
  158. package/dist/provider.d.ts +26 -0
  159. package/dist/provider.d.ts.map +1 -0
  160. package/dist/provider.js +47 -0
  161. package/dist/provider.js.map +1 -0
  162. package/dist/transaction/builder.d.ts +30 -0
  163. package/dist/transaction/builder.d.ts.map +1 -0
  164. package/dist/transaction/builder.js +48 -0
  165. package/dist/transaction/builder.js.map +1 -0
  166. package/dist/transaction/index.d.ts +3 -0
  167. package/dist/transaction/index.d.ts.map +1 -0
  168. package/dist/transaction/index.js +3 -0
  169. package/dist/transaction/index.js.map +1 -0
  170. package/dist/transaction/send.d.ts +25 -0
  171. package/dist/transaction/send.d.ts.map +1 -0
  172. package/dist/transaction/send.js +52 -0
  173. package/dist/transaction/send.js.map +1 -0
  174. package/dist/types.d.ts +311 -0
  175. package/dist/types.d.ts.map +1 -0
  176. package/dist/types.js +46 -0
  177. package/dist/types.js.map +1 -0
  178. package/package.json +112 -0
  179. package/src/accounts/index.ts +26 -0
  180. package/src/accounts/liquid-fees.ts +38 -0
  181. package/src/accounts/liquid-state.ts +134 -0
  182. package/src/accounts/liquid-swap.ts +79 -0
  183. package/src/accounts/liquid.ts +100 -0
  184. package/src/client.ts +1001 -0
  185. package/src/config.ts +91 -0
  186. package/src/errors.ts +94 -0
  187. package/src/events/index.ts +42 -0
  188. package/src/events/parser.ts +90 -0
  189. package/src/events/types.ts +310 -0
  190. package/src/helpers/index.ts +23 -0
  191. package/src/helpers/preview.ts +798 -0
  192. package/src/helpers/user.ts +24 -0
  193. package/src/idl/index.ts +94 -0
  194. package/src/idl/liquid.json +10516 -0
  195. package/src/idl/liquid.ts +10522 -0
  196. package/src/idl/liquid_fees.json +1513 -0
  197. package/src/idl/liquid_fees.ts +1519 -0
  198. package/src/idl/liquid_state.json +2929 -0
  199. package/src/idl/liquid_state.ts +2935 -0
  200. package/src/idl/liquid_swap.json +5842 -0
  201. package/src/idl/liquid_swap.ts +5848 -0
  202. package/src/index.ts +98 -0
  203. package/src/instructions/index.ts +109 -0
  204. package/src/instructions/liquid-fees.ts +289 -0
  205. package/src/instructions/liquid-state.ts +336 -0
  206. package/src/instructions/liquid-swap.ts +414 -0
  207. package/src/instructions/liquid.ts +884 -0
  208. package/src/instructions/program-cache.ts +106 -0
  209. package/src/math/amm.ts +146 -0
  210. package/src/math/bonding-curve.ts +122 -0
  211. package/src/math/constants.ts +19 -0
  212. package/src/math/fees.ts +191 -0
  213. package/src/math/index.ts +40 -0
  214. package/src/math/tiered-fees.ts +165 -0
  215. package/src/oracle.ts +97 -0
  216. package/src/pda/index.ts +331 -0
  217. package/src/pda/liquid-fees.ts +58 -0
  218. package/src/pda/liquid-state.ts +123 -0
  219. package/src/pda/liquid-swap.ts +162 -0
  220. package/src/pda/liquid.ts +152 -0
  221. package/src/provider.ts +60 -0
  222. package/src/transaction/builder.ts +80 -0
  223. package/src/transaction/index.ts +6 -0
  224. package/src/transaction/send.ts +72 -0
  225. 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
+ }