@gearbox-protocol/sdk 14.6.0 → 14.7.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 (32) hide show
  1. package/dist/cjs/common-utils/utils/strategies/index.js +2 -0
  2. package/dist/cjs/common-utils/utils/strategies/points/get-complex-points-list.js +38 -0
  3. package/dist/cjs/common-utils/utils/strategies/points/get-points-info.js +43 -0
  4. package/dist/cjs/common-utils/utils/strategies/points/get-points-rates.js +33 -0
  5. package/dist/cjs/common-utils/utils/strategies/points/get-strategy-points.js +81 -0
  6. package/dist/cjs/common-utils/utils/strategies/points/index.js +28 -0
  7. package/dist/cjs/common-utils/utils/strategies/strategy-info/get-strategy-info-core.js +16 -4
  8. package/dist/cjs/common-utils/utils/strategies/strategy-info/get-strategy-max-apy.js +9 -15
  9. package/dist/cjs/common-utils/utils/strategies/types/index.js +2 -0
  10. package/dist/cjs/common-utils/utils/strategies/types/points-slices.js +16 -0
  11. package/dist/esm/common-utils/utils/strategies/index.js +1 -0
  12. package/dist/esm/common-utils/utils/strategies/points/get-complex-points-list.js +14 -0
  13. package/dist/esm/common-utils/utils/strategies/points/get-points-info.js +19 -0
  14. package/dist/esm/common-utils/utils/strategies/points/get-points-rates.js +9 -0
  15. package/dist/esm/common-utils/utils/strategies/points/get-strategy-points.js +57 -0
  16. package/dist/esm/common-utils/utils/strategies/points/index.js +4 -0
  17. package/dist/esm/common-utils/utils/strategies/strategy-info/get-strategy-info-core.js +16 -4
  18. package/dist/esm/common-utils/utils/strategies/strategy-info/get-strategy-max-apy.js +9 -15
  19. package/dist/esm/common-utils/utils/strategies/types/index.js +1 -0
  20. package/dist/esm/common-utils/utils/strategies/types/points-slices.js +0 -0
  21. package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +1 -1
  22. package/dist/types/common-utils/utils/strategies/index.d.ts +1 -0
  23. package/dist/types/common-utils/utils/strategies/points/get-complex-points-list.d.ts +3 -0
  24. package/dist/types/common-utils/utils/strategies/points/get-points-info.d.ts +8 -0
  25. package/dist/types/common-utils/utils/strategies/points/get-points-rates.d.ts +2 -0
  26. package/dist/types/common-utils/utils/strategies/points/get-strategy-points.d.ts +16 -0
  27. package/dist/types/common-utils/utils/strategies/points/index.d.ts +4 -0
  28. package/dist/types/common-utils/utils/strategies/strategy-info/get-strategy-max-apy.d.ts +2 -2
  29. package/dist/types/common-utils/utils/strategies/strategy-info/types.d.ts +1 -0
  30. package/dist/types/common-utils/utils/strategies/types/index.d.ts +1 -0
  31. package/dist/types/common-utils/utils/strategies/types/points-slices.d.ts +20 -0
  32. package/package.json +1 -1
@@ -20,6 +20,7 @@ __reExport(strategies_exports, require("./credit-managers/index.js"), module.exp
20
20
  __reExport(strategies_exports, require("./eligibility/index.js"), module.exports);
21
21
  __reExport(strategies_exports, require("./leverage/index.js"), module.exports);
22
22
  __reExport(strategies_exports, require("./lists/index.js"), module.exports);
23
+ __reExport(strategies_exports, require("./points/index.js"), module.exports);
23
24
  __reExport(strategies_exports, require("./sort-strategy-cms-by-availability/index.js"), module.exports);
24
25
  __reExport(strategies_exports, require("./strategy-info/index.js"), module.exports);
25
26
  __reExport(strategies_exports, require("./strategy-state/index.js"), module.exports);
@@ -32,6 +33,7 @@ __reExport(strategies_exports, require("./types.js"), module.exports);
32
33
  ...require("./eligibility/index.js"),
33
34
  ...require("./leverage/index.js"),
34
35
  ...require("./lists/index.js"),
36
+ ...require("./points/index.js"),
35
37
  ...require("./sort-strategy-cms-by-availability/index.js"),
36
38
  ...require("./strategy-info/index.js"),
37
39
  ...require("./strategy-state/index.js"),
@@ -0,0 +1,38 @@
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 get_complex_points_list_exports = {};
20
+ __export(get_complex_points_list_exports, {
21
+ getComplexPointsList: () => getComplexPointsList
22
+ });
23
+ module.exports = __toCommonJS(get_complex_points_list_exports);
24
+ var import_mappers = require("../../../../sdk/utils/mappers.js");
25
+ function getComplexPointsList(baseList, extraList, pool) {
26
+ if (!pool) return baseList;
27
+ const poolExtra = extraList?.[pool];
28
+ if (!poolExtra) return baseList;
29
+ const baseCopy = { ...baseList };
30
+ import_mappers.TypedObjectUtils.entries(poolExtra).forEach(([token, extra]) => {
31
+ baseCopy[token] = extra;
32
+ });
33
+ return baseCopy;
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ getComplexPointsList
38
+ });
@@ -0,0 +1,43 @@
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 get_points_info_exports = {};
20
+ __export(get_points_info_exports, {
21
+ getPointsInfo: () => getPointsInfo
22
+ });
23
+ module.exports = __toCommonJS(get_points_info_exports);
24
+ function getPointsInfo({
25
+ chainId,
26
+ pointsList,
27
+ token,
28
+ creditManagers
29
+ }) {
30
+ if (chainId === void 0 || !pointsList || !token) return void 0;
31
+ const info = pointsList[token];
32
+ const r = info ? {
33
+ ...info,
34
+ debtRewards: creditManagers ? info.debtRewards?.filter(
35
+ (r2) => r2.cm === "any" || creditManagers[r2.cm]
36
+ ) : info.debtRewards
37
+ } : info;
38
+ return r;
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ getPointsInfo
43
+ });
@@ -0,0 +1,33 @@
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 get_points_rates_exports = {};
20
+ __export(get_points_rates_exports, {
21
+ getPointsRates: () => getPointsRates
22
+ });
23
+ module.exports = __toCommonJS(get_points_rates_exports);
24
+ var import_math = require("../../../../sdk/constants/math.js");
25
+ function getPointsRates(rewards, leverage) {
26
+ return rewards.map(
27
+ (r) => r.multiplier === "soon" ? r.multiplier : leverage * r.multiplier / import_math.LEVERAGE_DECIMALS
28
+ );
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ getPointsRates
33
+ });
@@ -0,0 +1,81 @@
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 get_strategy_points_exports = {};
20
+ __export(get_strategy_points_exports, {
21
+ getStrategyPoints: () => getStrategyPoints
22
+ });
23
+ module.exports = __toCommonJS(get_strategy_points_exports);
24
+ var import_leverage = require("../leverage/index.js");
25
+ var import_types = require("../types.js");
26
+ var import_get_complex_points_list = require("./get-complex-points-list.js");
27
+ var import_get_points_info = require("./get-points-info.js");
28
+ var import_get_points_rates = require("./get-points-rates.js");
29
+ const EMPTY_CHAIN_ID = 0;
30
+ const EMPTY_ARRAY = [];
31
+ function getStrategyPoints({
32
+ strategy,
33
+ info,
34
+ strategyCreditManagers,
35
+ apyListByNetwork
36
+ }) {
37
+ const { maxLeverage = 0n, minCreditManager } = info || {};
38
+ const chainId = strategy.chainId;
39
+ const apySnapshotForChain = apyListByNetwork?.[chainId || EMPTY_CHAIN_ID];
40
+ const cmPointsList = (0, import_get_complex_points_list.getComplexPointsList)(
41
+ apySnapshotForChain?.pointsList,
42
+ apySnapshotForChain?.extraCollateralPointsList,
43
+ minCreditManager?.pool ?? import_types.EMPTY_ADDRESS
44
+ );
45
+ const pointsInfo = (0, import_get_points_info.getPointsInfo)({
46
+ chainId,
47
+ pointsList: cmPointsList,
48
+ token: strategy.tokenOutAddress,
49
+ creditManagers: minCreditManager ? { [minCreditManager.address]: minCreditManager } : void 0
50
+ });
51
+ const debtPointsList = (0, import_get_complex_points_list.getComplexPointsList)(
52
+ apySnapshotForChain?.pointsList,
53
+ apySnapshotForChain?.extraCollateralPointsList,
54
+ import_types.EMPTY_ADDRESS
55
+ );
56
+ const pointsInfoDebt = (0, import_get_points_info.getPointsInfo)({
57
+ chainId,
58
+ pointsList: debtPointsList,
59
+ token: strategy.tokenOutAddress,
60
+ creditManagers: strategyCreditManagers
61
+ });
62
+ const { rewards = EMPTY_ARRAY } = pointsInfo || {};
63
+ const { debtRewards = EMPTY_ARRAY } = pointsInfoDebt || {};
64
+ const rewardRates = (0, import_get_points_rates.getPointsRates)(rewards, BigInt(maxLeverage));
65
+ const debtRewardRates = (0, import_get_points_rates.getPointsRates)(
66
+ debtRewards,
67
+ (0, import_leverage.getFactorFromLeverage)(maxLeverage)
68
+ );
69
+ return {
70
+ pointsInfo,
71
+ pointsInfoDebt,
72
+ rewards,
73
+ debtRewards,
74
+ rewardRates,
75
+ debtRewardRates
76
+ };
77
+ }
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ getStrategyPoints
81
+ });
@@ -0,0 +1,28 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var points_exports = {};
17
+ module.exports = __toCommonJS(points_exports);
18
+ __reExport(points_exports, require("./get-complex-points-list.js"), module.exports);
19
+ __reExport(points_exports, require("./get-points-info.js"), module.exports);
20
+ __reExport(points_exports, require("./get-points-rates.js"), module.exports);
21
+ __reExport(points_exports, require("./get-strategy-points.js"), module.exports);
22
+ // Annotate the CommonJS export names for ESM import in node:
23
+ 0 && (module.exports = {
24
+ ...require("./get-complex-points-list.js"),
25
+ ...require("./get-points-info.js"),
26
+ ...require("./get-points-rates.js"),
27
+ ...require("./get-strategy-points.js")
28
+ });
@@ -21,6 +21,7 @@ __export(get_strategy_info_core_exports, {
21
21
  getStrategyInfoCore: () => getStrategyInfoCore
22
22
  });
23
23
  module.exports = __toCommonJS(get_strategy_info_core_exports);
24
+ var import__ = require("../../index.js");
24
25
  var import_price_math = require("../../price-math.js");
25
26
  var import_leverage = require("../leverage/index.js");
26
27
  var import_sort_strategy_cms_by_availability = require("../sort-strategy-cms-by-availability/index.js");
@@ -65,8 +66,8 @@ function getStrategyInfoCore({
65
66
  bonusAPY,
66
67
  totalMaxApy = 0,
67
68
  maxLeverage = 0n,
68
- baseBorrowRate = 0,
69
- quotaRateMin = 0n
69
+ effectiveBaseRate = 0,
70
+ effectiveQuotaRate = 0n
70
71
  } = (0, import_get_strategy_max_apy.getStrategyMaxAPY)(
71
72
  targetTokenAddress,
72
73
  minCreditManager,
@@ -86,14 +87,25 @@ function getStrategyInfoCore({
86
87
  availableToBorrow,
87
88
  underlyingDecimals
88
89
  );
89
- const r = BigInt(baseBorrowRate) * (0, import_leverage.getFactorFromLeverage)(maxLeverage) / maxLeverage;
90
- const qr = quotaRateMin;
90
+ const r = BigInt(effectiveBaseRate) * (0, import_leverage.getFactorFromLeverage)(maxLeverage) / maxLeverage;
91
+ const qr = effectiveQuotaRate;
91
92
  const totalBorrowRate = Number(r + qr);
93
+ const baseQuotaRateWithFee = (0, import__.getSingleQuotaBorrowRate)({
94
+ quotaRates: minCreditManager?.quotas || {},
95
+ feeInterest: minCreditManager?.feeInterest || 0,
96
+ quotas: {
97
+ [targetTokenAddress]: {
98
+ token: targetTokenAddress,
99
+ balance: 1n
100
+ }
101
+ }
102
+ });
92
103
  return {
93
104
  maxLeverage,
94
105
  maxAPY: totalMaxApy,
95
106
  bonusAPY,
96
107
  totalBorrowRate,
108
+ baseQuotaRateWithFee,
97
109
  availableToBorrowMoney,
98
110
  minCreditManager
99
111
  };
@@ -35,27 +35,21 @@ function getStrategyMaxAPY(targetToken, cm, apyListByNetwork, slippage, quotaRes
35
35
  apyListByNetwork?.[cm.chainId]?.extraCollateralAPYList,
36
36
  cm.pool
37
37
  );
38
- const baseRateWithFee = (0, import_calculate_effective_borrow_rate.calculateEffectiveBorrowRate)({
38
+ const effectiveBaseRate = (0, import_calculate_effective_borrow_rate.calculateEffectiveBorrowRate)({
39
39
  underlyingTokenAddress: cm.underlyingToken,
40
40
  baseRateWithFee: cm.baseBorrowRate,
41
41
  apyList: apyRecord
42
42
  });
43
43
  const lt = cm.liquidationThresholds[targetToken] || 0n;
44
44
  const feeInterest = cm.feeInterest;
45
- const tokenQuota = cm.quotas[targetToken] || {
46
- token: targetToken,
47
- rate: 0n,
48
- quotaIncreaseFee: 0n,
49
- totalQuoted: 0n,
50
- limit: 0n,
51
- isActive: true
52
- };
45
+ const tokenQuota = cm.quotas[targetToken];
53
46
  const qRate = (tokenQuota?.rate || 0n) * lt / import_sdk.PERCENTAGE_FACTOR;
54
47
  const qRate_reserve = qRate * (import_sdk.PERCENTAGE_FACTOR + (0, import_sdk.toBigInt)(quotaReserve)) / import_sdk.PERCENTAGE_FACTOR;
55
- const quotaRateWithFee = (0, import_get_single_quota_borrow_rate.getSingleQuotaBorrowRate)({
48
+ const effectiveQuotaRate = (0, import_get_single_quota_borrow_rate.getSingleQuotaBorrowRate)({
56
49
  quotaRates: {
57
50
  [targetToken]: {
58
51
  ...tokenQuota,
52
+ isActive: tokenQuota?.isActive ?? true,
59
53
  rate: qRate_reserve
60
54
  }
61
55
  },
@@ -79,20 +73,20 @@ function getStrategyMaxAPY(targetToken, cm, apyListByNetwork, slippage, quotaRes
79
73
  const maxAPY = apyRecord ? (0, import_max_apy_formula.maxAPYFormula)({
80
74
  apy,
81
75
  leverage,
82
- baseRateWithFee,
83
- quotaRateWithFee: Number(quotaRateWithFee)
76
+ baseRateWithFee: effectiveBaseRate,
77
+ quotaRateWithFee: Number(effectiveQuotaRate)
84
78
  }) : void 0;
85
79
  const bonusAPY = import_bonus_apy_from_points.BONUS_APY_FROM_POINTS[targetToken];
86
80
  const bonusAPYTotal = BigInt(bonusAPY?.value || 0) * leverage / import_sdk.LEVERAGE_DECIMALS;
87
81
  const totalMaxApy = (maxAPY || 0) + Number(bonusAPYTotal);
88
- const totalBorrowRate = baseRateWithFee + Number(quotaRateWithFee);
82
+ const totalBorrowRate = effectiveBaseRate + Number(effectiveQuotaRate);
89
83
  return {
90
84
  totalMaxApy,
91
85
  bonusAPY,
92
86
  maxAPY: maxAPY || 0,
93
87
  maxLeverage: leverage,
94
- quotaRateMin: quotaRateWithFee,
95
- baseBorrowRate: baseRateWithFee,
88
+ effectiveBaseRate,
89
+ effectiveQuotaRate,
96
90
  totalBorrowRate
97
91
  };
98
92
  }
@@ -20,6 +20,7 @@ __reExport(types_exports, require("./constants.js"), module.exports);
20
20
  __reExport(types_exports, require("./credit-manager-data-legacy.js"), module.exports);
21
21
  __reExport(types_exports, require("./curator-filter.js"), module.exports);
22
22
  __reExport(types_exports, require("./legacy-strategy-data-source.js"), module.exports);
23
+ __reExport(types_exports, require("./points-slices.js"), module.exports);
23
24
  __reExport(types_exports, require("./sdk-state.js"), module.exports);
24
25
  __reExport(types_exports, require("./strategies-cm-list.js"), module.exports);
25
26
  __reExport(types_exports, require("./strategy.js"), module.exports);
@@ -32,6 +33,7 @@ __reExport(types_exports, require("./targetable.js"), module.exports);
32
33
  ...require("./credit-manager-data-legacy.js"),
33
34
  ...require("./curator-filter.js"),
34
35
  ...require("./legacy-strategy-data-source.js"),
36
+ ...require("./points-slices.js"),
35
37
  ...require("./sdk-state.js"),
36
38
  ...require("./strategies-cm-list.js"),
37
39
  ...require("./strategy.js"),
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var points_slices_exports = {};
16
+ module.exports = __toCommonJS(points_slices_exports);
@@ -3,6 +3,7 @@ export * from "./credit-managers/index.js";
3
3
  export * from "./eligibility/index.js";
4
4
  export * from "./leverage/index.js";
5
5
  export * from "./lists/index.js";
6
+ export * from "./points/index.js";
6
7
  export * from "./sort-strategy-cms-by-availability/index.js";
7
8
  export * from "./strategy-info/index.js";
8
9
  export * from "./strategy-state/index.js";
@@ -0,0 +1,14 @@
1
+ import { TypedObjectUtils } from "../../../../sdk/utils/mappers.js";
2
+ function getComplexPointsList(baseList, extraList, pool) {
3
+ if (!pool) return baseList;
4
+ const poolExtra = extraList?.[pool];
5
+ if (!poolExtra) return baseList;
6
+ const baseCopy = { ...baseList };
7
+ TypedObjectUtils.entries(poolExtra).forEach(([token, extra]) => {
8
+ baseCopy[token] = extra;
9
+ });
10
+ return baseCopy;
11
+ }
12
+ export {
13
+ getComplexPointsList
14
+ };
@@ -0,0 +1,19 @@
1
+ function getPointsInfo({
2
+ chainId,
3
+ pointsList,
4
+ token,
5
+ creditManagers
6
+ }) {
7
+ if (chainId === void 0 || !pointsList || !token) return void 0;
8
+ const info = pointsList[token];
9
+ const r = info ? {
10
+ ...info,
11
+ debtRewards: creditManagers ? info.debtRewards?.filter(
12
+ (r2) => r2.cm === "any" || creditManagers[r2.cm]
13
+ ) : info.debtRewards
14
+ } : info;
15
+ return r;
16
+ }
17
+ export {
18
+ getPointsInfo
19
+ };
@@ -0,0 +1,9 @@
1
+ import { LEVERAGE_DECIMALS } from "../../../../sdk/constants/math.js";
2
+ function getPointsRates(rewards, leverage) {
3
+ return rewards.map(
4
+ (r) => r.multiplier === "soon" ? r.multiplier : leverage * r.multiplier / LEVERAGE_DECIMALS
5
+ );
6
+ }
7
+ export {
8
+ getPointsRates
9
+ };
@@ -0,0 +1,57 @@
1
+ import { getFactorFromLeverage } from "../leverage/index.js";
2
+ import { EMPTY_ADDRESS } from "../types.js";
3
+ import { getComplexPointsList } from "./get-complex-points-list.js";
4
+ import { getPointsInfo } from "./get-points-info.js";
5
+ import { getPointsRates } from "./get-points-rates.js";
6
+ const EMPTY_CHAIN_ID = 0;
7
+ const EMPTY_ARRAY = [];
8
+ function getStrategyPoints({
9
+ strategy,
10
+ info,
11
+ strategyCreditManagers,
12
+ apyListByNetwork
13
+ }) {
14
+ const { maxLeverage = 0n, minCreditManager } = info || {};
15
+ const chainId = strategy.chainId;
16
+ const apySnapshotForChain = apyListByNetwork?.[chainId || EMPTY_CHAIN_ID];
17
+ const cmPointsList = getComplexPointsList(
18
+ apySnapshotForChain?.pointsList,
19
+ apySnapshotForChain?.extraCollateralPointsList,
20
+ minCreditManager?.pool ?? EMPTY_ADDRESS
21
+ );
22
+ const pointsInfo = getPointsInfo({
23
+ chainId,
24
+ pointsList: cmPointsList,
25
+ token: strategy.tokenOutAddress,
26
+ creditManagers: minCreditManager ? { [minCreditManager.address]: minCreditManager } : void 0
27
+ });
28
+ const debtPointsList = getComplexPointsList(
29
+ apySnapshotForChain?.pointsList,
30
+ apySnapshotForChain?.extraCollateralPointsList,
31
+ EMPTY_ADDRESS
32
+ );
33
+ const pointsInfoDebt = getPointsInfo({
34
+ chainId,
35
+ pointsList: debtPointsList,
36
+ token: strategy.tokenOutAddress,
37
+ creditManagers: strategyCreditManagers
38
+ });
39
+ const { rewards = EMPTY_ARRAY } = pointsInfo || {};
40
+ const { debtRewards = EMPTY_ARRAY } = pointsInfoDebt || {};
41
+ const rewardRates = getPointsRates(rewards, BigInt(maxLeverage));
42
+ const debtRewardRates = getPointsRates(
43
+ debtRewards,
44
+ getFactorFromLeverage(maxLeverage)
45
+ );
46
+ return {
47
+ pointsInfo,
48
+ pointsInfoDebt,
49
+ rewards,
50
+ debtRewards,
51
+ rewardRates,
52
+ debtRewardRates
53
+ };
54
+ }
55
+ export {
56
+ getStrategyPoints
57
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./get-complex-points-list.js";
2
+ export * from "./get-points-info.js";
3
+ export * from "./get-points-rates.js";
4
+ export * from "./get-strategy-points.js";
@@ -1,3 +1,4 @@
1
+ import { getSingleQuotaBorrowRate } from "../../index.js";
1
2
  import { PriceUtils } from "../../price-math.js";
2
3
  import { getFactorFromLeverage } from "../leverage/index.js";
3
4
  import { sortStrategyCMsByAvailability } from "../sort-strategy-cms-by-availability/index.js";
@@ -42,8 +43,8 @@ function getStrategyInfoCore({
42
43
  bonusAPY,
43
44
  totalMaxApy = 0,
44
45
  maxLeverage = 0n,
45
- baseBorrowRate = 0,
46
- quotaRateMin = 0n
46
+ effectiveBaseRate = 0,
47
+ effectiveQuotaRate = 0n
47
48
  } = getStrategyMaxAPY(
48
49
  targetTokenAddress,
49
50
  minCreditManager,
@@ -63,14 +64,25 @@ function getStrategyInfoCore({
63
64
  availableToBorrow,
64
65
  underlyingDecimals
65
66
  );
66
- const r = BigInt(baseBorrowRate) * getFactorFromLeverage(maxLeverage) / maxLeverage;
67
- const qr = quotaRateMin;
67
+ const r = BigInt(effectiveBaseRate) * getFactorFromLeverage(maxLeverage) / maxLeverage;
68
+ const qr = effectiveQuotaRate;
68
69
  const totalBorrowRate = Number(r + qr);
70
+ const baseQuotaRateWithFee = getSingleQuotaBorrowRate({
71
+ quotaRates: minCreditManager?.quotas || {},
72
+ feeInterest: minCreditManager?.feeInterest || 0,
73
+ quotas: {
74
+ [targetTokenAddress]: {
75
+ token: targetTokenAddress,
76
+ balance: 1n
77
+ }
78
+ }
79
+ });
69
80
  return {
70
81
  maxLeverage,
71
82
  maxAPY: totalMaxApy,
72
83
  bonusAPY,
73
84
  totalBorrowRate,
85
+ baseQuotaRateWithFee,
74
86
  availableToBorrowMoney,
75
87
  minCreditManager
76
88
  };
@@ -19,27 +19,21 @@ function getStrategyMaxAPY(targetToken, cm, apyListByNetwork, slippage, quotaRes
19
19
  apyListByNetwork?.[cm.chainId]?.extraCollateralAPYList,
20
20
  cm.pool
21
21
  );
22
- const baseRateWithFee = calculateEffectiveBorrowRate({
22
+ const effectiveBaseRate = calculateEffectiveBorrowRate({
23
23
  underlyingTokenAddress: cm.underlyingToken,
24
24
  baseRateWithFee: cm.baseBorrowRate,
25
25
  apyList: apyRecord
26
26
  });
27
27
  const lt = cm.liquidationThresholds[targetToken] || 0n;
28
28
  const feeInterest = cm.feeInterest;
29
- const tokenQuota = cm.quotas[targetToken] || {
30
- token: targetToken,
31
- rate: 0n,
32
- quotaIncreaseFee: 0n,
33
- totalQuoted: 0n,
34
- limit: 0n,
35
- isActive: true
36
- };
29
+ const tokenQuota = cm.quotas[targetToken];
37
30
  const qRate = (tokenQuota?.rate || 0n) * lt / PERCENTAGE_FACTOR;
38
31
  const qRate_reserve = qRate * (PERCENTAGE_FACTOR + toBigInt(quotaReserve)) / PERCENTAGE_FACTOR;
39
- const quotaRateWithFee = getSingleQuotaBorrowRate({
32
+ const effectiveQuotaRate = getSingleQuotaBorrowRate({
40
33
  quotaRates: {
41
34
  [targetToken]: {
42
35
  ...tokenQuota,
36
+ isActive: tokenQuota?.isActive ?? true,
43
37
  rate: qRate_reserve
44
38
  }
45
39
  },
@@ -63,20 +57,20 @@ function getStrategyMaxAPY(targetToken, cm, apyListByNetwork, slippage, quotaRes
63
57
  const maxAPY = apyRecord ? maxAPYFormula({
64
58
  apy,
65
59
  leverage,
66
- baseRateWithFee,
67
- quotaRateWithFee: Number(quotaRateWithFee)
60
+ baseRateWithFee: effectiveBaseRate,
61
+ quotaRateWithFee: Number(effectiveQuotaRate)
68
62
  }) : void 0;
69
63
  const bonusAPY = BONUS_APY_FROM_POINTS[targetToken];
70
64
  const bonusAPYTotal = BigInt(bonusAPY?.value || 0) * leverage / LEVERAGE_DECIMALS;
71
65
  const totalMaxApy = (maxAPY || 0) + Number(bonusAPYTotal);
72
- const totalBorrowRate = baseRateWithFee + Number(quotaRateWithFee);
66
+ const totalBorrowRate = effectiveBaseRate + Number(effectiveQuotaRate);
73
67
  return {
74
68
  totalMaxApy,
75
69
  bonusAPY,
76
70
  maxAPY: maxAPY || 0,
77
71
  maxLeverage: leverage,
78
- quotaRateMin: quotaRateWithFee,
79
- baseBorrowRate: baseRateWithFee,
72
+ effectiveBaseRate,
73
+ effectiveQuotaRate,
80
74
  totalBorrowRate
81
75
  };
82
76
  }
@@ -3,6 +3,7 @@ export * from "./constants.js";
3
3
  export * from "./credit-manager-data-legacy.js";
4
4
  export * from "./curator-filter.js";
5
5
  export * from "./legacy-strategy-data-source.js";
6
+ export * from "./points-slices.js";
6
7
  export * from "./sdk-state.js";
7
8
  export * from "./strategies-cm-list.js";
8
9
  export * from "./strategy.js";
@@ -3,7 +3,7 @@ import type { Asset } from "../../../sdk/index.js";
3
3
  import type { QuotaInfoSlice } from "./types.js";
4
4
  export interface CalcQuotaBorrowRateProps {
5
5
  quotas: Record<Address, Asset>;
6
- quotaRates: Record<Address, QuotaInfoSlice>;
6
+ quotaRates: Record<Address, QuotaInfoSlice | undefined>;
7
7
  }
8
8
  /**
9
9
  * Aggregates weighted quota borrow rate exposure across active quotas.
@@ -3,6 +3,7 @@ export * from "./credit-managers/index.js";
3
3
  export * from "./eligibility/index.js";
4
4
  export * from "./leverage/index.js";
5
5
  export * from "./lists/index.js";
6
+ export * from "./points/index.js";
6
7
  export * from "./sort-strategy-cms-by-availability/index.js";
7
8
  export * from "./strategy-info/index.js";
8
9
  export * from "./strategy-state/index.js";
@@ -0,0 +1,3 @@
1
+ import type { Address } from "viem";
2
+ import type { LocalPointsInfo } from "../types.js";
3
+ export declare function getComplexPointsList<T extends Address | undefined = undefined>(baseList: Record<Address, LocalPointsInfo> | undefined, extraList: Record<Address, Record<Address, LocalPointsInfo>> | undefined, pool: T | undefined): Record<Address, LocalPointsInfo> | undefined;
@@ -0,0 +1,8 @@
1
+ import type { Address } from "viem";
2
+ import type { LocalPointsInfo, PointsList, StrategyCreditManagerLike } from "../types.js";
3
+ export declare function getPointsInfo({ chainId, pointsList, token, creditManagers, }: {
4
+ chainId: number | undefined;
5
+ pointsList: PointsList | undefined;
6
+ token: Address | undefined;
7
+ creditManagers: Record<Address, StrategyCreditManagerLike> | undefined;
8
+ }): LocalPointsInfo | undefined;
@@ -0,0 +1,2 @@
1
+ import type { LocalPointsReward } from "../types.js";
2
+ export declare function getPointsRates(rewards: Array<Pick<LocalPointsReward, "multiplier">>, leverage: bigint): (bigint | "soon")[];
@@ -0,0 +1,16 @@
1
+ import type { Address } from "viem";
2
+ import type { APYListByNetwork, Strategy, StrategyCreditManagerLike, StrategyInfoLike } from "../types.js";
3
+ export interface GetStrategyPointsProps {
4
+ readonly strategy: Strategy;
5
+ readonly info: StrategyInfoLike | undefined;
6
+ readonly strategyCreditManagers: Record<Address, StrategyCreditManagerLike>;
7
+ readonly apyListByNetwork: APYListByNetwork | undefined;
8
+ }
9
+ export declare function getStrategyPoints({ strategy, info, strategyCreditManagers, apyListByNetwork, }: GetStrategyPointsProps): {
10
+ pointsInfo: import("../types.js").LocalPointsInfo | undefined;
11
+ pointsInfoDebt: import("../types.js").LocalPointsInfo | undefined;
12
+ rewards: import("../../../../rewards/index.js").PointsReward<string>[];
13
+ debtRewards: import("../../../../rewards/index.js").DebtReward<string>[];
14
+ rewardRates: (bigint | "soon")[];
15
+ debtRewardRates: (bigint | "soon")[];
16
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./get-complex-points-list.js";
2
+ export * from "./get-points-info.js";
3
+ export * from "./get-points-rates.js";
4
+ export * from "./get-strategy-points.js";
@@ -8,8 +8,8 @@ export declare function getStrategyMaxAPY(targetToken: Address, cm: CMForStrateg
8
8
  } | undefined;
9
9
  maxAPY: number;
10
10
  maxLeverage: bigint;
11
- quotaRateMin: bigint;
12
- baseBorrowRate: number;
11
+ effectiveBaseRate: number;
12
+ effectiveQuotaRate: bigint;
13
13
  totalBorrowRate: number;
14
14
  } | undefined;
15
15
  export {};
@@ -63,6 +63,7 @@ export interface StrategyInfoResult<CM extends CreditManagerSlice = CreditManage
63
63
  totalBorrowRate: number;
64
64
  availableToBorrowMoney: bigint;
65
65
  minCreditManager: CM;
66
+ baseQuotaRateWithFee: bigint;
66
67
  }
67
68
  export interface GetStrategyInfoArgs<ID extends string | number, CM extends CreditManagerSlice> {
68
69
  strategy: StrategySlice<ID>;
@@ -4,6 +4,7 @@ export * from "./constants.js";
4
4
  export * from "./credit-manager-data-legacy.js";
5
5
  export * from "./curator-filter.js";
6
6
  export * from "./legacy-strategy-data-source.js";
7
+ export * from "./points-slices.js";
7
8
  export * from "./sdk-state.js";
8
9
  export * from "./strategies-cm-list.js";
9
10
  export * from "./strategy.js";
@@ -0,0 +1,20 @@
1
+ import type { Address } from "viem";
2
+ import type { DebtReward, PointsInfo, PointsReward } from "../../../../rewards/index.js";
3
+ export type LocalPointsReward = PointsReward<string>;
4
+ export type LocalDebtReward = DebtReward<string>;
5
+ export type LocalPointsInfo = PointsInfo<string>;
6
+ export type PointsList = Record<Address, LocalPointsInfo>;
7
+ export type BasePointsList = Record<Address, LocalPointsInfo>;
8
+ export type ExtraCollateralPointsList = Record<Address, Record<Address, LocalPointsInfo>>;
9
+ export type APYListByNetwork = Partial<Record<number, {
10
+ pointsList?: BasePointsList;
11
+ extraCollateralPointsList?: ExtraCollateralPointsList;
12
+ } | undefined>>;
13
+ export interface StrategyCreditManagerLike {
14
+ address: Address;
15
+ pool?: Address | undefined;
16
+ }
17
+ export interface StrategyInfoLike {
18
+ maxLeverage?: bigint | undefined;
19
+ minCreditManager?: StrategyCreditManagerLike | undefined;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "14.6.0",
3
+ "version": "14.7.0-next.2",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",