@defisaver/positions-sdk 0.0.166-dev7-liquity-v2 → 0.0.166-dev9-liquity-v2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/config/contracts.d.ts +9 -18
- package/cjs/config/contracts.js +2 -2
- package/cjs/liquityV2/index.d.ts +5 -0
- package/cjs/liquityV2/index.js +34 -2
- package/cjs/types/contracts/generated/LiquityV2View.d.ts +18 -0
- package/cjs/types/liquityV2.d.ts +5 -0
- package/esm/config/contracts.d.ts +9 -18
- package/esm/config/contracts.js +2 -2
- package/esm/liquityV2/index.d.ts +5 -0
- package/esm/liquityV2/index.js +32 -1
- package/esm/types/contracts/generated/LiquityV2View.d.ts +18 -0
- package/esm/types/liquityV2.d.ts +5 -0
- package/package.json +1 -1
- package/src/config/contracts.js +2 -2
- package/src/liquityV2/index.ts +35 -1
- package/src/types/contracts/generated/LiquityV2View.ts +31 -0
- package/src/types/liquityV2.ts +5 -0
|
@@ -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": {
|
package/cjs/config/contracts.js
CHANGED
|
@@ -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": "
|
|
1037
|
+
"1": { "address": "0x7DC97868B4b2Fd31c1002E9bfFe9a4aF2b534c06" },
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
};
|
package/cjs/liquityV2/index.d.ts
CHANGED
|
@@ -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;
|
package/cjs/liquityV2/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getLiquityV2TroveData = exports.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");
|
|
@@ -25,6 +25,11 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
|
|
|
25
25
|
const { marketAddress, debtToken, collateralToken } = selectedMarket;
|
|
26
26
|
const data = yield viewContract.methods.getMarketData(marketAddress).call();
|
|
27
27
|
const hintHelperAddress = data.hintHelpers;
|
|
28
|
+
const troveNFTAddress = data.troveNFT;
|
|
29
|
+
const borrowerOperationsAddress = data.borrowerOperations;
|
|
30
|
+
const troveManagerAddress = data.troveManager;
|
|
31
|
+
const stabilityPoolAddress = data.stabilityPool;
|
|
32
|
+
const collSurplusPoolAddress = data.collSurplusPool;
|
|
28
33
|
const assetsData = {};
|
|
29
34
|
assetsData[debtToken] = {
|
|
30
35
|
symbol: debtToken,
|
|
@@ -49,9 +54,36 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
|
|
|
49
54
|
assetsData[collateralToken].incentiveSupplyToken = collateralToken;
|
|
50
55
|
}
|
|
51
56
|
const minCollRatio = new decimal_js_1.default(data.MCR).div(1e16).toString();
|
|
52
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
assetsData,
|
|
59
|
+
marketData: {
|
|
60
|
+
minCollRatio,
|
|
61
|
+
hintHelperAddress,
|
|
62
|
+
troveNFTAddress,
|
|
63
|
+
borrowerOperationsAddress,
|
|
64
|
+
troveManagerAddress,
|
|
65
|
+
stabilityPoolAddress,
|
|
66
|
+
collSurplusPoolAddress,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
53
69
|
});
|
|
54
70
|
exports.getLiquityV2MarketData = getLiquityV2MarketData;
|
|
71
|
+
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(); });
|
|
72
|
+
const getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100, troves = []) => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
const result = yield _getUserTroves(viewContract, account, marketAddress, startIndex, endIndex);
|
|
74
|
+
const newStartIndex = endIndex + 1;
|
|
75
|
+
const nextFreeTroveIndex = result.nextFreeTroveIndex;
|
|
76
|
+
const existingTroves = [...troves, ...result.troves];
|
|
77
|
+
if (nextFreeTroveIndex !== '-1')
|
|
78
|
+
return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
|
|
79
|
+
return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
80
|
+
});
|
|
81
|
+
const getLiquityV2UserTroveIds = (web3, network, selectedMarket, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
+
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
83
|
+
const { troves, nextFreeTroveIndex } = yield getUserTroves(viewContract, account, selectedMarket.marketAddress);
|
|
84
|
+
return { troves, nextFreeTroveIndex };
|
|
85
|
+
});
|
|
86
|
+
exports.getLiquityV2UserTroveIds = getLiquityV2UserTroveIds;
|
|
55
87
|
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
88
|
const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
89
|
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/cjs/types/liquityV2.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export type LiquityV2AssetsData = {
|
|
|
31
31
|
export interface InnerLiquityV2MarketData {
|
|
32
32
|
minCollRatio: string;
|
|
33
33
|
hintHelperAddress: EthAddress;
|
|
34
|
+
troveNFTAddress: EthAddress;
|
|
35
|
+
borrowerOperationsAddress: EthAddress;
|
|
36
|
+
troveManagerAddress: EthAddress;
|
|
37
|
+
stabilityPoolAddress: EthAddress;
|
|
38
|
+
collSurplusPoolAddress: EthAddress;
|
|
34
39
|
}
|
|
35
40
|
export interface LiquityV2MarketData {
|
|
36
41
|
assetsData: LiquityV2AssetsData;
|
|
@@ -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": {
|
package/esm/config/contracts.js
CHANGED
|
@@ -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": "
|
|
1036
|
+
"1": { "address": "0x7DC97868B4b2Fd31c1002E9bfFe9a4aF2b534c06" },
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
1039
|
};
|
package/esm/liquityV2/index.d.ts
CHANGED
|
@@ -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;
|
package/esm/liquityV2/index.js
CHANGED
|
@@ -19,6 +19,11 @@ export const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb
|
|
|
19
19
|
const { marketAddress, debtToken, collateralToken } = selectedMarket;
|
|
20
20
|
const data = yield viewContract.methods.getMarketData(marketAddress).call();
|
|
21
21
|
const hintHelperAddress = data.hintHelpers;
|
|
22
|
+
const troveNFTAddress = data.troveNFT;
|
|
23
|
+
const borrowerOperationsAddress = data.borrowerOperations;
|
|
24
|
+
const troveManagerAddress = data.troveManager;
|
|
25
|
+
const stabilityPoolAddress = data.stabilityPool;
|
|
26
|
+
const collSurplusPoolAddress = data.collSurplusPool;
|
|
22
27
|
const assetsData = {};
|
|
23
28
|
assetsData[debtToken] = {
|
|
24
29
|
symbol: debtToken,
|
|
@@ -43,7 +48,33 @@ export const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb
|
|
|
43
48
|
assetsData[collateralToken].incentiveSupplyToken = collateralToken;
|
|
44
49
|
}
|
|
45
50
|
const minCollRatio = new Dec(data.MCR).div(1e16).toString();
|
|
46
|
-
return {
|
|
51
|
+
return {
|
|
52
|
+
assetsData,
|
|
53
|
+
marketData: {
|
|
54
|
+
minCollRatio,
|
|
55
|
+
hintHelperAddress,
|
|
56
|
+
troveNFTAddress,
|
|
57
|
+
borrowerOperationsAddress,
|
|
58
|
+
troveManagerAddress,
|
|
59
|
+
stabilityPoolAddress,
|
|
60
|
+
collSurplusPoolAddress,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
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(); });
|
|
65
|
+
const getUserTroves = (viewContract, account, marketAddress, startIndex = 0, endIndex = 100, troves = []) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const result = yield _getUserTroves(viewContract, account, marketAddress, startIndex, endIndex);
|
|
67
|
+
const newStartIndex = endIndex + 1;
|
|
68
|
+
const nextFreeTroveIndex = result.nextFreeTroveIndex;
|
|
69
|
+
const existingTroves = [...troves, ...result.troves];
|
|
70
|
+
if (nextFreeTroveIndex !== '-1')
|
|
71
|
+
return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
|
|
72
|
+
return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
73
|
+
});
|
|
74
|
+
export const getLiquityV2UserTroveIds = (web3, network, selectedMarket, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
const viewContract = LiquityV2ViewContract(web3, network);
|
|
76
|
+
const { troves, nextFreeTroveIndex } = yield getUserTroves(viewContract, account, selectedMarket.marketAddress);
|
|
77
|
+
return { troves, nextFreeTroveIndex };
|
|
47
78
|
});
|
|
48
79
|
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
80
|
export const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -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/esm/types/liquityV2.d.ts
CHANGED
|
@@ -31,6 +31,11 @@ export type LiquityV2AssetsData = {
|
|
|
31
31
|
export interface InnerLiquityV2MarketData {
|
|
32
32
|
minCollRatio: string;
|
|
33
33
|
hintHelperAddress: EthAddress;
|
|
34
|
+
troveNFTAddress: EthAddress;
|
|
35
|
+
borrowerOperationsAddress: EthAddress;
|
|
36
|
+
troveManagerAddress: EthAddress;
|
|
37
|
+
stabilityPoolAddress: EthAddress;
|
|
38
|
+
collSurplusPoolAddress: EthAddress;
|
|
34
39
|
}
|
|
35
40
|
export interface LiquityV2MarketData {
|
|
36
41
|
assetsData: LiquityV2AssetsData;
|
package/package.json
CHANGED
package/src/config/contracts.js
CHANGED
|
@@ -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": "
|
|
1037
|
+
"1": { "address": "0x7DC97868B4b2Fd31c1002E9bfFe9a4aF2b534c06" },
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
}
|
package/src/liquityV2/index.ts
CHANGED
|
@@ -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> => {
|
|
@@ -19,6 +20,11 @@ export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber,
|
|
|
19
20
|
const { marketAddress, debtToken, collateralToken } = selectedMarket;
|
|
20
21
|
const data = await viewContract.methods.getMarketData(marketAddress).call();
|
|
21
22
|
const hintHelperAddress = data.hintHelpers;
|
|
23
|
+
const troveNFTAddress = data.troveNFT;
|
|
24
|
+
const borrowerOperationsAddress = data.borrowerOperations;
|
|
25
|
+
const troveManagerAddress = data.troveManager;
|
|
26
|
+
const stabilityPoolAddress = data.stabilityPool;
|
|
27
|
+
const collSurplusPoolAddress = data.collSurplusPool;
|
|
22
28
|
const assetsData: LiquityV2AssetsData = {};
|
|
23
29
|
assetsData[debtToken] = {
|
|
24
30
|
symbol: debtToken,
|
|
@@ -44,7 +50,35 @@ export const getLiquityV2MarketData = async (web3: Web3, network: NetworkNumber,
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
const minCollRatio = new Dec(data.MCR).div(1e16).toString();
|
|
47
|
-
return {
|
|
53
|
+
return {
|
|
54
|
+
assetsData,
|
|
55
|
+
marketData: {
|
|
56
|
+
minCollRatio,
|
|
57
|
+
hintHelperAddress,
|
|
58
|
+
troveNFTAddress,
|
|
59
|
+
borrowerOperationsAddress,
|
|
60
|
+
troveManagerAddress,
|
|
61
|
+
stabilityPoolAddress,
|
|
62
|
+
collSurplusPoolAddress,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const _getUserTroves = async (viewContract: any, account: EthAddress, marketAddress: EthAddress, startIndex = 0, endIndex = 100) => viewContract.methods.getUserTroves(account, marketAddress, startIndex, endIndex).call();
|
|
68
|
+
|
|
69
|
+
const getUserTroves = async (viewContract: any, account: EthAddress, marketAddress: EthAddress, startIndex = 0, endIndex = 100, troves: LiquityV2View.ExistingTroveStructOutput[] = []): Promise<{ troves: LiquityV2View.ExistingTroveStructOutput[], nextFreeTroveIndex: string }> => {
|
|
70
|
+
const result = await _getUserTroves(viewContract, account, marketAddress, startIndex, endIndex);
|
|
71
|
+
const newStartIndex = endIndex + 1;
|
|
72
|
+
const nextFreeTroveIndex = result.nextFreeTroveIndex;
|
|
73
|
+
const existingTroves = [...troves, ...result.troves];
|
|
74
|
+
if (nextFreeTroveIndex !== '-1') return { troves: existingTroves.filter((trove) => trove.ownedByUser), nextFreeTroveIndex };
|
|
75
|
+
return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const getLiquityV2UserTroveIds = async (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, account: EthAddress): Promise<{ troves: LiquityV2View.ExistingTroveStructOutput[], nextFreeTroveIndex: string }> => {
|
|
79
|
+
const viewContract = LiquityV2ViewContract(web3, network);
|
|
80
|
+
const { troves, nextFreeTroveIndex } = await getUserTroves(viewContract, account, selectedMarket.marketAddress);
|
|
81
|
+
return { troves, nextFreeTroveIndex };
|
|
48
82
|
};
|
|
49
83
|
|
|
50
84
|
const _getDebtInFront = async (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(marketAddress, troveId, accumulatedSum, iterations).call();
|
|
@@ -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;
|
package/src/types/liquityV2.ts
CHANGED
|
@@ -34,6 +34,11 @@ export type LiquityV2AssetsData = { [key: string]: LiquityV2AssetData };
|
|
|
34
34
|
export interface InnerLiquityV2MarketData {
|
|
35
35
|
minCollRatio: string,
|
|
36
36
|
hintHelperAddress: EthAddress,
|
|
37
|
+
troveNFTAddress: EthAddress,
|
|
38
|
+
borrowerOperationsAddress: EthAddress,
|
|
39
|
+
troveManagerAddress: EthAddress,
|
|
40
|
+
stabilityPoolAddress: EthAddress,
|
|
41
|
+
collSurplusPoolAddress: EthAddress,
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
export interface LiquityV2MarketData {
|