@defisaver/positions-sdk 2.0.13 → 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 (117) hide show
  1. package/CLAUDE.md +32 -0
  2. package/cjs/aaveV2/index.js +1 -0
  3. package/cjs/aaveV3/index.d.ts +12 -0
  4. package/cjs/aaveV3/index.js +93 -1
  5. package/cjs/claiming/aaveV3.d.ts +9 -0
  6. package/cjs/claiming/aaveV3.js +148 -0
  7. package/cjs/claiming/compV3.d.ts +15 -0
  8. package/cjs/claiming/compV3.js +34 -0
  9. package/cjs/claiming/index.d.ts +6 -0
  10. package/cjs/claiming/index.js +46 -0
  11. package/cjs/claiming/king.d.ts +4 -0
  12. package/cjs/claiming/king.js +72 -0
  13. package/cjs/claiming/morphoBlue.d.ts +6 -0
  14. package/cjs/claiming/morphoBlue.js +113 -0
  15. package/cjs/claiming/spark.d.ts +6 -0
  16. package/cjs/claiming/spark.js +188 -0
  17. package/cjs/config/contracts.d.ts +2667 -0
  18. package/cjs/config/contracts.js +103 -2
  19. package/cjs/constants/index.d.ts +4 -0
  20. package/cjs/constants/index.js +6 -2
  21. package/cjs/contracts.d.ts +2882 -23
  22. package/cjs/contracts.js +10 -1
  23. package/cjs/index.d.ts +2 -1
  24. package/cjs/index.js +3 -1
  25. package/cjs/liquity/index.d.ts +11 -0
  26. package/cjs/liquity/index.js +39 -1
  27. package/cjs/liquityV2/index.d.ts +8 -0
  28. package/cjs/liquityV2/index.js +161 -0
  29. package/cjs/markets/aave/marketAssets.js +1 -1
  30. package/cjs/markets/compound/marketsAssets.js +2 -2
  31. package/cjs/markets/spark/marketAssets.js +1 -1
  32. package/cjs/morphoBlue/index.d.ts +5 -0
  33. package/cjs/morphoBlue/index.js +38 -4
  34. package/cjs/portfolio/index.d.ts +6 -1
  35. package/cjs/portfolio/index.js +256 -10
  36. package/cjs/services/utils.d.ts +5 -0
  37. package/cjs/services/utils.js +33 -1
  38. package/cjs/services/viem.d.ts +12 -12
  39. package/cjs/spark/index.js +1 -0
  40. package/cjs/staking/staking.js +3 -1
  41. package/cjs/types/claiming.d.ts +93 -0
  42. package/cjs/types/claiming.js +27 -0
  43. package/cjs/umbrella/index.d.ts +5 -0
  44. package/cjs/umbrella/index.js +50 -0
  45. package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
  46. package/cjs/umbrella/umbrellaUtils.js +34 -0
  47. package/esm/aaveV2/index.js +1 -0
  48. package/esm/aaveV3/index.d.ts +12 -0
  49. package/esm/aaveV3/index.js +91 -1
  50. package/esm/claiming/aaveV3.d.ts +9 -0
  51. package/esm/claiming/aaveV3.js +139 -0
  52. package/esm/claiming/compV3.d.ts +15 -0
  53. package/esm/claiming/compV3.js +30 -0
  54. package/esm/claiming/index.d.ts +6 -0
  55. package/esm/claiming/index.js +6 -0
  56. package/esm/claiming/king.d.ts +4 -0
  57. package/esm/claiming/king.js +64 -0
  58. package/esm/claiming/morphoBlue.d.ts +6 -0
  59. package/esm/claiming/morphoBlue.js +104 -0
  60. package/esm/claiming/spark.d.ts +6 -0
  61. package/esm/claiming/spark.js +179 -0
  62. package/esm/config/contracts.d.ts +2667 -0
  63. package/esm/config/contracts.js +102 -1
  64. package/esm/constants/index.d.ts +4 -0
  65. package/esm/constants/index.js +5 -1
  66. package/esm/contracts.d.ts +2882 -23
  67. package/esm/contracts.js +9 -0
  68. package/esm/index.d.ts +2 -1
  69. package/esm/index.js +2 -1
  70. package/esm/liquity/index.d.ts +11 -0
  71. package/esm/liquity/index.js +38 -1
  72. package/esm/liquityV2/index.d.ts +8 -0
  73. package/esm/liquityV2/index.js +162 -1
  74. package/esm/markets/aave/marketAssets.js +1 -1
  75. package/esm/markets/compound/marketsAssets.js +2 -2
  76. package/esm/markets/spark/marketAssets.js +1 -1
  77. package/esm/morphoBlue/index.d.ts +5 -0
  78. package/esm/morphoBlue/index.js +38 -5
  79. package/esm/portfolio/index.d.ts +6 -1
  80. package/esm/portfolio/index.js +260 -14
  81. package/esm/services/utils.d.ts +5 -0
  82. package/esm/services/utils.js +31 -0
  83. package/esm/services/viem.d.ts +12 -12
  84. package/esm/spark/index.js +1 -0
  85. package/esm/staking/staking.js +3 -1
  86. package/esm/types/claiming.d.ts +93 -0
  87. package/esm/types/claiming.js +24 -0
  88. package/esm/umbrella/index.d.ts +5 -0
  89. package/esm/umbrella/index.js +46 -0
  90. package/esm/umbrella/umbrellaUtils.d.ts +22 -0
  91. package/esm/umbrella/umbrellaUtils.js +28 -0
  92. package/package.json +2 -2
  93. package/src/aaveV2/index.ts +2 -1
  94. package/src/aaveV3/index.ts +100 -2
  95. package/src/claiming/aaveV3.ts +163 -0
  96. package/src/claiming/compV3.ts +23 -0
  97. package/src/claiming/index.ts +13 -0
  98. package/src/claiming/king.ts +66 -0
  99. package/src/claiming/morphoBlue.ts +119 -0
  100. package/src/claiming/spark.ts +226 -0
  101. package/src/config/contracts.ts +105 -5
  102. package/src/constants/index.ts +5 -1
  103. package/src/contracts.ts +14 -1
  104. package/src/index.ts +2 -0
  105. package/src/liquity/index.ts +57 -2
  106. package/src/liquityV2/index.ts +177 -2
  107. package/src/markets/aave/marketAssets.ts +1 -1
  108. package/src/markets/compound/marketsAssets.ts +2 -2
  109. package/src/markets/spark/marketAssets.ts +1 -1
  110. package/src/morphoBlue/index.ts +43 -6
  111. package/src/portfolio/index.ts +263 -15
  112. package/src/services/utils.ts +37 -1
  113. package/src/spark/index.ts +2 -1
  114. package/src/staking/staking.ts +2 -1
  115. package/src/types/claiming.ts +109 -0
  116. package/src/umbrella/index.ts +70 -0
  117. package/src/umbrella/umbrellaUtils.ts +30 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,32 @@
1
+ # DeFiSaver Positions SDK
2
+
3
+ TypeScript SDK for DeFi positions tracking and management.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ # Development
9
+ npm run dev # Watch mode compilation
10
+ npm run build # Lint and build both CJS and ESM
11
+ npm run build:cjs # Build CommonJS
12
+ npm run build:esm # Build ES modules
13
+
14
+ # Linting
15
+ npm run lint # Lint and fix
16
+ npm run lint-check # Lint without fixing
17
+
18
+ # Testing
19
+ npm run test # Run all tests
20
+ npm run test-single # Run single test (use --name=filename)
21
+ npm run test:debugger # Run tests with debugger
22
+
23
+ # Versioning
24
+ npm run version-bump # Commit and bump patch version
25
+ ```
26
+
27
+ ## Project Structure
28
+
29
+ - `src/` - TypeScript source code
30
+ - `tests/` - Test files
31
+ - `esm/` - ES module build output
32
+ - `cjs/` - CommonJS build output
@@ -101,6 +101,7 @@ const _getAaveV2AccountBalances = (provider, network, block, addressMapping, add
101
101
  const marketAddress = market.providerAddress;
102
102
  // @ts-ignore
103
103
  const protocolDataProviderContract = (0, contracts_1.createViemContractFromConfigFunc)(market.protocolData, market.protocolDataAddress)(provider, network);
104
+ // @ts-ignore
104
105
  const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens((0, viem_1.setViemBlockNumber)(block));
105
106
  const symbols = reserveTokens.map(({ symbol }) => symbol);
106
107
  const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
@@ -32,3 +32,15 @@ export declare const getAaveV3AccountBalances: (provider: EthereumProvider, netw
32
32
  export declare const _getAaveV3AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
33
33
  export declare const getAaveV3AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
34
34
  export declare const getAaveV3FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo) => Promise<AaveV3PositionData>;
35
+ export declare const REWARDABLE_ASSETS: readonly ["0x028171bCA77440897B824Ca71D1c56caC55b68A3", "0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d", "0xD37EE7e4f452C6638c96536e68090De8cBcdb583", "0x279AF5b99540c1A3A7E3CDd326e19659401eF99e", "0xBcca60bB61934080951369a648Fb03DF4F96263C", "0x619beb58998eD2278e08620f97007e1116D5D25b", "0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811", "0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec", "0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656", "0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2", "0x030bA81f1c18d280636F32af80b9AAd02Cf0854e", "0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf", "0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0", "0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D", "0x6C5024Cd4F8A59110119C56f8933403A539555EB", "0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817", "0x5165d24277cD063F5ac44Efd447B27025e888f37", "0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97", "0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a", "0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A", "0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1", "0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73", "0xc713e5E149D5D0715DcD1c156a020976e7E56B88", "0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8", "0x101cc05f4A51C0319f570d5E146a8C625198e636", "0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92", "0xc9BC48c72154ef3e5425641a3c747242112a46AF", "0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b", "0x272F97b7a56a387aE942350bBC7Df5700f8a4576", "0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0", "0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3", "0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7", "0xA361718326c15715591c299427c62086F69923D9", "0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c", "0xd4937682df3C8aEF4FE912A96A74121C0829E664", "0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca", "0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3", "0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe", "0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1", "0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684", "0x6F634c6135D2EBD550000ac92F494F9CB8183dAe", "0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0"];
36
+ export declare const fetchYearlyMeritApyForStakingGho: () => Promise<string>;
37
+ export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
38
+ activatedCooldown: string;
39
+ activatedCooldownAmount: string;
40
+ stkAaveRewardsBalance: string;
41
+ aaveRewardsBalance: string;
42
+ stkAaveBalance: string;
43
+ stkGhoBalance: string;
44
+ ghoMeritApy: string;
45
+ stkAaveApy: string;
46
+ }>;
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getAaveV3FullPositionData = exports.getAaveV3AccountData = exports._getAaveV3AccountData = exports.getAaveV3AccountBalances = exports._getAaveV3AccountBalances = exports.EMPTY_AAVE_DATA = exports.aaveV3EmodeCategoriesMapping = void 0;
15
+ exports.getStakeAaveData = exports.fetchYearlyMeritApyForStakingGho = exports.REWARDABLE_ASSETS = exports.getAaveV3FullPositionData = exports.getAaveV3AccountData = exports._getAaveV3AccountData = exports.getAaveV3AccountBalances = exports._getAaveV3AccountBalances = exports.EMPTY_AAVE_DATA = exports.aaveV3EmodeCategoriesMapping = void 0;
16
16
  exports._getAaveV3MarketData = _getAaveV3MarketData;
17
17
  exports.getAaveV3MarketData = getAaveV3MarketData;
18
18
  const tokens_1 = require("@defisaver/tokens");
@@ -25,6 +25,7 @@ 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 constants_1 = require("../constants");
28
29
  const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
29
30
  const { eModeCategoriesData } = extractedState;
30
31
  const usedAssetsValues = Object.values(usedAssets);
@@ -313,6 +314,7 @@ const _getAaveV3AccountBalances = (provider, network, block, addressMapping, add
313
314
  const marketAddress = market.providerAddress;
314
315
  // @ts-ignore
315
316
  const protocolDataProviderContract = (0, contracts_1.createViemContractFromConfigFunc)(market.protocolData, market.protocolDataAddress)(provider, network);
317
+ // @ts-ignore
316
318
  const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens((0, viem_1.setViemBlockNumber)(block));
317
319
  const symbols = reserveTokens.map(({ symbol }) => symbol);
318
320
  const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
@@ -417,3 +419,93 @@ const getAaveV3FullPositionData = (provider, network, address, market) => __awai
417
419
  return positionData;
418
420
  });
419
421
  exports.getAaveV3FullPositionData = getAaveV3FullPositionData;
422
+ // aTokens eligible for AAVE rewards
423
+ exports.REWARDABLE_ASSETS = [
424
+ '0x028171bCA77440897B824Ca71D1c56caC55b68A3', // DAI
425
+ '0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d',
426
+ '0xD37EE7e4f452C6638c96536e68090De8cBcdb583', // GUSD
427
+ '0x279AF5b99540c1A3A7E3CDd326e19659401eF99e',
428
+ '0xBcca60bB61934080951369a648Fb03DF4F96263C', // USDC
429
+ '0x619beb58998eD2278e08620f97007e1116D5D25b',
430
+ '0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811', // USDT
431
+ '0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec',
432
+ '0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656', // WBTC
433
+ '0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2',
434
+ '0x030bA81f1c18d280636F32af80b9AAd02Cf0854e', // WETH
435
+ '0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf',
436
+ '0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0', // LINK
437
+ '0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D',
438
+ '0x6C5024Cd4F8A59110119C56f8933403A539555EB', // SUSD
439
+ '0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817',
440
+ '0x5165d24277cD063F5ac44Efd447B27025e888f37', // YFI
441
+ '0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97',
442
+ '0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a', // xSUSHI
443
+ '0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A',
444
+ '0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1', // UNI
445
+ '0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73',
446
+ '0xc713e5E149D5D0715DcD1c156a020976e7E56B88', // MKR
447
+ '0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8',
448
+ '0x101cc05f4A51C0319f570d5E146a8C625198e636', // TUSD
449
+ '0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92',
450
+ '0xc9BC48c72154ef3e5425641a3c747242112a46AF', // RAI
451
+ '0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b',
452
+ '0x272F97b7a56a387aE942350bBC7Df5700f8a4576', // BAL
453
+ '0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0',
454
+ '0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3', // USDP
455
+ '0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7',
456
+ '0xA361718326c15715591c299427c62086F69923D9', // BUSD
457
+ '0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c',
458
+ '0xd4937682df3C8aEF4FE912A96A74121C0829E664', // FRAX
459
+ '0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca',
460
+ '0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3', // FEI
461
+ '0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe',
462
+ '0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1', // CRV
463
+ '0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684',
464
+ '0x6F634c6135D2EBD550000ac92F494F9CB8183dAe', // DPI
465
+ '0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0',
466
+ ];
467
+ const fetchYearlyMeritApyForStakingGho = () => __awaiter(void 0, void 0, void 0, function* () {
468
+ var _a, _b;
469
+ try {
470
+ const response = yield fetch('https://apps.aavechan.com/api/merit/aprs', { signal: AbortSignal.timeout(5000) });
471
+ const data = yield response.json();
472
+ const apr = ((_b = (_a = data === null || data === void 0 ? void 0 : data.currentAPR) === null || _a === void 0 ? void 0 : _a.actionsAPR) === null || _b === void 0 ? void 0 : _b['ethereum-stkgho']) || '0';
473
+ const apy = (0, moneymarket_1.aprToApy)(apr);
474
+ const apyWithDFSBonus = new decimal_js_1.default(apy).mul(1.05).toString(); // 5% bonus for DFS users
475
+ return apyWithDFSBonus;
476
+ }
477
+ catch (e) {
478
+ const message = 'External API Failure: Failed to fetch yearly merit APY for staking GHO';
479
+ console.error(message, e);
480
+ return '0';
481
+ }
482
+ });
483
+ exports.fetchYearlyMeritApyForStakingGho = fetchYearlyMeritApyForStakingGho;
484
+ const getStakeAaveData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
485
+ const stkGhoAddress = (0, tokens_1.getAssetInfo)('stkGHO').address;
486
+ const stkAaveAddress = (0, tokens_1.getAssetInfo)('stkAAVE').address;
487
+ const AaveIncentivesController = (0, contracts_1.AaveIncentivesControllerViem)(provider, network);
488
+ const stkAAVE = (0, contracts_1.StkAAVEViem)(provider, network);
489
+ const stkGHO = (0, contracts_1.createViemContractFromConfigFunc)('Erc20', stkGhoAddress)(provider, network);
490
+ const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy] = yield Promise.all([
491
+ AaveIncentivesController.read.getRewardsBalance([exports.REWARDABLE_ASSETS, address]),
492
+ stkAAVE.read.assets([stkAaveAddress]),
493
+ stkAAVE.read.balanceOf([address]),
494
+ stkAAVE.read.totalSupply(),
495
+ stkGHO.read.balanceOf([address]),
496
+ (0, exports.fetchYearlyMeritApyForStakingGho)(),
497
+ ]);
498
+ const stkAaveApy = new decimal_js_1.default((0, tokens_1.assetAmountInEth)(emissionsPerSecond[0].toString(), 'GHO') || 0).mul(constants_1.SECONDS_PER_YEAR).mul(100).div((0, tokens_1.assetAmountInEth)(stkAAVETotalSupply.toString(), 'stkAAVE'))
499
+ .toString();
500
+ return {
501
+ activatedCooldown: '0',
502
+ activatedCooldownAmount: '0',
503
+ stkAaveRewardsBalance: '0',
504
+ aaveRewardsBalance: (0, tokens_1.assetAmountInEth)(aaveRewardsBalance.toString(), 'AAVE'),
505
+ stkAaveBalance: (0, tokens_1.assetAmountInEth)(stkAAVEBalance.toString(), 'stkAAVE'),
506
+ stkGhoBalance: (0, tokens_1.assetAmountInEth)(stkGHOBalance.toString(), 'GHO'),
507
+ ghoMeritApy,
508
+ stkAaveApy,
509
+ };
510
+ });
511
+ exports.getStakeAaveData = getStakeAaveData;
@@ -0,0 +1,9 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { ClaimableToken } from '../types/claiming';
4
+ /**
5
+ * won't cover all cases
6
+ */
7
+ export declare const getAaveUnderlyingSymbol: (_symbol?: string) => any;
8
+ export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<ClaimableToken[]>;
9
+ export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber, acceptMorpho?: boolean): Promise<ClaimableToken[]>;
@@ -0,0 +1,148 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getAaveUnderlyingSymbol = void 0;
16
+ exports.getUnclaimedRewardsForAllMarkets = getUnclaimedRewardsForAllMarkets;
17
+ exports.getMeritUnclaimedRewards = getMeritUnclaimedRewards;
18
+ const decimal_js_1 = __importDefault(require("decimal.js"));
19
+ const claiming_1 = require("../types/claiming");
20
+ const contracts_1 = require("../contracts");
21
+ const utils_1 = require("../services/utils");
22
+ /**
23
+ * won't cover all cases
24
+ */
25
+ const getAaveUnderlyingSymbol = (_symbol = '') => {
26
+ let symbol = _symbol
27
+ .replace(/^aEthLido/, '')
28
+ .replace(/^aEthEtherFi/, '')
29
+ .replace(/^aEth/, '')
30
+ .replace(/^aArb/, '')
31
+ .replace(/^aOpt/, '')
32
+ .replace(/^aBas/, '');
33
+ if (symbol.startsWith('a'))
34
+ symbol = symbol.slice(1);
35
+ return (0, utils_1.wethToEth)(symbol);
36
+ };
37
+ exports.getAaveUnderlyingSymbol = getAaveUnderlyingSymbol;
38
+ const mapAaveRewardsToClaimableTokens = (aaveRewards, marketAddress, walletAddress) => aaveRewards.map(reward => ({
39
+ symbol: reward.symbol,
40
+ amount: reward.amount,
41
+ claimType: claiming_1.ClaimType.AAVE_REWARDS,
42
+ tokenAddress: reward.rewardTokenAddress,
43
+ underlyingSymbol: reward.underlyingAsset,
44
+ walletAddress,
45
+ label: 'AAVE Rewards',
46
+ additionalClaimFields: {
47
+ marketAddress,
48
+ aTokenAddresses: reward.aTokenAddresses,
49
+ isAaveToken: reward.symbol.startsWith('a'),
50
+ },
51
+ }));
52
+ function getUnclaimedRewardsForAllMarkets(provider, network, walletAddress, marketAddress) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const contract = (0, contracts_1.AaveIncentiveDataProviderV3ContractViem)(provider, network);
55
+ const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
56
+ const allTokensDataArrays = tokensData.reduce((acc, val) => {
57
+ acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
58
+ acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
59
+ return acc;
60
+ }, []);
61
+ const allATokens = tokensData.reduce((acc, val) => {
62
+ acc.push(val.aTokenIncentivesUserData.tokenAddress);
63
+ acc.push(val.vTokenIncentivesUserData.tokenAddress);
64
+ return acc;
65
+ }, []);
66
+ // array of rewards for each market (aToken/vToken)
67
+ // reward can be any token like wstETH, but also aToken like aWETH
68
+ const aaveRewardsController = (0, contracts_1.AaveRewardsControllerViem)(provider, network);
69
+ const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => aaveRewardsController.read.getAllUserRewards([[token], walletAddress])));
70
+ // match amounts to token symbol, parse decimal amounts
71
+ const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
72
+ const rewardsList = rewardForAAsset[0];
73
+ const amounts = rewardForAAsset[1];
74
+ const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
75
+ const aTokenAddress = allATokens[aaIndex];
76
+ return rewardsList.map((rewardTokenAddress, rewardIndex) => {
77
+ var _a, _b;
78
+ const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr) => (0, utils_1.compareAddresses)(arr.rewardTokenAddress, rewardTokenAddress));
79
+ const amountWei = amounts[rewardIndex];
80
+ const amount = (0, utils_1.getEthAmountForDecimals)(amountWei.toString(), (_a = rewardsDataArraysForAAsset[dataArrIndex]) === null || _a === void 0 ? void 0 : _a.rewardTokenDecimals);
81
+ const symbol = ((_b = rewardsDataArraysForAAsset[dataArrIndex]) === null || _b === void 0 ? void 0 : _b.rewardTokenSymbol) || '';
82
+ const underlyingAsset = (0, exports.getAaveUnderlyingSymbol)(symbol);
83
+ return ({
84
+ amount,
85
+ symbol,
86
+ underlyingAsset,
87
+ rewardTokenAddress,
88
+ aTokenAddress,
89
+ });
90
+ });
91
+ });
92
+ // sum all unclaimed rewards of all markets per each token
93
+ // (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
94
+ const totalUnclaimedPerRewardToken = {};
95
+ rewardsPerAAssetWithInfo
96
+ .flat()
97
+ .forEach(({ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress, }) => {
98
+ if (+amount > 0) {
99
+ if (!totalUnclaimedPerRewardToken[symbol]) {
100
+ totalUnclaimedPerRewardToken[symbol] = {
101
+ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
102
+ };
103
+ }
104
+ else {
105
+ totalUnclaimedPerRewardToken[symbol].amount =
106
+ new decimal_js_1.default(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
107
+ totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
108
+ }
109
+ }
110
+ }, []);
111
+ return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
112
+ });
113
+ }
114
+ function getMeritUnclaimedRewards(account_1, network_1) {
115
+ return __awaiter(this, arguments, void 0, function* (account, network, acceptMorpho = true) {
116
+ const res = yield fetch(`https://api.merkl.xyz/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
117
+ const data = yield res.json();
118
+ const claimableTokens = [];
119
+ data.forEach((item) => {
120
+ item.rewards.forEach(reward => {
121
+ const { token, amount, claimed, proofs, } = reward;
122
+ const isTokenMorpho = token.symbol === 'MORPHO';
123
+ if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho))
124
+ return;
125
+ const unclaimedAmount = new decimal_js_1.default(amount).minus(claimed || 0).toString();
126
+ if (unclaimedAmount === '0')
127
+ return;
128
+ const unclaimed = (0, utils_1.getEthAmountForDecimals)(unclaimedAmount, token.decimals);
129
+ claimableTokens.push({
130
+ claimType: claiming_1.ClaimType.AAVE_MERIT_REWARDS,
131
+ amount: unclaimed,
132
+ symbol: token.symbol,
133
+ tokenAddress: token.address,
134
+ walletAddress: account,
135
+ label: 'AAVE Merit Rewards',
136
+ underlyingSymbol: (0, exports.getAaveUnderlyingSymbol)(token.symbol),
137
+ additionalClaimFields: {
138
+ accumulated: amount,
139
+ proof: proofs,
140
+ decimals: token.decimals,
141
+ unclaimed: unclaimedAmount,
142
+ },
143
+ });
144
+ });
145
+ });
146
+ return claimableTokens;
147
+ });
148
+ }
@@ -0,0 +1,15 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ import { ClaimType } from '../types/claiming';
4
+ export declare const getCompoundV3Rewards: (provider: Client, network: NetworkNumber, user: EthAddress, market: any) => Promise<{
5
+ symbol: string;
6
+ underlyingSymbol: string;
7
+ tokenAddress: `0x${string}`;
8
+ amount: string;
9
+ walletAddress: `0x${string}`;
10
+ label: string;
11
+ claimType: ClaimType;
12
+ additionalClaimFields: {
13
+ marketAddress: any;
14
+ };
15
+ }[]>;
@@ -0,0 +1,34 @@
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.getCompoundV3Rewards = void 0;
13
+ const tokens_1 = require("@defisaver/tokens");
14
+ const contracts_1 = require("../contracts");
15
+ const claiming_1 = require("../types/claiming");
16
+ const getCompoundV3Rewards = (provider, network, user, market) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const compV3View = (0, contracts_1.CompV3ViewContractViem)(provider, network);
18
+ const rewards = yield compV3View.read.getRewardsOwed([market, user]);
19
+ if (!rewards || rewards.owed.toString() === '0' || (0, tokens_1.getAssetInfoByAddress)(rewards.token, network).symbol !== 'COMP')
20
+ return [];
21
+ return [{
22
+ symbol: 'COMP',
23
+ underlyingSymbol: 'COMP',
24
+ tokenAddress: rewards.token,
25
+ amount: (0, tokens_1.assetAmountInEth)(rewards.owed.toString() || 0, 'COMP'),
26
+ walletAddress: user,
27
+ label: 'Compound V3',
28
+ claimType: claiming_1.ClaimType.COMPOUND_V3_COMP,
29
+ additionalClaimFields: {
30
+ marketAddress: market,
31
+ },
32
+ }];
33
+ });
34
+ exports.getCompoundV3Rewards = getCompoundV3Rewards;
@@ -0,0 +1,6 @@
1
+ import * as aaveV3Claim from './aaveV3';
2
+ import * as compV3Claim from './compV3';
3
+ import * as kingV3Claim from './king';
4
+ import * as morphoBlueClaim from './morphoBlue';
5
+ import * as sparkClaim from './spark';
6
+ export { aaveV3Claim, compV3Claim, kingV3Claim, morphoBlueClaim, sparkClaim, };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.sparkClaim = exports.morphoBlueClaim = exports.kingV3Claim = exports.compV3Claim = exports.aaveV3Claim = void 0;
37
+ const aaveV3Claim = __importStar(require("./aaveV3"));
38
+ exports.aaveV3Claim = aaveV3Claim;
39
+ const compV3Claim = __importStar(require("./compV3"));
40
+ exports.compV3Claim = compV3Claim;
41
+ const kingV3Claim = __importStar(require("./king"));
42
+ exports.kingV3Claim = kingV3Claim;
43
+ const morphoBlueClaim = __importStar(require("./morphoBlue"));
44
+ exports.morphoBlueClaim = morphoBlueClaim;
45
+ const sparkClaim = __importStar(require("./spark"));
46
+ exports.sparkClaim = sparkClaim;
@@ -0,0 +1,4 @@
1
+ import { Client } from 'viem';
2
+ import { EthAddress, NetworkNumber } from '../types/common';
3
+ export declare const fetchKingRewards: (walletAddress: EthAddress) => Promise<any>;
4
+ export declare const getKingRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, any[]>>;
@@ -0,0 +1,72 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getKingRewards = exports.fetchKingRewards = void 0;
16
+ const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const tokens_1 = require("@defisaver/tokens");
18
+ const contracts_1 = require("../contracts");
19
+ const claiming_1 = require("../types/claiming");
20
+ const fetchKingRewards = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
21
+ try {
22
+ const res = yield fetch(`https://fe.defisaver.com/api/etherfi/get-king-rewards/${walletAddress}`, { signal: AbortSignal.timeout(5000) });
23
+ if (!res.ok)
24
+ throw new Error(yield res.text());
25
+ return yield res.json();
26
+ }
27
+ catch (err) {
28
+ console.error('External API Error: Error fetching KING rewards:', err);
29
+ return { Amount: '0', Root: '', Proofs: [] };
30
+ }
31
+ });
32
+ exports.fetchKingRewards = fetchKingRewards;
33
+ const getKingRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
34
+ // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
35
+ const apiDataPromises = walletAddresses.map(address => (0, exports.fetchKingRewards)(address));
36
+ const apiDataArray = yield Promise.all(apiDataPromises);
37
+ // Batch all contract calls using multicall
38
+ const contract = (0, contracts_1.UUPSViem)(provider, network);
39
+ const cumulativePromises = walletAddresses.map(address => contract.read.cumulativeClaimed([address]));
40
+ const cumulativeResults = yield Promise.all(cumulativePromises);
41
+ // Process results
42
+ const results = {};
43
+ for (let i = 0; i < walletAddresses.length; i++) {
44
+ const walletAddress = walletAddresses[i];
45
+ const data = apiDataArray[i];
46
+ const cumulative = cumulativeResults[i];
47
+ const allRewardsAmount = (0, tokens_1.assetAmountInEth)(data.Amount, 'KING');
48
+ const claimedAmount = (0, tokens_1.assetAmountInEth)(cumulative.toString(), 'KING');
49
+ const amountToClaim = new decimal_js_1.default(allRewardsAmount).sub(claimedAmount);
50
+ if (amountToClaim.lessThanOrEqualTo('0')) {
51
+ results[walletAddress.toLowerCase()] = [];
52
+ }
53
+ else {
54
+ results[walletAddress.toLowerCase()] = [{
55
+ symbol: 'KING',
56
+ underlyingSymbol: 'KING',
57
+ tokenAddress: '0x8F08B70456eb22f6109F57b8fafE862ED28E6040',
58
+ amount: amountToClaim.toString(),
59
+ walletAddress,
60
+ label: 'weETH',
61
+ claimType: claiming_1.ClaimType.KING_REWARDS,
62
+ additionalClaimFields: {
63
+ allRewardsAmount,
64
+ merkleRoot: data.Root,
65
+ merkleProofs: data.Proofs,
66
+ },
67
+ }];
68
+ }
69
+ }
70
+ return results;
71
+ });
72
+ exports.getKingRewards = getKingRewards;
@@ -0,0 +1,6 @@
1
+ import { Client } from 'viem';
2
+ import { ClaimableToken } from '../types/claiming';
3
+ import { EthAddress, NetworkNumber } from '../types/common';
4
+ export declare const getMorphoUnderlyingSymbol: (_symbol: string) => any;
5
+ export declare const getMorphoBlueRewardsInfo: (address: EthAddress) => Promise<any>;
6
+ export declare const fetchMorphoBlueRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, ClaimableToken[]>>;
@@ -0,0 +1,113 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.fetchMorphoBlueRewards = exports.getMorphoBlueRewardsInfo = exports.getMorphoUnderlyingSymbol = void 0;
16
+ const tokens_1 = require("@defisaver/tokens");
17
+ const decimal_js_1 = __importDefault(require("decimal.js"));
18
+ const claiming_1 = require("../types/claiming");
19
+ const contracts_1 = require("../contracts");
20
+ const utils_1 = require("../services/utils");
21
+ const MORPHO_ALLOWED_CONTRACTS = [
22
+ '0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb',
23
+ '0x678dDC1d07eaa166521325394cDEb1E4c086DF43',
24
+ '0x2efd4625d0c149ebadf118ec5446c6de24d916a4',
25
+ ];
26
+ const MORPHO_ALLOWED_TOKENS = [
27
+ 'MORPHO',
28
+ 'MORPHO Legacy',
29
+ ];
30
+ const getMorphoUnderlyingSymbol = (_symbol) => {
31
+ if (_symbol === 'MORPHO Legacy')
32
+ return 'MORPHO';
33
+ return (0, utils_1.wethToEth)(_symbol);
34
+ };
35
+ exports.getMorphoUnderlyingSymbol = getMorphoUnderlyingSymbol;
36
+ const getMorphoBlueRewardsInfo = (address) => __awaiter(void 0, void 0, void 0, function* () {
37
+ if (!address)
38
+ return { claimable: '0' };
39
+ const res = yield fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`, { signal: AbortSignal.timeout(3000) });
40
+ if (!res.ok)
41
+ throw new Error(yield res.text());
42
+ return res.json();
43
+ });
44
+ exports.getMorphoBlueRewardsInfo = getMorphoBlueRewardsInfo;
45
+ const fetchMorphoBlueRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
46
+ var _a;
47
+ // Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
48
+ const apiDataPromises = walletAddresses.map(address => (0, exports.getMorphoBlueRewardsInfo)(address));
49
+ const apiDataArray = yield Promise.all(apiDataPromises);
50
+ // Process API data to get claimable tokens for each wallet
51
+ const allClaimableTokens = [];
52
+ const contractCallsData = [];
53
+ for (let i = 0; i < walletAddresses.length; i++) {
54
+ const walletAddress = walletAddresses[i];
55
+ const data = apiDataArray[i];
56
+ const claimableTokens = ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.reduce((acc, reward) => {
57
+ var _a, _b, _c;
58
+ const token = (0, tokens_1.getAssetInfoByAddress)(reward.asset.address);
59
+ 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)) {
60
+ return acc;
61
+ }
62
+ // Store contract call data for batching
63
+ contractCallsData.push({
64
+ walletAddress,
65
+ tokenAddress: reward.asset.address,
66
+ distributor: (_b = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _b === void 0 ? void 0 : _b.address,
67
+ });
68
+ return [
69
+ ...acc,
70
+ {
71
+ symbol: token.symbol,
72
+ underlyingSymbol: (0, exports.getMorphoUnderlyingSymbol)(token.symbol),
73
+ tokenAddress: reward.asset.address,
74
+ amount: (0, tokens_1.assetAmountInEth)(reward.claimable, token.symbol),
75
+ walletAddress,
76
+ label: token.symbol,
77
+ claimType: claiming_1.ClaimType.MORPHO,
78
+ additionalClaimFields: {
79
+ originalAmount: reward.claimable,
80
+ distributor: (_c = reward === null || reward === void 0 ? void 0 : reward.distributor) === null || _c === void 0 ? void 0 : _c.address,
81
+ merkleProofs: reward === null || reward === void 0 ? void 0 : reward.proof,
82
+ isLegacy: token.symbol === 'MORPHO Legacy',
83
+ txData: reward === null || reward === void 0 ? void 0 : reward.tx_data,
84
+ },
85
+ }
86
+ ];
87
+ }, [])) || [];
88
+ allClaimableTokens.push({ walletAddress, tokens: claimableTokens });
89
+ }
90
+ // Batch all contract calls using multicall
91
+ const contractPromises = contractCallsData.map(({ walletAddress, tokenAddress, distributor }) => {
92
+ const distributorContract = (0, contracts_1.createViemContractFromConfigFunc)('MorphoDistributor', distributor)(provider, network);
93
+ return distributorContract.read.claimed([walletAddress, tokenAddress]);
94
+ });
95
+ const contractResults = yield Promise.all(contractPromises);
96
+ // Process results
97
+ const results = {};
98
+ let contractCallIndex = 0;
99
+ for (const { walletAddress, tokens } of allClaimableTokens) {
100
+ const updatedTokens = [];
101
+ for (let i = 0; i < tokens.length; i++) {
102
+ const claimableToken = tokens[i];
103
+ const claimed = (0, tokens_1.assetAmountInEth)(contractResults[contractCallIndex].toString(), claimableToken.underlyingSymbol);
104
+ contractCallIndex++;
105
+ const updatedToken = Object.assign({}, claimableToken);
106
+ updatedToken.amount = new decimal_js_1.default(claimableToken.amount).sub(claimed).toString();
107
+ updatedTokens.push(updatedToken);
108
+ }
109
+ results[walletAddress.toLowerCase()] = updatedTokens.filter((claimableToken) => new decimal_js_1.default(claimableToken.amount).gt(0));
110
+ }
111
+ return results;
112
+ });
113
+ exports.fetchMorphoBlueRewards = fetchMorphoBlueRewards;