@defisaver/positions-sdk 0.0.166-dev4-liquity-v2 → 0.0.166-dev5-liquity-v2
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/config/contracts.js +1 -1
- package/cjs/liquityV2/index.d.ts +2 -1
- package/cjs/liquityV2/index.js +15 -7
- package/cjs/types/liquityV2.d.ts +1 -2
- package/esm/config/contracts.js +1 -1
- package/esm/liquityV2/index.d.ts +2 -1
- package/esm/liquityV2/index.js +13 -6
- package/esm/types/liquityV2.d.ts +1 -2
- package/package.json +1 -1
- package/src/config/contracts.js +1 -1
- package/src/liquityV2/index.ts +15 -6
- package/src/types/liquityV2.ts +1 -2
package/cjs/config/contracts.js
CHANGED
|
@@ -1034,7 +1034,7 @@ module.exports = {
|
|
|
1034
1034
|
"LiquityV2View": {
|
|
1035
1035
|
"abi": [{ "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_prevId", "type": "uint256" }, { "internalType": "uint256", "name": "_nextId", "type": "uint256" }], "name": "findInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getApproxHint", "outputs": [{ "internalType": "uint256", "name": "hintId", "type": "uint256" }, { "internalType": "uint256", "name": "diff", "type": "uint256" }, { "internalType": "uint256", "name": "latestRandomSeed", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getDebtInFront", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }, { "internalType": "uint256", "name": "_targetIR", "type": "uint256" }], "name": "getDebtInFrontByInterestRate", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_numTroves", "type": "uint256" }], "name": "getDebtInFrontByTroveNum", "outputs": [{ "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "address", "name": "_depositor", "type": "address" }], "name": "getDepositorInfo", "outputs": [{ "internalType": "uint256", "name": "compoundedBOLD", "type": "uint256" }, { "internalType": "uint256", "name": "collGain", "type": "uint256" }, { "internalType": "uint256", "name": "boldGain", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "getMarketData", "outputs": [{ "components": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "CCR", "type": "uint256" }, { "internalType": "uint256", "name": "MCR", "type": "uint256" }, { "internalType": "uint256", "name": "SCR", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_SP", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_REDISTRIBUTION", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemColl", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemDebt", "type": "uint256" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "troveNFT", "type": "address" }, { "internalType": "address", "name": "borrowerOperations", "type": "address" }, { "internalType": "address", "name": "troveManager", "type": "address" }, { "internalType": "address", "name": "stabilityPool", "type": "address" }, { "internalType": "address", "name": "sortedTroves", "type": "address" }, { "internalType": "address", "name": "collSurplusPool", "type": "address" }, { "internalType": "address", "name": "hintHelpers", "type": "address" }, { "internalType": "address", "name": "priceFeed", "type": "address" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "bool", "name": "isShutDown", "type": "bool" }], "internalType": "struct LiquityV2View.MarketData", "name": "data", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getNumOfTrovesInFrontOfTrove", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "numTroves", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }], "name": "getTroveInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "enum ITroveManager.Status", "name": "status", "type": "uint8" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "uint256", "name": "TCRatio", "type": "uint256" }, { "internalType": "uint256", "name": "annualInterestRate", "type": "uint256" }, { "internalType": "address", "name": "interestBatchManager", "type": "address" }, { "internalType": "uint256", "name": "batchDebtShares", "type": "uint256" }], "internalType": "struct LiquityV2View.TroveData", "name": "trove", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getTrovePosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "isShutDown", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }],
|
|
1036
1036
|
"networks": {
|
|
1037
|
-
"1": { "address": "
|
|
1037
|
+
"1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
};
|
package/cjs/liquityV2/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
|
-
import { NetworkNumber } from '../types/common';
|
|
2
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
|
|
4
4
|
export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
|
|
5
|
+
export declare const getDebtInFrontLiquityV2: (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
|
|
5
6
|
export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
|
|
6
7
|
selectedMarket: LiquityV2MarketInfo;
|
|
7
8
|
assetsData: LiquityV2AssetsData;
|
package/cjs/liquityV2/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getLiquityV2TroveData = exports.getLiquityV2MarketData = void 0;
|
|
15
|
+
exports.getLiquityV2TroveData = exports.getDebtInFrontLiquityV2 = exports.getLiquityV2MarketData = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const tokens_1 = require("@defisaver/tokens");
|
|
18
18
|
const contracts_1 = require("../contracts");
|
|
@@ -51,18 +51,27 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
|
|
|
51
51
|
return { assetsData, marketData: { minCollRatio } };
|
|
52
52
|
});
|
|
53
53
|
exports.getLiquityV2MarketData = getLiquityV2MarketData;
|
|
54
|
+
const _getDebtInFront = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call(); });
|
|
55
|
+
const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
|
|
57
|
+
if (next === '0')
|
|
58
|
+
return (0, tokens_1.assetAmountInEth)(debt);
|
|
59
|
+
return (0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, next, debt, iterations);
|
|
60
|
+
});
|
|
61
|
+
exports.getDebtInFrontLiquityV2 = getDebtInFrontLiquityV2;
|
|
54
62
|
const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, marketData, troveId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
63
|
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
56
64
|
const { minCollRatio } = marketData;
|
|
57
65
|
const { collateralToken, marketAddress, debtToken } = selectedMarket;
|
|
58
|
-
const data = yield
|
|
66
|
+
const [data, debtInFront] = yield Promise.all([
|
|
67
|
+
viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
|
|
68
|
+
(0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, troveId),
|
|
69
|
+
]);
|
|
59
70
|
const usedAssets = {};
|
|
60
71
|
const debtAssetData = assetsData[debtToken];
|
|
61
72
|
const borrowed = (0, tokens_1.assetAmountInEth)(data.debtAmount);
|
|
62
73
|
usedAssets[debtToken] = {
|
|
63
74
|
symbol: debtToken,
|
|
64
|
-
address: debtAssetData.address,
|
|
65
|
-
price: debtAssetData.price,
|
|
66
75
|
supplied: '0',
|
|
67
76
|
suppliedUsd: '0',
|
|
68
77
|
borrowed,
|
|
@@ -74,8 +83,6 @@ const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, mark
|
|
|
74
83
|
const suppliedColl = (0, tokens_1.assetAmountInEth)(data.collAmount);
|
|
75
84
|
usedAssets[collateralToken] = {
|
|
76
85
|
symbol: collateralToken,
|
|
77
|
-
address: collAssetData.address,
|
|
78
|
-
price: collAssetData.price,
|
|
79
86
|
supplied: suppliedColl,
|
|
80
87
|
suppliedUsd: new decimal_js_1.default(suppliedColl).mul(collAssetData.price).toString(),
|
|
81
88
|
borrowed: '0',
|
|
@@ -91,7 +98,8 @@ const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, mark
|
|
|
91
98
|
troveId,
|
|
92
99
|
collRatio,
|
|
93
100
|
interestRate,
|
|
94
|
-
interestBatchManager,
|
|
101
|
+
interestBatchManager,
|
|
102
|
+
debtInFront, troveStatus: types_1.LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, (0, liquityV2Helpers_1.getLiquityV2AggregatedPositionData)({
|
|
95
103
|
usedAssets, assetsData, minCollRatio, interestRate,
|
|
96
104
|
}));
|
|
97
105
|
return payload;
|
package/cjs/types/liquityV2.d.ts
CHANGED
|
@@ -37,8 +37,6 @@ export interface LiquityV2MarketData {
|
|
|
37
37
|
}
|
|
38
38
|
export interface LiquityV2UsedAsset {
|
|
39
39
|
symbol: string;
|
|
40
|
-
address: string;
|
|
41
|
-
price: string;
|
|
42
40
|
collateral?: boolean;
|
|
43
41
|
supplied: string;
|
|
44
42
|
suppliedUsd: string;
|
|
@@ -81,4 +79,5 @@ export interface LiquityV2TroveData {
|
|
|
81
79
|
leveragedType: string;
|
|
82
80
|
leveragedAsset: string;
|
|
83
81
|
liquidationPrice: string;
|
|
82
|
+
debtInFront: string;
|
|
84
83
|
}
|
package/esm/config/contracts.js
CHANGED
|
@@ -1033,7 +1033,7 @@ module.exports = {
|
|
|
1033
1033
|
"LiquityV2View": {
|
|
1034
1034
|
"abi": [{ "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_prevId", "type": "uint256" }, { "internalType": "uint256", "name": "_nextId", "type": "uint256" }], "name": "findInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getApproxHint", "outputs": [{ "internalType": "uint256", "name": "hintId", "type": "uint256" }, { "internalType": "uint256", "name": "diff", "type": "uint256" }, { "internalType": "uint256", "name": "latestRandomSeed", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getDebtInFront", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }, { "internalType": "uint256", "name": "_targetIR", "type": "uint256" }], "name": "getDebtInFrontByInterestRate", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_numTroves", "type": "uint256" }], "name": "getDebtInFrontByTroveNum", "outputs": [{ "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "address", "name": "_depositor", "type": "address" }], "name": "getDepositorInfo", "outputs": [{ "internalType": "uint256", "name": "compoundedBOLD", "type": "uint256" }, { "internalType": "uint256", "name": "collGain", "type": "uint256" }, { "internalType": "uint256", "name": "boldGain", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "getMarketData", "outputs": [{ "components": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "CCR", "type": "uint256" }, { "internalType": "uint256", "name": "MCR", "type": "uint256" }, { "internalType": "uint256", "name": "SCR", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_SP", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_REDISTRIBUTION", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemColl", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemDebt", "type": "uint256" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "troveNFT", "type": "address" }, { "internalType": "address", "name": "borrowerOperations", "type": "address" }, { "internalType": "address", "name": "troveManager", "type": "address" }, { "internalType": "address", "name": "stabilityPool", "type": "address" }, { "internalType": "address", "name": "sortedTroves", "type": "address" }, { "internalType": "address", "name": "collSurplusPool", "type": "address" }, { "internalType": "address", "name": "hintHelpers", "type": "address" }, { "internalType": "address", "name": "priceFeed", "type": "address" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "bool", "name": "isShutDown", "type": "bool" }], "internalType": "struct LiquityV2View.MarketData", "name": "data", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getNumOfTrovesInFrontOfTrove", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "numTroves", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }], "name": "getTroveInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "enum ITroveManager.Status", "name": "status", "type": "uint8" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "uint256", "name": "TCRatio", "type": "uint256" }, { "internalType": "uint256", "name": "annualInterestRate", "type": "uint256" }, { "internalType": "address", "name": "interestBatchManager", "type": "address" }, { "internalType": "uint256", "name": "batchDebtShares", "type": "uint256" }], "internalType": "struct LiquityV2View.TroveData", "name": "trove", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getTrovePosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "isShutDown", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }],
|
|
1035
1035
|
"networks": {
|
|
1036
|
-
"1": { "address": "
|
|
1036
|
+
"1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
1039
|
};
|
package/esm/liquityV2/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
|
-
import { NetworkNumber } from '../types/common';
|
|
2
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
|
|
4
4
|
export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
|
|
5
|
+
export declare const getDebtInFrontLiquityV2: (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
|
|
5
6
|
export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
|
|
6
7
|
selectedMarket: LiquityV2MarketInfo;
|
|
7
8
|
assetsData: LiquityV2AssetsData;
|
package/esm/liquityV2/index.js
CHANGED
|
@@ -44,18 +44,26 @@ export const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb
|
|
|
44
44
|
const minCollRatio = new Dec(data.MCR).div(1e16).toString();
|
|
45
45
|
return { assetsData, marketData: { minCollRatio } };
|
|
46
46
|
});
|
|
47
|
+
const _getDebtInFront = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call(); });
|
|
48
|
+
export const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
|
|
50
|
+
if (next === '0')
|
|
51
|
+
return assetAmountInEth(debt);
|
|
52
|
+
return getDebtInFrontLiquityV2(viewContract, marketAddress, next, debt, iterations);
|
|
53
|
+
});
|
|
47
54
|
export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, marketData, troveId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
55
|
const viewContract = LiquityV2ViewContract(web3, network);
|
|
49
56
|
const { minCollRatio } = marketData;
|
|
50
57
|
const { collateralToken, marketAddress, debtToken } = selectedMarket;
|
|
51
|
-
const data = yield
|
|
58
|
+
const [data, debtInFront] = yield Promise.all([
|
|
59
|
+
viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
|
|
60
|
+
getDebtInFrontLiquityV2(viewContract, marketAddress, troveId),
|
|
61
|
+
]);
|
|
52
62
|
const usedAssets = {};
|
|
53
63
|
const debtAssetData = assetsData[debtToken];
|
|
54
64
|
const borrowed = assetAmountInEth(data.debtAmount);
|
|
55
65
|
usedAssets[debtToken] = {
|
|
56
66
|
symbol: debtToken,
|
|
57
|
-
address: debtAssetData.address,
|
|
58
|
-
price: debtAssetData.price,
|
|
59
67
|
supplied: '0',
|
|
60
68
|
suppliedUsd: '0',
|
|
61
69
|
borrowed,
|
|
@@ -67,8 +75,6 @@ export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsDat
|
|
|
67
75
|
const suppliedColl = assetAmountInEth(data.collAmount);
|
|
68
76
|
usedAssets[collateralToken] = {
|
|
69
77
|
symbol: collateralToken,
|
|
70
|
-
address: collAssetData.address,
|
|
71
|
-
price: collAssetData.price,
|
|
72
78
|
supplied: suppliedColl,
|
|
73
79
|
suppliedUsd: new Dec(suppliedColl).mul(collAssetData.price).toString(),
|
|
74
80
|
borrowed: '0',
|
|
@@ -84,7 +90,8 @@ export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsDat
|
|
|
84
90
|
troveId,
|
|
85
91
|
collRatio,
|
|
86
92
|
interestRate,
|
|
87
|
-
interestBatchManager,
|
|
93
|
+
interestBatchManager,
|
|
94
|
+
debtInFront, troveStatus: LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, getLiquityV2AggregatedPositionData({
|
|
88
95
|
usedAssets, assetsData, minCollRatio, interestRate,
|
|
89
96
|
}));
|
|
90
97
|
return payload;
|
package/esm/types/liquityV2.d.ts
CHANGED
|
@@ -37,8 +37,6 @@ export interface LiquityV2MarketData {
|
|
|
37
37
|
}
|
|
38
38
|
export interface LiquityV2UsedAsset {
|
|
39
39
|
symbol: string;
|
|
40
|
-
address: string;
|
|
41
|
-
price: string;
|
|
42
40
|
collateral?: boolean;
|
|
43
41
|
supplied: string;
|
|
44
42
|
suppliedUsd: string;
|
|
@@ -81,4 +79,5 @@ export interface LiquityV2TroveData {
|
|
|
81
79
|
leveragedType: string;
|
|
82
80
|
leveragedAsset: string;
|
|
83
81
|
liquidationPrice: string;
|
|
82
|
+
debtInFront: string;
|
|
84
83
|
}
|
package/package.json
CHANGED
package/src/config/contracts.js
CHANGED
|
@@ -1034,7 +1034,7 @@ module.exports = {
|
|
|
1034
1034
|
"LiquityV2View":{
|
|
1035
1035
|
"abi": [ { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_prevId", "type": "uint256" }, { "internalType": "uint256", "name": "_nextId", "type": "uint256" } ], "name": "findInsertPosition", "outputs": [ { "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" } ], "name": "getApproxHint", "outputs": [ { "internalType": "uint256", "name": "hintId", "type": "uint256" }, { "internalType": "uint256", "name": "diff", "type": "uint256" }, { "internalType": "uint256", "name": "latestRandomSeed", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" } ], "name": "getDebtInFront", "outputs": [ { "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }, { "internalType": "uint256", "name": "_targetIR", "type": "uint256" } ], "name": "getDebtInFrontByInterestRate", "outputs": [ { "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_numTroves", "type": "uint256" } ], "name": "getDebtInFrontByTroveNum", "outputs": [ { "internalType": "uint256", "name": "debt", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "address", "name": "_depositor", "type": "address" } ], "name": "getDepositorInfo", "outputs": [ { "internalType": "uint256", "name": "compoundedBOLD", "type": "uint256" }, { "internalType": "uint256", "name": "collGain", "type": "uint256" }, { "internalType": "uint256", "name": "boldGain", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" } ], "name": "getInsertPosition", "outputs": [ { "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" } ], "name": "getMarketData", "outputs": [ { "components": [ { "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "CCR", "type": "uint256" }, { "internalType": "uint256", "name": "MCR", "type": "uint256" }, { "internalType": "uint256", "name": "SCR", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_SP", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_REDISTRIBUTION", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemColl", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemDebt", "type": "uint256" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "troveNFT", "type": "address" }, { "internalType": "address", "name": "borrowerOperations", "type": "address" }, { "internalType": "address", "name": "troveManager", "type": "address" }, { "internalType": "address", "name": "stabilityPool", "type": "address" }, { "internalType": "address", "name": "sortedTroves", "type": "address" }, { "internalType": "address", "name": "collSurplusPool", "type": "address" }, { "internalType": "address", "name": "hintHelpers", "type": "address" }, { "internalType": "address", "name": "priceFeed", "type": "address" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "bool", "name": "isShutDown", "type": "bool" } ], "internalType": "struct LiquityV2View.MarketData", "name": "data", "type": "tuple" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" } ], "name": "getNumOfTrovesInFrontOfTrove", "outputs": [ { "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "numTroves", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" } ], "name": "getTroveInfo", "outputs": [ { "components": [ { "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "enum ITroveManager.Status", "name": "status", "type": "uint8" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "uint256", "name": "TCRatio", "type": "uint256" }, { "internalType": "uint256", "name": "annualInterestRate", "type": "uint256" }, { "internalType": "address", "name": "interestBatchManager", "type": "address" }, { "internalType": "uint256", "name": "batchDebtShares", "type": "uint256" } ], "internalType": "struct LiquityV2View.TroveData", "name": "trove", "type": "tuple" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" } ], "name": "getTrovePosition", "outputs": [ { "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" } ], "name": "isShutDown", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "stateMutability": "view", "type": "function" } ],
|
|
1036
1036
|
"networks": {
|
|
1037
|
-
"1": { "address": "
|
|
1037
|
+
"1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
package/src/liquityV2/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Web3 from 'web3';
|
|
|
2
2
|
import Dec from 'decimal.js';
|
|
3
3
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
4
4
|
import { LiquityV2ViewContract } from '../contracts';
|
|
5
|
-
import { NetworkNumber } from '../types/common';
|
|
5
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
6
6
|
import {
|
|
7
7
|
InnerLiquityV2MarketData,
|
|
8
8
|
LIQUITY_TROVE_STATUS_ENUM,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
12
12
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
13
13
|
import { ethToWeth } from '../services/utils';
|
|
14
|
+
import { ZERO_ADDRESS } from '../constants';
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3): Promise<LiquityV2MarketData> => {
|
|
@@ -45,6 +46,14 @@ export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber,
|
|
|
45
46
|
return { assetsData, marketData: { minCollRatio } };
|
|
46
47
|
};
|
|
47
48
|
|
|
49
|
+
const _getDebtInFront = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call();
|
|
50
|
+
|
|
51
|
+
export const getDebtInFrontLiquityV2 = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000): Promise<string> => {
|
|
52
|
+
const { debt, next } = await _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
|
|
53
|
+
if (next === '0') return assetAmountInEth(debt);
|
|
54
|
+
return getDebtInFrontLiquityV2(viewContract, marketAddress, next, debt, iterations);
|
|
55
|
+
};
|
|
56
|
+
|
|
48
57
|
export const getLiquityV2TroveData = async (
|
|
49
58
|
web3: Web3,
|
|
50
59
|
network: NetworkNumber,
|
|
@@ -64,15 +73,16 @@ export const getLiquityV2TroveData = async (
|
|
|
64
73
|
const viewContract = LiquityV2ViewContract(web3, network);
|
|
65
74
|
const { minCollRatio } = marketData;
|
|
66
75
|
const { collateralToken, marketAddress, debtToken } = selectedMarket;
|
|
67
|
-
const data = await
|
|
76
|
+
const [data, debtInFront] = await Promise.all([
|
|
77
|
+
viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
|
|
78
|
+
getDebtInFrontLiquityV2(viewContract, marketAddress, troveId),
|
|
79
|
+
]);
|
|
68
80
|
const usedAssets: LiquityV2UsedAssets = {};
|
|
69
81
|
|
|
70
82
|
const debtAssetData = assetsData[debtToken];
|
|
71
83
|
const borrowed = assetAmountInEth(data.debtAmount);
|
|
72
84
|
usedAssets[debtToken] = {
|
|
73
85
|
symbol: debtToken,
|
|
74
|
-
address: debtAssetData.address,
|
|
75
|
-
price: debtAssetData.price,
|
|
76
86
|
supplied: '0',
|
|
77
87
|
suppliedUsd: '0',
|
|
78
88
|
borrowed,
|
|
@@ -85,8 +95,6 @@ export const getLiquityV2TroveData = async (
|
|
|
85
95
|
const suppliedColl = assetAmountInEth(data.collAmount);
|
|
86
96
|
usedAssets[collateralToken] = {
|
|
87
97
|
symbol: collateralToken,
|
|
88
|
-
address: collAssetData.address,
|
|
89
|
-
price: collAssetData.price,
|
|
90
98
|
supplied: suppliedColl,
|
|
91
99
|
suppliedUsd: new Dec(suppliedColl).mul(collAssetData.price).toString(),
|
|
92
100
|
borrowed: '0',
|
|
@@ -106,6 +114,7 @@ export const getLiquityV2TroveData = async (
|
|
|
106
114
|
collRatio,
|
|
107
115
|
interestRate,
|
|
108
116
|
interestBatchManager,
|
|
117
|
+
debtInFront,
|
|
109
118
|
troveStatus: LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)],
|
|
110
119
|
...getLiquityV2AggregatedPositionData({
|
|
111
120
|
usedAssets, assetsData, minCollRatio, interestRate,
|
package/src/types/liquityV2.ts
CHANGED
|
@@ -42,8 +42,6 @@ export interface LiquityV2MarketData {
|
|
|
42
42
|
|
|
43
43
|
export interface LiquityV2UsedAsset {
|
|
44
44
|
symbol: string,
|
|
45
|
-
address: string,
|
|
46
|
-
price: string,
|
|
47
45
|
collateral?: boolean,
|
|
48
46
|
supplied: string,
|
|
49
47
|
suppliedUsd: string,
|
|
@@ -87,4 +85,5 @@ export interface LiquityV2TroveData {
|
|
|
87
85
|
leveragedType: string,
|
|
88
86
|
leveragedAsset: string,
|
|
89
87
|
liquidationPrice: string,
|
|
88
|
+
debtInFront: string,
|
|
90
89
|
}
|