@defisaver/positions-sdk 2.0.14 → 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 +63 -46
  6. package/cjs/aaveV3/merit.d.ts +17 -0
  7. package/cjs/aaveV3/merit.js +95 -0
  8. package/cjs/aaveV3/merkl.d.ts +19 -0
  9. package/cjs/aaveV3/merkl.js +98 -0
  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 +3 -8
  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 +64 -47
  46. package/esm/aaveV3/merit.d.ts +17 -0
  47. package/esm/aaveV3/merit.js +90 -0
  48. package/esm/aaveV3/merkl.d.ts +19 -0
  49. package/esm/aaveV3/merkl.js +92 -0
  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 +3 -8
  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 -488
  87. package/src/aaveV3/merit.ts +98 -0
  88. package/src/aaveV3/merkl.ts +141 -0
  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 -194
  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
@@ -15,8 +15,10 @@ import { AAVE_V3 } from '../markets/aave';
15
15
  import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
16
16
  import { ethToWeth, isEnabledOnBitmap, isLayer2Network, wethToEth, wethToEthByAddress, } from '../services/utils';
17
17
  import { getStakingApy, STAKING_ASSETS } from '../staking';
18
- import { NetworkNumber, } from '../types/common';
18
+ import { IncentiveKind, NetworkNumber, } from '../types/common';
19
19
  import { getViemProvider, setViemBlockNumber } from '../services/viem';
20
+ import { getMeritCampaigns } from './merit';
21
+ import { getAaveUnderlyingSymbol, getMerkleCampaigns } from './merkl';
20
22
  export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
21
23
  const { eModeCategoriesData } = extractedState;
22
24
  const usedAssetsValues = Object.values(usedAssets);
@@ -51,11 +53,13 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
51
53
  const marketAddress = market.providerAddress;
52
54
  const networksWithIncentives = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Opt, NetworkNumber.Linea];
53
55
  // eslint-disable-next-line prefer-const
54
- let [loanInfo, eModesInfo, isBorrowAllowed, rewardInfo] = yield Promise.all([
56
+ let [loanInfo, eModesInfo, isBorrowAllowed, rewardInfo, merkleRewardsMap, meritRewardsMap] = yield Promise.all([
55
57
  loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses], setViemBlockNumber(blockNumber)),
56
58
  loanInfoContract.read.getAllEmodes([marketAddress], setViemBlockNumber(blockNumber)),
57
59
  loanInfoContract.read.isBorrowAllowed([marketAddress], setViemBlockNumber(blockNumber)), // Used on L2s check for PriceOracleSentinel (mainnet will always return true)
58
60
  networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], setViemBlockNumber(blockNumber)) : null,
61
+ getMerkleCampaigns(network),
62
+ getMeritCampaigns(network, market.value),
59
63
  ]);
60
64
  isBorrowAllowed = isLayer2Network(network) ? isBorrowAllowed : true;
61
65
  const eModeCategoriesData = {};
@@ -137,47 +141,74 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
137
141
  isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled,
138
142
  isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled,
139
143
  aTokenAddress: tokenMarket.aTokenAddress,
144
+ vTokenAddress: tokenMarket.debtTokenAddress,
145
+ supplyIncentives: [],
146
+ borrowIncentives: [],
140
147
  });
141
148
  })));
142
149
  // Get incentives data
143
- yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
150
+ yield Promise.all(assetsData.map((_market, index) => __awaiter(this, void 0, void 0, function* () {
151
+ var _a, _b;
144
152
  /* eslint-disable no-param-reassign */
145
153
  // @ts-ignore
146
154
  const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
147
155
  const isStakingAsset = STAKING_ASSETS.includes(_market.symbol);
148
156
  if (isStakingAsset) {
149
- _market.incentiveSupplyApy = yield getStakingApy(_market.symbol);
150
- _market.incentiveSupplyToken = _market.symbol;
151
- if (!_market.supplyIncentives) {
152
- _market.supplyIncentives = [];
153
- }
157
+ const yieldApy = yield getStakingApy(_market.symbol);
154
158
  _market.supplyIncentives.push({
155
- apy: _market.incentiveSupplyApy || '0',
159
+ apy: yieldApy,
156
160
  token: _market.symbol,
157
- incentiveKind: 'staking',
161
+ incentiveKind: IncentiveKind.Staking,
162
+ description: `Native ${_market.symbol} yield.`,
158
163
  });
159
- }
160
- if (_market.canBeBorrowed && _market.incentiveSupplyApy) {
161
- _market.incentiveBorrowApy = _market.incentiveSupplyApy;
162
- _market.incentiveBorrowToken = _market.incentiveSupplyToken;
163
- if (!_market.borrowIncentives) {
164
- _market.borrowIncentives = [];
164
+ if (_market.canBeBorrowed) {
165
+ // when borrowing assets whose value increases over time
166
+ _market.borrowIncentives.push({
167
+ apy: new Dec(yieldApy).mul(-1).toString(),
168
+ token: _market.symbol,
169
+ incentiveKind: IncentiveKind.Reward,
170
+ description: `Due to the native yield of ${_market.symbol}, the value of the debt would increase over time.`,
171
+ });
165
172
  }
173
+ }
174
+ const aTokenAddress = _market.aTokenAddress.toLowerCase(); // DEV: Should aTokenAddress be in AaveV3AssetData type?
175
+ if ((_a = merkleRewardsMap[aTokenAddress]) === null || _a === void 0 ? void 0 : _a.supply) {
176
+ const { apy, rewardTokenSymbol, description, identifier, } = merkleRewardsMap[aTokenAddress].supply;
177
+ _market.supplyIncentives.push({
178
+ apy,
179
+ token: rewardTokenSymbol,
180
+ incentiveKind: IncentiveKind.Reward,
181
+ description,
182
+ eligibilityId: identifier,
183
+ });
184
+ }
185
+ const vTokenAddress = _market.vTokenAddress.toLowerCase(); // DEV: Should vTokenAddress be in AaveV3AssetData type?
186
+ if ((_b = merkleRewardsMap[vTokenAddress]) === null || _b === void 0 ? void 0 : _b.borrow) {
187
+ const { apy, rewardTokenSymbol, description, identifier, } = merkleRewardsMap[vTokenAddress].borrow;
166
188
  _market.borrowIncentives.push({
167
- apy: _market.incentiveBorrowApy,
168
- token: _market.incentiveBorrowToken,
169
- incentiveKind: 'reward',
189
+ apy,
190
+ token: rewardTokenSymbol,
191
+ incentiveKind: IncentiveKind.Reward,
192
+ description,
193
+ eligibilityId: identifier,
170
194
  });
171
195
  }
172
- if (_market.symbol === 'USDe') {
173
- const merklApy = yield getStakingApy(_market.symbol);
174
- if (!_market.supplyIncentives) {
175
- _market.supplyIncentives = [];
176
- }
196
+ if (meritRewardsMap.supply[_market.symbol]) {
197
+ const { apy, rewardTokenSymbol, description } = meritRewardsMap.supply[_market.symbol];
177
198
  _market.supplyIncentives.push({
178
- apy: merklApy || '0',
179
- token: _market.symbol,
180
- incentiveKind: 'reward',
199
+ apy,
200
+ token: rewardTokenSymbol,
201
+ incentiveKind: IncentiveKind.Reward,
202
+ description,
203
+ });
204
+ }
205
+ if (meritRewardsMap.borrow[_market.symbol]) {
206
+ const { apy, rewardTokenSymbol, description } = meritRewardsMap.borrow[_market.symbol];
207
+ _market.borrowIncentives.push({
208
+ apy,
209
+ token: rewardTokenSymbol,
210
+ incentiveKind: IncentiveKind.Reward,
211
+ description,
181
212
  });
182
213
  }
183
214
  if (!rewardForMarket)
@@ -187,10 +218,7 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
187
218
  if (supplyRewardData) {
188
219
  if (+(supplyRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
189
220
  return;
190
- _market.incentiveSupplyToken = supplyRewardData.rewardTokenSymbol;
191
221
  // reward token is aave asset
192
- if (supplyRewardData.rewardTokenSymbol.startsWith('a') && supplyRewardData.rewardTokenSymbol.includes(_market.symbol))
193
- _market.incentiveSupplyToken = _market.symbol;
194
222
  const supplyEmissionPerSecond = supplyRewardData.emissionPerSecond;
195
223
  const supplyRewardPrice = new Dec(supplyRewardData.rewardPriceFeed).div(Math.pow(10, +supplyRewardData.priceFeedDecimals))
196
224
  .toString();
@@ -200,15 +228,11 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
200
228
  .div(_market.price)
201
229
  .div(_market.totalSupply)
202
230
  .toString();
203
- _market.incentiveSupplyApy = new Dec(_market.incentiveSupplyApy || '0').add(rewardApy)
204
- .toString();
205
- if (!_market.supplyIncentives) {
206
- _market.supplyIncentives = [];
207
- }
208
231
  _market.supplyIncentives.push({
209
- token: supplyRewardData.rewardTokenSymbol,
232
+ token: getAaveUnderlyingSymbol(supplyRewardData.rewardTokenSymbol),
210
233
  apy: rewardApy,
211
- incentiveKind: 'reward',
234
+ incentiveKind: IncentiveKind.Reward,
235
+ description: 'Eligible for protocol-level incentives.',
212
236
  });
213
237
  }
214
238
  });
@@ -217,9 +241,6 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
217
241
  if (borrowRewardData) {
218
242
  if (+(borrowRewardData.emissionEndTimestamp.toString()) * 1000 < Date.now())
219
243
  return;
220
- _market.incentiveBorrowToken = borrowRewardData.rewardTokenSymbol;
221
- if (borrowRewardData.rewardTokenSymbol.startsWith('a') && borrowRewardData.rewardTokenSymbol.includes(_market.symbol))
222
- _market.incentiveBorrowToken = _market.symbol;
223
244
  const supplyEmissionPerSecond = borrowRewardData.emissionPerSecond;
224
245
  const supplyRewardPrice = new Dec(borrowRewardData.rewardPriceFeed).div(Math.pow(10, +borrowRewardData.priceFeedDecimals))
225
246
  .toString();
@@ -229,15 +250,11 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
229
250
  .div(_market.price)
230
251
  .div(_market.totalBorrowVar)
231
252
  .toString();
232
- _market.incentiveBorrowApy = new Dec(_market.incentiveBorrowApy || '0').add(rewardApy)
233
- .toString();
234
- if (!_market.borrowIncentives) {
235
- _market.borrowIncentives = [];
236
- }
237
253
  _market.borrowIncentives.push({
238
- token: borrowRewardData.rewardTokenSymbol,
254
+ token: getAaveUnderlyingSymbol(borrowRewardData.rewardTokenSymbol),
239
255
  apy: rewardApy,
240
- incentiveKind: 'reward',
256
+ incentiveKind: IncentiveKind.Reward,
257
+ description: 'Eligible for protocol-level incentives.',
241
258
  });
242
259
  }
243
260
  });
@@ -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,90 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { DEFAULT_TIMEOUT } from '../services/utils';
11
+ import { NetworkNumber } from '../types/common';
12
+ import { aprToApy } from '../moneymarket';
13
+ import { AaveVersions } from '../types';
14
+ /**
15
+ * Maps API keys to reward data & actions - hardcoded and needs to be maintained actively.
16
+ * Mapping based on Aave interface implementation: https://github.com/aave/interface/blob/main/src/hooks/useMeritIncentives.ts
17
+ * Active campaigns found here: https://apps.aavechan.com/merit
18
+ */
19
+ const MERIT_DATA_MAP = {
20
+ [NetworkNumber.Eth]: {
21
+ [AaveVersions.AaveV3]: {
22
+ 'ethereum-supply-ethx': { rewardTokenSymbol: 'SD', action: 'supply', supplyTokens: ['ETHx'] },
23
+ 'ethereum-supply-rlusd': { rewardTokenSymbol: 'aEthRLUSD', action: 'supply', supplyTokens: ['RLUSD'] },
24
+ // Campaign disabled here as it's present on Merkl API:
25
+ // 'ethereum-borrow-eurc': { rewardTokenSymbol: 'aEthEURC', action: 'borrow', borrowTokens: ['EURC'] },
26
+ },
27
+ [AaveVersions.AaveV3Lido]: {},
28
+ [AaveVersions.AaveV3Etherfi]: {},
29
+ },
30
+ [NetworkNumber.Arb]: {
31
+ [AaveVersions.AaveV3]: {},
32
+ },
33
+ [NetworkNumber.Opt]: {
34
+ [AaveVersions.AaveV3]: {},
35
+ },
36
+ [NetworkNumber.Base]: {
37
+ [AaveVersions.AaveV3]: {
38
+ 'base-borrow-usdc': { rewardTokenSymbol: 'USDC', action: 'borrow', borrowTokens: ['USDC'] },
39
+ 'base-borrow-gho': { rewardTokenSymbol: 'GHO', action: 'borrow', borrowTokens: ['GHO'] },
40
+ 'base-borrow-eurc': { rewardTokenSymbol: 'EURC', action: 'borrow', borrowTokens: ['EURC'] },
41
+ },
42
+ },
43
+ [NetworkNumber.Linea]: {
44
+ [AaveVersions.AaveV3]: {},
45
+ },
46
+ };
47
+ /**
48
+ * Fetches merit rewards data from Aave API
49
+ */
50
+ export const fetchMeritRewardsData = () => __awaiter(void 0, void 0, void 0, function* () {
51
+ try {
52
+ const response = yield fetch('https://apps.aavechan.com/api/merit/aprs', {
53
+ signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
54
+ });
55
+ const data = yield response.json();
56
+ return data.currentAPR.actionsAPR;
57
+ }
58
+ catch (error) {
59
+ console.error('Failed to fetch merit rewards data:', error);
60
+ return {};
61
+ }
62
+ });
63
+ export const getMeritCampaigns = (chainId, market) => __awaiter(void 0, void 0, void 0, function* () {
64
+ var _a;
65
+ const meritData = yield fetchMeritRewardsData();
66
+ const relevantCampaigns = {
67
+ supply: {},
68
+ borrow: {},
69
+ };
70
+ Object.entries(((_a = MERIT_DATA_MAP[chainId]) === null || _a === void 0 ? void 0 : _a[market]) || {})
71
+ .filter(([key, rewardData]) => !!meritData[key])
72
+ .forEach(([key, rewardData]) => {
73
+ var _a, _b;
74
+ const apr = meritData[key];
75
+ if (!apr)
76
+ return;
77
+ const reward = {
78
+ rewardTokenSymbol: rewardData.rewardTokenSymbol,
79
+ apy: aprToApy(apr).toString(),
80
+ description: `Eligible for Merit rewards in ${rewardData.rewardTokenSymbol}. ${rewardData.message ? `\n${rewardData.message}` : ''}`,
81
+ };
82
+ (_a = rewardData.supplyTokens) === null || _a === void 0 ? void 0 : _a.forEach(token => {
83
+ relevantCampaigns.supply[token] = reward;
84
+ });
85
+ (_b = rewardData.borrowTokens) === null || _b === void 0 ? void 0 : _b.forEach(token => {
86
+ relevantCampaigns.borrow[token] = reward;
87
+ });
88
+ });
89
+ return relevantCampaigns;
90
+ });
@@ -0,0 +1,19 @@
1
+ import { EthAddress, NetworkNumber } from '../types/common';
2
+ type RewardInfo = {
3
+ apy: string;
4
+ rewardTokenSymbol: string;
5
+ description: string;
6
+ identifier: string;
7
+ };
8
+ type MerkleRewardMap = Record<EthAddress, {
9
+ supply?: RewardInfo;
10
+ borrow?: RewardInfo;
11
+ }>;
12
+ export declare const getAaveUnderlyingSymbol: (_symbol?: string) => any;
13
+ /**
14
+ * aEthLidoUSDC -> aUSDC
15
+ * USDC -> USDC
16
+ */
17
+ export declare const formatAaveAsset: (_symbol: string) => string;
18
+ export declare const getMerkleCampaigns: (chainId: NetworkNumber) => Promise<MerkleRewardMap>;
19
+ export {};
@@ -0,0 +1,92 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { aprToApy } from '../moneymarket';
11
+ import { DEFAULT_TIMEOUT, wethToEth } from '../services/utils';
12
+ var OpportunityAction;
13
+ (function (OpportunityAction) {
14
+ OpportunityAction["LEND"] = "LEND";
15
+ OpportunityAction["BORROW"] = "BORROW";
16
+ })(OpportunityAction || (OpportunityAction = {}));
17
+ var OpportunityStatus;
18
+ (function (OpportunityStatus) {
19
+ OpportunityStatus["LIVE"] = "LIVE";
20
+ OpportunityStatus["PAST"] = "PAST";
21
+ OpportunityStatus["UPCOMING"] = "UPCOMING";
22
+ })(OpportunityStatus || (OpportunityStatus = {}));
23
+ export const getAaveUnderlyingSymbol = (_symbol = '') => {
24
+ let symbol = _symbol
25
+ .replace(/^aEthLido/, '')
26
+ .replace(/^aEthEtherFi/, '')
27
+ .replace(/^aEth/, '')
28
+ .replace(/^aArb/, '')
29
+ .replace(/^aOpt/, '')
30
+ .replace(/^aBas/, '')
31
+ .replace(/^aLin/, '');
32
+ if (symbol.startsWith('a'))
33
+ symbol = symbol.slice(1);
34
+ return wethToEth(symbol);
35
+ };
36
+ /**
37
+ * aEthLidoUSDC -> aUSDC
38
+ * USDC -> USDC
39
+ */
40
+ export const formatAaveAsset = (_symbol) => {
41
+ if (_symbol.startsWith('a')) {
42
+ return `a${getAaveUnderlyingSymbol(_symbol)}`;
43
+ }
44
+ return _symbol;
45
+ };
46
+ export const getMerkleCampaigns = (chainId) => __awaiter(void 0, void 0, void 0, function* () {
47
+ try {
48
+ const res = yield fetch('https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave', {
49
+ signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
50
+ });
51
+ if (!res.ok)
52
+ throw new Error('Failed to fetch Merkle campaigns');
53
+ const opportunities = yield res.json();
54
+ const relevantOpportunities = opportunities
55
+ .filter((o) => o.chainId === chainId)
56
+ .filter((o) => o.status === OpportunityStatus.LIVE);
57
+ return relevantOpportunities.reduce((acc, opportunity) => {
58
+ var _a, _b;
59
+ const rewardToken = opportunity.rewardsRecord.breakdowns[0].token;
60
+ const description = `Eligible for ${formatAaveAsset(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
61
+ if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
62
+ const supplyAToken = (_a = opportunity.explorerAddress) === null || _a === void 0 ? void 0 : _a.toLowerCase();
63
+ if (!acc[supplyAToken])
64
+ acc[supplyAToken] = {};
65
+ acc[supplyAToken].supply = {
66
+ apy: aprToApy(opportunity.apr),
67
+ // rewardToken: rewardToken.address,
68
+ rewardTokenSymbol: rewardToken.symbol,
69
+ description,
70
+ identifier: opportunity.identifier,
71
+ };
72
+ }
73
+ if (opportunity.action === OpportunityAction.BORROW && opportunity.explorerAddress) {
74
+ const borrowAToken = (_b = opportunity.explorerAddress) === null || _b === void 0 ? void 0 : _b.toLowerCase();
75
+ if (!acc[borrowAToken])
76
+ acc[borrowAToken] = {};
77
+ acc[borrowAToken].borrow = {
78
+ apy: aprToApy(opportunity.apr),
79
+ // rewardToken: rewardToken.address,
80
+ rewardTokenSymbol: rewardToken.symbol,
81
+ description,
82
+ identifier: opportunity.identifier,
83
+ };
84
+ }
85
+ return acc;
86
+ }, {});
87
+ }
88
+ catch (e) {
89
+ console.error('Failed to fetch Merkle campaigns', e);
90
+ return {};
91
+ }
92
+ });
@@ -12,6 +12,7 @@ import Dec from 'decimal.js';
12
12
  import { BLOCKS_IN_A_YEAR } from '../constants';
13
13
  import { aprToApy } from '../moneymarket';
14
14
  import { compareAddresses, handleWbtcLegacy, wethToEth } from '../services/utils';
15
+ import { IncentiveKind, } from '../types/common';
15
16
  import { CompoundLoanInfoContractViem, ComptrollerContractViem } from '../contracts';
16
17
  import { compoundV2CollateralAssets } from '../markets';
17
18
  import { getCompoundV2AggregatedData } from '../helpers/compoundHelpers';
@@ -33,9 +34,6 @@ export const _getCompoundV2MarketsData = (provider, network) => __awaiter(void 0
33
34
  const compBorrowSpeeds = market.compBorrowSpeeds.toString();
34
35
  const assetPrice = market.price.toString();
35
36
  const pricePrecisionDiff = 18 - getAssetInfo(getAssetInfoByAddress(cAddresses[i]).underlyingAsset).decimals;
36
- // compSupplySpeeds/compBorrowSpeeds is per block per market (borrow & supply are separate markets)
37
- const incentiveSupplyApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString();
38
- const incentiveBorrowApy = aprToApy((100 * BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString();
39
37
  if (cAddresses[i].toLowerCase() === '0xc11b1268c1a384e55c48c2391d8d480264a3a7f4'.toLowerCase()) {
40
38
  symbol = 'WBTC Legacy';
41
39
  isWbtcLegacy = true;
@@ -45,10 +43,18 @@ export const _getCompoundV2MarketsData = (provider, network) => __awaiter(void 0
45
43
  underlyingTokenAddress: market.underlyingTokenAddress,
46
44
  supplyRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.supplyRate.toString()).div(1e16).toString()).toString(),
47
45
  borrowRate: aprToApy(new Dec(BLOCKS_IN_A_YEAR).times(market.borrowRate.toString()).div(1e16).toString()).toString(),
48
- incentiveSupplyToken: 'COMP',
49
- incentiveBorrowToken: 'COMP',
50
- incentiveSupplyApy,
51
- incentiveBorrowApy,
46
+ supplyIncentives: [{
47
+ token: 'COMP',
48
+ apy: aprToApy((100 * BLOCKS_IN_A_YEAR * +compSupplySpeeds * +compPrice) / +assetPrice / +totalSupply).toString(),
49
+ incentiveKind: IncentiveKind.Reward,
50
+ description: 'Eligible for protocol-level COMP incentives.',
51
+ }],
52
+ borrowIncentives: [{
53
+ token: 'COMP',
54
+ apy: aprToApy((100 * BLOCKS_IN_A_YEAR * +compBorrowSpeeds * +compPrice) / +assetPrice / +totalBorrow).toString(),
55
+ incentiveKind: IncentiveKind.Reward,
56
+ description: 'Eligible for protocol-level COMP incentives.',
57
+ }],
52
58
  collateralFactor: new Dec(market.collateralFactor.toString()).div(1e18).toString(),
53
59
  marketLiquidity: assetAmountInEth(market.marketLiquidity.toString(), handleWbtcLegacy(symbol)),
54
60
  utilization: new Dec(market.totalBorrow.toString()).div(totalSupply).times(100).toString(),
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import Dec from 'decimal.js';
11
11
  import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress, } from '@defisaver/tokens';
12
12
  import { CompV3ViewContractViem } from '../contracts';
13
+ import { IncentiveKind, } from '../types/common';
13
14
  import { getStakingApy, STAKING_ASSETS, } from '../staking';
14
15
  import { ethToWeth, wethToEth } from '../services/utils';
15
16
  import { ZERO_ADDRESS } from '../constants';
@@ -43,8 +44,12 @@ export const _getCompoundV3MarketsData = (provider, network, selectedMarket, def
43
44
  .map((coll) => formatMarketData(coll, network, baseAssetPrice));
44
45
  for (const coll of colls) {
45
46
  if (STAKING_ASSETS.includes(coll.symbol)) {
46
- coll.incentiveSupplyApy = yield getStakingApy(coll.symbol);
47
- coll.incentiveSupplyToken = coll.symbol;
47
+ coll.supplyIncentives.push({
48
+ apy: yield getStakingApy(coll.symbol),
49
+ token: coll.symbol,
50
+ incentiveKind: IncentiveKind.Staking,
51
+ description: `Native ${coll.symbol} yield.`,
52
+ });
48
53
  }
49
54
  }
50
55
  const base = formatBaseData(baseTokenInfo, network, baseAssetPrice);