@gearbox-protocol/sdk 8.24.6 → 8.24.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.
@@ -120,7 +120,10 @@ class PriceOracleBaseContract extends import_base.BaseContract {
120
120
  const { to: priceFeed, callData, description } = tx.raw;
121
121
  const [token, reserve] = this.findTokenForPriceFeed(priceFeed);
122
122
  if (!token) {
123
+ const mains = this.mainPriceFeeds.values().map((v) => v.address);
124
+ const reserves = this.reservePriceFeeds.values().map((v) => v.address);
123
125
  this.logger?.debug(
126
+ { mainPriceFeeds: mains, reservePriceFeeds: reserves },
124
127
  `skipping onDemandPriceUpdate ${description}): token not found for price feed ${priceFeed} in oracle ${this.address}`
125
128
  );
126
129
  continue;
@@ -319,12 +322,12 @@ class PriceOracleBaseContract extends import_base.BaseContract {
319
322
  */
320
323
  findTokenForPriceFeed(priceFeed) {
321
324
  for (const [token, pf] of this.mainPriceFeeds.entries()) {
322
- if (pf.address === priceFeed) {
325
+ if ((0, import_utils.hexEq)(pf.address, priceFeed)) {
323
326
  return [token, false];
324
327
  }
325
328
  }
326
329
  for (const [token, pf] of this.reservePriceFeeds.entries()) {
327
- if (pf.address === priceFeed) {
330
+ if ((0, import_utils.hexEq)(pf.address, priceFeed)) {
328
331
  return [token, true];
329
332
  }
330
333
  }
@@ -28,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var extraAPY_exports = {};
30
30
  __export(extraAPY_exports, {
31
- GearboxRewardsExtraApy: () => GearboxRewardsExtraApy
31
+ GearboxRewardsExtraApy: () => GearboxRewardsExtraApy,
32
+ getKeyForPoolPointsInfo: () => getKeyForPoolPointsInfo
32
33
  });
33
34
  module.exports = __toCommonJS(extraAPY_exports);
34
35
  var import_axios = __toESM(require("axios"));
@@ -37,6 +38,18 @@ var import_constants = require("../../constants/index.js");
37
38
  var import_endpoint = require("../core/endpoint.js");
38
39
  var import_formatter = require("../utils/formatter.js");
39
40
  var import_math = require("../utils/math.js");
41
+ function getKeyForPoolPointsInfo(i) {
42
+ return [
43
+ i.pool,
44
+ i.token,
45
+ i.symbol,
46
+ i.duration,
47
+ i.name,
48
+ i.type,
49
+ i.estimation,
50
+ i.condition
51
+ ].join("-");
52
+ }
40
53
  class GearboxRewardsExtraApy {
41
54
  static async getTotalTokensOnProtocol({
42
55
  tokensToCheck,
@@ -76,7 +89,7 @@ class GearboxRewardsExtraApy {
76
89
  tokensList
77
90
  }) {
78
91
  const r = pools.reduce((acc, p) => {
79
- const pointsInfo = Object.values(poolRewards[p.address] || {});
92
+ const pointsInfo = poolRewards[p.address] || [];
80
93
  const poolPointsList = pointsInfo.reduce(
81
94
  (acc2, pointsInfo2) => {
82
95
  const { address: tokenAddress } = tokensList[pointsInfo2.token];
@@ -88,7 +101,11 @@ class GearboxRewardsExtraApy {
88
101
  pointsInfo2
89
102
  );
90
103
  if (points !== null) {
91
- acc2.push({ balance: points, token: tokenAddress });
104
+ acc2.push({
105
+ key: getKeyForPoolPointsInfo(pointsInfo2),
106
+ info: pointsInfo2,
107
+ points
108
+ });
92
109
  }
93
110
  return acc2;
94
111
  },
@@ -100,19 +117,21 @@ class GearboxRewardsExtraApy {
100
117
  return r;
101
118
  }
102
119
  static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
103
- if (!tokenBalanceInPool && pointsInfo.estimation === "relative")
104
- return null;
105
120
  if (pool.expectedLiquidity <= 0) return 0n;
121
+ if (pointsInfo.estimation === "relative" && !tokenBalanceInPool)
122
+ return null;
106
123
  const { decimals = 18 } = tokensList[pointsInfo.token] || {};
107
124
  const targetFactor = 10n ** BigInt(decimals);
125
+ const defaultPoints = pointsInfo.amount * targetFactor / import_constants.PERCENTAGE_FACTOR;
126
+ if (pointsInfo.estimation === "absolute") return defaultPoints;
108
127
  const { decimals: underlyingDecimals = 18 } = tokensList[pool.underlyingToken] || {};
109
128
  const underlyingFactor = 10n ** BigInt(underlyingDecimals);
110
- const defaultPoints = pointsInfo.amount * targetFactor / import_constants.PERCENTAGE_FACTOR;
111
- const points = pointsInfo.estimation === "absolute" ? defaultPoints : (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
129
+ const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
112
130
  return import_math.BigIntMath.min(points, defaultPoints);
113
131
  }
114
132
  }
115
133
  // Annotate the CommonJS export names for ESM import in node:
116
134
  0 && (module.exports = {
117
- GearboxRewardsExtraApy
135
+ GearboxRewardsExtraApy,
136
+ getKeyForPoolPointsInfo
118
137
  });
@@ -8,7 +8,7 @@ import {
8
8
  isV300,
9
9
  VERSION_RANGE_310
10
10
  } from "../../constants/index.js";
11
- import { AddressMap, formatBN } from "../../utils/index.js";
11
+ import { AddressMap, formatBN, hexEq } from "../../utils/index.js";
12
12
  import { PriceFeedRef } from "../pricefeeds/index.js";
13
13
  import PriceFeedAnswerMap from "./PriceFeedAnswerMap.js";
14
14
  const ZERO_PRICE_FEED = stringToHex("PRICE_FEED::ZERO", { size: 32 });
@@ -91,7 +91,10 @@ class PriceOracleBaseContract extends BaseContract {
91
91
  const { to: priceFeed, callData, description } = tx.raw;
92
92
  const [token, reserve] = this.findTokenForPriceFeed(priceFeed);
93
93
  if (!token) {
94
+ const mains = this.mainPriceFeeds.values().map((v) => v.address);
95
+ const reserves = this.reservePriceFeeds.values().map((v) => v.address);
94
96
  this.logger?.debug(
97
+ { mainPriceFeeds: mains, reservePriceFeeds: reserves },
95
98
  `skipping onDemandPriceUpdate ${description}): token not found for price feed ${priceFeed} in oracle ${this.address}`
96
99
  );
97
100
  continue;
@@ -290,12 +293,12 @@ class PriceOracleBaseContract extends BaseContract {
290
293
  */
291
294
  findTokenForPriceFeed(priceFeed) {
292
295
  for (const [token, pf] of this.mainPriceFeeds.entries()) {
293
- if (pf.address === priceFeed) {
296
+ if (hexEq(pf.address, priceFeed)) {
294
297
  return [token, false];
295
298
  }
296
299
  }
297
300
  for (const [token, pf] of this.reservePriceFeeds.entries()) {
298
- if (pf.address === priceFeed) {
301
+ if (hexEq(pf.address, priceFeed)) {
299
302
  return [token, true];
300
303
  }
301
304
  }
@@ -4,6 +4,18 @@ import { PERCENTAGE_FACTOR } from "../../constants/index.js";
4
4
  import { GearboxBackendApi } from "../core/endpoint.js";
5
5
  import { toBN } from "../utils/formatter.js";
6
6
  import { BigIntMath } from "../utils/math.js";
7
+ function getKeyForPoolPointsInfo(i) {
8
+ return [
9
+ i.pool,
10
+ i.token,
11
+ i.symbol,
12
+ i.duration,
13
+ i.name,
14
+ i.type,
15
+ i.estimation,
16
+ i.condition
17
+ ].join("-");
18
+ }
7
19
  class GearboxRewardsExtraApy {
8
20
  static async getTotalTokensOnProtocol({
9
21
  tokensToCheck,
@@ -43,7 +55,7 @@ class GearboxRewardsExtraApy {
43
55
  tokensList
44
56
  }) {
45
57
  const r = pools.reduce((acc, p) => {
46
- const pointsInfo = Object.values(poolRewards[p.address] || {});
58
+ const pointsInfo = poolRewards[p.address] || [];
47
59
  const poolPointsList = pointsInfo.reduce(
48
60
  (acc2, pointsInfo2) => {
49
61
  const { address: tokenAddress } = tokensList[pointsInfo2.token];
@@ -55,7 +67,11 @@ class GearboxRewardsExtraApy {
55
67
  pointsInfo2
56
68
  );
57
69
  if (points !== null) {
58
- acc2.push({ balance: points, token: tokenAddress });
70
+ acc2.push({
71
+ key: getKeyForPoolPointsInfo(pointsInfo2),
72
+ info: pointsInfo2,
73
+ points
74
+ });
59
75
  }
60
76
  return acc2;
61
77
  },
@@ -67,18 +83,20 @@ class GearboxRewardsExtraApy {
67
83
  return r;
68
84
  }
69
85
  static getPoolTokenPoints(tokenBalanceInPool, pool, tokensList, pointsInfo) {
70
- if (!tokenBalanceInPool && pointsInfo.estimation === "relative")
71
- return null;
72
86
  if (pool.expectedLiquidity <= 0) return 0n;
87
+ if (pointsInfo.estimation === "relative" && !tokenBalanceInPool)
88
+ return null;
73
89
  const { decimals = 18 } = tokensList[pointsInfo.token] || {};
74
90
  const targetFactor = 10n ** BigInt(decimals);
91
+ const defaultPoints = pointsInfo.amount * targetFactor / PERCENTAGE_FACTOR;
92
+ if (pointsInfo.estimation === "absolute") return defaultPoints;
75
93
  const { decimals: underlyingDecimals = 18 } = tokensList[pool.underlyingToken] || {};
76
94
  const underlyingFactor = 10n ** BigInt(underlyingDecimals);
77
- const defaultPoints = pointsInfo.amount * targetFactor / PERCENTAGE_FACTOR;
78
- const points = pointsInfo.estimation === "absolute" ? defaultPoints : (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
95
+ const points = (tokenBalanceInPool?.balance || 0n) * defaultPoints / (pool.expectedLiquidity * targetFactor / underlyingFactor);
79
96
  return BigIntMath.min(points, defaultPoints);
80
97
  }
81
98
  }
82
99
  export {
83
- GearboxRewardsExtraApy
100
+ GearboxRewardsExtraApy,
101
+ getKeyForPoolPointsInfo
84
102
  };
@@ -16,7 +16,7 @@ export interface PoolPointsInfo {
16
16
  }
17
17
  type PartialPool = Pick<PoolData_Legacy, "expectedLiquidity" | "underlyingToken" | "address">;
18
18
  export interface GetPointsByPoolProps {
19
- poolRewards: Record<Address, Record<Address, PoolPointsInfo>>;
19
+ poolRewards: Record<Address, Array<PoolPointsInfo>>;
20
20
  totalTokenBalances: Record<Address, Asset>;
21
21
  pools: Array<PartialPool>;
22
22
  tokensList: Record<Address, TokenData>;
@@ -26,10 +26,16 @@ export interface GetTotalTokensOnProtocolProps {
26
26
  tokensList: Record<Address, TokenData>;
27
27
  network: NetworkType;
28
28
  }
29
+ export type PoolPointsBase = Record<Address, Array<{
30
+ key: string;
31
+ info: PoolPointsInfo;
32
+ points: bigint;
33
+ }>>;
34
+ export declare function getKeyForPoolPointsInfo(i: PoolPointsInfo): string;
29
35
  export declare class GearboxRewardsExtraApy {
30
36
  static getTotalTokensOnProtocol({ tokensToCheck, tokensList, network, }: GetTotalTokensOnProtocolProps): Promise<[`0x${string}`, PromiseSettledResult<Asset>][]>;
31
37
  private static getTokenTotal;
32
- static getPointsByPool({ poolRewards, totalTokenBalances, pools, tokensList, }: GetPointsByPoolProps): Record<`0x${string}`, Asset[]>;
38
+ static getPointsByPool({ poolRewards, totalTokenBalances, pools, tokensList, }: GetPointsByPoolProps): PoolPointsBase;
33
39
  private static getPoolTokenPoints;
34
40
  }
35
41
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "8.24.6",
3
+ "version": "8.24.8",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",