@defisaver/positions-sdk 2.1.174 → 2.1.175-looping-2-dev-dev
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.d.ts +4 -4
- package/cjs/aaveV2/index.js +7 -7
- package/cjs/aaveV3/index.d.ts +5 -14
- package/cjs/aaveV3/index.js +14 -10
- package/cjs/aaveV3/merkl.d.ts +5 -1
- package/cjs/aaveV3/merkl.js +8 -3
- package/cjs/aaveV3/sgho.d.ts +2 -16
- package/cjs/aaveV4/index.d.ts +4 -3
- package/cjs/aaveV4/index.js +19 -16
- package/cjs/aaveV4/lend.d.ts +2 -43
- package/cjs/aaveV4/merkl.d.ts +10 -2
- package/cjs/aaveV4/merkl.js +15 -6
- package/cjs/claiming/aaveV3.d.ts +3 -3
- package/cjs/claiming/aaveV3.js +5 -4
- package/cjs/claiming/ethena.d.ts +2 -1
- package/cjs/claiming/king.d.ts +3 -2
- package/cjs/claiming/king.js +3 -2
- package/cjs/claiming/spark.d.ts +4 -4
- package/cjs/claiming/spark.js +8 -7
- package/cjs/claiming/uniswap.d.ts +2 -2
- package/cjs/claiming/uniswap.js +3 -2
- package/cjs/compoundV2/index.d.ts +4 -4
- package/cjs/compoundV2/index.js +9 -9
- package/cjs/compoundV3/index.d.ts +5 -4
- package/cjs/compoundV3/index.js +17 -13
- package/cjs/compoundV3/merkl.d.ts +1 -1
- package/cjs/compoundV3/merkl.js +2 -5
- package/cjs/curveUsd/index.d.ts +5 -5
- package/cjs/curveUsd/index.js +17 -17
- package/cjs/fluid/index.d.ts +23 -66
- package/cjs/fluid/index.js +75 -72
- package/cjs/fluid/merkl.d.ts +5 -3
- package/cjs/fluid/merkl.js +11 -6
- package/cjs/helpers/aaveHelpers/index.js +1 -1
- package/cjs/helpers/aaveV4Helpers/index.js +14 -2
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/helpers/curveUsdHelpers/index.js +1 -1
- package/cjs/helpers/fluidHelpers/index.js +1 -1
- package/cjs/helpers/liquityV2Helpers/index.js +1 -1
- package/cjs/helpers/llamaLendHelpers/index.js +1 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
- package/cjs/helpers/morphoMidnightHelpers/index.js +1 -1
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/liquity/index.d.ts +5 -15
- package/cjs/liquity/index.js +23 -23
- package/cjs/liquityV2/index.d.ts +16 -31
- package/cjs/liquityV2/index.js +96 -78
- package/cjs/llamaLend/index.d.ts +5 -5
- package/cjs/llamaLend/index.js +13 -13
- package/cjs/maker/index.d.ts +6 -6
- package/cjs/maker/index.js +16 -16
- package/cjs/moneymarket/moneymarketCommonService.js +13 -2
- package/cjs/morphoBlue/index.d.ts +7 -7
- package/cjs/morphoBlue/index.js +28 -26
- package/cjs/morphoBlue/merkl.d.ts +5 -3
- package/cjs/morphoBlue/merkl.js +6 -8
- package/cjs/morphoMidnight/index.d.ts +5 -5
- package/cjs/morphoMidnight/index.js +18 -18
- package/cjs/portfolio/customDeFiData.d.ts +3 -0
- package/cjs/portfolio/customDeFiData.js +267 -0
- package/cjs/portfolio/index.d.ts +17 -8
- package/cjs/portfolio/index.js +459 -520
- package/cjs/portfolio/lendingProtocols.d.ts +184 -0
- package/cjs/portfolio/lendingProtocols.js +196 -0
- package/cjs/savings/index.d.ts +8 -2
- package/cjs/savings/index.js +33 -4
- package/cjs/services/merkl.d.ts +46 -2
- package/cjs/services/merkl.js +190 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -2
- package/cjs/services/viem.js +27 -1
- package/cjs/spark/index.d.ts +4 -4
- package/cjs/spark/index.js +9 -9
- package/cjs/types/aave.d.ts +98 -2
- package/cjs/types/aaveV4.d.ts +45 -0
- package/cjs/types/common.d.ts +1 -0
- package/cjs/types/common.js +1 -0
- package/cjs/types/compound.d.ts +26 -2
- package/cjs/types/curveUsd.d.ts +9 -1
- package/cjs/types/fluid.d.ts +13 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquity.d.ts +12 -0
- package/cjs/types/liquityV2.d.ts +24 -0
- package/cjs/types/llamaLend.d.ts +12 -1
- package/cjs/types/merkl.d.ts +18 -0
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/portfolio.d.ts +162 -5
- package/cjs/types/portfolio.js +18 -0
- package/cjs/types/savings/index.d.ts +9 -1
- package/cjs/types/spark.d.ts +21 -1
- package/cjs/umbrella/index.d.ts +3 -4
- package/cjs/umbrella/index.js +5 -4
- package/esm/aaveV2/index.d.ts +4 -4
- package/esm/aaveV2/index.js +8 -8
- package/esm/aaveV3/index.d.ts +5 -14
- package/esm/aaveV3/index.js +15 -11
- package/esm/aaveV3/merkl.d.ts +5 -1
- package/esm/aaveV3/merkl.js +9 -4
- package/esm/aaveV3/sgho.d.ts +2 -16
- package/esm/aaveV4/index.d.ts +4 -3
- package/esm/aaveV4/index.js +20 -17
- package/esm/aaveV4/lend.d.ts +2 -43
- package/esm/aaveV4/merkl.d.ts +10 -2
- package/esm/aaveV4/merkl.js +16 -7
- package/esm/claiming/aaveV3.d.ts +3 -3
- package/esm/claiming/aaveV3.js +6 -5
- package/esm/claiming/ethena.d.ts +2 -1
- package/esm/claiming/king.d.ts +3 -2
- package/esm/claiming/king.js +3 -2
- package/esm/claiming/spark.d.ts +4 -4
- package/esm/claiming/spark.js +9 -8
- package/esm/claiming/uniswap.d.ts +2 -2
- package/esm/claiming/uniswap.js +3 -2
- package/esm/compoundV2/index.d.ts +4 -4
- package/esm/compoundV2/index.js +9 -9
- package/esm/compoundV3/index.d.ts +5 -4
- package/esm/compoundV3/index.js +19 -15
- package/esm/compoundV3/merkl.d.ts +1 -1
- package/esm/compoundV3/merkl.js +3 -6
- package/esm/curveUsd/index.d.ts +5 -5
- package/esm/curveUsd/index.js +17 -17
- package/esm/fluid/index.d.ts +23 -66
- package/esm/fluid/index.js +76 -73
- package/esm/fluid/merkl.d.ts +5 -3
- package/esm/fluid/merkl.js +12 -7
- package/esm/helpers/aaveHelpers/index.js +1 -1
- package/esm/helpers/aaveV4Helpers/index.js +15 -3
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/curveUsdHelpers/index.js +1 -1
- package/esm/helpers/fluidHelpers/index.js +1 -1
- package/esm/helpers/liquityV2Helpers/index.js +1 -1
- package/esm/helpers/llamaLendHelpers/index.js +1 -1
- package/esm/helpers/morphoBlueHelpers/index.js +1 -1
- package/esm/helpers/morphoMidnightHelpers/index.js +1 -1
- package/esm/helpers/sparkHelpers/index.js +1 -1
- package/esm/liquity/index.d.ts +5 -15
- package/esm/liquity/index.js +23 -23
- package/esm/liquityV2/index.d.ts +16 -31
- package/esm/liquityV2/index.js +95 -78
- package/esm/llamaLend/index.d.ts +5 -5
- package/esm/llamaLend/index.js +13 -13
- package/esm/maker/index.d.ts +6 -6
- package/esm/maker/index.js +16 -16
- package/esm/moneymarket/moneymarketCommonService.js +13 -2
- package/esm/morphoBlue/index.d.ts +7 -7
- package/esm/morphoBlue/index.js +29 -27
- package/esm/morphoBlue/merkl.d.ts +5 -3
- package/esm/morphoBlue/merkl.js +7 -9
- package/esm/morphoMidnight/index.d.ts +5 -5
- package/esm/morphoMidnight/index.js +18 -18
- package/esm/portfolio/customDeFiData.d.ts +3 -0
- package/esm/portfolio/customDeFiData.js +261 -0
- package/esm/portfolio/index.d.ts +17 -8
- package/esm/portfolio/index.js +459 -522
- package/esm/portfolio/lendingProtocols.d.ts +184 -0
- package/esm/portfolio/lendingProtocols.js +189 -0
- package/esm/savings/index.d.ts +8 -2
- package/esm/savings/index.js +31 -3
- package/esm/services/merkl.d.ts +46 -2
- package/esm/services/merkl.js +180 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -2
- package/esm/services/viem.js +25 -0
- package/esm/spark/index.d.ts +4 -4
- package/esm/spark/index.js +10 -10
- package/esm/types/aave.d.ts +98 -2
- package/esm/types/aaveV4.d.ts +45 -0
- package/esm/types/common.d.ts +1 -0
- package/esm/types/common.js +1 -0
- package/esm/types/compound.d.ts +26 -2
- package/esm/types/curveUsd.d.ts +9 -1
- package/esm/types/fluid.d.ts +13 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquity.d.ts +12 -0
- package/esm/types/liquityV2.d.ts +24 -0
- package/esm/types/llamaLend.d.ts +12 -1
- package/esm/types/merkl.d.ts +18 -0
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/portfolio.d.ts +162 -5
- package/esm/types/portfolio.js +17 -1
- package/esm/types/savings/index.d.ts +9 -1
- package/esm/types/spark.d.ts +21 -1
- package/esm/umbrella/index.d.ts +3 -4
- package/esm/umbrella/index.js +5 -4
- package/package.json +1 -1
- package/src/aaveV2/index.ts +7 -7
- package/src/aaveV3/index.ts +16 -11
- package/src/aaveV3/merkl.ts +9 -4
- package/src/aaveV3/sgho.ts +2 -17
- package/src/aaveV4/index.ts +19 -16
- package/src/aaveV4/lend.ts +2 -48
- package/src/aaveV4/merkl.ts +16 -7
- package/src/claiming/aaveV3.ts +9 -5
- package/src/claiming/ethena.ts +5 -5
- package/src/claiming/king.ts +8 -5
- package/src/claiming/spark.ts +15 -10
- package/src/claiming/uniswap.ts +4 -3
- package/src/compoundV2/index.ts +10 -9
- package/src/compoundV3/index.ts +20 -14
- package/src/compoundV3/merkl.ts +5 -4
- package/src/curveUsd/index.ts +19 -17
- package/src/fluid/index.ts +91 -72
- package/src/fluid/merkl.ts +12 -7
- package/src/helpers/aaveHelpers/index.ts +1 -1
- package/src/helpers/aaveV4Helpers/index.ts +16 -2
- package/src/helpers/compoundHelpers/index.ts +2 -2
- package/src/helpers/curveUsdHelpers/index.ts +1 -1
- package/src/helpers/fluidHelpers/index.ts +1 -1
- package/src/helpers/liquityV2Helpers/index.ts +1 -1
- package/src/helpers/llamaLendHelpers/index.ts +1 -1
- package/src/helpers/morphoBlueHelpers/index.ts +1 -1
- package/src/helpers/morphoMidnightHelpers/index.ts +1 -1
- package/src/helpers/sparkHelpers/index.ts +1 -1
- package/src/liquity/index.ts +24 -24
- package/src/liquityV2/index.ts +110 -76
- package/src/llamaLend/index.ts +15 -13
- package/src/maker/index.ts +19 -16
- package/src/moneymarket/moneymarketCommonService.ts +14 -2
- package/src/morphoBlue/index.ts +23 -20
- package/src/morphoBlue/merkl.ts +9 -6
- package/src/morphoMidnight/index.ts +13 -13
- package/src/portfolio/customDeFiData.ts +385 -0
- package/src/portfolio/index.ts +307 -331
- package/src/portfolio/lendingProtocols.ts +281 -0
- package/src/savings/index.ts +41 -4
- package/src/services/merkl.ts +209 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +16 -0
- package/src/spark/index.ts +11 -8
- package/src/types/aave.ts +104 -1
- package/src/types/aaveV4.ts +50 -0
- package/src/types/common.ts +1 -0
- package/src/types/compound.ts +38 -2
- package/src/types/curveUsd.ts +17 -1
- package/src/types/fluid.ts +14 -0
- package/src/types/index.ts +1 -0
- package/src/types/liquity.ts +13 -1
- package/src/types/liquityV2.ts +26 -1
- package/src/types/llamaLend.ts +19 -1
- package/src/types/merkl.ts +20 -0
- package/src/types/morphoBlue.ts +3 -0
- package/src/types/portfolio.ts +191 -5
- package/src/types/savings/index.ts +12 -1
- package/src/types/spark.ts +25 -1
- package/src/umbrella/index.ts +7 -5
package/esm/types/spark.d.ts
CHANGED
|
@@ -46,6 +46,21 @@ export interface SparkAssetData extends MMAssetData {
|
|
|
46
46
|
eModeCategory: number;
|
|
47
47
|
liquidationBonus: string;
|
|
48
48
|
liquidationRatio: string;
|
|
49
|
+
debtCeilingForIsolationMode?: string;
|
|
50
|
+
isSiloed?: boolean;
|
|
51
|
+
isolationModeTotalDebt?: string;
|
|
52
|
+
isolationModeBorrowingEnabled?: boolean;
|
|
53
|
+
assetId?: number;
|
|
54
|
+
borrowRateStable?: string;
|
|
55
|
+
supplyCap?: string;
|
|
56
|
+
isInactive?: boolean;
|
|
57
|
+
isFrozen?: boolean;
|
|
58
|
+
isPaused?: boolean;
|
|
59
|
+
canBeWithdrawn?: boolean;
|
|
60
|
+
canBePayBacked?: boolean;
|
|
61
|
+
disabledStableBorrowing?: boolean;
|
|
62
|
+
isFlashLoanEnabled?: boolean;
|
|
63
|
+
aTokenAddress?: EthAddress;
|
|
49
64
|
}
|
|
50
65
|
export interface SparkAssetsData {
|
|
51
66
|
[token: string]: SparkAssetData;
|
|
@@ -101,7 +116,12 @@ export interface SparkAggregatedPositionData {
|
|
|
101
116
|
minHealthRatio: string;
|
|
102
117
|
exposure: string;
|
|
103
118
|
}
|
|
104
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Fields sparkGetAggregatedPositionData adds to every Spark position at runtime, on top of those declared below.
|
|
121
|
+
* Optional, so code that builds a position by hand keeps compiling.
|
|
122
|
+
*/
|
|
123
|
+
export type SparkPositionAggregatedFields = Partial<Omit<SparkAggregatedPositionData, keyof MMPositionData | 'ratio' | 'collRatio' | 'suppliedUsd' | 'borrowedUsd' | 'borrowLimitUsd' | 'suppliedCollateralUsd' | 'incentiveUsd' | 'totalInterestUsd'>>;
|
|
124
|
+
export interface SparkPositionData extends MMPositionData, SparkPositionAggregatedFields {
|
|
105
125
|
ratio: string;
|
|
106
126
|
minRatio: string;
|
|
107
127
|
collRatio: string;
|
package/esm/umbrella/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}>;
|
|
2
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
import { UmbrellaStakingData } from '../types/aave';
|
|
4
|
+
export declare const getUmbrellaData: (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber?: Blockish) => Promise<UmbrellaStakingData>;
|
package/esm/umbrella/index.js
CHANGED
|
@@ -9,16 +9,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AaveUmbrellaViewViem, AaveV3ViewContractViem } from '../contracts';
|
|
11
11
|
import { compareAddresses, convertHybridArraysToObjects, getEthAmountForDecimals } from '../services/utils';
|
|
12
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
12
13
|
import { findMatching, tokenEntries } from './umbrellaUtils';
|
|
13
14
|
const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
|
|
14
15
|
const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
|
|
15
|
-
export const getUmbrellaData = (
|
|
16
|
+
export const getUmbrellaData = (provider_1, network_1, address_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, ...args_1], void 0, function* (provider, network, address, blockNumber = 'latest') {
|
|
16
17
|
const umbrellaView = AaveUmbrellaViewViem(provider, network);
|
|
17
18
|
const aaveV3View = AaveV3ViewContractViem(provider, network);
|
|
18
19
|
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]),
|
|
20
|
+
umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle], setViemBlockNumber(blockNumber)),
|
|
21
|
+
aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address], setViemBlockNumber(blockNumber)),
|
|
22
|
+
umbrellaView.read.getUserAggregatedData([umbrella, address], setViemBlockNumber(blockNumber)),
|
|
22
23
|
]);
|
|
23
24
|
return Object.fromEntries(tokenEntries.map(([symbol, tokenAddr]) => {
|
|
24
25
|
// @ts-ignore
|
package/package.json
CHANGED
package/src/aaveV2/index.ts
CHANGED
|
@@ -18,13 +18,13 @@ import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
|
|
|
18
18
|
import { getEthPrice } from '../services/priceService';
|
|
19
19
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
20
20
|
|
|
21
|
-
export const _getAaveV2MarketsData = async (provider: Client, network: NetworkNumber, selectedMarket: AaveMarketInfo) => {
|
|
21
|
+
export const _getAaveV2MarketsData = async (provider: Client, network: NetworkNumber, selectedMarket: AaveMarketInfo, blockNumber: Blockish = 'latest') => {
|
|
22
22
|
const _addresses = selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
23
23
|
const loanInfoContract = AaveLoanInfoV2ContractViem(provider, network);
|
|
24
24
|
const marketAddress = selectedMarket.providerAddress;
|
|
25
25
|
const [loanInfo, ethPrice] = await Promise.all([
|
|
26
|
-
loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses as EthAddress[]]),
|
|
27
|
-
getEthPrice(provider),
|
|
26
|
+
loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses as EthAddress[]], setViemBlockNumber(blockNumber)),
|
|
27
|
+
getEthPrice(provider, blockNumber),
|
|
28
28
|
]);
|
|
29
29
|
const markets: AaveV2AssetData[] = loanInfo
|
|
30
30
|
.map((market, i) => ({
|
|
@@ -87,7 +87,7 @@ export const _getAaveV2MarketsData = async (provider: Client, network: NetworkNu
|
|
|
87
87
|
return { assetsData: payload };
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
export const getAaveV2MarketsData = async (provider: EthereumProvider, network: NetworkNumber, selectedMarket: AaveMarketInfo) => _getAaveV2MarketsData(getViemProvider(provider, network), network, selectedMarket);
|
|
90
|
+
export const getAaveV2MarketsData = async (provider: EthereumProvider, network: NetworkNumber, selectedMarket: AaveMarketInfo, blockNumber: Blockish = 'latest') => _getAaveV2MarketsData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
91
91
|
|
|
92
92
|
export const _getAaveV2AccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => {
|
|
93
93
|
const balances = await getAaveLikeBalances(provider, network, block, addressMapping, address, AAVE_V2, 'AaveLoanInfoV2');
|
|
@@ -100,7 +100,7 @@ export const _getAaveV2AccountBalances = async (provider: Client, network: Netwo
|
|
|
100
100
|
|
|
101
101
|
export const getAaveV2AccountBalances = async (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => _getAaveV2AccountBalances(getViemProvider(provider, network), network, block, addressMapping, address);
|
|
102
102
|
|
|
103
|
-
export const _getAaveV2AccountData = async (provider: Client, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo): Promise<AaveV2PositionData> => {
|
|
103
|
+
export const _getAaveV2AccountData = async (provider: Client, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo, blockNumber: Blockish = 'latest'): Promise<AaveV2PositionData> => {
|
|
104
104
|
if (!address) throw new Error('Address is required');
|
|
105
105
|
|
|
106
106
|
let payload: AaveV2PositionData = {
|
|
@@ -111,7 +111,7 @@ export const _getAaveV2AccountData = async (provider: Client, network: NetworkNu
|
|
|
111
111
|
const loanInfoContract = AaveLoanInfoV2ContractViem(provider, network);
|
|
112
112
|
const marketAddress = market.providerAddress;
|
|
113
113
|
const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
114
|
-
const loanInfo = await loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses as EthAddress[]]);
|
|
114
|
+
const loanInfo = await loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses as EthAddress[]], setViemBlockNumber(blockNumber));
|
|
115
115
|
const usedAssets = {} as AaveV2UsedAssets;
|
|
116
116
|
loanInfo.forEach((_tokenInfo, i) => {
|
|
117
117
|
const asset = market.assets[i];
|
|
@@ -193,7 +193,7 @@ export const _getAaveV2AccountData = async (provider: Client, network: NetworkNu
|
|
|
193
193
|
return payload;
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
-
export const getAaveV2AccountData = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo): Promise<AaveV2PositionData> => _getAaveV2AccountData(getViemProvider(provider, network), network, address, assetsData, market);
|
|
196
|
+
export const getAaveV2AccountData = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, assetsData: AaveV2AssetsData, market: AaveMarketInfo, blockNumber: Blockish = 'latest'): Promise<AaveV2PositionData> => _getAaveV2AccountData(getViemProvider(provider, network), network, address, assetsData, market, blockNumber);
|
|
197
197
|
|
|
198
198
|
export const getAaveV2FullPositionData = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo): Promise<AaveV2PositionData> => {
|
|
199
199
|
const marketData = await getAaveV2MarketsData(provider, network, market);
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
EModeCategoriesData,
|
|
32
32
|
EModeCategoryData,
|
|
33
33
|
EModeCategoryDataMapping,
|
|
34
|
+
StakeAaveData,
|
|
34
35
|
} from '../types';
|
|
35
36
|
import {
|
|
36
37
|
Blockish,
|
|
@@ -42,7 +43,7 @@ import {
|
|
|
42
43
|
PositionBalances,
|
|
43
44
|
HexString,
|
|
44
45
|
} from '../types/common';
|
|
45
|
-
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
46
|
+
import { getBlockTimestamp, getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
46
47
|
import { getMeritCampaigns } from './merit';
|
|
47
48
|
import { getAaveUnderlyingSymbol, getMerkleCampaigns } from './merkl';
|
|
48
49
|
import { getSghoData } from './sgho';
|
|
@@ -81,7 +82,8 @@ export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: Aa
|
|
|
81
82
|
return categoriesMapping;
|
|
82
83
|
};
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
/** `blockTimestamp` (unix seconds) is the historical block's timestamp when already known; otherwise it is read from the block. */
|
|
86
|
+
export async function _getAaveV3MarketData(provider: Client, network: NetworkNumber, market: AaveMarketInfo, blockNumber: 'latest' | number = 'latest', blockTimestamp?: number): Promise<AaveV3MarketData> {
|
|
85
87
|
const _addresses = market.assets.map(a => getAssetInfo(getWrappedNativeAssetFromUnwrapped(a), network).address);
|
|
86
88
|
|
|
87
89
|
const loanInfoContract = AaveV3ViewContractViem(provider, network);
|
|
@@ -100,12 +102,15 @@ export async function _getAaveV3MarketData(provider: Client, network: NetworkNum
|
|
|
100
102
|
[marketAddress, addresses],
|
|
101
103
|
setViemBlockNumber(blockNumber),
|
|
102
104
|
))).then((loanInfoChunks) => loanInfoChunks.flat());
|
|
105
|
+
// Merkl rewards are keyed by time, so a historical block resolves to its timestamp first (one
|
|
106
|
+
// RPC call unless given, none for 'latest') and the rewards in force at that moment are attached.
|
|
107
|
+
const merkleRewardsPromise = getBlockTimestamp(provider, blockNumber, blockTimestamp).then((asOfTimestamp) => getMerkleCampaigns(network, asOfTimestamp));
|
|
103
108
|
// eslint-disable-next-line prefer-const
|
|
104
109
|
let [loanInfo, eModesInfo, rewardInfo, merkleRewardsMap, meritRewardsMap] = await Promise.all([
|
|
105
110
|
loanInfoPromise,
|
|
106
111
|
loanInfoContract.read.getAllEmodes([marketAddress], setViemBlockNumber(blockNumber)),
|
|
107
112
|
networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], setViemBlockNumber(blockNumber)) : null,
|
|
108
|
-
|
|
113
|
+
merkleRewardsPromise,
|
|
109
114
|
getMeritCampaigns(network, market.value),
|
|
110
115
|
]);
|
|
111
116
|
// same break logic as view contract
|
|
@@ -356,8 +361,8 @@ export async function _getAaveV3MarketData(provider: Client, network: NetworkNum
|
|
|
356
361
|
return { assetsData: payload, eModeCategoriesData };
|
|
357
362
|
}
|
|
358
363
|
|
|
359
|
-
export async function getAaveV3MarketData(provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo, blockNumber: 'latest' | number = 'latest'): Promise<AaveV3MarketData> {
|
|
360
|
-
return _getAaveV3MarketData(getViemProvider(provider, network), network, market, blockNumber);
|
|
364
|
+
export async function getAaveV3MarketData(provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo, blockNumber: 'latest' | number = 'latest', blockTimestamp?: number): Promise<AaveV3MarketData> {
|
|
365
|
+
return _getAaveV3MarketData(getViemProvider(provider, network), network, market, blockNumber, blockTimestamp);
|
|
361
366
|
}
|
|
362
367
|
|
|
363
368
|
export const EMPTY_AAVE_DATA = {
|
|
@@ -852,7 +857,7 @@ export const fetchYearlyMeritApyForStakingGho = async () => {
|
|
|
852
857
|
}
|
|
853
858
|
};
|
|
854
859
|
|
|
855
|
-
export const getStakeAaveData = async (provider: Client, network: NetworkNumber, address: EthAddress) => {
|
|
860
|
+
export const getStakeAaveData = async (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber: Blockish = 'latest'): Promise<StakeAaveData> => {
|
|
856
861
|
const stkGhoAddress = getAssetInfo('stkGHO').address as HexString;
|
|
857
862
|
const stkAaveAddress = getAssetInfo('stkAAVE').address as HexString;
|
|
858
863
|
|
|
@@ -862,11 +867,11 @@ export const getStakeAaveData = async (provider: Client, network: NetworkNumber,
|
|
|
862
867
|
|
|
863
868
|
|
|
864
869
|
const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy, sgho] = await Promise.all([
|
|
865
|
-
AaveIncentivesController.read.getRewardsBalance([REWARDABLE_ASSETS, address]),
|
|
866
|
-
stkAAVE.read.assets([stkAaveAddress]),
|
|
867
|
-
stkAAVE.read.balanceOf([address]),
|
|
868
|
-
stkAAVE.read.totalSupply(),
|
|
869
|
-
stkGHO.read.balanceOf([address]),
|
|
870
|
+
AaveIncentivesController.read.getRewardsBalance([REWARDABLE_ASSETS, address], setViemBlockNumber(blockNumber)),
|
|
871
|
+
stkAAVE.read.assets([stkAaveAddress], setViemBlockNumber(blockNumber)),
|
|
872
|
+
stkAAVE.read.balanceOf([address], setViemBlockNumber(blockNumber)),
|
|
873
|
+
stkAAVE.read.totalSupply(setViemBlockNumber(blockNumber)),
|
|
874
|
+
stkGHO.read.balanceOf([address], setViemBlockNumber(blockNumber)),
|
|
870
875
|
fetchYearlyMeritApyForStakingGho(),
|
|
871
876
|
getSghoData(network, address),
|
|
872
877
|
]);
|
package/src/aaveV3/merkl.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { aprToApy } from '../moneymarket';
|
|
2
|
-
import {
|
|
2
|
+
import { fetchMerklOpportunities } from '../services/merkl';
|
|
3
3
|
import { wethToEth } from '../services/utils';
|
|
4
4
|
import {
|
|
5
5
|
MerkleRewardMap, MerklOpportunity, OpportunityAction, OpportunityStatus,
|
|
@@ -30,12 +30,17 @@ export const formatAaveAsset = (_symbol: string) => {
|
|
|
30
30
|
return _symbol;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Live Merkl reward campaigns for Aave V3 on the chain, keyed by aToken. With `asOfTimestamp` (unix
|
|
35
|
+
* seconds) the campaigns and APRs are the ones Merkl had at that moment instead.
|
|
36
|
+
*/
|
|
37
|
+
export const getMerkleCampaigns = async (chainId: NetworkNumber, asOfTimestamp?: number): Promise<MerkleRewardMap> => {
|
|
34
38
|
try {
|
|
35
|
-
const opportunities = await
|
|
39
|
+
const opportunities = await fetchMerklOpportunities({
|
|
36
40
|
mainProtocolId: 'aave',
|
|
41
|
+
chainId: chainId.toString(),
|
|
37
42
|
status: OpportunityStatus.LIVE,
|
|
38
|
-
});
|
|
43
|
+
}, asOfTimestamp, (o) => !o.type?.startsWith('AAVE_V4_'));
|
|
39
44
|
const relevantOpportunities = opportunities
|
|
40
45
|
.filter((o: MerklOpportunity) => o.chainId === chainId)
|
|
41
46
|
.filter((o: MerklOpportunity) => o.status === OpportunityStatus.LIVE);
|
package/src/aaveV3/sgho.ts
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
import { SghoData } from '../types/aave';
|
|
3
4
|
import { DEFAULT_TIMEOUT } from '../services/utils';
|
|
4
5
|
import { ZERO_ADDRESS } from '../constants';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
shares: string;
|
|
8
|
-
balance: string;
|
|
9
|
-
maxDeposit: string;
|
|
10
|
-
maxWithdraw: string;
|
|
11
|
-
underlyingBalance: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface SghoData {
|
|
15
|
-
totalAssets: string;
|
|
16
|
-
totalSupply: string;
|
|
17
|
-
supplyCap: string;
|
|
18
|
-
/** Target savings rate as an APY percent (e.g. "4.25" for 4.25%). */
|
|
19
|
-
targetRate: string;
|
|
20
|
-
paused: boolean;
|
|
21
|
-
user: SghoUserData;
|
|
22
|
-
}
|
|
7
|
+
export type { SghoData, SghoUserData } from '../types/aave';
|
|
23
8
|
|
|
24
9
|
const EMPTY_SGHO_DATA: SghoData = {
|
|
25
10
|
totalAssets: '0',
|
package/src/aaveV4/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import Dec from 'decimal.js';
|
|
3
3
|
import { assetAmountInEth, assetAmountInWei, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
4
|
-
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
4
|
+
import { getBlockTimestamp, getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
5
5
|
import {
|
|
6
6
|
AaveV4AccountData,
|
|
7
7
|
AaveV4HubAssetOnChainData,
|
|
@@ -32,8 +32,8 @@ import { attachAaveV4MerklIncentives, getAaveV4MerkleCampaigns } from './merkl';
|
|
|
32
32
|
export * as lend from './lend';
|
|
33
33
|
export { getAaveV4MerkleCampaigns } from './merkl';
|
|
34
34
|
|
|
35
|
-
const fetchHubData = async (viewContract: ReturnType<typeof AaveV4ViewContractViem>, hubAddress: EthAddress): Promise<AaveV4HubOnChainData> => {
|
|
36
|
-
const hubData = await viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
35
|
+
const fetchHubData = async (viewContract: ReturnType<typeof AaveV4ViewContractViem>, hubAddress: EthAddress, blockNumber: Blockish = 'latest'): Promise<AaveV4HubOnChainData> => {
|
|
36
|
+
const hubData = await viewContract.read.getHubAllAssetsData([hubAddress], setViemBlockNumber(blockNumber));
|
|
37
37
|
return {
|
|
38
38
|
assets: hubData.reduce((acc: Record<number, AaveV4HubAssetOnChainData>, assetOnChainData) => {
|
|
39
39
|
acc[assetOnChainData.assetId] = {
|
|
@@ -162,19 +162,22 @@ const formatReserveAsset = async (reserveAsset: AaveV4ReserveAssetOnChain, hubAs
|
|
|
162
162
|
});
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
/** `blockTimestamp` (unix seconds) is the historical block's timestamp when already known; otherwise it is read from the block. */
|
|
166
|
+
export async function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber: 'latest' | number = 'latest', blockTimestamp?: number): Promise<AaveV4SpokeData> {
|
|
166
167
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
167
168
|
|
|
168
169
|
const hubsData: Record<string, AaveV4HubOnChainData> = {};
|
|
169
170
|
const loadHubData = async (hubAddress: EthAddress) => {
|
|
170
|
-
hubsData[hubAddress.toLowerCase()] = await fetchHubData(viewContract, hubAddress);
|
|
171
|
+
hubsData[hubAddress.toLowerCase()] = await fetchHubData(viewContract, hubAddress, blockNumber);
|
|
171
172
|
};
|
|
172
173
|
|
|
173
174
|
// market.hubs is only a prefetch hint (lets known hubs load in parallel with the spoke data), so
|
|
174
175
|
// failures are tolerated here — any hub the reserves actually reference is (re)fetched below.
|
|
175
176
|
const [spokeData, merklCampaigns] = await Promise.all([
|
|
176
|
-
viewContract.read.getSpokeDataFull([market.address]),
|
|
177
|
-
|
|
177
|
+
viewContract.read.getSpokeDataFull([market.address], setViemBlockNumber(blockNumber)),
|
|
178
|
+
// Merkl rewards are keyed by time: a historical block resolves to its timestamp first (one RPC
|
|
179
|
+
// call unless given, none for 'latest') so the rewards in force at that moment are attached.
|
|
180
|
+
getBlockTimestamp(provider, blockNumber, blockTimestamp).then((asOfTimestamp) => getAaveV4MerkleCampaigns(network, asOfTimestamp)),
|
|
178
181
|
...market.hubs.map((hubAddress) => loadHubData(hubAddress).catch(() => {})),
|
|
179
182
|
]);
|
|
180
183
|
|
|
@@ -205,14 +208,14 @@ export async function _getAaveV4SpokeData(provider: Client, network: NetworkNumb
|
|
|
205
208
|
};
|
|
206
209
|
}
|
|
207
210
|
|
|
208
|
-
export async function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4SpokeData> {
|
|
209
|
-
return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber);
|
|
211
|
+
export async function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber: 'latest' | number = 'latest', blockTimestamp?: number): Promise<AaveV4SpokeData> {
|
|
212
|
+
return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber, blockTimestamp);
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
export async function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber: 'latest' | number = 'latest'): Promise<AaveV4AccountData> {
|
|
213
216
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
214
217
|
|
|
215
|
-
const loanData = await viewContract.read.getLoanData([spokeData.address, address]);
|
|
218
|
+
const loanData = await viewContract.read.getLoanData([spokeData.address, address], setViemBlockNumber(blockNumber));
|
|
216
219
|
|
|
217
220
|
const healthFactorFromContract = new Dec(loanData.healthFactor.toString());
|
|
218
221
|
const healthFactor = isMaxUint(healthFactorFromContract.toString()) ? 'Infinity' : healthFactorFromContract.div(1e18).toString();
|
|
@@ -297,7 +300,7 @@ export const _getAaveV4AccountHasAnyBalance = async (
|
|
|
297
300
|
const blockNumber = block === 'latest' ? 'latest' : Number(block);
|
|
298
301
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
299
302
|
|
|
300
|
-
const loanData = await viewContract.read.getLoanData([spokeAddress, address]);
|
|
303
|
+
const loanData = await viewContract.read.getLoanData([spokeAddress, address], setViemBlockNumber(blockNumber));
|
|
301
304
|
const reserves = loanData?.reserves || [];
|
|
302
305
|
|
|
303
306
|
return reserves.some((reserveAsset) => {
|
|
@@ -379,14 +382,14 @@ export const getAaveV4AccountBalances = async (
|
|
|
379
382
|
spokeData,
|
|
380
383
|
);
|
|
381
384
|
|
|
382
|
-
const _getAaveV4UnderlyingFromReserveId = async (provider: Client, network: NetworkNumber, spoke: EthAddress, reserveId: number): Promise<any> => {
|
|
383
|
-
const viewContract = AaveV4ViewContractViem(provider, network);
|
|
385
|
+
const _getAaveV4UnderlyingFromReserveId = async (provider: Client, network: NetworkNumber, spoke: EthAddress, reserveId: number, blockNumber: Blockish = 'latest'): Promise<any> => {
|
|
386
|
+
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
384
387
|
|
|
385
|
-
const reserveData = await viewContract.read.getReserveData([spoke, BigInt(reserveId)]);
|
|
388
|
+
const reserveData = await viewContract.read.getReserveData([spoke, BigInt(reserveId)], setViemBlockNumber(blockNumber));
|
|
386
389
|
|
|
387
390
|
return reserveData.underlying;
|
|
388
391
|
};
|
|
389
392
|
|
|
390
|
-
export async function getAaveV4UnderlyingFromReserveId(provider: EthereumProvider, network: NetworkNumber, spoke: EthAddress, reserveId: number): Promise<any> {
|
|
391
|
-
return _getAaveV4UnderlyingFromReserveId(getViemProvider(provider, network), network, spoke, reserveId);
|
|
393
|
+
export async function getAaveV4UnderlyingFromReserveId(provider: EthereumProvider, network: NetworkNumber, spoke: EthAddress, reserveId: number, blockNumber: Blockish = 'latest'): Promise<any> {
|
|
394
|
+
return _getAaveV4UnderlyingFromReserveId(getViemProvider(provider, network), network, spoke, reserveId, blockNumber);
|
|
392
395
|
}
|
package/src/aaveV4/lend.ts
CHANGED
|
@@ -7,26 +7,9 @@ import {
|
|
|
7
7
|
EthereumProvider,
|
|
8
8
|
NetworkNumber,
|
|
9
9
|
} from '../types/common';
|
|
10
|
+
import { AaveV4TokenizationSpokeDataParsed } from '../types/aaveV4';
|
|
10
11
|
|
|
11
|
-
export
|
|
12
|
-
underlyingAsset: EthAddress;
|
|
13
|
-
assetId: string;
|
|
14
|
-
decimals: number;
|
|
15
|
-
spoke: EthAddress;
|
|
16
|
-
spokeActive: boolean;
|
|
17
|
-
spokeHalted: boolean;
|
|
18
|
-
spokeDepositCap: string;
|
|
19
|
-
spokeTotalAssets: string;
|
|
20
|
-
spokeTotalShares: string;
|
|
21
|
-
hub: EthAddress;
|
|
22
|
-
hubLiquidity: string;
|
|
23
|
-
hubDrawnRate: string;
|
|
24
|
-
convertToShares: string;
|
|
25
|
-
convertToAssets: string;
|
|
26
|
-
user: EthAddress;
|
|
27
|
-
userSuppliedAssets: string;
|
|
28
|
-
userSuppliedShares: string;
|
|
29
|
-
}
|
|
12
|
+
export type { AaveV4TokenizationSpokeData, AaveV4TokenizationSpokeDataParsed } from '../types/aaveV4';
|
|
30
13
|
|
|
31
14
|
export const AAVE_V4_TOKENIZED_SPOKES: Record<string, EthAddress> = {
|
|
32
15
|
EURC_CORE: '0x6D9e2Cdd61CaF69af99b275704B6e272C41c6718',
|
|
@@ -102,34 +85,6 @@ export const aaveV4GetTokenizedVaultAddress = (
|
|
|
102
85
|
return AAVE_V4_TOKENIZED_SPOKES[key];
|
|
103
86
|
};
|
|
104
87
|
|
|
105
|
-
/** Parsed tokenization spoke data with human-readable supplied amounts for display */
|
|
106
|
-
export interface AaveV4TokenizationSpokeDataParsed {
|
|
107
|
-
vaultAddress: EthAddress;
|
|
108
|
-
key: string | null;
|
|
109
|
-
symbol: string;
|
|
110
|
-
hubKey: string;
|
|
111
|
-
// ---- Spoke ----
|
|
112
|
-
spokeActive: boolean;
|
|
113
|
-
spokeHalted: boolean;
|
|
114
|
-
/** Deposit cap in asset units (wei string) */
|
|
115
|
-
spokeDepositCap: string;
|
|
116
|
-
/** Total assets currently in spoke in asset units (wei string) */
|
|
117
|
-
spokeTotalAssets: string;
|
|
118
|
-
// ---- Hub ----
|
|
119
|
-
/** Available hub liquidity in asset units (wei string) */
|
|
120
|
-
hubLiquidity: string;
|
|
121
|
-
/** The conversion rate from assets to shares expressed in asset units. */
|
|
122
|
-
convertToShares: string;
|
|
123
|
-
// ---- User ----
|
|
124
|
-
userSuppliedAssetsEth: string;
|
|
125
|
-
userSuppliedSharesEth: string;
|
|
126
|
-
userSuppliedAssets: string;
|
|
127
|
-
userSuppliedShares: string;
|
|
128
|
-
underlyingAsset: EthAddress;
|
|
129
|
-
spoke: EthAddress;
|
|
130
|
-
decimals: number;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
88
|
const AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY: Record<string, string> = Object.entries(
|
|
134
89
|
AAVE_V4_TOKENIZED_SPOKES,
|
|
135
90
|
).reduce((acc, [k, v]) => {
|
|
@@ -189,4 +144,3 @@ export async function getAaveV4TokenizationSpokesData(
|
|
|
189
144
|
}).filter(item => item != null);
|
|
190
145
|
}
|
|
191
146
|
|
|
192
|
-
|
package/src/aaveV4/merkl.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { aprToApy } from '../moneymarket';
|
|
3
|
-
import {
|
|
3
|
+
import { fetchMerklOpportunities } from '../services/merkl';
|
|
4
4
|
import {
|
|
5
5
|
AaveV4MerklRewardMap,
|
|
6
6
|
AaveV4MerklIncentive,
|
|
@@ -46,7 +46,11 @@ const buildIncentive = (opportunity: MerklOpportunity): IncentiveData => {
|
|
|
46
46
|
};
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* `asOfTimestamp` (unix seconds, defaults to now) decides which of an opportunity's campaigns count
|
|
51
|
+
* as running, so historical opportunity lists are judged at their own moment rather than today's.
|
|
52
|
+
*/
|
|
53
|
+
export const buildAaveV4MerklRewardMap = (opportunities: MerklOpportunity[], chainId: NetworkNumber, asOfTimestamp: number = Date.now() / 1000): AaveV4MerklRewardMap => {
|
|
50
54
|
const result: AaveV4MerklRewardMap = { hub: {}, spoke: {} };
|
|
51
55
|
|
|
52
56
|
const endByCampaignId: Record<string, number> = {};
|
|
@@ -64,7 +68,7 @@ export const buildAaveV4MerklRewardMap = (opportunities: MerklOpportunity[], cha
|
|
|
64
68
|
.filter((o) => typeof o.type === 'string' && o.type.startsWith('AAVE_V4_'))
|
|
65
69
|
.forEach((o) => {
|
|
66
70
|
const side = o.action === OpportunityAction.BORROW ? IncentiveSide.Borrow : IncentiveSide.Supply;
|
|
67
|
-
const now =
|
|
71
|
+
const now = asOfTimestamp;
|
|
68
72
|
const methods = o.campaigns
|
|
69
73
|
?.filter((c) => (c.startTimestamp === undefined || c.startTimestamp <= now)
|
|
70
74
|
&& (c.endTimestamp === undefined || c.endTimestamp > now))
|
|
@@ -136,15 +140,20 @@ export const buildAaveV4MerklRewardMap = (opportunities: MerklOpportunity[], cha
|
|
|
136
140
|
return result;
|
|
137
141
|
};
|
|
138
142
|
|
|
139
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Live Aave V4 Merkl reward campaigns for the chain, split by hub/spoke scope. With `asOfTimestamp`
|
|
145
|
+
* (unix seconds) the campaigns and APRs are the ones Merkl had at that moment instead.
|
|
146
|
+
*/
|
|
147
|
+
export const getAaveV4MerkleCampaigns = async (chainId: NetworkNumber, asOfTimestamp?: number): Promise<AaveV4MerklRewardMap> => {
|
|
140
148
|
try {
|
|
141
|
-
const opportunities = await
|
|
149
|
+
const opportunities = await fetchMerklOpportunities({
|
|
142
150
|
mainProtocolId: 'aave',
|
|
151
|
+
chainId: chainId.toString(),
|
|
143
152
|
type: 'AAVE_V4_HUB_SUPPLY,AAVE_V4_HUB_BORROW,AAVE_V4_SPOKE_SUPPLY,AAVE_V4_SPOKE_BORROW,AAVE_V4_HUB_NET_LENDING,AAVE_V4_HUB_NET_BORROWING,AAVE_V4_SPOKE_NET_LENDING,AAVE_V4_SPOKE_NET_BORROWING',
|
|
144
153
|
status: OpportunityStatus.LIVE,
|
|
145
154
|
campaigns: 'true',
|
|
146
|
-
});
|
|
147
|
-
return buildAaveV4MerklRewardMap(opportunities, chainId);
|
|
155
|
+
}, asOfTimestamp);
|
|
156
|
+
return buildAaveV4MerklRewardMap(opportunities, chainId, asOfTimestamp);
|
|
148
157
|
} catch (e) {
|
|
149
158
|
console.error('Failed to fetch Aave V4 Merkle campaigns', e);
|
|
150
159
|
return { hub: {}, spoke: {} };
|
package/src/claiming/aaveV3.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import Dec from 'decimal.js';
|
|
3
|
-
import { EthAddress, NetworkNumber } from '../types';
|
|
4
|
-
import {
|
|
3
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types';
|
|
4
|
+
import {
|
|
5
|
+
AaveRewardsClaimableToken, ClaimableToken, ClaimType, MerklRewardsClaimableToken,
|
|
6
|
+
} from '../types/claiming';
|
|
5
7
|
import {
|
|
6
8
|
AaveIncentiveDataProviderV3ContractViem,
|
|
7
9
|
AaveRewardsControllerViem,
|
|
8
10
|
} from '../contracts';
|
|
9
11
|
import { compareAddresses, getEthAmountForDecimals, LONGER_TIMEOUT } from '../services/utils';
|
|
12
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
10
13
|
import { getAaveUnderlyingSymbol } from '../helpers/aaveHelpers';
|
|
11
14
|
|
|
12
15
|
type AaveReward = {
|
|
@@ -37,9 +40,10 @@ export async function getUnclaimedRewardsForAllMarkets(
|
|
|
37
40
|
network: NetworkNumber,
|
|
38
41
|
walletAddress: EthAddress,
|
|
39
42
|
marketAddress: EthAddress,
|
|
40
|
-
|
|
43
|
+
blockNumber: Blockish = 'latest',
|
|
44
|
+
): Promise<AaveRewardsClaimableToken[]> {
|
|
41
45
|
const contract = AaveIncentiveDataProviderV3ContractViem(provider, network);
|
|
42
|
-
const tokensData = await contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
46
|
+
const tokensData = await contract.read.getUserReservesIncentivesData([marketAddress, walletAddress], setViemBlockNumber(blockNumber));
|
|
43
47
|
const allTokensDataArrays = tokensData.reduce((acc: any[], val) => {
|
|
44
48
|
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
45
49
|
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
@@ -54,7 +58,7 @@ export async function getUnclaimedRewardsForAllMarkets(
|
|
|
54
58
|
// reward can be any token like wstETH, but also aToken like aWETH
|
|
55
59
|
const aaveRewardsController = AaveRewardsControllerViem(provider, network);
|
|
56
60
|
const rewardsPerAAsset = await Promise.all(allATokens.map(
|
|
57
|
-
(token: string) => aaveRewardsController.read.getAllUserRewards([[token as EthAddress], walletAddress])));
|
|
61
|
+
(token: string) => aaveRewardsController.read.getAllUserRewards([[token as EthAddress], walletAddress], setViemBlockNumber(blockNumber))));
|
|
58
62
|
|
|
59
63
|
// match amounts to token symbol, parse decimal amounts
|
|
60
64
|
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
package/src/claiming/ethena.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { getAssetInfo } from '@defisaver/tokens';
|
|
|
2
2
|
import Dec from 'decimal.js';
|
|
3
3
|
import { getAddress } from 'viem';
|
|
4
4
|
import { EthAddress } from '../types/common';
|
|
5
|
-
import { ClaimType } from '../types/claiming';
|
|
5
|
+
import { ClaimType, EthenaAirdropClaimableToken } from '../types/claiming';
|
|
6
6
|
import { getEthAmountForDecimals } from '../services/utils';
|
|
7
7
|
|
|
8
8
|
export const fetchEthenaAirdropReward = async (address: EthAddress) => {
|
|
@@ -23,11 +23,11 @@ export const fetchEthenaAirdropReward = async (address: EthAddress) => {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]): Promise<Record<string,
|
|
26
|
+
export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]): Promise<Record<string, EthenaAirdropClaimableToken[]>> => {
|
|
27
27
|
const apiDataPromises = walletAddresses.map(address => fetchEthenaAirdropReward(address));
|
|
28
28
|
const apiDataArray = await Promise.all(apiDataPromises);
|
|
29
29
|
|
|
30
|
-
const results: Record<string,
|
|
30
|
+
const results: Record<string, EthenaAirdropClaimableToken[]> = {};
|
|
31
31
|
for (let i = 0; i < walletAddresses.length; i++) {
|
|
32
32
|
const walletAddress = walletAddresses[i];
|
|
33
33
|
const data = apiDataArray[i];
|
|
@@ -36,7 +36,7 @@ export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]):
|
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const processedRewards = [];
|
|
39
|
+
const processedRewards: EthenaAirdropClaimableToken[] = [];
|
|
40
40
|
const assetInfo = getAssetInfo('sENA');
|
|
41
41
|
|
|
42
42
|
const amount = getEthAmountForDecimals(data.events[0].awardAmount, assetInfo.decimals);
|
|
@@ -47,7 +47,7 @@ export const fetchEthenaAirdropRewards = async (walletAddresses: EthAddress[]):
|
|
|
47
47
|
underlyingSymbol: assetInfo.symbol,
|
|
48
48
|
amount,
|
|
49
49
|
claimType: ClaimType.ETHENA_AIRDROP,
|
|
50
|
-
tokenAddress: assetInfo.address,
|
|
50
|
+
tokenAddress: assetInfo.address as EthAddress,
|
|
51
51
|
walletAddress,
|
|
52
52
|
label: 'Ethena Airdrop',
|
|
53
53
|
});
|
package/src/claiming/king.ts
CHANGED
|
@@ -2,8 +2,11 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import { assetAmountInEth } from '@defisaver/tokens';
|
|
3
3
|
import { Client } from 'viem';
|
|
4
4
|
import { UUPSViem } from '../contracts';
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
Blockish, EthAddress, HexString, NetworkNumber,
|
|
7
|
+
} from '../types/common';
|
|
8
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
9
|
+
import { ClaimType, KingRewardsClaimableToken } from '../types/claiming';
|
|
7
10
|
|
|
8
11
|
export const fetchKingRewards = async (walletAddress: EthAddress) => {
|
|
9
12
|
try {
|
|
@@ -19,19 +22,19 @@ export const fetchKingRewards = async (walletAddress: EthAddress) => {
|
|
|
19
22
|
}
|
|
20
23
|
};
|
|
21
24
|
|
|
22
|
-
export const getKingRewards = async (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => {
|
|
25
|
+
export const getKingRewards = async (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[], blockNumber: Blockish = 'latest'): Promise<Record<string, KingRewardsClaimableToken[]>> => {
|
|
23
26
|
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
24
27
|
const apiDataPromises = walletAddresses.map(address => fetchKingRewards(address));
|
|
25
28
|
const apiDataArray = await Promise.all(apiDataPromises);
|
|
26
29
|
|
|
27
30
|
// Batch all contract calls using multicall
|
|
28
31
|
const contract = UUPSViem(provider, network);
|
|
29
|
-
const cumulativePromises = walletAddresses.map(address => contract.read.cumulativeClaimed([address]),
|
|
32
|
+
const cumulativePromises = walletAddresses.map(address => contract.read.cumulativeClaimed([address], setViemBlockNumber(blockNumber)),
|
|
30
33
|
);
|
|
31
34
|
const cumulativeResults = await Promise.all(cumulativePromises);
|
|
32
35
|
|
|
33
36
|
// Process results
|
|
34
|
-
const results: Record<string,
|
|
37
|
+
const results: Record<string, KingRewardsClaimableToken[]> = {};
|
|
35
38
|
|
|
36
39
|
for (let i = 0; i < walletAddresses.length; i++) {
|
|
37
40
|
const walletAddress = walletAddresses[i];
|