@defisaver/positions-sdk 2.1.54 → 2.1.56-dev-exposure

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 (184) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/README.md +64 -64
  4. package/cjs/aaveV3/index.d.ts +1 -0
  5. package/cjs/aaveV3/index.js +5 -2
  6. package/cjs/compoundV2/index.d.ts +1 -0
  7. package/cjs/compoundV2/index.js +1 -0
  8. package/cjs/compoundV3/index.d.ts +1 -0
  9. package/cjs/compoundV3/index.js +1 -0
  10. package/cjs/eulerV2/index.d.ts +1 -0
  11. package/cjs/eulerV2/index.js +1 -0
  12. package/cjs/fluid/index.d.ts +3 -0
  13. package/cjs/helpers/aaveHelpers/index.js +1 -0
  14. package/cjs/helpers/compoundHelpers/index.js +2 -0
  15. package/cjs/helpers/curveUsdHelpers/index.js +1 -0
  16. package/cjs/helpers/eulerHelpers/index.js +1 -0
  17. package/cjs/helpers/fluidHelpers/index.js +1 -0
  18. package/cjs/helpers/liquityV2Helpers/index.js +1 -0
  19. package/cjs/helpers/llamaLendHelpers/index.js +1 -0
  20. package/cjs/helpers/morphoBlueHelpers/index.js +67 -66
  21. package/cjs/helpers/sparkHelpers/index.js +1 -0
  22. package/cjs/liquity/index.js +2 -0
  23. package/cjs/maker/index.js +2 -0
  24. package/cjs/markets/morphoBlue/index.d.ts +4 -0
  25. package/cjs/markets/morphoBlue/index.js +36 -2
  26. package/cjs/moneymarket/moneymarketCommonService.d.ts +1 -0
  27. package/cjs/moneymarket/moneymarketCommonService.js +8 -1
  28. package/cjs/savings/morphoVaults/index.js +17 -17
  29. package/cjs/spark/index.d.ts +1 -0
  30. package/cjs/spark/index.js +1 -0
  31. package/cjs/types/aave.d.ts +1 -0
  32. package/cjs/types/common.d.ts +1 -0
  33. package/cjs/types/compound.d.ts +1 -0
  34. package/cjs/types/curveUsd.d.ts +2 -0
  35. package/cjs/types/euler.d.ts +1 -0
  36. package/cjs/types/fluid.d.ts +1 -0
  37. package/cjs/types/liquity.d.ts +1 -0
  38. package/cjs/types/liquityV2.d.ts +2 -0
  39. package/cjs/types/llamaLend.d.ts +2 -0
  40. package/cjs/types/maker.d.ts +1 -0
  41. package/cjs/types/morphoBlue.d.ts +4 -0
  42. package/cjs/types/morphoBlue.js +2 -0
  43. package/cjs/types/spark.d.ts +1 -0
  44. package/esm/aaveV3/index.d.ts +1 -0
  45. package/esm/aaveV3/index.js +5 -2
  46. package/esm/compoundV2/index.d.ts +1 -0
  47. package/esm/compoundV2/index.js +1 -0
  48. package/esm/compoundV3/index.d.ts +1 -0
  49. package/esm/compoundV3/index.js +1 -0
  50. package/esm/eulerV2/index.d.ts +1 -0
  51. package/esm/eulerV2/index.js +1 -0
  52. package/esm/fluid/index.d.ts +3 -0
  53. package/esm/helpers/aaveHelpers/index.js +2 -1
  54. package/esm/helpers/compoundHelpers/index.js +3 -1
  55. package/esm/helpers/curveUsdHelpers/index.js +2 -1
  56. package/esm/helpers/eulerHelpers/index.js +2 -1
  57. package/esm/helpers/fluidHelpers/index.js +2 -1
  58. package/esm/helpers/liquityV2Helpers/index.js +2 -1
  59. package/esm/helpers/llamaLendHelpers/index.js +2 -1
  60. package/esm/helpers/morphoBlueHelpers/index.js +68 -67
  61. package/esm/helpers/sparkHelpers/index.js +2 -1
  62. package/esm/liquity/index.js +2 -0
  63. package/esm/maker/index.js +2 -0
  64. package/esm/markets/morphoBlue/index.d.ts +4 -0
  65. package/esm/markets/morphoBlue/index.js +32 -0
  66. package/esm/moneymarket/moneymarketCommonService.d.ts +1 -0
  67. package/esm/moneymarket/moneymarketCommonService.js +6 -0
  68. package/esm/savings/morphoVaults/index.js +17 -17
  69. package/esm/spark/index.d.ts +1 -0
  70. package/esm/spark/index.js +1 -0
  71. package/esm/types/aave.d.ts +1 -0
  72. package/esm/types/common.d.ts +1 -0
  73. package/esm/types/compound.d.ts +1 -0
  74. package/esm/types/curveUsd.d.ts +2 -0
  75. package/esm/types/euler.d.ts +1 -0
  76. package/esm/types/fluid.d.ts +1 -0
  77. package/esm/types/liquity.d.ts +1 -0
  78. package/esm/types/liquityV2.d.ts +2 -0
  79. package/esm/types/llamaLend.d.ts +2 -0
  80. package/esm/types/maker.d.ts +1 -0
  81. package/esm/types/morphoBlue.d.ts +4 -0
  82. package/esm/types/morphoBlue.js +2 -0
  83. package/esm/types/spark.d.ts +1 -0
  84. package/package.json +48 -48
  85. package/src/aaveV2/index.ts +240 -240
  86. package/src/aaveV3/index.ts +638 -635
  87. package/src/aaveV3/merit.ts +97 -97
  88. package/src/aaveV3/merkl.ts +74 -74
  89. package/src/claiming/aaveV3.ts +154 -154
  90. package/src/claiming/compV3.ts +22 -22
  91. package/src/claiming/ethena.ts +61 -61
  92. package/src/claiming/index.ts +12 -12
  93. package/src/claiming/king.ts +66 -66
  94. package/src/claiming/morphoBlue.ts +118 -118
  95. package/src/claiming/spark.ts +225 -225
  96. package/src/compoundV2/index.ts +245 -244
  97. package/src/compoundV3/index.ts +275 -274
  98. package/src/config/contracts.ts +1320 -1320
  99. package/src/constants/index.ts +10 -10
  100. package/src/contracts.ts +171 -171
  101. package/src/curveUsd/index.ts +254 -254
  102. package/src/eulerV2/index.ts +325 -324
  103. package/src/exchange/index.ts +25 -25
  104. package/src/fluid/index.ts +1800 -1800
  105. package/src/helpers/aaveHelpers/index.ts +203 -202
  106. package/src/helpers/compoundHelpers/index.ts +278 -276
  107. package/src/helpers/curveUsdHelpers/index.ts +44 -40
  108. package/src/helpers/eulerHelpers/index.ts +230 -229
  109. package/src/helpers/fluidHelpers/index.ts +338 -335
  110. package/src/helpers/index.ts +10 -10
  111. package/src/helpers/liquityV2Helpers/index.ts +85 -82
  112. package/src/helpers/llamaLendHelpers/index.ts +56 -53
  113. package/src/helpers/makerHelpers/index.ts +52 -52
  114. package/src/helpers/morphoBlueHelpers/index.ts +406 -405
  115. package/src/helpers/sparkHelpers/index.ts +170 -169
  116. package/src/index.ts +49 -49
  117. package/src/liquity/index.ts +161 -159
  118. package/src/liquityV2/index.ts +703 -703
  119. package/src/llamaLend/index.ts +305 -305
  120. package/src/maker/index.ts +225 -223
  121. package/src/markets/aave/index.ts +118 -118
  122. package/src/markets/aave/marketAssets.ts +54 -54
  123. package/src/markets/compound/index.ts +243 -243
  124. package/src/markets/compound/marketsAssets.ts +97 -97
  125. package/src/markets/curveUsd/index.ts +69 -69
  126. package/src/markets/euler/index.ts +26 -26
  127. package/src/markets/fluid/index.ts +2900 -2900
  128. package/src/markets/index.ts +25 -25
  129. package/src/markets/liquityV2/index.ts +102 -102
  130. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  131. package/src/markets/llamaLend/index.ts +235 -235
  132. package/src/markets/morphoBlue/index.ts +1020 -988
  133. package/src/markets/spark/index.ts +29 -29
  134. package/src/markets/spark/marketAssets.ts +12 -12
  135. package/src/moneymarket/moneymarketCommonService.ts +90 -84
  136. package/src/morphoBlue/index.ts +274 -274
  137. package/src/portfolio/index.ts +586 -586
  138. package/src/savings/index.ts +95 -95
  139. package/src/savings/makerDsr/index.ts +53 -53
  140. package/src/savings/makerDsr/options.ts +9 -9
  141. package/src/savings/morphoVaults/index.ts +80 -80
  142. package/src/savings/morphoVaults/options.ts +193 -193
  143. package/src/savings/skyOptions/index.ts +95 -95
  144. package/src/savings/skyOptions/options.ts +10 -10
  145. package/src/savings/sparkSavingsVaults/index.ts +60 -60
  146. package/src/savings/sparkSavingsVaults/options.ts +35 -35
  147. package/src/savings/yearnV3Vaults/index.ts +61 -61
  148. package/src/savings/yearnV3Vaults/options.ts +55 -55
  149. package/src/savings/yearnVaults/index.ts +73 -73
  150. package/src/savings/yearnVaults/options.ts +32 -32
  151. package/src/services/priceService.ts +278 -278
  152. package/src/services/utils.ts +115 -115
  153. package/src/services/viem.ts +57 -57
  154. package/src/setup.ts +8 -8
  155. package/src/spark/index.ts +460 -459
  156. package/src/staking/eligibility.ts +53 -53
  157. package/src/staking/index.ts +1 -1
  158. package/src/staking/staking.ts +192 -192
  159. package/src/types/aave.ts +200 -199
  160. package/src/types/claiming.ts +114 -114
  161. package/src/types/common.ts +116 -115
  162. package/src/types/compound.ts +146 -145
  163. package/src/types/curveUsd.ts +125 -123
  164. package/src/types/euler.ts +177 -176
  165. package/src/types/fluid.ts +486 -485
  166. package/src/types/index.ts +15 -15
  167. package/src/types/liquity.ts +31 -30
  168. package/src/types/liquityV2.ts +130 -128
  169. package/src/types/llamaLend.ts +163 -161
  170. package/src/types/maker.ts +64 -63
  171. package/src/types/merit.ts +1 -1
  172. package/src/types/merkl.ts +70 -70
  173. package/src/types/morphoBlue.ts +206 -202
  174. package/src/types/portfolio.ts +60 -60
  175. package/src/types/savings/index.ts +23 -23
  176. package/src/types/savings/makerDsr.ts +13 -13
  177. package/src/types/savings/morphoVaults.ts +32 -32
  178. package/src/types/savings/sky.ts +14 -14
  179. package/src/types/savings/sparkSavingsVaults.ts +15 -15
  180. package/src/types/savings/yearnV3Vaults.ts +17 -17
  181. package/src/types/savings/yearnVaults.ts +14 -14
  182. package/src/types/spark.ts +136 -135
  183. package/src/umbrella/index.ts +69 -69
  184. package/src/umbrella/umbrellaUtils.ts +29 -29
@@ -1,97 +1,97 @@
1
-
2
- import { DEFAULT_TIMEOUT } from '../services/utils';
3
- import { NetworkNumber } from '../types/common';
4
- import { aprToApy } from '../moneymarket';
5
- import { AaveVersions, MeritTokenRewardMap } from '../types';
6
-
7
- /**
8
- * Maps API keys to reward data & actions - hardcoded and needs to be maintained actively.
9
- * Mapping based on Aave interface implementation: https://github.com/aave/interface/blob/main/src/hooks/useMeritIncentives.ts
10
- * Active campaigns found here: https://apps.aavechan.com/merit
11
- */
12
- const MERIT_DATA_MAP:
13
- Record<
14
- NetworkNumber,
15
- Partial<Record<
16
- AaveVersions,
17
- Record<string, {
18
- rewardTokenSymbol: string;
19
- action: 'supply' | 'borrow' | 'stake';
20
- message?: string;
21
- supplyTokens?: string[],
22
- borrowTokens?: string[],
23
- }>
24
- >>
25
- > = {
26
- [NetworkNumber.Eth]: {
27
- [AaveVersions.AaveV3]: {
28
- 'ethereum-supply-ethx': { rewardTokenSymbol: 'SD', action: 'supply', supplyTokens: ['ETHx'] },
29
- 'ethereum-supply-rlusd': { rewardTokenSymbol: 'aEthRLUSD', action: 'supply', supplyTokens: ['RLUSD'] },
30
- // Campaign disabled here as it's present on Merkl API:
31
- // 'ethereum-borrow-eurc': { rewardTokenSymbol: 'aEthEURC', action: 'borrow', borrowTokens: ['EURC'] },
32
- },
33
- [AaveVersions.AaveV3Lido]: {},
34
- [AaveVersions.AaveV3Etherfi]: {},
35
- },
36
- [NetworkNumber.Arb]: {
37
- [AaveVersions.AaveV3]: {},
38
- },
39
- [NetworkNumber.Opt]: {
40
- [AaveVersions.AaveV3]: {},
41
- },
42
- [NetworkNumber.Base]: {
43
- [AaveVersions.AaveV3]: {
44
- 'base-borrow-usdc': { rewardTokenSymbol: 'USDC', action: 'borrow', borrowTokens: ['USDC'] },
45
- 'base-borrow-gho': { rewardTokenSymbol: 'GHO', action: 'borrow', borrowTokens: ['GHO'] },
46
- 'base-borrow-eurc': { rewardTokenSymbol: 'EURC', action: 'borrow', borrowTokens: ['EURC'] },
47
- },
48
- },
49
- [NetworkNumber.Linea]: {
50
- [AaveVersions.AaveV3]: {},
51
- },
52
- [NetworkNumber.Plasma]: {
53
- [AaveVersions.AaveV3]: {},
54
- },
55
- };
56
-
57
- /**
58
- * Fetches merit rewards data from Aave API
59
- */
60
- export const fetchMeritRewardsData = async (): Promise<Record<string, number | null>> => {
61
- try {
62
- const response = await fetch('https://apps.aavechan.com/api/merit/aprs', {
63
- signal: AbortSignal.timeout(5000),
64
- });
65
- const data = await response.json();
66
- return data.currentAPR.actionsAPR as Record<string, number | null>;
67
- } catch (error) {
68
- console.error('External API Failure: Failed to fetch merit rewards data:', error);
69
- return {};
70
- }
71
- };
72
-
73
- export const getMeritCampaigns = async (chainId: NetworkNumber, market: AaveVersions): Promise<MeritTokenRewardMap> => {
74
- const meritData = await fetchMeritRewardsData();
75
- const relevantCampaigns = {
76
- supply: {},
77
- borrow: {},
78
- } as MeritTokenRewardMap;
79
- Object.entries(MERIT_DATA_MAP[chainId]?.[market] || {})
80
- .filter(([key, rewardData]) => !!meritData[key])
81
- .forEach(([key, rewardData]) => {
82
- const apr = meritData[key]!;
83
- if (!apr) return;
84
- const reward = {
85
- rewardTokenSymbol: rewardData.rewardTokenSymbol,
86
- apy: aprToApy(apr).toString(),
87
- description: `Eligible for Merit rewards in ${rewardData.rewardTokenSymbol}. ${rewardData.message ? `\n${rewardData.message}` : ''}`,
88
- };
89
- rewardData.supplyTokens?.forEach(token => {
90
- relevantCampaigns.supply[token] = reward;
91
- });
92
- rewardData.borrowTokens?.forEach(token => {
93
- relevantCampaigns.borrow[token] = reward;
94
- });
95
- });
96
- return relevantCampaigns;
97
- };
1
+
2
+ import { DEFAULT_TIMEOUT } from '../services/utils';
3
+ import { NetworkNumber } from '../types/common';
4
+ import { aprToApy } from '../moneymarket';
5
+ import { AaveVersions, MeritTokenRewardMap } from '../types';
6
+
7
+ /**
8
+ * Maps API keys to reward data & actions - hardcoded and needs to be maintained actively.
9
+ * Mapping based on Aave interface implementation: https://github.com/aave/interface/blob/main/src/hooks/useMeritIncentives.ts
10
+ * Active campaigns found here: https://apps.aavechan.com/merit
11
+ */
12
+ const MERIT_DATA_MAP:
13
+ Record<
14
+ NetworkNumber,
15
+ Partial<Record<
16
+ AaveVersions,
17
+ Record<string, {
18
+ rewardTokenSymbol: string;
19
+ action: 'supply' | 'borrow' | 'stake';
20
+ message?: string;
21
+ supplyTokens?: string[],
22
+ borrowTokens?: string[],
23
+ }>
24
+ >>
25
+ > = {
26
+ [NetworkNumber.Eth]: {
27
+ [AaveVersions.AaveV3]: {
28
+ 'ethereum-supply-ethx': { rewardTokenSymbol: 'SD', action: 'supply', supplyTokens: ['ETHx'] },
29
+ 'ethereum-supply-rlusd': { rewardTokenSymbol: 'aEthRLUSD', action: 'supply', supplyTokens: ['RLUSD'] },
30
+ // Campaign disabled here as it's present on Merkl API:
31
+ // 'ethereum-borrow-eurc': { rewardTokenSymbol: 'aEthEURC', action: 'borrow', borrowTokens: ['EURC'] },
32
+ },
33
+ [AaveVersions.AaveV3Lido]: {},
34
+ [AaveVersions.AaveV3Etherfi]: {},
35
+ },
36
+ [NetworkNumber.Arb]: {
37
+ [AaveVersions.AaveV3]: {},
38
+ },
39
+ [NetworkNumber.Opt]: {
40
+ [AaveVersions.AaveV3]: {},
41
+ },
42
+ [NetworkNumber.Base]: {
43
+ [AaveVersions.AaveV3]: {
44
+ 'base-borrow-usdc': { rewardTokenSymbol: 'USDC', action: 'borrow', borrowTokens: ['USDC'] },
45
+ 'base-borrow-gho': { rewardTokenSymbol: 'GHO', action: 'borrow', borrowTokens: ['GHO'] },
46
+ 'base-borrow-eurc': { rewardTokenSymbol: 'EURC', action: 'borrow', borrowTokens: ['EURC'] },
47
+ },
48
+ },
49
+ [NetworkNumber.Linea]: {
50
+ [AaveVersions.AaveV3]: {},
51
+ },
52
+ [NetworkNumber.Plasma]: {
53
+ [AaveVersions.AaveV3]: {},
54
+ },
55
+ };
56
+
57
+ /**
58
+ * Fetches merit rewards data from Aave API
59
+ */
60
+ export const fetchMeritRewardsData = async (): Promise<Record<string, number | null>> => {
61
+ try {
62
+ const response = await fetch('https://apps.aavechan.com/api/merit/aprs', {
63
+ signal: AbortSignal.timeout(5000),
64
+ });
65
+ const data = await response.json();
66
+ return data.currentAPR.actionsAPR as Record<string, number | null>;
67
+ } catch (error) {
68
+ console.error('External API Failure: Failed to fetch merit rewards data:', error);
69
+ return {};
70
+ }
71
+ };
72
+
73
+ export const getMeritCampaigns = async (chainId: NetworkNumber, market: AaveVersions): Promise<MeritTokenRewardMap> => {
74
+ const meritData = await fetchMeritRewardsData();
75
+ const relevantCampaigns = {
76
+ supply: {},
77
+ borrow: {},
78
+ } as MeritTokenRewardMap;
79
+ Object.entries(MERIT_DATA_MAP[chainId]?.[market] || {})
80
+ .filter(([key, rewardData]) => !!meritData[key])
81
+ .forEach(([key, rewardData]) => {
82
+ const apr = meritData[key]!;
83
+ if (!apr) return;
84
+ const reward = {
85
+ rewardTokenSymbol: rewardData.rewardTokenSymbol,
86
+ apy: aprToApy(apr).toString(),
87
+ description: `Eligible for Merit rewards in ${rewardData.rewardTokenSymbol}. ${rewardData.message ? `\n${rewardData.message}` : ''}`,
88
+ };
89
+ rewardData.supplyTokens?.forEach(token => {
90
+ relevantCampaigns.supply[token] = reward;
91
+ });
92
+ rewardData.borrowTokens?.forEach(token => {
93
+ relevantCampaigns.borrow[token] = reward;
94
+ });
95
+ });
96
+ return relevantCampaigns;
97
+ };
@@ -1,74 +1,74 @@
1
- import { aprToApy } from '../moneymarket';
2
- import { DEFAULT_TIMEOUT, wethToEth } from '../services/utils';
3
- import {
4
- MerkleRewardMap, MerklOpportunity, OpportunityAction, OpportunityStatus,
5
- } from '../types';
6
- import { EthAddress, NetworkNumber } from '../types/common';
7
-
8
- export const getAaveUnderlyingSymbol = (_symbol = '') => {
9
- let symbol = _symbol
10
- .replace(/^aEthLido/, '')
11
- .replace(/^aEthEtherFi/, '')
12
- .replace(/^aEth/, '')
13
- .replace(/^aArb/, '')
14
- .replace(/^aOpt/, '')
15
- .replace(/^aBas/, '')
16
- .replace(/^aLin/, '');
17
- if (symbol.startsWith('a')) symbol = symbol.slice(1);
18
- return wethToEth(symbol);
19
- };
20
-
21
- /**
22
- * aEthLidoUSDC -> aUSDC
23
- * USDC -> USDC
24
- */
25
- export const formatAaveAsset = (_symbol: string) => {
26
- if (_symbol.startsWith('a')) {
27
- return `a${getAaveUnderlyingSymbol(_symbol)}`;
28
- }
29
- return _symbol;
30
- };
31
-
32
- export const getMerkleCampaigns = async (chainId: NetworkNumber): Promise<MerkleRewardMap> => {
33
- try {
34
- const res = await fetch('https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave', {
35
- signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
36
- });
37
- if (!res.ok) throw new Error('Failed to fetch Merkle campaigns');
38
- const opportunities = await res.json() as MerklOpportunity[];
39
- const relevantOpportunities = opportunities
40
- .filter((o: MerklOpportunity) => o.chainId === chainId)
41
- .filter((o: MerklOpportunity) => o.status === OpportunityStatus.LIVE);
42
- return relevantOpportunities.reduce((acc, opportunity) => {
43
- const rewardToken = opportunity.rewardsRecord.breakdowns[0].token;
44
- const description = `Eligible for ${formatAaveAsset(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
45
- if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
46
- const supplyAToken = opportunity.explorerAddress?.toLowerCase() as EthAddress;
47
- if (!acc[supplyAToken]) acc[supplyAToken] = {};
48
- acc[supplyAToken].supply = {
49
- apy: aprToApy(opportunity.apr),
50
- // rewardToken: rewardToken.address,
51
- rewardTokenSymbol: rewardToken.symbol,
52
- description,
53
- identifier: opportunity.identifier,
54
- };
55
- }
56
- if (opportunity.action === OpportunityAction.BORROW && opportunity.explorerAddress) {
57
- const borrowAToken = opportunity.explorerAddress?.toLowerCase() as EthAddress;
58
- if (!acc[borrowAToken]) acc[borrowAToken] = {};
59
- acc[borrowAToken].borrow = {
60
- apy: aprToApy(opportunity.apr),
61
- // rewardToken: rewardToken.address,
62
- rewardTokenSymbol: rewardToken.symbol,
63
- description,
64
- identifier: opportunity.identifier,
65
- };
66
- }
67
- return acc;
68
- }, {} as MerkleRewardMap);
69
- } catch (e) {
70
- console.error('Failed to fetch Merkle campaigns', e);
71
- return {};
72
- }
73
- };
74
-
1
+ import { aprToApy } from '../moneymarket';
2
+ import { DEFAULT_TIMEOUT, wethToEth } from '../services/utils';
3
+ import {
4
+ MerkleRewardMap, MerklOpportunity, OpportunityAction, OpportunityStatus,
5
+ } from '../types';
6
+ import { EthAddress, NetworkNumber } from '../types/common';
7
+
8
+ export const getAaveUnderlyingSymbol = (_symbol = '') => {
9
+ let symbol = _symbol
10
+ .replace(/^aEthLido/, '')
11
+ .replace(/^aEthEtherFi/, '')
12
+ .replace(/^aEth/, '')
13
+ .replace(/^aArb/, '')
14
+ .replace(/^aOpt/, '')
15
+ .replace(/^aBas/, '')
16
+ .replace(/^aLin/, '');
17
+ if (symbol.startsWith('a')) symbol = symbol.slice(1);
18
+ return wethToEth(symbol);
19
+ };
20
+
21
+ /**
22
+ * aEthLidoUSDC -> aUSDC
23
+ * USDC -> USDC
24
+ */
25
+ export const formatAaveAsset = (_symbol: string) => {
26
+ if (_symbol.startsWith('a')) {
27
+ return `a${getAaveUnderlyingSymbol(_symbol)}`;
28
+ }
29
+ return _symbol;
30
+ };
31
+
32
+ export const getMerkleCampaigns = async (chainId: NetworkNumber): Promise<MerkleRewardMap> => {
33
+ try {
34
+ const res = await fetch('https://api.merkl.xyz/v4/opportunities?mainProtocolId=aave', {
35
+ signal: AbortSignal.timeout(DEFAULT_TIMEOUT),
36
+ });
37
+ if (!res.ok) throw new Error('Failed to fetch Merkle campaigns');
38
+ const opportunities = await res.json() as MerklOpportunity[];
39
+ const relevantOpportunities = opportunities
40
+ .filter((o: MerklOpportunity) => o.chainId === chainId)
41
+ .filter((o: MerklOpportunity) => o.status === OpportunityStatus.LIVE);
42
+ return relevantOpportunities.reduce((acc, opportunity) => {
43
+ const rewardToken = opportunity.rewardsRecord.breakdowns[0].token;
44
+ const description = `Eligible for ${formatAaveAsset(rewardToken.symbol)} rewards through Merkl. ${opportunity.description ? `\n${opportunity.description}` : ''}`;
45
+ if (opportunity.action === OpportunityAction.LEND && opportunity.explorerAddress) {
46
+ const supplyAToken = opportunity.explorerAddress?.toLowerCase() as EthAddress;
47
+ if (!acc[supplyAToken]) acc[supplyAToken] = {};
48
+ acc[supplyAToken].supply = {
49
+ apy: aprToApy(opportunity.apr),
50
+ // rewardToken: rewardToken.address,
51
+ rewardTokenSymbol: rewardToken.symbol,
52
+ description,
53
+ identifier: opportunity.identifier,
54
+ };
55
+ }
56
+ if (opportunity.action === OpportunityAction.BORROW && opportunity.explorerAddress) {
57
+ const borrowAToken = opportunity.explorerAddress?.toLowerCase() as EthAddress;
58
+ if (!acc[borrowAToken]) acc[borrowAToken] = {};
59
+ acc[borrowAToken].borrow = {
60
+ apy: aprToApy(opportunity.apr),
61
+ // rewardToken: rewardToken.address,
62
+ rewardTokenSymbol: rewardToken.symbol,
63
+ description,
64
+ identifier: opportunity.identifier,
65
+ };
66
+ }
67
+ return acc;
68
+ }, {} as MerkleRewardMap);
69
+ } catch (e) {
70
+ console.error('Failed to fetch Merkle campaigns', e);
71
+ return {};
72
+ }
73
+ };
74
+
@@ -1,155 +1,155 @@
1
- import { Client } from 'viem';
2
- import Dec from 'decimal.js';
3
- import { EthAddress, NetworkNumber } from '../types/common';
4
- import { ClaimableToken, ClaimType } from '../types/claiming';
5
- import {
6
- AaveIncentiveDataProviderV3ContractViem,
7
- AaveRewardsControllerViem,
8
- } from '../contracts';
9
- import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
10
- import { getAaveUnderlyingSymbol } from '../helpers/aaveHelpers';
11
-
12
- type AaveReward = {
13
- amount: string;
14
- symbol: string;
15
- underlyingAsset: string;
16
- rewardTokenAddress: string;
17
- aTokenAddresses: string[];
18
- };
19
-
20
- const mapAaveRewardsToClaimableTokens = (aaveRewards: AaveReward[], marketAddress: EthAddress, walletAddress: EthAddress) => aaveRewards.map(reward => ({
21
- symbol: reward.symbol,
22
- amount: reward.amount,
23
- claimType: ClaimType.AAVE_REWARDS as const,
24
- tokenAddress: reward.rewardTokenAddress as EthAddress,
25
- underlyingSymbol: reward.underlyingAsset,
26
- walletAddress,
27
- label: 'AAVE Rewards',
28
- additionalClaimFields: {
29
- marketAddress,
30
- aTokenAddresses: reward.aTokenAddresses,
31
- isAaveToken: reward.symbol.startsWith('a'),
32
- },
33
- }));
34
-
35
- export async function getUnclaimedRewardsForAllMarkets(
36
- provider: Client,
37
- network: NetworkNumber,
38
- walletAddress: EthAddress,
39
- marketAddress: EthAddress,
40
- ): Promise<ClaimableToken[]> {
41
- const contract = AaveIncentiveDataProviderV3ContractViem(provider, network);
42
- const tokensData = await contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
43
- const allTokensDataArrays = tokensData.reduce((acc: any[], val) => {
44
- acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
45
- acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
46
- return acc;
47
- }, []);
48
- const allATokens = tokensData.reduce((acc, val) => {
49
- acc.push(val.aTokenIncentivesUserData.tokenAddress);
50
- acc.push(val.vTokenIncentivesUserData.tokenAddress);
51
- return acc;
52
- }, [] as string[]);
53
- // array of rewards for each market (aToken/vToken)
54
- // reward can be any token like wstETH, but also aToken like aWETH
55
- const aaveRewardsController = AaveRewardsControllerViem(provider, network);
56
- const rewardsPerAAsset = await Promise.all(allATokens.map(
57
- (token: string) => aaveRewardsController.read.getAllUserRewards([[token as EthAddress], walletAddress])));
58
-
59
- // match amounts to token symbol, parse decimal amounts
60
- const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
61
- const rewardsList = rewardForAAsset[0];
62
- const amounts = rewardForAAsset[1];
63
-
64
- const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
65
- const aTokenAddress = allATokens[aaIndex];
66
- return rewardsList.map((rewardTokenAddress, rewardIndex) => {
67
- const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr: { rewardTokenAddress: string | undefined; }) => compareAddresses(arr.rewardTokenAddress, rewardTokenAddress));
68
- const amountWei = amounts[rewardIndex];
69
- const amount = getEthAmountForDecimals(amountWei.toString(), rewardsDataArraysForAAsset[dataArrIndex]?.rewardTokenDecimals);
70
- const symbol = rewardsDataArraysForAAsset[dataArrIndex]?.rewardTokenSymbol || '';
71
- const underlyingAsset = getAaveUnderlyingSymbol(symbol);
72
- return ({
73
- amount,
74
- symbol,
75
- underlyingAsset,
76
- rewardTokenAddress,
77
- aTokenAddress,
78
- });
79
- });
80
- });
81
-
82
- // sum all unclaimed rewards of all markets per each token
83
- // (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
84
- const totalUnclaimedPerRewardToken: Record<string, any> = {};
85
- rewardsPerAAssetWithInfo
86
- .flat()
87
- .forEach(({
88
- amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress,
89
- }) => {
90
- if (+amount > 0) {
91
- if (!totalUnclaimedPerRewardToken[symbol]) {
92
- totalUnclaimedPerRewardToken[symbol] = {
93
- amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
94
- };
95
- } else {
96
- totalUnclaimedPerRewardToken[symbol].amount =
97
- new Dec(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
98
- totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
99
- }
100
- }
101
- }, []);
102
-
103
- return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
104
- }
105
-
106
- export async function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber, acceptMorpho: boolean = true): Promise<ClaimableToken[]> {
107
- let data;
108
- try {
109
- const res = await fetch(`https://api.merkl.xyz/v4/users/${account}/rewards?chainId=${network}`,
110
- { signal: AbortSignal.timeout(3000) });
111
- data = await res.json();
112
- } catch (error) {
113
- console.error('External API Failure: Aave Merit', error);
114
- data = [];
115
- }
116
-
117
- const claimableTokens: ClaimableToken[] = [];
118
-
119
- data.forEach((item: { rewards: any[]; }) => {
120
- item.rewards.forEach(reward => {
121
- const {
122
- token,
123
- amount,
124
- claimed,
125
- proofs,
126
- } = reward;
127
-
128
- const isTokenMorpho = token.symbol === 'MORPHO';
129
- if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho)) return;
130
-
131
- const unclaimedAmount = new Dec(amount).minus(claimed || 0).toString();
132
- if (unclaimedAmount === '0') return;
133
-
134
- const unclaimed = getEthAmountForDecimals(unclaimedAmount, token.decimals);
135
-
136
- claimableTokens.push({
137
- claimType: ClaimType.AAVE_MERIT_REWARDS,
138
- amount: unclaimed,
139
- symbol: token.symbol,
140
- tokenAddress: token.address,
141
- walletAddress: account,
142
- label: 'AAVE Merit Rewards',
143
- underlyingSymbol: getAaveUnderlyingSymbol(token.symbol),
144
- additionalClaimFields: {
145
- accumulated: amount,
146
- proof: proofs,
147
- decimals: token.decimals,
148
- unclaimed: unclaimedAmount,
149
- },
150
- });
151
- });
152
- });
153
-
154
- return claimableTokens;
1
+ import { Client } from 'viem';
2
+ import Dec from 'decimal.js';
3
+ import { EthAddress, NetworkNumber } from '../types/common';
4
+ import { ClaimableToken, ClaimType } from '../types/claiming';
5
+ import {
6
+ AaveIncentiveDataProviderV3ContractViem,
7
+ AaveRewardsControllerViem,
8
+ } from '../contracts';
9
+ import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
10
+ import { getAaveUnderlyingSymbol } from '../helpers/aaveHelpers';
11
+
12
+ type AaveReward = {
13
+ amount: string;
14
+ symbol: string;
15
+ underlyingAsset: string;
16
+ rewardTokenAddress: string;
17
+ aTokenAddresses: string[];
18
+ };
19
+
20
+ const mapAaveRewardsToClaimableTokens = (aaveRewards: AaveReward[], marketAddress: EthAddress, walletAddress: EthAddress) => aaveRewards.map(reward => ({
21
+ symbol: reward.symbol,
22
+ amount: reward.amount,
23
+ claimType: ClaimType.AAVE_REWARDS as const,
24
+ tokenAddress: reward.rewardTokenAddress as EthAddress,
25
+ underlyingSymbol: reward.underlyingAsset,
26
+ walletAddress,
27
+ label: 'AAVE Rewards',
28
+ additionalClaimFields: {
29
+ marketAddress,
30
+ aTokenAddresses: reward.aTokenAddresses,
31
+ isAaveToken: reward.symbol.startsWith('a'),
32
+ },
33
+ }));
34
+
35
+ export async function getUnclaimedRewardsForAllMarkets(
36
+ provider: Client,
37
+ network: NetworkNumber,
38
+ walletAddress: EthAddress,
39
+ marketAddress: EthAddress,
40
+ ): Promise<ClaimableToken[]> {
41
+ const contract = AaveIncentiveDataProviderV3ContractViem(provider, network);
42
+ const tokensData = await contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
43
+ const allTokensDataArrays = tokensData.reduce((acc: any[], val) => {
44
+ acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
45
+ acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
46
+ return acc;
47
+ }, []);
48
+ const allATokens = tokensData.reduce((acc, val) => {
49
+ acc.push(val.aTokenIncentivesUserData.tokenAddress);
50
+ acc.push(val.vTokenIncentivesUserData.tokenAddress);
51
+ return acc;
52
+ }, [] as string[]);
53
+ // array of rewards for each market (aToken/vToken)
54
+ // reward can be any token like wstETH, but also aToken like aWETH
55
+ const aaveRewardsController = AaveRewardsControllerViem(provider, network);
56
+ const rewardsPerAAsset = await Promise.all(allATokens.map(
57
+ (token: string) => aaveRewardsController.read.getAllUserRewards([[token as EthAddress], walletAddress])));
58
+
59
+ // match amounts to token symbol, parse decimal amounts
60
+ const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
61
+ const rewardsList = rewardForAAsset[0];
62
+ const amounts = rewardForAAsset[1];
63
+
64
+ const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
65
+ const aTokenAddress = allATokens[aaIndex];
66
+ return rewardsList.map((rewardTokenAddress, rewardIndex) => {
67
+ const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr: { rewardTokenAddress: string | undefined; }) => compareAddresses(arr.rewardTokenAddress, rewardTokenAddress));
68
+ const amountWei = amounts[rewardIndex];
69
+ const amount = getEthAmountForDecimals(amountWei.toString(), rewardsDataArraysForAAsset[dataArrIndex]?.rewardTokenDecimals);
70
+ const symbol = rewardsDataArraysForAAsset[dataArrIndex]?.rewardTokenSymbol || '';
71
+ const underlyingAsset = getAaveUnderlyingSymbol(symbol);
72
+ return ({
73
+ amount,
74
+ symbol,
75
+ underlyingAsset,
76
+ rewardTokenAddress,
77
+ aTokenAddress,
78
+ });
79
+ });
80
+ });
81
+
82
+ // sum all unclaimed rewards of all markets per each token
83
+ // (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
84
+ const totalUnclaimedPerRewardToken: Record<string, any> = {};
85
+ rewardsPerAAssetWithInfo
86
+ .flat()
87
+ .forEach(({
88
+ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress,
89
+ }) => {
90
+ if (+amount > 0) {
91
+ if (!totalUnclaimedPerRewardToken[symbol]) {
92
+ totalUnclaimedPerRewardToken[symbol] = {
93
+ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
94
+ };
95
+ } else {
96
+ totalUnclaimedPerRewardToken[symbol].amount =
97
+ new Dec(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
98
+ totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
99
+ }
100
+ }
101
+ }, []);
102
+
103
+ return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
104
+ }
105
+
106
+ export async function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber, acceptMorpho: boolean = true): Promise<ClaimableToken[]> {
107
+ let data;
108
+ try {
109
+ const res = await fetch(`https://api.merkl.xyz/v4/users/${account}/rewards?chainId=${network}`,
110
+ { signal: AbortSignal.timeout(3000) });
111
+ data = await res.json();
112
+ } catch (error) {
113
+ console.error('External API Failure: Aave Merit', error);
114
+ data = [];
115
+ }
116
+
117
+ const claimableTokens: ClaimableToken[] = [];
118
+
119
+ data.forEach((item: { rewards: any[]; }) => {
120
+ item.rewards.forEach(reward => {
121
+ const {
122
+ token,
123
+ amount,
124
+ claimed,
125
+ proofs,
126
+ } = reward;
127
+
128
+ const isTokenMorpho = token.symbol === 'MORPHO';
129
+ if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho)) return;
130
+
131
+ const unclaimedAmount = new Dec(amount).minus(claimed || 0).toString();
132
+ if (unclaimedAmount === '0') return;
133
+
134
+ const unclaimed = getEthAmountForDecimals(unclaimedAmount, token.decimals);
135
+
136
+ claimableTokens.push({
137
+ claimType: ClaimType.AAVE_MERIT_REWARDS,
138
+ amount: unclaimed,
139
+ symbol: token.symbol,
140
+ tokenAddress: token.address,
141
+ walletAddress: account,
142
+ label: 'AAVE Merit Rewards',
143
+ underlyingSymbol: getAaveUnderlyingSymbol(token.symbol),
144
+ additionalClaimFields: {
145
+ accumulated: amount,
146
+ proof: proofs,
147
+ decimals: token.decimals,
148
+ unclaimed: unclaimedAmount,
149
+ },
150
+ });
151
+ });
152
+ });
153
+
154
+ return claimableTokens;
155
155
  }