@defisaver/positions-sdk 0.0.166-dev-liquity-v2 → 0.0.166-dev10-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/helpers/liquityV2Helpers/index.d.ts +2 -2
- package/cjs/helpers/liquityV2Helpers/index.js +12 -2
- package/cjs/liquityV2/index.d.ts +7 -1
- package/cjs/liquityV2/index.js +60 -15
- package/cjs/markets/liquityV2/index.js +2 -2
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/types/contracts/generated/LiquityV2View.d.ts +18 -0
- package/cjs/types/liquityV2.d.ts +20 -3
- package/esm/config/contracts.d.ts +9 -18
- package/esm/config/contracts.js +2 -2
- package/esm/helpers/liquityV2Helpers/index.d.ts +2 -2
- package/esm/helpers/liquityV2Helpers/index.js +13 -3
- package/esm/liquityV2/index.d.ts +7 -1
- package/esm/liquityV2/index.js +57 -14
- package/esm/markets/liquityV2/index.js +2 -2
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/types/contracts/generated/LiquityV2View.d.ts +18 -0
- package/esm/types/liquityV2.d.ts +20 -3
- package/package.json +2 -2
- package/src/config/contracts.js +2 -2
- package/src/helpers/liquityV2Helpers/index.ts +15 -4
- package/src/liquityV2/index.ts +60 -12
- package/src/markets/liquityV2/index.ts +2 -2
- package/src/moneymarket/moneymarketCommonService.ts +1 -1
- package/src/types/contracts/generated/LiquityV2View.ts +31 -0
- package/src/types/liquityV2.ts +20 -3
|
@@ -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": "0x3113D2b6f712b163668ea9A68A84C6225d0B3c42" },
|
|
1038
1038
|
}
|
|
1039
1039
|
}
|
|
1040
1040
|
};
|
|
@@ -4,9 +4,9 @@ export declare const calculateNetApyLiquityV2: (usedAssets: LiquityV2UsedAssets,
|
|
|
4
4
|
totalInterestUsd: string;
|
|
5
5
|
incentiveUsd: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const getLiquityV2AggregatedPositionData: ({ usedAssets, assetsData,
|
|
7
|
+
export declare const getLiquityV2AggregatedPositionData: ({ usedAssets, assetsData, minCollRatio, interestRate, }: {
|
|
8
8
|
usedAssets: LiquityV2UsedAssets;
|
|
9
9
|
assetsData: LiquityV2AssetsData;
|
|
10
|
-
|
|
10
|
+
minCollRatio: string;
|
|
11
11
|
interestRate: string;
|
|
12
12
|
}) => LiquityV2AggregatedTroveData;
|
|
@@ -37,17 +37,27 @@ const calculateNetApyLiquityV2 = (usedAssets, assetsData, interestRate) => {
|
|
|
37
37
|
return { netApy, totalInterestUsd, incentiveUsd };
|
|
38
38
|
};
|
|
39
39
|
exports.calculateNetApyLiquityV2 = calculateNetApyLiquityV2;
|
|
40
|
-
const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData,
|
|
40
|
+
const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData, minCollRatio, interestRate, }) => {
|
|
41
41
|
const payload = {};
|
|
42
42
|
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, (usedAsset) => usedAsset, ({ suppliedUsd }) => suppliedUsd);
|
|
43
43
|
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, (usedAsset) => usedAsset, ({ borrowedUsd }) => borrowedUsd);
|
|
44
|
-
payload.borrowLimitUsd = new decimal_js_1.default(payload.suppliedUsd).div(
|
|
44
|
+
payload.borrowLimitUsd = new decimal_js_1.default(payload.suppliedUsd).div(minCollRatio).mul(100).toString();
|
|
45
45
|
const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
46
46
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
47
|
+
payload.ratio = +payload.suppliedUsd ? new decimal_js_1.default(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
48
|
+
payload.collRatio = +payload.suppliedUsd ? new decimal_js_1.default(payload.suppliedUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
47
49
|
const { netApy, incentiveUsd, totalInterestUsd } = (0, exports.calculateNetApyLiquityV2)(usedAssets, assetsData, interestRate);
|
|
48
50
|
payload.netApy = netApy;
|
|
49
51
|
payload.incentiveUsd = incentiveUsd;
|
|
50
52
|
payload.totalInterestUsd = totalInterestUsd;
|
|
53
|
+
const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
|
|
54
|
+
payload.leveragedType = leveragedType;
|
|
55
|
+
payload.leveragedAsset = leveragedAsset;
|
|
56
|
+
payload.liquidationPrice = '';
|
|
57
|
+
if (leveragedType !== '') {
|
|
58
|
+
const assetPrice = assetsData[leveragedAsset].price;
|
|
59
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
60
|
+
}
|
|
51
61
|
return payload;
|
|
52
62
|
};
|
|
53
63
|
exports.getLiquityV2AggregatedPositionData = getLiquityV2AggregatedPositionData;
|
package/cjs/liquityV2/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
|
-
import { NetworkNumber } from '../types/common';
|
|
2
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
|
|
4
|
+
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
|
+
}>;
|
|
10
|
+
export declare const getDebtInFrontLiquityV2: (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
|
|
5
11
|
export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
|
|
6
12
|
selectedMarket: LiquityV2MarketInfo;
|
|
7
13
|
assetsData: LiquityV2AssetsData;
|
package/cjs/liquityV2/index.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getLiquityV2TroveData = exports.getLiquityV2MarketData = void 0;
|
|
15
|
+
exports.getLiquityV2TroveData = exports.getDebtInFrontLiquityV2 = exports.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");
|
|
@@ -24,6 +24,12 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
|
|
|
24
24
|
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
25
25
|
const { marketAddress, debtToken, collateralToken } = selectedMarket;
|
|
26
26
|
const data = yield viewContract.methods.getMarketData(marketAddress).call();
|
|
27
|
+
const hintHelperAddress = data.hintHelpers;
|
|
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;
|
|
27
33
|
const assetsData = {};
|
|
28
34
|
assetsData[debtToken] = {
|
|
29
35
|
symbol: debtToken,
|
|
@@ -47,48 +53,87 @@ const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => _
|
|
|
47
53
|
assetsData[collateralToken].incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collateralToken, mainnetWeb3);
|
|
48
54
|
assetsData[collateralToken].incentiveSupplyToken = collateralToken;
|
|
49
55
|
}
|
|
50
|
-
const
|
|
51
|
-
return {
|
|
56
|
+
const minCollRatio = new decimal_js_1.default(data.MCR).div(1e16).toString();
|
|
57
|
+
return {
|
|
58
|
+
assetsData,
|
|
59
|
+
marketData: {
|
|
60
|
+
minCollRatio,
|
|
61
|
+
hintHelperAddress,
|
|
62
|
+
troveNFTAddress,
|
|
63
|
+
borrowerOperationsAddress,
|
|
64
|
+
troveManagerAddress,
|
|
65
|
+
stabilityPoolAddress,
|
|
66
|
+
collSurplusPoolAddress,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
52
69
|
});
|
|
53
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;
|
|
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(); });
|
|
88
|
+
const getDebtInFrontLiquityV2 = (viewContract, marketAddress, troveId, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const { debt, next } = yield _getDebtInFront(viewContract, marketAddress, troveId, accumulatedSum, iterations);
|
|
90
|
+
if (next === '0')
|
|
91
|
+
return (0, tokens_1.assetAmountInEth)(debt);
|
|
92
|
+
return (0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, next, debt, iterations);
|
|
93
|
+
});
|
|
94
|
+
exports.getDebtInFrontLiquityV2 = getDebtInFrontLiquityV2;
|
|
54
95
|
const getLiquityV2TroveData = (web3, network, { selectedMarket, assetsData, marketData, troveId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
96
|
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
56
|
-
const {
|
|
97
|
+
const { minCollRatio } = marketData;
|
|
57
98
|
const { collateralToken, marketAddress, debtToken } = selectedMarket;
|
|
58
|
-
const data = yield
|
|
99
|
+
const [data, debtInFront] = yield Promise.all([
|
|
100
|
+
viewContract.methods.getTroveInfo(marketAddress, troveId).call(),
|
|
101
|
+
(0, exports.getDebtInFrontLiquityV2)(viewContract, marketAddress, troveId),
|
|
102
|
+
]);
|
|
59
103
|
const usedAssets = {};
|
|
60
104
|
const debtAssetData = assetsData[debtToken];
|
|
61
105
|
const borrowed = (0, tokens_1.assetAmountInEth)(data.debtAmount);
|
|
62
106
|
usedAssets[debtToken] = {
|
|
63
107
|
symbol: debtToken,
|
|
64
|
-
address: debtAssetData.address,
|
|
65
|
-
price: debtAssetData.price,
|
|
66
108
|
supplied: '0',
|
|
67
109
|
suppliedUsd: '0',
|
|
68
110
|
borrowed,
|
|
69
111
|
borrowedUsd: new decimal_js_1.default(borrowed).mul(debtAssetData.price).toString(),
|
|
112
|
+
isBorrowed: true,
|
|
113
|
+
isSupplied: false,
|
|
70
114
|
};
|
|
71
115
|
const collAssetData = assetsData[collateralToken];
|
|
72
116
|
const suppliedColl = (0, tokens_1.assetAmountInEth)(data.collAmount);
|
|
73
117
|
usedAssets[collateralToken] = {
|
|
74
118
|
symbol: collateralToken,
|
|
75
|
-
address: collAssetData.address,
|
|
76
|
-
price: collAssetData.price,
|
|
77
119
|
supplied: suppliedColl,
|
|
78
120
|
suppliedUsd: new decimal_js_1.default(suppliedColl).mul(collAssetData.price).toString(),
|
|
79
121
|
borrowed: '0',
|
|
80
122
|
borrowedUsd: '0',
|
|
123
|
+
isBorrowed: false,
|
|
124
|
+
isSupplied: true,
|
|
125
|
+
collateral: true,
|
|
81
126
|
};
|
|
82
|
-
const
|
|
127
|
+
const collRatio = new decimal_js_1.default(data.TCRatio).div(1e16).toString();
|
|
83
128
|
const interestRate = new decimal_js_1.default(data.annualInterestRate).div(1e16).toString();
|
|
84
129
|
const interestBatchManager = data.interestBatchManager;
|
|
85
|
-
const payload = Object.assign({ usedAssets,
|
|
130
|
+
const payload = Object.assign(Object.assign({ usedAssets,
|
|
86
131
|
troveId,
|
|
87
|
-
ratio,
|
|
88
132
|
interestRate,
|
|
89
|
-
interestBatchManager,
|
|
90
|
-
|
|
91
|
-
|
|
133
|
+
interestBatchManager,
|
|
134
|
+
debtInFront, troveStatus: types_1.LIQUITY_TROVE_STATUS_ENUM[parseInt(data.status, 10)] }, (0, liquityV2Helpers_1.getLiquityV2AggregatedPositionData)({
|
|
135
|
+
usedAssets, assetsData, minCollRatio, interestRate,
|
|
136
|
+
})), { collRatio });
|
|
92
137
|
return payload;
|
|
93
138
|
});
|
|
94
139
|
exports.getLiquityV2TroveData = getLiquityV2TroveData;
|
|
@@ -11,7 +11,7 @@ const LIQUITY_V2_ETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
|
|
|
11
11
|
url: 'eth',
|
|
12
12
|
debtToken: 'BOLD',
|
|
13
13
|
collateralToken: 'ETH',
|
|
14
|
-
marketAddress: '
|
|
14
|
+
marketAddress: '0x7d2d2c79ec89c7f1d718ae1586363ad2c56ded9d',
|
|
15
15
|
protocolName: 'liquity-v2',
|
|
16
16
|
});
|
|
17
17
|
exports.LIQUITY_V2_ETH_MARKET = LIQUITY_V2_ETH_MARKET;
|
|
@@ -23,7 +23,7 @@ const LIQUITY_V2_WSTETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
|
|
|
23
23
|
url: 'wsteth',
|
|
24
24
|
debtToken: 'BOLD',
|
|
25
25
|
collateralToken: 'wstETH',
|
|
26
|
-
marketAddress: '
|
|
26
|
+
marketAddress: '0x83b74f12a2894fcf7a4864eff6090d7d8a060c6b',
|
|
27
27
|
protocolName: 'liquity-v2',
|
|
28
28
|
});
|
|
29
29
|
exports.LIQUITY_V2_WSTETH_MARKET = LIQUITY_V2_WSTETH_MARKET;
|
|
@@ -27,7 +27,7 @@ const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimit
|
|
|
27
27
|
exports.calcLeverageLiqPrice = calcLeverageLiqPrice;
|
|
28
28
|
const calculateBorrowingAssetLimit = (assetBorrowedUsd, borrowLimitUsd) => new decimal_js_1.default(assetBorrowedUsd).div(borrowLimitUsd).times(100).toString();
|
|
29
29
|
exports.calculateBorrowingAssetLimit = calculateBorrowingAssetLimit;
|
|
30
|
-
exports.STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD'];
|
|
30
|
+
exports.STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD', 'BOLD'];
|
|
31
31
|
const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
32
32
|
let borrowUnstable = 0;
|
|
33
33
|
let supplyStable = 0;
|
|
@@ -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
|
@@ -29,7 +29,13 @@ export type LiquityV2AssetsData = {
|
|
|
29
29
|
[key: string]: LiquityV2AssetData;
|
|
30
30
|
};
|
|
31
31
|
export interface InnerLiquityV2MarketData {
|
|
32
|
-
|
|
32
|
+
minCollRatio: string;
|
|
33
|
+
hintHelperAddress: EthAddress;
|
|
34
|
+
troveNFTAddress: EthAddress;
|
|
35
|
+
borrowerOperationsAddress: EthAddress;
|
|
36
|
+
troveManagerAddress: EthAddress;
|
|
37
|
+
stabilityPoolAddress: EthAddress;
|
|
38
|
+
collSurplusPoolAddress: EthAddress;
|
|
33
39
|
}
|
|
34
40
|
export interface LiquityV2MarketData {
|
|
35
41
|
assetsData: LiquityV2AssetsData;
|
|
@@ -37,12 +43,13 @@ export interface LiquityV2MarketData {
|
|
|
37
43
|
}
|
|
38
44
|
export interface LiquityV2UsedAsset {
|
|
39
45
|
symbol: string;
|
|
40
|
-
|
|
41
|
-
price: string;
|
|
46
|
+
collateral?: boolean;
|
|
42
47
|
supplied: string;
|
|
43
48
|
suppliedUsd: string;
|
|
44
49
|
borrowed: string;
|
|
45
50
|
borrowedUsd: string;
|
|
51
|
+
isSupplied: boolean;
|
|
52
|
+
isBorrowed: boolean;
|
|
46
53
|
}
|
|
47
54
|
export type LiquityV2UsedAssets = {
|
|
48
55
|
[key: string]: LiquityV2UsedAsset;
|
|
@@ -55,11 +62,17 @@ export interface LiquityV2AggregatedTroveData {
|
|
|
55
62
|
netApy: string;
|
|
56
63
|
incentiveUsd: string;
|
|
57
64
|
totalInterestUsd: string;
|
|
65
|
+
leveragedType: string;
|
|
66
|
+
leveragedAsset: string;
|
|
67
|
+
liquidationPrice: string;
|
|
68
|
+
ratio: string;
|
|
69
|
+
collRatio: string;
|
|
58
70
|
}
|
|
59
71
|
export interface LiquityV2TroveData {
|
|
60
72
|
usedAssets: LiquityV2UsedAssets;
|
|
61
73
|
troveId: string;
|
|
62
74
|
ratio: string;
|
|
75
|
+
collRatio: string;
|
|
63
76
|
interestRate: string;
|
|
64
77
|
leftToBorrowUsd: string;
|
|
65
78
|
borrowLimitUsd: string;
|
|
@@ -70,4 +83,8 @@ export interface LiquityV2TroveData {
|
|
|
70
83
|
totalInterestUsd: string;
|
|
71
84
|
interestBatchManager: EthAddress;
|
|
72
85
|
troveStatus: string;
|
|
86
|
+
leveragedType: string;
|
|
87
|
+
leveragedAsset: string;
|
|
88
|
+
liquidationPrice: string;
|
|
89
|
+
debtInFront: string;
|
|
73
90
|
}
|
|
@@ -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": "0x3113D2b6f712b163668ea9A68A84C6225d0B3c42" },
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
1039
|
};
|
|
@@ -4,9 +4,9 @@ export declare const calculateNetApyLiquityV2: (usedAssets: LiquityV2UsedAssets,
|
|
|
4
4
|
totalInterestUsd: string;
|
|
5
5
|
incentiveUsd: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const getLiquityV2AggregatedPositionData: ({ usedAssets, assetsData,
|
|
7
|
+
export declare const getLiquityV2AggregatedPositionData: ({ usedAssets, assetsData, minCollRatio, interestRate, }: {
|
|
8
8
|
usedAssets: LiquityV2UsedAssets;
|
|
9
9
|
assetsData: LiquityV2AssetsData;
|
|
10
|
-
|
|
10
|
+
minCollRatio: string;
|
|
11
11
|
interestRate: string;
|
|
12
12
|
}) => LiquityV2AggregatedTroveData;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetsTotal } from '../../moneymarket';
|
|
2
|
+
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
3
3
|
import { calculateInterestEarned } from '../../staking';
|
|
4
4
|
export const calculateNetApyLiquityV2 = (usedAssets, assetsData, interestRate) => {
|
|
5
5
|
const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
|
|
@@ -30,16 +30,26 @@ export const calculateNetApyLiquityV2 = (usedAssets, assetsData, interestRate) =
|
|
|
30
30
|
const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
|
|
31
31
|
return { netApy, totalInterestUsd, incentiveUsd };
|
|
32
32
|
};
|
|
33
|
-
export const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData,
|
|
33
|
+
export const getLiquityV2AggregatedPositionData = ({ usedAssets, assetsData, minCollRatio, interestRate, }) => {
|
|
34
34
|
const payload = {};
|
|
35
35
|
payload.suppliedUsd = getAssetsTotal(usedAssets, (usedAsset) => usedAsset, ({ suppliedUsd }) => suppliedUsd);
|
|
36
36
|
payload.borrowedUsd = getAssetsTotal(usedAssets, (usedAsset) => usedAsset, ({ borrowedUsd }) => borrowedUsd);
|
|
37
|
-
payload.borrowLimitUsd = new Dec(payload.suppliedUsd).div(
|
|
37
|
+
payload.borrowLimitUsd = new Dec(payload.suppliedUsd).div(minCollRatio).mul(100).toString();
|
|
38
38
|
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
39
39
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
40
|
+
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
41
|
+
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
40
42
|
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApyLiquityV2(usedAssets, assetsData, interestRate);
|
|
41
43
|
payload.netApy = netApy;
|
|
42
44
|
payload.incentiveUsd = incentiveUsd;
|
|
43
45
|
payload.totalInterestUsd = totalInterestUsd;
|
|
46
|
+
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
47
|
+
payload.leveragedType = leveragedType;
|
|
48
|
+
payload.leveragedAsset = leveragedAsset;
|
|
49
|
+
payload.liquidationPrice = '';
|
|
50
|
+
if (leveragedType !== '') {
|
|
51
|
+
const assetPrice = assetsData[leveragedAsset].price;
|
|
52
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
53
|
+
}
|
|
44
54
|
return payload;
|
|
45
55
|
};
|
package/esm/liquityV2/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
|
-
import { NetworkNumber } from '../types/common';
|
|
2
|
+
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
|
|
4
|
+
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
|
+
}>;
|
|
10
|
+
export declare const getDebtInFrontLiquityV2: (viewContract: any, marketAddress: EthAddress, troveId: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
|
|
5
11
|
export declare const getLiquityV2TroveData: (web3: Web3, network: NetworkNumber, { selectedMarket, assetsData, marketData, troveId, }: {
|
|
6
12
|
selectedMarket: LiquityV2MarketInfo;
|
|
7
13
|
assetsData: LiquityV2AssetsData;
|