@defisaver/positions-sdk 0.0.166-dev7-liquity-v2 → 0.0.166-dev8-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.
@@ -6697,28 +6697,14 @@ export namespace LlamaLendControllerAbi {
6697
6697
  export { networks_76 as networks };
6698
6698
  }
6699
6699
  export namespace LiquityV2View {
6700
- let abi_77: ({
6700
+ let abi_77: {
6701
6701
  inputs: {
6702
6702
  internalType: string;
6703
6703
  name: string;
6704
6704
  type: string;
6705
6705
  }[];
6706
6706
  name: string;
6707
- outputs: {
6708
- internalType: string;
6709
- name: string;
6710
- type: string;
6711
- }[];
6712
- stateMutability: string;
6713
- type: string;
6714
- } | {
6715
- inputs: {
6716
- internalType: string;
6717
- name: string;
6718
- type: string;
6719
- }[];
6720
- name: string;
6721
- outputs: {
6707
+ outputs: ({
6722
6708
  components: {
6723
6709
  internalType: string;
6724
6710
  name: string;
@@ -6727,10 +6713,15 @@ export namespace LiquityV2View {
6727
6713
  internalType: string;
6728
6714
  name: string;
6729
6715
  type: string;
6730
- }[];
6716
+ } | {
6717
+ internalType: string;
6718
+ name: string;
6719
+ type: string;
6720
+ components?: undefined;
6721
+ })[];
6731
6722
  stateMutability: string;
6732
6723
  type: string;
6733
- })[];
6724
+ }[];
6734
6725
  export { abi_77 as abi };
6735
6726
  let networks_77: {
6736
6727
  "1": {
@@ -1032,9 +1032,9 @@ module.exports = {
1032
1032
  "networks": {}
1033
1033
  },
1034
1034
  "LiquityV2View": {
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" }],
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": "_user", "type": "address" }, { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_startIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_endIndex", "type": "uint256" }], "name": "getUserTroves", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "bool", "name": "ownedByUser", "type": "bool" }], "internalType": "struct LiquityV2View.ExistingTrove[]", "name": "troves", "type": "tuple[]" }, { "internalType": "int256", "name": "nextFreeTroveIndex", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "isShutDown", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "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": "_debtIncrease", "type": "uint256" }], "name": "predictAdjustTroveUpfrontFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }],
1036
1036
  "networks": {
1037
- "1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
1037
+ "1": { "address": "0x7DC97868B4b2Fd31c1002E9bfFe9a4aF2b534c06" },
1038
1038
  }
1039
1039
  }
1040
1040
  };
@@ -1,7 +1,12 @@
1
1
  import Web3 from 'web3';
2
2
  import { EthAddress, NetworkNumber } from '../types/common';
3
3
  import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
4
+ import { LiquityV2View } from '../types/contracts/generated';
4
5
  export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
6
+ export declare const getLiquityV2UserTroveIds: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, account: EthAddress) => Promise<{
7
+ troves: LiquityV2View.ExistingTroveStructOutput[];
8
+ nextFreeTroveIndex: string;
9
+ }>;
5
10
  export declare const getDebtInFrontLiquityV2: (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
6
11
  export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
7
12
  selectedMarket: LiquityV2MarketInfo;
@@ -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.getDebtInFrontLiquityV2 = exports.getLiquityV2MarketData = void 0;
15
+ exports.getLiquityV2TroveData = exports.getDebtInFrontLiquityV2 = exports.getLiquityV2UserTroveIds = 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");
@@ -52,6 +52,22 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
52
52
  return { assetsData, marketData: { minCollRatio, hintHelperAddress } };
53
53
  });
54
54
  exports.getLiquityV2MarketData = getLiquityV2MarketData;
55
+ const _getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getUserTroves(account, marketAddress, startIndex, endIndex).call(); });
56
+ const getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100, troves = []) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const result = yield _getUserTroves(viewContract, account, marketAddress, startIndex, endIndex);
58
+ const newStartIndex = endIndex + 1;
59
+ const nextFreeTroveIndex = result.nextFreeTroveIndex;
60
+ const existingTroves = [...troves, ...result.troves];
61
+ if (nextFreeTroveIndex !== '-1')
62
+ return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
63
+ return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
64
+ });
65
+ const getLiquityV2UserTroveIds = (web3, network, selectedMarket, account) => __awaiter(void 0, void 0, void 0, function* () {
66
+ const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
67
+ const { troves, nextFreeTroveIndex } = yield getUserTroves(viewContract, account, selectedMarket.marketAddress);
68
+ return { troves, nextFreeTroveIndex };
69
+ });
70
+ exports.getLiquityV2UserTroveIds = getLiquityV2UserTroveIds;
55
71
  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
72
  const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
57
73
  const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
@@ -146,6 +146,16 @@ export declare namespace LiquityV2View {
146
146
  batchDebtShares: string;
147
147
  };
148
148
  type TroveDataStructOutput = TroveDataStructOutputArray & TroveDataStructOutputStruct;
149
+ type ExistingTroveStruct = [number | string | BN, boolean] | {
150
+ troveId: number | string | BN;
151
+ ownedByUser: boolean;
152
+ };
153
+ type ExistingTroveStructOutputArray = [string, boolean];
154
+ type ExistingTroveStructOutputStruct = {
155
+ troveId: string;
156
+ ownedByUser: boolean;
157
+ };
158
+ type ExistingTroveStructOutput = ExistingTroveStructOutputArray & ExistingTroveStructOutputStruct;
149
159
  }
150
160
  export interface LiquityV2View extends BaseContract {
151
161
  constructor(jsonInterface: any[], address?: string, options?: ContractOptions): LiquityV2View;
@@ -214,7 +224,15 @@ export interface LiquityV2View extends BaseContract {
214
224
  prevId: string;
215
225
  nextId: string;
216
226
  }>;
227
+ getUserTroves(_user: string, _market: string, _startIndex: number | string | BN, _endIndex: number | string | BN): NonPayableTransactionObject<[
228
+ LiquityV2View.ExistingTroveStructOutput[],
229
+ string
230
+ ] & {
231
+ troves: LiquityV2View.ExistingTroveStructOutput[];
232
+ nextFreeTroveIndex: string;
233
+ }>;
217
234
  isShutDown(_market: string): NonPayableTransactionObject<boolean>;
235
+ predictAdjustTroveUpfrontFee(_market: string, _collIndex: number | string | BN, _troveId: number | string | BN, _debtIncrease: number | string | BN): NonPayableTransactionObject<string>;
218
236
  };
219
237
  events: {
220
238
  allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
@@ -6697,28 +6697,14 @@ export namespace LlamaLendControllerAbi {
6697
6697
  export { networks_76 as networks };
6698
6698
  }
6699
6699
  export namespace LiquityV2View {
6700
- let abi_77: ({
6700
+ let abi_77: {
6701
6701
  inputs: {
6702
6702
  internalType: string;
6703
6703
  name: string;
6704
6704
  type: string;
6705
6705
  }[];
6706
6706
  name: string;
6707
- outputs: {
6708
- internalType: string;
6709
- name: string;
6710
- type: string;
6711
- }[];
6712
- stateMutability: string;
6713
- type: string;
6714
- } | {
6715
- inputs: {
6716
- internalType: string;
6717
- name: string;
6718
- type: string;
6719
- }[];
6720
- name: string;
6721
- outputs: {
6707
+ outputs: ({
6722
6708
  components: {
6723
6709
  internalType: string;
6724
6710
  name: string;
@@ -6727,10 +6713,15 @@ export namespace LiquityV2View {
6727
6713
  internalType: string;
6728
6714
  name: string;
6729
6715
  type: string;
6730
- }[];
6716
+ } | {
6717
+ internalType: string;
6718
+ name: string;
6719
+ type: string;
6720
+ components?: undefined;
6721
+ })[];
6731
6722
  stateMutability: string;
6732
6723
  type: string;
6733
- })[];
6724
+ }[];
6734
6725
  export { abi_77 as abi };
6735
6726
  let networks_77: {
6736
6727
  "1": {
@@ -1031,9 +1031,9 @@ module.exports = {
1031
1031
  "networks": {}
1032
1032
  },
1033
1033
  "LiquityV2View": {
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" }],
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": "_user", "type": "address" }, { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_startIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_endIndex", "type": "uint256" }], "name": "getUserTroves", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "bool", "name": "ownedByUser", "type": "bool" }], "internalType": "struct LiquityV2View.ExistingTrove[]", "name": "troves", "type": "tuple[]" }, { "internalType": "int256", "name": "nextFreeTroveIndex", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "isShutDown", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "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": "_debtIncrease", "type": "uint256" }], "name": "predictAdjustTroveUpfrontFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }],
1035
1035
  "networks": {
1036
- "1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
1036
+ "1": { "address": "0x7DC97868B4b2Fd31c1002E9bfFe9a4aF2b534c06" },
1037
1037
  }
1038
1038
  }
1039
1039
  };
@@ -1,7 +1,12 @@
1
1
  import Web3 from 'web3';
2
2
  import { EthAddress, NetworkNumber } from '../types/common';
3
3
  import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
4
+ import { LiquityV2View } from '../types/contracts/generated';
4
5
  export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
6
+ export declare const getLiquityV2UserTroveIds: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, account: EthAddress) => Promise<{
7
+ troves: LiquityV2View.ExistingTroveStructOutput[];
8
+ nextFreeTroveIndex: string;
9
+ }>;
5
10
  export declare const getDebtInFrontLiquityV2: (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
6
11
  export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
7
12
  selectedMarket: LiquityV2MarketInfo;
@@ -45,6 +45,21 @@ export const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb
45
45
  const minCollRatio = new Dec(data.MCR).div(1e16).toString();
46
46
  return { assetsData, marketData: { minCollRatio, hintHelperAddress } };
47
47
  });
48
+ const _getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getUserTroves(account, marketAddress, startIndex, endIndex).call(); });
49
+ const getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100, troves = []) => __awaiter(void 0, void 0, void 0, function* () {
50
+ const result = yield _getUserTroves(viewContract, account, marketAddress, startIndex, endIndex);
51
+ const newStartIndex = endIndex + 1;
52
+ const nextFreeTroveIndex = result.nextFreeTroveIndex;
53
+ const existingTroves = [...troves, ...result.troves];
54
+ if (nextFreeTroveIndex !== '-1')
55
+ return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
56
+ return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
57
+ });
58
+ export const getLiquityV2UserTroveIds = (web3, network, selectedMarket, account) => __awaiter(void 0, void 0, void 0, function* () {
59
+ const viewContract = LiquityV2ViewContract(web3, network);
60
+ const { troves, nextFreeTroveIndex } = yield getUserTroves(viewContract, account, selectedMarket.marketAddress);
61
+ return { troves, nextFreeTroveIndex };
62
+ });
48
63
  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
64
  export const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
50
65
  const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
@@ -146,6 +146,16 @@ export declare namespace LiquityV2View {
146
146
  batchDebtShares: string;
147
147
  };
148
148
  type TroveDataStructOutput = TroveDataStructOutputArray & TroveDataStructOutputStruct;
149
+ type ExistingTroveStruct = [number | string | BN, boolean] | {
150
+ troveId: number | string | BN;
151
+ ownedByUser: boolean;
152
+ };
153
+ type ExistingTroveStructOutputArray = [string, boolean];
154
+ type ExistingTroveStructOutputStruct = {
155
+ troveId: string;
156
+ ownedByUser: boolean;
157
+ };
158
+ type ExistingTroveStructOutput = ExistingTroveStructOutputArray & ExistingTroveStructOutputStruct;
149
159
  }
150
160
  export interface LiquityV2View extends BaseContract {
151
161
  constructor(jsonInterface: any[], address?: string, options?: ContractOptions): LiquityV2View;
@@ -214,7 +224,15 @@ export interface LiquityV2View extends BaseContract {
214
224
  prevId: string;
215
225
  nextId: string;
216
226
  }>;
227
+ getUserTroves(_user: string, _market: string, _startIndex: number | string | BN, _endIndex: number | string | BN): NonPayableTransactionObject<[
228
+ LiquityV2View.ExistingTroveStructOutput[],
229
+ string
230
+ ] & {
231
+ troves: LiquityV2View.ExistingTroveStructOutput[];
232
+ nextFreeTroveIndex: string;
233
+ }>;
217
234
  isShutDown(_market: string): NonPayableTransactionObject<boolean>;
235
+ predictAdjustTroveUpfrontFee(_market: string, _collIndex: number | string | BN, _troveId: number | string | BN, _debtIncrease: number | string | BN): NonPayableTransactionObject<string>;
218
236
  };
219
237
  events: {
220
238
  allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.166-dev7-liquity-v2",
3
+ "version": "0.0.166-dev8-liquity-v2",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -1032,9 +1032,9 @@ module.exports = {
1032
1032
  "networks":{}
1033
1033
  },
1034
1034
  "LiquityV2View":{
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" } ],
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": "_user", "type": "address" }, { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_startIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_endIndex", "type": "uint256" } ], "name": "getUserTroves", "outputs": [ { "components": [ { "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "bool", "name": "ownedByUser", "type": "bool" } ], "internalType": "struct LiquityV2View.ExistingTrove[]", "name": "troves", "type": "tuple[]" }, { "internalType": "int256", "name": "nextFreeTroveIndex", "type": "int256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_market", "type": "address" } ], "name": "isShutDown", "outputs": [ { "internalType": "bool", "name": "", "type": "bool" } ], "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": "_debtIncrease", "type": "uint256" } ], "name": "predictAdjustTroveUpfrontFee", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" } ],
1036
1036
  "networks": {
1037
- "1": { "address": "0xD484E43F56e2A83D8D4476b803dAEc99c557b4a8" },
1037
+ "1": { "address": "0x7DC97868B4b2Fd31c1002E9bfFe9a4aF2b534c06" },
1038
1038
  }
1039
1039
  }
1040
1040
  }
@@ -12,6 +12,7 @@ import { getStakingApy, STAKING_ASSETS } from '../staking';
12
12
  import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
13
13
  import { ethToWeth } from '../services/utils';
14
14
  import { ZERO_ADDRESS } from '../constants';
15
+ import { LiquityV2View } from '../types/contracts/generated';
15
16
 
16
17
 
17
18
  export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3): Promise<LiquityV2MarketData> => {
@@ -47,6 +48,23 @@ export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber,
47
48
  return { assetsData, marketData: { minCollRatio, hintHelperAddress } };
48
49
  };
49
50
 
51
+ const _getUserTroves = async (viewContract: any, account: EthAddress, marketAddress: EthAddress, startIndex = 0, endIndex = 100) => viewContract.methods.getUserTroves(account, marketAddress, startIndex, endIndex).call();
52
+
53
+ const getUserTroves = async (viewContract: any, account: EthAddress, marketAddress: EthAddress, startIndex = 0, endIndex = 100, troves: LiquityV2View.ExistingTroveStructOutput[] = []): Promise<{ troves: LiquityV2View.ExistingTroveStructOutput[], nextFreeTroveIndex: string }> => {
54
+ const result = await _getUserTroves(viewContract, account, marketAddress, startIndex, endIndex);
55
+ const newStartIndex = endIndex + 1;
56
+ const nextFreeTroveIndex = result.nextFreeTroveIndex;
57
+ const existingTroves = [...troves, ...result.troves];
58
+ if (nextFreeTroveIndex !== '-1') return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
59
+ return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
60
+ };
61
+
62
+ export const getLiquityV2UserTroveIds = async (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, account: EthAddress): Promise<{ troves: LiquityV2View.ExistingTroveStructOutput[], nextFreeTroveIndex: string }> => {
63
+ const viewContract = LiquityV2ViewContract(web3, network);
64
+ const { troves, nextFreeTroveIndex } = await getUserTroves(viewContract, account, selectedMarket.marketAddress);
65
+ return { troves, nextFreeTroveIndex };
66
+ };
67
+
50
68
  const _getDebtInFront = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call();
51
69
 
52
70
  export const getDebtInFrontLiquityV2 = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000): Promise<string> => {
@@ -167,6 +167,18 @@ export declare namespace LiquityV2View {
167
167
  };
168
168
  export type TroveDataStructOutput = TroveDataStructOutputArray &
169
169
  TroveDataStructOutputStruct;
170
+
171
+ export type ExistingTroveStruct =
172
+ | [number | string | BN, boolean]
173
+ | { troveId: number | string | BN; ownedByUser: boolean };
174
+
175
+ export type ExistingTroveStructOutputArray = [string, boolean];
176
+ export type ExistingTroveStructOutputStruct = {
177
+ troveId: string;
178
+ ownedByUser: boolean;
179
+ };
180
+ export type ExistingTroveStructOutput = ExistingTroveStructOutputArray &
181
+ ExistingTroveStructOutputStruct;
170
182
  }
171
183
 
172
184
  export interface LiquityV2View extends BaseContract {
@@ -272,7 +284,26 @@ export interface LiquityV2View extends BaseContract {
272
284
  [string, string] & { prevId: string; nextId: string }
273
285
  >;
274
286
 
287
+ getUserTroves(
288
+ _user: string,
289
+ _market: string,
290
+ _startIndex: number | string | BN,
291
+ _endIndex: number | string | BN
292
+ ): NonPayableTransactionObject<
293
+ [LiquityV2View.ExistingTroveStructOutput[], string] & {
294
+ troves: LiquityV2View.ExistingTroveStructOutput[];
295
+ nextFreeTroveIndex: string;
296
+ }
297
+ >;
298
+
275
299
  isShutDown(_market: string): NonPayableTransactionObject<boolean>;
300
+
301
+ predictAdjustTroveUpfrontFee(
302
+ _market: string,
303
+ _collIndex: number | string | BN,
304
+ _troveId: number | string | BN,
305
+ _debtIncrease: number | string | BN
306
+ ): NonPayableTransactionObject<string>;
276
307
  };
277
308
  events: {
278
309
  allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;