@coffer_so/sdk 1.0.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 (228) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/dist/clients/AdminClient.d.ts +194 -0
  4. package/dist/clients/AdminClient.d.ts.map +1 -0
  5. package/dist/clients/AdminClient.js +482 -0
  6. package/dist/clients/AdminClient.js.map +1 -0
  7. package/dist/clients/CofferBackendClient.d.ts +877 -0
  8. package/dist/clients/CofferBackendClient.d.ts.map +1 -0
  9. package/dist/clients/CofferBackendClient.js +536 -0
  10. package/dist/clients/CofferBackendClient.js.map +1 -0
  11. package/dist/clients/CubeBackendClient.d.ts +877 -0
  12. package/dist/clients/CubeBackendClient.d.ts.map +1 -0
  13. package/dist/clients/CubeBackendClient.js +536 -0
  14. package/dist/clients/CubeBackendClient.js.map +1 -0
  15. package/dist/clients/CubicPoolClient.d.ts +120 -0
  16. package/dist/clients/CubicPoolClient.d.ts.map +1 -0
  17. package/dist/clients/CubicPoolClient.js +687 -0
  18. package/dist/clients/CubicPoolClient.js.map +1 -0
  19. package/dist/clients/PoolFactoryClient.d.ts +53 -0
  20. package/dist/clients/PoolFactoryClient.d.ts.map +1 -0
  21. package/dist/clients/PoolFactoryClient.js +91 -0
  22. package/dist/clients/PoolFactoryClient.js.map +1 -0
  23. package/dist/clients/RpcClient.d.ts +49 -0
  24. package/dist/clients/RpcClient.d.ts.map +1 -0
  25. package/dist/clients/RpcClient.js +135 -0
  26. package/dist/clients/RpcClient.js.map +1 -0
  27. package/dist/clients/SingleTokenDepositClient.d.ts +67 -0
  28. package/dist/clients/SingleTokenDepositClient.d.ts.map +1 -0
  29. package/dist/clients/SingleTokenDepositClient.js +105 -0
  30. package/dist/clients/SingleTokenDepositClient.js.map +1 -0
  31. package/dist/clients/contract-instructions.d.ts +24 -0
  32. package/dist/clients/contract-instructions.d.ts.map +1 -0
  33. package/dist/clients/contract-instructions.js +130 -0
  34. package/dist/clients/contract-instructions.js.map +1 -0
  35. package/dist/clients/index.d.ts +10 -0
  36. package/dist/clients/index.d.ts.map +1 -0
  37. package/dist/clients/index.js +26 -0
  38. package/dist/clients/index.js.map +1 -0
  39. package/dist/clients/quote-math.d.ts +15 -0
  40. package/dist/clients/quote-math.d.ts.map +1 -0
  41. package/dist/clients/quote-math.js +98 -0
  42. package/dist/clients/quote-math.js.map +1 -0
  43. package/dist/clients/tx-builders.d.ts +231 -0
  44. package/dist/clients/tx-builders.d.ts.map +1 -0
  45. package/dist/clients/tx-builders.js +861 -0
  46. package/dist/clients/tx-builders.js.map +1 -0
  47. package/dist/clients/versioned.d.ts +34 -0
  48. package/dist/clients/versioned.d.ts.map +1 -0
  49. package/dist/clients/versioned.js +55 -0
  50. package/dist/clients/versioned.js.map +1 -0
  51. package/dist/config/index.d.ts +65 -0
  52. package/dist/config/index.d.ts.map +1 -0
  53. package/dist/config/index.js +75 -0
  54. package/dist/config/index.js.map +1 -0
  55. package/dist/config/networks.d.ts +12 -0
  56. package/dist/config/networks.d.ts.map +1 -0
  57. package/dist/config/networks.js +51 -0
  58. package/dist/config/networks.js.map +1 -0
  59. package/dist/config/tokens.d.ts +19 -0
  60. package/dist/config/tokens.d.ts.map +1 -0
  61. package/dist/config/tokens.js +43 -0
  62. package/dist/config/tokens.js.map +1 -0
  63. package/dist/idl/cubic_pool.json +4203 -0
  64. package/dist/idl/index.d.ts +1769 -0
  65. package/dist/idl/index.d.ts.map +1 -0
  66. package/dist/idl/index.js +18 -0
  67. package/dist/idl/index.js.map +1 -0
  68. package/dist/idl/protocol_admin.json +2615 -0
  69. package/dist/idl/single_token_liquidity.json +1121 -0
  70. package/dist/index.d.ts +75 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +206 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/math/cubicMath.d.ts +40 -0
  75. package/dist/math/cubicMath.d.ts.map +1 -0
  76. package/dist/math/cubicMath.js +82 -0
  77. package/dist/math/cubicMath.js.map +1 -0
  78. package/dist/math/fixedPoint.d.ts +19 -0
  79. package/dist/math/fixedPoint.d.ts.map +1 -0
  80. package/dist/math/fixedPoint.js +86 -0
  81. package/dist/math/fixedPoint.js.map +1 -0
  82. package/dist/math/index.d.ts +9 -0
  83. package/dist/math/index.d.ts.map +1 -0
  84. package/dist/math/index.js +30 -0
  85. package/dist/math/index.js.map +1 -0
  86. package/dist/math/logExp.d.ts +6 -0
  87. package/dist/math/logExp.d.ts.map +1 -0
  88. package/dist/math/logExp.js +68 -0
  89. package/dist/math/logExp.js.map +1 -0
  90. package/dist/math/lpLoss.d.ts +44 -0
  91. package/dist/math/lpLoss.d.ts.map +1 -0
  92. package/dist/math/lpLoss.js +103 -0
  93. package/dist/math/lpLoss.js.map +1 -0
  94. package/dist/math/maxSelloff.d.ts +164 -0
  95. package/dist/math/maxSelloff.d.ts.map +1 -0
  96. package/dist/math/maxSelloff.js +397 -0
  97. package/dist/math/maxSelloff.js.map +1 -0
  98. package/dist/math/singleToken.d.ts +54 -0
  99. package/dist/math/singleToken.d.ts.map +1 -0
  100. package/dist/math/singleToken.js +188 -0
  101. package/dist/math/singleToken.js.map +1 -0
  102. package/dist/math/slippage.d.ts +13 -0
  103. package/dist/math/slippage.d.ts.map +1 -0
  104. package/dist/math/slippage.js +44 -0
  105. package/dist/math/slippage.js.map +1 -0
  106. package/dist/math/surgeFee.d.ts +24 -0
  107. package/dist/math/surgeFee.d.ts.map +1 -0
  108. package/dist/math/surgeFee.js +85 -0
  109. package/dist/math/surgeFee.js.map +1 -0
  110. package/dist/math/weightedMath.d.ts +20 -0
  111. package/dist/math/weightedMath.d.ts.map +1 -0
  112. package/dist/math/weightedMath.js +66 -0
  113. package/dist/math/weightedMath.js.map +1 -0
  114. package/dist/parsers/borsh.d.ts +28 -0
  115. package/dist/parsers/borsh.d.ts.map +1 -0
  116. package/dist/parsers/borsh.js +104 -0
  117. package/dist/parsers/borsh.js.map +1 -0
  118. package/dist/parsers/contracts.d.ts +26 -0
  119. package/dist/parsers/contracts.d.ts.map +1 -0
  120. package/dist/parsers/contracts.js +62 -0
  121. package/dist/parsers/contracts.js.map +1 -0
  122. package/dist/parsers/events.d.ts +3 -0
  123. package/dist/parsers/events.d.ts.map +1 -0
  124. package/dist/parsers/events.js +281 -0
  125. package/dist/parsers/events.js.map +1 -0
  126. package/dist/parsers/index.d.ts +6 -0
  127. package/dist/parsers/index.d.ts.map +1 -0
  128. package/dist/parsers/index.js +22 -0
  129. package/dist/parsers/index.js.map +1 -0
  130. package/dist/parsers/mintAccount.d.ts +24 -0
  131. package/dist/parsers/mintAccount.d.ts.map +1 -0
  132. package/dist/parsers/mintAccount.js +27 -0
  133. package/dist/parsers/mintAccount.js.map +1 -0
  134. package/dist/parsers/poolAccount.d.ts +141 -0
  135. package/dist/parsers/poolAccount.d.ts.map +1 -0
  136. package/dist/parsers/poolAccount.js +224 -0
  137. package/dist/parsers/poolAccount.js.map +1 -0
  138. package/dist/types/contracts.d.ts +1340 -0
  139. package/dist/types/contracts.d.ts.map +1 -0
  140. package/dist/types/contracts.js +3 -0
  141. package/dist/types/contracts.js.map +1 -0
  142. package/dist/types/events.d.ts +172 -0
  143. package/dist/types/events.d.ts.map +1 -0
  144. package/dist/types/events.js +3 -0
  145. package/dist/types/events.js.map +1 -0
  146. package/dist/types/index.d.ts +6 -0
  147. package/dist/types/index.d.ts.map +1 -0
  148. package/dist/types/index.js +22 -0
  149. package/dist/types/index.js.map +1 -0
  150. package/dist/types/pool.d.ts +149 -0
  151. package/dist/types/pool.d.ts.map +1 -0
  152. package/dist/types/pool.js +3 -0
  153. package/dist/types/pool.js.map +1 -0
  154. package/dist/types/result.d.ts +24 -0
  155. package/dist/types/result.d.ts.map +1 -0
  156. package/dist/types/result.js +11 -0
  157. package/dist/types/result.js.map +1 -0
  158. package/dist/types/tx.d.ts +261 -0
  159. package/dist/types/tx.d.ts.map +1 -0
  160. package/dist/types/tx.js +3 -0
  161. package/dist/types/tx.js.map +1 -0
  162. package/dist/utils/errors.d.ts +44 -0
  163. package/dist/utils/errors.d.ts.map +1 -0
  164. package/dist/utils/errors.js +192 -0
  165. package/dist/utils/errors.js.map +1 -0
  166. package/dist/utils/extensions.d.ts +98 -0
  167. package/dist/utils/extensions.d.ts.map +1 -0
  168. package/dist/utils/extensions.js +187 -0
  169. package/dist/utils/extensions.js.map +1 -0
  170. package/dist/utils/index.d.ts +5 -0
  171. package/dist/utils/index.d.ts.map +1 -0
  172. package/dist/utils/index.js +21 -0
  173. package/dist/utils/index.js.map +1 -0
  174. package/dist/utils/pda.d.ts +8 -0
  175. package/dist/utils/pda.d.ts.map +1 -0
  176. package/dist/utils/pda.js +27 -0
  177. package/dist/utils/pda.js.map +1 -0
  178. package/dist/utils/retry.d.ts +22 -0
  179. package/dist/utils/retry.d.ts.map +1 -0
  180. package/dist/utils/retry.js +62 -0
  181. package/dist/utils/retry.js.map +1 -0
  182. package/package.json +54 -0
  183. package/src/clients/AdminClient.ts +608 -0
  184. package/src/clients/CofferBackendClient.ts +1413 -0
  185. package/src/clients/CubicPoolClient.ts +719 -0
  186. package/src/clients/PoolFactoryClient.ts +110 -0
  187. package/src/clients/RpcClient.ts +195 -0
  188. package/src/clients/SingleTokenDepositClient.ts +143 -0
  189. package/src/clients/contract-instructions.ts +115 -0
  190. package/src/clients/index.ts +9 -0
  191. package/src/clients/quote-math.ts +81 -0
  192. package/src/clients/tx-builders.ts +1096 -0
  193. package/src/clients/versioned.ts +80 -0
  194. package/src/config/index.ts +111 -0
  195. package/src/config/networks.ts +71 -0
  196. package/src/config/tokens.ts +52 -0
  197. package/src/idl/cubic_pool.json +4203 -0
  198. package/src/idl/index.ts +13 -0
  199. package/src/idl/protocol_admin.json +2615 -0
  200. package/src/idl/single_token_liquidity.json +1121 -0
  201. package/src/index.ts +262 -0
  202. package/src/math/cubicMath.ts +92 -0
  203. package/src/math/fixedPoint.ts +71 -0
  204. package/src/math/index.ts +13 -0
  205. package/src/math/logExp.ts +61 -0
  206. package/src/math/lpLoss.ts +160 -0
  207. package/src/math/maxSelloff.ts +564 -0
  208. package/src/math/singleToken.ts +251 -0
  209. package/src/math/slippage.ts +38 -0
  210. package/src/math/surgeFee.ts +101 -0
  211. package/src/math/weightedMath.ts +64 -0
  212. package/src/parsers/borsh.ts +106 -0
  213. package/src/parsers/contracts.ts +64 -0
  214. package/src/parsers/events.ts +275 -0
  215. package/src/parsers/index.ts +5 -0
  216. package/src/parsers/mintAccount.ts +44 -0
  217. package/src/parsers/poolAccount.ts +372 -0
  218. package/src/types/contracts.ts +238 -0
  219. package/src/types/events.ts +198 -0
  220. package/src/types/index.ts +5 -0
  221. package/src/types/pool.ts +147 -0
  222. package/src/types/result.ts +51 -0
  223. package/src/types/tx.ts +278 -0
  224. package/src/utils/errors.ts +210 -0
  225. package/src/utils/extensions.ts +196 -0
  226. package/src/utils/index.ts +4 -0
  227. package/src/utils/pda.ts +58 -0
  228. package/src/utils/retry.ts +85 -0
@@ -0,0 +1,261 @@
1
+ import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ import BN from "bn.js";
3
+ export interface SwapParams {
4
+ user: PublicKey;
5
+ tokenInIndex: number;
6
+ tokenOutIndex: number;
7
+ amountIn: BN;
8
+ /** Hundredths-bps; omit to use SDK config default. */
9
+ slippageHundredthsBps?: number;
10
+ /** Optional explicit minimum; overrides slippage-derived value. */
11
+ minAmountOut?: BN;
12
+ }
13
+ export interface SwapQuote {
14
+ tokenInIndex: number;
15
+ tokenOutIndex: number;
16
+ amountIn: BN;
17
+ amountOut: BN;
18
+ /** Output before the sell-off surge fee (equals amountOut + surgeFeeAmount). */
19
+ grossAmountOut?: BN;
20
+ /** Spot-based upper bound on amountOut; useful for price-impact UI. */
21
+ spotOut: BN;
22
+ /** Absolute price impact in hundredths of basis point. */
23
+ priceImpactHbps: number;
24
+ feeAmount: BN;
25
+ protocolFeeAmount: BN;
26
+ /** Minimum amount_out to pass to the swap ix given the quoted slippage. */
27
+ minAmountOut: BN;
28
+ /** Variable sell-off surge fee taken from the output. `0` when no surge. */
29
+ surgeFeeAmount: BN;
30
+ /** Static fee (in PERCENT_SCALE units) + surge pct, for UI display. */
31
+ effectiveFeePct: number;
32
+ /** Post-trade window fill in PERCENT_SCALE units. `0` when window disabled. */
33
+ windowFillPct: number;
34
+ }
35
+ export interface AddLiquidityParams {
36
+ user: PublicKey;
37
+ /**
38
+ * Per-token spend CEILING, one entry per pool token, in raw units.
39
+ *
40
+ * ⚠ As of v5.1 (audit M-4 / I-1) this is an upper bound, **not** an exact
41
+ * amount. The program computes the largest strictly-proportional basket
42
+ * that fits inside this vector, deposits that, and leaves the rest in the
43
+ * user's wallet. Passing `[100, 100]` to a 1:9 pool deposits `[11, 100]`,
44
+ * not `[100, 100]`.
45
+ *
46
+ * Consequences for callers:
47
+ * - Do not render these as "amount you will deposit". Show the quoted
48
+ * proportional basket and treat this vector as a spend limit.
49
+ * - Balance checks should validate against the ceiling (that is the most
50
+ * that can be pulled), but post-tx accounting must read the
51
+ * `LiquidityAdded` event's `tokenAmounts` for what actually moved.
52
+ * - Length must equal `pool.tokenCount` or the program reverts with
53
+ * `InvalidArrayLength` (6064).
54
+ */
55
+ tokenAmounts: BN[];
56
+ /**
57
+ * Slippage floor on BPT minted. Required and must be > 0 — this is the
58
+ * only guard on the join, since `tokenAmounts` is now a ceiling rather
59
+ * than a commitment.
60
+ */
61
+ minimumBptAmount?: BN;
62
+ }
63
+ /**
64
+ * Result of `CubicPoolClient.quoteAddLiquidity`. Mirrors
65
+ * `cubic-pool/add_liquidity.rs`: the program crops the caller's ceiling
66
+ * vector to the single limiting ratio `min_i(amount_i / actual_i)`, pulls
67
+ * `depositAmounts` and leaves `refundAmounts` in the wallet.
68
+ */
69
+ export interface AddLiquidityQuote {
70
+ /** The ceiling vector that was quoted (echo of the input). */
71
+ tokenAmounts: BN[];
72
+ /** What the program will actually pull per token (proportional basket). */
73
+ depositAmounts: BN[];
74
+ /** `tokenAmounts - depositAmounts`; stays in the user's wallet. */
75
+ refundAmounts: BN[];
76
+ /** BPT the program will mint for this basket at the synced state. */
77
+ bptOut: BN;
78
+ /** `bptOut` after the quoted slippage; pass as `minimumBptAmount`. */
79
+ minimumBptAmount: BN;
80
+ /** Index of the token that limits the basket (smallest amount/balance). */
81
+ limitingTokenIndex: number;
82
+ }
83
+ export interface RemoveLiquidityParams {
84
+ user: PublicKey;
85
+ bptAmount: BN;
86
+ minimumTokenAmounts?: BN[];
87
+ }
88
+ /**
89
+ * Single-token deposit ("zap"): deposit one token, the helper swaps it into
90
+ * the pool's proportions and joins on your behalf.
91
+ *
92
+ * Supported on pools of up to 10 tokens as of v5.1 (was 5 — the old cap was
93
+ * a heap-exhaustion limit, audit SF-3). Beyond 10 the program rejects with
94
+ * `PoolTooLargeForZap`.
95
+ *
96
+ * This deployed build does not account for Token-2022 transfer fees. The SDK
97
+ * rejects transfer-fee mints and other runtime-incompatible extensions before
98
+ * building a deposit. Plain Token-2022 mints and compatible extensions work.
99
+ */
100
+ export interface SingleTokenDepositParams {
101
+ user: PublicKey;
102
+ tokenInIndex: number;
103
+ amountIn: BN;
104
+ /**
105
+ * Used only by the off-chain quote to derive `minimumBptAmount`. There is
106
+ * no per-call slippage argument on the instruction any more — the single
107
+ * `minimumBptAmount` floor bounds the entire zap, and per-leg swaps run
108
+ * with `min_out = 0` (which is what keeps the route correct under the
109
+ * path-dependent surge fee).
110
+ */
111
+ slippageHundredthsBps?: number;
112
+ /**
113
+ * Required, must be > 0. The only slippage guard on the whole route:
114
+ * internal swaps + surge fees + the join.
115
+ */
116
+ minimumBptAmount?: BN;
117
+ }
118
+ /** Quote includes the helperBalances supplied to the quote call, or assumes
119
+ * zero balances when omitted. Re-read helper ATAs and pool state before signing. */
120
+ export interface SingleTokenDepositQuote {
121
+ tokenInIndex: number;
122
+ amountIn: BN;
123
+ /** Per-token allocations (sum = amountIn). */
124
+ allocations: BN[];
125
+ /** Per-leg expected swap out. `0` for sidelined tokens. */
126
+ expectedOuts: BN[];
127
+ /** Per-leg min_out derived from slippage. */
128
+ minOuts: BN[];
129
+ /** Estimated actual pool credits after both helper and pool proportional cropping. */
130
+ depositedAmounts: BN[];
131
+ /** Helper-held excess returned to the user after add_liquidity. */
132
+ refundAmounts: BN[];
133
+ /** Projected new BPT from the complete swap-and-join sequence at quoted state/time. */
134
+ estimatedBpt: BN;
135
+ /** Indices of tokens excluded from the deposit (actBal == 0). */
136
+ sidelinedTokenIndices: number[];
137
+ }
138
+ export interface BuiltTx {
139
+ instructions: TransactionInstruction[];
140
+ /** Accounts that should sign (user is implicit). */
141
+ extraSigners?: PublicKey[];
142
+ /** Suggested CU limit — caller decides whether to prepend ComputeBudget ix. */
143
+ suggestedCuLimit: number;
144
+ }
145
+ export interface DeployPoolParams {
146
+ payer: PublicKey;
147
+ configKey: PublicKey;
148
+ poolId: BN;
149
+ /**
150
+ * Pool's token mints, in the same order as `weightsBps`/`virtualBalances`.
151
+ * There is no `tokens` field in the on-chain `initialize_cubic_pool` ix
152
+ * data — the program derives the token set solely from remaining_accounts
153
+ * (one mint per token). The SDK still requires this array so it can build
154
+ * that remaining_accounts list in the right order.
155
+ */
156
+ tokens: PublicKey[];
157
+ weightsBps: number[];
158
+ virtualBalances: BN[];
159
+ swapFeeRate: number;
160
+ /** SPL Token program to use for the BPT mint (classic SPL Token recommended). */
161
+ bptTokenProgram?: PublicKey;
162
+ /**
163
+ * Optional creator-chosen Token-2022 banned-extensions bitmap. Omit
164
+ * (`undefined`/`null`) to inherit the config default. Set a bitmap to vet
165
+ * THIS pool's tokens against it and store it on the pool. `0` clears the
166
+ * configurable default; the hard floor and runtime restrictions still apply.
167
+ *
168
+ * ⚠ A permissive policy (un-banning PermanentDelegate / TransferHook /
169
+ * TransferFee) makes the pool drainable/abusable by the token issuer —
170
+ * surface this to the user before deploying.
171
+ */
172
+ bannedExtensions?: BN | number | null;
173
+ }
174
+ /**
175
+ * One compare-and-swap entry in a `range_manager_update`.
176
+ *
177
+ * ⚠ `expectedCurrent` was inserted **between** `index` and `newValue` in
178
+ * v5.1 (audit M-6). It is not optional padding and it is not appended at
179
+ * the end: the on-chain struct is `{ index: u8, expected_current: u64,
180
+ * new_value: u64 }` in exactly that order.
181
+ */
182
+ export interface TokenChange {
183
+ /** Token index within the pool, `0 .. tokenCount-1`. */
184
+ index: number;
185
+ /**
186
+ * The value the caller believes is currently stored for this token —
187
+ * `virtualBalance` for a `vbChanges` entry, `weightBps` (as a BN) for a
188
+ * `weightChanges` entry.
189
+ *
190
+ * The program compares this against the live value and reverts the whole
191
+ * instruction with `RangeManagerStaleValue` (6061) on any mismatch. This
192
+ * makes every update a compare-and-swap: two managers racing, or a bot
193
+ * replaying a stale quote, can no longer clobber each other's writes.
194
+ *
195
+ * It must come from the same pool read that produced `newValue`. Do not
196
+ * synthesise it, and do not carry it across a re-read — on a stale
197
+ * failure, re-read the pool and recompute both fields together.
198
+ */
199
+ expectedCurrent: BN;
200
+ /** The value to write if `expectedCurrent` still matches. */
201
+ newValue: BN;
202
+ }
203
+ export interface RangeManagerUpdateParams {
204
+ /** Must be the pool's configured `range_manager` and it must be enabled. */
205
+ authority: PublicKey;
206
+ /** Sparse virtual-balance changes. May be empty. */
207
+ vbChanges?: TokenChange[];
208
+ /**
209
+ * Sparse normalized-weight changes (basis points). May be empty. The
210
+ * resulting weight vector must still sum to 10_000.
211
+ */
212
+ weightChanges?: TokenChange[];
213
+ }
214
+ export interface SetRangeManagerParams {
215
+ /**
216
+ * Pool's governance config account. New in v5.1 (audit L-1) — it is
217
+ * PREPENDED before `pool` in the account list.
218
+ */
219
+ config: PublicKey;
220
+ /** Pool admin, or config protocol admin for disable-only with the same manager. */
221
+ authority: PublicKey;
222
+ /** Pubkey allowed to call `range_manager_update`. */
223
+ newManager: PublicKey;
224
+ /** Gate flag; `false` blocks the manager even when the pubkey is set. */
225
+ enabled: boolean;
226
+ }
227
+ export interface SetRangeManagerConfigParams {
228
+ /** Pool-admin only. */
229
+ authority: PublicKey;
230
+ /** Max per-update virtual-balance change, `PERCENT_SCALE` (10_000 = 100%). */
231
+ maxVbChangePct: number;
232
+ /** Max per-update weight change, same units. */
233
+ maxWeightChangePct: number;
234
+ minUpdateIntervalSecs: number;
235
+ /**
236
+ * Absolute UPPER bound on `virtual_balance / actual_balance`, in basis
237
+ * points (10_000 = 1.0×). `0` disables the band. New in v5.1 (M-2/SF-20).
238
+ *
239
+ * The per-update percentage caps velocity, not distance — 5% steps
240
+ * compound to ~131× in 100 updates. This is the distance limit.
241
+ */
242
+ maxLeverageBps: number;
243
+ /**
244
+ * Absolute LOWER bound on the same ratio, same units. `0` disables the
245
+ * floor. New in v5.1.
246
+ */
247
+ minLeverageBps: number;
248
+ }
249
+ /** Per-token sell-off policy, in pool order. Percent fields use 10,000 = 100%,
250
+ * except feeKinkPct, which is a whole percent (0 disables the kink).
251
+ */
252
+ export interface SelloffParams {
253
+ maxSelloffPct: number;
254
+ periodLength: number;
255
+ feeThresholdPct: number;
256
+ feeSlopeLowPct: number;
257
+ feeSlopeHighPct: number;
258
+ feeSlopeMidPct: number;
259
+ feeKinkPct: number;
260
+ }
261
+ //# sourceMappingURL=tx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../src/types/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,EAAE,CAAC;IACb,sDAAsD;IACtD,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mEAAmE;IACnE,YAAY,CAAC,EAAE,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa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;IAC1B,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;;;;;;OAaG;IACH,eAAe,EAAE,EAAE,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,EAAE,EAAE,CAAC;CACd;AAED,MAAM,WAAW,wBAAwB;IACvC,4EAA4E;IAC5E,SAAS,EAAE,SAAS,CAAC;IACrB,oDAAoD;IACpD,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,MAAM,EAAE,SAAS,CAAC;IAClB,mFAAmF;IACnF,SAAS,EAAE,SAAS,CAAC;IACrB,qDAAqD;IACrD,UAAU,EAAE,SAAS,CAAC;IACtB,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,2BAA2B;IAC1C,uBAAuB;IACvB,SAAS,EAAE,SAAS,CAAC;IACrB,8EAA8E;IAC9E,cAAc,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,qBAAqB,EAAE,MAAM,CAAC;IAC9B;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=tx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx.js","sourceRoot":"","sources":["../../src/types/tx.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import { SdkError, SdkErrorCode } from "../types/result";
2
+ /**
3
+ * Which on-chain program produced an error code.
4
+ *
5
+ * Anchor numbers every program's errors from 6000, so a bare custom-error
6
+ * code is ambiguous across the three Coffer programs — `6030` is
7
+ * `InvalidTokenProgram` in cubic-pool but `TokenExtensionsUnsupported` in
8
+ * single-token-liquidity. Pass this to {@link toSdkError} when you know
9
+ * which program the failing instruction belonged to; without it the
10
+ * cubic-pool table is used, which is the right default for swap / add /
11
+ * remove but WRONG for a zap or an admin call.
12
+ */
13
+ export type CofferProgram = "cubicPool" | "singleTokenLiquidity" | "protocolAdmin";
14
+ type ErrorTable = Record<number, {
15
+ code: SdkErrorCode;
16
+ message: string;
17
+ name: string;
18
+ }>;
19
+ /**
20
+ * Convert a raw error (possibly from Anchor, web3.js, or fetch) into a
21
+ * cleanly-typed SdkError. Used by safeCall wrappers so callers always
22
+ * get structured errors, never exceptions.
23
+ *
24
+ * @param program Which Coffer program the failing instruction belonged to.
25
+ * Anchor numbers each program's errors from 6000 independently, so the
26
+ * same code means different things in different programs. Defaults to
27
+ * `"cubicPool"` (correct for swap / add / remove liquidity). Pass
28
+ * `"singleTokenLiquidity"` for zap failures and `"protocolAdmin"` for
29
+ * treasury-routed admin calls, or the message will be plausible and wrong.
30
+ */
31
+ export declare function toSdkError(cause: unknown, program?: CofferProgram): SdkError;
32
+ /** @internal Exported for tests */
33
+ export declare function contractErrorMapForTests(program?: CofferProgram): ErrorTable;
34
+ /**
35
+ * Look up a program error by its numeric code without needing an exception
36
+ * to parse. Returns `undefined` for codes the program does not define.
37
+ */
38
+ export declare function describeProgramError(code: number, program?: CofferProgram): {
39
+ name: string;
40
+ message: string;
41
+ sdkCode: SdkErrorCode;
42
+ } | undefined;
43
+ export {};
44
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,sBAAsB,GAAG,eAAe,CAAC;AAuFnF,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAuBxF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,aAA2B,GAAG,QAAQ,CA6BzF;AA0BD,mCAAmC;AACnC,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,aAA2B,GAAG,UAAU,CAEzF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,aAA2B,GACnC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GAAG,SAAS,CAItE"}
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.toSdkError = toSdkError;
7
+ exports.contractErrorMapForTests = contractErrorMapForTests;
8
+ exports.describeProgramError = describeProgramError;
9
+ const cubic_pool_json_1 = __importDefault(require("../idl/cubic_pool.json"));
10
+ const protocol_admin_json_1 = __importDefault(require("../idl/protocol_admin.json"));
11
+ const single_token_liquidity_json_1 = __importDefault(require("../idl/single_token_liquidity.json"));
12
+ const ANCHOR_NAME_TO_SDK = {
13
+ InvalidTokenCount: "invalid_input",
14
+ InvalidTokenIndex: "invalid_input",
15
+ InvalidWeights: "invalid_input",
16
+ InvalidVirtualBalances: "invalid_input",
17
+ InsufficientLiquidity: "insufficient_funds",
18
+ SlippageExceeded: "slippage_exceeded",
19
+ InvalidAmounts: "invalid_input",
20
+ InsufficientBptOut: "slippage_exceeded",
21
+ InsufficientTokensOut: "slippage_exceeded",
22
+ FeeRateMaxExceeded: "invalid_input",
23
+ ProtocolFeeRateMaxExceeded: "invalid_input",
24
+ MathOverflow: "math_overflow",
25
+ MathUnderflow: "math_overflow",
26
+ DivisionByZero: "math_overflow",
27
+ TokenMintMismatch: "invalid_input",
28
+ InvalidTokenDecimals: "invalid_input",
29
+ AmountOutExceedsBalance: "invalid_input",
30
+ InvalidBptAmount: "invalid_input",
31
+ Unauthorized: "invalid_input",
32
+ InvalidMint: "invalid_input",
33
+ PoolDisabled: "pool_disabled",
34
+ SwapsDisabled: "swaps_disabled",
35
+ MaxSelloffExceeded: "selloff_window_full",
36
+ TokenInactive: "token_swaps_disabled",
37
+ PoolMustBeDisabled: "invalid_input",
38
+ ZeroAmount: "invalid_input",
39
+ ZeroFeeAmount: "invalid_input",
40
+ BannedExtension: "invalid_input",
41
+ TokenProgramMismatch: "invalid_input",
42
+ UserTokenAccountOwnerMismatch: "invalid_input",
43
+ InitialLiquidityTooSmall: "invalid_input",
44
+ InvalidTokenProgram: "invalid_input",
45
+ InvalidVault: "invalid_input",
46
+ InvalidSourceOwner: "invalid_input",
47
+ WouldBreakRentExempt: "invalid_input",
48
+ PoolAdminDisabled: "invalid_input",
49
+ ProtocolAdminUnset: "invalid_input",
50
+ NoPendingAdmin: "invalid_input",
51
+ NotPendingAdmin: "invalid_input",
52
+ InvalidPendingAdmin: "invalid_input",
53
+ ProtocolAdminNotTreasury: "invalid_input",
54
+ // ── cubic-pool 6055–6068, new in v5.1 ────────────────────────────────
55
+ /** Mint carries a Token-2022 extension this pool's policy forbids. */
56
+ UnsupportedExtension: "invalid_input",
57
+ /** Destination requires a memo — include the SPL Memo program account. */
58
+ MemoProgramMissing: "invalid_input",
59
+ TransferFeeCalculationMismatch: "invalid_input",
60
+ /** The whole deposit was eaten by the mint's transfer fee. */
61
+ AmountFullyConsumedByTransferFee: "invalid_input",
62
+ /** Only `pool.pool_admin` may make a pool's first (seed) deposit. */
63
+ SeedDepositNotPoolAdmin: "auth_failed",
64
+ StldTokenExtensionsUnsupported: "unsupported_pool_state",
65
+ /**
66
+ * Compare-and-swap guard on `range_manager_update` failed: the pool moved
67
+ * between the read and the write. The bot must re-read the pool and retry
68
+ * with fresh `expectedCurrent` values — it is a retryable race, not a
69
+ * permanent rejection.
70
+ */
71
+ RangeManagerStaleValue: "invalid_input",
72
+ RangeManagerLeverageBandExceeded: "invalid_input",
73
+ RangeManagerOverrideMustDisable: "auth_failed",
74
+ /** An array argument's length != the pool's `token_count`. */
75
+ InvalidArrayLength: "invalid_input",
76
+ FirstDepositRequiresNonzero: "invalid_input",
77
+ TokenLivenessMismatch: "invalid_input",
78
+ /** Deposit too small to mint a single unit of BPT — increase the amount. */
79
+ DepositTooSmall: "invalid_input",
80
+ /** Pool holds no liquidity yet; the pool admin must seed it first. */
81
+ PoolNotSeeded: "unsupported_pool_state",
82
+ // ── protocol-admin ───────────────────────────────────────────────────
83
+ /** New admin cannot be the all-zero pubkey. */
84
+ InvalidAdmin: "invalid_input",
85
+ // ── single-token-liquidity 6030–6032, new in v5.1 ────────────────────
86
+ /** Zap route can't carry an armed transfer hook's extra accounts. */
87
+ TokenExtensionsUnsupported: "unsupported_pool_state",
88
+ InsufficientHelperSol: "insufficient_funds",
89
+ /** Pool exceeds `STLD_MAX_TOKENS` (10) — use `add_liquidity` instead. */
90
+ PoolTooLargeForZap: "unsupported_pool_state",
91
+ };
92
+ function buildErrorTable(errors) {
93
+ return Object.fromEntries(errors.map((anchorError) => [
94
+ anchorError.code,
95
+ {
96
+ code: ANCHOR_NAME_TO_SDK[anchorError.name] ?? "invalid_input",
97
+ message: anchorError.msg,
98
+ name: anchorError.name,
99
+ },
100
+ ]));
101
+ }
102
+ const ERROR_TABLES = {
103
+ cubicPool: buildErrorTable(cubic_pool_json_1.default.errors),
104
+ protocolAdmin: buildErrorTable(protocol_admin_json_1.default.errors),
105
+ singleTokenLiquidity: buildErrorTable(single_token_liquidity_json_1.default.errors),
106
+ };
107
+ const CONTRACT_ERROR_MAP = ERROR_TABLES.cubicPool;
108
+ /**
109
+ * Convert a raw error (possibly from Anchor, web3.js, or fetch) into a
110
+ * cleanly-typed SdkError. Used by safeCall wrappers so callers always
111
+ * get structured errors, never exceptions.
112
+ *
113
+ * @param program Which Coffer program the failing instruction belonged to.
114
+ * Anchor numbers each program's errors from 6000 independently, so the
115
+ * same code means different things in different programs. Defaults to
116
+ * `"cubicPool"` (correct for swap / add / remove liquidity). Pass
117
+ * `"singleTokenLiquidity"` for zap failures and `"protocolAdmin"` for
118
+ * treasury-routed admin calls, or the message will be plausible and wrong.
119
+ */
120
+ function toSdkError(cause, program = "cubicPool") {
121
+ // Anchor-encoded program errors
122
+ const msg = extractMessage(cause);
123
+ const code = extractErrorCode(msg);
124
+ const table = ERROR_TABLES[program] ?? CONTRACT_ERROR_MAP;
125
+ if (code !== null && table[code]) {
126
+ return {
127
+ code: table[code].code,
128
+ humanMessage: table[code].message,
129
+ cause,
130
+ };
131
+ }
132
+ // Common network strings
133
+ if (/timed? ?out|ETIMEDOUT/i.test(msg)) {
134
+ return { code: "rpc_timeout", humanMessage: "RPC timed out", cause };
135
+ }
136
+ if (/429|rate limit/i.test(msg)) {
137
+ return { code: "rpc_rate_limited", humanMessage: "RPC rate-limited - slow down", cause };
138
+ }
139
+ if (/fetch failed|ECONNREFUSED|ENOTFOUND|Proxy error|-32056|-32052|403/i.test(msg)) {
140
+ return { code: "rpc_unavailable", humanMessage: "RPC endpoint unreachable", cause };
141
+ }
142
+ if (/Account does not exist|account not found/i.test(msg)) {
143
+ return { code: "account_not_found", humanMessage: "Account does not exist on-chain", cause };
144
+ }
145
+ if (/insufficient funds/i.test(msg)) {
146
+ return { code: "insufficient_funds", humanMessage: "Insufficient funds for this operation", cause };
147
+ }
148
+ return { code: "unknown", humanMessage: msg || "Unknown error", cause };
149
+ }
150
+ function extractMessage(e) {
151
+ if (!e)
152
+ return "";
153
+ if (typeof e === "string")
154
+ return e;
155
+ if (e instanceof Error)
156
+ return e.message;
157
+ if (typeof e === "object" && e !== null && "message" in e) {
158
+ return String(e.message ?? "");
159
+ }
160
+ try {
161
+ return JSON.stringify(e);
162
+ }
163
+ catch {
164
+ return String(e);
165
+ }
166
+ }
167
+ function extractErrorCode(msg) {
168
+ // Anchor error format: "custom program error: 0x1774"
169
+ const hex = msg.match(/custom program error: 0x([0-9a-fA-F]+)/);
170
+ if (hex)
171
+ return parseInt(hex[1], 16);
172
+ // Anchor SDK format: "Error Number: 6007"
173
+ const dec = msg.match(/Error Number:\s*(\d+)/);
174
+ if (dec)
175
+ return parseInt(dec[1], 10);
176
+ return null;
177
+ }
178
+ /** @internal Exported for tests */
179
+ function contractErrorMapForTests(program = "cubicPool") {
180
+ return ERROR_TABLES[program];
181
+ }
182
+ /**
183
+ * Look up a program error by its numeric code without needing an exception
184
+ * to parse. Returns `undefined` for codes the program does not define.
185
+ */
186
+ function describeProgramError(code, program = "cubicPool") {
187
+ const hit = ERROR_TABLES[program]?.[code];
188
+ if (!hit)
189
+ return undefined;
190
+ return { name: hit.name, message: hit.message, sdkCode: hit.code };
191
+ }
192
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":";;;;;AA0IA,gCA6BC;AA2BD,4DAEC;AAMD,oDAOC;AAjND,6EAAkD;AAClD,qFAA0D;AAC1D,qGAAyE;AAgBzE,MAAM,kBAAkB,GAAiC;IACvD,iBAAiB,EAAE,eAAe;IAClC,iBAAiB,EAAE,eAAe;IAClC,cAAc,EAAE,eAAe;IAC/B,sBAAsB,EAAE,eAAe;IACvC,qBAAqB,EAAE,oBAAoB;IAC3C,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;QAAE,OAAO,SAAS,CAAC;IAC3B,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC;AACrE,CAAC"}
@@ -0,0 +1,98 @@
1
+ import BN from "bn.js";
2
+ import { PoolInfo, PoolTokenInfo } from "../types/pool";
3
+ /**
4
+ * Token-2022 mint-extension policy.
5
+ *
6
+ * The cubic-pool program moves tokens with the plain SPL `Transfer`
7
+ * instruction (no `transfer_checked`, no fee accounting). Token-2022 refuses
8
+ * a plain `Transfer` for mints that carry a transfer fee, transfer hook or
9
+ * pausable extension,
10
+ * and a `NonTransferable` mint cannot move at all — so any pool operation
11
+ * that touches such a token reverts inside the token program
12
+ * (`MintRequiredForTransfer`, error 0x1f), after the user has already paid
13
+ * for the transaction.
14
+ *
15
+ * The SDK therefore inspects every pool token's mint on `sync()` and refuses
16
+ * to quote or build a transaction that would move a token with an
17
+ * unsupported extension. The refusal is a normal `SdkResult` error with code
18
+ * `unsupported_token_extension` (or a thrown `Error` from the low-level
19
+ * `build*Ix` helpers).
20
+ */
21
+ /** Token-2022 `ExtensionType` discriminants (u16, little-endian on the wire). */
22
+ export declare enum MintExtension {
23
+ Uninitialized = 0,
24
+ TransferFeeConfig = 1,
25
+ TransferFeeAmount = 2,
26
+ MintCloseAuthority = 3,
27
+ ConfidentialTransferMint = 4,
28
+ ConfidentialTransferAccount = 5,
29
+ DefaultAccountState = 6,
30
+ ImmutableOwner = 7,
31
+ MemoTransfer = 8,
32
+ NonTransferable = 9,
33
+ InterestBearingConfig = 10,
34
+ CpiGuard = 11,
35
+ PermanentDelegate = 12,
36
+ NonTransferableAccount = 13,
37
+ TransferHook = 14,
38
+ TransferHookAccount = 15,
39
+ ConfidentialTransferFeeConfig = 16,
40
+ ConfidentialTransferFeeAmount = 17,
41
+ MetadataPointer = 18,
42
+ TokenMetadata = 19,
43
+ GroupPointer = 20,
44
+ TokenGroup = 21,
45
+ GroupMemberPointer = 22,
46
+ TokenGroupMember = 23,
47
+ ConfidentialMintBurn = 24,
48
+ ScaledUiAmountConfig = 25,
49
+ PausableConfig = 26,
50
+ PausableAccount = 27,
51
+ PermissionedBurn = 28
52
+ }
53
+ /** Highest extension discriminant accepted by the deployed cubic-pool program. */
54
+ export declare const MAX_KNOWN_MINT_EXTENSION = MintExtension.PausableAccount;
55
+ /**
56
+ * Extensions the AMM can never move, whatever the pool's `banned_extensions`
57
+ * policy says. This is a transfer-capability check, not the mint-creation
58
+ * policy: even an inert TransferHook needs a mint account for plain Transfer.
59
+ */
60
+ export declare const HARD_UNSUPPORTED_MINT_EXTENSIONS: ReadonlyArray<MintExtension>;
61
+ /**
62
+ * `DEFAULT_BANNED_EXTENSIONS` from `cubic-pool/constants.rs`: the bitmap a
63
+ * fresh `CubicPoolConfig` starts with. Exposed so consumers can render the
64
+ * policy; the per-pool effective bitmap is `PoolInfo.bannedExtensions`.
65
+ */
66
+ export declare const DEFAULT_BANNED_EXTENSIONS: bigint;
67
+ /** Human-readable name for an extension discriminant. */
68
+ export declare function mintExtensionName(type: number): string;
69
+ /**
70
+ * Parse the TLV extension list of a Token-2022 mint. Returns `[]` for a
71
+ * classic SPL Token mint (82 bytes) or a Token-2022 mint with no
72
+ * extensions. Rejects uninitialized mints, invalid mint layouts and malformed
73
+ * TLV data. Pool policy and transfer capability are classified separately.
74
+ */
75
+ export declare function parseMintExtensions(data: Buffer | Uint8Array): number[];
76
+ /**
77
+ * Which of `extensions` the AMM cannot transfer: everything in
78
+ * {@link HARD_UNSUPPORTED_MINT_EXTENSIONS}, anything the program does not
79
+ * know (> {@link MAX_KNOWN_MINT_EXTENSION}; the program rejects unknown
80
+ * types at creation and the SDK cannot assume their transfer semantics).
81
+ *
82
+ * `banned_extensions` is a snapshot of creation policy, not a runtime transfer
83
+ * restriction. The optional second argument is retained for compatibility
84
+ * but does not change this result. Use `bannedMintExtensions` for diagnostics.
85
+ */
86
+ export declare function unsupportedMintExtensions(extensions: number[], _bannedExtensions?: BN | bigint): number[];
87
+ /** Extensions covered by a creation-policy bitmap; does not imply transfer failure. */
88
+ export declare function bannedMintExtensions(extensions: number[], bannedExtensions?: BN | bigint): number[];
89
+ /** One-line description of why a token is refused, for error messages. */
90
+ export declare function describeUnsupportedToken(t: Pick<PoolTokenInfo, "index" | "mint" | "unsupportedExtensions" | "metadata">): string;
91
+ /**
92
+ * Throw if any of the given token indices (or every token when `indices` is
93
+ * `"all"`) carries an unsupported extension. Used by the low-level
94
+ * instruction builders so that direct `build*Ix` callers get the same
95
+ * protection as `CubicPoolClient` users.
96
+ */
97
+ export declare function assertTokensSupported(pool: PoolInfo, indices: number[] | "all", op: string): void;
98
+ //# sourceMappingURL=extensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../../src/utils/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAExD;;;;;;;;;;;;;;;;;GAiBG;AAEH,iFAAiF;AACjF,oBAAY,aAAa;IACvB,aAAa,IAAI;IACjB,iBAAiB,IAAI;IACrB,iBAAiB,IAAI;IACrB,kBAAkB,IAAI;IACtB,wBAAwB,IAAI;IAC5B,2BAA2B,IAAI;IAC/B,mBAAmB,IAAI;IACvB,cAAc,IAAI;IAClB,YAAY,IAAI;IAChB,eAAe,IAAI;IACnB,qBAAqB,KAAK;IAC1B,QAAQ,KAAK;IACb,iBAAiB,KAAK;IACtB,sBAAsB,KAAK;IAC3B,YAAY,KAAK;IACjB,mBAAmB,KAAK;IACxB,6BAA6B,KAAK;IAClC,6BAA6B,KAAK;IAClC,eAAe,KAAK;IACpB,aAAa,KAAK;IAClB,YAAY,KAAK;IACjB,UAAU,KAAK;IACf,kBAAkB,KAAK;IACvB,gBAAgB,KAAK;IACrB,oBAAoB,KAAK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