@gearbox-protocol/sdk 14.0.0-next.1 → 14.0.0-next.2

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 (38) hide show
  1. package/dist/cjs/plugins/apy/ApyPlugin.js +266 -0
  2. package/dist/cjs/plugins/apy/apy-cache.js +120 -0
  3. package/dist/cjs/plugins/apy/apy-parser.js +169 -0
  4. package/dist/cjs/plugins/{pools-history/index.js → apy/constants.js} +14 -7
  5. package/dist/cjs/plugins/apy/index.js +34 -0
  6. package/dist/cjs/plugins/apy/pool-apy-types.js +16 -0
  7. package/dist/cjs/plugins/apy/pool-apy-utils.js +141 -0
  8. package/dist/cjs/rewards/rewards/extra-apy.js +10 -8
  9. package/dist/esm/plugins/apy/ApyPlugin.js +255 -0
  10. package/dist/esm/plugins/apy/apy-cache.js +86 -0
  11. package/dist/esm/plugins/apy/apy-parser.js +143 -0
  12. package/dist/esm/plugins/apy/constants.js +6 -0
  13. package/dist/esm/plugins/apy/index.js +7 -0
  14. package/dist/esm/plugins/apy/pool-apy-utils.js +113 -0
  15. package/dist/esm/plugins/apy/types.js +0 -0
  16. package/dist/esm/rewards/rewards/extra-apy.js +10 -8
  17. package/dist/types/src/plugins/apy/ApyPlugin.d.ts +46 -0
  18. package/dist/types/src/plugins/apy/apy-cache.d.ts +28 -0
  19. package/dist/types/src/plugins/apy/apy-parser.d.ts +5 -0
  20. package/dist/types/src/plugins/apy/constants.d.ts +2 -0
  21. package/dist/types/src/plugins/apy/index.d.ts +7 -0
  22. package/dist/types/src/plugins/apy/pool-apy-types.d.ts +41 -0
  23. package/dist/types/src/plugins/apy/pool-apy-utils.d.ts +73 -0
  24. package/dist/types/src/plugins/apy/types.d.ts +37 -0
  25. package/dist/types/src/rewards/rewards/api.d.ts +10 -1
  26. package/dist/types/src/rewards/rewards/common.d.ts +0 -10
  27. package/dist/types/src/rewards/rewards/extra-apy.d.ts +4 -6
  28. package/package.json +1 -1
  29. package/dist/cjs/plugins/pools-history/Pools7DAgoPlugin.js +0 -108
  30. package/dist/esm/plugins/pools-history/Pools7DAgoPlugin.js +0 -90
  31. package/dist/esm/plugins/pools-history/index.js +0 -2
  32. package/dist/types/src/plugins/pools-history/Pools7DAgoPlugin.d.ts +0 -20
  33. package/dist/types/src/plugins/pools-history/index.d.ts +0 -2
  34. package/dist/types/src/plugins/pools-history/types.d.ts +0 -9
  35. /package/dist/cjs/plugins/{pools-history → apy}/package.json +0 -0
  36. /package/dist/cjs/plugins/{pools-history → apy}/types.js +0 -0
  37. /package/dist/esm/plugins/{pools-history → apy}/package.json +0 -0
  38. /package/dist/esm/plugins/{pools-history/types.js → apy/pool-apy-types.js} +0 -0
@@ -0,0 +1,113 @@
1
+ import { PERCENTAGE_FACTOR, RAY } from "../../sdk/constants/index.js";
2
+ import { formatBN, rayToNumber } from "../../sdk/utils/formatter.js";
3
+ const SCALE = 1000000n;
4
+ const WEEKS_PER_YEAR = 54n;
5
+ function getPoolExtraAPY(lookupAddresses, poolExtraAPYList) {
6
+ if (!poolExtraAPYList) return [];
7
+ const result = [];
8
+ for (const addr of lookupAddresses) {
9
+ const extra = poolExtraAPYList[addr.toLowerCase()];
10
+ if (extra) {
11
+ result.push(...extra);
12
+ }
13
+ }
14
+ return result;
15
+ }
16
+ function calculateSupplyApy7d(currentDieselRate, currentSupplyRate, dieselRate7DAgo) {
17
+ if (dieselRate7DAgo > currentDieselRate) {
18
+ return rayToNumber(currentSupplyRate * SCALE) / Number(PERCENTAGE_FACTOR);
19
+ }
20
+ const apy = (currentDieselRate * RAY / dieselRate7DAgo - RAY) * WEEKS_PER_YEAR;
21
+ return rayToNumber(apy * SCALE) / Number(PERCENTAGE_FACTOR);
22
+ }
23
+ function calculatePoolFullAPY({
24
+ depositAPY,
25
+ underlyingAPY,
26
+ extraAPY,
27
+ currentExternalList
28
+ }) {
29
+ const baseAPY = [
30
+ { type: "supplyAPY", apy: depositAPY },
31
+ ...underlyingAPY > 0 ? [
32
+ {
33
+ type: "tokenYield",
34
+ apy: Number(underlyingAPY) / Number(PERCENTAGE_FACTOR)
35
+ }
36
+ ] : []
37
+ ];
38
+ const filteredExtra = [...extraAPY ?? []].filter((r) => r.apy > 0);
39
+ const baseAPYTotal = baseAPY.reduce((s, r) => s + (r.apy || 0), 0);
40
+ const extraAPYTotal = filteredExtra.reduce((s, r) => s + (r.apy || 0), 0);
41
+ const total = baseAPYTotal + extraAPYTotal;
42
+ const externalAPY = resolveExternalAPY(currentExternalList, total);
43
+ return {
44
+ totalAPY: total,
45
+ baseAPY,
46
+ extraAPY: filteredExtra,
47
+ extraAPYTotal,
48
+ externalAPY
49
+ };
50
+ }
51
+ function resolveExternalAPY(list, baseTotal) {
52
+ const first = list?.[0];
53
+ if (!first) return void 0;
54
+ return {
55
+ ...first,
56
+ totalValue: baseTotal + first.value
57
+ };
58
+ }
59
+ function calculatePoolFullAPY7DAgo({
60
+ supplyAPY7DAgo,
61
+ depositAPY,
62
+ poolAPY
63
+ }) {
64
+ const {
65
+ baseAPY = [],
66
+ extraAPYTotal = 0,
67
+ extraAPY = [],
68
+ externalAPY
69
+ } = poolAPY ?? {};
70
+ const base = [
71
+ { apy: supplyAPY7DAgo || depositAPY, type: "supplyAPY" },
72
+ ...baseAPY.filter((r) => r.type !== "supplyAPY")
73
+ ];
74
+ const baseTotal = base.reduce((acc, r) => acc + r.apy, 0);
75
+ const total = baseTotal + extraAPYTotal;
76
+ return {
77
+ totalAPY: total,
78
+ extraAPYTotal,
79
+ baseAPY: base,
80
+ extraAPY,
81
+ externalAPY,
82
+ loading7DAgo: supplyAPY7DAgo === void 0
83
+ };
84
+ }
85
+ function calculatePoolPoints({
86
+ poolTokenSymbol,
87
+ points,
88
+ tokensList
89
+ }) {
90
+ return points?.map(({ info, points: pts }) => {
91
+ const { decimals = 18 } = tokensList.get(info.token) || {};
92
+ const amount = formatBN(pts, decimals);
93
+ const { name = "Points", duration } = info ?? {};
94
+ return {
95
+ reward: info,
96
+ name,
97
+ amount,
98
+ tokenTitle: poolTokenSymbol,
99
+ fullTip: [
100
+ `${amount} ${name}`,
101
+ ...duration ? [duration] : [],
102
+ ...poolTokenSymbol ? [poolTokenSymbol] : []
103
+ ].join(" per ")
104
+ };
105
+ });
106
+ }
107
+ export {
108
+ calculatePoolFullAPY,
109
+ calculatePoolFullAPY7DAgo,
110
+ calculatePoolPoints,
111
+ calculateSupplyApy7d,
112
+ getPoolExtraAPY
113
+ };
File without changes
@@ -52,11 +52,13 @@ class PoolPointsAPI {
52
52
  tokensList
53
53
  }) {
54
54
  const r = pools.reduce((acc, p) => {
55
- const pointsInfo = poolRewards[p.address] || [];
55
+ const poolAddress = p.pool.pool.address.toLowerCase();
56
+ const pointsInfo = poolRewards[poolAddress] || [];
56
57
  const poolPointsList = pointsInfo.reduce(
57
58
  (acc2, pointsInfo2) => {
58
- const { address: tokenAddress } = tokensList[pointsInfo2.token] || {};
59
- const tokenBalance = totalTokenBalances[tokenAddress || ""];
59
+ const { addr: tokenAddress } = tokensList.get(pointsInfo2.token) || {};
60
+ const tokenAddressLower = (tokenAddress || "").toLowerCase();
61
+ const tokenBalance = totalTokenBalances[tokenAddressLower];
60
62
  const points = PoolPointsAPI.getPoolTokenPoints(
61
63
  tokenBalance,
62
64
  p,
@@ -74,22 +76,22 @@ class PoolPointsAPI {
74
76
  },
75
77
  []
76
78
  );
77
- acc[p.address] = poolPointsList;
79
+ acc[poolAddress] = poolPointsList;
78
80
  return acc;
79
81
  }, {});
80
82
  return r;
81
83
  }
82
84
  static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
83
- if (pool.expectedLiquidity <= 0) return 0n;
85
+ if (pool.pool.pool.expectedLiquidity <= 0) return 0n;
84
86
  if (pointsInfo.estimation === "relative" && !tokenBalanceInPool)
85
87
  return null;
86
- const { decimals = 18 } = tokensList[pointsInfo.token] || {};
88
+ const { decimals = 18 } = tokensList.get(pointsInfo.token) || {};
87
89
  const targetFactor = 10n ** BigInt(decimals);
88
90
  const defaultPoints = pointsInfo.amount * targetFactor / PERCENTAGE_FACTOR;
89
91
  if (pointsInfo.estimation === "absolute") return defaultPoints;
90
- const { decimals: underlyingDecimals = 18 } = tokensList[pool.underlyingToken] || {};
92
+ const { decimals: underlyingDecimals = 18 } = tokensList.get(pool.pool.pool.underlying) || {};
91
93
  const underlyingFactor = 10n ** BigInt(underlyingDecimals);
92
- const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
94
+ const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.pool.pool.expectedLiquidity * targetFactor / underlyingFactor);
93
95
  return BigIntMath.min(points, defaultPoints);
94
96
  }
95
97
  }
@@ -0,0 +1,46 @@
1
+ import type { Address } from "viem";
2
+ import type { IOnchainSDKPlugin } from "../../sdk/index.js";
3
+ import { AddressMap, BasePlugin } from "../../sdk/index.js";
4
+ import type { GetPoolsAPYResult } from "./pool-apy-types.js";
5
+ import type { ApySnapshotState, Pool7DAgoState, Pools7DAgoStateHuman } from "./types.js";
6
+ export interface ApyPluginState {
7
+ pools7DAgo: Record<Address, Pool7DAgoState>;
8
+ apySnapshot: ApySnapshotState;
9
+ }
10
+ export interface ApyPluginConstructorOptions {
11
+ apyUrl?: string;
12
+ /** TTL for the shared HTTP cache in milliseconds (default: 10 minutes, see `DEFAULT_APY_INTERVAL_MS`) */
13
+ cacheTtlMs?: number;
14
+ }
15
+ export interface ApyPluginLoadOptions {
16
+ /**
17
+ * When `false` and the plugin is already loaded, skips the multicall that loads
18
+ * pool diesel rates at the ~7d-ago block; only the APY snapshot is refreshed.
19
+ * Ignored on the first load (both datasets are always fetched initially).
20
+ */
21
+ loadPools7DAgo?: boolean;
22
+ }
23
+ export declare class ApyPlugin extends BasePlugin<ApyPluginState> implements IOnchainSDKPlugin<ApyPluginState> {
24
+ #private;
25
+ constructor(loadOnAttach?: boolean, options?: ApyPluginConstructorOptions);
26
+ load(force?: boolean, loadOptions?: ApyPluginLoadOptions): Promise<ApyPluginState>;
27
+ get loaded(): boolean;
28
+ /**
29
+ * @throws if plugin is not loaded
30
+ */
31
+ get pools7DAgo(): AddressMap<Pool7DAgoState>;
32
+ /**
33
+ * @throws if plugin is not loaded
34
+ */
35
+ get apySnapshot(): ApySnapshotState;
36
+ /**
37
+ * Computes per-pool APY (current + 7d-ago) and points for all markets.
38
+ *
39
+ * @throws if plugin is not loaded
40
+ */
41
+ getPoolsAPY(): GetPoolsAPYResult;
42
+ syncState(): Promise<void>;
43
+ stateHuman(_?: boolean): Pools7DAgoStateHuman[];
44
+ get state(): ApyPluginState;
45
+ hydrate(state: ApyPluginState): void;
46
+ }
@@ -0,0 +1,28 @@
1
+ import type { Output } from "../../rewards/apy/index.js";
2
+ import type { ILogger } from "../../sdk/index.js";
3
+ /**
4
+ * Process-wide cache for the APY state-cache JSON.
5
+ *
6
+ * Multiple ApyPlugin instances (one per SDK / network) share the same
7
+ * cached HTTP response so that only **one** request is made per TTL window
8
+ * regardless of how many SDK instances exist.
9
+ *
10
+ * Concurrent callers that arrive while a fetch is already in flight
11
+ * are de-duplicated — they all await the same promise.
12
+ */
13
+ export declare class ApyOutputCache {
14
+ #private;
15
+ private constructor();
16
+ /**
17
+ * Returns a shared cache instance for the given URL.
18
+ * The same instance is reused across all callers with identical URL.
19
+ */
20
+ static get(url: string, ttlMs: number, logger?: ILogger): ApyOutputCache;
21
+ /**
22
+ * Returns cached Output if fresh, otherwise fetches from the network.
23
+ * Concurrent calls are de-duplicated.
24
+ */
25
+ fetch(): Promise<Output<string, string> | undefined>;
26
+ /** Evicts all cached entries. Mainly useful for tests. */
27
+ static clearAll(): void;
28
+ }
@@ -0,0 +1,5 @@
1
+ import type { DataResult, Output, PoolOutputDetails, TokenOutputDetails } from "../../rewards/apy/index.js";
2
+ import type { GearStats, NetworkApyData } from "./types.js";
3
+ export declare function numberToAPY(baseApy: number): number;
4
+ export declare function parseGearStats(output: Output<string, string>): GearStats | null;
5
+ export declare function parseNetworkApy(apyResp: DataResult<TokenOutputDetails<string>[]> | undefined, poolResp: DataResult<PoolOutputDetails<string>[]> | undefined): NetworkApyData | undefined;
@@ -0,0 +1,2 @@
1
+ export declare const APY_STATE_CACHE_URL = "https://state-cache.gearbox.foundation/apy-server/latest.json";
2
+ export declare const DEFAULT_APY_INTERVAL_MS: number;
@@ -0,0 +1,7 @@
1
+ export * from "./ApyPlugin.js";
2
+ export * from "./apy-cache.js";
3
+ export * from "./apy-parser.js";
4
+ export * from "./constants.js";
5
+ export * from "./pool-apy-types.js";
6
+ export * from "./pool-apy-utils.js";
7
+ export * from "./types.js";
@@ -0,0 +1,41 @@
1
+ import type { Address } from "viem";
2
+ import type { ExternalApy as ExternalApySDK, PoolExtraApy, PoolPointsInfo } from "../../rewards/apy/index.js";
3
+ import type { PoolPointsBase } from "../../rewards/index.js";
4
+ export interface PoolBaseAPY {
5
+ type: "supplyAPY" | "tokenYield";
6
+ apy: number;
7
+ }
8
+ /**
9
+ * External APY enriched with the cumulative `totalValue`
10
+ * (base + extra + external).
11
+ */
12
+ export interface PoolExternalAPY extends ExternalApySDK {
13
+ totalValue: number;
14
+ }
15
+ export interface PoolFullAPY {
16
+ totalAPY: number;
17
+ baseAPY: PoolBaseAPY[];
18
+ extraAPY: PoolExtraApy[];
19
+ extraAPYTotal: number;
20
+ externalAPY: PoolExternalAPY | undefined;
21
+ }
22
+ export interface PoolFullAPY7DAgo extends PoolFullAPY {
23
+ loading7DAgo: boolean;
24
+ }
25
+ export interface PoolPointsWithTips {
26
+ reward?: PoolPointsInfo<string>;
27
+ amount: string;
28
+ name: string;
29
+ tokenTitle?: string;
30
+ fullTip: string;
31
+ }
32
+ type AllPoolsAPY = Record<Address, PoolFullAPY>;
33
+ type AllPoolsAPY7DAgo = Record<Address, PoolFullAPY7DAgo>;
34
+ type AllPoolsPoints = Record<Address, PoolPointsWithTips[] | undefined>;
35
+ export interface GetPoolsAPYResult {
36
+ data: AllPoolsAPY;
37
+ data7DAgo: AllPoolsAPY7DAgo;
38
+ pointsBase: PoolPointsBase;
39
+ points: AllPoolsPoints;
40
+ }
41
+ export {};
@@ -0,0 +1,73 @@
1
+ import type { Address } from "viem";
2
+ import type { ExternalApy, PoolExtraApy } from "../../rewards/apy/index.js";
3
+ import type { PoolPointsBase } from "../../rewards/rewards/extra-apy.js";
4
+ import type { AddressMap } from "../../sdk/index.js";
5
+ import type { PoolFullAPY, PoolFullAPY7DAgo, PoolPointsWithTips } from "./pool-apy-types.js";
6
+ /**
7
+ * Collects extra APY entries for the given token addresses from the
8
+ * `poolExtraAPYList` map.
9
+ *
10
+ * In the client, `lookupAddresses` = [pool.address, ...pool.stakedDieselToken].
11
+ * The caller is responsible for providing the correct set of addresses.
12
+ */
13
+ export declare function getPoolExtraAPY(lookupAddresses: Address[], poolExtraAPYList: Record<Address, PoolExtraApy[]> | undefined): PoolExtraApy[];
14
+ /**
15
+ * Computes annualized supply APY based on diesel rate change over ~7 days.
16
+ *
17
+ * Returns a value in "percentage" units (e.g. 5 ≈ 5 %).
18
+ * Falls back to current on-chain `supplyRate` if 7d-ago diesel rate is
19
+ * missing or higher than the current rate.
20
+ */
21
+ export declare function calculateSupplyApy7d(currentDieselRate: bigint, currentSupplyRate: bigint, dieselRate7DAgo: bigint): number;
22
+ interface CalculatePoolFullAPYProps {
23
+ depositAPY: number;
24
+ underlyingAPY: number;
25
+ extraAPY: PoolExtraApy[] | undefined;
26
+ currentExternalList: ExternalApy[] | undefined;
27
+ }
28
+ /**
29
+ * Aggregates all APY components for a single pool.
30
+ *
31
+ * `depositAPY` and returned values are in "percentage" units (5 ≈ 5 %).
32
+ * `underlyingAPY` comes from `apyList` (scaled by `PERCENTAGE_FACTOR`),
33
+ * so it is divided by `PERCENTAGE_FACTOR` here.
34
+ *
35
+ * External APY: first entry in `currentExternalList`, enriched with `totalValue`.
36
+ */
37
+ export declare function calculatePoolFullAPY({ depositAPY, underlyingAPY, extraAPY, currentExternalList, }: CalculatePoolFullAPYProps): PoolFullAPY;
38
+ interface CalculatePoolFullAPY7DAgoProps {
39
+ depositAPY: number;
40
+ /**
41
+ * Annualized supply APY from the ~7d diesel snapshot, in the same units as
42
+ * `depositAPY`.
43
+ *
44
+ * - `undefined` — 7d snapshot not loaded yet (`loading7DAgo: true`); supply
45
+ * row uses `depositAPY`.
46
+ * - `null` — snapshot loaded but no numeric 7d supply; supply row uses
47
+ * `depositAPY` (`||` semantics, same as client `pool7DAgo` with missing
48
+ * `supplyAPY7DAgo`).
49
+ * - `number` — explicit 7d supply; `0` falls back to `depositAPY` via `||`.
50
+ */
51
+ supplyAPY7DAgo?: number | null;
52
+ poolAPY?: PoolFullAPY | null;
53
+ }
54
+ /**
55
+ * Computes the 7-days-ago APY snapshot for a pool.
56
+ *
57
+ * `supplyAPY7DAgo` replaces the current deposit APY in the base component;
58
+ * extra & external APY are kept from the "current" calculation.
59
+ */
60
+ export declare function calculatePoolFullAPY7DAgo({ supplyAPY7DAgo, depositAPY, poolAPY, }: CalculatePoolFullAPY7DAgoProps): PoolFullAPY7DAgo;
61
+ interface CalculatePoolPointsProps {
62
+ poolTokenSymbol: string | undefined;
63
+ points: PoolPointsBase[Address] | undefined;
64
+ tokensList: AddressMap<{
65
+ decimals: number;
66
+ }>;
67
+ }
68
+ /**
69
+ * Transforms raw `PoolPointsBase` entries into consumer-friendly
70
+ * `PoolPointsWithTips` items with formatted amounts and tooltip strings.
71
+ */
72
+ export declare function calculatePoolPoints({ poolTokenSymbol, points, tokensList, }: CalculatePoolPointsProps): PoolPointsWithTips[] | undefined;
73
+ export {};
@@ -0,0 +1,37 @@
1
+ import type { Address } from "viem";
2
+ import type { ExternalApy, ExtraCollateralAPY, GearAPYDetails, PointsInfo, PoolExtraApy, PoolPointsInfo } from "../../rewards/apy/index.js";
3
+ import type { BaseContractStateHuman } from "../../sdk/index.js";
4
+ export interface Pool7DAgoState {
5
+ pool: Address;
6
+ dieselRate: bigint;
7
+ }
8
+ export interface Pools7DAgoStateHuman extends BaseContractStateHuman {
9
+ dieselRate: bigint;
10
+ }
11
+ export interface FarmRewardInfo {
12
+ address: Address;
13
+ symbol: string;
14
+ rewardToken: Address;
15
+ rewardSymbol: string;
16
+ token: Address;
17
+ duration: bigint;
18
+ finished: bigint;
19
+ reward: bigint;
20
+ balance: bigint;
21
+ }
22
+ export interface NetworkApyData {
23
+ apyList: Record<Address, number> | undefined;
24
+ extraCollateralAPYList: Record<Address, Record<Address, ExtraCollateralAPY>> | undefined;
25
+ pointsList: Record<Address, PointsInfo<string>> | undefined;
26
+ extraCollateralPointsList: Record<Address, Record<Address, PointsInfo<string>>> | undefined;
27
+ poolRewardsList: Record<Address, Array<PoolPointsInfo<string>>> | undefined;
28
+ tokenExtraRewardsList: Record<Address, Array<FarmRewardInfo>> | undefined;
29
+ poolExternalAPYList: Record<Address, Array<ExternalApy>> | undefined;
30
+ poolExtraAPYList: Record<Address, Array<PoolExtraApy>> | undefined;
31
+ }
32
+ export type GearStats = Omit<GearAPYDetails, "lastUpdated">;
33
+ export interface ApySnapshotState {
34
+ apy: NetworkApyData;
35
+ gearStats: GearStats | null;
36
+ timestamp: string;
37
+ }
@@ -1,6 +1,15 @@
1
1
  import type { Address } from "viem";
2
2
  import { type NetworkType } from "../../sdk/index.js";
3
- import type { PoolData } from "./common.js";
3
+ export interface PoolData {
4
+ address: Address;
5
+ version: number;
6
+ underlyingToken: Address;
7
+ dieselRateRay: bigint;
8
+ dieselToken: Address;
9
+ stakedDieselToken: Address[];
10
+ stakedDieselToken_old: Address[];
11
+ expectedLiquidity: bigint;
12
+ }
4
13
  export interface GearboxExtraMerkleLmReward {
5
14
  pool: Address;
6
15
  poolToken: Address;
@@ -4,13 +4,3 @@ export interface TokenData {
4
4
  symbol: string;
5
5
  decimals: number;
6
6
  }
7
- export interface PoolData {
8
- address: Address;
9
- version: number;
10
- underlyingToken: Address;
11
- dieselRateRay: bigint;
12
- dieselToken: Address;
13
- stakedDieselToken: Address[];
14
- stakedDieselToken_old: Address[];
15
- expectedLiquidity: bigint;
16
- }
@@ -1,13 +1,12 @@
1
1
  import type { Address } from "viem";
2
- import { type Asset, type NetworkType } from "../../sdk/index.js";
2
+ import { type Asset, type MarketSuite, type NetworkType, type TokensMeta } from "../../sdk/index.js";
3
3
  import type { PoolPointsInfo } from "../index.js";
4
- import type { PoolData, TokenData } from "./common.js";
5
- type PartialPool = Pick<PoolData, "expectedLiquidity" | "underlyingToken" | "address">;
4
+ import type { TokenData } from "./common.js";
6
5
  export interface GetPointsByPoolProps {
7
6
  poolRewards: Record<Address, Array<PoolPointsInfo<string>>>;
8
7
  totalTokenBalances: Record<Address, Asset>;
9
- pools: Array<PartialPool>;
10
- tokensList: Record<Address, TokenData>;
8
+ pools: MarketSuite[];
9
+ tokensList: TokensMeta;
11
10
  }
12
11
  export interface GetTotalTokensOnProtocolProps {
13
12
  tokensToCheck: Array<Address>;
@@ -27,4 +26,3 @@ export declare class PoolPointsAPI {
27
26
  static getPointsByPool({ poolRewards, totalTokenBalances, pools, tokensList, }: GetPointsByPoolProps): PoolPointsBase;
28
27
  private static getPoolTokenPoints;
29
28
  }
30
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.0.0-next.1",
3
+ "version": "14.0.0-next.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var Pools7DAgoPlugin_exports = {};
20
- __export(Pools7DAgoPlugin_exports, {
21
- Pools7DAgoPlugin: () => Pools7DAgoPlugin
22
- });
23
- module.exports = __toCommonJS(Pools7DAgoPlugin_exports);
24
- var import_marketCompressor = require("../../abi/compressors/marketCompressor.js");
25
- var import_sdk = require("../../sdk/index.js");
26
- const MAP_LABEL = "pools7DAgo";
27
- class Pools7DAgoPlugin extends import_sdk.BasePlugin {
28
- #pools7DAgo;
29
- async load(force) {
30
- if (!force && this.loaded) {
31
- return this.state;
32
- }
33
- const targetBlock = this.sdk.currentBlock - import_sdk.BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.networkType];
34
- const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
35
- import_sdk.AP_MARKET_COMPRESSOR,
36
- import_sdk.VERSION_RANGE_310
37
- );
38
- this.sdk.logger?.debug(
39
- `loading pools 7d ago with market compressor ${marketCompressorAddress}`
40
- );
41
- const markets = this.sdk.marketRegister.markets;
42
- const resp = await this.client.multicall({
43
- allowFailure: true,
44
- contracts: markets.map(
45
- (m) => ({
46
- address: marketCompressorAddress,
47
- abi: import_marketCompressor.marketCompressorAbi,
48
- functionName: "getPoolState",
49
- args: [m.pool.pool.address]
50
- })
51
- ),
52
- blockNumber: targetBlock > 0n ? targetBlock : void 0,
53
- batchSize: 0
54
- });
55
- this.#pools7DAgo = new import_sdk.AddressMap(void 0, MAP_LABEL);
56
- resp.forEach((r, index) => {
57
- const m = markets[index];
58
- const cfg = m.configurator.address;
59
- const pool = m.pool.pool.address;
60
- if (r.status === "success") {
61
- this.#pools7DAgo?.upsert(m.pool.pool.address, {
62
- dieselRate: r.result.dieselRate,
63
- pool
64
- });
65
- } else {
66
- this.sdk.logger?.error(
67
- `failed to load pools 7d ago for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.error}`
68
- );
69
- }
70
- });
71
- return this.state;
72
- }
73
- get loaded() {
74
- return !!this.#pools7DAgo;
75
- }
76
- /**
77
- * Returns a map of pool addresses to minified pool 7d ago state
78
- * @throws if pool 7d ago plugin is not attached
79
- */
80
- get pools7DAgo() {
81
- if (!this.#pools7DAgo) {
82
- throw new Error("pools 7d ago plugin not attached");
83
- }
84
- return this.#pools7DAgo;
85
- }
86
- stateHuman(_) {
87
- return this.pools7DAgo.values().flatMap((p) => ({
88
- address: p.pool,
89
- version: this.version,
90
- dieselRate: p.dieselRate
91
- }));
92
- }
93
- get state() {
94
- return {
95
- pools7DAgo: this.pools7DAgo.asRecord()
96
- };
97
- }
98
- hydrate(state) {
99
- this.#pools7DAgo = new import_sdk.AddressMap(
100
- Object.entries(state.pools7DAgo),
101
- MAP_LABEL
102
- );
103
- }
104
- }
105
- // Annotate the CommonJS export names for ESM import in node:
106
- 0 && (module.exports = {
107
- Pools7DAgoPlugin
108
- });
@@ -1,90 +0,0 @@
1
- import { marketCompressorAbi } from "../../abi/compressors/marketCompressor.js";
2
- import {
3
- AddressMap,
4
- AP_MARKET_COMPRESSOR,
5
- BasePlugin,
6
- BLOCKS_PER_WEEK_BY_NETWORK,
7
- VERSION_RANGE_310
8
- } from "../../sdk/index.js";
9
- const MAP_LABEL = "pools7DAgo";
10
- class Pools7DAgoPlugin extends BasePlugin {
11
- #pools7DAgo;
12
- async load(force) {
13
- if (!force && this.loaded) {
14
- return this.state;
15
- }
16
- const targetBlock = this.sdk.currentBlock - BLOCKS_PER_WEEK_BY_NETWORK[this.sdk.networkType];
17
- const [marketCompressorAddress] = this.sdk.addressProvider.mustGetLatest(
18
- AP_MARKET_COMPRESSOR,
19
- VERSION_RANGE_310
20
- );
21
- this.sdk.logger?.debug(
22
- `loading pools 7d ago with market compressor ${marketCompressorAddress}`
23
- );
24
- const markets = this.sdk.marketRegister.markets;
25
- const resp = await this.client.multicall({
26
- allowFailure: true,
27
- contracts: markets.map(
28
- (m) => ({
29
- address: marketCompressorAddress,
30
- abi: marketCompressorAbi,
31
- functionName: "getPoolState",
32
- args: [m.pool.pool.address]
33
- })
34
- ),
35
- blockNumber: targetBlock > 0n ? targetBlock : void 0,
36
- batchSize: 0
37
- });
38
- this.#pools7DAgo = new AddressMap(void 0, MAP_LABEL);
39
- resp.forEach((r, index) => {
40
- const m = markets[index];
41
- const cfg = m.configurator.address;
42
- const pool = m.pool.pool.address;
43
- if (r.status === "success") {
44
- this.#pools7DAgo?.upsert(m.pool.pool.address, {
45
- dieselRate: r.result.dieselRate,
46
- pool
47
- });
48
- } else {
49
- this.sdk.logger?.error(
50
- `failed to load pools 7d ago for market configurator ${this.labelAddress(cfg)} and pool ${this.labelAddress(pool)}: ${r.error}`
51
- );
52
- }
53
- });
54
- return this.state;
55
- }
56
- get loaded() {
57
- return !!this.#pools7DAgo;
58
- }
59
- /**
60
- * Returns a map of pool addresses to minified pool 7d ago state
61
- * @throws if pool 7d ago plugin is not attached
62
- */
63
- get pools7DAgo() {
64
- if (!this.#pools7DAgo) {
65
- throw new Error("pools 7d ago plugin not attached");
66
- }
67
- return this.#pools7DAgo;
68
- }
69
- stateHuman(_) {
70
- return this.pools7DAgo.values().flatMap((p) => ({
71
- address: p.pool,
72
- version: this.version,
73
- dieselRate: p.dieselRate
74
- }));
75
- }
76
- get state() {
77
- return {
78
- pools7DAgo: this.pools7DAgo.asRecord()
79
- };
80
- }
81
- hydrate(state) {
82
- this.#pools7DAgo = new AddressMap(
83
- Object.entries(state.pools7DAgo),
84
- MAP_LABEL
85
- );
86
- }
87
- }
88
- export {
89
- Pools7DAgoPlugin
90
- };
@@ -1,2 +0,0 @@
1
- export * from "./Pools7DAgoPlugin.js";
2
- export * from "./types.js";