@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
|
@@ -79,7 +79,7 @@ export const getLiquityV2AggregatedPositionData = ({
|
|
|
79
79
|
payload.leveragedType = leveragedType;
|
|
80
80
|
payload.leveragedAsset = leveragedAsset;
|
|
81
81
|
payload.liquidationPrice = '';
|
|
82
|
-
if (
|
|
82
|
+
if (leveragedAsset !== '') {
|
|
83
83
|
const assetPrice = assetsData[leveragedAsset].price;
|
|
84
84
|
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
85
85
|
}
|
|
@@ -48,7 +48,7 @@ export const getLlamaLendAggregatedData = ({
|
|
|
48
48
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets as unknown as MMUsedAssets);
|
|
49
49
|
payload.leveragedType = leveragedType;
|
|
50
50
|
payload.liquidationPrice = '';
|
|
51
|
-
if (
|
|
51
|
+
if (leveragedAsset !== '') {
|
|
52
52
|
payload.leveragedAsset = leveragedAsset;
|
|
53
53
|
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
54
54
|
}
|
|
@@ -60,7 +60,7 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
60
60
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
61
61
|
payload.leveragedType = leveragedType;
|
|
62
62
|
payload.liquidationPrice = '';
|
|
63
|
-
if (
|
|
63
|
+
if (leveragedAsset !== '') {
|
|
64
64
|
payload.leveragedAsset = leveragedAsset;
|
|
65
65
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
66
66
|
if (leveragedType === LeverageType.VolatilePair) {
|
|
@@ -108,7 +108,7 @@ export const getMorphoMidnightAggregatedPositionData = ({
|
|
|
108
108
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
109
109
|
payload.leveragedType = leveragedType;
|
|
110
110
|
payload.liquidationPrice = '';
|
|
111
|
-
if (
|
|
111
|
+
if (leveragedAsset !== '') {
|
|
112
112
|
payload.leveragedAsset = leveragedAsset;
|
|
113
113
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
114
114
|
if (leveragedType === LeverageType.VolatilePair) {
|
|
@@ -106,7 +106,7 @@ export const sparkGetAggregatedPositionData = ({
|
|
|
106
106
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
107
107
|
payload.leveragedType = leveragedType;
|
|
108
108
|
payload.liquidationPrice = '';
|
|
109
|
-
if (
|
|
109
|
+
if (leveragedAsset !== '') {
|
|
110
110
|
payload.leveragedAsset = leveragedAsset;
|
|
111
111
|
let assetPrice = data.assetsData[leveragedAsset].price; // TODO sparkPrice or price??
|
|
112
112
|
if (leveragedType === LeverageType.VolatilePair) {
|
package/src/liquity/index.ts
CHANGED
|
@@ -50,21 +50,21 @@ export const _getLiquityAccountBalances = async (provider: Client, network: Netw
|
|
|
50
50
|
|
|
51
51
|
export const getLiquityAccountBalances = async (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress): Promise<PositionBalances> => _getLiquityAccountBalances(getViemProvider(provider, network), network, block, addressMapping, address);
|
|
52
52
|
|
|
53
|
-
const _getDebtInFront = async (viewContract: any, address: EthAddress, accumulatedSum = '0', iterations = 2000): Promise<string> => {
|
|
54
|
-
const res = await viewContract.read.getDebtInFront([address, accumulatedSum, iterations]);
|
|
53
|
+
const _getDebtInFront = async (viewContract: any, address: EthAddress, accumulatedSum = '0', iterations = 2000, blockNumber: Blockish = 'latest'): Promise<string> => {
|
|
54
|
+
const res = await viewContract.read.getDebtInFront([address, accumulatedSum, iterations], setViemBlockNumber(blockNumber));
|
|
55
55
|
const debt = res[1].toString();
|
|
56
56
|
const next = res[0];
|
|
57
57
|
if (next === ZERO_ADDRESS) return assetAmountInEth(debt, 'LUSD');
|
|
58
|
-
return _getDebtInFront(viewContract, next, debt, iterations);
|
|
58
|
+
return _getDebtInFront(viewContract, next, debt, iterations, blockNumber);
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
export const getDebtInFront = async (provider: EthereumProvider, address: EthAddress): Promise<string> => {
|
|
61
|
+
export const getDebtInFront = async (provider: EthereumProvider, address: EthAddress, blockNumber: Blockish = 'latest'): Promise<string> => {
|
|
62
62
|
const client = getViemProvider(provider, NetworkNumber.Eth);
|
|
63
63
|
const viewContract = LiquityViewContractViem(client, NetworkNumber.Eth);
|
|
64
|
-
return _getDebtInFront(viewContract, address);
|
|
64
|
+
return _getDebtInFront(viewContract, address, '0', 2000, blockNumber);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNumber, address: EthAddress): Promise<LiquityTroveInfo> => {
|
|
67
|
+
export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber: Blockish = 'latest'): Promise<LiquityTroveInfo> => {
|
|
68
68
|
const viewContract = LiquityViewContractViem(provider, network);
|
|
69
69
|
const collSurplusPoolContract = LiquityCollSurplusPoolContractViem(provider, network);
|
|
70
70
|
const troveManagerContract = LiquityTroveManagerContractViem(provider, network);
|
|
@@ -80,13 +80,13 @@ export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNum
|
|
|
80
80
|
totalLUSD,
|
|
81
81
|
debtInFront,
|
|
82
82
|
] = await Promise.all([
|
|
83
|
-
viewContract.read.getTroveInfo([address]),
|
|
84
|
-
collSurplusPoolContract.read.getCollateral([address]),
|
|
85
|
-
troveManagerContract.read.getBorrowingRateWithDecay(),
|
|
86
|
-
priceFeedContract.read.fetchPrice(),
|
|
87
|
-
activePoolContract.read.getETH(),
|
|
88
|
-
activePoolContract.read.getLUSDDebt(),
|
|
89
|
-
_getDebtInFront(viewContract, address),
|
|
83
|
+
viewContract.read.getTroveInfo([address], setViemBlockNumber(blockNumber)),
|
|
84
|
+
collSurplusPoolContract.read.getCollateral([address], setViemBlockNumber(blockNumber)),
|
|
85
|
+
troveManagerContract.read.getBorrowingRateWithDecay(setViemBlockNumber(blockNumber)),
|
|
86
|
+
priceFeedContract.read.fetchPrice(setViemBlockNumber(blockNumber)),
|
|
87
|
+
activePoolContract.read.getETH(setViemBlockNumber(blockNumber)),
|
|
88
|
+
activePoolContract.read.getLUSDDebt(setViemBlockNumber(blockNumber)),
|
|
89
|
+
_getDebtInFront(viewContract, address, '0', 2000, blockNumber),
|
|
90
90
|
]);
|
|
91
91
|
|
|
92
92
|
const recoveryMode = troveInfo[6];
|
|
@@ -125,9 +125,9 @@ export const _getLiquityTroveInfo = async (provider: Client, network: NetworkNum
|
|
|
125
125
|
return payload;
|
|
126
126
|
};
|
|
127
127
|
|
|
128
|
-
export const getLiquityTroveInfo = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress): Promise<LiquityTroveInfo> => _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address);
|
|
128
|
+
export const getLiquityTroveInfo = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, blockNumber: Blockish = 'latest'): Promise<LiquityTroveInfo> => _getLiquityTroveInfo(getViemProvider(provider, network, { batch: { multicall: true } }), network, address, blockNumber);
|
|
129
129
|
|
|
130
|
-
export const getLiquityStakingData = async (provider: Client, network: NetworkNumber, address: EthAddress): Promise<LiquityStakingData> => {
|
|
130
|
+
export const getLiquityStakingData = async (provider: Client, network: NetworkNumber, address: EthAddress, blockNumber: Blockish = 'latest'): Promise<LiquityStakingData> => {
|
|
131
131
|
const lqtyStakingView = LiquityLQTYStakingViem(provider, network);
|
|
132
132
|
const stabilityPoolView = LiquityStabilityPoolViem(provider, network);
|
|
133
133
|
const [
|
|
@@ -140,14 +140,14 @@ export const getLiquityStakingData = async (provider: Client, network: NetworkNu
|
|
|
140
140
|
compoundedLUSDDeposit,
|
|
141
141
|
totalLUSDDeposits,
|
|
142
142
|
] = await Promise.all([
|
|
143
|
-
lqtyStakingView.read.stakes([address]),
|
|
144
|
-
lqtyStakingView.read.getPendingETHGain([address]),
|
|
145
|
-
lqtyStakingView.read.getPendingLUSDGain([address]),
|
|
146
|
-
lqtyStakingView.read.totalLQTYStaked(),
|
|
147
|
-
stabilityPoolView.read.getDepositorETHGain([address]),
|
|
148
|
-
stabilityPoolView.read.getDepositorLQTYGain([address]),
|
|
149
|
-
stabilityPoolView.read.getCompoundedLUSDDeposit([address]),
|
|
150
|
-
stabilityPoolView.read.getTotalLUSDDeposits(),
|
|
143
|
+
lqtyStakingView.read.stakes([address], setViemBlockNumber(blockNumber)),
|
|
144
|
+
lqtyStakingView.read.getPendingETHGain([address], setViemBlockNumber(blockNumber)),
|
|
145
|
+
lqtyStakingView.read.getPendingLUSDGain([address], setViemBlockNumber(blockNumber)),
|
|
146
|
+
lqtyStakingView.read.totalLQTYStaked(setViemBlockNumber(blockNumber)),
|
|
147
|
+
stabilityPoolView.read.getDepositorETHGain([address], setViemBlockNumber(blockNumber)),
|
|
148
|
+
stabilityPoolView.read.getDepositorLQTYGain([address], setViemBlockNumber(blockNumber)),
|
|
149
|
+
stabilityPoolView.read.getCompoundedLUSDDeposit([address], setViemBlockNumber(blockNumber)),
|
|
150
|
+
stabilityPoolView.read.getTotalLUSDDeposits(setViemBlockNumber(blockNumber)),
|
|
151
151
|
]);
|
|
152
152
|
const totalLUSDDeposited = getEthAmountForDecimals(totalLUSDDeposits as string, 18);
|
|
153
153
|
const totalLQTYStaked = getEthAmountForDecimals(totalLQTYStakes as string, 18);
|
package/src/liquityV2/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
LiquityV2ViewContractViem,
|
|
10
10
|
} from '../contracts';
|
|
11
11
|
import {
|
|
12
|
-
EthAddress, EthereumProvider, IncentiveKind, NetworkNumber, HexString,
|
|
12
|
+
Blockish, EthAddress, EthereumProvider, IncentiveKind, NetworkNumber, HexString,
|
|
13
13
|
} from '../types/common';
|
|
14
14
|
import {
|
|
15
15
|
LIQUITY_V2_TROVE_STATUS_ENUM,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from '../services/utils';
|
|
28
28
|
import { SECONDS_PER_YEAR, ZERO_ADDRESS } from '../constants';
|
|
29
29
|
import { LiquityV2Markets } from '../markets';
|
|
30
|
-
import { getViemProvider } from '../services/viem';
|
|
30
|
+
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
31
31
|
|
|
32
32
|
export type SPYieldGainParameters = {
|
|
33
33
|
P: string;
|
|
@@ -44,13 +44,13 @@ const getLiquityV2ViewContract = (provider: Client, network: NetworkNumber, isLe
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
export const _getLiquityV2MarketData = async (provider: Client, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo): Promise<LiquityV2MarketData> => {
|
|
47
|
+
export const _getLiquityV2MarketData = async (provider: Client, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, blockNumber: Blockish = 'latest'): Promise<LiquityV2MarketData> => {
|
|
48
48
|
const {
|
|
49
49
|
marketAddress, debtToken, collateralToken, isLegacy,
|
|
50
50
|
} = selectedMarket;
|
|
51
51
|
const data = isLegacy
|
|
52
|
-
? await LiquityV2LegacyViewContractViem(provider, network).read.getMarketData([marketAddress])
|
|
53
|
-
: (await LiquityV2ViewContractViem(provider, network).simulate.getMarketData([marketAddress])).result;
|
|
52
|
+
? await LiquityV2LegacyViewContractViem(provider, network).read.getMarketData([marketAddress], setViemBlockNumber(blockNumber))
|
|
53
|
+
: (await LiquityV2ViewContractViem(provider, network).simulate.getMarketData([marketAddress], setViemBlockNumber(blockNumber))).result;
|
|
54
54
|
const hintHelperAddress = data.hintHelpers;
|
|
55
55
|
const troveNFTAddress = data.troveNFT;
|
|
56
56
|
const borrowerOperationsAddress = data.borrowerOperations;
|
|
@@ -133,7 +133,8 @@ export const getLiquityV2MarketData = async (
|
|
|
133
133
|
provider: EthereumProvider,
|
|
134
134
|
network: NetworkNumber,
|
|
135
135
|
selectedMarket: LiquityV2MarketInfo,
|
|
136
|
-
|
|
136
|
+
blockNumber: Blockish = 'latest',
|
|
137
|
+
): Promise<LiquityV2MarketData> => _getLiquityV2MarketData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
137
138
|
|
|
138
139
|
const getUserTroves = async (
|
|
139
140
|
provider: Client,
|
|
@@ -144,14 +145,15 @@ const getUserTroves = async (
|
|
|
144
145
|
startIndex = 0,
|
|
145
146
|
endIndex = 100,
|
|
146
147
|
troves: { troveId: string, ownedByUser: boolean }[] = [],
|
|
148
|
+
blockNumber: Blockish = 'latest',
|
|
147
149
|
): Promise<{ troves: { troveId: string, ownedByUser: boolean }[], nextFreeTroveIndex: string }> => {
|
|
148
150
|
const viewContract = getLiquityV2ViewContract(provider, network, isLegacy);
|
|
149
|
-
const result = await viewContract.read.getUserTroves([account, marketAddress, BigInt(startIndex), BigInt(endIndex)]);
|
|
151
|
+
const result = await viewContract.read.getUserTroves([account, marketAddress, BigInt(startIndex), BigInt(endIndex)], setViemBlockNumber(blockNumber));
|
|
150
152
|
const newStartIndex = endIndex + 1;
|
|
151
153
|
const nextFreeTroveIndex = result[1].toString();
|
|
152
154
|
const existingTroves = [...troves, ...result[0].map((trove: any) => ({ ...trove, troveId: trove.troveId.toString() }))];
|
|
153
155
|
if (nextFreeTroveIndex !== '-1') return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
|
|
154
|
-
return getUserTroves(provider, network, isLegacy, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
156
|
+
return getUserTroves(provider, network, isLegacy, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves, blockNumber);
|
|
155
157
|
};
|
|
156
158
|
|
|
157
159
|
export const nftContractCreationBlockMapping = {
|
|
@@ -244,13 +246,14 @@ const getDebtInFrontForSingleMarketLiquityV2 = async (
|
|
|
244
246
|
troveId: string,
|
|
245
247
|
accumulatedSum = '0',
|
|
246
248
|
iterations = 2000,
|
|
249
|
+
blockNumber: Blockish = 'latest',
|
|
247
250
|
): Promise<string> => {
|
|
248
251
|
const viewContract = getLiquityV2ViewContract(provider, network, isLegacy);
|
|
249
|
-
const res = await viewContract.read.getDebtInFront([marketAddress, BigInt(troveId), BigInt(accumulatedSum), BigInt(iterations)]);
|
|
252
|
+
const res = await viewContract.read.getDebtInFront([marketAddress, BigInt(troveId), BigInt(accumulatedSum), BigInt(iterations)], setViemBlockNumber(blockNumber));
|
|
250
253
|
const next = res[0].toString();
|
|
251
254
|
const debt = res[1].toString();
|
|
252
255
|
if (next === '0') return assetAmountInEth(debt);
|
|
253
|
-
return getDebtInFrontForSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, next, debt, iterations);
|
|
256
|
+
return getDebtInFrontForSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, next, debt, iterations, blockNumber);
|
|
254
257
|
};
|
|
255
258
|
|
|
256
259
|
const getDebtInFrontForInterestRateSingleMarketLiquityV2 = async (
|
|
@@ -262,31 +265,32 @@ const getDebtInFrontForInterestRateSingleMarketLiquityV2 = async (
|
|
|
262
265
|
troveId = '0',
|
|
263
266
|
accumulatedSum = '0',
|
|
264
267
|
iterations = 2000,
|
|
268
|
+
blockNumber: Blockish = 'latest',
|
|
265
269
|
): Promise<string> => {
|
|
266
270
|
const viewContract = getLiquityV2ViewContract(provider, network, isLegacy);
|
|
267
271
|
if (+interestRate === 0 || !interestRate) return '0';
|
|
268
272
|
const interestRateWei = new Dec(interestRate).times(1e16).toFixed(0).toString();
|
|
269
|
-
const res = await viewContract.read.getDebtInFrontByInterestRate([marketAddress, BigInt(troveId), BigInt(accumulatedSum), BigInt(iterations), BigInt(interestRateWei)]);
|
|
273
|
+
const res = await viewContract.read.getDebtInFrontByInterestRate([marketAddress, BigInt(troveId), BigInt(accumulatedSum), BigInt(iterations), BigInt(interestRateWei)], setViemBlockNumber(blockNumber));
|
|
270
274
|
const next = res[0].toString();
|
|
271
275
|
const debt = res[1].toString();
|
|
272
276
|
if (next === '0') return assetAmountInEth(debt);
|
|
273
|
-
return getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, interestRate, next, debt, iterations);
|
|
277
|
+
return getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, interestRate, next, debt, iterations, blockNumber);
|
|
274
278
|
};
|
|
275
279
|
|
|
276
|
-
const getUnbackedDebtForSingleMarket = async (totalBorrowed: string, provider: Client, network: NetworkNumber, stabilityPoolAddress: EthAddress) => {
|
|
280
|
+
const getUnbackedDebtForSingleMarket = async (totalBorrowed: string, provider: Client, network: NetworkNumber, stabilityPoolAddress: EthAddress, blockNumber: Blockish = 'latest') => {
|
|
277
281
|
const stabilityPoolContract = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddress)(provider, network);
|
|
278
|
-
const totalBoldDeposits = await stabilityPoolContract.read.getTotalBoldDeposits();
|
|
282
|
+
const totalBoldDeposits = await stabilityPoolContract.read.getTotalBoldDeposits(setViemBlockNumber(blockNumber));
|
|
279
283
|
const totalBoldDepositsInEth = assetAmountInEth(totalBoldDeposits.toString());
|
|
280
284
|
|
|
281
285
|
return Dec.max(new Dec(totalBorrowed).sub(totalBoldDepositsInEth), 0).toString();
|
|
282
286
|
};
|
|
283
287
|
|
|
284
|
-
const getAllMarketsUnbackedDebts = async (markets: Record<LiquityV2Versions, LiquityV2MarketData>, isLegacy: boolean, provider: Client, network: NetworkNumber): Promise<Record<LiquityV2Versions, string>> => {
|
|
288
|
+
const getAllMarketsUnbackedDebts = async (markets: Record<LiquityV2Versions, LiquityV2MarketData>, isLegacy: boolean, provider: Client, network: NetworkNumber, blockNumber: Blockish = 'latest'): Promise<Record<LiquityV2Versions, string>> => {
|
|
285
289
|
const allMarketsUnbackedDebt = await Promise.all(Object.entries(markets).map(async ([version, market]) => {
|
|
286
290
|
const { assetsData, marketData } = market;
|
|
287
291
|
const { debtToken, isLegacy: isLegacyMarket } = LiquityV2Markets(network)[version as LiquityV2Versions];
|
|
288
292
|
if (isLegacyMarket !== isLegacy) return [version, '0'];
|
|
289
|
-
const unbackedDebt = await getUnbackedDebtForSingleMarket(assetsData[debtToken].totalBorrow, provider, network, marketData.stabilityPoolAddress);
|
|
293
|
+
const unbackedDebt = await getUnbackedDebtForSingleMarket(assetsData[debtToken].totalBorrow, provider, network, marketData.stabilityPoolAddress, blockNumber);
|
|
290
294
|
return [version, unbackedDebt];
|
|
291
295
|
}));
|
|
292
296
|
|
|
@@ -345,23 +349,23 @@ export const calculateDebtInFrontLiquityV2 = (markets: Record<LiquityV2Versions,
|
|
|
345
349
|
// @dev The amount redeemed on each branch depends on the unbacked debt of every branch (the difference between total borrow and stability pool deposits).
|
|
346
350
|
// When new debt is generated on the selected market, the unbacked debt will increase, resulting in a higher redemption amount on that branch.
|
|
347
351
|
// This function accepts the new debt that's about to be generated (e.g., trove creation) and estimates the debt in front based on the new state.
|
|
348
|
-
export const getDebtInFrontForInterestRateIncludingNewDebtLiquityV2 = async (newDebt: string, markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, interestRate: string) => {
|
|
352
|
+
export const getDebtInFrontForInterestRateIncludingNewDebtLiquityV2 = async (newDebt: string, markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, interestRate: string, blockNumber: Blockish = 'latest') => {
|
|
349
353
|
const marketsWithNewDebt = structuredClone(markets);
|
|
350
354
|
const selectedMarketDebtToken = LiquityV2Markets(network)[selectedMarket].debtToken;
|
|
351
355
|
const currentTotalBorrow = new Dec(marketsWithNewDebt[selectedMarket].assetsData[selectedMarketDebtToken].totalBorrow);
|
|
352
356
|
marketsWithNewDebt[selectedMarket].assetsData[selectedMarketDebtToken].totalBorrow = currentTotalBorrow.add(newDebt).toString();
|
|
353
357
|
|
|
354
358
|
const { isLegacy } = LiquityV2Markets(NetworkNumber.Eth)[selectedMarket];
|
|
355
|
-
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(marketsWithNewDebt, isLegacy, provider, network);
|
|
356
|
-
const interestRateDebtInFront = new Dec(await getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, LiquityV2Markets(network)[selectedMarket].marketAddress, interestRate));
|
|
359
|
+
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(marketsWithNewDebt, isLegacy, provider, network, blockNumber);
|
|
360
|
+
const interestRateDebtInFront = new Dec(await getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, LiquityV2Markets(network)[selectedMarket].marketAddress, interestRate, '0', '0', 2000, blockNumber));
|
|
357
361
|
|
|
358
362
|
return calculateDebtInFrontLiquityV2(marketsWithNewDebt, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
359
363
|
};
|
|
360
364
|
|
|
361
|
-
const getDebtInFrontLiquityV2 = async (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, viewContract: any, troveId: string) => {
|
|
365
|
+
const getDebtInFrontLiquityV2 = async (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, viewContract: any, troveId: string, blockNumber: Blockish = 'latest') => {
|
|
362
366
|
const { isLegacy } = LiquityV2Markets(NetworkNumber.Eth)[selectedMarket];
|
|
363
|
-
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(markets, isLegacy, provider, network);
|
|
364
|
-
const interestRateDebtInFront = await getDebtInFrontForSingleMarketLiquityV2(provider, network, isLegacy, LiquityV2Markets(network)[selectedMarket].marketAddress, troveId);
|
|
367
|
+
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(markets, isLegacy, provider, network, blockNumber);
|
|
368
|
+
const interestRateDebtInFront = await getDebtInFrontForSingleMarketLiquityV2(provider, network, isLegacy, LiquityV2Markets(network)[selectedMarket].marketAddress, troveId, '0', 2000, blockNumber);
|
|
365
369
|
|
|
366
370
|
return calculateDebtInFrontLiquityV2(markets, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
367
371
|
};
|
|
@@ -375,9 +379,9 @@ const getDebtInFrontLiquityV2 = async (markets: Record<LiquityV2Versions, Liquit
|
|
|
375
379
|
* @param interestRate
|
|
376
380
|
* @param debtInFrontBeingMoved - amound of debt being repositioned if interest rate is being increased (prevents including it as debt in front)
|
|
377
381
|
*/
|
|
378
|
-
const _getDebtInFrontForInterestRateLiquityV2 = async (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, isLegacy: boolean, interestRate: string, debtInFrontBeingMoved: string = '0') => {
|
|
379
|
-
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(markets, isLegacy, provider, network);
|
|
380
|
-
const interestRateDebtInFront = new Dec(await getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, LiquityV2Markets(network)[selectedMarket].marketAddress, interestRate))
|
|
382
|
+
const _getDebtInFrontForInterestRateLiquityV2 = async (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, isLegacy: boolean, interestRate: string, debtInFrontBeingMoved: string = '0', blockNumber: Blockish = 'latest') => {
|
|
383
|
+
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(markets, isLegacy, provider, network, blockNumber);
|
|
384
|
+
const interestRateDebtInFront = new Dec(await getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, LiquityV2Markets(network)[selectedMarket].marketAddress, interestRate, '0', '0', 2000, blockNumber))
|
|
381
385
|
.sub(debtInFrontBeingMoved);
|
|
382
386
|
|
|
383
387
|
return calculateDebtInFrontLiquityV2(markets, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
@@ -391,7 +395,8 @@ export const getDebtInFrontForInterestRateLiquityV2 = async (
|
|
|
391
395
|
isLegacy: boolean,
|
|
392
396
|
interestRate: string,
|
|
393
397
|
debtInFrontBeingMoved: string = '0',
|
|
394
|
-
|
|
398
|
+
blockNumber: Blockish = 'latest',
|
|
399
|
+
) => _getDebtInFrontForInterestRateLiquityV2(markets, selectedMarket, getViemProvider(provider, network), network, isLegacy, interestRate, debtInFrontBeingMoved, blockNumber);
|
|
395
400
|
|
|
396
401
|
export const _getLiquityV2TroveData = async (
|
|
397
402
|
provider: Client,
|
|
@@ -409,17 +414,18 @@ export const _getLiquityV2TroveData = async (
|
|
|
409
414
|
allMarketsData: Record<LiquityV2Versions, LiquityV2MarketData>,
|
|
410
415
|
},
|
|
411
416
|
fetchDebtInFront: boolean = true,
|
|
417
|
+
blockNumber: Blockish = 'latest',
|
|
412
418
|
): Promise<LiquityV2TroveData> => {
|
|
413
419
|
const { minCollRatio, batchCollRatio } = allMarketsData[selectedMarket.value].marketData;
|
|
414
420
|
const { collateralToken, marketAddress, debtToken } = selectedMarket;
|
|
415
421
|
const troveInfoPromise = selectedMarket.isLegacy
|
|
416
|
-
? LiquityV2LegacyViewContractViem(provider, network).read.getTroveInfo([marketAddress, BigInt(troveId)])
|
|
422
|
+
? LiquityV2LegacyViewContractViem(provider, network).read.getTroveInfo([marketAddress, BigInt(troveId)], setViemBlockNumber(blockNumber))
|
|
417
423
|
: LiquityV2ViewContractViem(provider, network).simulate
|
|
418
|
-
.getTroveInfo([marketAddress, BigInt(troveId)])
|
|
424
|
+
.getTroveInfo([marketAddress, BigInt(troveId)], setViemBlockNumber(blockNumber))
|
|
419
425
|
.then(({ result }) => result);
|
|
420
426
|
const [_data, debtInFront] = await Promise.all([
|
|
421
427
|
troveInfoPromise,
|
|
422
|
-
fetchDebtInFront ? getDebtInFrontLiquityV2(allMarketsData, selectedMarket.value, provider, network, selectedMarket.isLegacy, troveId) : Promise.resolve('0'),
|
|
428
|
+
fetchDebtInFront ? getDebtInFrontLiquityV2(allMarketsData, selectedMarket.value, provider, network, selectedMarket.isLegacy, troveId, blockNumber) : Promise.resolve('0'),
|
|
423
429
|
]);
|
|
424
430
|
const data = {
|
|
425
431
|
..._data,
|
|
@@ -495,6 +501,7 @@ export const getLiquityV2TroveData = async (
|
|
|
495
501
|
allMarketsData: Record<LiquityV2Versions, LiquityV2MarketData>,
|
|
496
502
|
},
|
|
497
503
|
fetchDebtInFront: boolean = true,
|
|
504
|
+
blockNumber: Blockish = 'latest',
|
|
498
505
|
): Promise<LiquityV2TroveData> => _getLiquityV2TroveData(
|
|
499
506
|
getViemProvider(provider, network),
|
|
500
507
|
network,
|
|
@@ -505,12 +512,13 @@ export const getLiquityV2TroveData = async (
|
|
|
505
512
|
allMarketsData,
|
|
506
513
|
},
|
|
507
514
|
fetchDebtInFront,
|
|
515
|
+
blockNumber,
|
|
508
516
|
);
|
|
509
517
|
|
|
510
|
-
export const getLiquityV2ClaimableCollateral = async (collSurplusPoolAddress: EthAddress, account: EthAddress, provider: EthereumProvider, network: NetworkNumber): Promise<string> => {
|
|
518
|
+
export const getLiquityV2ClaimableCollateral = async (collSurplusPoolAddress: EthAddress, account: EthAddress, provider: EthereumProvider, network: NetworkNumber, blockNumber: Blockish = 'latest'): Promise<string> => {
|
|
511
519
|
const client = getViemProvider(provider, network);
|
|
512
520
|
const collSurplusPoolContract = createViemContractFromConfigFunc('LiquityV2CollSurplusPool', collSurplusPoolAddress)(client, network);
|
|
513
|
-
const claimableCollateral = await collSurplusPoolContract.read.getCollateral([account]);
|
|
521
|
+
const claimableCollateral = await collSurplusPoolContract.read.getCollateral([account], setViemBlockNumber(blockNumber));
|
|
514
522
|
return claimableCollateral.toString();
|
|
515
523
|
};
|
|
516
524
|
|
|
@@ -607,7 +615,7 @@ const calculateSPApy = (
|
|
|
607
615
|
return apy;
|
|
608
616
|
};
|
|
609
617
|
|
|
610
|
-
export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress): Promise<LiquityV2StakingData> => {
|
|
618
|
+
export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress, blockNumber: Blockish = 'latest'): Promise<LiquityV2StakingData> => {
|
|
611
619
|
const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
|
|
612
620
|
const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
|
|
613
621
|
|
|
@@ -627,17 +635,17 @@ export const getLiquityV2Staking = async (provider: Client, network: NetworkNumb
|
|
|
627
635
|
aggWeightedDebtSum,
|
|
628
636
|
lastAggUpdateTime,
|
|
629
637
|
] = await Promise.all([
|
|
630
|
-
stabilityPoolView.read.getDepositorCollGain([user]),
|
|
631
|
-
stabilityPoolView.read.getDepositorYieldGain([user]),
|
|
632
|
-
stabilityPoolView.read.getCompoundedBoldDeposit([user]),
|
|
633
|
-
stabilityPoolView.read.getTotalBoldDeposits(),
|
|
634
|
-
stabilityPoolView.read.P(),
|
|
635
|
-
stabilityPoolView.read.currentScale(),
|
|
636
|
-
stabilityPoolView.read.getYieldGainsPending(),
|
|
637
|
-
debtTokenContract.read.balanceOf([user]),
|
|
638
|
-
|
|
639
|
-
activePoolView.read.aggWeightedDebtSum(),
|
|
640
|
-
activePoolView.read.lastAggUpdateTime(),
|
|
638
|
+
stabilityPoolView.read.getDepositorCollGain([user], setViemBlockNumber(blockNumber)),
|
|
639
|
+
stabilityPoolView.read.getDepositorYieldGain([user], setViemBlockNumber(blockNumber)),
|
|
640
|
+
stabilityPoolView.read.getCompoundedBoldDeposit([user], setViemBlockNumber(blockNumber)),
|
|
641
|
+
stabilityPoolView.read.getTotalBoldDeposits(setViemBlockNumber(blockNumber)),
|
|
642
|
+
stabilityPoolView.read.P(setViemBlockNumber(blockNumber)),
|
|
643
|
+
stabilityPoolView.read.currentScale(setViemBlockNumber(blockNumber)),
|
|
644
|
+
stabilityPoolView.read.getYieldGainsPending(setViemBlockNumber(blockNumber)),
|
|
645
|
+
debtTokenContract.read.balanceOf([user], setViemBlockNumber(blockNumber)),
|
|
646
|
+
|
|
647
|
+
activePoolView.read.aggWeightedDebtSum(setViemBlockNumber(blockNumber)),
|
|
648
|
+
activePoolView.read.lastAggUpdateTime(setViemBlockNumber(blockNumber)),
|
|
641
649
|
]);
|
|
642
650
|
|
|
643
651
|
const stabilityPoolYieldParams: SPYieldGainParameters = {
|
|
@@ -666,7 +674,7 @@ export const getLiquityV2Staking = async (provider: Client, network: NetworkNumb
|
|
|
666
674
|
};
|
|
667
675
|
};
|
|
668
676
|
|
|
669
|
-
export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress): Promise<LiquityV2SBoldYBoldData> => {
|
|
677
|
+
export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress, blockNumber: Blockish = 'latest'): Promise<LiquityV2SBoldYBoldData> => {
|
|
670
678
|
const sBold = LiquityV2sBoldVaultViem(provider, network);
|
|
671
679
|
const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
|
|
672
680
|
const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
|
|
@@ -695,22 +703,22 @@ export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumb
|
|
|
695
703
|
yBoldBalance,
|
|
696
704
|
stYBoldBalance,
|
|
697
705
|
] = await Promise.all([
|
|
698
|
-
sBold.read.totalAssets(),
|
|
699
|
-
sBold.read.convertToShares([BigInt(1e18)]),
|
|
700
|
-
sBold.read.maxWithdraw([user]),
|
|
706
|
+
sBold.read.totalAssets(setViemBlockNumber(blockNumber)),
|
|
707
|
+
sBold.read.convertToShares([BigInt(1e18)], setViemBlockNumber(blockNumber)),
|
|
708
|
+
sBold.read.maxWithdraw([user], setViemBlockNumber(blockNumber)),
|
|
701
709
|
|
|
702
|
-
sBold.read.sps([BigInt(0)]),
|
|
703
|
-
sBold.read.sps([BigInt(1)]),
|
|
704
|
-
sBold.read.sps([BigInt(2)]),
|
|
710
|
+
sBold.read.sps([BigInt(0)], setViemBlockNumber(blockNumber)),
|
|
711
|
+
sBold.read.sps([BigInt(1)], setViemBlockNumber(blockNumber)),
|
|
712
|
+
sBold.read.sps([BigInt(2)], setViemBlockNumber(blockNumber)),
|
|
705
713
|
|
|
706
|
-
yBold.read.totalAssets(),
|
|
707
|
-
yBold.read.maxWithdraw([user]),
|
|
708
|
-
stYBold.read.convertToShares([BigInt(1e18)]),
|
|
714
|
+
yBold.read.totalAssets(setViemBlockNumber(blockNumber)),
|
|
715
|
+
yBold.read.maxWithdraw([user], setViemBlockNumber(blockNumber)),
|
|
716
|
+
stYBold.read.convertToShares([BigInt(1e18)], setViemBlockNumber(blockNumber)),
|
|
709
717
|
getYBoldApyApi(),
|
|
710
718
|
|
|
711
|
-
sBold.read.balanceOf([user]),
|
|
712
|
-
yBold.read.balanceOf([user]),
|
|
713
|
-
stYBold.read.balanceOf([user]),
|
|
719
|
+
sBold.read.balanceOf([user], setViemBlockNumber(blockNumber)),
|
|
720
|
+
yBold.read.balanceOf([user], setViemBlockNumber(blockNumber)),
|
|
721
|
+
stYBold.read.balanceOf([user], setViemBlockNumber(blockNumber)),
|
|
714
722
|
]);
|
|
715
723
|
|
|
716
724
|
const spMarketRes = {
|
package/src/llamaLend/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { getLlamaLendMarketFromControllerAddress } from '../markets/llamaLend';
|
|
|
15
15
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
16
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
17
17
|
|
|
18
|
-
const getAndFormatBands = async (provider: Client, network: NetworkNumber, selectedMarket: LlamaLendMarketData, _minBand: string, _maxBand: string) => {
|
|
18
|
+
const getAndFormatBands = async (provider: Client, network: NetworkNumber, selectedMarket: LlamaLendMarketData, _minBand: string, _maxBand: string, blockNumber: Blockish = 'latest') => {
|
|
19
19
|
const contract = LlamaLendViewContractViem(provider, network);
|
|
20
20
|
const minBand = parseInt(_minBand, 10);
|
|
21
21
|
const maxBand = parseInt(_maxBand, 10);
|
|
@@ -39,7 +39,7 @@ const getAndFormatBands = async (provider: Client, network: NetworkNumber, selec
|
|
|
39
39
|
} else {
|
|
40
40
|
start = pivots[index - 1] + 1;
|
|
41
41
|
}
|
|
42
|
-
const pivotedBandsData = await contract.read.getBandsData([selectedMarket.controllerAddress, BigInt(start), BigInt(pivot)]);
|
|
42
|
+
const pivotedBandsData = await contract.read.getBandsData([selectedMarket.controllerAddress, BigInt(start), BigInt(pivot)], setViemBlockNumber(blockNumber));
|
|
43
43
|
return pivotedBandsData;
|
|
44
44
|
}))).flat();
|
|
45
45
|
|
|
@@ -52,13 +52,13 @@ const getAndFormatBands = async (provider: Client, network: NetworkNumber, selec
|
|
|
52
52
|
}));
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
export const _getLlamaLendGlobalData = async (provider: Client, network: NetworkNumber, selectedMarket: LlamaLendMarketData): Promise<LlamaLendGlobalMarketData> => {
|
|
55
|
+
export const _getLlamaLendGlobalData = async (provider: Client, network: NetworkNumber, selectedMarket: LlamaLendMarketData, blockNumber: Blockish = 'latest'): Promise<LlamaLendGlobalMarketData> => {
|
|
56
56
|
const contract = LlamaLendViewContractViem(provider, network);
|
|
57
57
|
|
|
58
58
|
const collAsset = selectedMarket.collAsset;
|
|
59
59
|
const debtAsset = selectedMarket.baseAsset;
|
|
60
60
|
|
|
61
|
-
const data = await contract.read.globalData([selectedMarket.controllerAddress]);
|
|
61
|
+
const data = await contract.read.globalData([selectedMarket.controllerAddress], setViemBlockNumber(blockNumber));
|
|
62
62
|
|
|
63
63
|
// all prices are in 18 decimals
|
|
64
64
|
const oraclePrice = getEthAmountForDecimals(data.oraclePrice.toString(), 18);
|
|
@@ -82,7 +82,7 @@ export const _getLlamaLendGlobalData = async (provider: Client, network: Network
|
|
|
82
82
|
const futureBorrowRate = new Dec(new Dec(2.718281828459).pow(exponentFutureRate).minus(1)).mul(100)
|
|
83
83
|
.toString();
|
|
84
84
|
|
|
85
|
-
const bandsData = await getAndFormatBands(provider, network, selectedMarket, data.minBand.toString(), data.maxBand.toString());
|
|
85
|
+
const bandsData = await getAndFormatBands(provider, network, selectedMarket, data.minBand.toString(), data.maxBand.toString(), blockNumber);
|
|
86
86
|
const cap = assetAmountInEth(data.debtTokenTotalSupply.toString(), debtAsset);
|
|
87
87
|
const leftToBorrow = getEthAmountForDecimals(data.debtTokenLeftToBorrow.toString(), 18);
|
|
88
88
|
|
|
@@ -152,7 +152,8 @@ export const getLlamaLendGlobalData = async (
|
|
|
152
152
|
provider: EthereumProvider,
|
|
153
153
|
network: NetworkNumber,
|
|
154
154
|
selectedMarket: LlamaLendMarketData,
|
|
155
|
-
|
|
155
|
+
blockNumber: Blockish = 'latest',
|
|
156
|
+
): Promise<LlamaLendGlobalMarketData> => _getLlamaLendGlobalData(getViemProvider(provider, network), network, selectedMarket, blockNumber);
|
|
156
157
|
|
|
157
158
|
const getStatusForUser = (bandRange: string[], activeBand: string, debtSupplied: string, collSupplied: string, healthPercent: string) => {
|
|
158
159
|
// if bands are equal, that can only be [0,0] which means user doesn't have loan (min number of bands is 4)
|
|
@@ -209,11 +210,11 @@ export const getLlamaLendAccountBalances = async (
|
|
|
209
210
|
controllerAddress: EthAddress,
|
|
210
211
|
): Promise<PositionBalances> => _getLlamaLendAccountBalances(getViemProvider(provider, network), network, block, addressMapping, address, controllerAddress);
|
|
211
212
|
|
|
212
|
-
export const _getLlamaLendUserData = async (provider: Client, network: NetworkNumber, address: EthAddress, selectedMarket: LlamaLendMarketData, marketData: LlamaLendGlobalMarketData): Promise<LlamaLendUserData> => {
|
|
213
|
+
export const _getLlamaLendUserData = async (provider: Client, network: NetworkNumber, address: EthAddress, selectedMarket: LlamaLendMarketData, marketData: LlamaLendGlobalMarketData, blockNumber: Blockish = 'latest'): Promise<LlamaLendUserData> => {
|
|
213
214
|
const contract = LlamaLendViewContractViem(provider, network);
|
|
214
215
|
const { assetsData } = marketData;
|
|
215
216
|
|
|
216
|
-
const data = await contract.read.userData([selectedMarket.controllerAddress, address]);
|
|
217
|
+
const data = await contract.read.userData([selectedMarket.controllerAddress, address], setViemBlockNumber(blockNumber));
|
|
217
218
|
const collAsset = selectedMarket.collAsset;
|
|
218
219
|
const debtAsset = selectedMarket.baseAsset;
|
|
219
220
|
|
|
@@ -267,7 +268,7 @@ export const _getLlamaLendUserData = async (provider: Client, network: NetworkNu
|
|
|
267
268
|
const priceHigh = assetAmountInEth(data.priceHigh.toString());
|
|
268
269
|
const priceLow = assetAmountInEth(data.priceLow.toString());
|
|
269
270
|
|
|
270
|
-
const _userBands = data.loanExists ? (await getAndFormatBands(provider, network, selectedMarket, data.bandRange[0].toString(), data.bandRange[1].toString())) : [];
|
|
271
|
+
const _userBands = data.loanExists ? (await getAndFormatBands(provider, network, selectedMarket, data.bandRange[0].toString(), data.bandRange[1].toString(), blockNumber)) : [];
|
|
271
272
|
|
|
272
273
|
const status = data.loanExists ? getStatusForUser(data.bandRange.map(b => b.toString()), marketData.activeBand, debtSupplied, collSupplied, healthPercent) : LlamaLendStatus.Nonexistant;
|
|
273
274
|
|
|
@@ -301,10 +302,11 @@ export const getLlamaLendUserData = async (
|
|
|
301
302
|
address: EthAddress,
|
|
302
303
|
selectedMarket: LlamaLendMarketData,
|
|
303
304
|
marketData: LlamaLendGlobalMarketData,
|
|
304
|
-
|
|
305
|
+
blockNumber: Blockish = 'latest',
|
|
306
|
+
): Promise<LlamaLendUserData> => _getLlamaLendUserData(getViemProvider(provider, network), network, address, selectedMarket, marketData, blockNumber);
|
|
305
307
|
|
|
306
|
-
export const getLlamaLendFullPositionData = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, selectedMarket: LlamaLendMarketData): Promise<LlamaLendUserData> => {
|
|
307
|
-
const marketData = await getLlamaLendGlobalData(provider, network, selectedMarket);
|
|
308
|
-
const positionData = await getLlamaLendUserData(provider, network, address, selectedMarket, marketData);
|
|
308
|
+
export const getLlamaLendFullPositionData = async (provider: EthereumProvider, network: NetworkNumber, address: EthAddress, selectedMarket: LlamaLendMarketData, blockNumber: Blockish = 'latest'): Promise<LlamaLendUserData> => {
|
|
309
|
+
const marketData = await getLlamaLendGlobalData(provider, network, selectedMarket, blockNumber);
|
|
310
|
+
const positionData = await getLlamaLendUserData(provider, network, address, selectedMarket, marketData, blockNumber);
|
|
309
311
|
return positionData;
|
|
310
312
|
};
|
package/src/maker/index.ts
CHANGED
|
@@ -106,13 +106,13 @@ export const getMakerAccountBalances = async (
|
|
|
106
106
|
_managerAddress?: EthAddress,
|
|
107
107
|
): Promise<PositionBalances> => _getMakerAccountBalances(getViemProvider(provider, network, { batch: { multicall: true } }), network, block, addressMapping, cdpId, _managerAddress);
|
|
108
108
|
|
|
109
|
-
export const _getUserCdps = async (provider: Client, network: NetworkNumber, userAddress: EthAddress): Promise<CdpInfo[]> => {
|
|
109
|
+
export const _getUserCdps = async (provider: Client, network: NetworkNumber, userAddress: EthAddress, blockNumber: Blockish = 'latest'): Promise<CdpInfo[]> => {
|
|
110
110
|
if (!userAddress) return [];
|
|
111
111
|
const mcdGetCdpsContract = McdGetCdpsContractViem(provider, network);
|
|
112
112
|
|
|
113
113
|
const mcdCdpManagerAddress = getConfigContractAddress('McdCdpManager', network);
|
|
114
114
|
|
|
115
|
-
const standardCdps = await mcdGetCdpsContract.read.getCdpsAsc([mcdCdpManagerAddress, userAddress]);
|
|
115
|
+
const standardCdps = await mcdGetCdpsContract.read.getCdpsAsc([mcdCdpManagerAddress, userAddress], setViemBlockNumber(blockNumber));
|
|
116
116
|
|
|
117
117
|
const parsedStandardCdps = standardCdps[0].map((id, i) => ({
|
|
118
118
|
id: parseInt(id.toString(), 10),
|
|
@@ -131,15 +131,16 @@ export const getUserCdps = async (
|
|
|
131
131
|
provider: EthereumProvider,
|
|
132
132
|
network: NetworkNumber,
|
|
133
133
|
userAddress: EthAddress,
|
|
134
|
-
|
|
134
|
+
blockNumber: Blockish = 'latest',
|
|
135
|
+
): Promise<CdpInfo[]> => _getUserCdps(getViemProvider(provider, network), network, userAddress, blockNumber);
|
|
135
136
|
|
|
136
|
-
export const _getMakerIlksData = async (provider: Client, network: NetworkNumber, ilkLabels: string[]): Promise<Record<string, IlkInfo>> => {
|
|
137
|
+
export const _getMakerIlksData = async (provider: Client, network: NetworkNumber, ilkLabels: string[], blockNumber: Blockish = 'latest'): Promise<Record<string, IlkInfo>> => {
|
|
137
138
|
const vatContract = McdVatContractViem(provider, network);
|
|
138
139
|
const spotterContract = McdSpotterContractViem(provider, network);
|
|
139
140
|
const dogContract = McdDogContractViem(provider, network);
|
|
140
141
|
const jugContract = McdJugContractViem(provider, network);
|
|
141
142
|
|
|
142
|
-
const par = await spotterContract.read.par();
|
|
143
|
+
const par = await spotterContract.read.par(setViemBlockNumber(blockNumber));
|
|
143
144
|
|
|
144
145
|
const ilksInfo = await Promise.all(ilkLabels.map(async (ilkLabel) => {
|
|
145
146
|
const ilk = stringToBytes(ilkLabel) as HexString;
|
|
@@ -150,11 +151,11 @@ export const _getMakerIlksData = async (provider: Client, network: NetworkNumber
|
|
|
150
151
|
futureRate,
|
|
151
152
|
chop,
|
|
152
153
|
] = await Promise.all([
|
|
153
|
-
spotterContract.read.ilks([ilk]),
|
|
154
|
-
vatContract.read.ilks([ilk]),
|
|
155
|
-
jugContract.read.ilks([ilk]),
|
|
156
|
-
jugContract.read.drip([ilk]),
|
|
157
|
-
dogContract.read.chop([ilk]),
|
|
154
|
+
spotterContract.read.ilks([ilk], setViemBlockNumber(blockNumber)),
|
|
155
|
+
vatContract.read.ilks([ilk], setViemBlockNumber(blockNumber)),
|
|
156
|
+
jugContract.read.ilks([ilk], setViemBlockNumber(blockNumber)),
|
|
157
|
+
jugContract.read.drip([ilk], setViemBlockNumber(blockNumber)),
|
|
158
|
+
dogContract.read.chop([ilk], setViemBlockNumber(blockNumber)),
|
|
158
159
|
]);
|
|
159
160
|
|
|
160
161
|
return parseCollateralInfo(
|
|
@@ -179,12 +180,13 @@ export const getMakerIlksData = async (
|
|
|
179
180
|
provider: EthereumProvider,
|
|
180
181
|
network: NetworkNumber,
|
|
181
182
|
ilkLabels: string[],
|
|
182
|
-
|
|
183
|
+
blockNumber: Blockish = 'latest',
|
|
184
|
+
): Promise<Record<string, IlkInfo>> => _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels, blockNumber);
|
|
183
185
|
|
|
184
186
|
/**
|
|
185
187
|
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
186
188
|
*/
|
|
187
|
-
export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo, ilkInfo?: IlkInfo): Promise<CdpData> => {
|
|
189
|
+
export const _getMakerCdpData = async (provider: Client, network: NetworkNumber, cdp: CdpInfo, ilkInfo?: IlkInfo, blockNumber: Blockish = 'latest'): Promise<CdpData> => {
|
|
188
190
|
const vatContract = McdVatContractViem(provider, network);
|
|
189
191
|
|
|
190
192
|
const [
|
|
@@ -193,9 +195,9 @@ export const _getMakerCdpData = async (provider: Client, network: NetworkNumber,
|
|
|
193
195
|
fetchedIlkInfo,
|
|
194
196
|
collStakingApy,
|
|
195
197
|
] = await Promise.all([
|
|
196
|
-
vatContract.read.urns([cdp.ilk, cdp.urn]),
|
|
197
|
-
vatContract.read.gem([cdp.ilk, cdp.urn]),
|
|
198
|
-
ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel]).then((ilks) => ilks[cdp.ilkLabel]),
|
|
198
|
+
vatContract.read.urns([cdp.ilk, cdp.urn], setViemBlockNumber(blockNumber)),
|
|
199
|
+
vatContract.read.gem([cdp.ilk, cdp.urn], setViemBlockNumber(blockNumber)),
|
|
200
|
+
ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel], blockNumber).then((ilks) => ilks[cdp.ilkLabel]),
|
|
199
201
|
STAKING_ASSETS.includes(cdp.asset) ? getStakingApy(cdp.asset) : Promise.resolve('0'),
|
|
200
202
|
]);
|
|
201
203
|
|
|
@@ -270,4 +272,5 @@ export const getMakerCdpData = async (
|
|
|
270
272
|
provider: EthereumProvider,
|
|
271
273
|
network: NetworkNumber,
|
|
272
274
|
cdp: CdpInfo,
|
|
273
|
-
|
|
275
|
+
blockNumber: Blockish = 'latest',
|
|
276
|
+
): Promise<CdpData> => _getMakerCdpData(getViemProvider(provider, network), network, cdp, undefined, blockNumber);
|