@defisaver/positions-sdk 2.1.174 → 2.1.175-looping-2-dev-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/aaveV2/index.d.ts +4 -4
- package/cjs/aaveV2/index.js +7 -7
- package/cjs/aaveV3/index.d.ts +5 -14
- package/cjs/aaveV3/index.js +14 -10
- package/cjs/aaveV3/merkl.d.ts +5 -1
- package/cjs/aaveV3/merkl.js +8 -3
- package/cjs/aaveV3/sgho.d.ts +2 -16
- package/cjs/aaveV4/index.d.ts +4 -3
- package/cjs/aaveV4/index.js +19 -16
- package/cjs/aaveV4/lend.d.ts +2 -43
- package/cjs/aaveV4/merkl.d.ts +10 -2
- package/cjs/aaveV4/merkl.js +15 -6
- package/cjs/claiming/aaveV3.d.ts +3 -3
- package/cjs/claiming/aaveV3.js +5 -4
- package/cjs/claiming/ethena.d.ts +2 -1
- package/cjs/claiming/king.d.ts +3 -2
- package/cjs/claiming/king.js +3 -2
- package/cjs/claiming/spark.d.ts +4 -4
- package/cjs/claiming/spark.js +8 -7
- package/cjs/claiming/uniswap.d.ts +2 -2
- package/cjs/claiming/uniswap.js +3 -2
- package/cjs/compoundV2/index.d.ts +4 -4
- package/cjs/compoundV2/index.js +9 -9
- package/cjs/compoundV3/index.d.ts +5 -4
- package/cjs/compoundV3/index.js +17 -13
- package/cjs/compoundV3/merkl.d.ts +1 -1
- package/cjs/compoundV3/merkl.js +2 -5
- package/cjs/curveUsd/index.d.ts +5 -5
- package/cjs/curveUsd/index.js +17 -17
- package/cjs/fluid/index.d.ts +23 -66
- package/cjs/fluid/index.js +75 -72
- package/cjs/fluid/merkl.d.ts +5 -3
- package/cjs/fluid/merkl.js +11 -6
- package/cjs/helpers/aaveHelpers/index.js +1 -1
- package/cjs/helpers/aaveV4Helpers/index.js +14 -2
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/helpers/curveUsdHelpers/index.js +1 -1
- package/cjs/helpers/fluidHelpers/index.js +1 -1
- package/cjs/helpers/liquityV2Helpers/index.js +1 -1
- package/cjs/helpers/llamaLendHelpers/index.js +1 -1
- package/cjs/helpers/morphoBlueHelpers/index.js +1 -1
- package/cjs/helpers/morphoMidnightHelpers/index.js +1 -1
- package/cjs/helpers/sparkHelpers/index.js +1 -1
- package/cjs/liquity/index.d.ts +5 -15
- package/cjs/liquity/index.js +23 -23
- package/cjs/liquityV2/index.d.ts +16 -31
- package/cjs/liquityV2/index.js +96 -78
- package/cjs/llamaLend/index.d.ts +5 -5
- package/cjs/llamaLend/index.js +13 -13
- package/cjs/maker/index.d.ts +6 -6
- package/cjs/maker/index.js +16 -16
- package/cjs/moneymarket/moneymarketCommonService.js +13 -2
- package/cjs/morphoBlue/index.d.ts +7 -7
- package/cjs/morphoBlue/index.js +28 -26
- package/cjs/morphoBlue/merkl.d.ts +5 -3
- package/cjs/morphoBlue/merkl.js +6 -8
- package/cjs/morphoMidnight/index.d.ts +5 -5
- package/cjs/morphoMidnight/index.js +18 -18
- package/cjs/portfolio/customDeFiData.d.ts +3 -0
- package/cjs/portfolio/customDeFiData.js +267 -0
- package/cjs/portfolio/index.d.ts +17 -8
- package/cjs/portfolio/index.js +459 -520
- package/cjs/portfolio/lendingProtocols.d.ts +184 -0
- package/cjs/portfolio/lendingProtocols.js +196 -0
- package/cjs/savings/index.d.ts +8 -2
- package/cjs/savings/index.js +33 -4
- package/cjs/services/merkl.d.ts +46 -2
- package/cjs/services/merkl.js +190 -19
- package/cjs/services/priceService.d.ts +12 -12
- package/cjs/services/priceService.js +30 -29
- package/cjs/services/viem.d.ts +10 -2
- package/cjs/services/viem.js +27 -1
- package/cjs/spark/index.d.ts +4 -4
- package/cjs/spark/index.js +9 -9
- package/cjs/types/aave.d.ts +98 -2
- package/cjs/types/aaveV4.d.ts +45 -0
- package/cjs/types/common.d.ts +1 -0
- package/cjs/types/common.js +1 -0
- package/cjs/types/compound.d.ts +26 -2
- package/cjs/types/curveUsd.d.ts +9 -1
- package/cjs/types/fluid.d.ts +13 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquity.d.ts +12 -0
- package/cjs/types/liquityV2.d.ts +24 -0
- package/cjs/types/llamaLend.d.ts +12 -1
- package/cjs/types/merkl.d.ts +18 -0
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/portfolio.d.ts +162 -5
- package/cjs/types/portfolio.js +18 -0
- package/cjs/types/savings/index.d.ts +9 -1
- package/cjs/types/spark.d.ts +21 -1
- package/cjs/umbrella/index.d.ts +3 -4
- package/cjs/umbrella/index.js +5 -4
- package/esm/aaveV2/index.d.ts +4 -4
- package/esm/aaveV2/index.js +8 -8
- package/esm/aaveV3/index.d.ts +5 -14
- package/esm/aaveV3/index.js +15 -11
- package/esm/aaveV3/merkl.d.ts +5 -1
- package/esm/aaveV3/merkl.js +9 -4
- package/esm/aaveV3/sgho.d.ts +2 -16
- package/esm/aaveV4/index.d.ts +4 -3
- package/esm/aaveV4/index.js +20 -17
- package/esm/aaveV4/lend.d.ts +2 -43
- package/esm/aaveV4/merkl.d.ts +10 -2
- package/esm/aaveV4/merkl.js +16 -7
- package/esm/claiming/aaveV3.d.ts +3 -3
- package/esm/claiming/aaveV3.js +6 -5
- package/esm/claiming/ethena.d.ts +2 -1
- package/esm/claiming/king.d.ts +3 -2
- package/esm/claiming/king.js +3 -2
- package/esm/claiming/spark.d.ts +4 -4
- package/esm/claiming/spark.js +9 -8
- package/esm/claiming/uniswap.d.ts +2 -2
- package/esm/claiming/uniswap.js +3 -2
- package/esm/compoundV2/index.d.ts +4 -4
- package/esm/compoundV2/index.js +9 -9
- package/esm/compoundV3/index.d.ts +5 -4
- package/esm/compoundV3/index.js +19 -15
- package/esm/compoundV3/merkl.d.ts +1 -1
- package/esm/compoundV3/merkl.js +3 -6
- package/esm/curveUsd/index.d.ts +5 -5
- package/esm/curveUsd/index.js +17 -17
- package/esm/fluid/index.d.ts +23 -66
- package/esm/fluid/index.js +76 -73
- package/esm/fluid/merkl.d.ts +5 -3
- package/esm/fluid/merkl.js +12 -7
- package/esm/helpers/aaveHelpers/index.js +1 -1
- package/esm/helpers/aaveV4Helpers/index.js +15 -3
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/helpers/curveUsdHelpers/index.js +1 -1
- package/esm/helpers/fluidHelpers/index.js +1 -1
- package/esm/helpers/liquityV2Helpers/index.js +1 -1
- package/esm/helpers/llamaLendHelpers/index.js +1 -1
- package/esm/helpers/morphoBlueHelpers/index.js +1 -1
- package/esm/helpers/morphoMidnightHelpers/index.js +1 -1
- package/esm/helpers/sparkHelpers/index.js +1 -1
- package/esm/liquity/index.d.ts +5 -15
- package/esm/liquity/index.js +23 -23
- package/esm/liquityV2/index.d.ts +16 -31
- package/esm/liquityV2/index.js +95 -78
- package/esm/llamaLend/index.d.ts +5 -5
- package/esm/llamaLend/index.js +13 -13
- package/esm/maker/index.d.ts +6 -6
- package/esm/maker/index.js +16 -16
- package/esm/moneymarket/moneymarketCommonService.js +13 -2
- package/esm/morphoBlue/index.d.ts +7 -7
- package/esm/morphoBlue/index.js +29 -27
- package/esm/morphoBlue/merkl.d.ts +5 -3
- package/esm/morphoBlue/merkl.js +7 -9
- package/esm/morphoMidnight/index.d.ts +5 -5
- package/esm/morphoMidnight/index.js +18 -18
- package/esm/portfolio/customDeFiData.d.ts +3 -0
- package/esm/portfolio/customDeFiData.js +261 -0
- package/esm/portfolio/index.d.ts +17 -8
- package/esm/portfolio/index.js +459 -522
- package/esm/portfolio/lendingProtocols.d.ts +184 -0
- package/esm/portfolio/lendingProtocols.js +189 -0
- package/esm/savings/index.d.ts +8 -2
- package/esm/savings/index.js +31 -3
- package/esm/services/merkl.d.ts +46 -2
- package/esm/services/merkl.js +180 -18
- package/esm/services/priceService.d.ts +12 -12
- package/esm/services/priceService.js +31 -30
- package/esm/services/viem.d.ts +10 -2
- package/esm/services/viem.js +25 -0
- package/esm/spark/index.d.ts +4 -4
- package/esm/spark/index.js +10 -10
- package/esm/types/aave.d.ts +98 -2
- package/esm/types/aaveV4.d.ts +45 -0
- package/esm/types/common.d.ts +1 -0
- package/esm/types/common.js +1 -0
- package/esm/types/compound.d.ts +26 -2
- package/esm/types/curveUsd.d.ts +9 -1
- package/esm/types/fluid.d.ts +13 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquity.d.ts +12 -0
- package/esm/types/liquityV2.d.ts +24 -0
- package/esm/types/llamaLend.d.ts +12 -1
- package/esm/types/merkl.d.ts +18 -0
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/portfolio.d.ts +162 -5
- package/esm/types/portfolio.js +17 -1
- package/esm/types/savings/index.d.ts +9 -1
- package/esm/types/spark.d.ts +21 -1
- package/esm/umbrella/index.d.ts +3 -4
- package/esm/umbrella/index.js +5 -4
- package/package.json +1 -1
- package/src/aaveV2/index.ts +7 -7
- package/src/aaveV3/index.ts +16 -11
- package/src/aaveV3/merkl.ts +9 -4
- package/src/aaveV3/sgho.ts +2 -17
- package/src/aaveV4/index.ts +19 -16
- package/src/aaveV4/lend.ts +2 -48
- package/src/aaveV4/merkl.ts +16 -7
- package/src/claiming/aaveV3.ts +9 -5
- package/src/claiming/ethena.ts +5 -5
- package/src/claiming/king.ts +8 -5
- package/src/claiming/spark.ts +15 -10
- package/src/claiming/uniswap.ts +4 -3
- package/src/compoundV2/index.ts +10 -9
- package/src/compoundV3/index.ts +20 -14
- package/src/compoundV3/merkl.ts +5 -4
- package/src/curveUsd/index.ts +19 -17
- package/src/fluid/index.ts +91 -72
- package/src/fluid/merkl.ts +12 -7
- package/src/helpers/aaveHelpers/index.ts +1 -1
- package/src/helpers/aaveV4Helpers/index.ts +16 -2
- package/src/helpers/compoundHelpers/index.ts +2 -2
- package/src/helpers/curveUsdHelpers/index.ts +1 -1
- package/src/helpers/fluidHelpers/index.ts +1 -1
- package/src/helpers/liquityV2Helpers/index.ts +1 -1
- package/src/helpers/llamaLendHelpers/index.ts +1 -1
- package/src/helpers/morphoBlueHelpers/index.ts +1 -1
- package/src/helpers/morphoMidnightHelpers/index.ts +1 -1
- package/src/helpers/sparkHelpers/index.ts +1 -1
- package/src/liquity/index.ts +24 -24
- package/src/liquityV2/index.ts +110 -76
- package/src/llamaLend/index.ts +15 -13
- package/src/maker/index.ts +19 -16
- package/src/moneymarket/moneymarketCommonService.ts +14 -2
- package/src/morphoBlue/index.ts +23 -20
- package/src/morphoBlue/merkl.ts +9 -6
- package/src/morphoMidnight/index.ts +13 -13
- package/src/portfolio/customDeFiData.ts +385 -0
- package/src/portfolio/index.ts +307 -331
- package/src/portfolio/lendingProtocols.ts +281 -0
- package/src/savings/index.ts +41 -4
- package/src/services/merkl.ts +209 -19
- package/src/services/priceService.ts +33 -30
- package/src/services/viem.ts +16 -0
- package/src/spark/index.ts +11 -8
- package/src/types/aave.ts +104 -1
- package/src/types/aaveV4.ts +50 -0
- package/src/types/common.ts +1 -0
- package/src/types/compound.ts +38 -2
- package/src/types/curveUsd.ts +17 -1
- package/src/types/fluid.ts +14 -0
- package/src/types/index.ts +1 -0
- package/src/types/liquity.ts +13 -1
- package/src/types/liquityV2.ts +26 -1
- package/src/types/llamaLend.ts +19 -1
- package/src/types/merkl.ts +20 -0
- package/src/types/morphoBlue.ts +3 -0
- package/src/types/portfolio.ts +191 -5
- package/src/types/savings/index.ts +12 -1
- package/src/types/spark.ts +25 -1
- package/src/umbrella/index.ts +7 -5
|
@@ -43,7 +43,7 @@ export const getCrvUsdAggregatedData = ({
|
|
|
43
43
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets as unknown as MMUsedAssets);
|
|
44
44
|
payload.leveragedType = leveragedType;
|
|
45
45
|
payload.liquidationPrice = '';
|
|
46
|
-
if (
|
|
46
|
+
if (leveragedAsset !== '') {
|
|
47
47
|
payload.leveragedAsset = leveragedAsset;
|
|
48
48
|
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
49
49
|
}
|
|
@@ -148,7 +148,7 @@ borrowShares?: string,
|
|
|
148
148
|
|
|
149
149
|
payload.leveragedType = leveragedType;
|
|
150
150
|
payload.liquidationPrice = '';
|
|
151
|
-
if (
|
|
151
|
+
if (leveragedAsset !== '') {
|
|
152
152
|
payload.leveragedAsset = leveragedAsset;
|
|
153
153
|
let assetPrice = assetsData[leveragedAsset].price;
|
|
154
154
|
if (leveragedType === LeverageType.VolatilePair) {
|
|
@@ -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
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
LiquityTroveManagerContractViem,
|
|
14
14
|
LiquityViewContractViem,
|
|
15
15
|
} from '../contracts';
|
|
16
|
-
import { LIQUITY_TROVE_STATUS_ENUM, LiquityTroveInfo } from '../types';
|
|
16
|
+
import { LIQUITY_TROVE_STATUS_ENUM, LiquityStakingData, LiquityTroveInfo } from '../types';
|
|
17
17
|
import { ZERO_ADDRESS } from '../constants';
|
|
18
18
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
19
19
|
import { getEthAmountForDecimals } from '../services/utils';
|
|
@@ -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) => {
|
|
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,11 +9,11 @@ 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,
|
|
16
|
-
LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData, LiquityV2UsedAssets,
|
|
16
|
+
LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2SBoldYBoldData, LiquityV2StakingData, LiquityV2TroveData, LiquityV2UsedAssets,
|
|
17
17
|
LiquityV2Versions,
|
|
18
18
|
} from '../types';
|
|
19
19
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
@@ -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 = {
|
|
@@ -164,31 +166,35 @@ export const nftContractCreationBlockMapping = {
|
|
|
164
166
|
[LiquityV2Versions.LiquityV2REthLegacy]: 21686257,
|
|
165
167
|
};
|
|
166
168
|
|
|
167
|
-
|
|
169
|
+
interface TroveTransfer {
|
|
170
|
+
from?: EthAddress,
|
|
171
|
+
to?: EthAddress,
|
|
172
|
+
tokenId: string,
|
|
173
|
+
blockNumber: number,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Every Transfer of a market's trove NFT since the contract was created (or, on a fork, in the last 1000 blocks). */
|
|
177
|
+
const getTroveTransfers = async (provider: PublicClient, network: NetworkNumber, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, market: LiquityV2Versions): Promise<TroveTransfer[]> => {
|
|
168
178
|
const nftContract = createViemContractFromConfigFunc('LiquityV2TroveNFT', troveNFTAddress)(provider, network);
|
|
169
179
|
const nftContractCreationBlock = nftContractCreationBlockMapping[market];
|
|
170
180
|
const currentBlock = +(await provider.getBlockNumber()).toString();
|
|
171
181
|
const _events = await nftContract.getEvents.Transfer({}, { fromBlock: limitBlocksForEventFetching ? BigInt(currentBlock - 1000) : BigInt(nftContractCreationBlock) });
|
|
172
|
-
|
|
182
|
+
return _events.map((event) => ({
|
|
173
183
|
from: event.args.from, to: event.args.to, tokenId: event.args.tokenId!.toString(), blockNumber: +(event.blockNumber.toString()),
|
|
174
184
|
}));
|
|
175
|
-
const userTransferredTroves = events.filter((event) => compareAddresses(event.to, account));
|
|
176
|
-
|
|
177
|
-
// check if the last know transfer address is the user
|
|
178
|
-
userTransferredTroves.forEach((event, index) => {
|
|
179
|
-
const otherTransfers = events.filter((e) => event.blockNumber < e.blockNumber && e.tokenId === event.tokenId);
|
|
180
|
-
// @ts-ignore
|
|
181
|
-
userTransferredTroves[index].invalid = !!otherTransfers.length;
|
|
182
|
-
});
|
|
183
|
-
// @ts-ignore
|
|
184
|
-
return userTransferredTroves.filter((event) => !event.invalid).map((event) => ({ troveId: event.tokenId }));
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
/** The troves transferred to an account that it still holds: no later transfer of the same trove. */
|
|
188
|
+
const getAccountTransferredTroves = (events: TroveTransfer[], account: EthAddress): { troveId: string }[] => events
|
|
189
|
+
.filter((event) => compareAddresses(event.to, account))
|
|
190
|
+
.filter((event) => !events.some((e) => event.blockNumber < e.blockNumber && e.tokenId === event.tokenId))
|
|
191
|
+
.map((event) => ({ troveId: event.tokenId }));
|
|
192
|
+
|
|
193
|
+
const getTransferredTroves = async (provider: PublicClient, network: NetworkNumber, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, market: LiquityV2Versions, account: EthAddress): Promise<{ troveId: string }[]> => (
|
|
194
|
+
getAccountTransferredTroves(await getTroveTransfers(provider, network, troveNFTAddress, limitBlocksForEventFetching, market), account));
|
|
195
|
+
|
|
196
|
+
/** The troves an account opened and still owns, then the ones transferred to it, each once. */
|
|
197
|
+
const mergeTroveIds = (userTroves: { troveId: string }[], userTransferredTroves: { troveId: string }[]): { troveId: string }[] => {
|
|
192
198
|
const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
|
|
193
199
|
const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (
|
|
194
200
|
t.troveId === value.troveId
|
|
@@ -197,8 +203,30 @@ export const _getLiquityV2UserTroveIds = async (provider: PublicClient, network:
|
|
|
197
203
|
const troveIds = filteredTroves.map((trove) => trove.troveId);
|
|
198
204
|
const troveIdsSet = new Set(troveIds);
|
|
199
205
|
const troveIdsArray = Array.from(troveIdsSet);
|
|
200
|
-
|
|
201
|
-
|
|
206
|
+
return troveIdsArray.map((troveId) => troves.find((trove) => trove.troveId === troveId)) as { troveId: string }[];
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The trove ids of several accounts in one market: the market's NFT transfers are read once for all of them, rather
|
|
211
|
+
* than once per account as _getLiquityV2UserTroveIds does.
|
|
212
|
+
*/
|
|
213
|
+
export const _getLiquityV2UsersTroveIds = async (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, accounts: EthAddress[]): Promise<Record<EthAddress, string[]>> => {
|
|
214
|
+
const [userTroves, events] = await Promise.all([
|
|
215
|
+
Promise.all(accounts.map((account) => getUserTroves(provider, network, selectedMarket.isLegacy, account, selectedMarket.marketAddress))),
|
|
216
|
+
getTroveTransfers(provider, network, troveNFTAddress, limitBlocksForEventFetching, selectedMarket.value),
|
|
217
|
+
]);
|
|
218
|
+
return Object.fromEntries(accounts.map((account, i) => [
|
|
219
|
+
account,
|
|
220
|
+
mergeTroveIds(userTroves[i].troves, getAccountTransferredTroves(events, account)).map(({ troveId }) => troveId),
|
|
221
|
+
]));
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export const _getLiquityV2UserTroveIds = async (provider: PublicClient, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress): Promise<{ troves: { troveId: string }[], nextFreeTroveIndex: string }> => {
|
|
225
|
+
const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = await Promise.all([
|
|
226
|
+
getUserTroves(provider, network, selectedMarket.isLegacy, account, selectedMarket.marketAddress),
|
|
227
|
+
getTransferredTroves(provider, network, troveNFTAddress, limitBlocksForEventFetching, selectedMarket.value, account),
|
|
228
|
+
]);
|
|
229
|
+
return { troves: mergeTroveIds(userTroves, userTransferredTroves), nextFreeTroveIndex };
|
|
202
230
|
};
|
|
203
231
|
|
|
204
232
|
export const getLiquityV2UserTroveIds = async (
|
|
@@ -218,13 +246,14 @@ const getDebtInFrontForSingleMarketLiquityV2 = async (
|
|
|
218
246
|
troveId: string,
|
|
219
247
|
accumulatedSum = '0',
|
|
220
248
|
iterations = 2000,
|
|
249
|
+
blockNumber: Blockish = 'latest',
|
|
221
250
|
): Promise<string> => {
|
|
222
251
|
const viewContract = getLiquityV2ViewContract(provider, network, isLegacy);
|
|
223
|
-
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));
|
|
224
253
|
const next = res[0].toString();
|
|
225
254
|
const debt = res[1].toString();
|
|
226
255
|
if (next === '0') return assetAmountInEth(debt);
|
|
227
|
-
return getDebtInFrontForSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, next, debt, iterations);
|
|
256
|
+
return getDebtInFrontForSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, next, debt, iterations, blockNumber);
|
|
228
257
|
};
|
|
229
258
|
|
|
230
259
|
const getDebtInFrontForInterestRateSingleMarketLiquityV2 = async (
|
|
@@ -236,31 +265,32 @@ const getDebtInFrontForInterestRateSingleMarketLiquityV2 = async (
|
|
|
236
265
|
troveId = '0',
|
|
237
266
|
accumulatedSum = '0',
|
|
238
267
|
iterations = 2000,
|
|
268
|
+
blockNumber: Blockish = 'latest',
|
|
239
269
|
): Promise<string> => {
|
|
240
270
|
const viewContract = getLiquityV2ViewContract(provider, network, isLegacy);
|
|
241
271
|
if (+interestRate === 0 || !interestRate) return '0';
|
|
242
272
|
const interestRateWei = new Dec(interestRate).times(1e16).toFixed(0).toString();
|
|
243
|
-
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));
|
|
244
274
|
const next = res[0].toString();
|
|
245
275
|
const debt = res[1].toString();
|
|
246
276
|
if (next === '0') return assetAmountInEth(debt);
|
|
247
|
-
return getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, interestRate, next, debt, iterations);
|
|
277
|
+
return getDebtInFrontForInterestRateSingleMarketLiquityV2(provider, network, isLegacy, marketAddress, interestRate, next, debt, iterations, blockNumber);
|
|
248
278
|
};
|
|
249
279
|
|
|
250
|
-
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') => {
|
|
251
281
|
const stabilityPoolContract = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddress)(provider, network);
|
|
252
|
-
const totalBoldDeposits = await stabilityPoolContract.read.getTotalBoldDeposits();
|
|
282
|
+
const totalBoldDeposits = await stabilityPoolContract.read.getTotalBoldDeposits(setViemBlockNumber(blockNumber));
|
|
253
283
|
const totalBoldDepositsInEth = assetAmountInEth(totalBoldDeposits.toString());
|
|
254
284
|
|
|
255
285
|
return Dec.max(new Dec(totalBorrowed).sub(totalBoldDepositsInEth), 0).toString();
|
|
256
286
|
};
|
|
257
287
|
|
|
258
|
-
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>> => {
|
|
259
289
|
const allMarketsUnbackedDebt = await Promise.all(Object.entries(markets).map(async ([version, market]) => {
|
|
260
290
|
const { assetsData, marketData } = market;
|
|
261
291
|
const { debtToken, isLegacy: isLegacyMarket } = LiquityV2Markets(network)[version as LiquityV2Versions];
|
|
262
292
|
if (isLegacyMarket !== isLegacy) return [version, '0'];
|
|
263
|
-
const unbackedDebt = await getUnbackedDebtForSingleMarket(assetsData[debtToken].totalBorrow, provider, network, marketData.stabilityPoolAddress);
|
|
293
|
+
const unbackedDebt = await getUnbackedDebtForSingleMarket(assetsData[debtToken].totalBorrow, provider, network, marketData.stabilityPoolAddress, blockNumber);
|
|
264
294
|
return [version, unbackedDebt];
|
|
265
295
|
}));
|
|
266
296
|
|
|
@@ -319,23 +349,23 @@ export const calculateDebtInFrontLiquityV2 = (markets: Record<LiquityV2Versions,
|
|
|
319
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).
|
|
320
350
|
// When new debt is generated on the selected market, the unbacked debt will increase, resulting in a higher redemption amount on that branch.
|
|
321
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.
|
|
322
|
-
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') => {
|
|
323
353
|
const marketsWithNewDebt = structuredClone(markets);
|
|
324
354
|
const selectedMarketDebtToken = LiquityV2Markets(network)[selectedMarket].debtToken;
|
|
325
355
|
const currentTotalBorrow = new Dec(marketsWithNewDebt[selectedMarket].assetsData[selectedMarketDebtToken].totalBorrow);
|
|
326
356
|
marketsWithNewDebt[selectedMarket].assetsData[selectedMarketDebtToken].totalBorrow = currentTotalBorrow.add(newDebt).toString();
|
|
327
357
|
|
|
328
358
|
const { isLegacy } = LiquityV2Markets(NetworkNumber.Eth)[selectedMarket];
|
|
329
|
-
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(marketsWithNewDebt, isLegacy, provider, network);
|
|
330
|
-
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));
|
|
331
361
|
|
|
332
362
|
return calculateDebtInFrontLiquityV2(marketsWithNewDebt, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
333
363
|
};
|
|
334
364
|
|
|
335
|
-
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') => {
|
|
336
366
|
const { isLegacy } = LiquityV2Markets(NetworkNumber.Eth)[selectedMarket];
|
|
337
|
-
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(markets, isLegacy, provider, network);
|
|
338
|
-
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);
|
|
339
369
|
|
|
340
370
|
return calculateDebtInFrontLiquityV2(markets, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
341
371
|
};
|
|
@@ -349,9 +379,9 @@ const getDebtInFrontLiquityV2 = async (markets: Record<LiquityV2Versions, Liquit
|
|
|
349
379
|
* @param interestRate
|
|
350
380
|
* @param debtInFrontBeingMoved - amound of debt being repositioned if interest rate is being increased (prevents including it as debt in front)
|
|
351
381
|
*/
|
|
352
|
-
const _getDebtInFrontForInterestRateLiquityV2 = async (markets: Record<LiquityV2Versions, LiquityV2MarketData>, selectedMarket: LiquityV2Versions, provider: Client, network: NetworkNumber, isLegacy: boolean, interestRate: string, debtInFrontBeingMoved: string = '0') => {
|
|
353
|
-
const allMarketsUnbackedDebts = await getAllMarketsUnbackedDebts(markets, isLegacy, provider, network);
|
|
354
|
-
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))
|
|
355
385
|
.sub(debtInFrontBeingMoved);
|
|
356
386
|
|
|
357
387
|
return calculateDebtInFrontLiquityV2(markets, selectedMarket, allMarketsUnbackedDebts, interestRateDebtInFront.toString());
|
|
@@ -365,7 +395,8 @@ export const getDebtInFrontForInterestRateLiquityV2 = async (
|
|
|
365
395
|
isLegacy: boolean,
|
|
366
396
|
interestRate: string,
|
|
367
397
|
debtInFrontBeingMoved: string = '0',
|
|
368
|
-
|
|
398
|
+
blockNumber: Blockish = 'latest',
|
|
399
|
+
) => _getDebtInFrontForInterestRateLiquityV2(markets, selectedMarket, getViemProvider(provider, network), network, isLegacy, interestRate, debtInFrontBeingMoved, blockNumber);
|
|
369
400
|
|
|
370
401
|
export const _getLiquityV2TroveData = async (
|
|
371
402
|
provider: Client,
|
|
@@ -383,17 +414,18 @@ export const _getLiquityV2TroveData = async (
|
|
|
383
414
|
allMarketsData: Record<LiquityV2Versions, LiquityV2MarketData>,
|
|
384
415
|
},
|
|
385
416
|
fetchDebtInFront: boolean = true,
|
|
417
|
+
blockNumber: Blockish = 'latest',
|
|
386
418
|
): Promise<LiquityV2TroveData> => {
|
|
387
419
|
const { minCollRatio, batchCollRatio } = allMarketsData[selectedMarket.value].marketData;
|
|
388
420
|
const { collateralToken, marketAddress, debtToken } = selectedMarket;
|
|
389
421
|
const troveInfoPromise = selectedMarket.isLegacy
|
|
390
|
-
? LiquityV2LegacyViewContractViem(provider, network).read.getTroveInfo([marketAddress, BigInt(troveId)])
|
|
422
|
+
? LiquityV2LegacyViewContractViem(provider, network).read.getTroveInfo([marketAddress, BigInt(troveId)], setViemBlockNumber(blockNumber))
|
|
391
423
|
: LiquityV2ViewContractViem(provider, network).simulate
|
|
392
|
-
.getTroveInfo([marketAddress, BigInt(troveId)])
|
|
424
|
+
.getTroveInfo([marketAddress, BigInt(troveId)], setViemBlockNumber(blockNumber))
|
|
393
425
|
.then(({ result }) => result);
|
|
394
426
|
const [_data, debtInFront] = await Promise.all([
|
|
395
427
|
troveInfoPromise,
|
|
396
|
-
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'),
|
|
397
429
|
]);
|
|
398
430
|
const data = {
|
|
399
431
|
..._data,
|
|
@@ -469,6 +501,7 @@ export const getLiquityV2TroveData = async (
|
|
|
469
501
|
allMarketsData: Record<LiquityV2Versions, LiquityV2MarketData>,
|
|
470
502
|
},
|
|
471
503
|
fetchDebtInFront: boolean = true,
|
|
504
|
+
blockNumber: Blockish = 'latest',
|
|
472
505
|
): Promise<LiquityV2TroveData> => _getLiquityV2TroveData(
|
|
473
506
|
getViemProvider(provider, network),
|
|
474
507
|
network,
|
|
@@ -479,12 +512,13 @@ export const getLiquityV2TroveData = async (
|
|
|
479
512
|
allMarketsData,
|
|
480
513
|
},
|
|
481
514
|
fetchDebtInFront,
|
|
515
|
+
blockNumber,
|
|
482
516
|
);
|
|
483
517
|
|
|
484
|
-
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> => {
|
|
485
519
|
const client = getViemProvider(provider, network);
|
|
486
520
|
const collSurplusPoolContract = createViemContractFromConfigFunc('LiquityV2CollSurplusPool', collSurplusPoolAddress)(client, network);
|
|
487
|
-
const claimableCollateral = await collSurplusPoolContract.read.getCollateral([account]);
|
|
521
|
+
const claimableCollateral = await collSurplusPoolContract.read.getCollateral([account], setViemBlockNumber(blockNumber));
|
|
488
522
|
return claimableCollateral.toString();
|
|
489
523
|
};
|
|
490
524
|
|
|
@@ -581,7 +615,7 @@ const calculateSPApy = (
|
|
|
581
615
|
return apy;
|
|
582
616
|
};
|
|
583
617
|
|
|
584
|
-
export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress) => {
|
|
618
|
+
export const getLiquityV2Staking = async (provider: Client, network: NetworkNumber, market: LiquityV2Versions, user: EthAddress, blockNumber: Blockish = 'latest'): Promise<LiquityV2StakingData> => {
|
|
585
619
|
const stabilityPoolView = createViemContractFromConfigFunc('LiquityV2StabilityPool', stabilityPoolAddrForMarket[market])(provider, network);
|
|
586
620
|
const activePoolView = createViemContractFromConfigFunc('LiquityV2ActivePool', activePoolAddrForMarket[market])(provider, network);
|
|
587
621
|
|
|
@@ -601,17 +635,17 @@ export const getLiquityV2Staking = async (provider: Client, network: NetworkNumb
|
|
|
601
635
|
aggWeightedDebtSum,
|
|
602
636
|
lastAggUpdateTime,
|
|
603
637
|
] = await Promise.all([
|
|
604
|
-
stabilityPoolView.read.getDepositorCollGain([user]),
|
|
605
|
-
stabilityPoolView.read.getDepositorYieldGain([user]),
|
|
606
|
-
stabilityPoolView.read.getCompoundedBoldDeposit([user]),
|
|
607
|
-
stabilityPoolView.read.getTotalBoldDeposits(),
|
|
608
|
-
stabilityPoolView.read.P(),
|
|
609
|
-
stabilityPoolView.read.currentScale(),
|
|
610
|
-
stabilityPoolView.read.getYieldGainsPending(),
|
|
611
|
-
debtTokenContract.read.balanceOf([user]),
|
|
612
|
-
|
|
613
|
-
activePoolView.read.aggWeightedDebtSum(),
|
|
614
|
-
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)),
|
|
615
649
|
]);
|
|
616
650
|
|
|
617
651
|
const stabilityPoolYieldParams: SPYieldGainParameters = {
|
|
@@ -640,7 +674,7 @@ export const getLiquityV2Staking = async (provider: Client, network: NetworkNumb
|
|
|
640
674
|
};
|
|
641
675
|
};
|
|
642
676
|
|
|
643
|
-
export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress) => {
|
|
677
|
+
export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumber, markets: any, user: EthAddress, blockNumber: Blockish = 'latest'): Promise<LiquityV2SBoldYBoldData> => {
|
|
644
678
|
const sBold = LiquityV2sBoldVaultViem(provider, network);
|
|
645
679
|
const yBold = createViemContractFromConfigFunc('Erc4626', '0x9F4330700a36B29952869fac9b33f45EEdd8A3d8')(provider, network);
|
|
646
680
|
const stYBold = createViemContractFromConfigFunc('Erc4626', '0x23346B04a7f55b8760E5860AA5A77383D63491cD')(provider, network);
|
|
@@ -669,22 +703,22 @@ export const getLiquitySAndYBold = async (provider: Client, network: NetworkNumb
|
|
|
669
703
|
yBoldBalance,
|
|
670
704
|
stYBoldBalance,
|
|
671
705
|
] = await Promise.all([
|
|
672
|
-
sBold.read.totalAssets(),
|
|
673
|
-
sBold.read.convertToShares([BigInt(1e18)]),
|
|
674
|
-
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)),
|
|
675
709
|
|
|
676
|
-
sBold.read.sps([BigInt(0)]),
|
|
677
|
-
sBold.read.sps([BigInt(1)]),
|
|
678
|
-
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)),
|
|
679
713
|
|
|
680
|
-
yBold.read.totalAssets(),
|
|
681
|
-
yBold.read.maxWithdraw([user]),
|
|
682
|
-
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)),
|
|
683
717
|
getYBoldApyApi(),
|
|
684
718
|
|
|
685
|
-
sBold.read.balanceOf([user]),
|
|
686
|
-
yBold.read.balanceOf([user]),
|
|
687
|
-
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)),
|
|
688
722
|
]);
|
|
689
723
|
|
|
690
724
|
const spMarketRes = {
|