@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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { EthAddress } from './common';
|
|
2
|
+
export declare enum ClaimType {
|
|
3
|
+
/** Rewards from AAVE - various tokens & aTokens (supplied to protocol) */
|
|
4
|
+
AAVE_REWARDS = "AAVE_REWARDS",
|
|
5
|
+
/** Merit rewards from AAVE (various tokens) */
|
|
6
|
+
AAVE_MERIT_REWARDS = "AAVE_MERIT_REWARDS",
|
|
7
|
+
/** Rewards from Compound V3 (only in COMP) */
|
|
8
|
+
COMPOUND_V3_COMP = "COMPOUND_V3_COMP",
|
|
9
|
+
/** Rewards from Spark (wstETH only for now) */
|
|
10
|
+
SPARK_REWARDS = "SPARK_REWARDS",
|
|
11
|
+
/** Rewards from Morpho */
|
|
12
|
+
MORPHO = "MORPHO",
|
|
13
|
+
/** Rewards from King (prev LTR^2 - received for weETH holding) */
|
|
14
|
+
KING_REWARDS = "KING_REWARDS",
|
|
15
|
+
/** Spark Airdrop */
|
|
16
|
+
SPARK_AIRDROP = "SPARK_AIRDROP",
|
|
17
|
+
/** Spark Airdrop */
|
|
18
|
+
SPARK_WST_ETH_REWARDS = "SPARK_WST_ETH_REWARDS"
|
|
19
|
+
}
|
|
20
|
+
type _ClaimableTokenPartial = {
|
|
21
|
+
symbol: string;
|
|
22
|
+
underlyingSymbol: string;
|
|
23
|
+
tokenAddress: EthAddress;
|
|
24
|
+
amount: string;
|
|
25
|
+
walletAddress: EthAddress;
|
|
26
|
+
label: string;
|
|
27
|
+
};
|
|
28
|
+
export type AaveRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
29
|
+
claimType: ClaimType.AAVE_REWARDS;
|
|
30
|
+
additionalClaimFields: {
|
|
31
|
+
marketAddress: EthAddress;
|
|
32
|
+
aTokenAddresses: string[];
|
|
33
|
+
isAaveToken: boolean;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type AaveMeritRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
37
|
+
claimType: ClaimType.AAVE_MERIT_REWARDS;
|
|
38
|
+
additionalClaimFields: {
|
|
39
|
+
accumulated: string;
|
|
40
|
+
proof: string[];
|
|
41
|
+
decimals: string;
|
|
42
|
+
unclaimed: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type SparkRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
46
|
+
claimType: ClaimType.SPARK_REWARDS;
|
|
47
|
+
additionalClaimFields: {
|
|
48
|
+
sparkAssetAddresses: string[];
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export type KingRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
52
|
+
claimType: ClaimType.KING_REWARDS;
|
|
53
|
+
additionalClaimFields: {
|
|
54
|
+
allRewardsAmount: string;
|
|
55
|
+
merkleRoot: string;
|
|
56
|
+
merkleProofs: string[];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type MorphoClaimableToken = _ClaimableTokenPartial & {
|
|
60
|
+
claimType: ClaimType.MORPHO;
|
|
61
|
+
additionalClaimFields: {
|
|
62
|
+
originalAmount: string;
|
|
63
|
+
merkleProofs: string[];
|
|
64
|
+
distributor: EthAddress;
|
|
65
|
+
isLegacy: boolean;
|
|
66
|
+
txData: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
export type CompoundV3CompClaimableToken = _ClaimableTokenPartial & {
|
|
70
|
+
claimType: ClaimType.COMPOUND_V3_COMP;
|
|
71
|
+
additionalClaimFields: {
|
|
72
|
+
marketAddress: EthAddress;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export declare enum SparkAirdropType {
|
|
76
|
+
SPARK_IGNITION = "spark-ignition",
|
|
77
|
+
PRE_FARMING_AND_SOCIAL = "pre-farming-and-social"
|
|
78
|
+
}
|
|
79
|
+
export type SparkAirdropClaimableToken = _ClaimableTokenPartial & {
|
|
80
|
+
claimType: ClaimType.SPARK_AIRDROP;
|
|
81
|
+
additionalClaimFields: {
|
|
82
|
+
merkleRoot: string;
|
|
83
|
+
merkleProofs: string[];
|
|
84
|
+
epoch: number;
|
|
85
|
+
rewardType: SparkAirdropType;
|
|
86
|
+
allRewardsAmount: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export type SparkWstEthRewardsClaimableToken = _ClaimableTokenPartial & {
|
|
90
|
+
claimType: ClaimType.SPARK_WST_ETH_REWARDS;
|
|
91
|
+
};
|
|
92
|
+
export type ClaimableToken = AaveRewardsClaimableToken | AaveMeritRewardsClaimableToken | CompoundV3CompClaimableToken | MorphoClaimableToken | SparkRewardsClaimableToken | KingRewardsClaimableToken | SparkAirdropClaimableToken | SparkWstEthRewardsClaimableToken;
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export var ClaimType;
|
|
2
|
+
(function (ClaimType) {
|
|
3
|
+
/** Rewards from AAVE - various tokens & aTokens (supplied to protocol) */
|
|
4
|
+
ClaimType["AAVE_REWARDS"] = "AAVE_REWARDS";
|
|
5
|
+
/** Merit rewards from AAVE (various tokens) */
|
|
6
|
+
ClaimType["AAVE_MERIT_REWARDS"] = "AAVE_MERIT_REWARDS";
|
|
7
|
+
/** Rewards from Compound V3 (only in COMP) */
|
|
8
|
+
ClaimType["COMPOUND_V3_COMP"] = "COMPOUND_V3_COMP";
|
|
9
|
+
/** Rewards from Spark (wstETH only for now) */
|
|
10
|
+
ClaimType["SPARK_REWARDS"] = "SPARK_REWARDS";
|
|
11
|
+
/** Rewards from Morpho */
|
|
12
|
+
ClaimType["MORPHO"] = "MORPHO";
|
|
13
|
+
/** Rewards from King (prev LTR^2 - received for weETH holding) */
|
|
14
|
+
ClaimType["KING_REWARDS"] = "KING_REWARDS";
|
|
15
|
+
/** Spark Airdrop */
|
|
16
|
+
ClaimType["SPARK_AIRDROP"] = "SPARK_AIRDROP";
|
|
17
|
+
/** Spark Airdrop */
|
|
18
|
+
ClaimType["SPARK_WST_ETH_REWARDS"] = "SPARK_WST_ETH_REWARDS";
|
|
19
|
+
})(ClaimType || (ClaimType = {}));
|
|
20
|
+
export var SparkAirdropType;
|
|
21
|
+
(function (SparkAirdropType) {
|
|
22
|
+
SparkAirdropType["SPARK_IGNITION"] = "spark-ignition";
|
|
23
|
+
SparkAirdropType["PRE_FARMING_AND_SOCIAL"] = "pre-farming-and-social";
|
|
24
|
+
})(SparkAirdropType || (SparkAirdropType = {}));
|
package/esm/types/common.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare enum IncentiveKind {
|
|
|
3
3
|
Reward = "reward"
|
|
4
4
|
}
|
|
5
5
|
export declare enum IncentiveEligibilityId {
|
|
6
|
-
AaveV3EthenaLiquidLeverage = "
|
|
6
|
+
AaveV3EthenaLiquidLeverage = "0x7361e6f04060154e0268a8402b073cbf97e11ae3BORROW_BL",
|
|
7
7
|
AaveV3ArbitrumEthSupply = "0x5d16261c6715a653248269861bbacf68a9774cde",
|
|
8
8
|
AaveV3ArbitrumETHLSBorrow = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351"
|
|
9
9
|
}
|
package/esm/types/common.js
CHANGED
|
@@ -5,7 +5,7 @@ export var IncentiveKind;
|
|
|
5
5
|
})(IncentiveKind || (IncentiveKind = {}));
|
|
6
6
|
export var IncentiveEligibilityId;
|
|
7
7
|
(function (IncentiveEligibilityId) {
|
|
8
|
-
IncentiveEligibilityId["AaveV3EthenaLiquidLeverage"] = "
|
|
8
|
+
IncentiveEligibilityId["AaveV3EthenaLiquidLeverage"] = "0x7361e6f04060154e0268a8402b073cbf97e11ae3BORROW_BL";
|
|
9
9
|
IncentiveEligibilityId["AaveV3ArbitrumEthSupply"] = "0x5d16261c6715a653248269861bbacf68a9774cde";
|
|
10
10
|
IncentiveEligibilityId["AaveV3ArbitrumETHLSBorrow"] = "0x0c84331e39d6658Cd6e6b9ba04736cC4c4734351";
|
|
11
11
|
})(IncentiveEligibilityId || (IncentiveEligibilityId = {}));
|
|
@@ -0,0 +1,46 @@
|
|
|
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 { AaveUmbrellaViewViem, AaveV3ViewContractViem } from '../contracts';
|
|
11
|
+
import { compareAddresses, convertHybridArraysToObjects, getEthAmountForDecimals } from '../services/utils';
|
|
12
|
+
import { findMatching, tokenEntries } from './umbrellaUtils';
|
|
13
|
+
const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
|
|
14
|
+
const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
|
|
15
|
+
export const getUmbrellaData = (provider, network, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const umbrellaView = AaveUmbrellaViewViem(provider, network);
|
|
17
|
+
const aaveV3View = AaveV3ViewContractViem(provider, network);
|
|
18
|
+
const [tokensAggregatedData, additionalUmbrellaStakingData, userAggregatedData] = yield Promise.all([
|
|
19
|
+
umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle]),
|
|
20
|
+
aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address]),
|
|
21
|
+
umbrellaView.read.getUserAggregatedData([umbrella, address]),
|
|
22
|
+
]);
|
|
23
|
+
return Object.fromEntries(tokenEntries.map(([symbol, tokenAddr]) => {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const fromTokens = convertHybridArraysToObjects(findMatching(tokensAggregatedData, tokenAddr));
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
const fromUser = convertHybridArraysToObjects(findMatching(userAggregatedData, tokenAddr));
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const fromAdditionalData = convertHybridArraysToObjects(findMatching(additionalUmbrellaStakingData, tokenAddr));
|
|
30
|
+
const data = Object.assign(Object.assign(Object.assign(Object.assign({}, fromTokens), fromUser), fromAdditionalData), { account: {
|
|
31
|
+
stakeUserBalance: (fromUser === null || fromUser === void 0 ? void 0 : fromUser.stakeUserBalance) || '0',
|
|
32
|
+
rewardsTokenUserData: convertHybridArraysToObjects(fromUser === null || fromUser === void 0 ? void 0 : fromUser.rewardsTokenUserData) || [],
|
|
33
|
+
userCooldownAmount: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userCooldownAmount) || '0',
|
|
34
|
+
userEndOfCooldown: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userEndOfCooldown) || '0',
|
|
35
|
+
userWithdrawalWindow: (fromAdditionalData === null || fromAdditionalData === void 0 ? void 0 : fromAdditionalData.userWithdrawalWindow) || '0',
|
|
36
|
+
} });
|
|
37
|
+
const stakeTokenData = data.stakeTokenData;
|
|
38
|
+
return [symbol, Object.assign(Object.assign({}, data), { stakeTokenData: Object.assign(Object.assign({}, stakeTokenData), { price: getEthAmountForDecimals(stakeTokenData.price, 8) }), stkTokenToWaTokenRate: getEthAmountForDecimals(data.stkTokenToWaTokenRate, stakeTokenData.decimals), waTokenToATokenRate: getEthAmountForDecimals(data.waTokenToATokenRate, stakeTokenData.decimals), totalShares: getEthAmountForDecimals(data.totalShares, stakeTokenData.decimals), totalAssets: getEthAmountForDecimals(data.totalAssets, stakeTokenData.decimals), targetLiquidity: getEthAmountForDecimals(data.targetLiquidity, stakeTokenData.decimals), rewardsTokenData: data.rewardsTokenData.map((tokenData) => (Object.assign(Object.assign({}, tokenData), { rewardTokenData: Object.assign(Object.assign({}, tokenData.rewardTokenData), { price: getEthAmountForDecimals(tokenData.rewardTokenData.price, 8) }) }))), rewardsEmissionRates: data.rewardsEmissionRates.map((rate, i) => {
|
|
39
|
+
const tokenData = data.rewardsTokenData[i].rewardTokenData;
|
|
40
|
+
return getEthAmountForDecimals(rate, tokenData.decimals);
|
|
41
|
+
}), account: Object.assign(Object.assign({}, data.account), { stakeUserBalance: getEthAmountForDecimals(data.account.stakeUserBalance, stakeTokenData.decimals), userCooldownAmount: getEthAmountForDecimals(data.account.userCooldownAmount, stakeTokenData.decimals), rewardsTokenUserData: data.account.rewardsTokenUserData.map((reward) => {
|
|
42
|
+
const tokenData = data.rewardsTokenData.find((tknData) => compareAddresses(tknData.rewardTokenData.token, reward.reward));
|
|
43
|
+
return (Object.assign(Object.assign({}, reward), { currentReward: getEthAmountForDecimals(reward.currentReward, tokenData.rewardTokenData.decimals) }));
|
|
44
|
+
}) }) })];
|
|
45
|
+
}));
|
|
46
|
+
});
|
|
@@ -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,28 @@
|
|
|
1
|
+
export var UmbrellaStaking;
|
|
2
|
+
(function (UmbrellaStaking) {
|
|
3
|
+
UmbrellaStaking["UmbrellaGHO"] = "UmbrellaGHO";
|
|
4
|
+
UmbrellaStaking["UmbrellaUSDC"] = "UmbrellaUSDC";
|
|
5
|
+
UmbrellaStaking["UmbrellaUSDT"] = "UmbrellaUSDT";
|
|
6
|
+
UmbrellaStaking["UmbrellaETH"] = "UmbrellaETH";
|
|
7
|
+
})(UmbrellaStaking || (UmbrellaStaking = {}));
|
|
8
|
+
export const tokenMapping = {
|
|
9
|
+
[UmbrellaStaking.UmbrellaUSDC]: '0x6bf183243FdD1e306ad2C4450BC7dcf6f0bf8Aa6',
|
|
10
|
+
[UmbrellaStaking.UmbrellaUSDT]: '0xA484Ab92fe32B143AEE7019fC1502b1dAA522D31',
|
|
11
|
+
[UmbrellaStaking.UmbrellaETH]: '0xaAFD07D53A7365D3e9fb6F3a3B09EC19676B73Ce',
|
|
12
|
+
[UmbrellaStaking.UmbrellaGHO]: '0x4f827A63755855cDf3e8f3bcD20265C833f15033',
|
|
13
|
+
};
|
|
14
|
+
// ----- chat gpt code for result mapping ---------
|
|
15
|
+
export 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 : ''; };
|
|
16
|
+
export const tokenEntries = Object.entries(tokenMapping).map(([symbol, address]) => [
|
|
17
|
+
symbol,
|
|
18
|
+
normalize(address),
|
|
19
|
+
]);
|
|
20
|
+
// 👇 Define how to extract the token address from each source type
|
|
21
|
+
export const extractAddress = (item) => {
|
|
22
|
+
var _a;
|
|
23
|
+
return normalize((item === null || item === void 0 ? void 0 : item.stakeToken)
|
|
24
|
+
|| (item === null || item === void 0 ? void 0 : item.stkToken)
|
|
25
|
+
|| ((_a = item === null || item === void 0 ? void 0 : item.stakeTokenData) === null || _a === void 0 ? void 0 : _a.token));
|
|
26
|
+
};
|
|
27
|
+
// 👇 Utility to find the matching object in a dataset
|
|
28
|
+
export const findMatching = (dataset, targetAddr) => dataset.find((item) => extractAddress(item) === targetAddr);
|
package/package.json
CHANGED
package/src/aaveV2/index.ts
CHANGED
|
@@ -106,7 +106,8 @@ export const _getAaveV2AccountBalances = async (provider: Client, network: Netwo
|
|
|
106
106
|
// @ts-ignore
|
|
107
107
|
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
const reserveTokens = await protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block)) as { symbol: string, tokenAddress: EthAddress }[];
|
|
110
111
|
const symbols = reserveTokens.map(({ symbol }: { symbol: string }) => symbol);
|
|
111
112
|
const _addresses = reserveTokens.map(({ tokenAddress }: { tokenAddress: EthAddress }) => tokenAddress);
|
|
112
113
|
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { Client } from 'viem';
|
|
|
3
3
|
import Dec from 'decimal.js';
|
|
4
4
|
import {
|
|
5
5
|
AaveIncentiveDataProviderV3ContractViem,
|
|
6
|
+
AaveIncentivesControllerViem,
|
|
6
7
|
AaveV3ViewContractViem,
|
|
7
8
|
createViemContractFromConfigFunc,
|
|
9
|
+
StkAAVEViem,
|
|
8
10
|
} from '../contracts';
|
|
9
11
|
import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode } from '../helpers/aaveHelpers';
|
|
10
12
|
import { AAVE_V3 } from '../markets/aave';
|
|
@@ -26,11 +28,12 @@ import {
|
|
|
26
28
|
EModeCategoryDataMapping,
|
|
27
29
|
} from '../types/aave';
|
|
28
30
|
import {
|
|
29
|
-
Blockish, EthAddress, EthereumProvider, IncentiveEligibilityId, IncentiveKind, NetworkNumber, PositionBalances,
|
|
31
|
+
Blockish, EthAddress, EthereumProvider, IncentiveEligibilityId, IncentiveKind, NetworkNumber, PositionBalances, HexString,
|
|
30
32
|
} from '../types/common';
|
|
31
33
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
32
34
|
import { getMeritCampaigns } from './merit';
|
|
33
35
|
import { getAaveUnderlyingSymbol, getMerkleCampaigns } from './merkl';
|
|
36
|
+
import { SECONDS_PER_DAY, SECONDS_PER_YEAR } from '../constants';
|
|
34
37
|
|
|
35
38
|
export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: AaveV3UsedAssets) => {
|
|
36
39
|
const { eModeCategoriesData }: { assetsData: AaveV3AssetsData, eModeCategoriesData: EModeCategoriesData } = extractedState;
|
|
@@ -360,7 +363,8 @@ export const _getAaveV3AccountBalances = async (provider: Client, network: Netwo
|
|
|
360
363
|
// @ts-ignore
|
|
361
364
|
const protocolDataProviderContract = createViemContractFromConfigFunc(market.protocolData, market.protocolDataAddress)(provider, network);
|
|
362
365
|
|
|
363
|
-
|
|
366
|
+
// @ts-ignore
|
|
367
|
+
const reserveTokens = await protocolDataProviderContract.read.getAllReservesTokens(setViemBlockNumber(block)) as { symbol: string, tokenAddress: EthAddress }[];
|
|
364
368
|
const symbols = reserveTokens.map(({ symbol }: { symbol: string }) => symbol);
|
|
365
369
|
const _addresses = reserveTokens.map(({ tokenAddress }: { tokenAddress: EthAddress }) => tokenAddress);
|
|
366
370
|
|
|
@@ -510,6 +514,100 @@ export const getAaveV3FullPositionData = async (provider: EthereumProvider, netw
|
|
|
510
514
|
return positionData;
|
|
511
515
|
};
|
|
512
516
|
|
|
517
|
+
// aTokens eligible for AAVE rewards
|
|
518
|
+
export const REWARDABLE_ASSETS = [
|
|
519
|
+
'0x028171bCA77440897B824Ca71D1c56caC55b68A3', // DAI
|
|
520
|
+
'0x6C3c78838c761c6Ac7bE9F59fe808ea2A6E4379d',
|
|
521
|
+
'0xD37EE7e4f452C6638c96536e68090De8cBcdb583', // GUSD
|
|
522
|
+
'0x279AF5b99540c1A3A7E3CDd326e19659401eF99e',
|
|
523
|
+
'0xBcca60bB61934080951369a648Fb03DF4F96263C', // USDC
|
|
524
|
+
'0x619beb58998eD2278e08620f97007e1116D5D25b',
|
|
525
|
+
'0x3Ed3B47Dd13EC9a98b44e6204A523E766B225811', // USDT
|
|
526
|
+
'0x531842cEbbdD378f8ee36D171d6cC9C4fcf475Ec',
|
|
527
|
+
'0x9ff58f4fFB29fA2266Ab25e75e2A8b3503311656', // WBTC
|
|
528
|
+
'0x9c39809Dec7F95F5e0713634a4D0701329B3b4d2',
|
|
529
|
+
'0x030bA81f1c18d280636F32af80b9AAd02Cf0854e', // WETH
|
|
530
|
+
'0xF63B34710400CAd3e044cFfDcAb00a0f32E33eCf',
|
|
531
|
+
'0xa06bC25B5805d5F8d82847D191Cb4Af5A3e873E0', // LINK
|
|
532
|
+
'0x0b8f12b1788BFdE65Aa1ca52E3e9F3Ba401be16D',
|
|
533
|
+
'0x6C5024Cd4F8A59110119C56f8933403A539555EB', // SUSD
|
|
534
|
+
'0xdC6a3Ab17299D9C2A412B0e0a4C1f55446AE0817',
|
|
535
|
+
'0x5165d24277cD063F5ac44Efd447B27025e888f37', // YFI
|
|
536
|
+
'0x7EbD09022Be45AD993BAA1CEc61166Fcc8644d97',
|
|
537
|
+
'0xF256CC7847E919FAc9B808cC216cAc87CCF2f47a', // xSUSHI
|
|
538
|
+
'0xfAFEDF95E21184E3d880bd56D4806c4b8d31c69A',
|
|
539
|
+
'0xB9D7CB55f463405CDfBe4E90a6D2Df01C2B92BF1', // UNI
|
|
540
|
+
'0x5BdB050A92CADcCfCDcCCBFC17204a1C9cC0Ab73',
|
|
541
|
+
'0xc713e5E149D5D0715DcD1c156a020976e7E56B88', // MKR
|
|
542
|
+
'0xba728eAd5e496BE00DCF66F650b6d7758eCB50f8',
|
|
543
|
+
'0x101cc05f4A51C0319f570d5E146a8C625198e636', // TUSD
|
|
544
|
+
'0x01C0eb1f8c6F1C1bF74ae028697ce7AA2a8b0E92',
|
|
545
|
+
'0xc9BC48c72154ef3e5425641a3c747242112a46AF', // RAI
|
|
546
|
+
'0xB5385132EE8321977FfF44b60cDE9fE9AB0B4e6b',
|
|
547
|
+
'0x272F97b7a56a387aE942350bBC7Df5700f8a4576', // BAL
|
|
548
|
+
'0x13210D4Fe0d5402bd7Ecbc4B5bC5cFcA3b71adB0',
|
|
549
|
+
'0x2e8f4bdbe3d47d7d7de490437aea9915d930f1a3', // USDP
|
|
550
|
+
'0xfdb93b3b10936cf81fa59a02a7523b6e2149b2b7',
|
|
551
|
+
'0xA361718326c15715591c299427c62086F69923D9', // BUSD
|
|
552
|
+
'0xbA429f7011c9fa04cDd46a2Da24dc0FF0aC6099c',
|
|
553
|
+
'0xd4937682df3C8aEF4FE912A96A74121C0829E664', // FRAX
|
|
554
|
+
'0xfE8F19B17fFeF0fDbfe2671F248903055AFAA8Ca',
|
|
555
|
+
'0x683923dB55Fead99A79Fa01A27EeC3cB19679cC3', // FEI
|
|
556
|
+
'0xC2e10006AccAb7B45D9184FcF5b7EC7763f5BaAe',
|
|
557
|
+
'0x8dAE6Cb04688C62d939ed9B68d32Bc62e49970b1', // CRV
|
|
558
|
+
'0x00ad8eBF64F141f1C81e9f8f792d3d1631c6c684',
|
|
559
|
+
'0x6F634c6135D2EBD550000ac92F494F9CB8183dAe', // DPI
|
|
560
|
+
'0x4dDff5885a67E4EffeC55875a3977D7E60F82ae0',
|
|
561
|
+
] as const;
|
|
562
|
+
|
|
563
|
+
export const fetchYearlyMeritApyForStakingGho = async () => {
|
|
564
|
+
try {
|
|
565
|
+
const response = await fetch('https://apps.aavechan.com/api/merit/aprs', { signal: AbortSignal.timeout(5000) });
|
|
566
|
+
const data = await response.json();
|
|
567
|
+
const apr = data?.currentAPR?.actionsAPR?.['ethereum-stkgho'] || '0' as string;
|
|
568
|
+
const apy = aprToApy(apr);
|
|
569
|
+
const apyWithDFSBonus = new Dec(apy).mul(1.05).toString(); // 5% bonus for DFS users
|
|
570
|
+
return apyWithDFSBonus;
|
|
571
|
+
} catch (e) {
|
|
572
|
+
const message = 'External API Failure: Failed to fetch yearly merit APY for staking GHO';
|
|
573
|
+
console.error(message, e);
|
|
574
|
+
return '0';
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
export const getStakeAaveData = async (provider: Client, network: NetworkNumber, address: EthAddress) => {
|
|
579
|
+
const stkGhoAddress = getAssetInfo('stkGHO').address as HexString;
|
|
580
|
+
const stkAaveAddress = getAssetInfo('stkAAVE').address as HexString;
|
|
581
|
+
|
|
582
|
+
const AaveIncentivesController = AaveIncentivesControllerViem(provider, network);
|
|
583
|
+
const stkAAVE = StkAAVEViem(provider, network);
|
|
584
|
+
const stkGHO = createViemContractFromConfigFunc('Erc20', stkGhoAddress as HexString)(provider, network);
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy] = await Promise.all([
|
|
588
|
+
AaveIncentivesController.read.getRewardsBalance([REWARDABLE_ASSETS, address]),
|
|
589
|
+
stkAAVE.read.assets([stkAaveAddress]),
|
|
590
|
+
stkAAVE.read.balanceOf([address]),
|
|
591
|
+
stkAAVE.read.totalSupply(),
|
|
592
|
+
stkGHO.read.balanceOf([address]),
|
|
593
|
+
fetchYearlyMeritApyForStakingGho(),
|
|
594
|
+
]);
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
const stkAaveApy = new Dec(assetAmountInEth(emissionsPerSecond[0].toString(), 'GHO') || 0).mul(SECONDS_PER_YEAR).mul(100).div(assetAmountInEth(stkAAVETotalSupply.toString(), 'stkAAVE'))
|
|
598
|
+
.toString();
|
|
599
|
+
return {
|
|
600
|
+
activatedCooldown: '0',
|
|
601
|
+
activatedCooldownAmount: '0',
|
|
602
|
+
stkAaveRewardsBalance: '0',
|
|
603
|
+
aaveRewardsBalance: assetAmountInEth(aaveRewardsBalance.toString(), 'AAVE'),
|
|
604
|
+
stkAaveBalance: assetAmountInEth(stkAAVEBalance.toString(), 'stkAAVE'),
|
|
605
|
+
stkGhoBalance: assetAmountInEth(stkGHOBalance.toString(), 'GHO'),
|
|
606
|
+
ghoMeritApy,
|
|
607
|
+
stkAaveApy,
|
|
608
|
+
};
|
|
609
|
+
};
|
|
610
|
+
|
|
513
611
|
export {
|
|
514
612
|
getMeritCampaigns,
|
|
515
613
|
getMerkleCampaigns,
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
3
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
4
|
+
import { ClaimableToken, ClaimType } from '../types/claiming';
|
|
5
|
+
import {
|
|
6
|
+
AaveIncentiveDataProviderV3ContractViem,
|
|
7
|
+
AaveRewardsControllerViem,
|
|
8
|
+
} from '../contracts';
|
|
9
|
+
import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
|
|
10
|
+
import { getAaveUnderlyingSymbol } from '../helpers/aaveHelpers';
|
|
11
|
+
|
|
12
|
+
type AaveReward = {
|
|
13
|
+
amount: string;
|
|
14
|
+
symbol: string;
|
|
15
|
+
underlyingAsset: string;
|
|
16
|
+
rewardTokenAddress: string;
|
|
17
|
+
aTokenAddresses: string[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const mapAaveRewardsToClaimableTokens = (aaveRewards: AaveReward[], marketAddress: EthAddress, walletAddress: EthAddress) => aaveRewards.map(reward => ({
|
|
21
|
+
symbol: reward.symbol,
|
|
22
|
+
amount: reward.amount,
|
|
23
|
+
claimType: ClaimType.AAVE_REWARDS as const,
|
|
24
|
+
tokenAddress: reward.rewardTokenAddress as EthAddress,
|
|
25
|
+
underlyingSymbol: reward.underlyingAsset,
|
|
26
|
+
walletAddress,
|
|
27
|
+
label: 'AAVE Rewards',
|
|
28
|
+
additionalClaimFields: {
|
|
29
|
+
marketAddress,
|
|
30
|
+
aTokenAddresses: reward.aTokenAddresses,
|
|
31
|
+
isAaveToken: reward.symbol.startsWith('a'),
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
export async function getUnclaimedRewardsForAllMarkets(
|
|
36
|
+
provider: Client,
|
|
37
|
+
network: NetworkNumber,
|
|
38
|
+
walletAddress: EthAddress,
|
|
39
|
+
marketAddress: EthAddress,
|
|
40
|
+
): Promise<ClaimableToken[]> {
|
|
41
|
+
const contract = AaveIncentiveDataProviderV3ContractViem(provider, network);
|
|
42
|
+
const tokensData = await contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
43
|
+
const allTokensDataArrays = tokensData.reduce((acc: any[], val) => {
|
|
44
|
+
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
45
|
+
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
46
|
+
return acc;
|
|
47
|
+
}, []);
|
|
48
|
+
const allATokens = tokensData.reduce((acc, val) => {
|
|
49
|
+
acc.push(val.aTokenIncentivesUserData.tokenAddress);
|
|
50
|
+
acc.push(val.vTokenIncentivesUserData.tokenAddress);
|
|
51
|
+
return acc;
|
|
52
|
+
}, [] as string[]);
|
|
53
|
+
// array of rewards for each market (aToken/vToken)
|
|
54
|
+
// reward can be any token like wstETH, but also aToken like aWETH
|
|
55
|
+
const aaveRewardsController = AaveRewardsControllerViem(provider, network);
|
|
56
|
+
const rewardsPerAAsset = await Promise.all(allATokens.map(
|
|
57
|
+
(token: string) => aaveRewardsController.read.getAllUserRewards([[token as EthAddress], walletAddress])));
|
|
58
|
+
|
|
59
|
+
// match amounts to token symbol, parse decimal amounts
|
|
60
|
+
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
|
61
|
+
const rewardsList = rewardForAAsset[0];
|
|
62
|
+
const amounts = rewardForAAsset[1];
|
|
63
|
+
|
|
64
|
+
const rewardsDataArraysForAAsset = allTokensDataArrays[aaIndex];
|
|
65
|
+
const aTokenAddress = allATokens[aaIndex];
|
|
66
|
+
return rewardsList.map((rewardTokenAddress, rewardIndex) => {
|
|
67
|
+
const dataArrIndex = rewardsDataArraysForAAsset.findIndex((arr: { rewardTokenAddress: string | undefined; }) => compareAddresses(arr.rewardTokenAddress, rewardTokenAddress));
|
|
68
|
+
const amountWei = amounts[rewardIndex];
|
|
69
|
+
const amount = getEthAmountForDecimals(amountWei.toString(), rewardsDataArraysForAAsset[dataArrIndex]?.rewardTokenDecimals);
|
|
70
|
+
const symbol = rewardsDataArraysForAAsset[dataArrIndex]?.rewardTokenSymbol || '';
|
|
71
|
+
const underlyingAsset = getAaveUnderlyingSymbol(symbol);
|
|
72
|
+
return ({
|
|
73
|
+
amount,
|
|
74
|
+
symbol,
|
|
75
|
+
underlyingAsset,
|
|
76
|
+
rewardTokenAddress,
|
|
77
|
+
aTokenAddress,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// sum all unclaimed rewards of all markets per each token
|
|
83
|
+
// (e.g. how much awstETH is claimable in total from both aUSDC and awstETH markets)
|
|
84
|
+
const totalUnclaimedPerRewardToken: Record<string, any> = {};
|
|
85
|
+
rewardsPerAAssetWithInfo
|
|
86
|
+
.flat()
|
|
87
|
+
.forEach(({
|
|
88
|
+
amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddress,
|
|
89
|
+
}) => {
|
|
90
|
+
if (+amount > 0) {
|
|
91
|
+
if (!totalUnclaimedPerRewardToken[symbol]) {
|
|
92
|
+
totalUnclaimedPerRewardToken[symbol] = {
|
|
93
|
+
amount, symbol, underlyingAsset, rewardTokenAddress, aTokenAddresses: [aTokenAddress],
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
totalUnclaimedPerRewardToken[symbol].amount =
|
|
97
|
+
new Dec(totalUnclaimedPerRewardToken[symbol].amount).add(amount).toString();
|
|
98
|
+
totalUnclaimedPerRewardToken[symbol].aTokenAddresses.push(aTokenAddress);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
return mapAaveRewardsToClaimableTokens(Object.values(totalUnclaimedPerRewardToken), marketAddress, walletAddress);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber, acceptMorpho: boolean = true): Promise<ClaimableToken[]> {
|
|
107
|
+
let data;
|
|
108
|
+
try {
|
|
109
|
+
const res = await fetch(`https://api.merkl.xyz/v4/users/${account}/rewards?chainId=${network}`,
|
|
110
|
+
{ signal: AbortSignal.timeout(3000) });
|
|
111
|
+
data = await res.json();
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('External API Failure: Aave Merit', error);
|
|
114
|
+
data = [];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const claimableTokens: ClaimableToken[] = [];
|
|
118
|
+
|
|
119
|
+
data.forEach((item: { rewards: any[]; }) => {
|
|
120
|
+
item.rewards.forEach(reward => {
|
|
121
|
+
const {
|
|
122
|
+
token,
|
|
123
|
+
amount,
|
|
124
|
+
claimed,
|
|
125
|
+
proofs,
|
|
126
|
+
} = reward;
|
|
127
|
+
|
|
128
|
+
const isTokenMorpho = token.symbol === 'MORPHO';
|
|
129
|
+
if (!token || !token.symbol || amount === '0' || (isTokenMorpho && !acceptMorpho)) return;
|
|
130
|
+
|
|
131
|
+
const unclaimedAmount = new Dec(amount).minus(claimed || 0).toString();
|
|
132
|
+
if (unclaimedAmount === '0') return;
|
|
133
|
+
|
|
134
|
+
const unclaimed = getEthAmountForDecimals(unclaimedAmount, token.decimals);
|
|
135
|
+
|
|
136
|
+
claimableTokens.push({
|
|
137
|
+
claimType: ClaimType.AAVE_MERIT_REWARDS,
|
|
138
|
+
amount: unclaimed,
|
|
139
|
+
symbol: token.symbol,
|
|
140
|
+
tokenAddress: token.address,
|
|
141
|
+
walletAddress: account,
|
|
142
|
+
label: 'AAVE Merit Rewards',
|
|
143
|
+
underlyingSymbol: getAaveUnderlyingSymbol(token.symbol),
|
|
144
|
+
additionalClaimFields: {
|
|
145
|
+
accumulated: amount,
|
|
146
|
+
proof: proofs,
|
|
147
|
+
decimals: token.decimals,
|
|
148
|
+
unclaimed: unclaimedAmount,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return claimableTokens;
|
|
155
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Client } from 'viem';
|
|
2
|
+
import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
4
|
+
import { CompV3ViewContractViem } from '../contracts';
|
|
5
|
+
import { ClaimType } from '../types/claiming';
|
|
6
|
+
|
|
7
|
+
export const getCompoundV3Rewards = async (provider: Client, network: NetworkNumber, user: EthAddress, market: any) => {
|
|
8
|
+
const compV3View = CompV3ViewContractViem(provider, network);
|
|
9
|
+
const rewards = await compV3View.read.getRewardsOwed([market, user]);
|
|
10
|
+
if (!rewards || rewards.owed.toString() === '0' || getAssetInfoByAddress(rewards.token, network).symbol !== 'COMP') return [];
|
|
11
|
+
return [{
|
|
12
|
+
symbol: 'COMP',
|
|
13
|
+
underlyingSymbol: 'COMP',
|
|
14
|
+
tokenAddress: rewards.token,
|
|
15
|
+
amount: assetAmountInEth(rewards.owed.toString() || 0, 'COMP'),
|
|
16
|
+
walletAddress: user,
|
|
17
|
+
label: 'Compound V3',
|
|
18
|
+
claimType: ClaimType.COMPOUND_V3_COMP,
|
|
19
|
+
additionalClaimFields: {
|
|
20
|
+
marketAddress: market,
|
|
21
|
+
},
|
|
22
|
+
}];
|
|
23
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
|
|
7
|
+
export {
|
|
8
|
+
aaveV3Claim,
|
|
9
|
+
compV3Claim,
|
|
10
|
+
kingV3Claim,
|
|
11
|
+
morphoBlueClaim,
|
|
12
|
+
sparkClaim,
|
|
13
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { assetAmountInEth } from '@defisaver/tokens';
|
|
3
|
+
import { Client } from 'viem';
|
|
4
|
+
import { UUPSViem } from '../contracts';
|
|
5
|
+
import { EthAddress, HexString, NetworkNumber } from '../types/common';
|
|
6
|
+
import { ClaimType } from '../types/claiming';
|
|
7
|
+
|
|
8
|
+
export const fetchKingRewards = async (walletAddress: EthAddress) => {
|
|
9
|
+
try {
|
|
10
|
+
const res = await fetch(`https://fe.defisaver.com/api/etherfi/get-king-rewards/${walletAddress}`,
|
|
11
|
+
{ signal: AbortSignal.timeout(5000) });
|
|
12
|
+
|
|
13
|
+
if (!res.ok) throw new Error(await res.text());
|
|
14
|
+
|
|
15
|
+
return await res.json();
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error('External API Error: Error fetching KING rewards:', err);
|
|
18
|
+
return { Amount: '0', Root: '', Proofs: [] };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getKingRewards = async (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => {
|
|
23
|
+
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
24
|
+
const apiDataPromises = walletAddresses.map(address => fetchKingRewards(address));
|
|
25
|
+
const apiDataArray = await Promise.all(apiDataPromises);
|
|
26
|
+
|
|
27
|
+
// Batch all contract calls using multicall
|
|
28
|
+
const contract = UUPSViem(provider, network);
|
|
29
|
+
const cumulativePromises = walletAddresses.map(address => contract.read.cumulativeClaimed([address]),
|
|
30
|
+
);
|
|
31
|
+
const cumulativeResults = await Promise.all(cumulativePromises);
|
|
32
|
+
|
|
33
|
+
// Process results
|
|
34
|
+
const results: Record<string, any[]> = {};
|
|
35
|
+
|
|
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
|
+
|
|
41
|
+
const allRewardsAmount = assetAmountInEth(data.Amount, 'KING');
|
|
42
|
+
const claimedAmount = assetAmountInEth(cumulative.toString(), 'KING');
|
|
43
|
+
const amountToClaim = new Dec(allRewardsAmount).sub(claimedAmount);
|
|
44
|
+
|
|
45
|
+
if (amountToClaim.lessThanOrEqualTo('0')) {
|
|
46
|
+
results[walletAddress.toLowerCase() as EthAddress] = [];
|
|
47
|
+
} else {
|
|
48
|
+
results[walletAddress.toLowerCase() as EthAddress] = [{
|
|
49
|
+
symbol: 'KING',
|
|
50
|
+
underlyingSymbol: 'KING',
|
|
51
|
+
tokenAddress: '0x8F08B70456eb22f6109F57b8fafE862ED28E6040',
|
|
52
|
+
amount: amountToClaim.toString(),
|
|
53
|
+
walletAddress,
|
|
54
|
+
label: 'weETH',
|
|
55
|
+
claimType: ClaimType.KING_REWARDS,
|
|
56
|
+
additionalClaimFields: {
|
|
57
|
+
allRewardsAmount,
|
|
58
|
+
merkleRoot: data.Root,
|
|
59
|
+
merkleProofs: data.Proofs,
|
|
60
|
+
},
|
|
61
|
+
}];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return results;
|
|
66
|
+
};
|