@defisaver/positions-sdk 2.1.169-custom-fetching-2-dev → 2.1.169-custom-fetching-4-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 +47 -43
- package/cjs/services/merkl.d.ts +44 -2
- package/cjs/services/merkl.js +181 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -4
- package/cjs/services/viem.js +18 -18
- 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 +1 -1
- 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 +49 -45
- package/esm/services/merkl.d.ts +44 -2
- package/esm/services/merkl.js +171 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -4
- package/esm/services/viem.js +16 -16
- 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 +1 -1
- 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 +50 -44
- package/src/services/merkl.ts +200 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +14 -12
- package/src/spark/index.ts +11 -8
- package/src/types/merkl.ts +20 -0
- package/src/types/portfolio.ts +1 -1
- package/src/umbrella/index.ts +6 -5
package/src/morphoBlue/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
getBorrowRate, getMorphoBlueAggregatedPositionData, getRewardsForMarket, getSupplyRate,
|
|
18
18
|
} from '../helpers/morphoBlueHelpers';
|
|
19
19
|
import { getChainlinkAssetAddress } from '../services/priceService';
|
|
20
|
-
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
20
|
+
import { getBlockTimestamp, getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
21
21
|
|
|
22
22
|
import { addMorphoBlueMerklOpportunitiesToMarketInfo, getMorphoBlueMerklOpportunities } from './merkl';
|
|
23
23
|
|
|
@@ -62,6 +62,7 @@ async function getMorphoBlueMarketDataInternal(
|
|
|
62
62
|
provider: Client,
|
|
63
63
|
network: NetworkNumber,
|
|
64
64
|
selectedMarket: MorphoBlueMarketData,
|
|
65
|
+
blockNumber: Blockish = 'latest',
|
|
65
66
|
): Promise<MorphoBlueMarketInfo> {
|
|
66
67
|
const {
|
|
67
68
|
loanToken, collateralToken, oracle, irm, lltv, oracleType,
|
|
@@ -82,8 +83,8 @@ async function getMorphoBlueMarketDataInternal(
|
|
|
82
83
|
if (isMainnet) {
|
|
83
84
|
const feedRegistryContract = FeedRegistryContractViem(provider, NetworkNumber.Eth);
|
|
84
85
|
const [_loanTokenPrice, _marketInfo] = await Promise.all([
|
|
85
|
-
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE]),
|
|
86
|
-
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)]),
|
|
86
|
+
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
87
|
+
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)], setViemBlockNumber(blockNumber)),
|
|
87
88
|
]);
|
|
88
89
|
marketInfo = _marketInfo;
|
|
89
90
|
loanTokenPrice = _loanTokenPrice;
|
|
@@ -93,8 +94,8 @@ async function getMorphoBlueMarketDataInternal(
|
|
|
93
94
|
|
|
94
95
|
const [loanTokenPriceRound, _marketInfo] = await Promise.all([
|
|
95
96
|
isHardcodedUsdStable ? Promise.resolve([0, HARDCODED_USD_STABLE_PRICE]) // Normalize to match the expected object structure
|
|
96
|
-
: feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE]),
|
|
97
|
-
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)]),
|
|
97
|
+
: feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
98
|
+
morphoBlueViewContract.read.getMarketInfoNotTuple([loanToken, collateralToken, oracle, irm, BigInt(lltvInWei)], setViemBlockNumber(blockNumber)),
|
|
98
99
|
]);
|
|
99
100
|
marketInfo = _marketInfo;
|
|
100
101
|
loanTokenPrice = loanTokenPriceRound[1].toString();
|
|
@@ -159,14 +160,16 @@ async function getMorphoBlueMarketDataInternal(
|
|
|
159
160
|
};
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
export async function _getMorphoBlueMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo> {
|
|
163
|
+
export async function _getMorphoBlueMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber: Blockish = 'latest'): Promise<MorphoBlueMarketInfo> {
|
|
163
164
|
const [marketInfo, rewards, merklOpportunities] = await Promise.all([
|
|
164
|
-
getMorphoBlueMarketDataInternal(provider, network, selectedMarket),
|
|
165
|
+
getMorphoBlueMarketDataInternal(provider, network, selectedMarket, blockNumber),
|
|
165
166
|
getRewardsForMarket(selectedMarket.marketId, network).catch((error) => {
|
|
166
167
|
console.error(error);
|
|
167
168
|
return { supplyApy: '0', borrowApy: '0' };
|
|
168
169
|
}),
|
|
169
|
-
|
|
170
|
+
// Merkl rewards are keyed by time: a historical block resolves to its timestamp first (one RPC
|
|
171
|
+
// call, none for 'latest') so the rewards in force at that moment are attached.
|
|
172
|
+
getBlockTimestamp(provider, blockNumber).then((asOfTimestamp) => getMorphoBlueMerklOpportunities(asOfTimestamp, network)),
|
|
170
173
|
]);
|
|
171
174
|
|
|
172
175
|
return addMorphoBlueMerklOpportunitiesToMarketInfo(
|
|
@@ -177,16 +180,16 @@ export async function _getMorphoBlueMarketData(provider: Client, network: Networ
|
|
|
177
180
|
);
|
|
178
181
|
}
|
|
179
182
|
|
|
180
|
-
export function _getMorphoBluePortfolioMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo> {
|
|
181
|
-
return getMorphoBlueMarketDataInternal(provider, network, selectedMarket);
|
|
183
|
+
export function _getMorphoBluePortfolioMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber: Blockish = 'latest'): Promise<MorphoBlueMarketInfo> {
|
|
184
|
+
return getMorphoBlueMarketDataInternal(provider, network, selectedMarket, blockNumber);
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
export async function getMorphoBlueMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo> {
|
|
185
|
-
return _getMorphoBlueMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
187
|
+
export async function getMorphoBlueMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber: Blockish = 'latest'): Promise<MorphoBlueMarketInfo> {
|
|
188
|
+
return _getMorphoBlueMarketData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
186
189
|
}
|
|
187
190
|
|
|
188
|
-
export function getMorphoBluePortfolioMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData): Promise<MorphoBlueMarketInfo> {
|
|
189
|
-
return _getMorphoBluePortfolioMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
191
|
+
export function getMorphoBluePortfolioMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, blockNumber: Blockish = 'latest'): Promise<MorphoBlueMarketInfo> {
|
|
192
|
+
return _getMorphoBluePortfolioMarketData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
190
193
|
}
|
|
191
194
|
|
|
192
195
|
export const getMorphoBluePositionDataWithMarketInfo = (
|
|
@@ -273,7 +276,7 @@ export const getMorphoBlueAccountBalances = async (
|
|
|
273
276
|
selectedMarket: MorphoBlueMarketData,
|
|
274
277
|
): Promise<PositionBalances> => _getMorphoBlueAccountBalances(getViemProvider(provider, network), network, block, addressMapping, address, selectedMarket);
|
|
275
278
|
|
|
276
|
-
export async function _getMorphoBlueAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData> {
|
|
279
|
+
export async function _getMorphoBlueAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo, blockNumber: Blockish = 'latest'): Promise<MorphoBluePositionData> {
|
|
277
280
|
const {
|
|
278
281
|
loanToken, collateralToken, oracle, irm, lltv,
|
|
279
282
|
} = selectedMarket;
|
|
@@ -283,7 +286,7 @@ export async function _getMorphoBlueAccountData(provider: Client, network: Netwo
|
|
|
283
286
|
{
|
|
284
287
|
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
285
288
|
},
|
|
286
|
-
account]));
|
|
289
|
+
account], setViemBlockNumber(blockNumber)));
|
|
287
290
|
const usedAssets: MMUsedAssets = {};
|
|
288
291
|
|
|
289
292
|
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
@@ -321,11 +324,11 @@ export async function _getMorphoBlueAccountData(provider: Client, network: Netwo
|
|
|
321
324
|
};
|
|
322
325
|
}
|
|
323
326
|
|
|
324
|
-
export async function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData> {
|
|
325
|
-
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
327
|
+
export async function getMorphoBlueAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo, blockNumber: Blockish = 'latest'): Promise<MorphoBluePositionData> {
|
|
328
|
+
return _getMorphoBlueAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo, blockNumber);
|
|
326
329
|
}
|
|
327
330
|
|
|
328
|
-
export async function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBlueEarnData> {
|
|
331
|
+
export async function getMorphoEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo, blockNumber: Blockish = 'latest'): Promise<MorphoBlueEarnData> {
|
|
329
332
|
const {
|
|
330
333
|
loanToken, collateralToken, oracle, irm, lltv,
|
|
331
334
|
} = selectedMarket;
|
|
@@ -336,7 +339,7 @@ export async function getMorphoEarn(provider: Client, network: NetworkNumber, ac
|
|
|
336
339
|
{
|
|
337
340
|
loanToken, collateralToken, oracle, irm, lltv: BigInt(lltvInWei),
|
|
338
341
|
},
|
|
339
|
-
account]));
|
|
342
|
+
account], setViemBlockNumber(blockNumber)));
|
|
340
343
|
|
|
341
344
|
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
342
345
|
const loanTokenSupplied = assetAmountInEth(loanInfo.suppliedInAssets.toString(), marketInfo.loanToken);
|
package/src/morphoBlue/merkl.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { aprToApy } from '../moneymarket';
|
|
2
|
-
import {
|
|
2
|
+
import { fetchMerklOpportunities } from '../services/merkl';
|
|
3
3
|
import {
|
|
4
4
|
IncentiveData,
|
|
5
5
|
IncentiveKind,
|
|
@@ -94,16 +94,19 @@ export const addMorphoBlueMerklOpportunitiesToMarketInfo = (
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
* Fetches live market-scoped Morpho Blue campaigns for all chains
|
|
98
|
-
*
|
|
97
|
+
* Fetches live market-scoped Morpho Blue campaigns for all chains (or one, when `chainId` is given).
|
|
98
|
+
* With `asOfTimestamp` (unix seconds) the campaigns and APRs are the ones Merkl had at that moment
|
|
99
|
+
* instead. Never throws — on any failure it returns an empty list, so Merkl being down can't break
|
|
100
|
+
* market data.
|
|
99
101
|
*/
|
|
100
|
-
export const getMorphoBlueMerklOpportunities = async (): Promise<MerklOpportunity[]> => {
|
|
102
|
+
export const getMorphoBlueMerklOpportunities = async (asOfTimestamp?: number, chainId?: NetworkNumber): Promise<MerklOpportunity[]> => {
|
|
101
103
|
try {
|
|
102
|
-
return await
|
|
104
|
+
return await fetchMerklOpportunities({
|
|
103
105
|
mainProtocolId: 'morpho',
|
|
104
106
|
type: Object.values(MorphoBlueMerklOpportunityType).join(','),
|
|
105
107
|
status: OpportunityStatus.LIVE,
|
|
106
|
-
|
|
108
|
+
...(chainId ? { chainId: chainId.toString() } : {}),
|
|
109
|
+
}, asOfTimestamp);
|
|
107
110
|
} catch (e) {
|
|
108
111
|
console.error('Failed to fetch Morpho Blue Merkl campaigns', e);
|
|
109
112
|
return [];
|
|
@@ -20,7 +20,7 @@ import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
|
20
20
|
const HARDCODED_USD_STABLE_PRICE = '100000000'; // $1 with 8 decimals
|
|
21
21
|
const nowInSeconds = () => Math.floor(Date.now() / 1000);
|
|
22
22
|
|
|
23
|
-
export async function _getMorphoMidnightMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData): Promise<MorphoMidnightMarketInfo> {
|
|
23
|
+
export async function _getMorphoMidnightMarketData(provider: Client, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData, blockNumber: Blockish = 'latest'): Promise<MorphoMidnightMarketInfo> {
|
|
24
24
|
const { loanToken, collaterals, marketId } = selectedMarket;
|
|
25
25
|
const loanTokenInfo = getAssetInfoByAddress(loanToken, network);
|
|
26
26
|
const loanSym = wethToEth(loanTokenInfo.symbol);
|
|
@@ -34,8 +34,8 @@ export async function _getMorphoMidnightMarketData(provider: Client, network: Ne
|
|
|
34
34
|
if (isMainnetNetwork(network)) {
|
|
35
35
|
const feedRegistryContract = FeedRegistryContractViem(provider, NetworkNumber.Eth);
|
|
36
36
|
const [_loanTokenPrice, _marketInfo] = await Promise.all([
|
|
37
|
-
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE]),
|
|
38
|
-
viewContract.read.getMarketInfo([marketId as `0x${string}`]),
|
|
37
|
+
isHardcodedUsdStable ? Promise.resolve(HARDCODED_USD_STABLE_PRICE) : feedRegistryContract.read.latestAnswer([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
38
|
+
viewContract.read.getMarketInfo([marketId as `0x${string}`], setViemBlockNumber(blockNumber)),
|
|
39
39
|
]);
|
|
40
40
|
marketInfo = _marketInfo;
|
|
41
41
|
loanTokenPrice = _loanTokenPrice;
|
|
@@ -43,8 +43,8 @@ export async function _getMorphoMidnightMarketData(provider: Client, network: Ne
|
|
|
43
43
|
// Currently only Base is supported
|
|
44
44
|
const feedRegistryContract = DFSFeedRegistryContractViem(provider, network);
|
|
45
45
|
const [loanTokenPriceRound, _marketInfo] = await Promise.all([
|
|
46
|
-
isHardcodedUsdStable ? Promise.resolve([0, HARDCODED_USD_STABLE_PRICE]) : feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE]),
|
|
47
|
-
viewContract.read.getMarketInfo([marketId as `0x${string}`]),
|
|
46
|
+
isHardcodedUsdStable ? Promise.resolve([0, HARDCODED_USD_STABLE_PRICE]) : feedRegistryContract.read.latestRoundData([loanTokenFeedAddress, USD_QUOTE], setViemBlockNumber(blockNumber)),
|
|
47
|
+
viewContract.read.getMarketInfo([marketId as `0x${string}`], setViemBlockNumber(blockNumber)),
|
|
48
48
|
]);
|
|
49
49
|
marketInfo = _marketInfo;
|
|
50
50
|
loanTokenPrice = loanTokenPriceRound[1].toString();
|
|
@@ -119,14 +119,14 @@ export async function _getMorphoMidnightMarketData(provider: Client, network: Ne
|
|
|
119
119
|
};
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
export async function getMorphoMidnightMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData): Promise<MorphoMidnightMarketInfo> {
|
|
123
|
-
return _getMorphoMidnightMarketData(getViemProvider(provider, network), network, selectedMarket);
|
|
122
|
+
export async function getMorphoMidnightMarketData(provider: EthereumProvider, network: NetworkNumber, selectedMarket: MorphoMidnightMarketData, blockNumber: Blockish = 'latest'): Promise<MorphoMidnightMarketInfo> {
|
|
123
|
+
return _getMorphoMidnightMarketData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export async function _getMorphoMidnightAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo): Promise<MorphoMidnightPositionData> {
|
|
126
|
+
export async function _getMorphoMidnightAccountData(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo, blockNumber: Blockish = 'latest'): Promise<MorphoMidnightPositionData> {
|
|
127
127
|
const { marketId, collaterals } = selectedMarket;
|
|
128
128
|
const viewContract = MorphoMidnightViewContractViem(provider, network);
|
|
129
|
-
const positionInfo = await viewContract.read.getPositionInfo([marketId as `0x${string}`, account]);
|
|
129
|
+
const positionInfo = await viewContract.read.getPositionInfo([marketId as `0x${string}`, account], setViemBlockNumber(blockNumber));
|
|
130
130
|
|
|
131
131
|
const usedAssets: MMUsedAssets = {};
|
|
132
132
|
|
|
@@ -218,8 +218,8 @@ export async function _getMorphoMidnightAccountData(provider: Client, network: N
|
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
export async function getMorphoMidnightAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo): Promise<MorphoMidnightPositionData> {
|
|
222
|
-
return _getMorphoMidnightAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo);
|
|
221
|
+
export async function getMorphoMidnightAccountData(provider: EthereumProvider, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo, blockNumber: Blockish = 'latest'): Promise<MorphoMidnightPositionData> {
|
|
222
|
+
return _getMorphoMidnightAccountData(getViemProvider(provider, network), network, account, selectedMarket, marketInfo, blockNumber);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
export const _getMorphoMidnightAccountBalances = async (provider: Client, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress, selectedMarket: MorphoMidnightMarketData, includeCredit = false): Promise<PositionBalances> => {
|
|
@@ -263,10 +263,10 @@ export const getMorphoMidnightAccountBalances = async (
|
|
|
263
263
|
|
|
264
264
|
// Lender-side (credit-only) supply position, mirroring getMorphoEarn. `amount` is the credit face value
|
|
265
265
|
// redeemable at maturity; `apy` is '0' in MVP because the fixed yield is orderbook-derived, not on-chain.
|
|
266
|
-
export async function getMorphoMidnightEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo): Promise<{ apy: string, amount: string, amountUsd: string }> {
|
|
266
|
+
export async function getMorphoMidnightEarn(provider: Client, network: NetworkNumber, account: EthAddress, selectedMarket: MorphoMidnightMarketData, marketInfo: MorphoMidnightMarketInfo, blockNumber: Blockish = 'latest'): Promise<{ apy: string, amount: string, amountUsd: string }> {
|
|
267
267
|
const { marketId } = selectedMarket;
|
|
268
268
|
const viewContract = MorphoMidnightViewContractViem(provider, network);
|
|
269
|
-
const positionInfo = await viewContract.read.getPositionInfo([marketId as `0x${string}`, account]);
|
|
269
|
+
const positionInfo = await viewContract.read.getPositionInfo([marketId as `0x${string}`, account], setViemBlockNumber(blockNumber));
|
|
270
270
|
|
|
271
271
|
const loanTokenData = marketInfo.assetsData[marketInfo.loanToken];
|
|
272
272
|
const credit = assetAmountInEth(positionInfo.credit.toString(), marketInfo.loanToken);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Blockish, EthAddress, EthereumProvider, NetworkNumber,
|
|
4
|
+
} from '../types/common';
|
|
3
5
|
import {
|
|
4
6
|
AaveMarkets,
|
|
5
7
|
AaveV4Spokes,
|
|
@@ -22,7 +24,7 @@ import {
|
|
|
22
24
|
PortfolioPositionsData,
|
|
23
25
|
PortfolioProtocol,
|
|
24
26
|
} from '../types';
|
|
25
|
-
import {
|
|
27
|
+
import { getBlockTimestamp, getViemProvider } from '../services/viem';
|
|
26
28
|
import { ZERO_ADDRESS } from '../constants';
|
|
27
29
|
import { _getAaveV2AccountData, _getAaveV2MarketsData } from '../aaveV2';
|
|
28
30
|
import { _getAaveV3AccountData, _getAaveV3MarketData, getStakeAaveData } from '../aaveV3';
|
|
@@ -74,9 +76,13 @@ export async function getCustomDeFiData(
|
|
|
74
76
|
const isMainnet = network === NetworkNumber.Eth;
|
|
75
77
|
const isFluidSupported = [NetworkNumber.Eth, NetworkNumber.Arb, NetworkNumber.Base, NetworkNumber.Plasma].includes(network);
|
|
76
78
|
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
79
|
+
const client = getViemProvider(provider, network, { batch: { multicall: { batchSize } } });
|
|
80
|
+
const defaultClient = getViemProvider(defaultProvider, network, { batch: { multicall: { batchSize } } });
|
|
81
|
+
// Every fetch below takes the block explicitly and passes it to each of its contract reads.
|
|
82
|
+
// Time-keyed sources (Merkl rewards) need the block's timestamp instead, resolved once here (no
|
|
83
|
+
// RPC call for 'latest') and handed to the market fetches so they don't each look it up.
|
|
84
|
+
const blockNumber: Blockish = options.blockNumber ?? 'latest';
|
|
85
|
+
const blockTimestamp = await getBlockTimestamp(client, blockNumber);
|
|
80
86
|
|
|
81
87
|
const aaveV3Markets = has(PortfolioProtocol.AaveV3)
|
|
82
88
|
? [AaveVersions.AaveV3, AaveVersions.AaveV3Lido, AaveVersions.AaveV3Etherfi].map((v) => AaveMarkets(network)[v]).filter((m) => m.chainIds.includes(network))
|
|
@@ -170,33 +176,33 @@ export async function getCustomDeFiData(
|
|
|
170
176
|
})();
|
|
171
177
|
|
|
172
178
|
await Promise.allSettled([
|
|
173
|
-
...morphoMarkets.map(async (m) => { markets.morphoMarketsData[m.value] = await _getMorphoBluePortfolioMarketData(client, network, m); }),
|
|
174
|
-
...morphoMidnightMarkets.map(async (m) => { markets.morphoMidnightMarketsData[m.value] = await _getMorphoMidnightMarketData(client, network, m); }),
|
|
175
|
-
...compoundV3Markets.map(async (m) => { markets.compoundV3MarketsData[m.value] = await _getCompoundV3MarketsData(client, network, m, defaultClient); }),
|
|
176
|
-
...sparkMarkets.map(async (m) => { markets.sparkMarketsData[m.value] = await _getSparkMarketsData(client, network, m); }),
|
|
177
|
-
...aaveV3Markets.map(async (m) => { markets.aaveV3MarketsData[m.value] = await _getAaveV3MarketData(client, network, m); }),
|
|
178
|
-
...aaveV4Spokes.map(async (s) => { markets.aaveV4SpokesData[s.value] = await _getAaveV4SpokeData(client, network, s); }),
|
|
179
|
-
...aaveV2Markets.map(async (m) => { markets.aaveV2MarketsData[m.value] = await _getAaveV2MarketsData(client, network, m); }),
|
|
180
|
-
...compoundV2Markets.map(async (m) => { markets.compoundV2MarketsData[m.value] = await _getCompoundV2MarketsData(client, network); }),
|
|
181
|
-
...crvUsdMarkets.map(async (m) => { markets.crvUsdMarketsData[m.value] = await _getCurveUsdGlobalData(client, network, m); }),
|
|
182
|
-
...llamaLendMarkets.map(async (m) => { markets.llamaLendMarketsData[m.value] = await _getLlamaLendGlobalData(client, network, m); }),
|
|
183
|
-
...liquityV2Markets.map(async (m) => { markets.liquityV2MarketsData[m.value] = await _getLiquityV2MarketData(client, network, m); }),
|
|
179
|
+
...morphoMarkets.map(async (m) => { markets.morphoMarketsData[m.value] = await _getMorphoBluePortfolioMarketData(client, network, m, blockNumber); }),
|
|
180
|
+
...morphoMidnightMarkets.map(async (m) => { markets.morphoMidnightMarketsData[m.value] = await _getMorphoMidnightMarketData(client, network, m, blockNumber); }),
|
|
181
|
+
...compoundV3Markets.map(async (m) => { markets.compoundV3MarketsData[m.value] = await _getCompoundV3MarketsData(client, network, m, defaultClient, blockNumber, blockTimestamp); }),
|
|
182
|
+
...sparkMarkets.map(async (m) => { markets.sparkMarketsData[m.value] = await _getSparkMarketsData(client, network, m, blockNumber); }),
|
|
183
|
+
...aaveV3Markets.map(async (m) => { markets.aaveV3MarketsData[m.value] = await _getAaveV3MarketData(client, network, m, blockNumber, blockTimestamp); }),
|
|
184
|
+
...aaveV4Spokes.map(async (s) => { markets.aaveV4SpokesData[s.value] = await _getAaveV4SpokeData(client, network, s, blockNumber, blockTimestamp); }),
|
|
185
|
+
...aaveV2Markets.map(async (m) => { markets.aaveV2MarketsData[m.value] = await _getAaveV2MarketsData(client, network, m, blockNumber); }),
|
|
186
|
+
...compoundV2Markets.map(async (m) => { markets.compoundV2MarketsData[m.value] = await _getCompoundV2MarketsData(client, network, blockNumber); }),
|
|
187
|
+
...crvUsdMarkets.map(async (m) => { markets.crvUsdMarketsData[m.value] = await _getCurveUsdGlobalData(client, network, m, blockNumber); }),
|
|
188
|
+
...llamaLendMarkets.map(async (m) => { markets.llamaLendMarketsData[m.value] = await _getLlamaLendGlobalData(client, network, m, blockNumber); }),
|
|
189
|
+
...liquityV2Markets.map(async (m) => { markets.liquityV2MarketsData[m.value] = await _getLiquityV2MarketData(client, network, m, blockNumber); }),
|
|
184
190
|
(async () => {
|
|
185
191
|
if (!fetchFluid || !fetchFluidMarkets) return;
|
|
186
|
-
try { markets.fluidMarketsData = await _getAllFluidMarketDataPortfolio(client, network); } catch (error) { console.error('Error fetching Fluid markets data:', error); }
|
|
192
|
+
try { markets.fluidMarketsData = await _getAllFluidMarketDataPortfolio(client, network, blockNumber, blockTimestamp); } catch (error) { console.error('Error fetching Fluid markets data:', error); }
|
|
187
193
|
})(),
|
|
188
194
|
(async () => {
|
|
189
195
|
if (!fetchMaker) return;
|
|
190
|
-
try { markets.makerMarketsData = await _getMakerIlksData(client, network, MakerActiveIlks); } catch (error) { console.error('Error fetching Maker ilks data:', error); }
|
|
196
|
+
try { markets.makerMarketsData = await _getMakerIlksData(client, network, MakerActiveIlks, blockNumber); } catch (error) { console.error('Error fetching Maker ilks data:', error); }
|
|
191
197
|
})(),
|
|
192
198
|
|
|
193
199
|
...addresses.map(async (address) => {
|
|
194
200
|
if (!fetchMaker) return;
|
|
195
|
-
makerCdps[lower(address)] = await _getUserCdps(client, network, address);
|
|
201
|
+
makerCdps[lower(address)] = await _getUserCdps(client, network, address, blockNumber);
|
|
196
202
|
}),
|
|
197
203
|
...addresses.map((address) => fetchFluid && run(
|
|
198
204
|
`Fluid positions for address ${address}`,
|
|
199
|
-
() => _getUserPositionsPortfolio(client, network, address),
|
|
205
|
+
() => _getUserPositionsPortfolio(client, network, address, blockNumber),
|
|
200
206
|
(userPositions) => {
|
|
201
207
|
for (const position of userPositions) {
|
|
202
208
|
if (position.userData && positive(position.userData.suppliedUsd)) positions[lower(address)].fluid.data[position.userData.nftId] = position.userData;
|
|
@@ -208,40 +214,40 @@ export async function getCustomDeFiData(
|
|
|
208
214
|
...(fetchStaking ? [
|
|
209
215
|
...addresses.map((address) => fetchFluid && run(
|
|
210
216
|
`Fluid lend data for address ${address}`,
|
|
211
|
-
() => _getAllUserEarnPositionsWithFTokens(client, network, address),
|
|
217
|
+
() => _getAllUserEarnPositionsWithFTokens(client, network, address, blockNumber),
|
|
212
218
|
(data) => { stakingPositions[lower(address)].fluid = data; },
|
|
213
219
|
(err) => { stakingPositions[lower(address)].fluid = err; },
|
|
214
220
|
)),
|
|
215
221
|
...addresses.map((address) => fetchLiquity && run(
|
|
216
222
|
`Liquity staking data for address ${address}`,
|
|
217
|
-
() => getLiquityStakingData(client, network, address),
|
|
223
|
+
() => getLiquityStakingData(client, network, address, blockNumber),
|
|
218
224
|
(data) => { stakingPositions[lower(address)].liquity = data; },
|
|
219
225
|
(err) => { stakingPositions[lower(address)].liquity = err; },
|
|
220
226
|
)),
|
|
221
227
|
...addresses.map((address) => has(PortfolioProtocol.AaveV3) && isMainnet && run(
|
|
222
228
|
`Aave V3 staking data for address ${address}`,
|
|
223
|
-
() => getStakeAaveData(client, network, address),
|
|
229
|
+
() => getStakeAaveData(client, network, address, blockNumber),
|
|
224
230
|
(data) => { stakingPositions[lower(address)].aaveV3 = data; },
|
|
225
231
|
(err) => { stakingPositions[lower(address)].aaveV3 = err; },
|
|
226
232
|
)),
|
|
227
233
|
...addresses.map((address) => has(PortfolioProtocol.AaveV3) && isMainnet && run(
|
|
228
234
|
`Umbrella staking data for address ${address}`,
|
|
229
|
-
() => getUmbrellaData(client, network, address),
|
|
235
|
+
() => getUmbrellaData(client, network, address, blockNumber),
|
|
230
236
|
(data) => { stakingPositions[lower(address)].umbrella = data; },
|
|
231
237
|
(err) => { stakingPositions[lower(address)].umbrella = err; },
|
|
232
238
|
)),
|
|
233
239
|
...perAddress(liquityV2StakingMarkets, (market, address) => run(
|
|
234
240
|
`Liquity V2 staking data for address ${address}, market ${market.value}`,
|
|
235
|
-
() => getLiquityV2Staking(client, network, market.value, address),
|
|
241
|
+
() => getLiquityV2Staking(client, network, market.value, address, blockNumber),
|
|
236
242
|
(data) => { stakingPositions[lower(address)].liquityV2[market.value] = { error: '', data }; },
|
|
237
243
|
(err) => { stakingPositions[lower(address)].liquityV2[market.value] = err; },
|
|
238
244
|
)),
|
|
239
245
|
] : []),
|
|
240
246
|
|
|
241
247
|
...(fetchRewards ? [
|
|
242
|
-
batchRewards('king', 'King rewards data', () => getKingRewards(client, network, addresses), isMainnet),
|
|
243
|
-
batchRewards('uniswap', 'Uniswap rewards data', () => getUniswapRewards(client, network, addresses), isMainnet),
|
|
244
|
-
batchRewards('spk', 'Spark Airdrop rewards data', () => fetchSparkAirdropRewards(client, network, addresses), isMainnet && has(PortfolioProtocol.Spark)),
|
|
248
|
+
batchRewards('king', 'King rewards data', () => getKingRewards(client, network, addresses, blockNumber), isMainnet),
|
|
249
|
+
batchRewards('uniswap', 'Uniswap rewards data', () => getUniswapRewards(client, network, addresses, blockNumber), isMainnet),
|
|
250
|
+
batchRewards('spk', 'Spark Airdrop rewards data', () => fetchSparkAirdropRewards(client, network, addresses, blockNumber), isMainnet && has(PortfolioProtocol.Spark)),
|
|
245
251
|
batchRewards('ethena', 'Ethena Airdrop rewards data', () => fetchEthenaAirdropRewards(addresses), isMainnet),
|
|
246
252
|
...addresses.map((address) => run(
|
|
247
253
|
`Merkl rewards data for address ${address}`,
|
|
@@ -251,7 +257,7 @@ export async function getCustomDeFiData(
|
|
|
251
257
|
)),
|
|
252
258
|
...perAddress(aaveV3Markets, (market, address) => run(
|
|
253
259
|
`Aave V3 rewards data for address ${address}, market ${market.value}`,
|
|
254
|
-
() => getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress),
|
|
260
|
+
() => getUnclaimedRewardsForAllMarkets(client, network, address, market.providerAddress, blockNumber),
|
|
255
261
|
(data) => { rewardsData[lower(address)].aaveV3[market.value] = { error: '', data }; },
|
|
256
262
|
(err) => { rewardsData[lower(address)].aaveV3[market.value] = err; },
|
|
257
263
|
)),
|
|
@@ -262,7 +268,7 @@ export async function getCustomDeFiData(
|
|
|
262
268
|
}
|
|
263
269
|
return run(
|
|
264
270
|
`Spark rewards data for address ${address}, market ${market.value}`,
|
|
265
|
-
() => fetchSparkRewards(client, network, address, market.providerAddress),
|
|
271
|
+
() => fetchSparkRewards(client, network, address, market.providerAddress, blockNumber),
|
|
266
272
|
(data) => { rewardsData[lower(address)].spark[market.value] = { error: '', data }; },
|
|
267
273
|
(err) => { rewardsData[lower(address)].spark[market.value] = err; },
|
|
268
274
|
);
|
|
@@ -273,31 +279,31 @@ export async function getCustomDeFiData(
|
|
|
273
279
|
await Promise.all([
|
|
274
280
|
...perAddress(aaveV3Markets, (market, address) => run(
|
|
275
281
|
`AaveV3 account data for address ${address} on market ${market.value}`,
|
|
276
|
-
() => _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...markets.aaveV3MarketsData[market.value] }),
|
|
282
|
+
() => _getAaveV3AccountData(client, network, address, { selectedMarket: market, ...markets.aaveV3MarketsData[market.value] }, blockNumber),
|
|
277
283
|
(data) => { if (returnEmptyEModePositions || positive(data.suppliedUsd)) positions[lower(address)].aaveV3[market.value] = { error: '', data }; },
|
|
278
284
|
(err) => { positions[lower(address)].aaveV3[market.value] = err; },
|
|
279
285
|
)),
|
|
280
286
|
...perAddress(sparkMarkets, (market, address) => run(
|
|
281
287
|
`Spark account data for address ${address} on market ${market.value}`,
|
|
282
|
-
() => _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData }),
|
|
288
|
+
() => _getSparkAccountData(client, network, address, { selectedMarket: market, assetsData: markets.sparkMarketsData[market.value].assetsData, eModeCategoriesData: markets.sparkMarketsData[market.value].eModeCategoriesData }, blockNumber),
|
|
283
289
|
(data) => { if (returnEmptyEModePositions || positive(data.suppliedUsd)) positions[lower(address)].spark[market.value] = { error: '', data }; },
|
|
284
290
|
(err) => { positions[lower(address)].spark[market.value] = err; },
|
|
285
291
|
)),
|
|
286
292
|
...perAddress(aaveV4Spokes, (spoke, address) => run(
|
|
287
293
|
`AaveV4 account data for address ${address} on spoke ${spoke.value}`,
|
|
288
|
-
() => _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address),
|
|
294
|
+
() => _getAaveV4AccountData(client, network, markets.aaveV4SpokesData[spoke.value], address, blockNumber),
|
|
289
295
|
(data) => { if (positive(data.suppliedUsd)) positions[lower(address)].aaveV4[spoke.value] = { error: '', data }; },
|
|
290
296
|
(err) => { positions[lower(address)].aaveV4[spoke.value] = err; },
|
|
291
297
|
)),
|
|
292
298
|
...perAddress(morphoMarkets, (market, address) => run(
|
|
293
299
|
`MorphoBlue account data for address ${address} on market ${market.value}`,
|
|
294
|
-
() => _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value]),
|
|
300
|
+
() => _getMorphoBlueAccountData(client, network, address, market, markets.morphoMarketsData[market.value], blockNumber),
|
|
295
301
|
(data) => { if (positive(data.suppliedUsd)) positions[lower(address)].morphoBlue[market.value] = { error: '', data }; },
|
|
296
302
|
(err) => { positions[lower(address)].morphoBlue[market.value] = err; },
|
|
297
303
|
)),
|
|
298
304
|
...(fetchStaking ? perAddress(morphoMarkets, (market, address) => run(
|
|
299
305
|
`MorphoBlue earn data for address ${address} on market ${market.value}`,
|
|
300
|
-
() => getMorphoEarn(client, network, address, market, markets.morphoMarketsData[market.value]),
|
|
306
|
+
() => getMorphoEarn(client, network, address, market, markets.morphoMarketsData[market.value], blockNumber),
|
|
301
307
|
(data) => { if (data && positive(data.amount)) stakingPositions[lower(address)].morphoBlue[market.value] = { error: '', data }; },
|
|
302
308
|
(err) => { stakingPositions[lower(address)].morphoBlue[market.value] = err; },
|
|
303
309
|
)) : []),
|
|
@@ -305,38 +311,38 @@ export async function getCustomDeFiData(
|
|
|
305
311
|
if (!markets.morphoMidnightMarketsData[market.value]?.isCreated) return Promise.resolve();
|
|
306
312
|
return run(
|
|
307
313
|
`MorphoMidnight account data for address ${address} on market ${market.value}`,
|
|
308
|
-
() => _getMorphoMidnightAccountData(client, network, address, market, markets.morphoMidnightMarketsData[market.value]),
|
|
314
|
+
() => _getMorphoMidnightAccountData(client, network, address, market, markets.morphoMidnightMarketsData[market.value], blockNumber),
|
|
309
315
|
(data) => { if (positive(data.suppliedUsd)) positions[lower(address)].morphoMidnight[market.value] = { error: '', data }; },
|
|
310
316
|
(err) => { positions[lower(address)].morphoMidnight[market.value] = err; },
|
|
311
317
|
);
|
|
312
318
|
}),
|
|
313
319
|
...perAddress(compoundV3Markets, (market, address) => run(
|
|
314
320
|
`CompoundV3 account data for address ${address} on market ${market.value}`,
|
|
315
|
-
() => _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData }),
|
|
321
|
+
() => _getCompoundV3AccountData(client, network, address, ZERO_ADDRESS, { selectedMarket: market, assetsData: markets.compoundV3MarketsData[market.value].assetsData }, blockNumber),
|
|
316
322
|
(data) => { if (positive(data.suppliedUsd)) positions[lower(address)].compoundV3[market.value] = { error: '', data }; },
|
|
317
323
|
(err) => { positions[lower(address)].compoundV3[market.value] = err; },
|
|
318
324
|
)),
|
|
319
325
|
...perAddress(compoundV2Markets, (market, address) => run(
|
|
320
326
|
`CompoundV2 account data for address ${address}`,
|
|
321
|
-
() => _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData),
|
|
327
|
+
() => _getCompoundV2AccountData(client, network, address, markets.compoundV2MarketsData[market.value].assetsData, blockNumber),
|
|
322
328
|
(data) => { if (positive(data.suppliedUsd)) positions[lower(address)].compoundV2[market.value] = { error: '', data }; },
|
|
323
329
|
(err) => { positions[lower(address)].compoundV2[market.value] = err; },
|
|
324
330
|
)),
|
|
325
331
|
...perAddress(aaveV2Markets, (market, address) => run(
|
|
326
332
|
`AaveV2 account data for address ${address}`,
|
|
327
|
-
() => _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market),
|
|
333
|
+
() => _getAaveV2AccountData(client, network, address, markets.aaveV2MarketsData[market.value].assetsData, market, blockNumber),
|
|
328
334
|
(data) => { if (positive(data.suppliedUsd)) positions[lower(address)].aaveV2[market.value] = { error: '', data }; },
|
|
329
335
|
(err) => { positions[lower(address)].aaveV2[market.value] = err; },
|
|
330
336
|
)),
|
|
331
337
|
...perAddress(crvUsdMarkets, (market, address) => run(
|
|
332
338
|
`Curve USD account data for address ${address} on market ${market.value}`,
|
|
333
|
-
() => _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate),
|
|
339
|
+
() => _getCurveUsdUserData(client, network, address, market, markets.crvUsdMarketsData[market.value].activeBand, markets.crvUsdMarketsData[market.value].borrowRate, blockNumber),
|
|
334
340
|
(data) => { if (positive(data.suppliedUsd) || positive(data.borrowedUsd)) positions[lower(address)].crvUsd[market.value] = { error: '', data }; },
|
|
335
341
|
(err) => { positions[lower(address)].crvUsd[market.value] = err; },
|
|
336
342
|
)),
|
|
337
343
|
...perAddress(llamaLendMarkets, (market, address) => run(
|
|
338
344
|
`LlamaLend account data for address ${address} on market ${market.value}`,
|
|
339
|
-
() => _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value]),
|
|
345
|
+
() => _getLlamaLendUserData(client, network, address, market, markets.llamaLendMarketsData[market.value], blockNumber),
|
|
340
346
|
(data) => {
|
|
341
347
|
if (positive(data.suppliedUsd) || positive(data.borrowedUsd)) {
|
|
342
348
|
positions[lower(address)].llamaLend[market.value] = { error: '', data: { ...data, borrowRate: markets.llamaLendMarketsData[market.value].borrowRate } };
|
|
@@ -346,13 +352,13 @@ export async function getCustomDeFiData(
|
|
|
346
352
|
)),
|
|
347
353
|
...addresses.map((address) => (makerCdps[lower(address)] || []).map((cdpInfo) => run(
|
|
348
354
|
`Maker CDP data for address ${address} with ID ${cdpInfo.id}`,
|
|
349
|
-
() => _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel]),
|
|
355
|
+
() => _getMakerCdpData(client, network, cdpInfo, markets.makerMarketsData[cdpInfo.ilkLabel], blockNumber),
|
|
350
356
|
(data) => { if (data) positions[lower(address)].maker[cdpInfo.id] = { error: '', data }; },
|
|
351
357
|
(err) => { positions[lower(address)].maker[cdpInfo.id] = err; },
|
|
352
358
|
))).flat(),
|
|
353
359
|
...addresses.map((address) => fetchLiquity && run(
|
|
354
360
|
`Liquity trove info for address ${address}`,
|
|
355
|
-
() => _getLiquityTroveInfo(client, network, address),
|
|
361
|
+
() => _getLiquityTroveInfo(client, network, address, blockNumber),
|
|
356
362
|
(data) => { if (positive(data.collateral)) positions[lower(address)].liquity = { error: '', data }; },
|
|
357
363
|
(err) => { positions[lower(address)].liquity = err; },
|
|
358
364
|
)),
|
|
@@ -363,7 +369,7 @@ export async function getCustomDeFiData(
|
|
|
363
369
|
}
|
|
364
370
|
return run(
|
|
365
371
|
`sBold/yBold data for address ${address}`,
|
|
366
|
-
() => getLiquitySAndYBold(client, network, stakingPositions[lower(address)].liquityV2, address),
|
|
372
|
+
() => getLiquitySAndYBold(client, network, stakingPositions[lower(address)].liquityV2, address, blockNumber),
|
|
367
373
|
(data) => { stakingPositions[lower(address)].liquityV2SBoldYBold = { error: '', data }; },
|
|
368
374
|
(err) => { stakingPositions[lower(address)].liquityV2SBoldYBold = err; },
|
|
369
375
|
);
|