@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.
- package/CLAUDE.md +32 -0
- 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 +9 -0
- package/cjs/claiming/aaveV3.js +148 -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 +6 -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 +2667 -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 +2882 -23
- package/cjs/contracts.js +10 -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 +8 -0
- package/cjs/liquityV2/index.js +161 -0
- package/cjs/markets/aave/marketAssets.js +1 -1
- package/cjs/markets/compound/marketsAssets.js +2 -2
- package/cjs/markets/spark/marketAssets.js +1 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +38 -4
- package/cjs/portfolio/index.d.ts +6 -1
- package/cjs/portfolio/index.js +256 -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/staking.js +3 -1
- package/cjs/types/claiming.d.ts +93 -0
- package/cjs/types/claiming.js +27 -0
- 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 +9 -0
- package/esm/claiming/aaveV3.js +139 -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 +6 -0
- package/esm/claiming/morphoBlue.js +104 -0
- package/esm/claiming/spark.d.ts +6 -0
- package/esm/claiming/spark.js +179 -0
- package/esm/config/contracts.d.ts +2667 -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 +2882 -23
- package/esm/contracts.js +9 -0
- 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 +8 -0
- package/esm/liquityV2/index.js +162 -1
- package/esm/markets/aave/marketAssets.js +1 -1
- package/esm/markets/compound/marketsAssets.js +2 -2
- package/esm/markets/spark/marketAssets.js +1 -1
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +38 -5
- package/esm/portfolio/index.d.ts +6 -1
- package/esm/portfolio/index.js +260 -14
- 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/staking.js +3 -1
- package/esm/types/claiming.d.ts +93 -0
- package/esm/types/claiming.js +24 -0
- 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 +2 -2
- package/src/aaveV2/index.ts +2 -1
- package/src/aaveV3/index.ts +100 -2
- package/src/claiming/aaveV3.ts +163 -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 +105 -5
- package/src/constants/index.ts +5 -1
- package/src/contracts.ts +14 -1
- package/src/index.ts +2 -0
- package/src/liquity/index.ts +57 -2
- package/src/liquityV2/index.ts +177 -2
- package/src/markets/aave/marketAssets.ts +1 -1
- package/src/markets/compound/marketsAssets.ts +2 -2
- package/src/markets/spark/marketAssets.ts +1 -1
- package/src/morphoBlue/index.ts +43 -6
- package/src/portfolio/index.ts +263 -15
- package/src/services/utils.ts +37 -1
- package/src/spark/index.ts +2 -1
- package/src/staking/staking.ts +2 -1
- package/src/types/claiming.ts +109 -0
- package/src/umbrella/index.ts +70 -0
- package/src/umbrella/umbrellaUtils.ts +30 -0
|
@@ -0,0 +1,50 @@
|
|
|
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.getUmbrellaData = void 0;
|
|
13
|
+
const contracts_1 = require("../contracts");
|
|
14
|
+
const utils_1 = require("../services/utils");
|
|
15
|
+
const umbrellaUtils_1 = require("./umbrellaUtils");
|
|
16
|
+
const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
|
|
17
|
+
const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
|
|
18
|
+
const getUmbrellaData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const umbrellaView = (0, contracts_1.AaveUmbrellaViewViem)(provider, network);
|
|
20
|
+
const aaveV3View = (0, contracts_1.AaveV3ViewContractViem)(provider, network);
|
|
21
|
+
const [tokensAggregatedData, additionalUmbrellaStakingData, userAggregatedData] = yield Promise.all([
|
|
22
|
+
umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle]),
|
|
23
|
+
aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address]),
|
|
24
|
+
umbrellaView.read.getUserAggregatedData([umbrella, address]),
|
|
25
|
+
]);
|
|
26
|
+
return Object.fromEntries(umbrellaUtils_1.tokenEntries.map(([symbol, tokenAddr]) => {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
const fromTokens = (0, utils_1.convertHybridArraysToObjects)((0, umbrellaUtils_1.findMatching)(tokensAggregatedData, tokenAddr));
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
const fromUser = (0, utils_1.convertHybridArraysToObjects)((0, umbrellaUtils_1.findMatching)(userAggregatedData, tokenAddr));
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const fromAdditionalData = (0, utils_1.convertHybridArraysToObjects)((0, umbrellaUtils_1.findMatching)(additionalUmbrellaStakingData, tokenAddr));
|
|
33
|
+
const data = Object.assign(Object.assign(Object.assign(Object.assign({}, fromTokens), fromUser), fromAdditionalData), { account: {
|
|
34
|
+
stakeUserBalance: (fromUser === null || fromUser === void 0 ? void 0 : fromUser.stakeUserBalance) || '0',
|
|
35
|
+
rewardsTokenUserData: (0, utils_1.convertHybridArraysToObjects)(fromUser === null || fromUser === void 0 ? void 0 : fromUser.rewardsTokenUserData) || [],
|
|
36
|
+
userCooldownAmount: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userCooldownAmount) || '0',
|
|
37
|
+
userEndOfCooldown: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userEndOfCooldown) || '0',
|
|
38
|
+
userWithdrawalWindow: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userWithdrawalWindow) || '0',
|
|
39
|
+
} });
|
|
40
|
+
const stakeTokenData = data.stakeTokenData;
|
|
41
|
+
return [symbol, Object.assign(Object.assign({}, data), { stakeTokenData: Object.assign(Object.assign({}, stakeTokenData), { price: (0, utils_1.getEthAmountForDecimals)(stakeTokenData.price, 8) }), stkTokenToWaTokenRate: (0, utils_1.getEthAmountForDecimals)(data.stkTokenToWaTokenRate, stakeTokenData.decimals), waTokenToATokenRate: (0, utils_1.getEthAmountForDecimals)(data.waTokenToATokenRate, stakeTokenData.decimals), totalShares: (0, utils_1.getEthAmountForDecimals)(data.totalShares, stakeTokenData.decimals), totalAssets: (0, utils_1.getEthAmountForDecimals)(data.totalAssets, stakeTokenData.decimals), targetLiquidity: (0, utils_1.getEthAmountForDecimals)(data.targetLiquidity, stakeTokenData.decimals), rewardsTokenData: data.rewardsTokenData.map((tokenData) => (Object.assign(Object.assign({}, tokenData), { rewardTokenData: Object.assign(Object.assign({}, tokenData.rewardTokenData), { price: (0, utils_1.getEthAmountForDecimals)(tokenData.rewardTokenData.price, 8) }) }))), rewardsEmissionRates: data.rewardsEmissionRates.map((rate, i) => {
|
|
42
|
+
const tokenData = data.rewardsTokenData[i].rewardTokenData;
|
|
43
|
+
return (0, utils_1.getEthAmountForDecimals)(rate, tokenData.decimals);
|
|
44
|
+
}), account: Object.assign(Object.assign({}, data.account), { stakeUserBalance: (0, utils_1.getEthAmountForDecimals)(data.account.stakeUserBalance, stakeTokenData.decimals), userCooldownAmount: (0, utils_1.getEthAmountForDecimals)(data.account.userCooldownAmount, stakeTokenData.decimals), rewardsTokenUserData: data.account.rewardsTokenUserData.map((reward) => {
|
|
45
|
+
const tokenData = data.rewardsTokenData.find((tknData) => (0, utils_1.compareAddresses)(tknData.rewardTokenData.token, reward.reward));
|
|
46
|
+
return (Object.assign(Object.assign({}, reward), { currentReward: (0, utils_1.getEthAmountForDecimals)(reward.currentReward, tokenData.rewardTokenData.decimals) }));
|
|
47
|
+
}) }) })];
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
exports.getUmbrellaData = getUmbrellaData;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare enum UmbrellaStaking {
|
|
2
|
+
UmbrellaGHO = "UmbrellaGHO",
|
|
3
|
+
UmbrellaUSDC = "UmbrellaUSDC",
|
|
4
|
+
UmbrellaUSDT = "UmbrellaUSDT",
|
|
5
|
+
UmbrellaETH = "UmbrellaETH"
|
|
6
|
+
}
|
|
7
|
+
export declare const tokenMapping: {
|
|
8
|
+
readonly UmbrellaUSDC: "0x6bf183243FdD1e306ad2C4450BC7dcf6f0bf8Aa6";
|
|
9
|
+
readonly UmbrellaUSDT: "0xA484Ab92fe32B143AEE7019fC1502b1dAA522D31";
|
|
10
|
+
readonly UmbrellaETH: "0xaAFD07D53A7365D3e9fb6F3a3B09EC19676B73Ce";
|
|
11
|
+
readonly UmbrellaGHO: "0x4f827A63755855cDf3e8f3bcD20265C833f15033";
|
|
12
|
+
};
|
|
13
|
+
export declare const normalize: (addr?: string) => string;
|
|
14
|
+
export declare const tokenEntries: string[][];
|
|
15
|
+
export declare const extractAddress: (item?: {
|
|
16
|
+
stakeToken?: string;
|
|
17
|
+
stkToken?: string;
|
|
18
|
+
stakeTokenData?: {
|
|
19
|
+
token?: string;
|
|
20
|
+
};
|
|
21
|
+
}) => string;
|
|
22
|
+
export declare const findMatching: (dataset: any[], targetAddr: string) => any;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findMatching = exports.extractAddress = exports.tokenEntries = exports.normalize = exports.tokenMapping = exports.UmbrellaStaking = void 0;
|
|
4
|
+
var UmbrellaStaking;
|
|
5
|
+
(function (UmbrellaStaking) {
|
|
6
|
+
UmbrellaStaking["UmbrellaGHO"] = "UmbrellaGHO";
|
|
7
|
+
UmbrellaStaking["UmbrellaUSDC"] = "UmbrellaUSDC";
|
|
8
|
+
UmbrellaStaking["UmbrellaUSDT"] = "UmbrellaUSDT";
|
|
9
|
+
UmbrellaStaking["UmbrellaETH"] = "UmbrellaETH";
|
|
10
|
+
})(UmbrellaStaking || (exports.UmbrellaStaking = UmbrellaStaking = {}));
|
|
11
|
+
exports.tokenMapping = {
|
|
12
|
+
[UmbrellaStaking.UmbrellaUSDC]: '0x6bf183243FdD1e306ad2C4450BC7dcf6f0bf8Aa6',
|
|
13
|
+
[UmbrellaStaking.UmbrellaUSDT]: '0xA484Ab92fe32B143AEE7019fC1502b1dAA522D31',
|
|
14
|
+
[UmbrellaStaking.UmbrellaETH]: '0xaAFD07D53A7365D3e9fb6F3a3B09EC19676B73Ce',
|
|
15
|
+
[UmbrellaStaking.UmbrellaGHO]: '0x4f827A63755855cDf3e8f3bcD20265C833f15033',
|
|
16
|
+
};
|
|
17
|
+
// ----- chat gpt code for result mapping ---------
|
|
18
|
+
const normalize = (addr) => { var _a, _b; return (_b = (_a = addr === null || addr === void 0 ? void 0 : addr.toLowerCase) === null || _a === void 0 ? void 0 : _a.call(addr)) !== null && _b !== void 0 ? _b : ''; };
|
|
19
|
+
exports.normalize = normalize;
|
|
20
|
+
exports.tokenEntries = Object.entries(exports.tokenMapping).map(([symbol, address]) => [
|
|
21
|
+
symbol,
|
|
22
|
+
(0, exports.normalize)(address),
|
|
23
|
+
]);
|
|
24
|
+
// 👇 Define how to extract the token address from each source type
|
|
25
|
+
const extractAddress = (item) => {
|
|
26
|
+
var _a;
|
|
27
|
+
return (0, exports.normalize)((item === null || item === void 0 ? void 0 : item.stakeToken)
|
|
28
|
+
|| (item === null || item === void 0 ? void 0 : item.stkToken)
|
|
29
|
+
|| ((_a = item === null || item === void 0 ? void 0 : item.stakeTokenData) === null || _a === void 0 ? void 0 : _a.token));
|
|
30
|
+
};
|
|
31
|
+
exports.extractAddress = extractAddress;
|
|
32
|
+
// 👇 Utility to find the matching object in a dataset
|
|
33
|
+
const findMatching = (dataset, targetAddr) => dataset.find((item) => (0, exports.extractAddress)(item) === targetAddr);
|
|
34
|
+
exports.findMatching = findMatching;
|
package/esm/aaveV2/index.js
CHANGED
|
@@ -93,6 +93,7 @@ export const _getAaveV2AccountBalances = (provider, network, block, addressMappi
|
|
|
93
93
|
const marketAddress = market.providerAddress;
|
|
94
94
|
// @ts-ignore
|
|
95
95
|
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
96
|
+
// @ts-ignore
|
|
96
97
|
const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block));
|
|
97
98
|
const symbols = reserveTokens.map(({ symbol }) => symbol);
|
|
98
99
|
const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
|
package/esm/aaveV3/index.d.ts
CHANGED
|
@@ -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
|
+
}>;
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
11
11
|
import Dec from 'decimal.js';
|
|
12
|
-
import { AaveIncentiveDataProviderV3ContractViem, AaveV3ViewContractViem, createViemContractFromConfigFunc, } from '../contracts';
|
|
12
|
+
import { AaveIncentiveDataProviderV3ContractViem, AaveIncentivesControllerViem, AaveV3ViewContractViem, createViemContractFromConfigFunc, StkAAVEViem, } from '../contracts';
|
|
13
13
|
import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode } from '../helpers/aaveHelpers';
|
|
14
14
|
import { AAVE_V3 } from '../markets/aave';
|
|
15
15
|
import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
@@ -17,6 +17,7 @@ import { ethToWeth, isEnabledOnBitmap, isLayer2Network, wethToEth, wethToEthByAd
|
|
|
17
17
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
18
18
|
import { NetworkNumber, } from '../types/common';
|
|
19
19
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
20
|
+
import { SECONDS_PER_YEAR } from '../constants';
|
|
20
21
|
export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
21
22
|
const { eModeCategoriesData } = extractedState;
|
|
22
23
|
const usedAssetsValues = Object.values(usedAssets);
|
|
@@ -304,6 +305,7 @@ export const _getAaveV3AccountBalances = (provider, network, block, addressMappi
|
|
|
304
305
|
const marketAddress = market.providerAddress;
|
|
305
306
|
// @ts-ignore
|
|
306
307
|
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
308
|
+
// @ts-ignore
|
|
307
309
|
const reserveTokens = yield protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block));
|
|
308
310
|
const symbols = reserveTokens.map(({ symbol }) => symbol);
|
|
309
311
|
const _addresses = reserveTokens.map(({ tokenAddress }) => tokenAddress);
|
|
@@ -403,3 +405,91 @@ export const getAaveV3FullPositionData = (provider, network, address, market) =>
|
|
|
403
405
|
const positionData = yield getAaveV3AccountData(provider, network, address, { assetsData: marketData.assetsData, selectedMarket: market, eModeCategoriesData: marketData.eModeCategoriesData });
|
|
404
406
|
return positionData;
|
|
405
407
|
});
|
|
408
|
+
// aTokens eligible for AAVE rewards
|
|
409
|
+
export const REWARDABLE_ASSETS = [
|
|
410
|
+
'0x028171bCA77440897B824Ca71D1c56caC55b68A3', // DAI
|
|
411
|
+
'0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d',
|
|
412
|
+
'0xD37EE7e4f452C6638c96536e68090De8cBcdb583', // GUSD
|
|
413
|
+
'0x279AF5b99540c1A3A7E3CDd326e19659401eF99e',
|
|
414
|
+
'0xBcca60bB61934080951369a648Fb03DF4F96263C', // USDC
|
|
415
|
+
'0x619beb58998eD2278e08620f97007e1116D5D25b',
|
|
416
|
+
'0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811', // USDT
|
|
417
|
+
'0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec',
|
|
418
|
+
'0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656', // WBTC
|
|
419
|
+
'0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2',
|
|
420
|
+
'0x030bA81f1c18d280636F32af80b9AAd02Cf0854e', // WETH
|
|
421
|
+
'0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf',
|
|
422
|
+
'0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0', // LINK
|
|
423
|
+
'0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D',
|
|
424
|
+
'0x6C5024Cd4F8A59110119C56f8933403A539555EB', // SUSD
|
|
425
|
+
'0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817',
|
|
426
|
+
'0x5165d24277cD063F5ac44Efd447B27025e888f37', // YFI
|
|
427
|
+
'0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97',
|
|
428
|
+
'0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a', // xSUSHI
|
|
429
|
+
'0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A',
|
|
430
|
+
'0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1', // UNI
|
|
431
|
+
'0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73',
|
|
432
|
+
'0xc713e5E149D5D0715DcD1c156a020976e7E56B88', // MKR
|
|
433
|
+
'0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8',
|
|
434
|
+
'0x101cc05f4A51C0319f570d5E146a8C625198e636', // TUSD
|
|
435
|
+
'0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92',
|
|
436
|
+
'0xc9BC48c72154ef3e5425641a3c747242112a46AF', // RAI
|
|
437
|
+
'0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b',
|
|
438
|
+
'0x272F97b7a56a387aE942350bBC7Df5700f8a4576', // BAL
|
|
439
|
+
'0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0',
|
|
440
|
+
'0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3', // USDP
|
|
441
|
+
'0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7',
|
|
442
|
+
'0xA361718326c15715591c299427c62086F69923D9', // BUSD
|
|
443
|
+
'0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c',
|
|
444
|
+
'0xd4937682df3C8aEF4FE912A96A74121C0829E664', // FRAX
|
|
445
|
+
'0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca',
|
|
446
|
+
'0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3', // FEI
|
|
447
|
+
'0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe',
|
|
448
|
+
'0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1', // CRV
|
|
449
|
+
'0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684',
|
|
450
|
+
'0x6F634c6135D2EBD550000ac92F494F9CB8183dAe', // DPI
|
|
451
|
+
'0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0',
|
|
452
|
+
];
|
|
453
|
+
export const fetchYearlyMeritApyForStakingGho = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
454
|
+
var _a, _b;
|
|
455
|
+
try {
|
|
456
|
+
const response = yield fetch('https://apps.aavechan.com/api/merit/aprs', { signal: AbortSignal.timeout(5000) });
|
|
457
|
+
const data = yield response.json();
|
|
458
|
+
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';
|
|
459
|
+
const apy = aprToApy(apr);
|
|
460
|
+
const apyWithDFSBonus = new Dec(apy).mul(1.05).toString(); // 5% bonus for DFS users
|
|
461
|
+
return apyWithDFSBonus;
|
|
462
|
+
}
|
|
463
|
+
catch (e) {
|
|
464
|
+
const message = 'External API Failure: Failed to fetch yearly merit APY for staking GHO';
|
|
465
|
+
console.error(message, e);
|
|
466
|
+
return '0';
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
export const getStakeAaveData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
470
|
+
const stkGhoAddress = getAssetInfo('stkGHO').address;
|
|
471
|
+
const stkAaveAddress = getAssetInfo('stkAAVE').address;
|
|
472
|
+
const AaveIncentivesController = AaveIncentivesControllerViem(provider, network);
|
|
473
|
+
const stkAAVE = StkAAVEViem(provider, network);
|
|
474
|
+
const stkGHO = createViemContractFromConfigFunc('Erc20', stkGhoAddress)(provider, network);
|
|
475
|
+
const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy] = yield Promise.all([
|
|
476
|
+
AaveIncentivesController.read.getRewardsBalance([REWARDABLE_ASSETS, address]),
|
|
477
|
+
stkAAVE.read.assets([stkAaveAddress]),
|
|
478
|
+
stkAAVE.read.balanceOf([address]),
|
|
479
|
+
stkAAVE.read.totalSupply(),
|
|
480
|
+
stkGHO.read.balanceOf([address]),
|
|
481
|
+
fetchYearlyMeritApyForStakingGho(),
|
|
482
|
+
]);
|
|
483
|
+
const stkAaveApy = new Dec(assetAmountInEth(emissionsPerSecond[0].toString(), 'GHO') || 0).mul(SECONDS_PER_YEAR).mul(100).div(assetAmountInEth(stkAAVETotalSupply.toString(), 'stkAAVE'))
|
|
484
|
+
.toString();
|
|
485
|
+
return {
|
|
486
|
+
activatedCooldown: '0',
|
|
487
|
+
activatedCooldownAmount: '0',
|
|
488
|
+
stkAaveRewardsBalance: '0',
|
|
489
|
+
aaveRewardsBalance: assetAmountInEth(aaveRewardsBalance.toString(), 'AAVE'),
|
|
490
|
+
stkAaveBalance: assetAmountInEth(stkAAVEBalance.toString(), 'stkAAVE'),
|
|
491
|
+
stkGhoBalance: assetAmountInEth(stkGHOBalance.toString(), 'GHO'),
|
|
492
|
+
ghoMeritApy,
|
|
493
|
+
stkAaveApy,
|
|
494
|
+
};
|
|
495
|
+
});
|
|
@@ -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,139 @@
|
|
|
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 Dec from 'decimal.js';
|
|
11
|
+
import { ClaimType } from '../types/claiming';
|
|
12
|
+
import { AaveIncentiveDataProviderV3ContractViem, AaveRewardsControllerViem, } from '../contracts';
|
|
13
|
+
import { compareAddresses, getEthAmountForDecimals, wethToEth } from '../services/utils';
|
|
14
|
+
/**
|
|
15
|
+
* won't cover all cases
|
|
16
|
+
*/
|
|
17
|
+
export const getAaveUnderlyingSymbol = (_symbol = '') => {
|
|
18
|
+
let symbol = _symbol
|
|
19
|
+
.replace(/^aEthLido/, '')
|
|
20
|
+
.replace(/^aEthEtherFi/, '')
|
|
21
|
+
.replace(/^aEth/, '')
|
|
22
|
+
.replace(/^aArb/, '')
|
|
23
|
+
.replace(/^aOpt/, '')
|
|
24
|
+
.replace(/^aBas/, '');
|
|
25
|
+
if (symbol.startsWith('a'))
|
|
26
|
+
symbol = symbol.slice(1);
|
|
27
|
+
return wethToEth(symbol);
|
|
28
|
+
};
|
|
29
|
+
const mapAaveRewardsToClaimableTokens = (aaveRewards, marketAddress, walletAddress) => aaveRewards.map(reward => ({
|
|
30
|
+
symbol: reward.symbol,
|
|
31
|
+
amount: reward.amount,
|
|
32
|
+
claimType: ClaimType.AAVE_REWARDS,
|
|
33
|
+
tokenAddress: reward.rewardTokenAddress,
|
|
34
|
+
underlyingSymbol: reward.underlyingAsset,
|
|
35
|
+
walletAddress,
|
|
36
|
+
label: 'AAVE Rewards',
|
|
37
|
+
additionalClaimFields: {
|
|
38
|
+
marketAddress,
|
|
39
|
+
aTokenAddresses: reward.aTokenAddresses,
|
|
40
|
+
isAaveToken: reward.symbol.startsWith('a'),
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
export function getUnclaimedRewardsForAllMarkets(provider, network, walletAddress, marketAddress) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const contract = AaveIncentiveDataProviderV3ContractViem(provider, network);
|
|
46
|
+
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
47
|
+
const allTokensDataArrays = tokensData.reduce((acc, val) => {
|
|
48
|
+
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
49
|
+
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
50
|
+
return acc;
|
|
51
|
+
}, []);
|
|
52
|
+
const allATokens = tokensData.reduce((acc, val) => {
|
|
53
|
+
acc.push(val.aTokenIncentivesUserData.tokenAddress);
|
|
54
|
+
acc.push(val.vTokenIncentivesUserData.tokenAddress);
|
|
55
|
+
return acc;
|
|
56
|
+
}, []);
|
|
57
|
+
// array of rewards for each market (aToken/vToken)
|
|
58
|
+
// reward can be any token like wstETH, but also aToken like aWETH
|
|
59
|
+
const aaveRewardsController = AaveRewardsControllerViem(provider, network);
|
|
60
|
+
const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => aaveRewardsController.read.getAllUserRewards([[token], walletAddress])));
|
|
61
|
+
// match amounts to token symbol, parse decimal amounts
|
|
62
|
+
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
|
63
|
+
const rewardsList = rewardForAAsset[0];
|
|
64
|
+
const amounts = rewardForAAsset[1];
|
|
65
|
+
const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
|
|
66
|
+
const aTokenAddress = allATokens[aaIndex];
|
|
67
|
+
return rewardsList.map((rewardTokenAddress, rewardIndex) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr) => compareAddresses(arr.rewardTokenAddress, rewardTokenAddress));
|
|
70
|
+
const amountWei = amounts[rewardIndex];
|
|
71
|
+
const amount = getEthAmountForDecimals(amountWei.toString(), (_a = rewardsDataArraysForAAsset[dataArrIndex]) === null || _a === void 0 ? void 0 : _a.rewardTokenDecimals);
|
|
72
|
+
const symbol = ((_b = rewardsDataArraysForAAsset[dataArrIndex]) === null || _b === void 0 ? void 0 : _b.rewardTokenSymbol) || '';
|
|
73
|
+
const underlyingAsset = getAaveUnderlyingSymbol(symbol);
|
|
74
|
+
return ({
|
|
75
|
+
amount,
|
|
76
|
+
symbol,
|
|
77
|
+
underlyingAsset,
|
|
78
|
+
rewardTokenAddress,
|
|
79
|
+
aTokenAddress,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
// sum all unclaimed rewards of all markets per each token
|
|
84
|
+
// (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
|
|
85
|
+
const totalUnclaimedPerRewardToken = {};
|
|
86
|
+
rewardsPerAAssetWithInfo
|
|
87
|
+
.flat()
|
|
88
|
+
.forEach(({ amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress, }) => {
|
|
89
|
+
if (+amount > 0) {
|
|
90
|
+
if (!totalUnclaimedPerRewardToken[symbol]) {
|
|
91
|
+
totalUnclaimedPerRewardToken[symbol] = {
|
|
92
|
+
amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
totalUnclaimedPerRewardToken[symbol].amount =
|
|
97
|
+
new Dec(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
|
|
98
|
+
totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, []);
|
|
102
|
+
return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export function getMeritUnclaimedRewards(account_1, network_1) {
|
|
106
|
+
return __awaiter(this, arguments, void 0, function* (account, network, acceptMorpho = true) {
|
|
107
|
+
const res = yield fetch(`https://api.merkl.xyz/v4/users/${account}/rewards?chainId=${network}`, { signal: AbortSignal.timeout(3000) });
|
|
108
|
+
const data = yield res.json();
|
|
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 Dec(amount).minus(claimed || 0).toString();
|
|
117
|
+
if (unclaimedAmount === '0')
|
|
118
|
+
return;
|
|
119
|
+
const unclaimed = getEthAmountForDecimals(unclaimedAmount, token.decimals);
|
|
120
|
+
claimableTokens.push({
|
|
121
|
+
claimType: 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: 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,30 @@
|
|
|
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 { CompV3ViewContractViem } from '../contracts';
|
|
12
|
+
import { ClaimType } from '../types/claiming';
|
|
13
|
+
export const getCompoundV3Rewards = (provider, network, user, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const compV3View = CompV3ViewContractViem(provider, network);
|
|
15
|
+
const rewards = yield compV3View.read.getRewardsOwed([market, user]);
|
|
16
|
+
if (!rewards || rewards.owed.toString() === '0' || getAssetInfoByAddress(rewards.token, network).symbol !== 'COMP')
|
|
17
|
+
return [];
|
|
18
|
+
return [{
|
|
19
|
+
symbol: 'COMP',
|
|
20
|
+
underlyingSymbol: 'COMP',
|
|
21
|
+
tokenAddress: rewards.token,
|
|
22
|
+
amount: assetAmountInEth(rewards.owed.toString() || 0, 'COMP'),
|
|
23
|
+
walletAddress: user,
|
|
24
|
+
label: 'Compound V3',
|
|
25
|
+
claimType: ClaimType.COMPOUND_V3_COMP,
|
|
26
|
+
additionalClaimFields: {
|
|
27
|
+
marketAddress: market,
|
|
28
|
+
},
|
|
29
|
+
}];
|
|
30
|
+
});
|
|
@@ -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,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,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,64 @@
|
|
|
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 Dec from 'decimal.js';
|
|
11
|
+
import { assetAmountInEth } from '@defisaver/tokens';
|
|
12
|
+
import { UUPSViem } from '../contracts';
|
|
13
|
+
import { ClaimType } from '../types/claiming';
|
|
14
|
+
export const fetchKingRewards = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
const res = yield fetch(`https://fe.defisaver.com/api/etherfi/get-king-rewards/${walletAddress}`, { signal: AbortSignal.timeout(5000) });
|
|
17
|
+
if (!res.ok)
|
|
18
|
+
throw new Error(yield res.text());
|
|
19
|
+
return yield res.json();
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.error('External API Error: Error fetching KING rewards:', err);
|
|
23
|
+
return { Amount: '0', Root: '', Proofs: [] };
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
export const getKingRewards = (provider, network, walletAddresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
28
|
+
const apiDataPromises = walletAddresses.map(address => fetchKingRewards(address));
|
|
29
|
+
const apiDataArray = yield Promise.all(apiDataPromises);
|
|
30
|
+
// Batch all contract calls using multicall
|
|
31
|
+
const contract = UUPSViem(provider, network);
|
|
32
|
+
const cumulativePromises = walletAddresses.map(address => contract.read.cumulativeClaimed([address]));
|
|
33
|
+
const cumulativeResults = yield Promise.all(cumulativePromises);
|
|
34
|
+
// Process results
|
|
35
|
+
const results = {};
|
|
36
|
+
for (let i = 0; i < walletAddresses.length; i++) {
|
|
37
|
+
const walletAddress = walletAddresses[i];
|
|
38
|
+
const data = apiDataArray[i];
|
|
39
|
+
const cumulative = cumulativeResults[i];
|
|
40
|
+
const allRewardsAmount = assetAmountInEth(data.Amount, 'KING');
|
|
41
|
+
const claimedAmount = assetAmountInEth(cumulative.toString(), 'KING');
|
|
42
|
+
const amountToClaim = new Dec(allRewardsAmount).sub(claimedAmount);
|
|
43
|
+
if (amountToClaim.lessThanOrEqualTo('0')) {
|
|
44
|
+
results[walletAddress.toLowerCase()] = [];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
results[walletAddress.toLowerCase()] = [{
|
|
48
|
+
symbol: 'KING',
|
|
49
|
+
underlyingSymbol: 'KING',
|
|
50
|
+
tokenAddress: '0x8F08B70456eb22f6109F57b8fafE862ED28E6040',
|
|
51
|
+
amount: amountToClaim.toString(),
|
|
52
|
+
walletAddress,
|
|
53
|
+
label: 'weETH',
|
|
54
|
+
claimType: ClaimType.KING_REWARDS,
|
|
55
|
+
additionalClaimFields: {
|
|
56
|
+
allRewardsAmount,
|
|
57
|
+
merkleRoot: data.Root,
|
|
58
|
+
merkleProofs: data.Proofs,
|
|
59
|
+
},
|
|
60
|
+
}];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return results;
|
|
64
|
+
});
|
|
@@ -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[]>>;
|