@defisaver/positions-sdk 2.1.169-custom-fetching-dev → 2.1.169-custom-fetching-3-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 +4 -3
- package/cjs/aaveV3/index.js +14 -10
- package/cjs/aaveV3/merkl.d.ts +5 -1
- package/cjs/aaveV3/merkl.js +8 -3
- package/cjs/aaveV4/index.d.ts +4 -3
- package/cjs/aaveV4/index.js +19 -16
- package/cjs/aaveV4/merkl.d.ts +10 -2
- package/cjs/aaveV4/merkl.js +15 -6
- package/cjs/claiming/aaveV3.d.ts +2 -2
- package/cjs/claiming/aaveV3.js +5 -4
- package/cjs/claiming/king.d.ts +2 -2
- package/cjs/claiming/king.js +3 -2
- package/cjs/claiming/spark.d.ts +3 -3
- 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 -22
- package/cjs/fluid/index.js +75 -72
- package/cjs/fluid/merkl.d.ts +5 -3
- package/cjs/fluid/merkl.js +11 -6
- package/cjs/liquity/index.d.ts +4 -4
- package/cjs/liquity/index.js +23 -23
- package/cjs/liquityV2/index.d.ts +10 -10
- package/cjs/liquityV2/index.js +59 -59
- 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/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.js +45 -40
- package/cjs/services/merkl.d.ts +36 -2
- package/cjs/services/merkl.js +142 -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/merkl.d.ts +18 -0
- package/cjs/types/portfolio.d.ts +2 -0
- package/cjs/umbrella/index.d.ts +2 -2
- 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 +4 -3
- package/esm/aaveV3/index.js +15 -11
- package/esm/aaveV3/merkl.d.ts +5 -1
- package/esm/aaveV3/merkl.js +9 -4
- package/esm/aaveV4/index.d.ts +4 -3
- package/esm/aaveV4/index.js +20 -17
- package/esm/aaveV4/merkl.d.ts +10 -2
- package/esm/aaveV4/merkl.js +16 -7
- package/esm/claiming/aaveV3.d.ts +2 -2
- package/esm/claiming/aaveV3.js +5 -4
- package/esm/claiming/king.d.ts +2 -2
- package/esm/claiming/king.js +3 -2
- package/esm/claiming/spark.d.ts +3 -3
- package/esm/claiming/spark.js +8 -7
- 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 -22
- package/esm/fluid/index.js +76 -73
- package/esm/fluid/merkl.d.ts +5 -3
- package/esm/fluid/merkl.js +12 -7
- package/esm/liquity/index.d.ts +4 -4
- package/esm/liquity/index.js +23 -23
- package/esm/liquityV2/index.d.ts +10 -10
- package/esm/liquityV2/index.js +60 -60
- 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/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.js +47 -42
- package/esm/services/merkl.d.ts +36 -2
- package/esm/services/merkl.js +136 -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/merkl.d.ts +18 -0
- package/esm/types/portfolio.d.ts +2 -0
- package/esm/umbrella/index.d.ts +2 -2
- package/esm/umbrella/index.js +5 -4
- package/package.json +1 -1
- package/src/aaveV2/index.ts +7 -7
- package/src/aaveV3/index.ts +15 -11
- package/src/aaveV3/merkl.ts +9 -4
- package/src/aaveV4/index.ts +19 -16
- package/src/aaveV4/merkl.ts +16 -7
- package/src/claiming/aaveV3.ts +5 -3
- package/src/claiming/king.ts +6 -3
- package/src/claiming/spark.ts +9 -6
- 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 +88 -70
- package/src/fluid/merkl.ts +12 -7
- package/src/liquity/index.ts +23 -23
- package/src/liquityV2/index.ts +64 -56
- package/src/llamaLend/index.ts +15 -13
- package/src/maker/index.ts +19 -16
- 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 +48 -41
- package/src/services/merkl.ts +152 -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/merkl.ts +20 -0
- package/src/types/portfolio.ts +2 -0
- package/src/umbrella/index.ts +6 -5
package/esm/aaveV2/index.js
CHANGED
|
@@ -19,14 +19,14 @@ import { EMPTY_AAVE_DATA } from '../aaveV3';
|
|
|
19
19
|
import { AAVE_V2 } from '../markets/aave';
|
|
20
20
|
import { aaveAnyGetAggregatedPositionData } from '../helpers/aaveHelpers';
|
|
21
21
|
import { getEthPrice } from '../services/priceService';
|
|
22
|
-
import { getViemProvider } from '../services/viem';
|
|
23
|
-
export const _getAaveV2MarketsData = (
|
|
22
|
+
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
23
|
+
export const _getAaveV2MarketsData = (provider_1, network_1, selectedMarket_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, selectedMarket_1, ...args_1], void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') {
|
|
24
24
|
const _addresses = selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
25
25
|
const loanInfoContract = AaveLoanInfoV2ContractViem(provider, network);
|
|
26
26
|
const marketAddress = selectedMarket.providerAddress;
|
|
27
27
|
const [loanInfo, ethPrice] = yield Promise.all([
|
|
28
|
-
loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses]),
|
|
29
|
-
getEthPrice(provider),
|
|
28
|
+
loanInfoContract.read.getFullTokensInfo([marketAddress, _addresses], setViemBlockNumber(blockNumber)),
|
|
29
|
+
getEthPrice(provider, blockNumber),
|
|
30
30
|
]);
|
|
31
31
|
const markets = loanInfo
|
|
32
32
|
.map((market, i) => ({
|
|
@@ -84,7 +84,7 @@ export const _getAaveV2MarketsData = (provider, network, selectedMarket) => __aw
|
|
|
84
84
|
});
|
|
85
85
|
return { assetsData: payload };
|
|
86
86
|
});
|
|
87
|
-
export const getAaveV2MarketsData = (
|
|
87
|
+
export const getAaveV2MarketsData = (provider_1, network_1, selectedMarket_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, selectedMarket_1, ...args_1], void 0, function* (provider, network, selectedMarket, blockNumber = 'latest') { return _getAaveV2MarketsData(getViemProvider(provider, network), network, selectedMarket, blockNumber); });
|
|
88
88
|
export const _getAaveV2AccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
89
|
var _a;
|
|
90
90
|
const balances = yield getAaveLikeBalances(provider, network, block, addressMapping, address, AAVE_V2, 'AaveLoanInfoV2');
|
|
@@ -97,14 +97,14 @@ export const _getAaveV2AccountBalances = (provider, network, block, addressMappi
|
|
|
97
97
|
return balances;
|
|
98
98
|
});
|
|
99
99
|
export const getAaveV2AccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () { return _getAaveV2AccountBalances(getViemProvider(provider, network), network, block, addressMapping, address); });
|
|
100
|
-
export const _getAaveV2AccountData = (
|
|
100
|
+
export const _getAaveV2AccountData = (provider_1, network_1, address_1, assetsData_1, market_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, assetsData_1, market_1, ...args_1], void 0, function* (provider, network, address, assetsData, market, blockNumber = 'latest') {
|
|
101
101
|
if (!address)
|
|
102
102
|
throw new Error('Address is required');
|
|
103
103
|
let payload = Object.assign(Object.assign({}, EMPTY_AAVE_DATA), { lastUpdated: Date.now() });
|
|
104
104
|
const loanInfoContract = AaveLoanInfoV2ContractViem(provider, network);
|
|
105
105
|
const marketAddress = market.providerAddress;
|
|
106
106
|
const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a)).address);
|
|
107
|
-
const loanInfo = yield loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses]);
|
|
107
|
+
const loanInfo = yield loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses], setViemBlockNumber(blockNumber));
|
|
108
108
|
const usedAssets = {};
|
|
109
109
|
loanInfo.forEach((_tokenInfo, i) => {
|
|
110
110
|
const asset = market.assets[i];
|
|
@@ -165,7 +165,7 @@ export const _getAaveV2AccountData = (provider, network, address, assetsData, ma
|
|
|
165
165
|
payload.totalInterestUsd = totalInterestUsd;
|
|
166
166
|
return payload;
|
|
167
167
|
});
|
|
168
|
-
export const getAaveV2AccountData = (
|
|
168
|
+
export const getAaveV2AccountData = (provider_1, network_1, address_1, assetsData_1, market_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, address_1, assetsData_1, market_1, ...args_1], void 0, function* (provider, network, address, assetsData, market, blockNumber = 'latest') { return _getAaveV2AccountData(getViemProvider(provider, network), network, address, assetsData, market, blockNumber); });
|
|
169
169
|
export const getAaveV2FullPositionData = (provider, network, address, market) => __awaiter(void 0, void 0, void 0, function* () {
|
|
170
170
|
const marketData = yield getAaveV2MarketsData(provider, network, market);
|
|
171
171
|
const positionData = yield getAaveV2AccountData(provider, network, address, marketData.assetsData, market);
|
package/esm/aaveV3/index.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ import { getMerkleCampaigns } from './merkl';
|
|
|
6
6
|
export declare const aaveV3EmodeCategoriesMapping: (extractedState: any, usedAssets: AaveV3UsedAssets) => {
|
|
7
7
|
[key: number]: EModeCategoryDataMapping;
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
export declare function
|
|
9
|
+
/** `blockTimestamp` (unix seconds) is the historical block's timestamp when already known; otherwise it is read from the block. */
|
|
10
|
+
export declare function _getAaveV3MarketData(provider: Client, network: NetworkNumber, market: AaveMarketInfo, blockNumber?: 'latest' | number, blockTimestamp?: number): Promise<AaveV3MarketData>;
|
|
11
|
+
export declare function getAaveV3MarketData(provider: EthereumProvider, network: NetworkNumber, market: AaveMarketInfo, blockNumber?: 'latest' | number, blockTimestamp?: number): Promise<AaveV3MarketData>;
|
|
11
12
|
export declare const EMPTY_AAVE_DATA: {
|
|
12
13
|
usedAssets: {};
|
|
13
14
|
suppliedUsd: string;
|
|
@@ -76,7 +77,7 @@ export declare const getAaveV3AccountData: (provider: EthereumProvider, network:
|
|
|
76
77
|
export declare const getAaveV3FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: AaveMarketInfo) => Promise<AaveV3PositionData>;
|
|
77
78
|
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"];
|
|
78
79
|
export declare const fetchYearlyMeritApyForStakingGho: () => Promise<string>;
|
|
79
|
-
export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress) => Promise<{
|
|
80
|
+
export declare const getStakeAaveData: (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber?: Blockish) => Promise<{
|
|
80
81
|
activatedCooldown: string;
|
|
81
82
|
activatedCooldownAmount: string;
|
|
82
83
|
stkAaveRewardsBalance: string;
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { aprToApy, calculateBorrowingAssetLimit } from '../moneymarket';
|
|
|
17
17
|
import { getWrappedNativeAssetFromUnwrapped, isEnabledOnBitmap, } from '../services/utils';
|
|
18
18
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
19
19
|
import { IncentiveKind, NetworkNumber, } from '../types/common';
|
|
20
|
-
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
20
|
+
import { getBlockTimestamp, getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
21
21
|
import { getMeritCampaigns } from './merit';
|
|
22
22
|
import { getAaveUnderlyingSymbol, getMerkleCampaigns } from './merkl';
|
|
23
23
|
import { getSghoData } from './sgho';
|
|
@@ -50,8 +50,9 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
50
50
|
});
|
|
51
51
|
return categoriesMapping;
|
|
52
52
|
};
|
|
53
|
+
/** `blockTimestamp` (unix seconds) is the historical block's timestamp when already known; otherwise it is read from the block. */
|
|
53
54
|
export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
54
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
55
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest', blockTimestamp) {
|
|
55
56
|
var _a;
|
|
56
57
|
const _addresses = market.assets.map(a => getAssetInfo(getWrappedNativeAssetFromUnwrapped(a), network).address);
|
|
57
58
|
const loanInfoContract = AaveV3ViewContractViem(provider, network);
|
|
@@ -64,12 +65,15 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
64
65
|
? Array.from({ length: Math.ceil(_addresses.length / addressesPerRequest) }, (_, index) => _addresses.slice(index * addressesPerRequest, (index + 1) * addressesPerRequest))
|
|
65
66
|
: [_addresses];
|
|
66
67
|
const loanInfoPromise = Promise.all(addressChunks.map((addresses) => loanInfoContract.read.getFullTokensInfo([marketAddress, addresses], setViemBlockNumber(blockNumber)))).then((loanInfoChunks) => loanInfoChunks.flat());
|
|
68
|
+
// Merkl rewards are keyed by time, so a historical block resolves to its timestamp first (one
|
|
69
|
+
// RPC call unless given, none for 'latest') and the rewards in force at that moment are attached.
|
|
70
|
+
const merkleRewardsPromise = getBlockTimestamp(provider, blockNumber, blockTimestamp).then((asOfTimestamp) => getMerkleCampaigns(network, asOfTimestamp));
|
|
67
71
|
// eslint-disable-next-line prefer-const
|
|
68
72
|
let [loanInfo, eModesInfo, rewardInfo, merkleRewardsMap, meritRewardsMap] = yield Promise.all([
|
|
69
73
|
loanInfoPromise,
|
|
70
74
|
loanInfoContract.read.getAllEmodes([marketAddress], setViemBlockNumber(blockNumber)),
|
|
71
75
|
networksWithIncentives.includes(network) ? aaveIncentivesContract.read.getReservesIncentivesData([marketAddress], setViemBlockNumber(blockNumber)) : null,
|
|
72
|
-
|
|
76
|
+
merkleRewardsPromise,
|
|
73
77
|
getMeritCampaigns(network, market.value),
|
|
74
78
|
]);
|
|
75
79
|
// same break logic as view contract
|
|
@@ -308,8 +312,8 @@ export function _getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
|
308
312
|
});
|
|
309
313
|
}
|
|
310
314
|
export function getAaveV3MarketData(provider_1, network_1, market_1) {
|
|
311
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
312
|
-
return _getAaveV3MarketData(getViemProvider(provider, network), network, market, blockNumber);
|
|
315
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest', blockTimestamp) {
|
|
316
|
+
return _getAaveV3MarketData(getViemProvider(provider, network), network, market, blockNumber, blockTimestamp);
|
|
313
317
|
});
|
|
314
318
|
}
|
|
315
319
|
export const EMPTY_AAVE_DATA = {
|
|
@@ -703,18 +707,18 @@ export const fetchYearlyMeritApyForStakingGho = () => __awaiter(void 0, void 0,
|
|
|
703
707
|
return '0';
|
|
704
708
|
}
|
|
705
709
|
});
|
|
706
|
-
export const getStakeAaveData = (
|
|
710
|
+
export const getStakeAaveData = (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') {
|
|
707
711
|
const stkGhoAddress = getAssetInfo('stkGHO').address;
|
|
708
712
|
const stkAaveAddress = getAssetInfo('stkAAVE').address;
|
|
709
713
|
const AaveIncentivesController = AaveIncentivesControllerViem(provider, network);
|
|
710
714
|
const stkAAVE = StkAAVEViem(provider, network);
|
|
711
715
|
const stkGHO = createViemContractFromConfigFunc('Erc20', stkGhoAddress)(provider, network);
|
|
712
716
|
const [aaveRewardsBalance, emissionsPerSecond, stkAAVEBalance, stkAAVETotalSupply, stkGHOBalance, ghoMeritApy, sgho] = yield Promise.all([
|
|
713
|
-
AaveIncentivesController.read.getRewardsBalance([REWARDABLE_ASSETS, address]),
|
|
714
|
-
stkAAVE.read.assets([stkAaveAddress]),
|
|
715
|
-
stkAAVE.read.balanceOf([address]),
|
|
716
|
-
stkAAVE.read.totalSupply(),
|
|
717
|
-
stkGHO.read.balanceOf([address]),
|
|
717
|
+
AaveIncentivesController.read.getRewardsBalance([REWARDABLE_ASSETS, address], setViemBlockNumber(blockNumber)),
|
|
718
|
+
stkAAVE.read.assets([stkAaveAddress], setViemBlockNumber(blockNumber)),
|
|
719
|
+
stkAAVE.read.balanceOf([address], setViemBlockNumber(blockNumber)),
|
|
720
|
+
stkAAVE.read.totalSupply(setViemBlockNumber(blockNumber)),
|
|
721
|
+
stkGHO.read.balanceOf([address], setViemBlockNumber(blockNumber)),
|
|
718
722
|
fetchYearlyMeritApyForStakingGho(),
|
|
719
723
|
getSghoData(network, address),
|
|
720
724
|
]);
|
package/esm/aaveV3/merkl.d.ts
CHANGED
|
@@ -5,4 +5,8 @@ export declare const getAaveUnderlyingSymbol: (_symbol?: string) => string;
|
|
|
5
5
|
* USDC -> USDC
|
|
6
6
|
*/
|
|
7
7
|
export declare const formatAaveAsset: (_symbol: string) => string;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Live Merkl reward campaigns for Aave V3 on the chain, keyed by aToken. With `asOfTimestamp` (unix
|
|
10
|
+
* seconds) the campaigns and APRs are the ones Merkl had at that moment instead.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getMerkleCampaigns: (chainId: NetworkNumber, asOfTimestamp?: number) => Promise<MerkleRewardMap>;
|
package/esm/aaveV3/merkl.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { aprToApy } from '../moneymarket';
|
|
11
|
-
import {
|
|
11
|
+
import { fetchMerklOpportunities } from '../services/merkl';
|
|
12
12
|
import { wethToEth } from '../services/utils';
|
|
13
13
|
import { OpportunityAction, OpportunityStatus, } from '../types';
|
|
14
14
|
export const getAaveUnderlyingSymbol = (_symbol = '') => {
|
|
@@ -34,12 +34,17 @@ export const formatAaveAsset = (_symbol) => {
|
|
|
34
34
|
}
|
|
35
35
|
return _symbol;
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Live Merkl reward campaigns for Aave V3 on the chain, keyed by aToken. With `asOfTimestamp` (unix
|
|
39
|
+
* seconds) the campaigns and APRs are the ones Merkl had at that moment instead.
|
|
40
|
+
*/
|
|
41
|
+
export const getMerkleCampaigns = (chainId, asOfTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
42
|
try {
|
|
39
|
-
const opportunities = yield
|
|
43
|
+
const opportunities = yield fetchMerklOpportunities({
|
|
40
44
|
mainProtocolId: 'aave',
|
|
45
|
+
chainId: chainId.toString(),
|
|
41
46
|
status: OpportunityStatus.LIVE,
|
|
42
|
-
});
|
|
47
|
+
}, asOfTimestamp);
|
|
43
48
|
const relevantOpportunities = opportunities
|
|
44
49
|
.filter((o) => o.chainId === chainId)
|
|
45
50
|
.filter((o) => o.status === OpportunityStatus.LIVE);
|
package/esm/aaveV4/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import { Client } from 'viem';
|
|
|
2
2
|
import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo, EthAddress, EthereumProvider, NetworkNumber, Blockish, PositionBalances } from '../types';
|
|
3
3
|
export * as lend from './lend';
|
|
4
4
|
export { getAaveV4MerkleCampaigns } from './merkl';
|
|
5
|
-
|
|
6
|
-
export declare function
|
|
5
|
+
/** `blockTimestamp` (unix seconds) is the historical block's timestamp when already known; otherwise it is read from the block. */
|
|
6
|
+
export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number, blockTimestamp?: number): Promise<AaveV4SpokeData>;
|
|
7
|
+
export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number, blockTimestamp?: number): Promise<AaveV4SpokeData>;
|
|
7
8
|
export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
|
|
8
9
|
/** Shared raw read; no spoke metadata or market enrichment. */
|
|
9
10
|
export declare const _getAaveV4LoanBalances: (provider: Client, network: NetworkNumber, block: Blockish, address: EthAddress, spoke: EthAddress) => Promise<{
|
|
@@ -39,4 +40,4 @@ export declare const _getAaveV4AccountHasAnyBalance: (provider: Client, network:
|
|
|
39
40
|
export declare function getAaveV4AccountData(provider: EthereumProvider, network: NetworkNumber, marketData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<any>;
|
|
40
41
|
export declare const _getAaveV4AccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, spokeAddress: EthAddress, spokeData?: AaveV4SpokeData) => Promise<PositionBalances>;
|
|
41
42
|
export declare const getAaveV4AccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, spokeAddress: EthAddress, spokeData?: AaveV4SpokeData) => Promise<PositionBalances>;
|
|
42
|
-
export declare function getAaveV4UnderlyingFromReserveId(provider: EthereumProvider, network: NetworkNumber, spoke: EthAddress, reserveId: number): Promise<any>;
|
|
43
|
+
export declare function getAaveV4UnderlyingFromReserveId(provider: EthereumProvider, network: NetworkNumber, spoke: EthAddress, reserveId: number, blockNumber?: Blockish): Promise<any>;
|
package/esm/aaveV4/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, assetAmountInWei, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
12
|
-
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
12
|
+
import { getBlockTimestamp, getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
13
13
|
import { IncentiveKind, } from '../types';
|
|
14
14
|
import { AaveV4ViewContractViem } from '../contracts';
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
@@ -20,8 +20,8 @@ import { aprToApy } from '../moneymarket';
|
|
|
20
20
|
import { attachAaveV4MerklIncentives, getAaveV4MerkleCampaigns } from './merkl';
|
|
21
21
|
export * as lend from './lend';
|
|
22
22
|
export { getAaveV4MerkleCampaigns } from './merkl';
|
|
23
|
-
const fetchHubData = (
|
|
24
|
-
const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress]);
|
|
23
|
+
const fetchHubData = (viewContract_1, hubAddress_1, ...args_1) => __awaiter(void 0, [viewContract_1, hubAddress_1, ...args_1], void 0, function* (viewContract, hubAddress, blockNumber = 'latest') {
|
|
24
|
+
const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress], setViemBlockNumber(blockNumber));
|
|
25
25
|
return {
|
|
26
26
|
assets: hubData.reduce((acc, assetOnChainData) => {
|
|
27
27
|
acc[assetOnChainData.assetId] = {
|
|
@@ -143,18 +143,21 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
|
|
|
143
143
|
liquidityFee: liquidityFee.toString(),
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
|
+
/** `blockTimestamp` (unix seconds) is the historical block's timestamp when already known; otherwise it is read from the block. */
|
|
146
147
|
export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
147
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest') {
|
|
148
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, market, blockNumber = 'latest', blockTimestamp) {
|
|
148
149
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
149
150
|
const hubsData = {};
|
|
150
151
|
const loadHubData = (hubAddress) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
hubsData[hubAddress.toLowerCase()] = yield fetchHubData(viewContract, hubAddress);
|
|
152
|
+
hubsData[hubAddress.toLowerCase()] = yield fetchHubData(viewContract, hubAddress, blockNumber);
|
|
152
153
|
});
|
|
153
154
|
// market.hubs is only a prefetch hint (lets known hubs load in parallel with the spoke data), so
|
|
154
155
|
// failures are tolerated here — any hub the reserves actually reference is (re)fetched below.
|
|
155
156
|
const [spokeData, merklCampaigns] = yield Promise.all([
|
|
156
|
-
viewContract.read.getSpokeDataFull([market.address]),
|
|
157
|
-
|
|
157
|
+
viewContract.read.getSpokeDataFull([market.address], setViemBlockNumber(blockNumber)),
|
|
158
|
+
// Merkl rewards are keyed by time: a historical block resolves to its timestamp first (one RPC
|
|
159
|
+
// call unless given, none for 'latest') so the rewards in force at that moment are attached.
|
|
160
|
+
getBlockTimestamp(provider, blockNumber, blockTimestamp).then((asOfTimestamp) => getAaveV4MerkleCampaigns(network, asOfTimestamp)),
|
|
158
161
|
...market.hubs.map((hubAddress) => loadHubData(hubAddress).catch(() => { })),
|
|
159
162
|
]);
|
|
160
163
|
// The on-chain reserves are the source of truth for which hubs the spoke uses — fetch any hub
|
|
@@ -184,14 +187,14 @@ export function _getAaveV4SpokeData(provider_1, network_1, market_1) {
|
|
|
184
187
|
});
|
|
185
188
|
}
|
|
186
189
|
export function getAaveV4SpokeData(provider_1, network_1, spoke_1) {
|
|
187
|
-
return __awaiter(this, arguments, void 0, function* (provider, network, spoke, blockNumber = 'latest') {
|
|
188
|
-
return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber);
|
|
190
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, spoke, blockNumber = 'latest', blockTimestamp) {
|
|
191
|
+
return _getAaveV4SpokeData(getViemProvider(provider, network), network, spoke, blockNumber, blockTimestamp);
|
|
189
192
|
});
|
|
190
193
|
}
|
|
191
194
|
export function _getAaveV4AccountData(provider_1, network_1, spokeData_1, address_1) {
|
|
192
195
|
return __awaiter(this, arguments, void 0, function* (provider, network, spokeData, address, blockNumber = 'latest') {
|
|
193
196
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
194
|
-
const loanData = yield viewContract.read.getLoanData([spokeData.address, address]);
|
|
197
|
+
const loanData = yield viewContract.read.getLoanData([spokeData.address, address], setViemBlockNumber(blockNumber));
|
|
195
198
|
const healthFactorFromContract = new Dec(loanData.healthFactor.toString());
|
|
196
199
|
const healthFactor = isMaxUint(healthFactorFromContract.toString()) ? 'Infinity' : healthFactorFromContract.div(1e18).toString();
|
|
197
200
|
const usedAssets = loanData.reserves.reduce((acc, usedReserveAsset) => {
|
|
@@ -263,7 +266,7 @@ export const _getAaveV4AccountHasAnyBalance = (provider, network, block, address
|
|
|
263
266
|
return false;
|
|
264
267
|
const blockNumber = block === 'latest' ? 'latest' : Number(block);
|
|
265
268
|
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
266
|
-
const loanData = yield viewContract.read.getLoanData([spokeAddress, address]);
|
|
269
|
+
const loanData = yield viewContract.read.getLoanData([spokeAddress, address], setViemBlockNumber(blockNumber));
|
|
267
270
|
const reserves = (loanData === null || loanData === void 0 ? void 0 : loanData.reserves) || [];
|
|
268
271
|
return reserves.some((reserveAsset) => {
|
|
269
272
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
@@ -315,13 +318,13 @@ export const _getAaveV4AccountBalances = (provider, network, block, addressMappi
|
|
|
315
318
|
export const getAaveV4AccountBalances = (provider, network, block, addressMapping, address, spokeAddress, spokeData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
316
319
|
return _getAaveV4AccountBalances(getViemProvider(provider, network), network, block, addressMapping, address, spokeAddress, spokeData);
|
|
317
320
|
});
|
|
318
|
-
const _getAaveV4UnderlyingFromReserveId = (
|
|
319
|
-
const viewContract = AaveV4ViewContractViem(provider, network);
|
|
320
|
-
const reserveData = yield viewContract.read.getReserveData([spoke, BigInt(reserveId)]);
|
|
321
|
+
const _getAaveV4UnderlyingFromReserveId = (provider_1, network_1, spoke_1, reserveId_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, spoke_1, reserveId_1, ...args_1], void 0, function* (provider, network, spoke, reserveId, blockNumber = 'latest') {
|
|
322
|
+
const viewContract = AaveV4ViewContractViem(provider, network, blockNumber);
|
|
323
|
+
const reserveData = yield viewContract.read.getReserveData([spoke, BigInt(reserveId)], setViemBlockNumber(blockNumber));
|
|
321
324
|
return reserveData.underlying;
|
|
322
325
|
});
|
|
323
|
-
export function getAaveV4UnderlyingFromReserveId(
|
|
324
|
-
return __awaiter(this,
|
|
325
|
-
return _getAaveV4UnderlyingFromReserveId(getViemProvider(provider, network), network, spoke, reserveId);
|
|
326
|
+
export function getAaveV4UnderlyingFromReserveId(provider_1, network_1, spoke_1, reserveId_1) {
|
|
327
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, spoke, reserveId, blockNumber = 'latest') {
|
|
328
|
+
return _getAaveV4UnderlyingFromReserveId(getViemProvider(provider, network), network, spoke, reserveId, blockNumber);
|
|
326
329
|
});
|
|
327
330
|
}
|
package/esm/aaveV4/merkl.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { AaveV4MerklRewardMap, AaveV4ReserveAssetData, MerklOpportunity, NetworkNumber } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* `asOfTimestamp` (unix seconds, defaults to now) decides which of an opportunity's campaigns count
|
|
4
|
+
* as running, so historical opportunity lists are judged at their own moment rather than today's.
|
|
5
|
+
*/
|
|
6
|
+
export declare const buildAaveV4MerklRewardMap: (opportunities: MerklOpportunity[], chainId: NetworkNumber, asOfTimestamp?: number) => AaveV4MerklRewardMap;
|
|
7
|
+
/**
|
|
8
|
+
* Live Aave V4 Merkl reward campaigns for the chain, split by hub/spoke scope. With `asOfTimestamp`
|
|
9
|
+
* (unix seconds) the campaigns and APRs are the ones Merkl had at that moment instead.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getAaveV4MerkleCampaigns: (chainId: NetworkNumber, asOfTimestamp?: number) => Promise<AaveV4MerklRewardMap>;
|
|
4
12
|
/**
|
|
5
13
|
* Returns a copy of the asset with scope-specific incentive arrays pre-combined with the asset's
|
|
6
14
|
* intrinsic (staking) incentives, so each surface can render base yield + the rewards that apply to it.
|
package/esm/aaveV4/merkl.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { aprToApy } from '../moneymarket';
|
|
12
|
-
import {
|
|
12
|
+
import { fetchMerklOpportunities } from '../services/merkl';
|
|
13
13
|
import { IncentiveKind, IncentiveSide, IncentiveSource, OpportunityAction, OpportunityStatus, } from '../types';
|
|
14
14
|
/**
|
|
15
15
|
* Merkl tags Aave V4 reward campaigns by scope via the `type` field:
|
|
@@ -39,7 +39,11 @@ const buildIncentive = (opportunity) => {
|
|
|
39
39
|
description: opportunity.description || `Eligible for ${token} rewards through Merkl.`,
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* `asOfTimestamp` (unix seconds, defaults to now) decides which of an opportunity's campaigns count
|
|
44
|
+
* as running, so historical opportunity lists are judged at their own moment rather than today's.
|
|
45
|
+
*/
|
|
46
|
+
export const buildAaveV4MerklRewardMap = (opportunities, chainId, asOfTimestamp = Date.now() / 1000) => {
|
|
43
47
|
const result = { hub: {}, spoke: {} };
|
|
44
48
|
const endByCampaignId = {};
|
|
45
49
|
opportunities.forEach((o) => {
|
|
@@ -57,7 +61,7 @@ export const buildAaveV4MerklRewardMap = (opportunities, chainId) => {
|
|
|
57
61
|
.forEach((o) => {
|
|
58
62
|
var _a, _b, _c;
|
|
59
63
|
const side = o.action === OpportunityAction.BORROW ? IncentiveSide.Borrow : IncentiveSide.Supply;
|
|
60
|
-
const now =
|
|
64
|
+
const now = asOfTimestamp;
|
|
61
65
|
const methods = (_a = o.campaigns) === null || _a === void 0 ? void 0 : _a.filter((c) => (c.startTimestamp === undefined || c.startTimestamp <= now)
|
|
62
66
|
&& (c.endTimestamp === undefined || c.endTimestamp > now)).map((c) => { var _a, _b; return (_b = (_a = c.params) === null || _a === void 0 ? void 0 : _a.distributionMethodParameters) === null || _b === void 0 ? void 0 : _b.distributionMethod; });
|
|
63
67
|
// An opportunity-level APR cannot be split between simultaneous net and additive campaigns.
|
|
@@ -135,15 +139,20 @@ export const buildAaveV4MerklRewardMap = (opportunities, chainId) => {
|
|
|
135
139
|
});
|
|
136
140
|
return result;
|
|
137
141
|
};
|
|
138
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Live Aave V4 Merkl reward campaigns for the chain, split by hub/spoke scope. With `asOfTimestamp`
|
|
144
|
+
* (unix seconds) the campaigns and APRs are the ones Merkl had at that moment instead.
|
|
145
|
+
*/
|
|
146
|
+
export const getAaveV4MerkleCampaigns = (chainId, asOfTimestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
147
|
try {
|
|
140
|
-
const opportunities = yield
|
|
148
|
+
const opportunities = yield fetchMerklOpportunities({
|
|
141
149
|
mainProtocolId: 'aave',
|
|
150
|
+
chainId: chainId.toString(),
|
|
142
151
|
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',
|
|
143
152
|
status: OpportunityStatus.LIVE,
|
|
144
153
|
campaigns: 'true',
|
|
145
|
-
});
|
|
146
|
-
return buildAaveV4MerklRewardMap(opportunities, chainId);
|
|
154
|
+
}, asOfTimestamp);
|
|
155
|
+
return buildAaveV4MerklRewardMap(opportunities, chainId, asOfTimestamp);
|
|
147
156
|
}
|
|
148
157
|
catch (e) {
|
|
149
158
|
console.error('Failed to fetch Aave V4 Merkle campaigns', e);
|
package/esm/claiming/aaveV3.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { EthAddress, NetworkNumber } from '../types';
|
|
2
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types';
|
|
3
3
|
import { ClaimableToken, MerklRewardsClaimableToken } from '../types/claiming';
|
|
4
|
-
export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress): Promise<ClaimableToken[]>;
|
|
4
|
+
export declare function getUnclaimedRewardsForAllMarkets(provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress, blockNumber?: Blockish): Promise<ClaimableToken[]>;
|
|
5
5
|
export declare function getMerklUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<MerklRewardsClaimableToken[]>;
|
|
6
6
|
export declare function getMeritUnclaimedRewards(account: EthAddress, network: NetworkNumber): Promise<ClaimableToken[]>;
|
package/esm/claiming/aaveV3.js
CHANGED
|
@@ -11,6 +11,7 @@ import Dec from 'decimal.js';
|
|
|
11
11
|
import { ClaimType } from '../types/claiming';
|
|
12
12
|
import { AaveIncentiveDataProviderV3ContractViem, AaveRewardsControllerViem, } from '../contracts';
|
|
13
13
|
import { compareAddresses, getEthAmountForDecimals, LONGER_TIMEOUT } from '../services/utils';
|
|
14
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
14
15
|
import { getAaveUnderlyingSymbol } from '../helpers/aaveHelpers';
|
|
15
16
|
const mapAaveRewardsToClaimableTokens = (aaveRewards, marketAddress, walletAddress) => aaveRewards.map(reward => ({
|
|
16
17
|
symbol: reward.symbol,
|
|
@@ -26,10 +27,10 @@ const mapAaveRewardsToClaimableTokens = (aaveRewards, marketAddress, walletAddre
|
|
|
26
27
|
isAaveToken: reward.symbol.startsWith('a'),
|
|
27
28
|
},
|
|
28
29
|
}));
|
|
29
|
-
export function getUnclaimedRewardsForAllMarkets(
|
|
30
|
-
return __awaiter(this,
|
|
30
|
+
export function getUnclaimedRewardsForAllMarkets(provider_1, network_1, walletAddress_1, marketAddress_1) {
|
|
31
|
+
return __awaiter(this, arguments, void 0, function* (provider, network, walletAddress, marketAddress, blockNumber = 'latest') {
|
|
31
32
|
const contract = AaveIncentiveDataProviderV3ContractViem(provider, network);
|
|
32
|
-
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
33
|
+
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress], setViemBlockNumber(blockNumber));
|
|
33
34
|
const allTokensDataArrays = tokensData.reduce((acc, val) => {
|
|
34
35
|
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
35
36
|
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
@@ -43,7 +44,7 @@ export function getUnclaimedRewardsForAllMarkets(provider, network, walletAddres
|
|
|
43
44
|
// array of rewards for each market (aToken/vToken)
|
|
44
45
|
// reward can be any token like wstETH, but also aToken like aWETH
|
|
45
46
|
const aaveRewardsController = AaveRewardsControllerViem(provider, network);
|
|
46
|
-
const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => aaveRewardsController.read.getAllUserRewards([[token], walletAddress])));
|
|
47
|
+
const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => aaveRewardsController.read.getAllUserRewards([[token], walletAddress], setViemBlockNumber(blockNumber))));
|
|
47
48
|
// match amounts to token symbol, parse decimal amounts
|
|
48
49
|
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
|
49
50
|
const rewardsList = rewardForAAsset[0];
|
package/esm/claiming/king.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { EthAddress, NetworkNumber } from '../types/common';
|
|
2
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
export declare const fetchKingRewards: (walletAddress: EthAddress) => Promise<any>;
|
|
4
|
-
export declare const getKingRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, any[]>>;
|
|
4
|
+
export declare const getKingRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[], blockNumber?: Blockish) => Promise<Record<string, any[]>>;
|
package/esm/claiming/king.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth } from '@defisaver/tokens';
|
|
12
12
|
import { UUPSViem } from '../contracts';
|
|
13
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
13
14
|
import { ClaimType } from '../types/claiming';
|
|
14
15
|
export const fetchKingRewards = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
16
|
try {
|
|
@@ -23,13 +24,13 @@ export const fetchKingRewards = (walletAddress) => __awaiter(void 0, void 0, voi
|
|
|
23
24
|
return { Amount: '0', Root: '', Proofs: [] };
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
|
-
export const getKingRewards = (
|
|
27
|
+
export const getKingRewards = (provider_1, network_1, walletAddresses_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, walletAddresses_1, ...args_1], void 0, function* (provider, network, walletAddresses, blockNumber = 'latest') {
|
|
27
28
|
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
28
29
|
const apiDataPromises = walletAddresses.map(address => fetchKingRewards(address));
|
|
29
30
|
const apiDataArray = yield Promise.all(apiDataPromises);
|
|
30
31
|
// Batch all contract calls using multicall
|
|
31
32
|
const contract = UUPSViem(provider, network);
|
|
32
|
-
const cumulativePromises = walletAddresses.map(address => contract.read.cumulativeClaimed([address]));
|
|
33
|
+
const cumulativePromises = walletAddresses.map(address => contract.read.cumulativeClaimed([address], setViemBlockNumber(blockNumber)));
|
|
33
34
|
const cumulativeResults = yield Promise.all(cumulativePromises);
|
|
34
35
|
// Process results
|
|
35
36
|
const results = {};
|
package/esm/claiming/spark.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { EthAddress, NetworkNumber } from '../types/common';
|
|
2
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { SparkRewardsClaimableToken } from '../types/claiming';
|
|
4
4
|
export declare const fetchSpkAirdropRewards: (walletAddress: EthAddress) => Promise<any>;
|
|
5
|
-
export declare const fetchSparkAirdropRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, any[]>>;
|
|
6
|
-
export declare const fetchSparkRewards: (provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress) => Promise<SparkRewardsClaimableToken[]>;
|
|
5
|
+
export declare const fetchSparkAirdropRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[], blockNumber?: Blockish) => Promise<Record<string, any[]>>;
|
|
6
|
+
export declare const fetchSparkRewards: (provider: Client, network: NetworkNumber, walletAddress: EthAddress, marketAddress: EthAddress, blockNumber?: Blockish) => Promise<SparkRewardsClaimableToken[]>;
|
package/esm/claiming/spark.js
CHANGED
|
@@ -12,6 +12,7 @@ import Dec from 'decimal.js';
|
|
|
12
12
|
import { createViemContractFromConfigFunc, SparkIncentiveDataProviderContractViem, SparkRewardsControllerViem, } from '../contracts';
|
|
13
13
|
import { ClaimType, SparkAirdropType } from '../types/claiming';
|
|
14
14
|
import { compareAddresses, getEthAmountForDecimals } from '../services/utils';
|
|
15
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
15
16
|
const IGNITION_REWARDS = '0xCBA0C0a2a0B6Bb11233ec4EA85C5bFfea33e724d';
|
|
16
17
|
const PFL3_REWARDS = '0x7ac96180C4d6b2A328D3a19ac059D0E7Fc3C6d41';
|
|
17
18
|
export const fetchSpkAirdropRewards = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -26,17 +27,17 @@ export const fetchSpkAirdropRewards = (walletAddress) => __awaiter(void 0, void
|
|
|
26
27
|
return [];
|
|
27
28
|
}
|
|
28
29
|
});
|
|
29
|
-
const getCumulativeClaimedSpkAirdrop = (
|
|
30
|
+
const getCumulativeClaimedSpkAirdrop = (provider_1, network_1, data_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, data_1, ...args_1], void 0, function* (provider, network, data, blockNumber = 'latest') {
|
|
30
31
|
const contractIgnition = createViemContractFromConfigFunc('SparkAirdrop', IGNITION_REWARDS)(provider, network);
|
|
31
32
|
const contractPFL = createViemContractFromConfigFunc('SparkAirdrop', PFL3_REWARDS)(provider, network);
|
|
32
33
|
const cumulativeAmounts = yield Promise.all(data.map((airdrop) => {
|
|
33
34
|
const { user, tokenAddress, epoch, type, } = airdrop;
|
|
34
35
|
const contract = type === SparkAirdropType.SPARK_IGNITION ? contractIgnition : contractPFL;
|
|
35
|
-
return contract.read.cumulativeClaimed([user, tokenAddress, BigInt(epoch)]);
|
|
36
|
+
return contract.read.cumulativeClaimed([user, tokenAddress, BigInt(epoch)], setViemBlockNumber(blockNumber));
|
|
36
37
|
}));
|
|
37
38
|
return cumulativeAmounts.map((amount, i) => assetAmountInEth(amount.toString(), getAssetInfoByAddress(data[i].tokenAddress).symbol).toString());
|
|
38
39
|
});
|
|
39
|
-
export const fetchSparkAirdropRewards = (
|
|
40
|
+
export const fetchSparkAirdropRewards = (provider_1, network_1, walletAddresses_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, walletAddresses_1, ...args_1], void 0, function* (provider, network, walletAddresses, blockNumber = 'latest') {
|
|
40
41
|
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
41
42
|
const apiDataPromises = walletAddresses.map(address => fetchSpkAirdropRewards(address));
|
|
42
43
|
const apiDataArray = yield Promise.all(apiDataPromises);
|
|
@@ -67,7 +68,7 @@ export const fetchSparkAirdropRewards = (provider, network, walletAddresses) =>
|
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
// Batch all contract calls
|
|
70
|
-
const cumulativeClaimedAmounts = yield getCumulativeClaimedSpkAirdrop(provider, network, contractCallsData);
|
|
71
|
+
const cumulativeClaimedAmounts = yield getCumulativeClaimedSpkAirdrop(provider, network, contractCallsData, blockNumber);
|
|
71
72
|
// Process results
|
|
72
73
|
const results = {};
|
|
73
74
|
let contractCallIndex = 0;
|
|
@@ -106,9 +107,9 @@ export const fetchSparkAirdropRewards = (provider, network, walletAddresses) =>
|
|
|
106
107
|
}
|
|
107
108
|
return results;
|
|
108
109
|
});
|
|
109
|
-
export const fetchSparkRewards = (
|
|
110
|
+
export const fetchSparkRewards = (provider_1, network_1, walletAddress_1, marketAddress_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, walletAddress_1, marketAddress_1, ...args_1], void 0, function* (provider, network, walletAddress, marketAddress, blockNumber = 'latest') {
|
|
110
111
|
const contract = SparkIncentiveDataProviderContractViem(provider, network);
|
|
111
|
-
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress]);
|
|
112
|
+
const tokensData = yield contract.read.getUserReservesIncentivesData([marketAddress, walletAddress], setViemBlockNumber(blockNumber));
|
|
112
113
|
const allTokensDataArrays = tokensData.reduce((acc, val) => {
|
|
113
114
|
acc.push(val.aTokenIncentivesUserData.userRewardsInformation);
|
|
114
115
|
acc.push(val.vTokenIncentivesUserData.userRewardsInformation);
|
|
@@ -121,7 +122,7 @@ export const fetchSparkRewards = (provider, network, walletAddress, marketAddres
|
|
|
121
122
|
}, []);
|
|
122
123
|
const rewardsPerAAsset = yield Promise.all(allATokens.map((token) => {
|
|
123
124
|
const sparkRewardsContract = SparkRewardsControllerViem(provider, network);
|
|
124
|
-
return sparkRewardsContract.read.getAllUserRewards([[token], walletAddress]);
|
|
125
|
+
return sparkRewardsContract.read.getAllUserRewards([[token], walletAddress], setViemBlockNumber(blockNumber));
|
|
125
126
|
}));
|
|
126
127
|
// match amounts to token symbol, parse decimal amounts
|
|
127
128
|
const rewardsPerAAssetWithInfo = rewardsPerAAsset.map((rewardForAAsset, aaIndex) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
|
-
import { EthAddress, NetworkNumber } from '../types';
|
|
2
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types';
|
|
3
3
|
import { UniswapAirdropClaimableToken } from '../types/claiming';
|
|
4
4
|
export declare const fetchUniswapRewardsData: (walletAddress: EthAddress) => Promise<any>;
|
|
5
|
-
export declare const getUniswapRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[]) => Promise<Record<string, UniswapAirdropClaimableToken[]>>;
|
|
5
|
+
export declare const getUniswapRewards: (provider: Client, network: NetworkNumber, walletAddresses: EthAddress[], blockNumber?: Blockish) => Promise<Record<string, UniswapAirdropClaimableToken[]>>;
|
package/esm/claiming/uniswap.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth } from '@defisaver/tokens';
|
|
12
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
12
13
|
import { UniswapTokenDistributorViem } from '../contracts';
|
|
13
14
|
import { ClaimType } from '../types/claiming';
|
|
14
15
|
const EMPTY_DATA = (walletAddress) => ({
|
|
@@ -28,13 +29,13 @@ export const fetchUniswapRewardsData = (walletAddress) => __awaiter(void 0, void
|
|
|
28
29
|
return EMPTY_DATA(walletAddress);
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
|
-
export const getUniswapRewards = (
|
|
32
|
+
export const getUniswapRewards = (provider_1, network_1, walletAddresses_1, ...args_1) => __awaiter(void 0, [provider_1, network_1, walletAddresses_1, ...args_1], void 0, function* (provider, network, walletAddresses, blockNumber = 'latest') {
|
|
32
33
|
// Fetch all API data in parallel (these are external API calls, can't be batched with multicall)
|
|
33
34
|
const apiDataPromises = walletAddresses.map(address => fetchUniswapRewardsData(address));
|
|
34
35
|
const apiDataArray = yield Promise.all(apiDataPromises);
|
|
35
36
|
// Batch all contract calls using multicall
|
|
36
37
|
const contract = UniswapTokenDistributorViem(provider, network);
|
|
37
|
-
const cumulativePromises = apiDataArray.map(data => (data.index ? contract.read.isClaimed([data.index]) : Promise.resolve(false)));
|
|
38
|
+
const cumulativePromises = apiDataArray.map(data => (data.index ? contract.read.isClaimed([data.index], setViemBlockNumber(blockNumber)) : Promise.resolve(false)));
|
|
38
39
|
const cumulativeResults = yield Promise.all(cumulativePromises);
|
|
39
40
|
// Process results
|
|
40
41
|
const results = {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
3
|
import { CompoundV2AssetsData, CompoundV2MarketsData, CompoundV2PositionData } from '../types';
|
|
4
|
-
export declare const _getCompoundV2MarketsData: (provider: Client, network: NetworkNumber) => Promise<CompoundV2MarketsData>;
|
|
5
|
-
export declare const getCompoundV2MarketsData: (provider: EthereumProvider, network: NetworkNumber) => Promise<CompoundV2MarketsData>;
|
|
4
|
+
export declare const _getCompoundV2MarketsData: (provider: Client, network: NetworkNumber, blockNumber?: Blockish) => Promise<CompoundV2MarketsData>;
|
|
5
|
+
export declare const getCompoundV2MarketsData: (provider: EthereumProvider, network: NetworkNumber, blockNumber?: Blockish) => Promise<CompoundV2MarketsData>;
|
|
6
6
|
export declare const EMPTY_COMPOUND_DATA: {
|
|
7
7
|
usedAssets: {};
|
|
8
8
|
suppliedUsd: string;
|
|
@@ -19,6 +19,6 @@ export declare const EMPTY_COMPOUND_DATA: {
|
|
|
19
19
|
};
|
|
20
20
|
export declare const _getCompoundV2AccountBalances: (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, tokens?: EthAddress[]) => Promise<PositionBalances>;
|
|
21
21
|
export declare const getCompoundV2AccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
22
|
-
export declare const _getCompoundV2AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, assetsData: CompoundV2AssetsData) => Promise<CompoundV2PositionData>;
|
|
23
|
-
export declare const getCompoundV2AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, assetsData: CompoundV2AssetsData) => Promise<CompoundV2PositionData>;
|
|
22
|
+
export declare const _getCompoundV2AccountData: (provider: Client, network: NetworkNumber, address: EthAddress, assetsData: CompoundV2AssetsData, blockNumber?: Blockish) => Promise<CompoundV2PositionData>;
|
|
23
|
+
export declare const getCompoundV2AccountData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, assetsData: CompoundV2AssetsData, blockNumber?: Blockish) => Promise<CompoundV2PositionData>;
|
|
24
24
|
export declare const getCompoundV2FullPositionData: (provider: EthereumProvider, network: NetworkNumber, address: EthAddress) => Promise<CompoundV2PositionData>;
|