@defisaver/positions-sdk 2.0.15-dev → 2.0.15-dev-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 (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
package/.mocharc.json CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "require": "ts-node/register",
3
- "extension": ["ts"]
4
- }
1
+ {
2
+ "require": "ts-node/register",
3
+ "extension": ["ts"]
4
+ }
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- v20.17.0
1
+ v20.17.0
package/README.md CHANGED
@@ -1,64 +1,64 @@
1
- # DeFi Saver Positions SDK
2
-
3
- Supported protocols:
4
- - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
- - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
- - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
- - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
- - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
- - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
10
- - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
11
- - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
12
-
13
- ## Setup
14
- Supported Node version is v10.
15
-
16
- - run `npm install` (first time)
17
- - run `npm run build`
18
-
19
- `build` command will generate contracts and build ejs and esm folders
20
-
21
- ## How to use
22
- [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
23
-
24
- This is a Compound V3 example, and every other protocol is similar
25
- ```js
26
- import { compoundV3 } from '@defisaver/positions-sdk';
27
-
28
-
29
- // every protocol has market data and user data getters
30
- const {
31
- getCompoundV3MarketsData,
32
- getCompoundV3AccountData,
33
- } = compoundV3;
34
-
35
- const provider = 'Your RPC provider';
36
-
37
- const user = '0x123...';
38
-
39
- const { assetsData } = await getCompoundV3MarketsData(
40
- provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
41
- 1, // network
42
- selectedMarket, // market object like in /src/markets/compound/index.ts
43
- provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
44
- );
45
-
46
- const userData = await getCompoundV3AccountData(
47
- provider,
48
- 1, // network
49
- userAddress, // EOA or DSProxy
50
- '', // proxy address of the user, or just empty string if checking for EOA
51
- {
52
- selectedMarket, // market object as in /src/markets/compound/index.ts
53
- assetsData,
54
- }
55
- );
56
- ```
57
-
58
- More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
59
-
60
- ## Testing
61
-
62
- `npm run test` - Run all tests
63
-
64
- `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
1
+ # DeFi Saver Positions SDK
2
+
3
+ Supported protocols:
4
+ - [Maker](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/maker)
5
+ - [Spark](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/spark)
6
+ - [CrvUSD](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/curveUsd)
7
+ - [Aave V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV2)
8
+ - [Aave V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/aaveV3)
9
+ - [Compound V2](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV2)
10
+ - [Compound V3](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/compoundV3)
11
+ - [Liquity](https://github.com/defisaver/defisaver-positions-sdk/tree/main/src/liquity)
12
+
13
+ ## Setup
14
+ Supported Node version is v10.
15
+
16
+ - run `npm install` (first time)
17
+ - run `npm run build`
18
+
19
+ `build` command will generate contracts and build ejs and esm folders
20
+
21
+ ## How to use
22
+ [All available imports](https://github.com/defisaver/defisaver-positions-sdk/blob/main/src/index.ts)
23
+
24
+ This is a Compound V3 example, and every other protocol is similar
25
+ ```js
26
+ import { compoundV3 } from '@defisaver/positions-sdk';
27
+
28
+
29
+ // every protocol has market data and user data getters
30
+ const {
31
+ getCompoundV3MarketsData,
32
+ getCompoundV3AccountData,
33
+ } = compoundV3;
34
+
35
+ const provider = 'Your RPC provider';
36
+
37
+ const user = '0x123...';
38
+
39
+ const { assetsData } = await getCompoundV3MarketsData(
40
+ provider, // rpc for the network you are using (note: can be tenderly or any other testnet rpc)
41
+ 1, // network
42
+ selectedMarket, // market object like in /src/markets/compound/index.ts
43
+ provider, // this must be mainnet rpc - used for getting prices onchain and calculating apys
44
+ );
45
+
46
+ const userData = await getCompoundV3AccountData(
47
+ provider,
48
+ 1, // network
49
+ userAddress, // EOA or DSProxy
50
+ '', // proxy address of the user, or just empty string if checking for EOA
51
+ {
52
+ selectedMarket, // market object as in /src/markets/compound/index.ts
53
+ assetsData,
54
+ }
55
+ );
56
+ ```
57
+
58
+ More examples found [here](https://github.com/defisaver/defisaver-positions-sdk/tree/main/tests)
59
+
60
+ ## Testing
61
+
62
+ `npm run test` - Run all tests
63
+
64
+ `npm run test-single --name=your_test_name` - Run single test for specified name e.g. for MyTest.js test name is MyTest
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getAaveV2FullPositionData = exports.getAaveV2AccountData = exports._getAaveV2AccountData = exports.getAaveV2AccountBalances = exports._getAaveV2AccountBalances = exports.getAaveV2MarketsData = exports._getAaveV2MarketsData = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const tokens_1 = require("@defisaver/tokens");
18
+ const common_1 = require("../types/common");
18
19
  const staking_1 = require("../staking");
19
20
  const utils_1 = require("../services/utils");
20
21
  const contracts_1 = require("../contracts");
@@ -62,15 +63,18 @@ const _getAaveV2MarketsData = (provider, network, selectedMarket) => __awaiter(v
62
63
  totalBorrow: (0, tokens_1.assetAmountInEth)(market.totalBorrow.toString(), selectedMarket.assets[i]),
63
64
  totalBorrowVar: (0, tokens_1.assetAmountInEth)(market.totalBorrowVar.toString(), selectedMarket.assets[i]),
64
65
  priceInEth: new decimal_js_1.default(market.price.toString()).div(1e18).toString(),
65
- incentiveSupplyToken: 'AAVE',
66
- incentiveBorrowToken: 'AAVE',
67
- incentiveSupplyApy: '0',
66
+ supplyIncentives: [],
67
+ borrowIncentives: [],
68
68
  price: new decimal_js_1.default(market.price.toString()).div(1e18).mul(ethPrice).toString(),
69
69
  }));
70
70
  const stEthMarket = markets.find(({ symbol }) => symbol === 'stETH');
71
71
  if (stEthMarket) {
72
- stEthMarket.incentiveSupplyApy = yield (0, staking_1.getStakingApy)('stETH');
73
- stEthMarket.incentiveSupplyToken = 'stETH';
72
+ stEthMarket.supplyIncentives.push({
73
+ apy: yield (0, staking_1.getStakingApy)('stETH'),
74
+ token: 'stETH',
75
+ incentiveKind: common_1.IncentiveKind.Staking,
76
+ description: 'Native stETH yield.',
77
+ });
74
78
  }
75
79
  const payload = {};
76
80
  // Sort by market size
@@ -25,7 +25,8 @@ const utils_1 = require("../services/utils");
25
25
  const staking_1 = require("../staking");
26
26
  const common_1 = require("../types/common");
27
27
  const viem_1 = require("../services/viem");
28
- const rewards_1 = require("./rewards");
28
+ const merit_1 = require("./merit");
29
+ const merkl_1 = require("./merkl");
29
30
  const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
30
31
  const { eModeCategoriesData } = extractedState;
31
32
  const usedAssetsValues = Object.values(usedAssets);
@@ -61,12 +62,13 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
61
62
  const marketAddress = market.providerAddress;
62
63
  const networksWithIncentives = [common_1.NetworkNumber.Eth, common_1.NetworkNumber.Arb, common_1.NetworkNumber.Opt, common_1.NetworkNumber.Linea];
63
64
  // eslint-disable-next-line prefer-const
64
- let [loanInfo, eModesInfo, isBorrowAllowed, rewardInfo, merkleRewardsMap] = yield Promise.all([
65
+ let [loanInfo, eModesInfo, isBorrowAllowed, rewardInfo, merkleRewardsMap, meritRewardsMap] = yield Promise.all([
65
66
  loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses], (0, viem_1.setViemBlockNumber)(blockNumber)),
66
67
  loanInfoContract.read.getAllEmodes([marketAddress], (0, viem_1.setViemBlockNumber)(blockNumber)),
67
68
  loanInfoContract.read.isBorrowAllowed([marketAddress], (0, viem_1.setViemBlockNumber)(blockNumber)), // Used on L2s check for PriceOracleSentinel (mainnet will always return true)
68
69
  networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], (0, viem_1.setViemBlockNumber)(blockNumber)) : null,
69
- (0, rewards_1.getMerkleCampaigns)(network),
70
+ (0, merkl_1.getMerkleCampaigns)(network),
71
+ (0, merit_1.getMeritCampaigns)(network, market.value),
70
72
  ]);
71
73
  isBorrowAllowed = (0, utils_1.isLayer2Network)(network) ? isBorrowAllowed : true;
72
74
  const eModeCategoriesData = {};
@@ -148,58 +150,76 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
148
150
  isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled,
149
151
  isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled,
150
152
  aTokenAddress: tokenMarket.aTokenAddress,
153
+ vTokenAddress: tokenMarket.debtTokenAddress,
151
154
  supplyIncentives: [],
152
155
  borrowIncentives: [],
153
156
  });
154
157
  })));
155
158
  // Get incentives data
156
159
  yield Promise.all(assetsData.map((_market, index) => __awaiter(this, void 0, void 0, function* () {
157
- var _a;
160
+ var _a, _b;
158
161
  /* eslint-disable no-param-reassign */
159
162
  // @ts-ignore
160
163
  const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
161
164
  const isStakingAsset = staking_1.STAKING_ASSETS.includes(_market.symbol);
162
165
  if (isStakingAsset) {
163
- _market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(_market.symbol);
164
- _market.incentiveSupplyToken = _market.symbol;
166
+ const yieldApy = yield (0, staking_1.getStakingApy)(_market.symbol);
165
167
  _market.supplyIncentives.push({
166
- apy: _market.incentiveSupplyApy || '0',
168
+ apy: yieldApy,
167
169
  token: _market.symbol,
168
- incentiveKind: 'staking',
170
+ incentiveKind: common_1.IncentiveKind.Staking,
169
171
  description: `Native ${_market.symbol} yield.`,
170
172
  });
171
173
  if (_market.canBeBorrowed) {
172
174
  // when borrowing assets whose value increases over time
173
- _market.incentiveBorrowApy = new decimal_js_1.default(_market.incentiveSupplyApy).mul(-1).toString();
174
- _market.incentiveBorrowToken = _market.symbol;
175
175
  _market.borrowIncentives.push({
176
- apy: _market.incentiveBorrowApy,
177
- token: _market.incentiveBorrowToken,
178
- incentiveKind: 'reward',
176
+ apy: new decimal_js_1.default(yieldApy).mul(-1).toString(),
177
+ token: _market.symbol,
178
+ incentiveKind: common_1.IncentiveKind.Reward,
179
179
  description: `Due to the native yield of ${_market.symbol}, the value of the debt would increase over time.`,
180
180
  });
181
181
  }
182
182
  }
183
183
  const aTokenAddress = _market.aTokenAddress.toLowerCase(); // DEV: Should aTokenAddress be in AaveV3AssetData type?
184
184
  if ((_a = merkleRewardsMap[aTokenAddress]) === null || _a === void 0 ? void 0 : _a.supply) {
185
- const { apr, rewardTokenSymbol, description } = merkleRewardsMap[aTokenAddress].supply;
185
+ const { apy, rewardTokenSymbol, description, identifier, } = merkleRewardsMap[aTokenAddress].supply;
186
186
  _market.supplyIncentives.push({
187
- apy: (0, moneymarket_1.aprToApy)(apr),
187
+ apy,
188
188
  token: rewardTokenSymbol,
189
- incentiveKind: 'reward',
189
+ incentiveKind: common_1.IncentiveKind.Reward,
190
+ description,
191
+ eligibilityId: identifier,
192
+ });
193
+ }
194
+ const vTokenAddress = _market.vTokenAddress.toLowerCase(); // DEV: Should vTokenAddress be in AaveV3AssetData type?
195
+ if ((_b = merkleRewardsMap[vTokenAddress]) === null || _b === void 0 ? void 0 : _b.borrow) {
196
+ const { apy, rewardTokenSymbol, description, identifier, } = merkleRewardsMap[vTokenAddress].borrow;
197
+ _market.borrowIncentives.push({
198
+ apy,
199
+ token: rewardTokenSymbol,
200
+ incentiveKind: common_1.IncentiveKind.Reward,
201
+ description,
202
+ eligibilityId: identifier,
203
+ });
204
+ }
205
+ if (meritRewardsMap.supply[_market.symbol]) {
206
+ const { apy, rewardTokenSymbol, description } = meritRewardsMap.supply[_market.symbol];
207
+ _market.supplyIncentives.push({
208
+ apy,
209
+ token: rewardTokenSymbol,
210
+ incentiveKind: common_1.IncentiveKind.Reward,
211
+ description,
212
+ });
213
+ }
214
+ if (meritRewardsMap.borrow[_market.symbol]) {
215
+ const { apy, rewardTokenSymbol, description } = meritRewardsMap.borrow[_market.symbol];
216
+ _market.borrowIncentives.push({
217
+ apy,
218
+ token: rewardTokenSymbol,
219
+ incentiveKind: common_1.IncentiveKind.Reward,
190
220
  description,
191
221
  });
192
222
  }
193
- // const aTokenDebtAddress = '0xTODO';
194
- // if (merkleRewardsMap[aTokenDebtAddress]?.supply) {
195
- // const { apr, rewardTokenSymbol, description } = merkleRewardsMap[aTokenDebtAddress].supply;
196
- // _market.borrowIncentives.push({
197
- // apy: aprToApy(apr),
198
- // token: rewardTokenSymbol,
199
- // incentiveKind: 'reward',
200
- // description,
201
- // });
202
- // }
203
223
  if (!rewardForMarket)
204
224
  return;
205
225
  // @ts-ignore
@@ -207,10 +227,7 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
207
227
  if (supplyRewardData) {
208
228
  if (+(supplyRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
209
229
  return;
210
- _market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
211
230
  // reward token is aave asset
212
- if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
213
- _market.incentiveSupplyToken = _market.symbol;
214
231
  const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
215
232
  const supplyRewardPrice = new decimal_js_1.default(supplyRewardData.rewardPriceFeed).div(Math.pow(10, +supplyRewardData.priceFeedDecimals))
216
233
  .toString();
@@ -220,12 +237,10 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
220
237
  .div(_market.price)
221
238
  .div(_market.totalSupply)
222
239
  .toString();
223
- _market.incentiveSupplyApy = new decimal_js_1.default(_market.incentiveSupplyApy || '0').add(rewardApy)
224
- .toString();
225
240
  _market.supplyIncentives.push({
226
- token: (0, rewards_1.getAaveUnderlyingSymbol)(supplyRewardData.rewardTokenSymbol),
241
+ token: (0, merkl_1.getAaveUnderlyingSymbol)(supplyRewardData.rewardTokenSymbol),
227
242
  apy: rewardApy,
228
- incentiveKind: 'reward',
243
+ incentiveKind: common_1.IncentiveKind.Reward,
229
244
  description: 'Eligible for protocol-level incentives.',
230
245
  });
231
246
  }
@@ -235,9 +250,6 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
235
250
  if (borrowRewardData) {
236
251
  if (+(borrowRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
237
252
  return;
238
- _market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
239
- if (borrowRewardData.rewardTokenSymbol.startsWith('a') && borrowRewardData.rewardTokenSymbol.includes(_market.symbol))
240
- _market.incentiveBorrowToken = _market.symbol;
241
253
  const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
242
254
  const supplyRewardPrice = new decimal_js_1.default(borrowRewardData.rewardPriceFeed).div(Math.pow(10, +borrowRewardData.priceFeedDecimals))
243
255
  .toString();
@@ -247,12 +259,10 @@ function _getAaveV3MarketData(provider_1, network_1, market_1) {
247
259
  .div(_market.price)
248
260
  .div(_market.totalBorrowVar)
249
261
  .toString();
250
- _market.incentiveBorrowApy = new decimal_js_1.default(_market.incentiveBorrowApy || '0').add(rewardApy)
251
- .toString();
252
262
  _market.borrowIncentives.push({
253
- token: (0, rewards_1.getAaveUnderlyingSymbol)(borrowRewardData.rewardTokenSymbol),
263
+ token: (0, merkl_1.getAaveUnderlyingSymbol)(borrowRewardData.rewardTokenSymbol),
254
264
  apy: rewardApy,
255
- incentiveKind: 'reward',
265
+ incentiveKind: common_1.IncentiveKind.Reward,
256
266
  description: 'Eligible for protocol-level incentives.',
257
267
  });
258
268
  }
@@ -0,0 +1,17 @@
1
+ import { NetworkNumber } from '../types/common';
2
+ import { AaveVersions } from '../types';
3
+ type RewardInfo = {
4
+ apy: string;
5
+ rewardTokenSymbol: string;
6
+ description: string;
7
+ };
8
+ type MeritTokenRewardMap = {
9
+ supply: Record<string, RewardInfo>;
10
+ borrow: Record<string, RewardInfo>;
11
+ };
12
+ /**
13
+ * Fetches merit rewards data from Aave API
14
+ */
15
+ export declare const fetchMeritRewardsData: () => Promise<Record<string, number | null>>;
16
+ export declare const getMeritCampaigns: (chainId: NetworkNumber, market: AaveVersions) => Promise<MeritTokenRewardMap>;
17
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getMeritCampaigns = exports.fetchMeritRewardsData = void 0;
13
+ const utils_1 = require("../services/utils");
14
+ const common_1 = require("../types/common");
15
+ const moneymarket_1 = require("../moneymarket");
16
+ const types_1 = require("../types");
17
+ /**
18
+ * Maps API keys to reward data & actions - hardcoded and needs to be maintained actively.
19
+ * Mapping based on Aave interface implementation: https://github.com/aave/interface/blob/main/src/hooks/useMeritIncentives.ts
20
+ * Active campaigns found here: https://apps.aavechan.com/merit
21
+ */
22
+ const MERIT_DATA_MAP = {
23
+ [common_1.NetworkNumber.Eth]: {
24
+ [types_1.AaveVersions.AaveV3]: {
25
+ 'ethereum-supply-ethx': { rewardTokenSymbol: 'SD', action: 'supply', supplyTokens: ['ETHx'] },
26
+ 'ethereum-supply-rlusd': { rewardTokenSymbol: 'aEthRLUSD', action: 'supply', supplyTokens: ['RLUSD'] },
27
+ // Campaign disabled here as it's present on Merkl API:
28
+ // 'ethereum-borrow-eurc': { rewardTokenSymbol: 'aEthEURC', action: 'borrow', borrowTokens: ['EURC'] },
29
+ },
30
+ [types_1.AaveVersions.AaveV3Lido]: {},
31
+ [types_1.AaveVersions.AaveV3Etherfi]: {},
32
+ },
33
+ [common_1.NetworkNumber.Arb]: {
34
+ [types_1.AaveVersions.AaveV3]: {},
35
+ },
36
+ [common_1.NetworkNumber.Opt]: {
37
+ [types_1.AaveVersions.AaveV3]: {},
38
+ },
39
+ [common_1.NetworkNumber.Base]: {
40
+ [types_1.AaveVersions.AaveV3]: {
41
+ 'base-borrow-usdc': { rewardTokenSymbol: 'USDC', action: 'borrow', borrowTokens: ['USDC'] },
42
+ 'base-borrow-gho': { rewardTokenSymbol: 'GHO', action: 'borrow', borrowTokens: ['GHO'] },
43
+ 'base-borrow-eurc': { rewardTokenSymbol: 'EURC', action: 'borrow', borrowTokens: ['EURC'] },
44
+ },
45
+ },
46
+ [common_1.NetworkNumber.Linea]: {
47
+ [types_1.AaveVersions.AaveV3]: {},
48
+ },
49
+ };
50
+ /**
51
+ * Fetches merit rewards data from Aave API
52
+ */
53
+ const fetchMeritRewardsData = () => __awaiter(void 0, void 0, void 0, function* () {
54
+ try {
55
+ const response = yield fetch('https://apps.aavechan.com/api/merit/aprs', {
56
+ signal: AbortSignal.timeout(utils_1.DEFAULT_TIMEOUT),
57
+ });
58
+ const data = yield response.json();
59
+ return data.currentAPR.actionsAPR;
60
+ }
61
+ catch (error) {
62
+ console.error('Failed to fetch merit rewards data:', error);
63
+ return {};
64
+ }
65
+ });
66
+ exports.fetchMeritRewardsData = fetchMeritRewardsData;
67
+ const getMeritCampaigns = (chainId, market) => __awaiter(void 0, void 0, void 0, function* () {
68
+ var _a;
69
+ const meritData = yield (0, exports.fetchMeritRewardsData)();
70
+ const relevantCampaigns = {
71
+ supply: {},
72
+ borrow: {},
73
+ };
74
+ Object.entries(((_a = MERIT_DATA_MAP[chainId]) === null || _a === void 0 ? void 0 : _a[market]) || {})
75
+ .filter(([key, rewardData]) => !!meritData[key])
76
+ .forEach(([key, rewardData]) => {
77
+ var _a, _b;
78
+ const apr = meritData[key];
79
+ if (!apr)
80
+ return;
81
+ const reward = {
82
+ rewardTokenSymbol: rewardData.rewardTokenSymbol,
83
+ apy: (0, moneymarket_1.aprToApy)(apr).toString(),
84
+ description: `Eligible for Merit rewards in ${rewardData.rewardTokenSymbol}. ${rewardData.message ? `\n${rewardData.message}` : ''}`,
85
+ };
86
+ (_a = rewardData.supplyTokens) === null || _a === void 0 ? void 0 : _a.forEach(token => {
87
+ relevantCampaigns.supply[token] = reward;
88
+ });
89
+ (_b = rewardData.borrowTokens) === null || _b === void 0 ? void 0 : _b.forEach(token => {
90
+ relevantCampaigns.borrow[token] = reward;
91
+ });
92
+ });
93
+ return relevantCampaigns;
94
+ });
95
+ exports.getMeritCampaigns = getMeritCampaigns;
@@ -1,14 +1,19 @@
1
1
  import { EthAddress, NetworkNumber } from '../types/common';
2
2
  type RewardInfo = {
3
- apr: number;
4
- rewardToken: EthAddress;
3
+ apy: string;
5
4
  rewardTokenSymbol: string;
6
5
  description: string;
6
+ identifier: string;
7
7
  };
8
8
  type MerkleRewardMap = Record<EthAddress, {
9
9
  supply?: RewardInfo;
10
10
  borrow?: RewardInfo;
11
11
  }>;
12
12
  export declare const getAaveUnderlyingSymbol: (_symbol?: string) => any;
13
+ /**
14
+ * aEthLidoUSDC -> aUSDC
15
+ * USDC -> USDC
16
+ */
17
+ export declare const formatAaveAsset: (_symbol: string) => string;
13
18
  export declare const getMerkleCampaigns: (chainId: NetworkNumber) => Promise<MerkleRewardMap>;
14
19
  export {};
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getMerkleCampaigns = exports.getAaveUnderlyingSymbol = void 0;
12
+ exports.getMerkleCampaigns = exports.formatAaveAsset = exports.getAaveUnderlyingSymbol = void 0;
13
+ const moneymarket_1 = require("../moneymarket");
13
14
  const utils_1 = require("../services/utils");
14
15
  var OpportunityAction;
15
16
  (function (OpportunityAction) {
@@ -36,6 +37,17 @@ const getAaveUnderlyingSymbol = (_symbol = '') => {
36
37
  return (0, utils_1.wethToEth)(symbol);
37
38
  };
38
39
  exports.getAaveUnderlyingSymbol = getAaveUnderlyingSymbol;
40
+ /**
41
+ * aEthLidoUSDC -> aUSDC
42
+ * USDC -> USDC
43
+ */
44
+ const formatAaveAsset = (_symbol) => {
45
+ if (_symbol.startsWith('a')) {
46
+ return `a${(0, exports.getAaveUnderlyingSymbol)(_symbol)}`;
47
+ }
48
+ return _symbol;
49
+ };
50
+ exports.formatAaveAsset = formatAaveAsset;
39
51
  const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
40
52
  try {
41
53
  const res = yield fetch('https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave', {
@@ -46,29 +58,33 @@ const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, functi
46
58
  const opportunities = yield res.json();
47
59
  const relevantOpportunities = opportunities
48
60
  .filter((o) => o.chainId === chainId)
49
- .filter((o) => o.liveCampaigns > 0);
61
+ .filter((o) => o.status === OpportunityStatus.LIVE);
50
62
  return relevantOpportunities.reduce((acc, opportunity) => {
63
+ var _a, _b;
51
64
  const rewardToken = opportunity.rewardsRecord.breakdowns[0].token;
52
- if (opportunity.action === OpportunityAction.LEND) {
53
- const supplyAToken = opportunity.explorerAddress.toLowerCase();
65
+ const description = `Eligible for ${(0, exports.formatAaveAsset)(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
66
+ if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
67
+ const supplyAToken = (_a = opportunity.explorerAddress) === null || _a === void 0 ? void 0 : _a.toLowerCase();
54
68
  if (!acc[supplyAToken])
55
69
  acc[supplyAToken] = {};
56
70
  acc[supplyAToken].supply = {
57
- apr: opportunity.apr,
58
- rewardToken: rewardToken.address,
59
- rewardTokenSymbol: (0, exports.getAaveUnderlyingSymbol)(rewardToken.symbol),
60
- description: `Eligible for incentives through Merkl. \n${opportunity.description}`,
71
+ apy: (0, moneymarket_1.aprToApy)(opportunity.apr),
72
+ // rewardToken: rewardToken.address,
73
+ rewardTokenSymbol: rewardToken.symbol,
74
+ description,
75
+ identifier: opportunity.identifier,
61
76
  };
62
77
  }
63
- if (opportunity.action === OpportunityAction.BORROW) {
64
- const borrowAToken = opportunity.explorerAddress.toLowerCase();
78
+ if (opportunity.action === OpportunityAction.BORROW && opportunity.explorerAddress) {
79
+ const borrowAToken = (_b = opportunity.explorerAddress) === null || _b === void 0 ? void 0 : _b.toLowerCase();
65
80
  if (!acc[borrowAToken])
66
81
  acc[borrowAToken] = {};
67
82
  acc[borrowAToken].borrow = {
68
- apr: opportunity.apr,
69
- rewardToken: rewardToken.address,
70
- rewardTokenSymbol: (0, exports.getAaveUnderlyingSymbol)(rewardToken.symbol),
71
- description: `Eligible for incentives through Merkl. \n${opportunity.description}`,
83
+ apy: (0, moneymarket_1.aprToApy)(opportunity.apr),
84
+ // rewardToken: rewardToken.address,
85
+ rewardTokenSymbol: rewardToken.symbol,
86
+ description,
87
+ identifier: opportunity.identifier,
72
88
  };
73
89
  }
74
90
  return acc;
@@ -18,6 +18,7 @@ const decimal_js_1 = __importDefault(require("decimal.js"));
18
18
  const constants_1 = require("../constants");
19
19
  const moneymarket_1 = require("../moneymarket");
20
20
  const utils_1 = require("../services/utils");
21
+ const common_1 = require("../types/common");
21
22
  const contracts_1 = require("../contracts");
22
23
  const markets_1 = require("../markets");
23
24
  const compoundHelpers_1 = require("../helpers/compoundHelpers");
@@ -39,9 +40,6 @@ const _getCompoundV2MarketsData = (provider, network) => __awaiter(void 0, void
39
40
  const compBorrowSpeeds = market.compBorrowSpeeds.toString();
40
41
  const assetPrice = market.price.toString();
41
42
  const pricePrecisionDiff = 18 - (0, tokens_1.getAssetInfo)((0, tokens_1.getAssetInfoByAddress)(cAddresses[i]).underlyingAsset).decimals;
42
- // compSupplySpeeds/compBorrowSpeeds is per block per market (borrow & supply are separate markets)
43
- const incentiveSupplyApy = (0, moneymarket_1.aprToApy)((100 * constants_1.BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString();
44
- const incentiveBorrowApy = (0, moneymarket_1.aprToApy)((100 * constants_1.BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString();
45
43
  if (cAddresses[i].toLowerCase() === '0xc11b1268c1a384e55c48c2391d8d480264a3a7f4'.toLowerCase()) {
46
44
  symbol = 'WBTC Legacy';
47
45
  isWbtcLegacy = true;
@@ -51,10 +49,18 @@ const _getCompoundV2MarketsData = (provider, network) => __awaiter(void 0, void
51
49
  underlyingTokenAddress: market.underlyingTokenAddress,
52
50
  supplyRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(constants_1.BLOCKS_IN_A_YEAR).times(market.supplyRate.toString()).div(1e16).toString()).toString(),
53
51
  borrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(constants_1.BLOCKS_IN_A_YEAR).times(market.borrowRate.toString()).div(1e16).toString()).toString(),
54
- incentiveSupplyToken: 'COMP',
55
- incentiveBorrowToken: 'COMP',
56
- incentiveSupplyApy,
57
- incentiveBorrowApy,
52
+ supplyIncentives: [{
53
+ token: 'COMP',
54
+ apy: (0, moneymarket_1.aprToApy)((100 * constants_1.BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString(),
55
+ incentiveKind: common_1.IncentiveKind.Reward,
56
+ description: 'Eligible for protocol-level COMP incentives.',
57
+ }],
58
+ borrowIncentives: [{
59
+ token: 'COMP',
60
+ apy: (0, moneymarket_1.aprToApy)((100 * constants_1.BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString(),
61
+ incentiveKind: common_1.IncentiveKind.Reward,
62
+ description: 'Eligible for protocol-level COMP incentives.',
63
+ }],
58
64
  collateralFactor: new decimal_js_1.default(market.collateralFactor.toString()).div(1e18).toString(),
59
65
  marketLiquidity: (0, tokens_1.assetAmountInEth)(market.marketLiquidity.toString(), (0, utils_1.handleWbtcLegacy)(symbol)),
60
66
  utilization: new decimal_js_1.default(market.totalBorrow.toString()).div(totalSupply).times(100).toString(),
@@ -16,6 +16,7 @@ exports.getCompoundV3FullPositionData = exports.getCompoundV3AccountData = expor
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const tokens_1 = require("@defisaver/tokens");
18
18
  const contracts_1 = require("../contracts");
19
+ const common_1 = require("../types/common");
19
20
  const staking_1 = require("../staking");
20
21
  const utils_1 = require("../services/utils");
21
22
  const constants_1 = require("../constants");
@@ -49,8 +50,12 @@ const _getCompoundV3MarketsData = (provider, network, selectedMarket, defaultPro
49
50
  .map((coll) => (0, compoundHelpers_1.formatMarketData)(coll, network, baseAssetPrice));
50
51
  for (const coll of colls) {
51
52
  if (staking_1.STAKING_ASSETS.includes(coll.symbol)) {
52
- coll.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(coll.symbol);
53
- coll.incentiveSupplyToken = coll.symbol;
53
+ coll.supplyIncentives.push({
54
+ apy: yield (0, staking_1.getStakingApy)(coll.symbol),
55
+ token: coll.symbol,
56
+ incentiveKind: common_1.IncentiveKind.Staking,
57
+ description: `Native ${coll.symbol} yield.`,
58
+ });
54
59
  }
55
60
  }
56
61
  const base = (0, compoundHelpers_1.formatBaseData)(baseTokenInfo, network, baseAssetPrice);