@defisaver/positions-sdk 2.1.1 → 2.1.3
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.
- package/cjs/aaveV2/index.js +1 -0
- package/cjs/aaveV3/index.d.ts +12 -0
- package/cjs/aaveV3/index.js +93 -1
- package/cjs/claiming/aaveV3.d.ts +5 -0
- package/cjs/claiming/aaveV3.js +139 -0
- package/cjs/claiming/compV3.d.ts +15 -0
- package/cjs/claiming/compV3.js +34 -0
- package/cjs/claiming/index.d.ts +6 -0
- package/cjs/claiming/index.js +46 -0
- package/cjs/claiming/king.d.ts +4 -0
- package/cjs/claiming/king.js +72 -0
- package/cjs/claiming/morphoBlue.d.ts +5 -0
- package/cjs/claiming/morphoBlue.js +113 -0
- package/cjs/claiming/spark.d.ts +6 -0
- package/cjs/claiming/spark.js +188 -0
- package/cjs/config/contracts.d.ts +2681 -0
- package/cjs/config/contracts.js +103 -2
- package/cjs/constants/index.d.ts +4 -0
- package/cjs/constants/index.js +6 -2
- package/cjs/contracts.d.ts +3027 -23
- package/cjs/contracts.js +10 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +4 -0
- package/cjs/helpers/aaveHelpers/index.js +25 -8
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/cjs/helpers/morphoBlueHelpers/index.js +7 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/liquity/index.d.ts +11 -0
- package/cjs/liquity/index.js +39 -1
- package/cjs/liquityV2/index.d.ts +35 -0
- package/cjs/liquityV2/index.js +142 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +35 -0
- package/cjs/portfolio/index.d.ts +6 -1
- package/cjs/portfolio/index.js +293 -10
- package/cjs/services/utils.d.ts +5 -0
- package/cjs/services/utils.js +33 -1
- package/cjs/services/viem.d.ts +12 -12
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/eligibility.d.ts +4 -2
- package/cjs/staking/eligibility.js +3 -4
- package/cjs/staking/staking.d.ts +2 -1
- package/cjs/staking/staking.js +3 -3
- package/cjs/types/claiming.d.ts +93 -0
- package/cjs/types/claiming.js +27 -0
- package/cjs/types/common.d.ts +1 -1
- package/cjs/types/common.js +1 -1
- package/cjs/umbrella/index.d.ts +5 -0
- package/cjs/umbrella/index.js +50 -0
- package/cjs/umbrella/umbrellaUtils.d.ts +22 -0
- package/cjs/umbrella/umbrellaUtils.js +34 -0
- package/esm/aaveV2/index.js +1 -0
- package/esm/aaveV3/index.d.ts +12 -0
- package/esm/aaveV3/index.js +91 -1
- package/esm/claiming/aaveV3.d.ts +5 -0
- package/esm/claiming/aaveV3.js +132 -0
- package/esm/claiming/compV3.d.ts +15 -0
- package/esm/claiming/compV3.js +30 -0
- package/esm/claiming/index.d.ts +6 -0
- package/esm/claiming/index.js +6 -0
- package/esm/claiming/king.d.ts +4 -0
- package/esm/claiming/king.js +64 -0
- package/esm/claiming/morphoBlue.d.ts +5 -0
- package/esm/claiming/morphoBlue.js +105 -0
- package/esm/claiming/spark.d.ts +6 -0
- package/esm/claiming/spark.js +179 -0
- package/esm/config/contracts.d.ts +2681 -0
- package/esm/config/contracts.js +102 -1
- package/esm/constants/index.d.ts +4 -0
- package/esm/constants/index.js +5 -1
- package/esm/contracts.d.ts +3027 -23
- package/esm/contracts.js +9 -0
- package/esm/helpers/aaveHelpers/index.d.ts +4 -0
- package/esm/helpers/aaveHelpers/index.js +23 -7
- package/esm/helpers/morphoBlueHelpers/index.d.ts +1 -0
- package/esm/helpers/morphoBlueHelpers/index.js +6 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/liquity/index.d.ts +11 -0
- package/esm/liquity/index.js +38 -1
- package/esm/liquityV2/index.d.ts +35 -0
- package/esm/liquityV2/index.js +142 -3
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +35 -1
- package/esm/portfolio/index.d.ts +6 -1
- package/esm/portfolio/index.js +298 -15
- package/esm/services/utils.d.ts +5 -0
- package/esm/services/utils.js +31 -0
- package/esm/services/viem.d.ts +12 -12
- package/esm/spark/index.js +1 -0
- package/esm/staking/eligibility.d.ts +4 -2
- package/esm/staking/eligibility.js +3 -4
- package/esm/staking/staking.d.ts +2 -1
- package/esm/staking/staking.js +3 -3
- package/esm/types/claiming.d.ts +93 -0
- package/esm/types/claiming.js +24 -0
- package/esm/types/common.d.ts +1 -1
- package/esm/types/common.js +1 -1
- package/esm/umbrella/index.d.ts +5 -0
- package/esm/umbrella/index.js +46 -0
- package/esm/umbrella/umbrellaUtils.d.ts +22 -0
- package/esm/umbrella/umbrellaUtils.js +28 -0
- package/package.json +1 -1
- package/src/aaveV2/index.ts +2 -1
- package/src/aaveV3/index.ts +100 -2
- package/src/claiming/aaveV3.ts +155 -0
- package/src/claiming/compV3.ts +23 -0
- package/src/claiming/index.ts +13 -0
- package/src/claiming/king.ts +66 -0
- package/src/claiming/morphoBlue.ts +119 -0
- package/src/claiming/spark.ts +226 -0
- package/src/config/contracts.ts +104 -4
- package/src/constants/index.ts +5 -1
- package/src/contracts.ts +14 -1
- package/src/helpers/aaveHelpers/index.ts +24 -7
- package/src/helpers/morphoBlueHelpers/index.ts +7 -2
- package/src/index.ts +2 -0
- package/src/liquity/index.ts +57 -2
- package/src/liquityV2/index.ts +244 -4
- package/src/morphoBlue/index.ts +40 -2
- package/src/portfolio/index.ts +300 -15
- package/src/services/utils.ts +37 -1
- package/src/spark/index.ts +2 -1
- package/src/staking/eligibility.ts +3 -4
- package/src/staking/staking.ts +4 -4
- package/src/types/claiming.ts +109 -0
- package/src/types/common.ts +1 -1
- package/src/umbrella/index.ts +70 -0
- package/src/umbrella/umbrellaUtils.ts +30 -0
package/cjs/aaveV2/index.js
CHANGED
|
@@ -105,6 +105,7 @@ const _getAaveV2AccountBalances = (provider, network, block, addressMapping, add
|
|
|
105
105
|
const marketAddress = market.providerAddress;
|
|
106
106
|
// @ts-ignore
|
|
107
107
|
const protocolDataProviderContract = (0, contracts_1.createViemContractFromConfigFunc)(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
108
|
+
// @ts-ignore
|
|
108
109
|
const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens((0, viem_1.setViemBlockNumber)(block));
|
|
109
110
|
const symbols = reserveTokens.map(({ symbol }) => symbol);
|
|
110
111
|
const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
|
package/cjs/aaveV3/index.d.ts
CHANGED
|
@@ -34,4 +34,16 @@ export declare const getAaveV3AccountBalances: (provider: EthereumProvider, netw
|
|
|
34
34
|
export declare const _getAaveV3AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
|
|
35
35
|
export declare const getAaveV3AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, extractedState: any, blockNumber?: "latest" | number) => Promise<AaveV3PositionData>;
|
|
36
36
|
export declare const getAaveV3FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo) => Promise<AaveV3PositionData>;
|
|
37
|
+
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"];
|
|
38
|
+
export declare const fetchYearlyMeritApyForStakingGho: () => Promise<string>;
|
|
39
|
+
export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
|
|
40
|
+
activatedCooldown: string;
|
|
41
|
+
activatedCooldownAmount: string;
|
|
42
|
+
stkAaveRewardsBalance: string;
|
|
43
|
+
aaveRewardsBalance: string;
|
|
44
|
+
stkAaveBalance: string;
|
|
45
|
+
stkGhoBalance: string;
|
|
46
|
+
ghoMeritApy: string;
|
|
47
|
+
stkAaveApy: string;
|
|
48
|
+
}>;
|
|
37
49
|
export { getMeritCampaigns, getMerkleCampaigns, };
|
package/cjs/aaveV3/index.js
CHANGED
|
@@ -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.getMerkleCampaigns = exports.getMeritCampaigns = exports.getAaveV3FullPositionData = exports.getAaveV3AccountData = exports._getAaveV3AccountData = exports.getAaveV3AccountBalances = exports._getAaveV3AccountBalances = exports.EMPTY_AAVE_DATA = exports.aaveV3EmodeCategoriesMapping = void 0;
|
|
15
|
+
exports.getMerkleCampaigns = exports.getMeritCampaigns = 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");
|
|
@@ -29,6 +29,7 @@ const merit_1 = require("./merit");
|
|
|
29
29
|
Object.defineProperty(exports, "getMeritCampaigns", { enumerable: true, get: function () { return merit_1.getMeritCampaigns; } });
|
|
30
30
|
const merkl_1 = require("./merkl");
|
|
31
31
|
Object.defineProperty(exports, "getMerkleCampaigns", { enumerable: true, get: function () { return merkl_1.getMerkleCampaigns; } });
|
|
32
|
+
const constants_1 = require("../constants");
|
|
32
33
|
const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
33
34
|
const { eModeCategoriesData } = extractedState;
|
|
34
35
|
const usedAssetsValues = Object.values(usedAssets);
|
|
@@ -332,6 +333,7 @@ const _getAaveV3AccountBalances = (provider, network, block, addressMapping, add
|
|
|
332
333
|
const marketAddress = market.providerAddress;
|
|
333
334
|
// @ts-ignore
|
|
334
335
|
const protocolDataProviderContract = (0, contracts_1.createViemContractFromConfigFunc)(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
336
|
+
// @ts-ignore
|
|
335
337
|
const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens((0, viem_1.setViemBlockNumber)(block));
|
|
336
338
|
const symbols = reserveTokens.map(({ symbol }) => symbol);
|
|
337
339
|
const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
|
|
@@ -436,3 +438,93 @@ const getAaveV3FullPositionData = (provider, network, address, market) => __awai
|
|
|
436
438
|
return positionData;
|
|
437
439
|
});
|
|
438
440
|
exports.getAaveV3FullPositionData = getAaveV3FullPositionData;
|
|
441
|
+
// aTokens eligible for AAVE rewards
|
|
442
|
+
exports.REWARDABLE_ASSETS = [
|
|
443
|
+
'0x028171bCA77440897B824Ca71D1c56caC55b68A3', // DAI
|
|
444
|
+
'0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d',
|
|
445
|
+
'0xD37EE7e4f452C6638c96536e68090De8cBcdb583', // GUSD
|
|
446
|
+
'0x279AF5b99540c1A3A7E3CDd326e19659401eF99e',
|
|
447
|
+
'0xBcca60bB61934080951369a648Fb03DF4F96263C', // USDC
|
|
448
|
+
'0x619beb58998eD2278e08620f97007e1116D5D25b',
|
|
449
|
+
'0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811', // USDT
|
|
450
|
+
'0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec',
|
|
451
|
+
'0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656', // WBTC
|
|
452
|
+
'0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2',
|
|
453
|
+
'0x030bA81f1c18d280636F32af80b9AAd02Cf0854e', // WETH
|
|
454
|
+
'0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf',
|
|
455
|
+
'0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0', // LINK
|
|
456
|
+
'0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D',
|
|
457
|
+
'0x6C5024Cd4F8A59110119C56f8933403A539555EB', // SUSD
|
|
458
|
+
'0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817',
|
|
459
|
+
'0x5165d24277cD063F5ac44Efd447B27025e888f37', // YFI
|
|
460
|
+
'0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97',
|
|
461
|
+
'0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a', // xSUSHI
|
|
462
|
+
'0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A',
|
|
463
|
+
'0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1', // UNI
|
|
464
|
+
'0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73',
|
|
465
|
+
'0xc713e5E149D5D0715DcD1c156a020976e7E56B88', // MKR
|
|
466
|
+
'0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8',
|
|
467
|
+
'0x101cc05f4A51C0319f570d5E146a8C625198e636', // TUSD
|
|
468
|
+
'0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92',
|
|
469
|
+
'0xc9BC48c72154ef3e5425641a3c747242112a46AF', // RAI
|
|
470
|
+
'0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b',
|
|
471
|
+
'0x272F97b7a56a387aE942350bBC7Df5700f8a4576', // BAL
|
|
472
|
+
'0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0',
|
|
473
|
+
'0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3', // USDP
|
|
474
|
+
'0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7',
|
|
475
|
+
'0xA361718326c15715591c299427c62086F69923D9', // BUSD
|
|
476
|
+
'0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c',
|
|
477
|
+
'0xd4937682df3C8aEF4FE912A96A74121C0829E664', // FRAX
|
|
478
|
+
'0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca',
|
|
479
|
+
'0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3', // FEI
|
|
480
|
+
'0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe',
|
|
481
|
+
'0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1', // CRV
|
|
482
|
+
'0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684',
|
|
483
|
+
'0x6F634c6135D2EBD550000ac92F494F9CB8183dAe', // DPI
|
|
484
|
+
'0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0',
|
|
485
|
+
];
|
|
486
|
+
const fetchYearlyMeritApyForStakingGho = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
|
+
var _a, _b;
|
|
488
|
+
try {
|
|
489
|
+
const response = yield fetch('https://apps.aavechan.com/api/merit/aprs', { signal: AbortSignal.timeout(5000) });
|
|
490
|
+
const data = yield response.json();
|
|
491
|
+
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';
|
|
492
|
+
const apy = (0, moneymarket_1.aprToApy)(apr);
|
|
493
|
+
const apyWithDFSBonus = new decimal_js_1.default(apy).mul(1.05).toString(); // 5% bonus for DFS users
|
|
494
|
+
return apyWithDFSBonus;
|
|
495
|
+
}
|
|
496
|
+
catch (e) {
|
|
497
|
+
const message = 'External API Failure: Failed to fetch yearly merit APY for staking GHO';
|
|
498
|
+
console.error(message, e);
|
|
499
|
+
return '0';
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
exports.fetchYearlyMeritApyForStakingGho = fetchYearlyMeritApyForStakingGho;
|
|
503
|
+
const getStakeAaveData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
504
|
+
const stkGhoAddress = (0, tokens_1.getAssetInfo)('stkGHO').address;
|
|
505
|
+
const stkAaveAddress = (0, tokens_1.getAssetInfo)('stkAAVE').address;
|
|
506
|
+
const AaveIncentivesController = (0, contracts_1.AaveIncentivesControllerViem)(provider, network);
|
|
507
|
+
const stkAAVE = (0, contracts_1.StkAAVEViem)(provider, network);
|
|
508
|
+
const stkGHO = (0, contracts_1.createViemContractFromConfigFunc)('Erc20', stkGhoAddress)(provider, network);
|
|
509
|
+
const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy] = yield Promise.all([
|
|
510
|
+
AaveIncentivesController.read.getRewardsBalance([exports.REWARDABLE_ASSETS, address]),
|
|
511
|
+
stkAAVE.read.assets([stkAaveAddress]),
|
|
512
|
+
stkAAVE.read.balanceOf([address]),
|
|
513
|
+
stkAAVE.read.totalSupply(),
|
|
514
|
+
stkGHO.read.balanceOf([address]),
|
|
515
|
+
(0, exports.fetchYearlyMeritApyForStakingGho)(),
|
|
516
|
+
]);
|
|
517
|
+
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'))
|
|
518
|
+
.toString();
|
|
519
|
+
return {
|
|
520
|
+
activatedCooldown: '0',
|
|
521
|
+
activatedCooldownAmount: '0',
|
|
522
|
+
stkAaveRewardsBalance: '0',
|
|
523
|
+
aaveRewardsBalance: (0, tokens_1.assetAmountInEth)(aaveRewardsBalance.toString(), 'AAVE'),
|
|
524
|
+
stkAaveBalance: (0, tokens_1.assetAmountInEth)(stkAAVEBalance.toString(), 'stkAAVE'),
|
|
525
|
+
stkGhoBalance: (0, tokens_1.assetAmountInEth)(stkGHOBalance.toString(), 'GHO'),
|
|
526
|
+
ghoMeritApy,
|
|
527
|
+
stkAaveApy,
|
|
528
|
+
};
|
|
529
|
+
});
|
|
530
|
+
exports.getStakeAaveData = getStakeAaveData;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
import { ClaimableToken } from '../types/claiming';
|
|
4
|
+
export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<ClaimableToken[]>;
|
|
5
|
+
export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber, acceptMorpho?: boolean): Promise<ClaimableToken[]>;
|
|
@@ -0,0 +1,139 @@
|
|
|
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.getUnclaimedRewardsForAllMarkets = getUnclaimedRewardsForAllMarkets;
|
|
16
|
+
exports.getMeritUnclaimedRewards = getMeritUnclaimedRewards;
|
|
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 aaveHelpers_1 = require("../helpers/aaveHelpers");
|
|
22
|
+
const mapAaveRewardsToClaimableTokens = (aaveRewards, marketAddress, walletAddress) => aaveRewards.map(reward => ({
|
|
23
|
+
symbol: reward.symbol,
|
|
24
|
+
amount: reward.amount,
|
|
25
|
+
claimType: claiming_1.ClaimType.AAVE_REWARDS,
|
|
26
|
+
tokenAddress: reward.rewardTokenAddress,
|
|
27
|
+
underlyingSymbol: reward.underlyingAsset,
|
|
28
|
+
walletAddress,
|
|
29
|
+
label: 'AAVE Rewards',
|
|
30
|
+
additionalClaimFields: {
|
|
31
|
+
marketAddress,
|
|
32
|
+
aTokenAddresses: reward.aTokenAddresses,
|
|
33
|
+
isAaveToken: reward.symbol.startsWith('a'),
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
function getUnclaimedRewardsForAllMarkets(provider, network, walletAddress, marketAddress) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const contract = (0, contracts_1.AaveIncentiveDataProviderV3ContractViem)(provider, network);
|
|
39
|
+
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
40
|
+
const allTokensDataArrays = tokensData.reduce((acc, val) => {
|
|
41
|
+
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
42
|
+
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
43
|
+
return acc;
|
|
44
|
+
}, []);
|
|
45
|
+
const allATokens = tokensData.reduce((acc, val) => {
|
|
46
|
+
acc.push(val.aTokenIncentivesUserData.tokenAddress);
|
|
47
|
+
acc.push(val.vTokenIncentivesUserData.tokenAddress);
|
|
48
|
+
return acc;
|
|
49
|
+
}, []);
|
|
50
|
+
// array of rewards for each market (aToken/vToken)
|
|
51
|
+
// reward can be any token like wstETH, but also aToken like aWETH
|
|
52
|
+
const aaveRewardsController = (0, contracts_1.AaveRewardsControllerViem)(provider, network);
|
|
53
|
+
const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => aaveRewardsController.read.getAllUserRewards([[token], walletAddress])));
|
|
54
|
+
// match amounts to token symbol, parse decimal amounts
|
|
55
|
+
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
|
56
|
+
const rewardsList = rewardForAAsset[0];
|
|
57
|
+
const amounts = rewardForAAsset[1];
|
|
58
|
+
const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
|
|
59
|
+
const aTokenAddress = allATokens[aaIndex];
|
|
60
|
+
return rewardsList.map((rewardTokenAddress, rewardIndex) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr) => (0, utils_1.compareAddresses)(arr.rewardTokenAddress, rewardTokenAddress));
|
|
63
|
+
const amountWei = amounts[rewardIndex];
|
|
64
|
+
const amount = (0, utils_1.getEthAmountForDecimals)(amountWei.toString(), (_a = rewardsDataArraysForAAsset[dataArrIndex]) === null || _a === void 0 ? void 0 : _a.rewardTokenDecimals);
|
|
65
|
+
const symbol = ((_b = rewardsDataArraysForAAsset[dataArrIndex]) === null || _b === void 0 ? void 0 : _b.rewardTokenSymbol) || '';
|
|
66
|
+
const underlyingAsset = (0, aaveHelpers_1.getAaveUnderlyingSymbol)(symbol);
|
|
67
|
+
return ({
|
|
68
|
+
amount,
|
|
69
|
+
symbol,
|
|
70
|
+
underlyingAsset,
|
|
71
|
+
rewardTokenAddress,
|
|
72
|
+
aTokenAddress,
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
// sum all unclaimed rewards of all markets per each token
|
|
77
|
+
// (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
|
|
78
|
+
const totalUnclaimedPerRewardToken = {};
|
|
79
|
+
rewardsPerAAssetWithInfo
|
|
80
|
+
.flat()
|
|
81
|
+
.forEach(({ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress, }) => {
|
|
82
|
+
if (+amount > 0) {
|
|
83
|
+
if (!totalUnclaimedPerRewardToken[symbol]) {
|
|
84
|
+
totalUnclaimedPerRewardToken[symbol] = {
|
|
85
|
+
amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
totalUnclaimedPerRewardToken[symbol].amount =
|
|
90
|
+
new decimal_js_1.default(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
|
|
91
|
+
totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, []);
|
|
95
|
+
return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function getMeritUnclaimedRewards(account_1, network_1) {
|
|
99
|
+
return __awaiter(this, arguments, void 0, function* (account, network, acceptMorpho = true) {
|
|
100
|
+
let data;
|
|
101
|
+
try {
|
|
102
|
+
const res = yield fetch(`https://api.merkl.xyz/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
|
|
103
|
+
data = yield res.json();
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error('External API Failure: Aave Merit', error);
|
|
107
|
+
data = [];
|
|
108
|
+
}
|
|
109
|
+
const claimableTokens = [];
|
|
110
|
+
data.forEach((item) => {
|
|
111
|
+
item.rewards.forEach(reward => {
|
|
112
|
+
const { token, amount, claimed, proofs, } = reward;
|
|
113
|
+
const isTokenMorpho = token.symbol === 'MORPHO';
|
|
114
|
+
if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho))
|
|
115
|
+
return;
|
|
116
|
+
const unclaimedAmount = new decimal_js_1.default(amount).minus(claimed || 0).toString();
|
|
117
|
+
if (unclaimedAmount === '0')
|
|
118
|
+
return;
|
|
119
|
+
const unclaimed = (0, utils_1.getEthAmountForDecimals)(unclaimedAmount, token.decimals);
|
|
120
|
+
claimableTokens.push({
|
|
121
|
+
claimType: claiming_1.ClaimType.AAVE_MERIT_REWARDS,
|
|
122
|
+
amount: unclaimed,
|
|
123
|
+
symbol: token.symbol,
|
|
124
|
+
tokenAddress: token.address,
|
|
125
|
+
walletAddress: account,
|
|
126
|
+
label: 'AAVE Merit Rewards',
|
|
127
|
+
underlyingSymbol: (0, aaveHelpers_1.getAaveUnderlyingSymbol)(token.symbol),
|
|
128
|
+
additionalClaimFields: {
|
|
129
|
+
accumulated: amount,
|
|
130
|
+
proof: proofs,
|
|
131
|
+
decimals: token.decimals,
|
|
132
|
+
unclaimed: unclaimedAmount,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return claimableTokens;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
@@ -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,5 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import { ClaimableToken } from '../types/claiming';
|
|
3
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
4
|
+
export declare const getMorphoBlueRewardsInfo: (address: EthAddress) => Promise<any>;
|
|
5
|
+
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 = 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 morphoBlueHelpers_1 = require("../helpers/morphoBlueHelpers");
|
|
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 getMorphoBlueRewardsInfo = (address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
if (!address)
|
|
32
|
+
return { claimable: '0' };
|
|
33
|
+
try {
|
|
34
|
+
const res = yield fetch(`https://rewards.morpho.org/v1/users/${address}/distributions`, { signal: AbortSignal.timeout(3000) });
|
|
35
|
+
if (!res.ok)
|
|
36
|
+
throw new Error(yield res.text());
|
|
37
|
+
return yield res.json();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('External API Failure: Morpho Merit', error);
|
|
41
|
+
return { claimable: '0' };
|
|
42
|
+
}
|
|
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, morphoBlueHelpers_1.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;
|
|
@@ -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[]>;
|