@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/client.ts ADDED
@@ -0,0 +1,1001 @@
1
+ import type {
2
+ Connection,
3
+ PublicKey,
4
+ Transaction,
5
+ TransactionInstruction,
6
+ } from "@solana/web3.js";
7
+ import type BN from "bn.js";
8
+ import { MAINNET_CONFIG, WSOL_MINT, type LiquidConfig } from "./config.js";
9
+ import type {
10
+ BuyCurvePreview,
11
+ SellCurvePreview,
12
+ SwapPreview,
13
+ FeeRecipient,
14
+ } from "./types.js";
15
+ import {
16
+ buildTransaction as buildTransactionFn,
17
+ type BuildTransactionOptions,
18
+ } from "./transaction/builder.js";
19
+
20
+ // Instruction builders
21
+ import {
22
+ buildCreateNativeCurve,
23
+ buildBuyNative,
24
+ buildBuyNativeAutoResolve,
25
+ buildSellNative,
26
+ buildSellNativeAutoResolve,
27
+ buildMigrateNative,
28
+ buildInitializeNativeReferralVault,
29
+ buildWithdrawReferralRewards,
30
+ buildExecuteBuybackNative,
31
+ buildExecuteBuybackToken,
32
+ } from "./instructions/liquid.js";
33
+ import {
34
+ buildCreatePool,
35
+ buildSwapBuy,
36
+ buildSwapSell,
37
+ buildDeposit,
38
+ buildWithdraw,
39
+ buildSwapExecuteBuyback,
40
+ } from "./instructions/liquid-swap.js";
41
+ import {
42
+ buildUpdateFeeConfig,
43
+ buildRevokeFeeConfig,
44
+ buildDistributeFees,
45
+ buildDistributeTokenFees,
46
+ buildClaimFees,
47
+ buildClaimTokenFees,
48
+ type RecipientVaultPair,
49
+ } from "./instructions/liquid-fees.js";
50
+ import {
51
+ buildInitializeUser,
52
+ buildSetReferrer,
53
+ buildSetCashbackMode,
54
+ buildTransferAdmin,
55
+ buildAcceptAdmin,
56
+ buildCancelAdminTransfer,
57
+ buildCreateDeal,
58
+ buildUpdateDeal,
59
+ buildCloseDeal,
60
+ buildRedeemDeal,
61
+ buildTakeSnapshot,
62
+ buildAdminUpdateUser,
63
+ } from "./instructions/liquid-state.js";
64
+
65
+ // Account fetchers
66
+ import {
67
+ fetchLiquidGlobalConfig as fetchLiquidGlobalConfigFn,
68
+ fetchNativeBondingCurve as fetchNativeBondingCurveFn,
69
+ fetchNativeBondingCurveByAddress as fetchNativeBondingCurveByAddressFn,
70
+ } from "./accounts/liquid.js";
71
+ import {
72
+ fetchAmmConfig as fetchAmmConfigFn,
73
+ fetchPoolState as fetchPoolStateFn,
74
+ fetchPoolStateByAddress as fetchPoolStateByAddressFn,
75
+ fetchObservationState as fetchObservationStateFn,
76
+ } from "./accounts/liquid-swap.js";
77
+ import {
78
+ fetchFeeConfig as fetchFeeConfigFn,
79
+ fetchFeeConfigByAddress as fetchFeeConfigByAddressFn,
80
+ } from "./accounts/liquid-fees.js";
81
+ import {
82
+ fetchUserProperties as fetchUserPropertiesFn,
83
+ fetchTokenVolume as fetchTokenVolumeFn,
84
+ fetchGlobalCurveVolume as fetchGlobalCurveVolumeFn,
85
+ fetchGlobalAmmVolume as fetchGlobalAmmVolumeFn,
86
+ fetchCashbackConfig as fetchCashbackConfigFn,
87
+ fetchUserSnapshot as fetchUserSnapshotFn,
88
+ fetchDeal as fetchDealFn,
89
+ } from "./accounts/liquid-state.js";
90
+
91
+ // Preview helpers
92
+ import {
93
+ previewBuyOnCurve as previewBuyOnCurveFn,
94
+ previewSellOnCurve as previewSellOnCurveFn,
95
+ previewSwapSell as previewSwapSellFn,
96
+ previewSwapBuy as previewSwapBuyFn,
97
+ type CurveAsyncOptions,
98
+ type SwapPrefetchedState,
99
+ } from "./helpers/preview.js";
100
+
101
+ // PDA helpers
102
+ import {
103
+ getBondingCurvePDA,
104
+ getBondingCurveSolVaultPDA,
105
+ getReferralVaultPDA,
106
+ getBuybackVaultPDA,
107
+ getPoolPDA,
108
+ getPoolLpMintPDA,
109
+ getPoolVaultPDA,
110
+ getObservationPDA,
111
+ getFeeConfigPDA,
112
+ getFeeVaultPDA,
113
+ getRecipientVaultPDA,
114
+ getUserPropertiesPDA,
115
+ getTokenVolumePDA,
116
+ getUserSnapshotPDA,
117
+ getDealPDA,
118
+ getAllBondingCurvePDAs,
119
+ getAllPoolPDAs,
120
+ getMigrationPDAs,
121
+ } from "./pda/index.js";
122
+
123
+ // Utility
124
+ import { resolveTokenProgram as resolveTokenProgramFn } from "./helpers/user.js";
125
+
126
+ export interface LiquidClientConfig {
127
+ connection: Connection;
128
+ config?: LiquidConfig;
129
+ }
130
+
131
+ /**
132
+ * Unified entry point for the Liquid protocol SDK.
133
+ *
134
+ * Holds a `Connection` and `LiquidConfig`, removing the need to pass them
135
+ * to every function call. Auto-resolves token programs and pool PDAs for
136
+ * AMM operations. All instruction-building methods return unsigned
137
+ * `TransactionInstruction`s — the caller is responsible for signing.
138
+ */
139
+ export class LiquidClient {
140
+ readonly connection: Connection;
141
+ readonly config: LiquidConfig;
142
+
143
+ /**
144
+ * @param options - Client configuration with connection and optional protocol config
145
+ */
146
+ constructor({ connection, config = MAINNET_CONFIG }: LiquidClientConfig) {
147
+ this.connection = connection;
148
+ this.config = config;
149
+ }
150
+
151
+ /** Builds a createCurve instruction for launching a new token on the bonding curve. */
152
+ buildCreateCurve(params: {
153
+ creator: PublicKey;
154
+ mint: PublicKey;
155
+ pythPriceFeed: PublicKey;
156
+ name: string;
157
+ symbol: string;
158
+ uri: string;
159
+ }): Promise<TransactionInstruction> {
160
+ return buildCreateNativeCurve({ ...params, config: this.config });
161
+ }
162
+
163
+ /** Builds a buyOnCurve instruction. Requires the creator address and Pyth price feed. */
164
+ buildBuyOnCurve(params: {
165
+ user: PublicKey;
166
+ mint: PublicKey;
167
+ creator: PublicKey;
168
+ pythPriceFeed: PublicKey;
169
+ amountIn: BN;
170
+ minAmountOut: BN;
171
+ feeRecipient: PublicKey;
172
+ creatorReferralVault?: PublicKey | null;
173
+ traderReferralVault?: PublicKey | null;
174
+ }): Promise<TransactionInstruction> {
175
+ return buildBuyNative({ ...params, config: this.config });
176
+ }
177
+
178
+ /**
179
+ * Like `buildBuyOnCurve` but auto-fetches the bonding curve creator.
180
+ */
181
+ buildBuyOnCurveAutoResolve(params: {
182
+ user: PublicKey;
183
+ mint: PublicKey;
184
+ pythPriceFeed: PublicKey;
185
+ amountIn: BN;
186
+ minAmountOut: BN;
187
+ feeRecipient: PublicKey;
188
+ creatorReferralVault?: PublicKey | null;
189
+ traderReferralVault?: PublicKey | null;
190
+ }): Promise<TransactionInstruction> {
191
+ return buildBuyNativeAutoResolve(this.connection, {
192
+ ...params,
193
+ config: this.config,
194
+ });
195
+ }
196
+
197
+ /** Builds a sellOnCurve instruction. Requires the creator address and Pyth price feed. */
198
+ buildSellOnCurve(params: {
199
+ user: PublicKey;
200
+ mint: PublicKey;
201
+ creator: PublicKey;
202
+ pythPriceFeed: PublicKey;
203
+ amountIn: BN;
204
+ minAmountOut: BN;
205
+ feeRecipient: PublicKey;
206
+ creatorReferralVault?: PublicKey | null;
207
+ traderReferralVault?: PublicKey | null;
208
+ }): Promise<TransactionInstruction> {
209
+ return buildSellNative({ ...params, config: this.config });
210
+ }
211
+
212
+ /**
213
+ * Like `buildSellOnCurve` but auto-fetches the bonding curve creator.
214
+ */
215
+ buildSellOnCurveAutoResolve(params: {
216
+ user: PublicKey;
217
+ mint: PublicKey;
218
+ pythPriceFeed: PublicKey;
219
+ amountIn: BN;
220
+ minAmountOut: BN;
221
+ feeRecipient: PublicKey;
222
+ creatorReferralVault?: PublicKey | null;
223
+ traderReferralVault?: PublicKey | null;
224
+ }): Promise<TransactionInstruction> {
225
+ return buildSellNativeAutoResolve(this.connection, {
226
+ ...params,
227
+ config: this.config,
228
+ });
229
+ }
230
+
231
+ /** Builds a migrate instruction (bonding curve → AMM pool). Permissionless once the curve completes. */
232
+ buildMigrateNative(params: {
233
+ migrator: PublicKey;
234
+ mint: PublicKey;
235
+ }): Promise<TransactionInstruction> {
236
+ return buildMigrateNative({ ...params, config: this.config });
237
+ }
238
+
239
+ /** Builds an initializeNativeReferralVault instruction (creates native SOL referral vault). */
240
+ buildInitializeNativeReferralVault(params: {
241
+ user: PublicKey;
242
+ }): Promise<TransactionInstruction> {
243
+ return buildInitializeNativeReferralVault({
244
+ ...params,
245
+ config: this.config,
246
+ });
247
+ }
248
+
249
+ /** Builds a withdrawReferralRewards instruction. */
250
+ buildWithdrawReferralRewards(params: {
251
+ user: PublicKey;
252
+ }): Promise<TransactionInstruction> {
253
+ return buildWithdrawReferralRewards({ ...params, config: this.config });
254
+ }
255
+
256
+ /** Builds an executeBuybackNative instruction for native SOL curves. Permissionless; requires revoked fee config. */
257
+ buildExecuteBuybackNative(params: {
258
+ payer: PublicKey;
259
+ mint: PublicKey;
260
+ pythPriceFeed: PublicKey;
261
+ }): Promise<TransactionInstruction> {
262
+ return buildExecuteBuybackNative({ ...params, config: this.config });
263
+ }
264
+
265
+ /** Builds an executeBuybackToken instruction for token-based curves. Permissionless; requires revoked fee config. */
266
+ buildExecuteBuybackToken(params: {
267
+ payer: PublicKey;
268
+ mint: PublicKey;
269
+ quoteMint: PublicKey;
270
+ }): Promise<TransactionInstruction> {
271
+ return buildExecuteBuybackToken({ ...params, config: this.config });
272
+ }
273
+
274
+ /**
275
+ * Builds a create pool instruction. Auto-resolves token programs if not provided.
276
+ */
277
+ async buildCreatePool(params: {
278
+ signer: PublicKey;
279
+ baseMint: PublicKey;
280
+ quoteMint?: PublicKey;
281
+ initAmountBase: BN;
282
+ initAmountQuote: BN;
283
+ baseTokenProgram?: PublicKey;
284
+ quoteTokenProgram?: PublicKey;
285
+ }): Promise<TransactionInstruction> {
286
+ const quoteMint = params.quoteMint ?? WSOL_MINT;
287
+ const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
288
+ params.baseTokenProgram
289
+ ? Promise.resolve(params.baseTokenProgram)
290
+ : resolveTokenProgramFn(this.connection, params.baseMint),
291
+ params.quoteTokenProgram
292
+ ? Promise.resolve(params.quoteTokenProgram)
293
+ : resolveTokenProgramFn(this.connection, quoteMint),
294
+ ]);
295
+
296
+ return buildCreatePool({
297
+ signer: params.signer,
298
+ baseMint: params.baseMint,
299
+ quoteMint,
300
+ baseTokenProgram,
301
+ quoteTokenProgram,
302
+ initAmountBase: params.initAmountBase,
303
+ initAmountQuote: params.initAmountQuote,
304
+ config: this.config,
305
+ });
306
+ }
307
+
308
+ /**
309
+ * Builds a buy swap instruction (quote -> base).
310
+ * Auto-resolves token programs if not provided. Defaults quoteMint to WSOL.
311
+ */
312
+ async buildSwapBuy(params: {
313
+ payer: PublicKey;
314
+ creator: PublicKey;
315
+ baseMint: PublicKey;
316
+ quoteMint?: PublicKey;
317
+ maxAmountIn: BN;
318
+ amountOut: BN;
319
+ feeRecipient: PublicKey;
320
+ baseTokenProgram?: PublicKey;
321
+ quoteTokenProgram?: PublicKey;
322
+ }): Promise<TransactionInstruction> {
323
+ const quoteMint = params.quoteMint ?? WSOL_MINT;
324
+ const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
325
+ params.baseTokenProgram
326
+ ? Promise.resolve(params.baseTokenProgram)
327
+ : resolveTokenProgramFn(this.connection, params.baseMint),
328
+ params.quoteTokenProgram
329
+ ? Promise.resolve(params.quoteTokenProgram)
330
+ : resolveTokenProgramFn(this.connection, quoteMint),
331
+ ]);
332
+
333
+ return buildSwapBuy({
334
+ payer: params.payer,
335
+ creator: params.creator,
336
+ baseMint: params.baseMint,
337
+ quoteMint,
338
+ baseTokenProgram,
339
+ quoteTokenProgram,
340
+ maxAmountIn: params.maxAmountIn,
341
+ amountOut: params.amountOut,
342
+ feeRecipient: params.feeRecipient,
343
+ config: this.config,
344
+ });
345
+ }
346
+
347
+ /**
348
+ * Builds a sell swap instruction (base -> quote).
349
+ * Auto-resolves token programs if not provided. Defaults quoteMint to WSOL.
350
+ */
351
+ async buildSwapSell(params: {
352
+ payer: PublicKey;
353
+ creator: PublicKey;
354
+ baseMint: PublicKey;
355
+ quoteMint?: PublicKey;
356
+ amountIn: BN;
357
+ minimumAmountOut: BN;
358
+ feeRecipient: PublicKey;
359
+ baseTokenProgram?: PublicKey;
360
+ quoteTokenProgram?: PublicKey;
361
+ }): Promise<TransactionInstruction> {
362
+ const quoteMint = params.quoteMint ?? WSOL_MINT;
363
+ const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
364
+ params.baseTokenProgram
365
+ ? Promise.resolve(params.baseTokenProgram)
366
+ : resolveTokenProgramFn(this.connection, params.baseMint),
367
+ params.quoteTokenProgram
368
+ ? Promise.resolve(params.quoteTokenProgram)
369
+ : resolveTokenProgramFn(this.connection, quoteMint),
370
+ ]);
371
+
372
+ return buildSwapSell({
373
+ payer: params.payer,
374
+ creator: params.creator,
375
+ baseMint: params.baseMint,
376
+ quoteMint,
377
+ baseTokenProgram,
378
+ quoteTokenProgram,
379
+ amountIn: params.amountIn,
380
+ minimumAmountOut: params.minimumAmountOut,
381
+ feeRecipient: params.feeRecipient,
382
+ config: this.config,
383
+ });
384
+ }
385
+
386
+ /**
387
+ * Builds a deposit (add liquidity) instruction.
388
+ * Auto-resolves pool PDAs, vaults, LP mint, and token programs.
389
+ * Defaults quoteMint to WSOL.
390
+ */
391
+ async buildDeposit(params: {
392
+ owner: PublicKey;
393
+ baseMint: PublicKey;
394
+ quoteMint?: PublicKey;
395
+ lpTokenAmount: BN;
396
+ maximumBaseAmount: BN;
397
+ maximumQuoteAmount: BN;
398
+ baseTokenProgram?: PublicKey;
399
+ quoteTokenProgram?: PublicKey;
400
+ }): Promise<TransactionInstruction> {
401
+ const quoteMint = params.quoteMint ?? WSOL_MINT;
402
+ const [poolAddress] = getPoolPDA(
403
+ params.baseMint,
404
+ quoteMint,
405
+ this.config.liquidSwapProgramId
406
+ );
407
+ const [lpMint] = getPoolLpMintPDA(
408
+ poolAddress,
409
+ this.config.liquidSwapProgramId
410
+ );
411
+ const [baseVault] = getPoolVaultPDA(
412
+ poolAddress,
413
+ params.baseMint,
414
+ this.config.liquidSwapProgramId
415
+ );
416
+ const [quoteVault] = getPoolVaultPDA(
417
+ poolAddress,
418
+ quoteMint,
419
+ this.config.liquidSwapProgramId
420
+ );
421
+
422
+ const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
423
+ params.baseTokenProgram
424
+ ? Promise.resolve(params.baseTokenProgram)
425
+ : resolveTokenProgramFn(this.connection, params.baseMint),
426
+ params.quoteTokenProgram
427
+ ? Promise.resolve(params.quoteTokenProgram)
428
+ : resolveTokenProgramFn(this.connection, quoteMint),
429
+ ]);
430
+
431
+ return buildDeposit({
432
+ owner: params.owner,
433
+ poolAddress,
434
+ baseMint: params.baseMint,
435
+ quoteMint,
436
+ baseTokenProgram,
437
+ quoteTokenProgram,
438
+ baseVault,
439
+ quoteVault,
440
+ lpMint,
441
+ lpTokenAmount: params.lpTokenAmount,
442
+ maximumBaseAmount: params.maximumBaseAmount,
443
+ maximumQuoteAmount: params.maximumQuoteAmount,
444
+ config: this.config,
445
+ });
446
+ }
447
+
448
+ /**
449
+ * Builds a withdraw (remove liquidity) instruction.
450
+ * Auto-resolves pool PDAs, vaults, LP mint, and token programs.
451
+ * Defaults quoteMint to WSOL.
452
+ */
453
+ async buildWithdraw(params: {
454
+ owner: PublicKey;
455
+ baseMint: PublicKey;
456
+ quoteMint?: PublicKey;
457
+ lpTokenAmount: BN;
458
+ minimumBaseAmount: BN;
459
+ minimumQuoteAmount: BN;
460
+ baseTokenProgram?: PublicKey;
461
+ quoteTokenProgram?: PublicKey;
462
+ }): Promise<TransactionInstruction> {
463
+ const quoteMint = params.quoteMint ?? WSOL_MINT;
464
+ const [poolAddress] = getPoolPDA(
465
+ params.baseMint,
466
+ quoteMint,
467
+ this.config.liquidSwapProgramId
468
+ );
469
+ const [lpMint] = getPoolLpMintPDA(
470
+ poolAddress,
471
+ this.config.liquidSwapProgramId
472
+ );
473
+ const [baseVault] = getPoolVaultPDA(
474
+ poolAddress,
475
+ params.baseMint,
476
+ this.config.liquidSwapProgramId
477
+ );
478
+ const [quoteVault] = getPoolVaultPDA(
479
+ poolAddress,
480
+ quoteMint,
481
+ this.config.liquidSwapProgramId
482
+ );
483
+
484
+ const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
485
+ params.baseTokenProgram
486
+ ? Promise.resolve(params.baseTokenProgram)
487
+ : resolveTokenProgramFn(this.connection, params.baseMint),
488
+ params.quoteTokenProgram
489
+ ? Promise.resolve(params.quoteTokenProgram)
490
+ : resolveTokenProgramFn(this.connection, quoteMint),
491
+ ]);
492
+
493
+ return buildWithdraw({
494
+ owner: params.owner,
495
+ poolAddress,
496
+ baseMint: params.baseMint,
497
+ quoteMint,
498
+ baseTokenProgram,
499
+ quoteTokenProgram,
500
+ baseVault,
501
+ quoteVault,
502
+ lpMint,
503
+ lpTokenAmount: params.lpTokenAmount,
504
+ minimumBaseAmount: params.minimumBaseAmount,
505
+ minimumQuoteAmount: params.minimumQuoteAmount,
506
+ config: this.config,
507
+ });
508
+ }
509
+
510
+ /**
511
+ * Builds an executeBuyback instruction for an AMM pool.
512
+ * Auto-resolves token programs if not provided. Defaults quoteMint to WSOL.
513
+ */
514
+ async buildSwapExecuteBuyback(params: {
515
+ payer: PublicKey;
516
+ baseMint: PublicKey;
517
+ quoteMint?: PublicKey;
518
+ baseTokenProgram?: PublicKey;
519
+ quoteTokenProgram?: PublicKey;
520
+ }): Promise<TransactionInstruction> {
521
+ const quoteMint = params.quoteMint ?? WSOL_MINT;
522
+ const [baseTokenProgram, quoteTokenProgram] = await Promise.all([
523
+ params.baseTokenProgram
524
+ ? Promise.resolve(params.baseTokenProgram)
525
+ : resolveTokenProgramFn(this.connection, params.baseMint),
526
+ params.quoteTokenProgram
527
+ ? Promise.resolve(params.quoteTokenProgram)
528
+ : resolveTokenProgramFn(this.connection, quoteMint),
529
+ ]);
530
+
531
+ return buildSwapExecuteBuyback({
532
+ payer: params.payer,
533
+ baseMint: params.baseMint,
534
+ quoteMint,
535
+ baseTokenProgram,
536
+ quoteTokenProgram,
537
+ config: this.config,
538
+ });
539
+ }
540
+
541
+ /** Builds an updateFeeConfig instruction. Cannot be called on revoked configs. */
542
+ buildUpdateFeeConfig(params: {
543
+ authority: PublicKey;
544
+ tokenMint: PublicKey;
545
+ recipients?: FeeRecipient[] | null;
546
+ newUpdateAuthority?: PublicKey | null;
547
+ /** Required when changing recipients to verify token fee vault is drained. */
548
+ quoteMint?: PublicKey;
549
+ }): Promise<TransactionInstruction> {
550
+ return buildUpdateFeeConfig({ ...params, config: this.config });
551
+ }
552
+
553
+ /** Builds a revokeFeeConfig instruction. Permanently sets fee mode to Revoked. Irreversible. */
554
+ buildRevokeFeeConfig(params: {
555
+ authority: PublicKey;
556
+ tokenMint: PublicKey;
557
+ quoteMint: PublicKey;
558
+ }): Promise<TransactionInstruction> {
559
+ return buildRevokeFeeConfig({ ...params, config: this.config });
560
+ }
561
+
562
+ /** Builds a permissionless distributeFees instruction (SOL fees). */
563
+ buildDistributeFees(params: {
564
+ payer: PublicKey;
565
+ tokenMint: PublicKey;
566
+ recipientVaults: PublicKey[];
567
+ }): Promise<TransactionInstruction> {
568
+ return buildDistributeFees({ ...params, config: this.config });
569
+ }
570
+
571
+ /** Builds a permissionless distributeTokenFees instruction (SPL token fees). */
572
+ buildDistributeTokenFees(params: {
573
+ payer: PublicKey;
574
+ tokenMint: PublicKey;
575
+ quoteMint: PublicKey;
576
+ recipientVaultPairs: RecipientVaultPair[];
577
+ }): Promise<TransactionInstruction> {
578
+ return buildDistributeTokenFees({ ...params, config: this.config });
579
+ }
580
+
581
+ /** Builds a claimFees instruction. Recipient claims accumulated SOL from their vault PDA. */
582
+ buildClaimFees(params: {
583
+ recipient: PublicKey;
584
+ tokenMint: PublicKey;
585
+ }): Promise<TransactionInstruction> {
586
+ return buildClaimFees({ ...params, config: this.config });
587
+ }
588
+
589
+ /** Builds a claimTokenFees instruction. Recipient claims accumulated tokens from their vault ATA. */
590
+ buildClaimTokenFees(params: {
591
+ recipient: PublicKey;
592
+ tokenMint: PublicKey;
593
+ quoteMint: PublicKey;
594
+ }): Promise<TransactionInstruction> {
595
+ return buildClaimTokenFees({ ...params, config: this.config });
596
+ }
597
+
598
+ /** Builds an initializeUser instruction. Creates the user properties account. */
599
+ buildInitializeUser(params: {
600
+ user: PublicKey;
601
+ }): Promise<TransactionInstruction> {
602
+ return buildInitializeUser({ ...params, config: this.config });
603
+ }
604
+
605
+ /** Builds a setReferrer instruction. One-time operation — referrer cannot be changed. */
606
+ buildSetReferrer(params: {
607
+ user: PublicKey;
608
+ referrer: PublicKey;
609
+ }): Promise<TransactionInstruction> {
610
+ return buildSetReferrer({ ...params, config: this.config });
611
+ }
612
+
613
+ /** Builds a setCashbackMode instruction. Toggles between earning and spending mode. */
614
+ buildSetCashbackMode(params: {
615
+ user: PublicKey;
616
+ }): Promise<TransactionInstruction> {
617
+ return buildSetCashbackMode({ ...params, config: this.config });
618
+ }
619
+
620
+ /** Builds a transferAdmin instruction. Proposes admin transfer to a new pubkey (two-step). */
621
+ buildTransferAdmin(params: {
622
+ admin: PublicKey;
623
+ newAdmin: PublicKey;
624
+ }): Promise<TransactionInstruction> {
625
+ return buildTransferAdmin({ ...params, config: this.config });
626
+ }
627
+
628
+ /** Builds an acceptAdmin instruction. Completes a pending admin transfer. */
629
+ buildAcceptAdmin(params: {
630
+ newAdmin: PublicKey;
631
+ }): Promise<TransactionInstruction> {
632
+ return buildAcceptAdmin({ ...params, config: this.config });
633
+ }
634
+
635
+ /** Builds a cancelAdminTransfer instruction. Cancels a pending admin transfer. */
636
+ buildCancelAdminTransfer(params: {
637
+ authority: PublicKey;
638
+ }): Promise<TransactionInstruction> {
639
+ return buildCancelAdminTransfer({ ...params, config: this.config });
640
+ }
641
+
642
+ /** Builds a createDeal instruction. Admin creates an exclusive deal for a pubkey. */
643
+ buildCreateDeal(params: {
644
+ admin: PublicKey;
645
+ owner: PublicKey;
646
+ cashbackMultiplierBps: number;
647
+ payer: PublicKey;
648
+ }): Promise<TransactionInstruction> {
649
+ return buildCreateDeal({ ...params, config: this.config });
650
+ }
651
+
652
+ /** Builds an updateDeal instruction. Admin updates a deal's cashback multiplier. */
653
+ buildUpdateDeal(params: {
654
+ admin: PublicKey;
655
+ dealOwner: PublicKey;
656
+ newCashbackMultiplierBps: number;
657
+ }): Promise<TransactionInstruction> {
658
+ return buildUpdateDeal({ ...params, config: this.config });
659
+ }
660
+
661
+ /** Builds a closeDeal instruction. Admin closes/deletes a deal, returning rent. */
662
+ buildCloseDeal(params: {
663
+ admin: PublicKey;
664
+ dealOwner: PublicKey;
665
+ }): Promise<TransactionInstruction> {
666
+ return buildCloseDeal({ ...params, config: this.config });
667
+ }
668
+
669
+ /** Builds a redeemDeal instruction. User redeems their referrer's deal. */
670
+ buildRedeemDeal(params: {
671
+ user: PublicKey;
672
+ dealOwner: PublicKey;
673
+ }): Promise<TransactionInstruction> {
674
+ return buildRedeemDeal({ ...params, config: this.config });
675
+ }
676
+
677
+ /** Builds a takeSnapshot instruction. Admin takes a snapshot of a user's volume. */
678
+ buildTakeSnapshot(params: {
679
+ admin: PublicKey;
680
+ user: PublicKey;
681
+ payer: PublicKey;
682
+ snapshotIndex: number;
683
+ }): Promise<TransactionInstruction> {
684
+ return buildTakeSnapshot({ ...params, config: this.config });
685
+ }
686
+
687
+ /** Builds an adminUpdateUser instruction. Admin updates a user's referrer/multiplier and takes a snapshot. */
688
+ buildAdminUpdateUser(params: {
689
+ admin: PublicKey;
690
+ user: PublicKey;
691
+ payer: PublicKey;
692
+ newReferrer: PublicKey | null;
693
+ newCashbackMultiplierBps: number | null;
694
+ snapshotIndex: number;
695
+ }): Promise<TransactionInstruction> {
696
+ return buildAdminUpdateUser({ ...params, config: this.config });
697
+ }
698
+
699
+ /** Fetches the global configuration for the bonding curve program. */
700
+ fetchLiquidGlobalConfig() {
701
+ return fetchLiquidGlobalConfigFn(this.connection, this.config);
702
+ }
703
+
704
+ /** Fetches a bonding curve account by token mint. */
705
+ fetchNativeBondingCurve(mint: PublicKey) {
706
+ return fetchNativeBondingCurveFn(this.connection, mint, this.config);
707
+ }
708
+
709
+ /** Fetches a bonding curve account by its PDA address directly. */
710
+ fetchNativeBondingCurveByAddress(address: PublicKey) {
711
+ return fetchNativeBondingCurveByAddressFn(
712
+ this.connection,
713
+ address,
714
+ this.config
715
+ );
716
+ }
717
+
718
+ /** Fetches the AMM global configuration. */
719
+ fetchAmmConfig() {
720
+ return fetchAmmConfigFn(this.connection, this.config);
721
+ }
722
+
723
+ /** Fetches an AMM pool state by base and quote mint. */
724
+ fetchPoolState(baseMint: PublicKey, quoteMint: PublicKey = WSOL_MINT) {
725
+ return fetchPoolStateFn(
726
+ this.connection,
727
+ baseMint,
728
+ quoteMint,
729
+ this.config
730
+ );
731
+ }
732
+
733
+ /** Fetches a pool state by its PDA address directly. */
734
+ fetchPoolStateByAddress(address: PublicKey) {
735
+ return fetchPoolStateByAddressFn(this.connection, address, this.config);
736
+ }
737
+
738
+ /** Fetches the observation state (oracle data) for a pool. */
739
+ fetchObservationState(poolAddress: PublicKey) {
740
+ return fetchObservationStateFn(
741
+ this.connection,
742
+ poolAddress,
743
+ this.config
744
+ );
745
+ }
746
+
747
+ /** Fetches the fee configuration for a token mint. */
748
+ fetchFeeConfig(tokenMint: PublicKey) {
749
+ return fetchFeeConfigFn(this.connection, tokenMint, this.config);
750
+ }
751
+
752
+ /** Fetches a fee configuration by its PDA address directly. */
753
+ fetchFeeConfigByAddress(address: PublicKey) {
754
+ return fetchFeeConfigByAddressFn(this.connection, address, this.config);
755
+ }
756
+
757
+ /** Fetches a user's properties (referrer, volumes, cashback state). */
758
+ fetchUserProperties(user: PublicKey) {
759
+ return fetchUserPropertiesFn(this.connection, user, this.config);
760
+ }
761
+
762
+ /** Fetches the token volume accumulator for a mint. */
763
+ fetchTokenVolume(mint: PublicKey) {
764
+ return fetchTokenVolumeFn(this.connection, mint, this.config);
765
+ }
766
+
767
+ /** Fetches the global curve volume accumulator. */
768
+ fetchGlobalCurveVolume() {
769
+ return fetchGlobalCurveVolumeFn(this.connection, this.config);
770
+ }
771
+
772
+ /** Fetches the global AMM volume accumulator. */
773
+ fetchGlobalAmmVolume() {
774
+ return fetchGlobalAmmVolumeFn(this.connection, this.config);
775
+ }
776
+
777
+ /** Fetches the cashback configuration. */
778
+ fetchCashbackConfig() {
779
+ return fetchCashbackConfigFn(this.connection, this.config);
780
+ }
781
+
782
+ /** Fetches a user snapshot by user and index. */
783
+ fetchUserSnapshot(user: PublicKey, index: number) {
784
+ return fetchUserSnapshotFn(this.connection, user, index, this.config);
785
+ }
786
+
787
+ /** Fetches a deal account by its owner. */
788
+ fetchDeal(owner: PublicKey) {
789
+ return fetchDealFn(this.connection, owner, this.config);
790
+ }
791
+
792
+ /**
793
+ * Previews a buy on the bonding curve. Auto-fetches state from chain.
794
+ *
795
+ * @param mint - Token mint address
796
+ * @param amountInQuote - Quote token amount to spend (lamports for SOL, smallest unit for stables)
797
+ * @param options - Native (`{ solPriceUsd }`) or stable (`{ quoteMint }`) curve options
798
+ * @returns Buy preview with `tokensOut`, `fees`, `priceImpactBps`, `newReserves`, and `willComplete`
799
+ */
800
+ previewBuyOnCurve(
801
+ mint: PublicKey,
802
+ amountInQuote: BN,
803
+ options: CurveAsyncOptions
804
+ ): Promise<BuyCurvePreview> {
805
+ return previewBuyOnCurveFn(
806
+ this.connection,
807
+ mint,
808
+ amountInQuote,
809
+ this.config,
810
+ options
811
+ );
812
+ }
813
+
814
+ /**
815
+ * Previews a sell on the bonding curve. Auto-fetches state from chain.
816
+ *
817
+ * @param mint - Token mint address
818
+ * @param amountInTokens - Token amount to sell (smallest unit, 6 decimals)
819
+ * @param options - Native (`{ solPriceUsd }`) or stable (`{ quoteMint }`) curve options
820
+ * @returns Sell preview with `quoteOut`, `quoteOutNet`, `fees`, `priceImpactBps`, and `newReserves`
821
+ */
822
+ previewSellOnCurve(
823
+ mint: PublicKey,
824
+ amountInTokens: BN,
825
+ options: CurveAsyncOptions
826
+ ): Promise<SellCurvePreview> {
827
+ return previewSellOnCurveFn(
828
+ this.connection,
829
+ mint,
830
+ amountInTokens,
831
+ this.config,
832
+ options
833
+ );
834
+ }
835
+
836
+ /** Previews a sell swap on the AMM (base → quote). Accepts optional pre-fetched state. */
837
+ previewSwapSell(
838
+ baseMint: PublicKey,
839
+ quoteMint: PublicKey,
840
+ amountIn: BN,
841
+ options?: { prefetched?: SwapPrefetchedState }
842
+ ): Promise<SwapPreview> {
843
+ return previewSwapSellFn(
844
+ this.connection,
845
+ baseMint,
846
+ quoteMint,
847
+ amountIn,
848
+ this.config,
849
+ options
850
+ );
851
+ }
852
+
853
+ /** Previews a buy swap on the AMM (quote → base). Accepts optional pre-fetched state. */
854
+ previewSwapBuy(
855
+ baseMint: PublicKey,
856
+ quoteMint: PublicKey,
857
+ amountOut: BN,
858
+ options?: { prefetched?: SwapPrefetchedState }
859
+ ): Promise<SwapPreview> {
860
+ return previewSwapBuyFn(
861
+ this.connection,
862
+ baseMint,
863
+ quoteMint,
864
+ amountOut,
865
+ this.config,
866
+ options
867
+ );
868
+ }
869
+
870
+ /** Derives the bonding curve PDA for a token mint. */
871
+ getBondingCurvePDA(mint: PublicKey): [PublicKey, number] {
872
+ return getBondingCurvePDA(mint, this.config.liquidProgramId);
873
+ }
874
+
875
+ /** Derives the SOL vault PDA for a bonding curve. */
876
+ getBondingCurveSolVaultPDA(bondingCurve: PublicKey): [PublicKey, number] {
877
+ return getBondingCurveSolVaultPDA(
878
+ bondingCurve,
879
+ this.config.liquidProgramId
880
+ );
881
+ }
882
+
883
+ /** Derives the referral vault PDA. */
884
+ getReferralVaultPDA(referrer: PublicKey): [PublicKey, number] {
885
+ return getReferralVaultPDA(referrer, this.config.liquidProgramId);
886
+ }
887
+
888
+ /** Derives the buyback vault PDA for a bonding curve. */
889
+ getBuybackVaultPDA(bondingCurve: PublicKey): [PublicKey, number] {
890
+ return getBuybackVaultPDA(bondingCurve, this.config.liquidProgramId);
891
+ }
892
+
893
+ /** Derives the pool state PDA for a token pair. */
894
+ getPoolPDA(
895
+ baseMint: PublicKey,
896
+ quoteMint: PublicKey = WSOL_MINT
897
+ ): [PublicKey, number] {
898
+ return getPoolPDA(baseMint, quoteMint, this.config.liquidSwapProgramId);
899
+ }
900
+
901
+ /** Derives the LP mint PDA for a pool. */
902
+ getPoolLpMintPDA(poolState: PublicKey): [PublicKey, number] {
903
+ return getPoolLpMintPDA(poolState, this.config.liquidSwapProgramId);
904
+ }
905
+
906
+ /** Derives the pool vault PDA for a specific token. */
907
+ getPoolVaultPDA(
908
+ poolState: PublicKey,
909
+ mint: PublicKey
910
+ ): [PublicKey, number] {
911
+ return getPoolVaultPDA(
912
+ poolState,
913
+ mint,
914
+ this.config.liquidSwapProgramId
915
+ );
916
+ }
917
+
918
+ /** Derives the observation state PDA (oracle data) for a pool. */
919
+ getObservationPDA(poolState: PublicKey): [PublicKey, number] {
920
+ return getObservationPDA(poolState, this.config.liquidSwapProgramId);
921
+ }
922
+
923
+ /** Derives the fee configuration PDA for a token mint. */
924
+ getFeeConfigPDA(tokenMint: PublicKey): [PublicKey, number] {
925
+ return getFeeConfigPDA(tokenMint, this.config.liquidFeesProgramId);
926
+ }
927
+
928
+ /** Derives the fee vault PDA for a fee configuration. */
929
+ getFeeVaultPDA(feeConfig: PublicKey): [PublicKey, number] {
930
+ return getFeeVaultPDA(feeConfig, this.config.liquidFeesProgramId);
931
+ }
932
+
933
+ /** Derives the recipient vault PDA for a specific recipient within a fee config. */
934
+ getRecipientVaultPDA(
935
+ feeConfig: PublicKey,
936
+ recipient: PublicKey
937
+ ): [PublicKey, number] {
938
+ return getRecipientVaultPDA(
939
+ feeConfig,
940
+ recipient,
941
+ this.config.liquidFeesProgramId
942
+ );
943
+ }
944
+
945
+ /** Derives the user properties PDA. */
946
+ getUserPropertiesPDA(user: PublicKey): [PublicKey, number] {
947
+ return getUserPropertiesPDA(user, this.config.liquidStateProgramId);
948
+ }
949
+
950
+ /** Derives the token volume accumulator PDA. */
951
+ getTokenVolumePDA(mint: PublicKey): [PublicKey, number] {
952
+ return getTokenVolumePDA(mint, this.config.liquidStateProgramId);
953
+ }
954
+
955
+ /** Derives the user snapshot PDA for a given user and index. */
956
+ getUserSnapshotPDA(user: PublicKey, index: number): [PublicKey, number] {
957
+ return getUserSnapshotPDA(
958
+ user,
959
+ index,
960
+ this.config.liquidStateProgramId
961
+ );
962
+ }
963
+
964
+ /** Derives the deal PDA for a given owner. */
965
+ getDealPDA(owner: PublicKey): [PublicKey, number] {
966
+ return getDealPDA(owner, this.config.liquidStateProgramId);
967
+ }
968
+
969
+ /** Derives all PDAs associated with a bonding curve token. */
970
+ getAllBondingCurvePDAs(mint: PublicKey, creator: PublicKey) {
971
+ return getAllBondingCurvePDAs(mint, creator, this.config);
972
+ }
973
+
974
+ /** Derives all PDAs associated with an AMM pool. */
975
+ getAllPoolPDAs(baseMint: PublicKey, quoteMint: PublicKey = WSOL_MINT) {
976
+ return getAllPoolPDAs(baseMint, quoteMint, this.config);
977
+ }
978
+
979
+ /** Derives all PDAs needed for bonding curve to AMM migration. */
980
+ getMigrationPDAs(tokenMint: PublicKey) {
981
+ return getMigrationPDAs(tokenMint, this.config);
982
+ }
983
+
984
+ /**
985
+ * Builds an unsigned Transaction from instructions, with optional compute
986
+ * budget. Fetches a recent blockhash. Caller is responsible for signing.
987
+ */
988
+ buildTransaction(
989
+ instructions: TransactionInstruction[],
990
+ options: BuildTransactionOptions
991
+ ): Promise<Transaction> {
992
+ return buildTransactionFn(this.connection, instructions, options);
993
+ }
994
+
995
+ /**
996
+ * Resolves the token program (SPL Token or Token-2022) for a mint.
997
+ */
998
+ resolveTokenProgram(mint: PublicKey): Promise<PublicKey> {
999
+ return resolveTokenProgramFn(this.connection, mint);
1000
+ }
1001
+ }