@exponent-labs/exponent-sdk 0.1.6 → 0.1.8

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 (92) hide show
  1. package/build/EventDecoderV2.d.ts +31 -0
  2. package/build/EventDecoderV2.js +76 -0
  3. package/build/EventDecoderV2.js.map +1 -0
  4. package/build/addressLookupTableUtil.d.ts +17 -1
  5. package/build/addressLookupTableUtil.js +35 -1
  6. package/build/addressLookupTableUtil.js.map +1 -1
  7. package/build/clmm/events.d.ts +10 -0
  8. package/build/clmm/events.js +10 -0
  9. package/build/clmm/events.js.map +1 -0
  10. package/build/clmm/index.d.ts +1 -0
  11. package/build/clmm/index.js +18 -0
  12. package/build/clmm/index.js.map +1 -0
  13. package/build/events.d.ts +200 -9
  14. package/build/events.js +73 -24
  15. package/build/events.js.map +1 -1
  16. package/build/eventsV2.d.ts +7 -0
  17. package/build/eventsV2.js +10 -0
  18. package/build/eventsV2.js.map +1 -0
  19. package/build/flavors.d.ts +2 -0
  20. package/build/flavors.js +81 -27
  21. package/build/flavors.js.map +1 -1
  22. package/build/index.d.ts +6 -0
  23. package/build/index.js +14 -4
  24. package/build/index.js.map +1 -1
  25. package/build/lpPosition.js +4 -1
  26. package/build/lpPosition.js.map +1 -1
  27. package/build/market.d.ts +14 -2
  28. package/build/market.js +70 -29
  29. package/build/market.js.map +1 -1
  30. package/build/marketThree.d.ts +664 -0
  31. package/build/marketThree.js +1415 -0
  32. package/build/marketThree.js.map +1 -0
  33. package/build/marketThree.test.d.ts +1 -0
  34. package/build/marketThree.test.js +166 -0
  35. package/build/marketThree.test.js.map +1 -0
  36. package/build/orderbook/events.d.ts +7 -0
  37. package/build/orderbook/events.js +10 -0
  38. package/build/orderbook/events.js.map +1 -0
  39. package/build/orderbook/index.d.ts +4 -0
  40. package/build/orderbook/index.js +41 -0
  41. package/build/orderbook/index.js.map +1 -0
  42. package/build/orderbook/math.d.ts +26 -0
  43. package/build/orderbook/math.js +111 -0
  44. package/build/orderbook/math.js.map +1 -0
  45. package/build/orderbook/orderbook.d.ts +175 -0
  46. package/build/orderbook/orderbook.js +756 -0
  47. package/build/orderbook/orderbook.js.map +1 -0
  48. package/build/orderbook/types.d.ts +49 -0
  49. package/build/orderbook/types.js +27 -0
  50. package/build/orderbook/types.js.map +1 -0
  51. package/build/orderbook/utils.d.ts +18 -0
  52. package/build/orderbook/utils.js +74 -0
  53. package/build/orderbook/utils.js.map +1 -0
  54. package/build/router.d.ts +92 -0
  55. package/build/router.js +214 -0
  56. package/build/router.js.map +1 -0
  57. package/build/syPosition.js +6 -0
  58. package/build/syPosition.js.map +1 -1
  59. package/build/utils/index.d.ts +3 -2
  60. package/build/utils/index.js +22 -1
  61. package/build/utils/index.js.map +1 -1
  62. package/build/vault.d.ts +3 -1
  63. package/build/vault.js +98 -62
  64. package/build/vault.js.map +1 -1
  65. package/build/ytPosition.d.ts +2 -0
  66. package/build/ytPosition.js +18 -5
  67. package/build/ytPosition.js.map +1 -1
  68. package/package.json +28 -23
  69. package/src/EventDecoderV2.ts +96 -0
  70. package/src/addressLookupTableUtil.ts +42 -1
  71. package/src/clmm/events.ts +17 -0
  72. package/src/clmm/index.ts +1 -0
  73. package/src/events.ts +280 -27
  74. package/src/eventsV2.ts +13 -0
  75. package/src/flavors.ts +97 -27
  76. package/src/index.ts +6 -0
  77. package/src/lpPosition.ts +5 -2
  78. package/src/market.ts +100 -31
  79. package/src/marketThree.test.ts +208 -0
  80. package/src/marketThree.ts +2430 -0
  81. package/src/orderbook/events.ts +13 -0
  82. package/src/orderbook/index.ts +12 -0
  83. package/src/orderbook/math.ts +122 -0
  84. package/src/orderbook/orderbook.ts +1153 -0
  85. package/src/orderbook/types.ts +45 -0
  86. package/src/orderbook/utils.ts +74 -0
  87. package/src/router.ts +360 -0
  88. package/src/syPosition.ts +4 -0
  89. package/src/utils/index.ts +27 -2
  90. package/src/vault.ts +100 -62
  91. package/src/ytPosition.ts +28 -7
  92. package/tsconfig.json +4 -1
@@ -0,0 +1,664 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, Program, web3 } from "@coral-xyz/anchor";
3
+ import { ExponentClmm } from "@exponent-labs/exponent-clmm-idl";
4
+ import { ExponentCLMMPDA } from "@exponent-labs/exponent-clmm-pda";
5
+ import { LiquidityNetBalanceLimits, LpFarm, LpPositionCLMM, MarketConfigurationOptions, MarketThreeFinancials, Ticks } from "@exponent-labs/exponent-fetcher";
6
+ import { ExponentCore } from "@exponent-labs/exponent-idl";
7
+ import { ExponentPDA } from "@exponent-labs/exponent-pda";
8
+ import { AnchorizedPNum, CpiAccountsRaw, ExponentCoreCpiAccountsRaw, Flavor, SyPosition } from "@exponent-labs/exponent-types";
9
+ import { LiquidityAdd } from "@exponent-labs/market-math";
10
+ import { Environment } from "./environment";
11
+ import { Vault } from "./vault";
12
+ export { LiquidityAdd };
13
+ interface Emission {
14
+ /** Token account that holds emission tokens */
15
+ escrowAccountAddress: web3.PublicKey;
16
+ /** Mint for the emission token */
17
+ mint: web3.PublicKey;
18
+ /** Token program ID for the emission token */
19
+ tokenProgramAddress: web3.PublicKey;
20
+ /** How many emissions have been claimed by SY holders */
21
+ totalClaimed: bigint;
22
+ /** How many emissions have been earned by the SY robot over its lifetime */
23
+ lastSeenTotalAccruedEmissions: bigint;
24
+ /** Global index for sharing out rewards to SY holders */
25
+ index: AnchorizedPNum;
26
+ }
27
+ export type MarketAdminAction = {
28
+ setStatus: [number];
29
+ } | {
30
+ setMaxLpSupply: [BN];
31
+ } | {
32
+ changeTreasuryTradeSyBpsFee: [number];
33
+ } | {
34
+ changeLnFeeRateRoot: [number];
35
+ } | {
36
+ changeLiquidityNetBalanceLimits: {
37
+ maxNetBalanceChangeNegativePercentage: number;
38
+ maxNetBalanceChangePositivePercentage: number;
39
+ windowDurationSeconds: number;
40
+ };
41
+ } | {
42
+ changeEpsilonClamp: [number];
43
+ } | {
44
+ changeMinLpTickAmount: [BN];
45
+ } | {
46
+ changeTickSpace: [number];
47
+ };
48
+ export type SwapDirection = {
49
+ ptToSy: {};
50
+ } | {
51
+ syToPt: {};
52
+ };
53
+ interface MarketThreeLoadOptions {
54
+ syConfig?: {
55
+ skipWrap?: boolean;
56
+ };
57
+ }
58
+ type MarketThreeArgs = {
59
+ admin: web3.PublicKey;
60
+ addressLookupTable: web3.PublicKey;
61
+ mintPt: web3.PublicKey;
62
+ mintYt: web3.PublicKey;
63
+ mintSy: web3.PublicKey;
64
+ vault: Vault;
65
+ tokenPtEscrow: web3.PublicKey;
66
+ tokenSyEscrow: web3.PublicKey;
67
+ tokenYtEscrow: web3.PublicKey;
68
+ tokenFeeTreasurySy: web3.PublicKey;
69
+ tokenFeeTreasuryPt: web3.PublicKey;
70
+ syProgram: web3.PublicKey;
71
+ exponentCoreProgram: web3.PublicKey;
72
+ selfAddress: web3.PublicKey;
73
+ statusFlags: number;
74
+ configurationOptions: MarketConfigurationOptions;
75
+ financials: MarketThreeFinancials;
76
+ cpiSyAccounts: CpiAccountsRaw;
77
+ cpiCoreAccounts: ExponentCoreCpiAccountsRaw;
78
+ isCurrentFlashSwap: boolean;
79
+ lpFarm: LpFarm;
80
+ flavor: Flavor;
81
+ emissions: {
82
+ trackers: {
83
+ tokenEscrow: web3.PublicKey;
84
+ lpShareIndex: number;
85
+ lastSeenStaged: number;
86
+ }[];
87
+ };
88
+ liquidityNetBalanceLimits: LiquidityNetBalanceLimits;
89
+ ticksAccount: web3.PublicKey;
90
+ ticks: Ticks;
91
+ syPosition: SyPosition;
92
+ treasuryFeeOwner: web3.PublicKey;
93
+ };
94
+ export declare class MarketThree {
95
+ state: MarketThreeArgs;
96
+ selfAddress: web3.PublicKey;
97
+ env: Environment;
98
+ connection: web3.Connection;
99
+ clmmProgram: Program<ExponentClmm>;
100
+ coreProgram: Program<ExponentCore>;
101
+ xponPda: ExponentPDA;
102
+ pda: ExponentCLMMPDA;
103
+ constructor(state: MarketThreeArgs, selfAddress: web3.PublicKey, env: Environment, connection: web3.Connection);
104
+ static load(env: Environment, connection: web3.Connection, address: web3.PublicKey, vault?: Vault, ticks?: Ticks, options?: MarketThreeLoadOptions): Promise<MarketThree>;
105
+ reload(connection?: web3.Connection): Promise<MarketThree>;
106
+ get vault(): Vault;
107
+ get flavor(): Flavor;
108
+ get lpBalance(): bigint;
109
+ get syBalance(): bigint;
110
+ get ptBalance(): bigint;
111
+ get mintSy(): web3.PublicKey;
112
+ get mintPt(): web3.PublicKey;
113
+ get statusFlags(): number;
114
+ get mintYt(): web3.PublicKey;
115
+ get addressLookupTable(): web3.PublicKey;
116
+ get syProgram(): web3.PublicKey;
117
+ get cpiSyAccounts(): CpiAccountsRaw;
118
+ get cpiCoreAccounts(): ExponentCoreCpiAccountsRaw;
119
+ get marketEmissions(): {
120
+ trackers: {
121
+ tokenEscrow: web3.PublicKey;
122
+ lpShareIndex: number;
123
+ lastSeenStaged: number;
124
+ }[];
125
+ };
126
+ get ticksKey(): web3.PublicKey;
127
+ get corePda(): ExponentPDA;
128
+ get coreEventAuthority(): web3.PublicKey;
129
+ get emissions(): Emission[];
130
+ /** Get the escrow token account addresses for the emissions, in order */
131
+ get emissionTokenAccounts(): web3.PublicKey[];
132
+ /** Pass-through SY account owned by the market */
133
+ get tokenSyEscrow(): web3.PublicKey;
134
+ /** Pass-through YT account owned by the market */
135
+ get tokenYtEscrow(): web3.PublicKey;
136
+ /** SY account that holds treasury SY fees from PT trading */
137
+ get tokenFeeTreasurySy(): web3.PublicKey;
138
+ /** PT account that holds treasury PT fees from PT trading */
139
+ get tokenFeeTreasuryPt(): web3.PublicKey;
140
+ /** Market liquidity for PT */
141
+ get tokenPtEscrow(): web3.PublicKey;
142
+ get currentSyExchangeRate(): number;
143
+ /** Special account for event emit self-cpi */
144
+ get eventAuthority(): web3.PublicKey;
145
+ get secondsRemaining(): number;
146
+ /** Annualize a rate given the number of seconds remaining until maturity */
147
+ static annualize(rate: number, secondsRemaining: number): number;
148
+ static annualizeApy(rate: number, secondsRemaining: number): number;
149
+ /** The fee rate taken off of trade fees (typically around 20%) expressed as a BPS number */
150
+ get feeTreasuryBps(): number;
151
+ /** The fee rate taken off of trade fees (typically around 20%) expressed as a rational number */
152
+ get feeTreasuryRate(): number;
153
+ /** Get the owner of the treasury fee accounts: tokenFeeTreasuryPt & tokenFeeTreasurySy */
154
+ static fetchTreasuryFeeOwner(tokenFeeTreasury: web3.PublicKey, connection: web3.Connection): Promise<web3.PublicKey>;
155
+ /** Deposit a pair of tokens as liquidity to the market
156
+ * Adds PT & SY from the `depositor` to the market
157
+ *
158
+ * Due to unforeseeable slippage, the PT & SY amounts intended are effectively the maximum amounts
159
+ * The minimum LP tokens to receive is specified by `minLpOut`
160
+ *
161
+ * The token accounts themselves are optional, and will be derived from the depositor's wallet if not provided
162
+ */
163
+ ixDepositLiquidity({ ptInIntent, syInIntent, depositor, lowerTickKey, upperTickKey, ptSrc: ptSrcParam, sySrc: sySrcParam, lpPosition: lpPositionParam, }: {
164
+ /** Intended (maximum) amount of PT in */
165
+ ptInIntent: bigint;
166
+ /** Intended (maximum) amount of SY in */
167
+ syInIntent: bigint;
168
+ /** Lower tick key */
169
+ lowerTickKey: number;
170
+ /** Upper tick key */
171
+ upperTickKey: number;
172
+ depositor: web3.PublicKey;
173
+ ptSrc?: web3.PublicKey;
174
+ sySrc?: web3.PublicKey;
175
+ lpPosition?: web3.Keypair;
176
+ }): Promise<{
177
+ ix: web3.TransactionInstruction;
178
+ signers: web3.Keypair;
179
+ }>;
180
+ /**
181
+ * Redeem LP tokens for PT & SY (liquidity removal)
182
+ *
183
+ * The lpIn is exactly the amount of LP tokens to burn
184
+ * The minimum PT & SY out are specified by minPtOut & minSyOut
185
+ * The transaction may fail due to unforeseeable slippage on the redemption rate
186
+ *
187
+ * The token accounts themselves are optional, and will be derived from the withdrawer's wallet if not provided
188
+ */
189
+ ixWithdrawLiquidity({ lpIn, withdrawer, lpPosition, minPtOut, minSyOut, ptDst: ptDstParam, syDst: syDstParam, }: {
190
+ lpIn: bigint;
191
+ withdrawer: web3.PublicKey;
192
+ lpPosition: web3.PublicKey;
193
+ minPtOut: bigint;
194
+ minSyOut: bigint;
195
+ ptDst?: web3.PublicKey;
196
+ syDst?: web3.PublicKey;
197
+ lnImpliedApyLimit?: number;
198
+ }): Promise<{
199
+ ixs: web3.TransactionInstruction[];
200
+ setupIxs: web3.TransactionInstruction[];
201
+ }>;
202
+ ixTradePt({ trader, traderAmount, outConstraint, swapDirection, tokenPt: tokenPtParam, tokenSy: tokenSyParam, lnImpliedApyLimit, }: {
203
+ trader: web3.PublicKey;
204
+ traderAmount: bigint;
205
+ outConstraint: bigint;
206
+ swapDirection: SwapDirection;
207
+ tokenPt?: web3.PublicKey;
208
+ tokenSy?: web3.PublicKey;
209
+ lnImpliedApyLimit?: number;
210
+ }): Promise<{
211
+ ixs: web3.TransactionInstruction[];
212
+ setupIxs: web3.TransactionInstruction[];
213
+ }>;
214
+ ixTradePtExactOut({ trader, amountOut, swapDirection, amountInConstraint, tokenPt: tokenPtParam, tokenSy: tokenSyParam, lnImpliedApyLimit, }: {
215
+ trader: web3.PublicKey;
216
+ amountOut: bigint;
217
+ swapDirection: SwapDirection;
218
+ amountInConstraint?: bigint;
219
+ tokenPt?: web3.PublicKey;
220
+ tokenSy?: web3.PublicKey;
221
+ lnImpliedApyLimit?: number;
222
+ }): Promise<{
223
+ ixs: web3.TransactionInstruction[];
224
+ setupIxs: web3.TransactionInstruction[];
225
+ }>;
226
+ /** Buy PT with SY
227
+ *
228
+ * The trader is the account that sends the SY
229
+ * The amountPt is the exact amount of PT the trader intends to buy
230
+ * The syConstraint is the maximum amount of SY the trader is willing to spend
231
+ *
232
+ * The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
233
+ */
234
+ ixBuyPt({ trader, amountSy, outConstraint, tokenPt, tokenSy, lnImpliedApyLimit, }: {
235
+ trader: web3.PublicKey;
236
+ amountSy: bigint;
237
+ outConstraint: bigint;
238
+ tokenPt?: web3.PublicKey;
239
+ tokenSy?: web3.PublicKey;
240
+ lnImpliedApyLimit?: number;
241
+ }): Promise<{
242
+ ixs: web3.TransactionInstruction[];
243
+ setupIxs: web3.TransactionInstruction[];
244
+ }>;
245
+ /**
246
+ * Sell PT for SY
247
+ * The trader is the account that sends the PT
248
+ * The amountPt is the exact amount of PT the trader intends to sell
249
+ * The minSyReceive is the minimum amount of SY the trader is willing to receive
250
+ *
251
+ * The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
252
+ */
253
+ ixSellPt({ trader, amountPt, outConstraint, tokenPt, tokenSy, lnImpliedApyLimit, }: {
254
+ trader: web3.PublicKey;
255
+ amountPt: bigint;
256
+ outConstraint: bigint;
257
+ tokenPt?: web3.PublicKey;
258
+ tokenSy?: web3.PublicKey;
259
+ lnImpliedApyLimit?: number;
260
+ }): Promise<{
261
+ ixs: web3.TransactionInstruction[];
262
+ setupIxs: web3.TransactionInstruction[];
263
+ }>;
264
+ /**
265
+ * Buy exact amount of PT with SY
266
+ *
267
+ * The trader specifies the exact amount of PT they want to receive
268
+ * The maxSyIn is the maximum amount of SY the trader is willing to spend
269
+ */
270
+ ixBuyPtExactOut({ trader, amountPt, maxSyIn, tokenPt, tokenSy, lnImpliedApyLimit, }: {
271
+ trader: web3.PublicKey;
272
+ amountPt: bigint;
273
+ maxSyIn?: bigint;
274
+ tokenPt?: web3.PublicKey;
275
+ tokenSy?: web3.PublicKey;
276
+ lnImpliedApyLimit?: number;
277
+ }): Promise<{
278
+ ixs: web3.TransactionInstruction[];
279
+ setupIxs: web3.TransactionInstruction[];
280
+ }>;
281
+ /**
282
+ * Sell PT for exact amount of SY
283
+ *
284
+ * The trader specifies the exact amount of SY they want to receive
285
+ * The maxPtIn is the maximum amount of PT the trader is willing to spend
286
+ */
287
+ ixSellPtExactOut({ trader, amountSy, maxPtIn, tokenPt, tokenSy, lnImpliedApyLimit, }: {
288
+ trader: web3.PublicKey;
289
+ amountSy: bigint;
290
+ maxPtIn?: bigint;
291
+ tokenPt?: web3.PublicKey;
292
+ tokenSy?: web3.PublicKey;
293
+ lnImpliedApyLimit?: number;
294
+ }): Promise<{
295
+ ixs: web3.TransactionInstruction[];
296
+ setupIxs: web3.TransactionInstruction[];
297
+ }>;
298
+ /** Buy YT with SY
299
+ *
300
+ * The trader is the account that sends the SY
301
+ *
302
+ * The ytOut is the exact amount of YT the trader intends to buy
303
+ *
304
+ * The maxSyIn is the maximum amount of SY the trader is willing to spend
305
+ *
306
+ * The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
307
+ */
308
+ ixBuyYt({ trader, ytOut, maxSyIn, ytTrader: ytTraderParam, ptTrader: ptTraderParam, syTrader: syTraderParam, lnImpliedApyLimit, }: {
309
+ trader: web3.PublicKey;
310
+ ytOut: bigint;
311
+ maxSyIn: bigint;
312
+ ytTrader?: web3.PublicKey;
313
+ ptTrader?: web3.PublicKey;
314
+ syTrader?: web3.PublicKey;
315
+ lnImpliedApyLimit?: number;
316
+ }): Promise<{
317
+ ixs: web3.TransactionInstruction[];
318
+ setupIxs: web3.TransactionInstruction[];
319
+ }>;
320
+ /** Sell YT for SY
321
+ *
322
+ * The trader is the account that sends the YT
323
+ *
324
+ * The amountYt is the exact amount of YT the trader intends to sell
325
+ *
326
+ * The minSyOut is the minimum amount of SY the trader is willing to receive
327
+ *
328
+ * The token accounts themselves are optional, and will be derived from the trader's wallet if not provided
329
+ */
330
+ ixSellYt({ trader, ytIn, minSyOut, ytSrc: ytSrcParam, ptSrc: ptSrcParam, syDst: syDstParam, lnImpliedApyLimit, }: {
331
+ trader: web3.PublicKey;
332
+ ytIn: bigint;
333
+ minSyOut: bigint;
334
+ ytSrc?: web3.PublicKey;
335
+ ptSrc?: web3.PublicKey;
336
+ syDst?: web3.PublicKey;
337
+ lnImpliedApyLimit?: number;
338
+ }): Promise<{
339
+ ixs: web3.TransactionInstruction[];
340
+ setupIxs: web3.TransactionInstruction[];
341
+ }>;
342
+ ixModifyMarketSetting({ signer, adminAction }: {
343
+ signer: web3.PublicKey;
344
+ adminAction: MarketAdminAction;
345
+ }): Promise<web3.TransactionInstruction>;
346
+ /**
347
+ * Add a new farm to the market to distribute rewards to LP holders
348
+ *
349
+ * @param signer - The admin address that signs the transaction
350
+ * @param farmMint - The mint address of the farm reward token
351
+ * @param farmTokenProgram - The token program for the farm reward token
352
+ * @param emissionsRate - The rate of emissions per second (in token smallest units)
353
+ * @param untilTimestamp - Unix timestamp when the farm emissions should end
354
+ * @param farmTokenSrc - Optional source token account for the farm rewards (derived from signer if not provided)
355
+ * @param feePayer - Optional fee payer for account reallocation (defaults to signer)
356
+ */
357
+ ixAddFarm({ signer, farmMint, farmTokenProgram, emissionsRate, untilTimestamp, farmTokenSrc: farmTokenSrcParam, feePayer: feePayerParam, }: {
358
+ signer: web3.PublicKey;
359
+ farmMint: web3.PublicKey;
360
+ farmTokenProgram: web3.PublicKey;
361
+ emissionsRate: bigint;
362
+ untilTimestamp: number;
363
+ farmTokenSrc?: web3.PublicKey;
364
+ feePayer?: web3.PublicKey;
365
+ }): Promise<{
366
+ ixs: web3.TransactionInstruction[];
367
+ setupIxs: web3.TransactionInstruction[];
368
+ }>;
369
+ /**
370
+ * Modify an existing farm's emissions rate and/or expiration timestamp
371
+ *
372
+ * If the new parameters require more tokens than previously undistributed,
373
+ * additional tokens will be transferred from the signer's token account.
374
+ * If fewer tokens are needed, the surplus will be returned to the signer.
375
+ *
376
+ * @param signer - The admin address that signs the transaction
377
+ * @param farmMint - The mint address of the farm reward token
378
+ * @param farmTokenProgram - The token program for the farm reward token
379
+ * @param newRate - The new rate of emissions per second (in token smallest units)
380
+ * @param untilTimestamp - New unix timestamp when the farm emissions should end
381
+ * @param farmTokenSrc - Optional source/destination token account (derived from signer if not provided)
382
+ */
383
+ ixModifyFarm({ signer, farmMint, farmTokenProgram, newRate, untilTimestamp, farmTokenSrc: farmTokenSrcParam, }: {
384
+ signer: web3.PublicKey;
385
+ farmMint: web3.PublicKey;
386
+ farmTokenProgram: web3.PublicKey;
387
+ newRate: bigint;
388
+ untilTimestamp: number;
389
+ farmTokenSrc?: web3.PublicKey;
390
+ }): Promise<{
391
+ ixs: web3.TransactionInstruction[];
392
+ }>;
393
+ ixWrapperBuyPt({ owner, minPtOut, baseIn, tokenSyTrader: tokenSyTraderParam, tokenPtTrader: tokenPtTraderParam, tokenBaseTrader: tokenBaseTraderParam, lnImpliedApyLimit, }: {
394
+ owner: web3.PublicKey;
395
+ minPtOut: bigint;
396
+ baseIn: bigint;
397
+ tokenSyTrader?: web3.PublicKey;
398
+ tokenPtTrader?: web3.PublicKey;
399
+ tokenBaseTrader?: web3.PublicKey;
400
+ lnImpliedApyLimit?: number;
401
+ }): Promise<{
402
+ ixs: web3.TransactionInstruction[];
403
+ setupIxs: web3.TransactionInstruction[];
404
+ }>;
405
+ ixWrapperSellPt({ owner, amount, minBaseOut, tokenSyTrader: tokenSyTraderParam, tokenPtTrader: tokenPtTraderParam, tokenBaseTrader: tokenBaseTraderParam, lnImpliedApyLimit, }: {
406
+ owner: web3.PublicKey;
407
+ amount: bigint;
408
+ minBaseOut: bigint;
409
+ tokenSyTrader?: web3.PublicKey;
410
+ tokenPtTrader?: web3.PublicKey;
411
+ tokenBaseTrader?: web3.PublicKey;
412
+ lnImpliedApyLimit?: number;
413
+ }): Promise<{
414
+ ixs: web3.TransactionInstruction[];
415
+ setupIxs: web3.TransactionInstruction[];
416
+ }>;
417
+ ixWrapperBuyYt({ owner, ytOut, maxBaseIn, tokenSyTrader: tokenSyTraderParam, tokenPtTrader: tokenPtTraderParam, tokenYtTrader: tokenYtTraderParam, tokenBaseTrader: tokenBaseTraderParam, }: {
418
+ owner: web3.PublicKey;
419
+ ytOut: bigint;
420
+ maxBaseIn: bigint;
421
+ tokenSyTrader?: web3.PublicKey;
422
+ tokenPtTrader?: web3.PublicKey;
423
+ tokenYtTrader?: web3.PublicKey;
424
+ tokenBaseTrader?: web3.PublicKey;
425
+ }): Promise<{
426
+ ixs: web3.TransactionInstruction[];
427
+ setupIxs: web3.TransactionInstruction[];
428
+ }>;
429
+ ixWrapperSellYt({ owner, amount, minBaseOut, tokenBaseTrader: tokenBaseTraderParam, tokenSyTrader: tokenSyTraderParam, tokenYtTrader: tokenYtTraderParam, tokenPtTrader: tokenPtTraderParam, }: {
430
+ owner: web3.PublicKey;
431
+ amount: bigint;
432
+ minBaseOut: bigint;
433
+ tokenBaseTrader?: web3.PublicKey;
434
+ tokenSyTrader?: web3.PublicKey;
435
+ tokenYtTrader?: web3.PublicKey;
436
+ tokenPtTrader?: web3.PublicKey;
437
+ }): Promise<{
438
+ ixs: web3.TransactionInstruction[];
439
+ setupIxs: web3.TransactionInstruction[];
440
+ }>;
441
+ /** Provide liquidity from a base asset - and receive YT and LP tokens in return */
442
+ ixWrapperProvideLiquidity({ depositor, amountBase, minLpOut, lowerTickApy, upperTickApy, tokenSyDepositor: tokenSyDepositorParam, tokenYtDepositor: tokenYtDepositorParam, tokenPtDepositor: tokenPtDepositorParam, tokenBaseDepositor: tokenBaseDepositorParam, lpPosition: lpPositionParam, }: {
443
+ depositor: web3.PublicKey;
444
+ amountBase: bigint;
445
+ minLpOut: bigint;
446
+ lowerTickApy: number;
447
+ upperTickApy: number;
448
+ tokenSyDepositor?: web3.PublicKey;
449
+ tokenYtDepositor?: web3.PublicKey;
450
+ tokenPtDepositor?: web3.PublicKey;
451
+ tokenBaseDepositor?: web3.PublicKey;
452
+ lpPosition?: web3.Keypair;
453
+ }): Promise<{
454
+ ixs: web3.TransactionInstruction[];
455
+ signers: web3.Keypair[];
456
+ setupIxs: web3.TransactionInstruction[];
457
+ }>;
458
+ ixProvideLiquidityClassic({ depositor, amountBase, amountPt, minLpOut, lowerTickApy, upperTickApy, tokenSyDepositor: tokenSyDepositorParam, tokenYtDepositor: tokenYtDepositorParam, tokenPtDepositor: tokenPtDepositorParam, tokenBaseDepositor: tokenBaseDepositorParam, }: {
459
+ depositor: web3.PublicKey;
460
+ amountBase: bigint;
461
+ amountPt: bigint;
462
+ minLpOut: bigint;
463
+ lowerTickApy: number;
464
+ upperTickApy: number;
465
+ tokenSyDepositor?: web3.PublicKey;
466
+ tokenYtDepositor?: web3.PublicKey;
467
+ tokenPtDepositor?: web3.PublicKey;
468
+ tokenBaseDepositor?: web3.PublicKey;
469
+ }): Promise<{
470
+ ixs: web3.TransactionInstruction[];
471
+ signers: web3.Keypair[];
472
+ setupIxs: web3.TransactionInstruction[];
473
+ }>;
474
+ ixWithdrawLiquidityToBase({ owner, amountLp, minBaseOut, lpPosition, tokenSyWithdrawer: tokenSyWithdrawerParam, tokenYtWithdrawer: tokenYtWithdrawerParam, tokenPtWithdrawer: tokenPtWithdrawerParam, tokenBaseWithdrawer: tokenBaseWithdrawerParam, }: {
475
+ owner: web3.PublicKey;
476
+ amountLp: bigint;
477
+ minBaseOut: bigint;
478
+ lpPosition: web3.PublicKey;
479
+ tokenSyWithdrawer?: web3.PublicKey;
480
+ tokenYtWithdrawer?: web3.PublicKey;
481
+ tokenPtWithdrawer?: web3.PublicKey;
482
+ tokenBaseWithdrawer?: web3.PublicKey;
483
+ }): Promise<{
484
+ ixs: web3.TransactionInstruction[];
485
+ setupIxs: web3.TransactionInstruction[];
486
+ }>;
487
+ ixWithdrawLiquidityClassic({ owner, amountLp, lpPosition, tokenSyWithdrawer: tokenSyWithdrawerParam, tokenYtWithdrawer: tokenYtWithdrawerParam, tokenPtWithdrawer: tokenPtWithdrawerParam, tokenBaseWithdrawer: tokenBaseWithdrawerParam, }: {
488
+ owner: web3.PublicKey;
489
+ amountLp: bigint;
490
+ lpPosition: web3.PublicKey;
491
+ tokenSyWithdrawer?: web3.PublicKey;
492
+ tokenYtWithdrawer?: web3.PublicKey;
493
+ tokenPtWithdrawer?: web3.PublicKey;
494
+ tokenBaseWithdrawer?: web3.PublicKey;
495
+ }): Promise<{
496
+ ixs: web3.TransactionInstruction[];
497
+ setupIxs: web3.TransactionInstruction[];
498
+ }>;
499
+ getUserLpPositions(owner: web3.PublicKey, market: web3.PublicKey): Promise<{
500
+ lpPositions: import("@coral-xyz/anchor").ProgramAccount<{
501
+ owner: web3.PublicKey;
502
+ market: web3.PublicKey;
503
+ feeInsideLastPt: BN;
504
+ feeInsideLastSy: BN;
505
+ lpBalance: BN;
506
+ tokensOwedSy: BN;
507
+ tokensOwedPt: BN;
508
+ lowerTickIdx: number;
509
+ upperTickIdx: number;
510
+ farms: {
511
+ trackers: {
512
+ lastSeenIndex: {
513
+ 0: BN[];
514
+ };
515
+ staged: BN;
516
+ }[];
517
+ };
518
+ shareTrackers: {
519
+ trackers: {
520
+ tickIdx: number;
521
+ rightTickIdx: number;
522
+ splitEpoch: BN;
523
+ lpShare: BN;
524
+ emissions: {
525
+ trackers: {
526
+ lastSeenIndex: unknown;
527
+ staged: BN;
528
+ }[];
529
+ };
530
+ }[];
531
+ };
532
+ }>[][];
533
+ }>;
534
+ ixMarketAccureEmissions({ owner, lpPosition }: {
535
+ owner: web3.PublicKey;
536
+ lpPosition: web3.PublicKey;
537
+ }): Promise<{
538
+ ixs: web3.TransactionInstruction[];
539
+ }>;
540
+ /**
541
+ * Calculate the current price per unit of liquidity (principal only) for a tick range.
542
+ * Mirrors the on-chain `liquidity_unit_price_in_asset` helper but performs the
543
+ * principal aggregation client-side using the fetched ticks account.
544
+ *
545
+ * @param lowerTickKey - Inclusive tick key (APY in parts-per-million) for the left boundary
546
+ * @param upperTickKey - Exclusive tick key for the right boundary
547
+ * @param ticksOverride - Optional ticks account (defaults to the instance state)
548
+ * @param syExchangeRateOverride - Optional SY exchange rate (defaults to current flavor rate)
549
+ * @returns Price per unit of liquidity in underlying asset terms (principal only)
550
+ */
551
+ liquidityUnitPriceInAsset({ lowerTickKey, upperTickKey, ticksOverride, syExchangeRateOverride, }: {
552
+ lowerTickKey: number;
553
+ upperTickKey: number;
554
+ ticksOverride?: Ticks;
555
+ syExchangeRateOverride?: number;
556
+ }): number;
557
+ /**
558
+ * Compute fee growth inside a tick range using Uniswap V3 formula
559
+ *
560
+ * @param lowerTick - Lower tick boundary
561
+ * @param upperTick - Upper tick boundary
562
+ * @param feeGlobalPt - Optional: Override global PT fees (for historical calculations)
563
+ * @param feeGlobalSy - Optional: Override global SY fees (for historical calculations)
564
+ * @returns Object with inside_sy and inside_pt fee growth values
565
+ */
566
+ static computeFeeInsideForRange({ currentTickPrice, lowerTickPrice, upperTickPrice, feeGrowthIndexGlobalPt, feeGrowthIndexGlobalSy, lowerTickOutsidePt, lowerTickOutsideSy, upperTickOutsidePt, upperTickOutsideSy, }: {
567
+ currentTickPrice: number;
568
+ lowerTickPrice: number;
569
+ upperTickPrice: number;
570
+ feeGrowthIndexGlobalPt: bigint;
571
+ feeGrowthIndexGlobalSy: bigint;
572
+ lowerTickOutsidePt: bigint;
573
+ lowerTickOutsideSy: bigint;
574
+ upperTickOutsidePt: bigint;
575
+ upperTickOutsideSy: bigint;
576
+ }): {
577
+ insideSy: bigint;
578
+ insidePt: bigint;
579
+ };
580
+ /**
581
+ * Calculate claimable fees for a position
582
+ * Uses Q64.64 fixed-point math: tokens = floor((L * Δindex) >> 64)
583
+ *
584
+ * @param lpBalance - Position's liquidity balance
585
+ * @param feeInsideLastSy - Last snapshot of inside SY fee growth
586
+ * @param feeInsideLastPt - Last snapshot of inside PT fee growth
587
+ * @param currentInsideSy - Current inside SY fee growth
588
+ * @param currentInsidePt - Current inside PT fee growth
589
+ * @param tokensOwedSy - Previously owed SY fees
590
+ * @param tokensOwedPt - Previously owed PT fees
591
+ * @returns Object with claimable and total fees
592
+ */
593
+ static calculateClaimableFees({ lpBalance, feeInsideLastSy, feeInsideLastPt, currentInsideSy, currentInsidePt, tokensOwedSy, tokensOwedPt, }: {
594
+ lpBalance: bigint;
595
+ feeInsideLastSy: bigint;
596
+ feeInsideLastPt: bigint;
597
+ currentInsideSy: bigint;
598
+ currentInsidePt: bigint;
599
+ tokensOwedSy: bigint;
600
+ tokensOwedPt: bigint;
601
+ }): {
602
+ claimableSy: bigint;
603
+ claimablePt: bigint;
604
+ tokensOwedSy: bigint;
605
+ tokensOwedPt: bigint;
606
+ totalSy: bigint;
607
+ totalPt: bigint;
608
+ };
609
+ /**
610
+ * Calculate historical fee APY for a tick range
611
+ *
612
+ * @param feeGrowthDeltaSy - Change in global SY fee growth over period
613
+ * @param feeGrowthDeltaPt - Change in global PT fee growth over period
614
+ * @param avgLiquidity - Average liquidity in the range during period
615
+ * @param hoursElapsed - Number of hours in the period
616
+ * @returns Object with fee APY metrics
617
+ */
618
+ static calculateHistoricalFeeApy({ feeGrowthDeltaSy, feeGrowthDeltaPt, avgLiquidity, hoursElapsed, }: {
619
+ feeGrowthDeltaSy: bigint;
620
+ feeGrowthDeltaPt: bigint;
621
+ avgLiquidity: bigint;
622
+ hoursElapsed: number;
623
+ }): {
624
+ feeApySy: number;
625
+ feeApyPt: number;
626
+ feeApyTotal: number;
627
+ totalFeesSy: bigint;
628
+ totalFeesPt: bigint;
629
+ };
630
+ depositYtAccounts({ owner, ytSrc: ytSrcParam, }: {
631
+ owner: web3.PublicKey;
632
+ ytSrc?: web3.PublicKey;
633
+ }): Promise<web3.TransactionInstruction>;
634
+ static calcEstimatedYieldForPosition(marketSnapshotDataCurrent: MarketSnapshotData, marketSnapshotDataHistory: MarketSnapshotData, lowerPricePercentage: number, upperPricePercentage: number, baseTokenAmount: number): {
635
+ totalFeeRate: number;
636
+ ptExpectedFees: bigint;
637
+ syExpectedFees: bigint;
638
+ expectedFeesBaseToken: number;
639
+ };
640
+ static calcGlobalFeeRate(marketSnapshotDataCurrent: MarketSnapshotData, marketSnapshotDataHistory: MarketSnapshotData): {
641
+ totalFeeRate: number;
642
+ totalFeesInBaseToken: number;
643
+ tvlInBaseToken: number;
644
+ };
645
+ /**
646
+ * Returns PT and SY amounts that will be received on liquidity removal from a position
647
+ * If liquidityToRemove is not provided, assume that the full position balance will be removed
648
+ */
649
+ getPtAndSyOnWithdrawLiquidity(position: LpPositionCLMM, liquidityToRemove?: bigint): {
650
+ totalPtOut: bigint;
651
+ totalSyOut: bigint;
652
+ };
653
+ }
654
+ /** Market snapshot data for CLMM market */
655
+ export type MarketSnapshotData = {
656
+ syExchangeRate: number;
657
+ /** Current spot price in format of 1 + percentage / 100 */
658
+ currentSpotPrice: number;
659
+ financials: MarketThreeFinancials;
660
+ feeGrowthIndexGlobalPt: bigint;
661
+ feeGrowthIndexGlobalSy: bigint;
662
+ currentPrefixSum: bigint;
663
+ snapshotTimeUnix: number;
664
+ };