@defisaver/positions-sdk 2.0.15-dev → 2.0.15-dev-3

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 (152) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +64 -64
  4. package/cjs/aaveV2/index.js +9 -5
  5. package/cjs/aaveV3/index.js +50 -40
  6. package/cjs/aaveV3/merit.d.ts +17 -0
  7. package/cjs/aaveV3/merit.js +95 -0
  8. package/cjs/aaveV3/{rewards.d.ts → merkl.d.ts} +7 -2
  9. package/cjs/aaveV3/{rewards.js → merkl.js} +30 -14
  10. package/cjs/compoundV2/index.js +13 -7
  11. package/cjs/compoundV3/index.js +7 -2
  12. package/cjs/config/contracts.d.ts +6510 -1851
  13. package/cjs/config/contracts.js +33 -12
  14. package/cjs/contracts.d.ts +178 -0
  15. package/cjs/eulerV2/index.js +11 -2
  16. package/cjs/fluid/index.js +105 -34
  17. package/cjs/helpers/aaveHelpers/index.js +0 -1
  18. package/cjs/helpers/compoundHelpers/index.d.ts +3 -5
  19. package/cjs/helpers/compoundHelpers/index.js +15 -11
  20. package/cjs/helpers/eulerHelpers/index.d.ts +0 -5
  21. package/cjs/helpers/eulerHelpers/index.js +2 -31
  22. package/cjs/helpers/fluidHelpers/index.js +2 -0
  23. package/cjs/helpers/liquityV2Helpers/index.js +3 -2
  24. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  25. package/cjs/liquityV2/index.js +10 -2
  26. package/cjs/llamaLend/index.js +10 -2
  27. package/cjs/morphoBlue/index.js +20 -6
  28. package/cjs/spark/index.js +20 -30
  29. package/cjs/staking/eligibility.d.ts +11 -0
  30. package/cjs/staking/eligibility.js +43 -0
  31. package/cjs/staking/index.d.ts +1 -0
  32. package/cjs/staking/index.js +1 -0
  33. package/cjs/staking/staking.d.ts +1 -7
  34. package/cjs/staking/staking.js +29 -55
  35. package/cjs/types/aave.d.ts +1 -7
  36. package/cjs/types/common.d.ts +16 -4
  37. package/cjs/types/common.js +10 -1
  38. package/cjs/types/euler.d.ts +3 -3
  39. package/cjs/types/fluid.d.ts +3 -5
  40. package/cjs/types/liquityV2.d.ts +3 -3
  41. package/cjs/types/llamaLend.d.ts +3 -1
  42. package/cjs/types/morphoBlue.d.ts +3 -5
  43. package/cjs/types/spark.d.ts +0 -3
  44. package/esm/aaveV2/index.js +9 -5
  45. package/esm/aaveV3/index.js +48 -38
  46. package/esm/aaveV3/merit.d.ts +17 -0
  47. package/esm/aaveV3/merit.js +90 -0
  48. package/esm/aaveV3/{rewards.d.ts → merkl.d.ts} +7 -2
  49. package/esm/aaveV3/{rewards.js → merkl.js} +28 -13
  50. package/esm/compoundV2/index.js +13 -7
  51. package/esm/compoundV3/index.js +7 -2
  52. package/esm/config/contracts.d.ts +6510 -1851
  53. package/esm/config/contracts.js +33 -12
  54. package/esm/contracts.d.ts +178 -0
  55. package/esm/eulerV2/index.js +11 -2
  56. package/esm/fluid/index.js +106 -35
  57. package/esm/helpers/aaveHelpers/index.js +0 -1
  58. package/esm/helpers/compoundHelpers/index.d.ts +3 -5
  59. package/esm/helpers/compoundHelpers/index.js +16 -12
  60. package/esm/helpers/eulerHelpers/index.d.ts +0 -5
  61. package/esm/helpers/eulerHelpers/index.js +2 -30
  62. package/esm/helpers/fluidHelpers/index.js +2 -0
  63. package/esm/helpers/liquityV2Helpers/index.js +3 -2
  64. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  65. package/esm/liquityV2/index.js +11 -3
  66. package/esm/llamaLend/index.js +11 -3
  67. package/esm/morphoBlue/index.js +21 -7
  68. package/esm/spark/index.js +21 -31
  69. package/esm/staking/eligibility.d.ts +11 -0
  70. package/esm/staking/eligibility.js +36 -0
  71. package/esm/staking/index.d.ts +1 -0
  72. package/esm/staking/index.js +1 -0
  73. package/esm/staking/staking.d.ts +1 -7
  74. package/esm/staking/staking.js +28 -53
  75. package/esm/types/aave.d.ts +1 -7
  76. package/esm/types/common.d.ts +16 -4
  77. package/esm/types/common.js +9 -0
  78. package/esm/types/euler.d.ts +3 -3
  79. package/esm/types/fluid.d.ts +3 -5
  80. package/esm/types/liquityV2.d.ts +3 -3
  81. package/esm/types/llamaLend.d.ts +3 -1
  82. package/esm/types/morphoBlue.d.ts +3 -5
  83. package/esm/types/spark.d.ts +0 -3
  84. package/package.json +47 -47
  85. package/src/aaveV2/index.ts +239 -236
  86. package/src/aaveV3/index.ts +511 -493
  87. package/src/aaveV3/merit.ts +98 -0
  88. package/src/aaveV3/{rewards.ts → merkl.ts} +141 -125
  89. package/src/compoundV2/index.ts +244 -240
  90. package/src/compoundV3/index.ts +274 -270
  91. package/src/config/contracts.ts +1129 -1108
  92. package/src/constants/index.ts +6 -6
  93. package/src/contracts.ts +107 -107
  94. package/src/curveUsd/index.ts +250 -250
  95. package/src/eulerV2/index.ts +324 -314
  96. package/src/exchange/index.ts +25 -25
  97. package/src/fluid/index.ts +1636 -1568
  98. package/src/helpers/aaveHelpers/index.ts +169 -170
  99. package/src/helpers/compoundHelpers/index.ts +267 -261
  100. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  101. package/src/helpers/eulerHelpers/index.ts +222 -259
  102. package/src/helpers/fluidHelpers/index.ts +326 -324
  103. package/src/helpers/index.ts +10 -10
  104. package/src/helpers/liquityV2Helpers/index.ts +82 -80
  105. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  106. package/src/helpers/makerHelpers/index.ts +52 -52
  107. package/src/helpers/morphoBlueHelpers/index.ts +390 -390
  108. package/src/helpers/sparkHelpers/index.ts +155 -155
  109. package/src/index.ts +45 -45
  110. package/src/liquity/index.ts +104 -104
  111. package/src/liquityV2/index.ts +418 -408
  112. package/src/llamaLend/index.ts +305 -296
  113. package/src/maker/index.ts +223 -223
  114. package/src/markets/aave/index.ts +116 -116
  115. package/src/markets/aave/marketAssets.ts +49 -49
  116. package/src/markets/compound/index.ts +227 -227
  117. package/src/markets/compound/marketsAssets.ts +90 -90
  118. package/src/markets/curveUsd/index.ts +69 -69
  119. package/src/markets/euler/index.ts +26 -26
  120. package/src/markets/fluid/index.ts +2456 -2456
  121. package/src/markets/index.ts +25 -25
  122. package/src/markets/liquityV2/index.ts +102 -102
  123. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  124. package/src/markets/llamaLend/index.ts +235 -235
  125. package/src/markets/morphoBlue/index.ts +895 -895
  126. package/src/markets/spark/index.ts +29 -29
  127. package/src/markets/spark/marketAssets.ts +11 -11
  128. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  129. package/src/morphoBlue/index.ts +236 -222
  130. package/src/portfolio/index.ts +285 -285
  131. package/src/services/priceService.ts +159 -159
  132. package/src/services/utils.ts +63 -63
  133. package/src/services/viem.ts +32 -32
  134. package/src/setup.ts +8 -8
  135. package/src/spark/index.ts +444 -456
  136. package/src/staking/eligibility.ts +37 -0
  137. package/src/staking/index.ts +2 -1
  138. package/src/staking/staking.ts +169 -194
  139. package/src/types/aave.ts +189 -195
  140. package/src/types/common.ts +103 -88
  141. package/src/types/compound.ts +136 -136
  142. package/src/types/curveUsd.ts +121 -121
  143. package/src/types/euler.ts +175 -174
  144. package/src/types/fluid.ts +448 -450
  145. package/src/types/index.ts +11 -11
  146. package/src/types/liquity.ts +30 -30
  147. package/src/types/liquityV2.ts +126 -126
  148. package/src/types/llamaLend.ts +159 -157
  149. package/src/types/maker.ts +63 -63
  150. package/src/types/morphoBlue.ts +194 -194
  151. package/src/types/portfolio.ts +60 -60
  152. package/src/types/spark.ts +135 -137
@@ -87,10 +87,18 @@ function _getMorphoBlueMarketData(provider, network, selectedMarket) {
87
87
  totalBorrow: new decimal_js_1.default(marketInfo.totalBorrowAssets.toString()).div(scale).toString(),
88
88
  canBeSupplied: true,
89
89
  canBeBorrowed: true,
90
- incentiveSupplyApy: morphoSupplyApy,
91
- incentiveBorrowApy: morphoBorrowApy,
92
- incentiveSupplyToken: 'MORPHO',
93
- incentiveBorrowToken: 'MORPHO',
90
+ supplyIncentives: [{
91
+ token: 'MORPHO',
92
+ apy: morphoSupplyApy,
93
+ incentiveKind: common_1.IncentiveKind.Reward,
94
+ description: 'Eligible for protocol-level MORPHO incentives.',
95
+ }],
96
+ borrowIncentives: [{
97
+ token: 'MORPHO',
98
+ apy: morphoBorrowApy,
99
+ incentiveKind: common_1.IncentiveKind.Reward,
100
+ description: 'Eligible for protocol-level MORPHO incentives.',
101
+ }],
94
102
  };
95
103
  assetsData[(0, utils_1.wethToEth)(collateralTokenInfo.symbol)] = {
96
104
  symbol: (0, utils_1.wethToEth)(collateralTokenInfo.symbol),
@@ -100,10 +108,16 @@ function _getMorphoBlueMarketData(provider, network, selectedMarket) {
100
108
  borrowRate: '0',
101
109
  canBeSupplied: true,
102
110
  canBeBorrowed: false,
111
+ supplyIncentives: [],
112
+ borrowIncentives: [],
103
113
  };
104
114
  if (staking_1.STAKING_ASSETS.includes(collateralTokenInfo.symbol)) {
105
- assetsData[collateralTokenInfo.symbol].incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collateralTokenInfo.symbol);
106
- assetsData[collateralTokenInfo.symbol].incentiveSupplyToken = collateralTokenInfo.symbol;
115
+ assetsData[collateralTokenInfo.symbol].supplyIncentives = [{
116
+ apy: yield (0, staking_1.getStakingApy)(collateralTokenInfo.symbol),
117
+ token: collateralTokenInfo.symbol,
118
+ incentiveKind: common_1.IncentiveKind.Staking,
119
+ description: `Native ${collateralTokenInfo.symbol} yield.`,
120
+ }];
107
121
  }
108
122
  return {
109
123
  id: marketInfo.id,
@@ -123,36 +123,32 @@ const _getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(vo
123
123
  collateralFactor: new decimal_js_1.default(market.ltv).div(10000).toString(),
124
124
  priceSource: market.priceSource,
125
125
  },
126
+ supplyIncentives: [],
127
+ borrowIncentives: [],
126
128
  });
127
129
  })));
128
130
  yield Promise.all(assetsData.map((market) => __awaiter(void 0, void 0, void 0, function* () {
129
131
  /* eslint-disable no-param-reassign */
130
132
  const rewardForMarket = rewardInfo[market.underlyingTokenAddress];
131
133
  if (staking_1.STAKING_ASSETS.includes(market.symbol)) {
132
- market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(market.symbol);
133
- market.incentiveSupplyToken = market.symbol;
134
- if (!market.supplyIncentives) {
135
- market.supplyIncentives = [];
136
- }
134
+ const yieldApy = yield (0, staking_1.getStakingApy)(market.symbol);
137
135
  market.supplyIncentives.push({
138
- apy: market.incentiveSupplyApy || '0',
136
+ apy: yieldApy,
139
137
  token: market.symbol,
138
+ incentiveKind: common_1.IncentiveKind.Staking,
139
+ description: `Native ${market.symbol} yield.`,
140
140
  });
141
- }
142
- if (market.symbol === 'sDAI') {
143
- market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)('sDAI');
144
- market.incentiveSupplyToken = 'sDAI';
145
- }
146
- if (market.canBeBorrowed && market.incentiveSupplyApy) {
147
- market.incentiveBorrowApy = market.incentiveSupplyApy;
148
- market.incentiveBorrowToken = market.incentiveSupplyToken;
149
- if (!market.borrowIncentives) {
150
- market.borrowIncentives = [];
141
+ if (market.canBeBorrowed) {
142
+ if (!market.borrowIncentives) {
143
+ market.borrowIncentives = [];
144
+ }
145
+ market.borrowIncentives.push({
146
+ apy: new decimal_js_1.default(yieldApy).mul(-1).toString(),
147
+ token: market.symbol,
148
+ incentiveKind: common_1.IncentiveKind.Reward,
149
+ description: `Due to the native yield of ${market.symbol}, the value of the debt would increase over time.`,
150
+ });
151
151
  }
152
- market.borrowIncentives.push({
153
- apy: market.incentiveBorrowApy,
154
- token: market.incentiveBorrowToken,
155
- });
156
152
  }
157
153
  if (!rewardForMarket)
158
154
  return;
@@ -160,7 +156,6 @@ const _getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(vo
160
156
  if (supplyRewardData) {
161
157
  if (supplyRewardData.emissionEndTimestamp * 1000 < Date.now())
162
158
  return;
163
- market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
164
159
  const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
165
160
  const supplyRewardPrice = new decimal_js_1.default(supplyRewardData.rewardPriceFeed).div(Math.pow(10, supplyRewardData.priceFeedDecimals))
166
161
  .toString();
@@ -170,13 +165,11 @@ const _getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(vo
170
165
  .div(market.price)
171
166
  .div(market.totalSupply)
172
167
  .toString();
173
- market.incentiveSupplyApy = new decimal_js_1.default(market.incentiveSupplyApy || '0').add(rewardApy).toString();
174
- if (!market.supplyIncentives) {
175
- market.supplyIncentives = [];
176
- }
177
168
  market.supplyIncentives.push({
178
169
  token: supplyRewardData.rewardTokenSymbol,
179
170
  apy: rewardApy,
171
+ incentiveKind: common_1.IncentiveKind.Reward,
172
+ description: 'Eligible for protocol-level incentives.',
180
173
  });
181
174
  }
182
175
  });
@@ -184,7 +177,6 @@ const _getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(vo
184
177
  if (borrowRewardData) {
185
178
  if (borrowRewardData.emissionEndTimestamp * 1000 < Date.now())
186
179
  return;
187
- market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
188
180
  const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
189
181
  const supplyRewardPrice = new decimal_js_1.default(borrowRewardData.rewardPriceFeed).div(Math.pow(10, borrowRewardData.priceFeedDecimals))
190
182
  .toString();
@@ -194,13 +186,11 @@ const _getSparkMarketsData = (provider, network, selectedMarket) => __awaiter(vo
194
186
  .div(market.price)
195
187
  .div(market.totalBorrowVar)
196
188
  .toString();
197
- market.incentiveBorrowApy = new decimal_js_1.default(market.incentiveBorrowApy || '0').add(rewardApy).toString();
198
- if (!market.borrowIncentives) {
199
- market.borrowIncentives = [];
200
- }
201
189
  market.borrowIncentives.push({
202
190
  token: borrowRewardData.rewardTokenSymbol,
203
191
  apy: rewardApy,
192
+ incentiveKind: common_1.IncentiveKind.Reward,
193
+ description: 'Eligible for protocol-level incentives.',
204
194
  });
205
195
  }
206
196
  });
@@ -0,0 +1,11 @@
1
+ import { IncentiveEligibilityId, MMUsedAssets } from '../types/common';
2
+ export declare const isEligibleForEthenaUSDeRewards: (usedAssets: MMUsedAssets) => {
3
+ isEligible: boolean;
4
+ eligibleUSDAmount: string;
5
+ };
6
+ export declare const EligibilityMapping: {
7
+ [key in IncentiveEligibilityId]: (usedAssets: MMUsedAssets) => {
8
+ isEligible: boolean;
9
+ eligibleUSDAmount: string;
10
+ };
11
+ };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EligibilityMapping = exports.isEligibleForEthenaUSDeRewards = void 0;
7
+ const decimal_js_1 = __importDefault(require("decimal.js"));
8
+ const common_1 = require("../types/common");
9
+ const isEligibleForEthenaUSDeRewards = (usedAssets) => {
10
+ var _a, _b;
11
+ const USDeUSDAmountSupplied = ((_a = usedAssets.USDe) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
12
+ const sUSDeUSDAmountSupplied = ((_b = usedAssets.sUSDe) === null || _b === void 0 ? void 0 : _b.suppliedUsd) || '0';
13
+ const anythingElseSupplied = Object.values(usedAssets).some((asset) => asset.symbol !== 'USDe' && asset.symbol !== 'sUSDe' && asset.isSupplied);
14
+ if (anythingElseSupplied)
15
+ return { isEligible: false, eligibleUSDAmount: '0' };
16
+ const totalAmountSupplied = new decimal_js_1.default(USDeUSDAmountSupplied).add(sUSDeUSDAmountSupplied).toString();
17
+ const percentageInUSDe = new decimal_js_1.default(USDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
18
+ if (percentageInUSDe < 0.45 || percentageInUSDe > 0.55)
19
+ return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in USDe
20
+ const percentageInSUSDe = new decimal_js_1.default(sUSDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
21
+ if (percentageInSUSDe < 0.45 || percentageInSUSDe > 0.55)
22
+ return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in sUSDe
23
+ const allowedBorrowAssets = ['USDC', 'USDT', 'USDS'];
24
+ const anythingBorrowedNotAllowed = Object.values(usedAssets).some((asset) => asset.isBorrowed && !allowedBorrowAssets.includes(asset.symbol));
25
+ if (anythingBorrowedNotAllowed)
26
+ return { isEligible: false, eligibleUSDAmount: '0' };
27
+ const totalAmountBorrowed = Object.values(usedAssets).reduce((acc, asset) => {
28
+ if (asset.isBorrowed) {
29
+ return acc.add(asset.borrowedUsd);
30
+ }
31
+ return acc;
32
+ }, new decimal_js_1.default(0)).toString();
33
+ const borrowPercentage = new decimal_js_1.default(totalAmountBorrowed).div(totalAmountSupplied).toNumber();
34
+ if (borrowPercentage < 0.5)
35
+ return { isEligible: false, eligibleUSDAmount: '0' }; // must be looped at least once
36
+ const halfAmountSupplied = new decimal_js_1.default(totalAmountSupplied).div(2).toString();
37
+ const USDeAmountEligibleForRewards = decimal_js_1.default.min(USDeUSDAmountSupplied, halfAmountSupplied).toString(); // rewards are given to amount of USDe supplied up to half of total amount supplied
38
+ return { isEligible: true, eligibleUSDAmount: USDeAmountEligibleForRewards };
39
+ };
40
+ exports.isEligibleForEthenaUSDeRewards = isEligibleForEthenaUSDeRewards;
41
+ exports.EligibilityMapping = {
42
+ [common_1.IncentiveEligibilityId.AaveV3EthenaLiquidLeverage]: exports.isEligibleForEthenaUSDeRewards,
43
+ };
@@ -1 +1,2 @@
1
1
  export * from './staking';
2
+ export * from './eligibility';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./staking"), exports);
18
+ __exportStar(require("./eligibility"), exports);
@@ -3,15 +3,9 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
3
3
  export declare const STAKING_ASSETS: string[];
4
4
  export declare const getStakingApy: ((asset: string) => Promise<string>) & memoize.Memoized<(asset: string) => Promise<string>>;
5
5
  export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
6
- export declare const isEligibleForEthenaUSDeRewards: (usedAssets: MMUsedAssets) => {
7
- isEligible: boolean;
8
- eligibleUSDAmount: string;
9
- };
10
- export declare const calculateNetApy: ({ usedAssets, assetsData, isMorpho, isAave, }: {
6
+ export declare const calculateNetApy: ({ usedAssets, assetsData, }: {
11
7
  usedAssets: MMUsedAssets;
12
8
  assetsData: MMAssetsData;
13
- isMorpho?: boolean;
14
- isAave?: boolean;
15
9
  }) => {
16
10
  netApy: string;
17
11
  totalInterestUsd: string;
@@ -12,11 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.calculateNetApy = exports.isEligibleForEthenaUSDeRewards = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = void 0;
15
+ exports.calculateNetApy = exports.calculateInterestEarned = exports.getStakingApy = exports.STAKING_ASSETS = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const memoizee_1 = __importDefault(require("memoizee"));
18
18
  const constants_1 = require("../constants");
19
19
  const utils_1 = require("../services/utils");
20
+ const eligibility_1 = require("./eligibility");
20
21
  const getSsrApy = () => __awaiter(void 0, void 0, void 0, function* () {
21
22
  try {
22
23
  const res = yield fetch('https://fe.defisaver.com/api/sky/data', { signal: AbortSignal.timeout(utils_1.DEFAULT_TIMEOUT) });
@@ -135,75 +136,48 @@ const calculateInterestEarned = (principal, interest, type, apy = false) => {
135
136
  return (+principal * (Math.pow(((1 + (+interest / 100) / constants_1.BLOCKS_IN_A_YEAR)), (constants_1.BLOCKS_IN_A_YEAR * interval)))) - +principal; // eslint-disable-line
136
137
  };
137
138
  exports.calculateInterestEarned = calculateInterestEarned;
138
- const isEligibleForEthenaUSDeRewards = (usedAssets) => {
139
- var _a, _b;
140
- const USDeUSDAmountSupplied = ((_a = usedAssets.USDe) === null || _a === void 0 ? void 0 : _a.suppliedUsd) || '0';
141
- const sUSDeUSDAmountSupplied = ((_b = usedAssets.sUSDe) === null || _b === void 0 ? void 0 : _b.suppliedUsd) || '0';
142
- const anythingElseSupplied = Object.values(usedAssets).some((asset) => asset.symbol !== 'USDe' && asset.symbol !== 'sUSDe' && asset.isSupplied);
143
- if (anythingElseSupplied)
144
- return { isEligible: false, eligibleUSDAmount: '0' };
145
- const totalAmountSupplied = new decimal_js_1.default(USDeUSDAmountSupplied).add(sUSDeUSDAmountSupplied).toString();
146
- const percentageInUSDe = new decimal_js_1.default(USDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
147
- if (percentageInUSDe < 0.45 || percentageInUSDe > 0.55)
148
- return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in USDe
149
- const percentageInSUSDe = new decimal_js_1.default(sUSDeUSDAmountSupplied).div(totalAmountSupplied).toNumber();
150
- if (percentageInSUSDe < 0.45 || percentageInSUSDe > 0.55)
151
- return { isEligible: false, eligibleUSDAmount: '0' }; // 45% - 55% of total amount supplied must be in sUSDe
152
- const allowedBorrowAssets = ['USDC', 'USDT', 'USDS'];
153
- const anythingBorrowedNotAllowed = Object.values(usedAssets).some((asset) => asset.isBorrowed && !allowedBorrowAssets.includes(asset.symbol));
154
- if (anythingBorrowedNotAllowed)
155
- return { isEligible: false, eligibleUSDAmount: '0' };
156
- const totalAmountBorrowed = Object.values(usedAssets).reduce((acc, asset) => {
157
- if (asset.isBorrowed) {
158
- return acc.add(asset.borrowedUsd);
159
- }
160
- return acc;
161
- }, new decimal_js_1.default(0)).toString();
162
- const borrowPercentage = new decimal_js_1.default(totalAmountBorrowed).div(totalAmountSupplied).toNumber();
163
- if (borrowPercentage < 0.5)
164
- return { isEligible: false, eligibleUSDAmount: '0' }; // must be looped at least once
165
- const halfAmountSupplied = new decimal_js_1.default(totalAmountSupplied).div(2).toString();
166
- const USDeAmountEligibleForRewards = decimal_js_1.default.min(USDeUSDAmountSupplied, halfAmountSupplied).toString(); // rewards are given to amount of USDe supplied up to half of total amount supplied
167
- return { isEligible: true, eligibleUSDAmount: USDeAmountEligibleForRewards };
168
- };
169
- exports.isEligibleForEthenaUSDeRewards = isEligibleForEthenaUSDeRewards;
170
- const calculateNetApy = ({ usedAssets, assetsData, isMorpho = false, isAave = false, }) => {
171
- const { isEligible, eligibleUSDAmount } = isAave ? (0, exports.isEligibleForEthenaUSDeRewards)(usedAssets) : { isEligible: true, eligibleUSDAmount: '0' };
139
+ const calculateNetApy = ({ usedAssets, assetsData, }) => {
172
140
  const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
173
- var _a, _b;
174
141
  const acc = Object.assign({}, _acc);
175
142
  const assetData = assetsData[usedAsset.symbol];
176
143
  if (usedAsset.isSupplied) {
177
144
  const amount = usedAsset.suppliedUsd;
178
145
  acc.suppliedUsd = new decimal_js_1.default(acc.suppliedUsd).add(amount).toString();
179
- const rate = isMorpho
180
- ? usedAsset.supplyRate === '0' ? assetData.supplyRateP2P : usedAsset.supplyRate
181
- : assetData.supplyRate;
146
+ const rate = assetData.supplyRate;
182
147
  const supplyInterest = (0, exports.calculateInterestEarned)(amount, rate, 'year', true);
183
148
  acc.supplyInterest = new decimal_js_1.default(acc.supplyInterest).add(supplyInterest.toString()).toString();
184
- if (assetData.incentiveSupplyApy) {
185
- // take COMP/AAVE yield into account
186
- const incentiveInterest = (0, exports.calculateInterestEarned)(amount, assetData.incentiveSupplyApy, 'year', true);
187
- acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
188
- }
189
- if (usedAsset.symbol === 'USDe' && isEligible) {
190
- // @ts-ignore
191
- const incentiveInterest = (0, exports.calculateInterestEarned)(eligibleUSDAmount, ((_b = (_a = assetData.supplyIncentives) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.apy) || '0', 'year', true);
192
- acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
149
+ for (const supplyIncentive of assetData.supplyIncentives) {
150
+ const { apy, eligibilityId } = supplyIncentive;
151
+ const eligibilityCheck = eligibilityId ? eligibility_1.EligibilityMapping[eligibilityId] : null;
152
+ if (eligibilityCheck) {
153
+ const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
154
+ const incentiveInterest = isEligible ? (0, exports.calculateInterestEarned)(eligibleUSDAmount, apy, 'year', true) : '0';
155
+ acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
156
+ }
157
+ else {
158
+ const incentiveInterest = (0, exports.calculateInterestEarned)(amount, apy, 'year', true);
159
+ acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
160
+ }
193
161
  }
194
162
  }
195
163
  if (usedAsset.isBorrowed) {
196
164
  const amount = usedAsset.borrowedUsd;
197
165
  acc.borrowedUsd = new decimal_js_1.default(acc.borrowedUsd).add(amount).toString();
198
- const rate = isMorpho
199
- ? usedAsset.borrowRate === '0' ? assetData.borrowRateP2P : usedAsset.borrowRate
200
- : ((usedAsset === null || usedAsset === void 0 ? void 0 : usedAsset.interestMode) === '1' ? usedAsset.stableBorrowRate : assetData.borrowRate);
166
+ const rate = assetData.borrowRate;
201
167
  const borrowInterest = (0, exports.calculateInterestEarned)(amount, rate, 'year', true);
202
168
  acc.borrowInterest = new decimal_js_1.default(acc.borrowInterest).sub(borrowInterest.toString()).toString();
203
- if (assetData.incentiveBorrowApy) {
204
- // take COMP/AAVE yield into account
205
- const incentiveInterest = (0, exports.calculateInterestEarned)(amount, assetData.incentiveBorrowApy, 'year', true);
206
- acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).sub(incentiveInterest).toString();
169
+ for (const borrowIncentive of assetData.borrowIncentives) {
170
+ const { apy, eligibilityId } = borrowIncentive;
171
+ const eligibilityCheck = eligibilityId ? eligibility_1.EligibilityMapping[eligibilityId] : null;
172
+ if (eligibilityCheck) {
173
+ const { isEligible, eligibleUSDAmount } = eligibilityCheck(usedAssets);
174
+ const incentiveInterest = isEligible ? (0, exports.calculateInterestEarned)(eligibleUSDAmount, apy, 'year', true) : '0';
175
+ acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
176
+ }
177
+ else {
178
+ const incentiveInterest = (0, exports.calculateInterestEarned)(amount, apy, 'year', true);
179
+ acc.incentiveUsd = new decimal_js_1.default(acc.incentiveUsd).add(incentiveInterest).toString();
180
+ }
207
181
  }
208
182
  }
209
183
  return acc;
@@ -1,4 +1,4 @@
1
- import { MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
1
+ import { IncentiveData, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
2
2
  export declare enum AaveVersions {
3
3
  AaveV1 = "v1",
4
4
  AaveV2 = "v2default",
@@ -62,12 +62,6 @@ export interface AaveV2AssetData extends AaveAssetData {
62
62
  priceInEth: string;
63
63
  isFrozen: boolean;
64
64
  }
65
- export interface IncentiveData {
66
- token: string;
67
- apy: string;
68
- incentiveKind?: 'staking' | 'reward';
69
- description?: string;
70
- }
71
65
  export interface AaveV3AssetData extends AaveAssetData {
72
66
  isIsolated: boolean;
73
67
  isSiloed: boolean;
@@ -1,3 +1,17 @@
1
+ export declare enum IncentiveKind {
2
+ Staking = "staking",
3
+ Reward = "reward"
4
+ }
5
+ export declare enum IncentiveEligibilityId {
6
+ AaveV3EthenaLiquidLeverage = "0x8772bb231f3af13ead41d7ecf6abd60f5f716ec8BORROW_BL"
7
+ }
8
+ export interface IncentiveData {
9
+ token: string;
10
+ apy: string;
11
+ incentiveKind?: IncentiveKind;
12
+ description?: string;
13
+ eligibilityId?: IncentiveEligibilityId;
14
+ }
1
15
  export type EthAddress = HexString;
2
16
  export type Blockish = number | 'latest';
3
17
  export type AssetSymbol = string;
@@ -24,12 +38,10 @@ export interface MMAssetData {
24
38
  canBeBorrowed: boolean;
25
39
  canBeSupplied: boolean;
26
40
  totalBorrow: string;
27
- incentiveBorrowApy?: string;
28
- incentiveBorrowToken?: string;
29
- incentiveSupplyApy?: string;
30
- incentiveSupplyToken?: string;
31
41
  borrowRateP2P?: string;
32
42
  supplyRateP2P?: string;
43
+ supplyIncentives: IncentiveData[];
44
+ borrowIncentives: IncentiveData[];
33
45
  }
34
46
  export interface MMAssetsData {
35
47
  [token: string]: MMAssetData;
@@ -1,6 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NetworkNumber = void 0;
3
+ exports.NetworkNumber = exports.IncentiveEligibilityId = exports.IncentiveKind = void 0;
4
+ var IncentiveKind;
5
+ (function (IncentiveKind) {
6
+ IncentiveKind["Staking"] = "staking";
7
+ IncentiveKind["Reward"] = "reward";
8
+ })(IncentiveKind || (exports.IncentiveKind = IncentiveKind = {}));
9
+ var IncentiveEligibilityId;
10
+ (function (IncentiveEligibilityId) {
11
+ IncentiveEligibilityId["AaveV3EthenaLiquidLeverage"] = "0x8772bb231f3af13ead41d7ecf6abd60f5f716ec8BORROW_BL";
12
+ })(IncentiveEligibilityId || (exports.IncentiveEligibilityId = IncentiveEligibilityId = {}));
4
13
  var NetworkNumber;
5
14
  (function (NetworkNumber) {
6
15
  NetworkNumber[NetworkNumber["Eth"] = 1] = "Eth";
@@ -1,4 +1,4 @@
1
- import { EthAddress, MMPositionData, NetworkNumber } from './common';
1
+ import { EthAddress, IncentiveData, MMPositionData, NetworkNumber } from './common';
2
2
  export declare enum EulerV2Versions {
3
3
  eUSDC2 = "eUSDC-2",
4
4
  eWETH2 = "eWETH-2"
@@ -42,8 +42,8 @@ export interface EulerV2AssetData {
42
42
  borrowCap: string;
43
43
  canBeBorrowed: boolean;
44
44
  canBeSupplied: boolean;
45
- incentiveSupplyApy?: string;
46
- incentiveSupplyToken?: string;
45
+ supplyIncentives: IncentiveData[];
46
+ borrowIncentives: IncentiveData[];
47
47
  totalBorrow: string;
48
48
  collateralFactor: string;
49
49
  borrowRate: string;
@@ -1,4 +1,4 @@
1
- import { EthAddress, NetworkNumber } from './common';
1
+ import { EthAddress, IncentiveData, NetworkNumber } from './common';
2
2
  export interface FluidMarketInfo {
3
3
  chainIds: number[];
4
4
  label: string;
@@ -181,10 +181,8 @@ export interface FluidAssetData {
181
181
  symbol: string;
182
182
  address: string;
183
183
  price: string;
184
- incentiveSupplyApy?: string;
185
- incentiveSupplyToken?: string;
186
- incentiveBorrowApy?: string;
187
- incentiveBorrowToken?: string;
184
+ supplyIncentives: IncentiveData[];
185
+ borrowIncentives: IncentiveData[];
188
186
  totalSupply: string;
189
187
  totalBorrow: string;
190
188
  canBeSupplied: boolean;
@@ -1,4 +1,4 @@
1
- import { EthAddress, NetworkNumber } from './common';
1
+ import { EthAddress, IncentiveData, NetworkNumber } from './common';
2
2
  export declare enum LiquityV2Versions {
3
3
  LiquityV2Eth = "liquityv2eth",
4
4
  LiquityV2WstEth = "liquityv2wsteth",
@@ -37,14 +37,14 @@ export interface LiquityV2AssetData {
37
37
  symbol: string;
38
38
  address: string;
39
39
  price: string;
40
- incentiveSupplyApy?: string;
41
- incentiveSupplyToken?: string;
42
40
  totalSupply: string;
43
41
  totalBorrow: string;
44
42
  canBeSupplied: boolean;
45
43
  canBeBorrowed: boolean;
46
44
  leftToBorrowGlobal: string;
47
45
  leftToWithdrawGlobal: string;
46
+ supplyIncentives: IncentiveData[];
47
+ borrowIncentives: IncentiveData[];
48
48
  }
49
49
  export type LiquityV2AssetsData = {
50
50
  [key: string]: LiquityV2AssetData;
@@ -1,4 +1,4 @@
1
- import { EthAddress, NetworkNumber } from './common';
1
+ import { EthAddress, IncentiveData, NetworkNumber } from './common';
2
2
  import { BandData, UserBandData } from './curveUsd';
3
3
  export declare enum LLVersionsEth {
4
4
  LLWstethCrvusd = "llamaLendwstETHcrvUSD",
@@ -74,6 +74,8 @@ export interface LlamaLendAssetData {
74
74
  canBeSupplied?: boolean;
75
75
  canBeBorrowed?: boolean;
76
76
  shares?: string;
77
+ supplyIncentives: IncentiveData[];
78
+ borrowIncentives: IncentiveData[];
77
79
  }
78
80
  export type LlamaLendAssetsData = {
79
81
  [key: string]: LlamaLendAssetData;
@@ -1,4 +1,4 @@
1
- import { EthAddress, MMUsedAssets, NetworkNumber } from './common';
1
+ import { EthAddress, IncentiveData, MMUsedAssets, NetworkNumber } from './common';
2
2
  export declare enum MorphoBlueVersions {
3
3
  MorphoBlueWstEthUSDC = "morphobluewstethusdc",// wstETH/USDC
4
4
  MorphoBlueSDAIUSDC = "morphobluesdaiusdc",// sDAI/USDC
@@ -81,10 +81,8 @@ export interface MorphoBlueAssetData {
81
81
  price: string;
82
82
  supplyRate: string;
83
83
  borrowRate: string;
84
- incentiveSupplyApy?: string;
85
- incentiveSupplyToken?: string;
86
- incentiveBorrowApy?: string;
87
- incentiveBorrowToken?: string;
84
+ supplyIncentives: IncentiveData[];
85
+ borrowIncentives: IncentiveData[];
88
86
  totalSupply?: string;
89
87
  totalBorrow?: string;
90
88
  canBeSupplied?: boolean;
@@ -1,5 +1,4 @@
1
1
  import { EthAddress, MMAssetData, MMPositionData, MMUsedAsset, NetworkNumber } from './common';
2
- import { IncentiveData } from './aave';
3
2
  export declare enum SparkVersions {
4
3
  SparkV1 = "v1default"
5
4
  }
@@ -48,8 +47,6 @@ export interface SparkAssetData extends MMAssetData {
48
47
  eModeCategory: number;
49
48
  eModeCategoryData: SparkEModeCategoryData;
50
49
  liquidationRatio: string;
51
- supplyIncentives?: IncentiveData[];
52
- borrowIncentives?: IncentiveData[];
53
50
  }
54
51
  export interface SparkAssetsData {
55
52
  [token: string]: SparkAssetData;
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import Dec from 'decimal.js';
11
11
  import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
12
+ import { IncentiveKind, } from '../types/common';
12
13
  import { calculateNetApy, getStakingApy } from '../staking';
13
14
  import { ethToWeth, wethToEth, wethToEthByAddress } from '../services/utils';
14
15
  import { AaveLoanInfoV2ContractViem, createViemContractFromConfigFunc } from '../contracts';
@@ -56,15 +57,18 @@ export const _getAaveV2MarketsData = (provider, network, selectedMarket) => __aw
56
57
  totalBorrow: assetAmountInEth(market.totalBorrow.toString(), selectedMarket.assets[i]),
57
58
  totalBorrowVar: assetAmountInEth(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
58
59
  priceInEth: new Dec(market.price.toString()).div(1e18).toString(),
59
- incentiveSupplyToken: 'AAVE',
60
- incentiveBorrowToken: 'AAVE',
61
- incentiveSupplyApy: '0',
60
+ supplyIncentives: [],
61
+ borrowIncentives: [],
62
62
  price: new Dec(market.price.toString()).div(1e18).mul(ethPrice).toString(),
63
63
  }));
64
64
  const stEthMarket = markets.find(({ symbol }) => symbol === 'stETH');
65
65
  if (stEthMarket) {
66
- stEthMarket.incentiveSupplyApy = yield getStakingApy('stETH');
67
- stEthMarket.incentiveSupplyToken = 'stETH';
66
+ stEthMarket.supplyIncentives.push({
67
+ apy: yield getStakingApy('stETH'),
68
+ token: 'stETH',
69
+ incentiveKind: IncentiveKind.Staking,
70
+ description: 'Native stETH yield.',
71
+ });
68
72
  }
69
73
  const payload = {};
70
74
  // Sort by market size