@exponent-labs/exponent-fetcher 0.1.7 → 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 (50) hide show
  1. package/build/exponentFetcher.d.ts +303 -31
  2. package/build/exponentFetcher.js +666 -168
  3. package/build/exponentFetcher.js.map +1 -1
  4. package/build/index.d.ts +10 -0
  5. package/build/index.js +10 -0
  6. package/build/index.js.map +1 -1
  7. package/build/utils/adrena.d.ts +13 -0
  8. package/build/utils/adrena.js +29 -0
  9. package/build/utils/adrena.js.map +1 -0
  10. package/build/utils/fragmetric.d.ts +17 -0
  11. package/build/utils/fragmetric.js +23 -0
  12. package/build/utils/fragmetric.js.map +1 -0
  13. package/build/utils/jito.d.ts +7 -0
  14. package/build/utils/jito.js +29 -0
  15. package/build/utils/jito.js.map +1 -0
  16. package/build/utils/jupiter.d.ts +30 -0
  17. package/build/utils/jupiter.js +63 -0
  18. package/build/utils/jupiter.js.map +1 -0
  19. package/build/utils/kamino.d.ts +5 -0
  20. package/build/utils/kamino.js +10 -0
  21. package/build/utils/kamino.js.map +1 -0
  22. package/build/utils/meteora.d.ts +19 -0
  23. package/build/utils/meteora.js +36 -1
  24. package/build/utils/meteora.js.map +1 -1
  25. package/build/utils/ore.d.ts +74 -0
  26. package/build/utils/ore.js +217 -0
  27. package/build/utils/ore.js.map +1 -0
  28. package/build/utils/perena.d.ts +12 -0
  29. package/build/utils/perena.js +27 -0
  30. package/build/utils/perena.js.map +1 -0
  31. package/build/utils/sanctum.d.ts +6 -0
  32. package/build/utils/sanctum.js +26 -0
  33. package/build/utils/sanctum.js.map +1 -0
  34. package/build/utils/solstice.d.ts +12 -0
  35. package/build/utils/solstice.js +45 -0
  36. package/build/utils/solstice.js.map +1 -0
  37. package/package.json +20 -18
  38. package/src/exponentFetcher.ts +1077 -222
  39. package/src/index.ts +10 -0
  40. package/src/utils/adrena.ts +44 -0
  41. package/src/utils/fragmetric.ts +34 -0
  42. package/src/utils/jito.ts +30 -0
  43. package/src/utils/jupiter.ts +98 -0
  44. package/src/utils/kamino.ts +6 -0
  45. package/src/utils/meteora.ts +73 -1
  46. package/src/utils/ore.ts +322 -0
  47. package/src/utils/perena.ts +28 -0
  48. package/src/utils/sanctum.ts +24 -0
  49. package/src/utils/solstice.ts +51 -0
  50. package/tsconfig.json +2 -0
@@ -1,14 +1,22 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  /// <reference types="bn.js" />
2
4
  import { BN, Program, Wallet, web3 } from "@coral-xyz/anchor";
3
5
  import Decimal from "decimal.js";
6
+ import { ExponentClmm } from "@exponent-labs/exponent-clmm-idl";
4
7
  import { ExponentCore } from "@exponent-labs/exponent-idl";
5
- import { AnchorizedPNum, AnchorizedPNumJson, CpiAccountIndexes, GenericSyMetaAccount, InterfaceType, JitoRestakingSyMetaAccount, MarginfiSyMeta, PerenaSyMetaAccount, SyEmissionRaw, VaultEmission, VaultEmissionJson } from "@exponent-labs/exponent-types";
8
+ import { ExponentOrderbook } from "@exponent-labs/exponent-orderbook-idl";
9
+ import { AnchorizedPNum, AnchorizedPNumJson, CpiAccountIndexes, ExponentCoreCpiIndexes, GenericSyMetaAccount, InterfaceType, JitoRestakingSyMetaAccount, MarginfiSyMeta, MarketCpiCoreIndexes, PerenaSyMetaAccount, SyEmissionRaw, VaultEmission, VaultEmissionJson } from "@exponent-labs/exponent-types";
10
+ import { OfferNode, PriceTreeNode, UserEscrowNode } from "@exponent-labs/exponent-types";
6
11
  import { GenericStandard } from "@exponent-labs/generic-sy-idl";
7
12
  import { JitoRestakingStandard } from "@exponent-labs/jito-restaking-sy-idl";
8
13
  import { Obligation } from "@exponent-labs/kamino-reserve-deserializer";
9
14
  import { KaminoLendStandard } from "@exponent-labs/kamino-sy-idl";
10
15
  import { MarginfiStandard } from "@exponent-labs/marginfi-sy-idl";
11
16
  import { PerenaStandard } from "@exponent-labs/perena-sy-idl";
17
+ import { calculateFragmetricSupportedTokenIndex } from "./utils/fragmetric";
18
+ import { calculateJupiterLendIndex, calculateJupiterPerpsIndex } from "./utils/jupiter";
19
+ import { calculateSolsticeRedemptionRate } from "./utils/solstice";
12
20
  export declare function serializeAnchorizedPNumFromJson(pnum: AnchorizedPNum): AnchorizedPNumJson;
13
21
  export declare function deserializeAnchorizedPNumFromJson(serialized: AnchorizedPNumJson): AnchorizedPNum;
14
22
  export declare class MyWallet implements Wallet {
@@ -25,6 +33,8 @@ export declare class ExponentFetcher {
25
33
  jitoRestakingSyProgram: Program<JitoRestakingStandard>;
26
34
  perenaSyProgram: Program<PerenaStandard>;
27
35
  genericStandardProgram: Program<GenericStandard>;
36
+ exponentClmmProgram: Program<ExponentClmm>;
37
+ orderbookProgram: Program<ExponentOrderbook>;
28
38
  connection: web3.Connection;
29
39
  coreProgramId: web3.PublicKey;
30
40
  marginfiSyProgramId: web3.PublicKey;
@@ -43,6 +53,8 @@ export declare class ExponentFetcher {
43
53
  });
44
54
  fetchVault(address: web3.PublicKey): Promise<Vault>;
45
55
  fetchMarket(address: web3.PublicKey): Promise<MarketTwo>;
56
+ fetchOrderbook(address: web3.PublicKey): Promise<Orderbook>;
57
+ fetchOrderbookCpiAccounts(address: web3.PublicKey): Promise<OrderbookCpiAccountsRaw>;
46
58
  fetchMarginfiSyMeta(address: web3.PublicKey): Promise<MarginfiSyMeta>;
47
59
  fetchMarginfiSyPosition(address: web3.PublicKey): Promise<SyPosition>;
48
60
  fetchKaminoSyPosition(address: web3.PublicKey): Promise<SyPosition>;
@@ -51,19 +63,177 @@ export declare class ExponentFetcher {
51
63
  fetchGenericSyPosition(address: web3.PublicKey): Promise<SyPosition>;
52
64
  fetchKaminoSyMeta(address: web3.PublicKey): Promise<KaminoSyMeta>;
53
65
  fetchLpPosition(address: web3.PublicKey): Promise<LpPosition>;
66
+ fetchLpPositionCLMM(address: web3.PublicKey): Promise<LpPositionCLMM>;
54
67
  fetchYtPosition(address: web3.PublicKey): Promise<YtPosition>;
68
+ /** Batch fetch multiple YT positions in a single RPC call */
69
+ fetchYtPositions(addresses: web3.PublicKey[]): Promise<(YtPosition | null)[]>;
55
70
  fetchJitoRestakingSyMeta(address: web3.PublicKey): Promise<JitoRestakingSyMetaAccount>;
56
71
  fetchPerenaSyMeta(address: web3.PublicKey): Promise<PerenaSyMetaAccount>;
57
72
  fetchGenericSyMeta(address: web3.PublicKey): Promise<GenericSyMetaAccount>;
73
+ fetchAllMarketThree(): Promise<MarketThree[]>;
74
+ fetchMarketThree(address: web3.PublicKey): Promise<MarketThree>;
75
+ fetchAllMarketThreeTicks(): Promise<Ticks[]>;
76
+ fetchMarketThreeTicks(address: web3.PublicKey): Promise<Ticks>;
58
77
  }
59
- export declare function fetchKaminoReserve(address: web3.PublicKey, connection: web3.Connection): Promise<{
78
+ export declare function deserializeMarketThreeTicks(data: Buffer): Ticks;
79
+ export declare function deserializeLpPosition(x: LpPositionRaw): LpPosition;
80
+ export declare function deserializeYtPosition(x: YtPositionRaw): YtPosition;
81
+ export interface KaminoReserveSummary {
60
82
  lendingMarket: web3.PublicKey;
61
83
  baseMint: web3.PublicKey;
62
84
  assetShareValue: Decimal;
63
- }>;
85
+ scopePriceFeed?: web3.PublicKey;
86
+ }
87
+ export declare function fetchKaminoReserve(address: web3.PublicKey, connection: web3.Connection): Promise<KaminoReserveSummary>;
64
88
  export declare function fetchAllKaminoObligationsByKaminoReserve(reserve: web3.PublicKey, connection: web3.Connection): Promise<Obligation[]>;
65
89
  export declare function serializeEmission(emission: VaultEmission): VaultEmissionJson;
66
90
  export declare function deserializeEmission(emission: VaultEmissionJson): VaultEmission;
91
+ export interface MarketThree {
92
+ admin: web3.PublicKey;
93
+ addressLookupTable: web3.PublicKey;
94
+ mintPt: web3.PublicKey;
95
+ mintSy: web3.PublicKey;
96
+ mintYt: web3.PublicKey;
97
+ vault: web3.PublicKey;
98
+ tokenPtEscrow: web3.PublicKey;
99
+ tokenSyEscrow: web3.PublicKey;
100
+ tokenYtEscrow: web3.PublicKey;
101
+ tokenFeeTreasurySy: web3.PublicKey;
102
+ tokenFeeTreasuryPt: web3.PublicKey;
103
+ syProgram: web3.PublicKey;
104
+ exponentCoreProgram: web3.PublicKey;
105
+ selfAddress: web3.PublicKey;
106
+ ticks: web3.PublicKey;
107
+ statusFlags: number;
108
+ configurationOptions: MarketConfigurationOptions;
109
+ financials: MarketThreeFinancials;
110
+ cpiSyAccounts: CpiAccountIndexes;
111
+ cpiCoreAccounts: MarketCpiCoreIndexes;
112
+ isCurrentFlashSwap: boolean;
113
+ lpFarm: LpFarm;
114
+ emissions: {
115
+ trackers: {
116
+ tokenEscrow: web3.PublicKey;
117
+ lpShareIndex: number;
118
+ lastSeenStaged: number;
119
+ }[];
120
+ };
121
+ liquidityNetBalanceLimits: LiquidityNetBalanceLimits;
122
+ }
123
+ export interface Ticks {
124
+ /** Current tick (left boundary of the active interval) */
125
+ currentTick: number;
126
+ /** Array of ticks (simplified from RBTree for TypeScript) */
127
+ ticksTree: Tick[];
128
+ /** Market address this ticks account belongs to */
129
+ market: web3.PublicKey;
130
+ /** Fee growth index global for PT */
131
+ feeGrowthIndexGlobalPt: bigint;
132
+ /** Fee growth index global for SY */
133
+ feeGrowthIndexGlobalSy: bigint;
134
+ /** Current prefix sum - the active liquidity at the current tick */
135
+ currentPrefixSum: bigint;
136
+ /** Current spot price (ln implied rate) */
137
+ currentSpotPrice: number;
138
+ }
139
+ export interface Tick {
140
+ liquidityNet: bigint;
141
+ /** Total liquidity referencing this tick as a boundary */
142
+ liquidityGross: bigint;
143
+ /** Fee growth index outside this tick for PT */
144
+ feeGrowthOutsidePt: bigint;
145
+ /** Fee growth index outside this tick for SY */
146
+ feeGrowthOutsideSy: bigint;
147
+ /** Principal PT accrued in the interval starting at this tick */
148
+ impliedRate: number;
149
+ principalPt: bigint;
150
+ /** Principal SY accrued in the interval starting at this tick */
151
+ principalSy: bigint;
152
+ apyBasePoints: number;
153
+ principalShareSupply: bigint;
154
+ /** Farm yield trackers (3 trackers) */
155
+ farms: {
156
+ lastSeenIndex: number;
157
+ }[];
158
+ /** Emission yield trackers (3 trackers) */
159
+ emissions: {
160
+ lastSeenIndex: number;
161
+ lastPositionIndex: number;
162
+ }[];
163
+ /** Last split epoch for this tick */
164
+ lastSplitEpoch: bigint;
165
+ }
166
+ export interface MarketThreeRaw {
167
+ admin: web3.PublicKey;
168
+ addressLookupTable: web3.PublicKey;
169
+ mintPt: web3.PublicKey;
170
+ mintSy: web3.PublicKey;
171
+ mintYt: web3.PublicKey;
172
+ vault: web3.PublicKey;
173
+ tokenPtEscrow: web3.PublicKey;
174
+ tokenSyEscrow: web3.PublicKey;
175
+ tokenYtEscrow: web3.PublicKey;
176
+ tokenFeeTreasurySy: web3.PublicKey;
177
+ tokenFeeTreasuryPt: web3.PublicKey;
178
+ syProgram: web3.PublicKey;
179
+ exponentCoreProgram: web3.PublicKey;
180
+ selfAddress: web3.PublicKey;
181
+ ticks: web3.PublicKey;
182
+ statusFlags: number;
183
+ configurationOptions: MarketConfigurationOptionsRaw;
184
+ financials: MarketThreeFinancialsRaw;
185
+ cpiSyAccounts: CpiAccountIndexes;
186
+ cpiCoreAccounts: MarketCpiCoreIndexes;
187
+ isCurrentFlashSwap: boolean;
188
+ lpFarm: LpFarm;
189
+ emissions: MarketEmissions;
190
+ liquidityNetBalanceLimits: LiquidityNetBalanceLimits;
191
+ seedId: number[];
192
+ }
193
+ export interface MarketConfigurationOptions {
194
+ /** ln of fee rate root */
195
+ lnFeeRateRoot: number;
196
+ /** Treasury fee in basis points */
197
+ treasuryFeeBps: number;
198
+ /** Minimum LP amount per tick */
199
+ minLpTickAmount: bigint;
200
+ /** Epsilon clamp for numerical stability */
201
+ epsilonClamp: number;
202
+ /** Maximum LP supply */
203
+ maxLpSupply: bigint;
204
+ /** Tick space */
205
+ tickSpace: number;
206
+ }
207
+ export interface MarketThreeFinancials {
208
+ expirationTs: bigint;
209
+ ptBalance: bigint;
210
+ syBalance: bigint;
211
+ liquidityBalance: bigint;
212
+ }
213
+ export interface MarketConfigurationOptionsRaw {
214
+ lnFeeRateRoot: number;
215
+ treasuryFeeBps: number;
216
+ minLpTickAmount: BN;
217
+ epsilonClamp: number;
218
+ maxLpSupply: BN;
219
+ tickSpace: number;
220
+ }
221
+ export interface OrderbookConfigurationOptionsRaw {
222
+ thresholdAmount: BN;
223
+ lnMakerFeeRate: number;
224
+ lnTakerFeeRate: number;
225
+ priceDecimals: number;
226
+ }
227
+ export interface MarketThreeFinancialsRaw {
228
+ /** Expiration timestamp */
229
+ expirationTs: number;
230
+ /** PT balance in the market */
231
+ ptBalance: BN;
232
+ /** SY balance in the market */
233
+ syBalance: BN;
234
+ /** Total liquidity balance */
235
+ liquidityBalance: BN;
236
+ }
67
237
  export interface MarketTwo {
68
238
  ptBalance: bigint;
69
239
  syBalance: bigint;
@@ -127,6 +297,39 @@ export interface Vault {
127
297
  cpiAccounts: CpiAccountIndexes;
128
298
  maxPySupply: bigint;
129
299
  }
300
+ interface OrderbookFinancials {
301
+ expirationTs: number;
302
+ ytBalance: bigint;
303
+ syBalance: bigint;
304
+ ptBalance: bigint;
305
+ ytFeeBalance: bigint;
306
+ syFeeBalance: bigint;
307
+ ptFeeBalance: bigint;
308
+ stagedSy: bigint;
309
+ }
310
+ export interface ConfigurationOptions {
311
+ priceDecimals: number;
312
+ thresholdAmount: bigint;
313
+ lnMakerFeeRate: number;
314
+ lnTakerFeeRate: number;
315
+ }
316
+ export interface Orderbook {
317
+ vault: web3.PublicKey;
318
+ yieldPosition: web3.PublicKey;
319
+ addressLookupTable: web3.PublicKey;
320
+ exponentCoreProgram: web3.PublicKey;
321
+ syProgram: web3.PublicKey;
322
+ tokenEscrowSy: web3.PublicKey;
323
+ tokenEscrowYt: web3.PublicKey;
324
+ tokenEscrowPt: web3.PublicKey;
325
+ cpiAccountOrderbook: web3.PublicKey;
326
+ admin: web3.PublicKey;
327
+ configurationOptions: ConfigurationOptions;
328
+ financials: OrderbookFinancials;
329
+ prices: PriceTreeNode[];
330
+ offers: OfferNode[];
331
+ userEscrows: UserEscrowNode[];
332
+ }
130
333
  export interface KaminoSyMeta {
131
334
  kaminoReserve: web3.PublicKey;
132
335
  kaminoObligation: web3.PublicKey;
@@ -175,6 +378,48 @@ export interface YieldTokenTracker {
175
378
  staged: bigint;
176
379
  lastSeenIndex: number;
177
380
  }
381
+ export interface LpPositionRaw {
382
+ owner: web3.PublicKey;
383
+ market: web3.PublicKey;
384
+ lpBalance: BN;
385
+ emissions: {
386
+ trackers: {
387
+ staged: BN;
388
+ lastSeenIndex: AnchorizedPNum;
389
+ }[];
390
+ };
391
+ farms: {
392
+ trackers: {
393
+ staged: BN;
394
+ lastSeenIndex: AnchorizedPNum;
395
+ }[];
396
+ };
397
+ }
398
+ export interface LpPositionCLMM {
399
+ owner: web3.PublicKey;
400
+ market: web3.PublicKey;
401
+ feeInsideLastPt: bigint;
402
+ feeInsideLastSy: bigint;
403
+ lpBalance: bigint;
404
+ tokensOwedSy: bigint;
405
+ tokensOwedPt: bigint;
406
+ lowerTickIdx: number;
407
+ upperTickIdx: number;
408
+ farms: {
409
+ staged: bigint;
410
+ lastSeenIndex: number;
411
+ }[];
412
+ shareTrackers: {
413
+ tickIdx: number;
414
+ rightTickIdx: number;
415
+ splitEpoch: bigint;
416
+ lpShare: bigint;
417
+ emissions: {
418
+ staged: bigint;
419
+ lastSeenIndex: number;
420
+ }[];
421
+ }[];
422
+ }
178
423
  export interface LpFarm {
179
424
  lastSeenTimestamp: number;
180
425
  farmEmissions: FarmEmissionRaw[];
@@ -195,11 +440,51 @@ export interface LiquidityNetBalanceLimits {
195
440
  export interface MarketEmissions {
196
441
  trackers: MarketEmission[];
197
442
  }
198
- interface MarketEmission {
443
+ export interface MarketEmission {
199
444
  tokenEscrow: web3.PublicKey;
200
445
  lpShareIndex: AnchorizedPNum;
201
446
  lastSeenStaged: BN;
202
447
  }
448
+ export interface YtPositionRaw {
449
+ owner: web3.PublicKey;
450
+ vault: web3.PublicKey;
451
+ ytBalance: BN;
452
+ interest: YieldTokenTrackerRaw;
453
+ emissions: YieldTokenTrackerRaw[];
454
+ }
455
+ interface YieldTokenTrackerRaw {
456
+ staged: BN;
457
+ lastSeenIndex: AnchorizedPNum;
458
+ }
459
+ export interface OrderbookCpiAccountsRaw {
460
+ syCpiAccounts: CpiAccountIndexes;
461
+ exponentCoreCpiAccounts: ExponentCoreCpiIndexes;
462
+ }
463
+ export interface PriceTreeNodeRaw {
464
+ key: number;
465
+ firstOffer: number;
466
+ parent: number;
467
+ left: number;
468
+ right: number;
469
+ }
470
+ export interface OfferNodeRaw {
471
+ register: number;
472
+ amount: BN;
473
+ userVaultPointer: number;
474
+ expiryAt: number;
475
+ createdAt: number;
476
+ virtualOffer: boolean;
477
+ orderTypeFlag: number;
478
+ fillOrKill: boolean;
479
+ }
480
+ export interface UserEscrowNodeRaw {
481
+ user: web3.PublicKey;
482
+ yieldIndex: BN;
483
+ ptAmount: BN;
484
+ syAmount: BN;
485
+ ytAmount: BN;
486
+ staged: number;
487
+ }
203
488
  export declare function fetchSplStakePoolIndex({ connection, stakePool, }: {
204
489
  connection: web3.Connection;
205
490
  stakePool: web3.PublicKey;
@@ -239,15 +524,7 @@ export declare function fetchJupiterPerpsIndex({ connection, pool, lastFeeUsdRes
239
524
  lastAumUsd: BN;
240
525
  currentIndex: AnchorizedPNum;
241
526
  lastRealizedFeeUsdUpdateUnixTimestamp: number;
242
- }): Promise<{
243
- index: number;
244
- newState: {
245
- lastAumUsd: BN;
246
- lastRealizedFeeUsd: BN;
247
- lastFeeUsdResetUnixTimestamp: number;
248
- lastRealizedFeeUsdUpdateUnixTimestamp: number;
249
- };
250
- }>;
527
+ }): Promise<ReturnType<typeof calculateJupiterPerpsIndex>>;
251
528
  export declare function fetchPyth(connection: web3.Connection): Promise<string>;
252
529
  export declare function fetchGenericSyMetaIndex({ connection, genericSyMeta, }: {
253
530
  connection: web3.Connection;
@@ -266,12 +543,7 @@ export declare function fetchFragmetricIndex({ connection, fragmetricFund, }: {
266
543
  export declare function fetchJupiterLendIndex({ connection, jupiterLendAccount, }: {
267
544
  connection: web3.Connection;
268
545
  jupiterLendAccount: web3.PublicKey;
269
- }): Promise<{
270
- index: number;
271
- baseTokenMint: any;
272
- tokenReservesLiquidity: any;
273
- lendingSupplyPosition: any;
274
- rewardsRateModel: any;
546
+ }): Promise<ReturnType<typeof calculateJupiterLendIndex> & {
275
547
  rateModel: web3.PublicKey;
276
548
  }>;
277
549
  export declare function fetchKaminoVaultIndex({ connection, kaminoVaultAccount, }: {
@@ -289,11 +561,7 @@ export declare function fetchFragmetricSupportedTokenIndex({ connection, fragmet
289
561
  connection: web3.Connection;
290
562
  fragmetricFund: web3.PublicKey;
291
563
  index: number;
292
- }): Promise<{
293
- index: number;
294
- receiptTokenMint: web3.PublicKey;
295
- wrappedTokenMint: web3.PublicKey;
296
- }>;
564
+ }): Promise<ReturnType<typeof calculateFragmetricSupportedTokenIndex>>;
297
565
  interface AccountsInterface {
298
566
  [k: string]: web3.PublicKey;
299
567
  }
@@ -325,11 +593,15 @@ export declare function fetchSolsticeRedemptionRate({ connection, yieldPool, ves
325
593
  connection: web3.Connection;
326
594
  yieldPool: web3.PublicKey;
327
595
  vestingSchedule: web3.PublicKey;
328
- }): Promise<{
329
- redemptionRate: number;
330
- totalAssets: string;
331
- sharesSupply: string;
332
- vestingAmount: string;
333
- totalVestedAssets: string;
334
- }>;
596
+ }): Promise<ReturnType<typeof calculateSolsticeRedemptionRate>>;
597
+ export declare function fetchReflectRedemptionRate({ connection, oracle, }: {
598
+ connection: web3.Connection;
599
+ oracle: web3.PublicKey;
600
+ }): Promise<number>;
601
+ export declare function fetchOreExchangeRate({ connection, storeMint, stakeAccount, treasury, }: {
602
+ connection: web3.Connection;
603
+ storeMint: web3.PublicKey;
604
+ stakeAccount: web3.PublicKey;
605
+ treasury: web3.PublicKey;
606
+ }): Promise<number>;
335
607
  export {};