@defisaver/positions-sdk 2.0.12 → 2.0.14-dev-portfolio

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 (170) hide show
  1. package/.mocharc.json +4 -4
  2. package/.nvmrc +1 -1
  3. package/CLAUDE.md +32 -0
  4. package/README.md +64 -64
  5. package/cjs/aaveV2/index.js +1 -0
  6. package/cjs/aaveV3/index.d.ts +12 -0
  7. package/cjs/aaveV3/index.js +93 -1
  8. package/cjs/claiming/aaveV3.d.ts +9 -0
  9. package/cjs/claiming/aaveV3.js +148 -0
  10. package/cjs/claiming/compV3.d.ts +15 -0
  11. package/cjs/claiming/compV3.js +34 -0
  12. package/cjs/claiming/index.d.ts +6 -0
  13. package/cjs/claiming/index.js +46 -0
  14. package/cjs/claiming/king.d.ts +4 -0
  15. package/cjs/claiming/king.js +72 -0
  16. package/cjs/claiming/morphoBlue.d.ts +6 -0
  17. package/cjs/claiming/morphoBlue.js +113 -0
  18. package/cjs/claiming/spark.d.ts +6 -0
  19. package/cjs/claiming/spark.js +188 -0
  20. package/cjs/config/contracts.d.ts +2667 -0
  21. package/cjs/config/contracts.js +103 -2
  22. package/cjs/constants/index.d.ts +4 -0
  23. package/cjs/constants/index.js +6 -2
  24. package/cjs/contracts.d.ts +2882 -23
  25. package/cjs/contracts.js +10 -1
  26. package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
  27. package/cjs/index.d.ts +2 -1
  28. package/cjs/index.js +3 -1
  29. package/cjs/liquity/index.d.ts +11 -0
  30. package/cjs/liquity/index.js +39 -1
  31. package/cjs/liquityV2/index.d.ts +8 -0
  32. package/cjs/liquityV2/index.js +161 -0
  33. package/cjs/markets/aave/marketAssets.js +1 -1
  34. package/cjs/markets/compound/marketsAssets.js +2 -2
  35. package/cjs/markets/spark/marketAssets.js +1 -1
  36. package/cjs/morphoBlue/index.d.ts +5 -0
  37. package/cjs/morphoBlue/index.js +38 -4
  38. package/cjs/portfolio/index.d.ts +6 -1
  39. package/cjs/portfolio/index.js +256 -10
  40. package/cjs/services/utils.d.ts +5 -0
  41. package/cjs/services/utils.js +33 -1
  42. package/cjs/services/viem.d.ts +12 -12
  43. package/cjs/spark/index.js +1 -0
  44. package/cjs/staking/staking.js +3 -1
  45. package/cjs/types/claiming.d.ts +93 -0
  46. package/cjs/types/claiming.js +27 -0
  47. package/cjs/umbrella/index.d.ts +5 -0
  48. package/cjs/umbrella/index.js +50 -0
  49. package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
  50. package/cjs/umbrella/umbrellaUtils.js +34 -0
  51. package/esm/aaveV2/index.js +1 -0
  52. package/esm/aaveV3/index.d.ts +12 -0
  53. package/esm/aaveV3/index.js +91 -1
  54. package/esm/claiming/aaveV3.d.ts +9 -0
  55. package/esm/claiming/aaveV3.js +139 -0
  56. package/esm/claiming/compV3.d.ts +15 -0
  57. package/esm/claiming/compV3.js +30 -0
  58. package/esm/claiming/index.d.ts +6 -0
  59. package/esm/claiming/index.js +6 -0
  60. package/esm/claiming/king.d.ts +4 -0
  61. package/esm/claiming/king.js +64 -0
  62. package/esm/claiming/morphoBlue.d.ts +6 -0
  63. package/esm/claiming/morphoBlue.js +104 -0
  64. package/esm/claiming/spark.d.ts +6 -0
  65. package/esm/claiming/spark.js +179 -0
  66. package/esm/config/contracts.d.ts +2667 -0
  67. package/esm/config/contracts.js +102 -1
  68. package/esm/constants/index.d.ts +4 -0
  69. package/esm/constants/index.js +5 -1
  70. package/esm/contracts.d.ts +2882 -23
  71. package/esm/contracts.js +9 -0
  72. package/esm/helpers/morphoBlueHelpers/index.js +66 -66
  73. package/esm/index.d.ts +2 -1
  74. package/esm/index.js +2 -1
  75. package/esm/liquity/index.d.ts +11 -0
  76. package/esm/liquity/index.js +38 -1
  77. package/esm/liquityV2/index.d.ts +8 -0
  78. package/esm/liquityV2/index.js +162 -1
  79. package/esm/markets/aave/marketAssets.js +1 -1
  80. package/esm/markets/compound/marketsAssets.js +2 -2
  81. package/esm/markets/spark/marketAssets.js +1 -1
  82. package/esm/morphoBlue/index.d.ts +5 -0
  83. package/esm/morphoBlue/index.js +38 -5
  84. package/esm/portfolio/index.d.ts +6 -1
  85. package/esm/portfolio/index.js +260 -14
  86. package/esm/services/utils.d.ts +5 -0
  87. package/esm/services/utils.js +31 -0
  88. package/esm/services/viem.d.ts +12 -12
  89. package/esm/spark/index.js +1 -0
  90. package/esm/staking/staking.js +3 -1
  91. package/esm/types/claiming.d.ts +93 -0
  92. package/esm/types/claiming.js +24 -0
  93. package/esm/umbrella/index.d.ts +5 -0
  94. package/esm/umbrella/index.js +46 -0
  95. package/esm/umbrella/umbrellaUtils.d.ts +22 -0
  96. package/esm/umbrella/umbrellaUtils.js +28 -0
  97. package/package.json +47 -47
  98. package/src/aaveV2/index.ts +237 -236
  99. package/src/aaveV3/index.ts +586 -488
  100. package/src/claiming/aaveV3.ts +163 -0
  101. package/src/claiming/compV3.ts +23 -0
  102. package/src/claiming/index.ts +13 -0
  103. package/src/claiming/king.ts +66 -0
  104. package/src/claiming/morphoBlue.ts +119 -0
  105. package/src/claiming/spark.ts +226 -0
  106. package/src/compoundV2/index.ts +240 -240
  107. package/src/compoundV3/index.ts +270 -270
  108. package/src/config/contracts.ts +1208 -1108
  109. package/src/constants/index.ts +10 -6
  110. package/src/contracts.ts +121 -108
  111. package/src/curveUsd/index.ts +250 -250
  112. package/src/eulerV2/index.ts +314 -314
  113. package/src/exchange/index.ts +25 -25
  114. package/src/fluid/index.ts +1568 -1568
  115. package/src/helpers/aaveHelpers/index.ts +170 -170
  116. package/src/helpers/compoundHelpers/index.ts +261 -261
  117. package/src/helpers/curveUsdHelpers/index.ts +40 -40
  118. package/src/helpers/eulerHelpers/index.ts +259 -259
  119. package/src/helpers/fluidHelpers/index.ts +324 -324
  120. package/src/helpers/index.ts +10 -10
  121. package/src/helpers/liquityV2Helpers/index.ts +80 -80
  122. package/src/helpers/llamaLendHelpers/index.ts +53 -53
  123. package/src/helpers/makerHelpers/index.ts +52 -52
  124. package/src/helpers/morphoBlueHelpers/index.ts +390 -390
  125. package/src/helpers/sparkHelpers/index.ts +155 -155
  126. package/src/index.ts +47 -45
  127. package/src/liquity/index.ts +160 -105
  128. package/src/liquityV2/index.ts +583 -408
  129. package/src/llamaLend/index.ts +296 -296
  130. package/src/maker/index.ts +223 -223
  131. package/src/markets/aave/index.ts +116 -116
  132. package/src/markets/aave/marketAssets.ts +49 -49
  133. package/src/markets/compound/index.ts +227 -227
  134. package/src/markets/compound/marketsAssets.ts +90 -90
  135. package/src/markets/curveUsd/index.ts +69 -69
  136. package/src/markets/euler/index.ts +26 -26
  137. package/src/markets/fluid/index.ts +2456 -2456
  138. package/src/markets/index.ts +25 -25
  139. package/src/markets/liquityV2/index.ts +102 -102
  140. package/src/markets/llamaLend/contractAddresses.ts +141 -141
  141. package/src/markets/llamaLend/index.ts +235 -235
  142. package/src/markets/morphoBlue/index.ts +895 -895
  143. package/src/markets/spark/index.ts +29 -29
  144. package/src/markets/spark/marketAssets.ts +11 -11
  145. package/src/moneymarket/moneymarketCommonService.ts +80 -80
  146. package/src/morphoBlue/index.ts +259 -222
  147. package/src/portfolio/index.ts +533 -285
  148. package/src/services/priceService.ts +159 -159
  149. package/src/services/utils.ts +100 -64
  150. package/src/services/viem.ts +32 -32
  151. package/src/setup.ts +8 -8
  152. package/src/spark/index.ts +457 -456
  153. package/src/staking/staking.ts +194 -193
  154. package/src/types/aave.ts +194 -194
  155. package/src/types/claiming.ts +109 -0
  156. package/src/types/common.ts +88 -88
  157. package/src/types/compound.ts +136 -136
  158. package/src/types/curveUsd.ts +121 -121
  159. package/src/types/euler.ts +174 -174
  160. package/src/types/fluid.ts +450 -450
  161. package/src/types/index.ts +11 -11
  162. package/src/types/liquity.ts +30 -30
  163. package/src/types/liquityV2.ts +126 -126
  164. package/src/types/llamaLend.ts +157 -157
  165. package/src/types/maker.ts +63 -63
  166. package/src/types/morphoBlue.ts +194 -194
  167. package/src/types/portfolio.ts +60 -60
  168. package/src/types/spark.ts +137 -137
  169. package/src/umbrella/index.ts +70 -0
  170. package/src/umbrella/umbrellaUtils.ts +30 -0
@@ -0,0 +1,104 @@
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 { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
11
+ import Dec from 'decimal.js';
12
+ import { ClaimType } from '../types/claiming';
13
+ import { createViemContractFromConfigFunc } from '../contracts';
14
+ import { wethToEth } from '../services/utils';
15
+ const MORPHO_ALLOWED_CONTRACTS = [
16
+ '0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb',
17
+ '0x678dDC1d07eaa166521325394cDEb1E4c086DF43',
18
+ '0x2efd4625d0c149ebadf118ec5446c6de24d916a4',
19
+ ];
20
+ const MORPHO_ALLOWED_TOKENS = [
21
+ 'MORPHO',
22
+ 'MORPHO Legacy',
23
+ ];
24
+ export const getMorphoUnderlyingSymbol = (_symbol) => {
25
+ if (_symbol === 'MORPHO Legacy')
26
+ return 'MORPHO';
27
+ return wethToEth(_symbol);
28
+ };
29
+ export const getMorphoBlueRewardsInfo = (address) => __awaiter(void 0, void 0, void 0, function* () {
30
+ if (!address)
31
+ return { claimable: '0' };
32
+ const res = yield fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`, { signal: AbortSignal.timeout(3000) });
33
+ if (!res.ok)
34
+ throw new Error(yield res.text());
35
+ return res.json();
36
+ });
37
+ export const fetchMorphoBlueRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
38
+ var _a;
39
+ // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
40
+ const apiDataPromises = walletAddresses.map(address => getMorphoBlueRewardsInfo(address));
41
+ const apiDataArray = yield Promise.all(apiDataPromises);
42
+ // Process API data to get claimable tokens for each wallet
43
+ const allClaimableTokens = [];
44
+ const contractCallsData = [];
45
+ for (let i = 0; i < walletAddresses.length; i++) {
46
+ const walletAddress = walletAddresses[i];
47
+ const data = apiDataArray[i];
48
+ const claimableTokens = ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.reduce((acc, reward) => {
49
+ var _a, _b, _c;
50
+ const token = getAssetInfoByAddress(reward.asset.address);
51
+ if (!MORPHO_ALLOWED_CONTRACTS.includes((_a = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _a === void 0 ? void 0 : _a.address) || !MORPHO_ALLOWED_TOKENS.includes(token.symbol)) {
52
+ return acc;
53
+ }
54
+ // Store contract call data for batching
55
+ contractCallsData.push({
56
+ walletAddress,
57
+ tokenAddress: reward.asset.address,
58
+ distributor: (_b = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _b === void 0 ? void 0 : _b.address,
59
+ });
60
+ return [
61
+ ...acc,
62
+ {
63
+ symbol: token.symbol,
64
+ underlyingSymbol: getMorphoUnderlyingSymbol(token.symbol),
65
+ tokenAddress: reward.asset.address,
66
+ amount: assetAmountInEth(reward.claimable, token.symbol),
67
+ walletAddress,
68
+ label: token.symbol,
69
+ claimType: ClaimType.MORPHO,
70
+ additionalClaimFields: {
71
+ originalAmount: reward.claimable,
72
+ distributor: (_c = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _c === void 0 ? void 0 : _c.address,
73
+ merkleProofs: reward === null || reward === void 0 ? void 0 : reward.proof,
74
+ isLegacy: token.symbol === 'MORPHO Legacy',
75
+ txData: reward === null || reward === void 0 ? void 0 : reward.tx_data,
76
+ },
77
+ }
78
+ ];
79
+ }, [])) || [];
80
+ allClaimableTokens.push({ walletAddress, tokens: claimableTokens });
81
+ }
82
+ // Batch all contract calls using multicall
83
+ const contractPromises = contractCallsData.map(({ walletAddress, tokenAddress, distributor }) => {
84
+ const distributorContract = createViemContractFromConfigFunc('MorphoDistributor', distributor)(provider, network);
85
+ return distributorContract.read.claimed([walletAddress, tokenAddress]);
86
+ });
87
+ const contractResults = yield Promise.all(contractPromises);
88
+ // Process results
89
+ const results = {};
90
+ let contractCallIndex = 0;
91
+ for (const { walletAddress, tokens } of allClaimableTokens) {
92
+ const updatedTokens = [];
93
+ for (let i = 0; i < tokens.length; i++) {
94
+ const claimableToken = tokens[i];
95
+ const claimed = assetAmountInEth(contractResults[contractCallIndex].toString(), claimableToken.underlyingSymbol);
96
+ contractCallIndex++;
97
+ const updatedToken = Object.assign({}, claimableToken);
98
+ updatedToken.amount = new Dec(claimableToken.amount).sub(claimed).toString();
99
+ updatedTokens.push(updatedToken);
100
+ }
101
+ results[walletAddress.toLowerCase()] = updatedTokens.filter((claimableToken) => new Dec(claimableToken.amount).gt(0));
102
+ }
103
+ return results;
104
+ });
@@ -0,0 +1,6 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { SparkRewardsClaimableToken } from '../types/claiming';
4
+ export declare const fetchSpkAirdropRewards: (walletAddress: EthAddress) => Promise<any>;
5
+ export declare const fetchSparkAirdropRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, any[]>>;
6
+ export declare const fetchSparkRewards: (provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress) => Promise<SparkRewardsClaimableToken[]>;
@@ -0,0 +1,179 @@
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 { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
11
+ import Dec from 'decimal.js';
12
+ import { createViemContractFromConfigFunc, SparkIncentiveDataProviderContractViem, SparkRewardsControllerViem, } from '../contracts';
13
+ import { ClaimType, SparkAirdropType } from '../types/claiming';
14
+ import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
15
+ const IGNITION_REWARDS = '0xCBA0C0a2a0B6Bb11233ec4EA85C5bFfea33e724d';
16
+ const PFL3_REWARDS = '0x7ac96180C4d6b2A328D3a19ac059D0E7Fc3C6d41';
17
+ export const fetchSpkAirdropRewards = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
18
+ try {
19
+ const res = yield fetch(`https://fe.defisaver.com/api/spark/get-spk-airdrop-rewards/${walletAddress}`, { signal: AbortSignal.timeout(3000) });
20
+ if (!res.ok)
21
+ throw new Error(yield res.text());
22
+ return yield res.json();
23
+ }
24
+ catch (err) {
25
+ console.error('External API Error: Error fetching SPK airdrop rewards:', err);
26
+ return [];
27
+ }
28
+ });
29
+ const getCumulativeClaimedSpkAirdrop = (provider, network, data) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const contractIgnition = createViemContractFromConfigFunc('SparkAirdrop', IGNITION_REWARDS)(provider, network);
31
+ const contractPFL = createViemContractFromConfigFunc('SparkAirdrop', PFL3_REWARDS)(provider, network);
32
+ const cumulativeAmounts = yield Promise.all(data.map((airdrop) => {
33
+ const { user, tokenAddress, epoch, type, } = airdrop;
34
+ const contract = type === SparkAirdropType.SPARK_IGNITION ? contractIgnition : contractPFL;
35
+ return contract.read.cumulativeClaimed([user, tokenAddress, BigInt(epoch)]);
36
+ }));
37
+ return cumulativeAmounts.map((amount, i) => assetAmountInEth(amount.toString(), getAssetInfoByAddress(data[i].tokenAddress).symbol).toString());
38
+ });
39
+ export const fetchSparkAirdropRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
40
+ // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
41
+ const apiDataPromises = walletAddresses.map(address => fetchSpkAirdropRewards(address));
42
+ const apiDataArray = yield Promise.all(apiDataPromises);
43
+ // Process API data and collect contract call data
44
+ const allClaimData = [];
45
+ const contractCallsData = [];
46
+ for (let i = 0; i < walletAddresses.length; i++) {
47
+ const walletAddress = walletAddresses[i];
48
+ const data = apiDataArray[i];
49
+ const falseResponse = !data;
50
+ const emptyResponse = data && data.length === 0;
51
+ const singleResponseWithoutAmount = data && data.length === 1 && !+data[0].amount;
52
+ if (falseResponse || emptyResponse || singleResponseWithoutAmount) {
53
+ allClaimData.push({ walletAddress, data: [] });
54
+ continue;
55
+ }
56
+ // Filter out IGNITION_REWARDS since they are no longer active
57
+ const filteredData = data.filter((rewardInfo) => rewardInfo.type !== SparkAirdropType.SPARK_IGNITION);
58
+ allClaimData.push({ walletAddress, data: filteredData });
59
+ // Collect contract call data
60
+ filteredData.forEach((airdropInfo) => {
61
+ contractCallsData.push({
62
+ user: airdropInfo.wallet_address,
63
+ tokenAddress: airdropInfo.token_address,
64
+ epoch: airdropInfo.epoch,
65
+ type: airdropInfo.type,
66
+ });
67
+ });
68
+ }
69
+ // Batch all contract calls
70
+ const cumulativeClaimedAmounts = yield getCumulativeClaimedSpkAirdrop(provider, network, contractCallsData);
71
+ // Process results
72
+ const results = {};
73
+ let contractCallIndex = 0;
74
+ for (const { walletAddress, data } of allClaimData) {
75
+ if (data.length === 0) {
76
+ results[walletAddress.toLowerCase()] = [];
77
+ continue;
78
+ }
79
+ const processedRewards = [];
80
+ for (let i = 0; i < data.length; i++) {
81
+ const rewardInfo = data[i];
82
+ const assetInfo = getAssetInfoByAddress(rewardInfo.token_address);
83
+ const claimedAmount = cumulativeClaimedAmounts[contractCallIndex];
84
+ contractCallIndex++;
85
+ const amount = new Dec(rewardInfo.amount_normalized).minus(claimedAmount).toString();
86
+ if (new Dec(amount).gt('0')) {
87
+ processedRewards.push({
88
+ symbol: assetInfo.symbol,
89
+ underlyingSymbol: assetInfo.symbol,
90
+ amount,
91
+ claimType: ClaimType.SPARK_AIRDROP,
92
+ tokenAddress: rewardInfo.token_address,
93
+ walletAddress: rewardInfo.wallet_address,
94
+ label: 'Spark Airdrop',
95
+ additionalClaimFields: {
96
+ merkleRoot: rewardInfo.root_hash,
97
+ merkleProofs: rewardInfo.proof,
98
+ epoch: rewardInfo.epoch,
99
+ rewardType: rewardInfo.type,
100
+ allRewardsAmount: rewardInfo.amount_normalized,
101
+ },
102
+ });
103
+ }
104
+ }
105
+ results[walletAddress.toLowerCase()] = processedRewards;
106
+ }
107
+ return results;
108
+ });
109
+ export const fetchSparkRewards = (provider, network, walletAddress, marketAddress) => __awaiter(void 0, void 0, void 0, function* () {
110
+ const contract = SparkIncentiveDataProviderContractViem(provider, network);
111
+ const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
112
+ const allTokensDataArrays = tokensData.reduce((acc, val) => {
113
+ acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
114
+ acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
115
+ return acc;
116
+ }, []);
117
+ const allATokens = tokensData.reduce((acc, val) => {
118
+ acc.push(val.aTokenIncentivesUserData.tokenAddress);
119
+ acc.push(val.vTokenIncentivesUserData.tokenAddress);
120
+ return acc;
121
+ }, []);
122
+ const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => {
123
+ const sparkRewardsContract = SparkRewardsControllerViem(provider, network);
124
+ return sparkRewardsContract.read.getAllUserRewards([[token], walletAddress]);
125
+ }));
126
+ // match amounts to token symbol, parse decimal amounts
127
+ const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
128
+ const rewardsList = rewardForAAsset[0];
129
+ const amounts = rewardForAAsset[1];
130
+ const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
131
+ const aTokenAddress = allATokens[aaIndex];
132
+ return rewardsList.map((rewardTokenAddress, rewardIndex) => {
133
+ var _a, _b;
134
+ const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr) => compareAddresses(arr.rewardTokenAddress, rewardTokenAddress));
135
+ const amountWei = amounts[rewardIndex];
136
+ const amount = getEthAmountForDecimals(amountWei.toString(), (_a = rewardsDataArraysForAAsset[dataArrIndex]) === null || _a === void 0 ? void 0 : _a.rewardTokenDecimals);
137
+ const symbol = ((_b = rewardsDataArraysForAAsset[dataArrIndex]) === null || _b === void 0 ? void 0 : _b.rewardTokenSymbol) || '';
138
+ const underlyingAsset = symbol;
139
+ return ({
140
+ amount,
141
+ symbol,
142
+ underlyingAsset,
143
+ rewardTokenAddress,
144
+ aTokenAddress,
145
+ });
146
+ });
147
+ });
148
+ // sum all unclaimed rewards of all markets per each token
149
+ // (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
150
+ const totalUnclaimedPerRewardToken = {};
151
+ rewardsPerAAssetWithInfo
152
+ .flat()
153
+ .forEach(({ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress, }) => {
154
+ if (+amount > 0) {
155
+ if (!totalUnclaimedPerRewardToken[symbol]) {
156
+ totalUnclaimedPerRewardToken[symbol] = {
157
+ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
158
+ };
159
+ }
160
+ else {
161
+ totalUnclaimedPerRewardToken[symbol].amount =
162
+ new Dec(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
163
+ totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
164
+ }
165
+ }
166
+ }, []);
167
+ return Object.values(totalUnclaimedPerRewardToken).map((reward) => ({
168
+ symbol: reward.symbol,
169
+ amount: reward.amount,
170
+ claimType: ClaimType.SPARK_REWARDS,
171
+ tokenAddress: reward.rewardTokenAddress,
172
+ underlyingSymbol: reward.underlyingAsset,
173
+ walletAddress,
174
+ label: 'Spark',
175
+ additionalClaimFields: {
176
+ sparkAssetAddresses: reward.aTokenAddresses,
177
+ },
178
+ }));
179
+ });