@defisaver/positions-sdk 0.0.166-dev4-liquity-v2 → 0.0.166-dev6-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.
@@ -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": "0x88bBa5Ce5cE20286Cf866b9f310354FFB701A296" },
1037
+ "1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
1038
1038
  }
1039
1039
  }
1040
1040
  };
@@ -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;
@@ -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");
@@ -24,6 +24,7 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
24
24
  const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
25
25
  const { marketAddress, debtToken, collateralToken } = selectedMarket;
26
26
  const data = yield viewContract.methods.getMarketData(marketAddress).call();
27
+ const hintHelperAddress = data.hintHelpers;
27
28
  const assetsData = {};
28
29
  assetsData[debtToken] = {
29
30
  symbol: debtToken,
@@ -48,21 +49,30 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
48
49
  assetsData[collateralToken].incentiveSupplyToken = collateralToken;
49
50
  }
50
51
  const minCollRatio = new decimal_js_1.default(data.MCR).div(1e16).toString();
51
- return { assetsData, marketData: { minCollRatio } };
52
+ return { assetsData, marketData: { minCollRatio, hintHelperAddress } };
52
53
  });
53
54
  exports.getLiquityV2MarketData = getLiquityV2MarketData;
55
+ 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(); });
56
+ const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
58
+ if (next === '0')
59
+ return (0, tokens_1.assetAmountInEth)(debt);
60
+ return (0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, next, debt, iterations);
61
+ });
62
+ exports.getDebtInFrontLiquityV2 = getDebtInFrontLiquityV2;
54
63
  const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, marketData, troveId, }) => __awaiter(void 0, void 0, void 0, function* () {
55
64
  const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
56
65
  const { minCollRatio } = marketData;
57
66
  const { collateralToken, marketAddress, debtToken } = selectedMarket;
58
- const data = yield viewContract.methods.getTroveInfo(marketAddress, troveId).call();
67
+ const [data, debtInFront] = yield Promise.all([
68
+ viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
69
+ (0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, troveId),
70
+ ]);
59
71
  const usedAssets = {};
60
72
  const debtAssetData = assetsData[debtToken];
61
73
  const borrowed = (0, tokens_1.assetAmountInEth)(data.debtAmount);
62
74
  usedAssets[debtToken] = {
63
75
  symbol: debtToken,
64
- address: debtAssetData.address,
65
- price: debtAssetData.price,
66
76
  supplied: '0',
67
77
  suppliedUsd: '0',
68
78
  borrowed,
@@ -74,8 +84,6 @@ const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, mark
74
84
  const suppliedColl = (0, tokens_1.assetAmountInEth)(data.collAmount);
75
85
  usedAssets[collateralToken] = {
76
86
  symbol: collateralToken,
77
- address: collAssetData.address,
78
- price: collAssetData.price,
79
87
  supplied: suppliedColl,
80
88
  suppliedUsd: new decimal_js_1.default(suppliedColl).mul(collAssetData.price).toString(),
81
89
  borrowed: '0',
@@ -91,7 +99,8 @@ const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, mark
91
99
  troveId,
92
100
  collRatio,
93
101
  interestRate,
94
- interestBatchManager, troveStatus: types_1.LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, (0, liquityV2Helpers_1.getLiquityV2AggregatedPositionData)({
102
+ interestBatchManager,
103
+ debtInFront, troveStatus: types_1.LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, (0, liquityV2Helpers_1.getLiquityV2AggregatedPositionData)({
95
104
  usedAssets, assetsData, minCollRatio, interestRate,
96
105
  }));
97
106
  return payload;
@@ -30,6 +30,7 @@ export type LiquityV2AssetsData = {
30
30
  };
31
31
  export interface InnerLiquityV2MarketData {
32
32
  minCollRatio: string;
33
+ hintHelperAddress: EthAddress;
33
34
  }
34
35
  export interface LiquityV2MarketData {
35
36
  assetsData: LiquityV2AssetsData;
@@ -37,8 +38,6 @@ export interface LiquityV2MarketData {
37
38
  }
38
39
  export interface LiquityV2UsedAsset {
39
40
  symbol: string;
40
- address: string;
41
- price: string;
42
41
  collateral?: boolean;
43
42
  supplied: string;
44
43
  suppliedUsd: string;
@@ -81,4 +80,5 @@ export interface LiquityV2TroveData {
81
80
  leveragedType: string;
82
81
  leveragedAsset: string;
83
82
  liquidationPrice: string;
83
+ debtInFront: string;
84
84
  }
@@ -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": "0x88bBa5Ce5cE20286Cf866b9f310354FFB701A296" },
1036
+ "1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
1037
1037
  }
1038
1038
  }
1039
1039
  };
@@ -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;
@@ -18,6 +18,7 @@ export const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb
18
18
  const viewContract = LiquityV2ViewContract(web3, network);
19
19
  const { marketAddress, debtToken, collateralToken } = selectedMarket;
20
20
  const data = yield viewContract.methods.getMarketData(marketAddress).call();
21
+ const hintHelperAddress = data.hintHelpers;
21
22
  const assetsData = {};
22
23
  assetsData[debtToken] = {
23
24
  symbol: debtToken,
@@ -42,20 +43,28 @@ export const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb
42
43
  assetsData[collateralToken].incentiveSupplyToken = collateralToken;
43
44
  }
44
45
  const minCollRatio = new Dec(data.MCR).div(1e16).toString();
45
- return { assetsData, marketData: { minCollRatio } };
46
+ return { assetsData, marketData: { minCollRatio, hintHelperAddress } };
47
+ });
48
+ 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(); });
49
+ export const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
50
+ const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
51
+ if (next === '0')
52
+ return assetAmountInEth(debt);
53
+ return getDebtInFrontLiquityV2(viewContract, marketAddress, next, debt, iterations);
46
54
  });
47
55
  export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, marketData, troveId, }) => __awaiter(void 0, void 0, void 0, function* () {
48
56
  const viewContract = LiquityV2ViewContract(web3, network);
49
57
  const { minCollRatio } = marketData;
50
58
  const { collateralToken, marketAddress, debtToken } = selectedMarket;
51
- const data = yield viewContract.methods.getTroveInfo(marketAddress, troveId).call();
59
+ const [data, debtInFront] = yield Promise.all([
60
+ viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
61
+ getDebtInFrontLiquityV2(viewContract, marketAddress, troveId),
62
+ ]);
52
63
  const usedAssets = {};
53
64
  const debtAssetData = assetsData[debtToken];
54
65
  const borrowed = assetAmountInEth(data.debtAmount);
55
66
  usedAssets[debtToken] = {
56
67
  symbol: debtToken,
57
- address: debtAssetData.address,
58
- price: debtAssetData.price,
59
68
  supplied: '0',
60
69
  suppliedUsd: '0',
61
70
  borrowed,
@@ -67,8 +76,6 @@ export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsDat
67
76
  const suppliedColl = assetAmountInEth(data.collAmount);
68
77
  usedAssets[collateralToken] = {
69
78
  symbol: collateralToken,
70
- address: collAssetData.address,
71
- price: collAssetData.price,
72
79
  supplied: suppliedColl,
73
80
  suppliedUsd: new Dec(suppliedColl).mul(collAssetData.price).toString(),
74
81
  borrowed: '0',
@@ -84,7 +91,8 @@ export const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsDat
84
91
  troveId,
85
92
  collRatio,
86
93
  interestRate,
87
- interestBatchManager, troveStatus: LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, getLiquityV2AggregatedPositionData({
94
+ interestBatchManager,
95
+ debtInFront, troveStatus: LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, getLiquityV2AggregatedPositionData({
88
96
  usedAssets, assetsData, minCollRatio, interestRate,
89
97
  }));
90
98
  return payload;
@@ -30,6 +30,7 @@ export type LiquityV2AssetsData = {
30
30
  };
31
31
  export interface InnerLiquityV2MarketData {
32
32
  minCollRatio: string;
33
+ hintHelperAddress: EthAddress;
33
34
  }
34
35
  export interface LiquityV2MarketData {
35
36
  assetsData: LiquityV2AssetsData;
@@ -37,8 +38,6 @@ export interface LiquityV2MarketData {
37
38
  }
38
39
  export interface LiquityV2UsedAsset {
39
40
  symbol: string;
40
- address: string;
41
- price: string;
42
41
  collateral?: boolean;
43
42
  supplied: string;
44
43
  suppliedUsd: string;
@@ -81,4 +80,5 @@ export interface LiquityV2TroveData {
81
80
  leveragedType: string;
82
81
  leveragedAsset: string;
83
82
  liquidationPrice: string;
83
+ debtInFront: string;
84
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.166-dev4-liquity-v2",
3
+ "version": "0.0.166-dev6-liquity-v2",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -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": "0x88bBa5Ce5cE20286Cf866b9f310354FFB701A296" },
1037
+ "1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
1038
1038
  }
1039
1039
  }
1040
1040
  }
@@ -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,12 +11,14 @@ 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> => {
17
18
  const viewContract = LiquityV2ViewContract(web3, network);
18
19
  const { marketAddress, debtToken, collateralToken } = selectedMarket;
19
20
  const data = await viewContract.methods.getMarketData(marketAddress).call();
21
+ const hintHelperAddress = data.hintHelpers;
20
22
  const assetsData: LiquityV2AssetsData = {};
21
23
  assetsData[debtToken] = {
22
24
  symbol: debtToken,
@@ -42,7 +44,15 @@ export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber,
42
44
  }
43
45
 
44
46
  const minCollRatio = new Dec(data.MCR).div(1e16).toString();
45
- return { assetsData, marketData: { minCollRatio } };
47
+ return { assetsData, marketData: { minCollRatio, hintHelperAddress } };
48
+ };
49
+
50
+ const _getDebtInFront = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call();
51
+
52
+ export const getDebtInFrontLiquityV2 = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000): Promise<string> => {
53
+ const { debt, next } = await _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
54
+ if (next === '0') return assetAmountInEth(debt);
55
+ return getDebtInFrontLiquityV2(viewContract, marketAddress, next, debt, iterations);
46
56
  };
47
57
 
48
58
  export const getLiquityV2TroveData = async (
@@ -64,15 +74,16 @@ export const getLiquityV2TroveData = async (
64
74
  const viewContract = LiquityV2ViewContract(web3, network);
65
75
  const { minCollRatio } = marketData;
66
76
  const { collateralToken, marketAddress, debtToken } = selectedMarket;
67
- const data = await viewContract.methods.getTroveInfo(marketAddress, troveId).call();
77
+ const [data, debtInFront] = await Promise.all([
78
+ viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
79
+ getDebtInFrontLiquityV2(viewContract, marketAddress, troveId),
80
+ ]);
68
81
  const usedAssets: LiquityV2UsedAssets = {};
69
82
 
70
83
  const debtAssetData = assetsData[debtToken];
71
84
  const borrowed = assetAmountInEth(data.debtAmount);
72
85
  usedAssets[debtToken] = {
73
86
  symbol: debtToken,
74
- address: debtAssetData.address,
75
- price: debtAssetData.price,
76
87
  supplied: '0',
77
88
  suppliedUsd: '0',
78
89
  borrowed,
@@ -85,8 +96,6 @@ export const getLiquityV2TroveData = async (
85
96
  const suppliedColl = assetAmountInEth(data.collAmount);
86
97
  usedAssets[collateralToken] = {
87
98
  symbol: collateralToken,
88
- address: collAssetData.address,
89
- price: collAssetData.price,
90
99
  supplied: suppliedColl,
91
100
  suppliedUsd: new Dec(suppliedColl).mul(collAssetData.price).toString(),
92
101
  borrowed: '0',
@@ -106,6 +115,7 @@ export const getLiquityV2TroveData = async (
106
115
  collRatio,
107
116
  interestRate,
108
117
  interestBatchManager,
118
+ debtInFront,
109
119
  troveStatus: LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)],
110
120
  ...getLiquityV2AggregatedPositionData({
111
121
  usedAssets, assetsData, minCollRatio, interestRate,
@@ -33,6 +33,7 @@ export type LiquityV2AssetsData = { [key: string]: LiquityV2AssetData };
33
33
 
34
34
  export interface InnerLiquityV2MarketData {
35
35
  minCollRatio: string,
36
+ hintHelperAddress: EthAddress,
36
37
  }
37
38
 
38
39
  export interface LiquityV2MarketData {
@@ -42,8 +43,6 @@ export interface LiquityV2MarketData {
42
43
 
43
44
  export interface LiquityV2UsedAsset {
44
45
  symbol: string,
45
- address: string,
46
- price: string,
47
46
  collateral?: boolean,
48
47
  supplied: string,
49
48
  suppliedUsd: string,
@@ -87,4 +86,5 @@ export interface LiquityV2TroveData {
87
86
  leveragedType: string,
88
87
  leveragedAsset: string,
89
88
  liquidationPrice: string,
89
+ debtInFront: string,
90
90
  }