@defisaver/positions-sdk 2.1.175-looping-dev → 2.1.175-pendle-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/helpers/aaveHelpers/index.js +1 -1
- package/cjs/helpers/aaveV4Helpers/index.js +14 -2
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/helpers/curveUsdHelpers/index.js +1 -1
- package/cjs/helpers/fluidHelpers/index.js +1 -1
- package/cjs/helpers/liquityV2Helpers/index.js +1 -1
- package/cjs/helpers/llamaLendHelpers/index.js +1 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
- package/cjs/helpers/morphoMidnightHelpers/index.js +1 -1
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/liquity/index.d.ts +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/markets/morphoBlue/index.d.ts +2 -0
- package/cjs/markets/morphoBlue/index.js +19 -2
- package/cjs/moneymarket/moneymarketCommonService.js +14 -3
- package/cjs/morphoBlue/index.d.ts +7 -7
- package/cjs/morphoBlue/index.js +28 -26
- package/cjs/morphoBlue/merkl.d.ts +5 -3
- package/cjs/morphoBlue/merkl.js +6 -8
- package/cjs/morphoMidnight/index.d.ts +5 -5
- package/cjs/morphoMidnight/index.js +18 -18
- package/cjs/portfolio/customDeFiData.d.ts +3 -0
- package/cjs/portfolio/customDeFiData.js +267 -0
- package/cjs/portfolio/index.d.ts +1 -0
- package/cjs/portfolio/index.js +1 -0
- package/cjs/services/merkl.d.ts +46 -2
- package/cjs/services/merkl.js +190 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -2
- package/cjs/services/viem.js +27 -1
- package/cjs/spark/index.d.ts +4 -4
- package/cjs/spark/index.js +9 -9
- package/cjs/staking/staking.js +3 -1
- package/cjs/types/aaveV4.d.ts +1 -0
- package/cjs/types/common.d.ts +1 -0
- package/cjs/types/common.js +1 -0
- package/cjs/types/merkl.d.ts +18 -0
- package/cjs/types/morphoBlue.d.ts +1 -0
- package/cjs/types/morphoBlue.js +1 -0
- package/cjs/types/portfolio.d.ts +37 -0
- package/cjs/types/portfolio.js +18 -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/helpers/aaveHelpers/index.js +1 -1
- package/esm/helpers/aaveV4Helpers/index.js +15 -3
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/curveUsdHelpers/index.js +1 -1
- package/esm/helpers/fluidHelpers/index.js +1 -1
- package/esm/helpers/liquityV2Helpers/index.js +1 -1
- package/esm/helpers/llamaLendHelpers/index.js +1 -1
- package/esm/helpers/morphoBlueHelpers/index.js +1 -1
- package/esm/helpers/morphoMidnightHelpers/index.js +1 -1
- package/esm/helpers/sparkHelpers/index.js +1 -1
- package/esm/liquity/index.d.ts +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/markets/morphoBlue/index.d.ts +2 -0
- package/esm/markets/morphoBlue/index.js +16 -0
- package/esm/moneymarket/moneymarketCommonService.js +14 -3
- package/esm/morphoBlue/index.d.ts +7 -7
- package/esm/morphoBlue/index.js +29 -27
- package/esm/morphoBlue/merkl.d.ts +5 -3
- package/esm/morphoBlue/merkl.js +7 -9
- package/esm/morphoMidnight/index.d.ts +5 -5
- package/esm/morphoMidnight/index.js +18 -18
- package/esm/portfolio/customDeFiData.d.ts +3 -0
- package/esm/portfolio/customDeFiData.js +261 -0
- package/esm/portfolio/index.d.ts +1 -0
- package/esm/portfolio/index.js +1 -0
- package/esm/services/merkl.d.ts +46 -2
- package/esm/services/merkl.js +180 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -2
- package/esm/services/viem.js +25 -0
- package/esm/spark/index.d.ts +4 -4
- package/esm/spark/index.js +10 -10
- package/esm/staking/staking.js +3 -1
- package/esm/types/aaveV4.d.ts +1 -0
- package/esm/types/common.d.ts +1 -0
- package/esm/types/common.js +1 -0
- package/esm/types/merkl.d.ts +18 -0
- package/esm/types/morphoBlue.d.ts +1 -0
- package/esm/types/morphoBlue.js +1 -0
- package/esm/types/portfolio.d.ts +37 -0
- package/esm/types/portfolio.js +17 -1
- package/esm/umbrella/index.d.ts +2 -2
- package/esm/umbrella/index.js +5 -4
- package/package.json +2 -2
- 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/helpers/aaveHelpers/index.ts +1 -1
- package/src/helpers/aaveV4Helpers/index.ts +16 -2
- package/src/helpers/compoundHelpers/index.ts +2 -2
- package/src/helpers/curveUsdHelpers/index.ts +1 -1
- package/src/helpers/fluidHelpers/index.ts +1 -1
- package/src/helpers/liquityV2Helpers/index.ts +1 -1
- package/src/helpers/llamaLendHelpers/index.ts +1 -1
- package/src/helpers/morphoBlueHelpers/index.ts +1 -1
- package/src/helpers/morphoMidnightHelpers/index.ts +1 -1
- package/src/helpers/sparkHelpers/index.ts +1 -1
- package/src/liquity/index.ts +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/markets/morphoBlue/index.ts +16 -0
- package/src/moneymarket/moneymarketCommonService.ts +15 -3
- package/src/morphoBlue/index.ts +23 -20
- package/src/morphoBlue/merkl.ts +9 -6
- package/src/morphoMidnight/index.ts +13 -13
- package/src/portfolio/customDeFiData.ts +385 -0
- package/src/portfolio/index.ts +1 -0
- package/src/services/merkl.ts +209 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +16 -0
- package/src/spark/index.ts +11 -8
- package/src/staking/staking.ts +2 -1
- package/src/types/aaveV4.ts +1 -0
- package/src/types/common.ts +1 -0
- package/src/types/merkl.ts +20 -0
- package/src/types/morphoBlue.ts +1 -0
- package/src/types/portfolio.ts +40 -0
- package/src/umbrella/index.ts +6 -5
|
@@ -10,36 +10,39 @@ import {
|
|
|
10
10
|
WeETHPriceFeedContractViem,
|
|
11
11
|
WstETHPriceFeedContractViem,
|
|
12
12
|
} from '../contracts';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Blockish, EthAddress, NetworkNumber, HexString,
|
|
15
|
+
} from '../types/common';
|
|
14
16
|
import { getEthAmountForDecimals } from './utils';
|
|
17
|
+
import { setViemBlockNumber } from './viem';
|
|
15
18
|
import { USD_QUOTE } from '../constants';
|
|
16
19
|
|
|
17
|
-
export const getEthPrice = async (client: Client) => {
|
|
20
|
+
export const getEthPrice = async (client: Client, block: Blockish = 'latest') => {
|
|
18
21
|
const contract = ETHPriceFeedContractViem(client, NetworkNumber.Eth);
|
|
19
|
-
const price = await contract.read.latestAnswer();
|
|
22
|
+
const price = await contract.read.latestAnswer(setViemBlockNumber(block));
|
|
20
23
|
return new Dec(price.toString()).div(1e8).toString();
|
|
21
24
|
};
|
|
22
25
|
|
|
23
|
-
export const getUSDCPrice = async (client: Client) => {
|
|
26
|
+
export const getUSDCPrice = async (client: Client, block: Blockish = 'latest') => {
|
|
24
27
|
const contract = USDCPriceFeedContractViem(client, NetworkNumber.Eth);
|
|
25
|
-
const price = await contract.read.latestAnswer();
|
|
28
|
+
const price = await contract.read.latestAnswer(setViemBlockNumber(block));
|
|
26
29
|
return new Dec(price.toString()).div(1e8).toString();
|
|
27
30
|
};
|
|
28
31
|
|
|
29
|
-
export const getCompPrice = async (client: Client) => {
|
|
32
|
+
export const getCompPrice = async (client: Client, block: Blockish = 'latest') => {
|
|
30
33
|
const contract = COMPPriceFeedContractViem(client, NetworkNumber.Eth);
|
|
31
|
-
const price = await contract.read.latestAnswer();
|
|
34
|
+
const price = await contract.read.latestAnswer(setViemBlockNumber(block));
|
|
32
35
|
return new Dec(price.toString()).div(1e8).toString();
|
|
33
36
|
};
|
|
34
37
|
|
|
35
|
-
export const getWstETHPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth) => {
|
|
38
|
+
export const getWstETHPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth, block: Blockish = 'latest') => {
|
|
36
39
|
const wstETHFeedContract = WstETHPriceFeedContractViem(client, network);
|
|
37
40
|
const ethFeedContract = ETHPriceFeedContractViem(client, network);
|
|
38
41
|
|
|
39
42
|
const [ethPriceWei, wstETHRateWei, decimals] = await Promise.all([
|
|
40
|
-
ethFeedContract.read.latestAnswer(),
|
|
41
|
-
wstETHFeedContract.read.latestRoundData(),
|
|
42
|
-
wstETHFeedContract.read.decimals(),
|
|
43
|
+
ethFeedContract.read.latestAnswer(setViemBlockNumber(block)),
|
|
44
|
+
wstETHFeedContract.read.latestRoundData(setViemBlockNumber(block)),
|
|
45
|
+
wstETHFeedContract.read.decimals(setViemBlockNumber(block)),
|
|
43
46
|
]);
|
|
44
47
|
|
|
45
48
|
const ethPrice = new Dec(ethPriceWei.toString()).div(1e8);
|
|
@@ -49,14 +52,14 @@ export const getWstETHPrice = async (client: Client, network: NetworkNumber = Ne
|
|
|
49
52
|
return new Dec(ethPrice).mul(wstETHRate).toString();
|
|
50
53
|
};
|
|
51
54
|
|
|
52
|
-
export const getWeETHPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth) => {
|
|
55
|
+
export const getWeETHPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth, block: Blockish = 'latest') => {
|
|
53
56
|
const weETHFeedContract = WeETHPriceFeedContractViem(client, network);
|
|
54
57
|
const ethFeedContract = ETHPriceFeedContractViem(client, network);
|
|
55
58
|
|
|
56
59
|
const [ethPriceWei, weETHRateWei, decimals] = await Promise.all([
|
|
57
|
-
ethFeedContract.read.latestAnswer(),
|
|
58
|
-
weETHFeedContract.read.latestRoundData(),
|
|
59
|
-
weETHFeedContract.read.decimals(),
|
|
60
|
+
ethFeedContract.read.latestAnswer(setViemBlockNumber(block)),
|
|
61
|
+
weETHFeedContract.read.latestRoundData(setViemBlockNumber(block)),
|
|
62
|
+
weETHFeedContract.read.decimals(setViemBlockNumber(block)),
|
|
60
63
|
]);
|
|
61
64
|
|
|
62
65
|
const ethPrice = new Dec(ethPriceWei.toString()).div(1e8);
|
|
@@ -66,11 +69,11 @@ export const getWeETHPrice = async (client: Client, network: NetworkNumber = Net
|
|
|
66
69
|
return new Dec(ethPrice).mul(weETHRate).toString();
|
|
67
70
|
};
|
|
68
71
|
|
|
69
|
-
export const getWsrETHPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth) => {
|
|
72
|
+
export const getWsrETHPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth, block: Blockish = 'latest') => {
|
|
70
73
|
const feedRegistryContract = DFSFeedRegistryContractViem(client, network);
|
|
71
74
|
const [ethPriceWei, wrsETHRateWei] = await Promise.all([
|
|
72
|
-
feedRegistryContract.read.latestRoundData([getAssetInfo('WETH', network).address as HexString, USD_QUOTE]),
|
|
73
|
-
feedRegistryContract.read.latestRoundData([getAssetInfo('wrsETH', network).address as HexString, getAssetInfo('WETH', network).address as HexString]),
|
|
75
|
+
feedRegistryContract.read.latestRoundData([getAssetInfo('WETH', network).address as HexString, USD_QUOTE], setViemBlockNumber(block)),
|
|
76
|
+
feedRegistryContract.read.latestRoundData([getAssetInfo('wrsETH', network).address as HexString, getAssetInfo('WETH', network).address as HexString], setViemBlockNumber(block)),
|
|
74
77
|
]);
|
|
75
78
|
|
|
76
79
|
const ethPrice = new Dec(ethPriceWei[1].toString()).div(1e8);
|
|
@@ -80,11 +83,11 @@ export const getWsrETHPrice = async (client: Client, network: NetworkNumber = Ne
|
|
|
80
83
|
return new Dec(ethPrice).mul(wrsETHRate).toString();
|
|
81
84
|
};
|
|
82
85
|
|
|
83
|
-
export const getSyrupUSDTPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth) => {
|
|
86
|
+
export const getSyrupUSDTPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth, block: Blockish = 'latest') => {
|
|
84
87
|
const feedRegistryContract = DFSFeedRegistryContractViem(client, network);
|
|
85
88
|
const [usdtPriceWei, syrupUSDTRateWei] = await Promise.all([
|
|
86
|
-
feedRegistryContract.read.latestRoundData([getAssetInfo('USDT', network).address as HexString, USD_QUOTE]),
|
|
87
|
-
feedRegistryContract.read.latestRoundData([getAssetInfo('syrupUSDT', network).address as HexString, getAssetInfo('USDT', network).address as HexString]),
|
|
89
|
+
feedRegistryContract.read.latestRoundData([getAssetInfo('USDT', network).address as HexString, USD_QUOTE], setViemBlockNumber(block)),
|
|
90
|
+
feedRegistryContract.read.latestRoundData([getAssetInfo('syrupUSDT', network).address as HexString, getAssetInfo('USDT', network).address as HexString], setViemBlockNumber(block)),
|
|
88
91
|
]);
|
|
89
92
|
|
|
90
93
|
const usdtPrice = new Dec(usdtPriceWei[1].toString()).div(1e8);
|
|
@@ -94,11 +97,11 @@ export const getSyrupUSDTPrice = async (client: Client, network: NetworkNumber =
|
|
|
94
97
|
return new Dec(usdtPrice).mul(syrupUSDTPrice).toString();
|
|
95
98
|
};
|
|
96
99
|
|
|
97
|
-
export const getWstUSRPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth) => {
|
|
100
|
+
export const getWstUSRPrice = async (client: Client, network: NetworkNumber = NetworkNumber.Eth, block: Blockish = 'latest') => {
|
|
98
101
|
const feedRegistryContract = DFSFeedRegistryContractViem(client, network);
|
|
99
102
|
const [usrPriceWei, wstUSRRateWei] = await Promise.all([
|
|
100
|
-
feedRegistryContract.read.latestRoundData([getAssetInfo('USR', network).address as HexString, USD_QUOTE]),
|
|
101
|
-
feedRegistryContract.read.latestRoundData([getAssetInfo('wstUSR', network).address as HexString, getAssetInfo('USR', network).address as HexString]),
|
|
103
|
+
feedRegistryContract.read.latestRoundData([getAssetInfo('USR', network).address as HexString, USD_QUOTE], setViemBlockNumber(block)),
|
|
104
|
+
feedRegistryContract.read.latestRoundData([getAssetInfo('wstUSR', network).address as HexString, getAssetInfo('USR', network).address as HexString], setViemBlockNumber(block)),
|
|
102
105
|
]);
|
|
103
106
|
|
|
104
107
|
const usrPrice = new Dec(usrPriceWei[1].toString()).div(1e8);
|
|
@@ -248,24 +251,24 @@ export const parseWeETHPriceCalls = (_ethPrice: string, weETHrateAnswer: string,
|
|
|
248
251
|
};
|
|
249
252
|
|
|
250
253
|
// this is a fixed version, the original version is above but requires to refactor comp v3 function, so it's easier to just copy the function for now
|
|
251
|
-
export const getWstETHPriceFluid = async (client: PublicClient, network: NetworkNumber) => {
|
|
254
|
+
export const getWstETHPriceFluid = async (client: PublicClient, network: NetworkNumber, block: Blockish = 'latest') => {
|
|
252
255
|
const calls = getWstETHChainLinkPriceCalls(client, network);
|
|
253
|
-
const results = await client.multicall({ contracts: calls });
|
|
256
|
+
const results = await client.multicall({ contracts: calls, ...setViemBlockNumber(block) });
|
|
254
257
|
// @ts-ignore
|
|
255
258
|
const { ethPrice, wstETHRate } = parseWstETHPriceCalls(results[0].result!.toString(), results[1].result[1]!.toString(), results[2].result!.toString());
|
|
256
259
|
|
|
257
260
|
return new Dec(ethPrice).mul(wstETHRate).toString();
|
|
258
261
|
};
|
|
259
262
|
|
|
260
|
-
export const getBTCPriceForFluid = async (client: PublicClient, network: NetworkNumber) => {
|
|
263
|
+
export const getBTCPriceForFluid = async (client: PublicClient, network: NetworkNumber, block: Blockish = 'latest') => {
|
|
261
264
|
const contract = BTCPriceFeedContractViem(client, network);
|
|
262
|
-
const price = await contract.read.latestAnswer();
|
|
265
|
+
const price = await contract.read.latestAnswer(setViemBlockNumber(block));
|
|
263
266
|
return new Dec(price).div(1e8).toString();
|
|
264
267
|
};
|
|
265
268
|
|
|
266
|
-
export const getEthPriceForFluid = async (client: PublicClient, network: NetworkNumber) => {
|
|
269
|
+
export const getEthPriceForFluid = async (client: PublicClient, network: NetworkNumber, block: Blockish = 'latest') => {
|
|
267
270
|
const contract = ETHPriceFeedContractViem(client, network);
|
|
268
|
-
const price = await contract.read.latestAnswer();
|
|
271
|
+
const price = await contract.read.latestAnswer(setViemBlockNumber(block));
|
|
269
272
|
return new Dec(price).div(1e8).toString();
|
|
270
273
|
};
|
|
271
274
|
|
package/src/services/viem.ts
CHANGED
|
@@ -3,7 +3,9 @@ import {
|
|
|
3
3
|
custom,
|
|
4
4
|
encodeFunctionData,
|
|
5
5
|
type Abi,
|
|
6
|
+
type Client,
|
|
6
7
|
} from 'viem';
|
|
8
|
+
import { getBlock } from 'viem/actions';
|
|
7
9
|
import {
|
|
8
10
|
arbitrum, base, mainnet, optimism, linea, plasma,
|
|
9
11
|
} from 'viem/chains';
|
|
@@ -34,6 +36,20 @@ export const getViemProvider = (provider: EthereumProvider, network: NetworkNumb
|
|
|
34
36
|
...options,
|
|
35
37
|
});
|
|
36
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Unix timestamp (seconds) of the block, for data sources keyed by time rather than block (Merkl
|
|
41
|
+
* reward history). `'latest'` resolves to `undefined` without an RPC call, since live sources need
|
|
42
|
+
* no timestamp. A numeric block costs one `eth_getBlockByNumber` unless the caller already knows
|
|
43
|
+
* its timestamp and passes it — flows that fetch many markets at one block resolve it once and
|
|
44
|
+
* hand it down.
|
|
45
|
+
*/
|
|
46
|
+
export const getBlockTimestamp = async (client: Client, block: Blockish, blockTimestamp?: number): Promise<number | undefined> => {
|
|
47
|
+
if (block === 'latest') return undefined;
|
|
48
|
+
if (blockTimestamp !== undefined) return blockTimestamp;
|
|
49
|
+
const { timestamp } = await getBlock(client, { blockNumber: BigInt(block) });
|
|
50
|
+
return Number(timestamp);
|
|
51
|
+
};
|
|
52
|
+
|
|
37
53
|
export const setViemBlockNumber = (block: Blockish) => {
|
|
38
54
|
if (block === 'latest') return {};
|
|
39
55
|
return { blockNumber: BigInt(block) };
|
package/src/spark/index.ts
CHANGED
|
@@ -62,7 +62,7 @@ export const sparkEmodeCategoriesMapping = (extractedState: { assetsData: SparkA
|
|
|
62
62
|
return categoriesMapping;
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
export const _getSparkMarketsData = async (provider: Client, network: NetworkNumber, selectedMarket: SparkMarketData): Promise<SparkMarketsData> => {
|
|
65
|
+
export const _getSparkMarketsData = async (provider: Client, network: NetworkNumber, selectedMarket: SparkMarketData, blockNumber: Blockish = 'latest'): Promise<SparkMarketsData> => {
|
|
66
66
|
const marketAddress = selectedMarket.providerAddress;
|
|
67
67
|
|
|
68
68
|
const loanInfoContract = SparkViewContractViem(provider, network);
|
|
@@ -70,8 +70,8 @@ export const _getSparkMarketsData = async (provider: Client, network: NetworkNum
|
|
|
70
70
|
|
|
71
71
|
// eslint-disable-next-line prefer-const
|
|
72
72
|
let [loanInfo, rewardInfo] = await Promise.all([
|
|
73
|
-
loanInfoContract.read.getFullTokensInfo([marketAddress, selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address) as EthAddress[]]),
|
|
74
|
-
sparkIncentivesContract.read.getReservesIncentivesData([marketAddress]),
|
|
73
|
+
loanInfoContract.read.getFullTokensInfo([marketAddress, selectedMarket.assets.map(a => getAssetInfo(ethToWeth(a)).address) as EthAddress[]], setViemBlockNumber(blockNumber)),
|
|
74
|
+
sparkIncentivesContract.read.getReservesIncentivesData([marketAddress], setViemBlockNumber(blockNumber)),
|
|
75
75
|
]);
|
|
76
76
|
|
|
77
77
|
rewardInfo = rewardInfo.reduce((all: any, market: any) => {
|
|
@@ -246,7 +246,8 @@ export const getSparkMarketsData = async (
|
|
|
246
246
|
provider: EthereumProvider,
|
|
247
247
|
network: NetworkNumber,
|
|
248
248
|
selectedMarket: SparkMarketData,
|
|
249
|
-
|
|
249
|
+
blockNumber: Blockish = 'latest',
|
|
250
|
+
): Promise<SparkMarketsData> => _getSparkMarketsData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
250
251
|
|
|
251
252
|
export const EMPTY_SPARK_DATA = {
|
|
252
253
|
usedAssets: {},
|
|
@@ -287,6 +288,7 @@ export const _getSparkAccountData = async (
|
|
|
287
288
|
network: NetworkNumber,
|
|
288
289
|
address: EthAddress,
|
|
289
290
|
extractedState: { selectedMarket: SparkMarketData, assetsData: SparkAssetsData, eModeCategoriesData: EModeCategoriesData },
|
|
291
|
+
blockNumber: Blockish = 'latest',
|
|
290
292
|
) => {
|
|
291
293
|
const {
|
|
292
294
|
selectedMarket: market, assetsData,
|
|
@@ -313,9 +315,9 @@ export const _getSparkAccountData = async (
|
|
|
313
315
|
const middleAddressIndex = Math.floor(_addresses.length / 2); // split addresses in half to avoid gas limit by multicall
|
|
314
316
|
|
|
315
317
|
const [userEMode, tokenBalances1, tokenBalances2] = await Promise.all([
|
|
316
|
-
lendingPoolContract.read.getUserEMode([address]),
|
|
317
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(0, middleAddressIndex) as EthAddress[]]),
|
|
318
|
-
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(middleAddressIndex, _addresses.length) as EthAddress[]]),
|
|
318
|
+
lendingPoolContract.read.getUserEMode([address], setViemBlockNumber(blockNumber)),
|
|
319
|
+
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(0, middleAddressIndex) as EthAddress[]], setViemBlockNumber(blockNumber)),
|
|
320
|
+
loanInfoContract.read.getTokenBalances([marketAddress, address, _addresses.slice(middleAddressIndex, _addresses.length) as EthAddress[]], setViemBlockNumber(blockNumber)),
|
|
319
321
|
]);
|
|
320
322
|
|
|
321
323
|
|
|
@@ -406,7 +408,8 @@ export const getSparkAccountData = async (
|
|
|
406
408
|
network: NetworkNumber,
|
|
407
409
|
address: EthAddress,
|
|
408
410
|
extractedState: { selectedMarket: SparkMarketData, assetsData: SparkAssetsData, eModeCategoriesData: EModeCategoriesData },
|
|
409
|
-
|
|
411
|
+
blockNumber: Blockish = 'latest',
|
|
412
|
+
) => _getSparkAccountData(getViemProvider(provider, network), network, address, extractedState, blockNumber);
|
|
410
413
|
|
|
411
414
|
export const getSparkFullPositionData = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, market: SparkMarketData): Promise<SparkPositionData> => {
|
|
412
415
|
const marketData = await getSparkMarketsData(provider, network, market);
|
package/src/staking/staking.ts
CHANGED
|
@@ -65,7 +65,7 @@ export const STAKING_ASSETS = [
|
|
|
65
65
|
'PT sUSDe Nov', 'PT USDe Nov', 'PT USDe Jan', 'PT sUSDe Jan', 'wrsETH', 'wstETH', 'syrupUSDT', 'syrupUSDC', 'wstUSR',
|
|
66
66
|
'PT sUSDe Feb', 'PT USDe Feb', 'PT sUSDe Apr', 'PT USDe Apr', 'PT sUSDe May', 'PT USDe May', 'PT srUSDe Apr', 'GHO',
|
|
67
67
|
'PT sUSDe June', 'PT USDe June', 'PT srUSDe Jun', 'PT srUSDe Oct', 'PT USDG May', 'PT sUSDS Nov', 'PT sUSDe Oct', 'PT USDG Sep',
|
|
68
|
-
'syrupUSDG',
|
|
68
|
+
'syrupUSDG', 'PT USDat Jan',
|
|
69
69
|
];
|
|
70
70
|
|
|
71
71
|
export const getStakingApy = memoize(async (asset: string, network: number = NetworkNumber.Eth) => {
|
|
@@ -114,6 +114,7 @@ export const getStakingApy = memoize(async (asset: string, network: number = Net
|
|
|
114
114
|
if (asset === 'PT USDG May') return await getApyFromDfsApi('PT USDG May', network);
|
|
115
115
|
if (asset === 'PT USDG Sep') return await getApyFromDfsApi('PT USDG Sep', network);
|
|
116
116
|
if (asset === 'PT sUSDS Nov') return await getApyFromDfsApi('PT sUSDS Nov', network);
|
|
117
|
+
if (asset === 'PT USDat Jan') return await getApyFromDfsApi('PT USDat Jan', network);
|
|
117
118
|
if (asset === 'GHO') return await getApyFromDfsApi('GHO', network);
|
|
118
119
|
} catch (e) {
|
|
119
120
|
console.error(`Failed to fetch APY for ${asset}`);
|
package/src/types/aaveV4.ts
CHANGED
package/src/types/common.ts
CHANGED
package/src/types/merkl.ts
CHANGED
|
@@ -114,6 +114,26 @@ export type MerklOpportunity = {
|
|
|
114
114
|
};
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
+
/** One entry of Merkl's campaign listing: a campaign plus the opportunity it rewards. */
|
|
118
|
+
export type MerklCampaignListItem = MerklCampaign & {
|
|
119
|
+
opportunityId: string;
|
|
120
|
+
type: string;
|
|
121
|
+
rewardToken?: MerklOpportunity['rewardsRecord']['breakdowns'][number]['token'];
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** One bucket of an opportunity's APR history (`apr` is the last value recorded in the bucket). */
|
|
125
|
+
export type MerklAprRecord = {
|
|
126
|
+
timestamp: string;
|
|
127
|
+
date: string;
|
|
128
|
+
apr: number;
|
|
129
|
+
open: number;
|
|
130
|
+
min: number;
|
|
131
|
+
max: number;
|
|
132
|
+
avg: number;
|
|
133
|
+
samples: number;
|
|
134
|
+
hasUntrustedContribution: boolean;
|
|
135
|
+
};
|
|
136
|
+
|
|
117
137
|
export type MerkleRewardInfo = { apy: string; rewardTokenSymbol: string, description: string, identifier: string };
|
|
118
138
|
export type MerkleRewardMap = Record<EthAddress, { supply?: MerkleRewardInfo; borrow?: MerkleRewardInfo }>;
|
|
119
139
|
|
package/src/types/morphoBlue.ts
CHANGED
|
@@ -97,6 +97,7 @@ export enum MorphoBlueVersions {
|
|
|
97
97
|
MorphoBlueWstEthEURCV_860 = 'morphobluewstetheurcv_860', // wstETH/EURCV 0.86
|
|
98
98
|
MorphoBlueCbBTCEURCV_860 = 'morphobluecbbtceurcv_860', // cbBTC/EURCV 0.86
|
|
99
99
|
MorphoBlueWBTCEURC_860 = 'morphobluewbtceurc_860', // WBTC/EURC 0.86
|
|
100
|
+
MorphoBluePTUSDatJanUSDC_915 = 'morphoblueptusdatjanusdc_915', // PT-USDat-14JAN2027/USDC 0.915
|
|
100
101
|
|
|
101
102
|
// BASE
|
|
102
103
|
MorphoBlueCbEthUSDC_860_Base = 'morphobluecbethusdc_860_base',
|
package/src/types/portfolio.ts
CHANGED
|
@@ -114,6 +114,46 @@ export interface PortfolioPositionsData {
|
|
|
114
114
|
[key: EthAddress]: PortfolioPositionsDataForAddress;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
export enum PortfolioProtocol {
|
|
118
|
+
AaveV2 = 'aaveV2',
|
|
119
|
+
AaveV3 = 'aaveV3',
|
|
120
|
+
AaveV4 = 'aaveV4',
|
|
121
|
+
CompoundV2 = 'compoundV2',
|
|
122
|
+
CompoundV3 = 'compoundV3',
|
|
123
|
+
Spark = 'spark',
|
|
124
|
+
MorphoBlue = 'morphoBlue',
|
|
125
|
+
MorphoMidnight = 'morphoMidnight',
|
|
126
|
+
CrvUsd = 'crvUsd',
|
|
127
|
+
LlamaLend = 'llamaLend',
|
|
128
|
+
Maker = 'maker',
|
|
129
|
+
Liquity = 'liquity',
|
|
130
|
+
LiquityV2 = 'liquityV2',
|
|
131
|
+
Fluid = 'fluid',
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface CustomDeFiDataOptions {
|
|
135
|
+
/** Defaults to every protocol. */
|
|
136
|
+
protocols?: PortfolioProtocol[];
|
|
137
|
+
fetchStaking?: boolean;
|
|
138
|
+
fetchRewards?: boolean;
|
|
139
|
+
/** Keep Aave V3 / Spark positions with no supply so the eMode category is available. */
|
|
140
|
+
returnEmptyEModePositions?: boolean;
|
|
141
|
+
fetchFluidMarkets?: boolean;
|
|
142
|
+
isSim?: boolean;
|
|
143
|
+
/** viem multicall calldata cap in bytes; defaults to 250k (2k when isSim). */
|
|
144
|
+
batchSize?: number;
|
|
145
|
+
/** Every read is made at this block; defaults to latest. */
|
|
146
|
+
blockNumber?: number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface CustomDeFiData {
|
|
150
|
+
positions: PortfolioPositionsData;
|
|
151
|
+
stakingPositions: Record<string, any>;
|
|
152
|
+
rewardsData: Record<string, any>;
|
|
153
|
+
/** Includes Fluid's and Maker's markets, filled when their protocols (and fetchFluidMarkets) are requested. */
|
|
154
|
+
markets: ShifterPortfolioMarketsData;
|
|
155
|
+
}
|
|
156
|
+
|
|
117
157
|
/**
|
|
118
158
|
* The staking positions getPortfolioData returns for an address. The shapes are uneven, and the DeFi Saver app
|
|
119
159
|
* parses them as they are: a protocol read once per address comes back unwrapped on success, as
|
package/src/umbrella/index.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { Client } from 'viem';
|
|
2
2
|
import { AaveUmbrellaViewViem, AaveV3ViewContractViem } from '../contracts';
|
|
3
|
-
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
|
+
import { Blockish, EthAddress, NetworkNumber } from '../types/common';
|
|
4
4
|
import { UmbrellaStakingData } from '../types/aave';
|
|
5
5
|
import { compareAddresses, convertHybridArraysToObjects, getEthAmountForDecimals } from '../services/utils';
|
|
6
|
+
import { setViemBlockNumber } from '../services/viem';
|
|
6
7
|
import { findMatching, tokenEntries } from './umbrellaUtils';
|
|
7
8
|
|
|
8
9
|
const umbrella = '0xD400fc38ED4732893174325693a63C30ee3881a8';
|
|
9
10
|
const aaveOracle = '0x54586bE62E3c3580375aE3723C145253060Ca0C2';
|
|
10
11
|
|
|
11
|
-
export const getUmbrellaData = async (provider: Client, network: NetworkNumber, address: EthAddress): Promise<UmbrellaStakingData> => {
|
|
12
|
+
export const getUmbrellaData = async (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber: Blockish = 'latest'): Promise<UmbrellaStakingData> => {
|
|
12
13
|
const umbrellaView = AaveUmbrellaViewViem(provider, network);
|
|
13
14
|
const aaveV3View = AaveV3ViewContractViem(provider, network);
|
|
14
15
|
const [tokensAggregatedData, additionalUmbrellaStakingData, userAggregatedData] = await Promise.all([
|
|
15
|
-
umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle]),
|
|
16
|
-
aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address]),
|
|
17
|
-
umbrellaView.read.getUserAggregatedData([umbrella, address]),
|
|
16
|
+
umbrellaView.read.getTokensAggregatedData([umbrella, aaveOracle], setViemBlockNumber(blockNumber)),
|
|
17
|
+
aaveV3View.read.getAdditionalUmbrellaStakingData([umbrella, address], setViemBlockNumber(blockNumber)),
|
|
18
|
+
umbrellaView.read.getUserAggregatedData([umbrella, address], setViemBlockNumber(blockNumber)),
|
|
18
19
|
]);
|
|
19
20
|
|
|
20
21
|
return Object.fromEntries(
|