liquity projected debt position

This commit is contained in:
Georges KABBOUCHI 2021-09-06 01:17:03 +03:00
parent 67f6e463df
commit f82f274453
2 changed files with 150 additions and 0 deletions

View File

@ -1,3 +1,4 @@
import BigNumber from "bignumber.js";
import abis from "~/constant/abis";
import addresses from "~/constant/addresses";
import {
@ -96,6 +97,74 @@ export default defineStrategy({
defaults: ({ getTokenByKey, variables }) => ({
token: getTokenByKey?.(variables.debtTokenKey)
})
}),
defineStrategyComponent({
type: StrategyComponentType.HEADING,
name: "Projected Debt Position"
}),
defineStrategyComponent({
type: StrategyComponentType.STATUS,
name: "Status",
update: ({ position, positionExtra, component, components, toBN }) => {
if (
toBN(components[0].value).isZero() &&
toBN(components[1].value).isZero()
) {
return;
}
if (!position && !positionExtra) {
return;
}
const troveOverallDetails = positionExtra["troveOverallDetails"];
component.liquidation = troveOverallDetails.liquidation;
component.status =
toBN(components[0].value).isZero() &&
!toBN(components[1].value).isZero()
? "1.1"
: toBN(components[1].value)
.div(toBN(components[0].value).times(position.price))
.toFixed();
}
}),
defineStrategyComponent({
type: StrategyComponentType.VALUE,
name: "LIQUIDATION PRICE (IN ETH)",
value: "-",
update: ({
position,
component,
components,
toBN,
formatting,
positionExtra
}) => {
if (!position && !positionExtra) {
return;
}
const troveOverallDetails = positionExtra["troveOverallDetails"];
let liquidationPrice =
toBN(components[0].value).isZero() &&
!toBN(components[1].value).isZero()
? toBN(position.price)
.times("1.1")
.toFixed()
: BigNumber.max(
toBN(components[1].value)
.div(components[0].value)
.div(troveOverallDetails.liquidation),
"0"
).toFixed();
component.value = `${formatting.formatUsdMax(
isNaN(parseInt(liquidationPrice)) ? "0" : liquidationPrice,
position.price
)} / ${formatting.formatUsd(position.price)}`;
}
})
],

View File

@ -90,6 +90,87 @@ export default defineStrategy({
defaults: ({ getTokenByKey }) => ({
token: getTokenByKey?.("eth")
})
}),
defineStrategyComponent({
type: StrategyComponentType.HEADING,
name: "Projected Debt Position"
}),
defineStrategyComponent({
type: StrategyComponentType.STATUS,
name: "Status",
update: ({ position, positionExtra, component, components, toBN }) => {
if (!position && !positionExtra) {
return;
}
const troveOverallDetails = positionExtra["troveOverallDetails"];
component.liquidation = troveOverallDetails.liquidation;
if (
toBN(components[1].value).isZero() ||
!components[1].value ||
toBN(components[0].value).isZero() ||
!components[0].value
) {
component.status = position.ratio;
} else {
const changedDebt = BigNumber.max(toBN(position.debt).minus(components[0].value), '0')
const changedCollateral = toBN(position.collateral).minus(components[1].value);
component.status = changedDebt
.div(toBN(changedCollateral).times(position.price))
.toFixed();
}
}
}),
defineStrategyComponent({
type: StrategyComponentType.VALUE,
name: "LIQUIDATION PRICE (IN ETH)",
value: "-",
update: ({
position,
component,
components,
toBN,
formatting,
positionExtra
}) => {
if (!position && !positionExtra) {
return;
}
const troveOverallDetails = positionExtra["troveOverallDetails"];
let liquidationPrice = "0";
if (
toBN(components[1].value).isZero() ||
!components[1].value ||
toBN(components[0].value).isZero() ||
!components[0].value
) {
liquidationPrice = BigNumber.max(
toBN(position.debt)
.div(position.collateral)
.div(troveOverallDetails.liquidation),
"0"
).toFixed();
} else {
const changedDebt = BigNumber.max(toBN(position.debt).minus(components[0].value), '0')
const changedCollateral = toBN(position.collateral).minus(components[1].value);
liquidationPrice = BigNumber.max(
toBN(changedDebt)
.div(changedCollateral)
.div(troveOverallDetails.liquidation),
"0"
).toFixed();
}
component.value = `${formatting.formatUsdMax(
isNaN(parseInt(liquidationPrice)) ? "0" : liquidationPrice,
position.price
)} / ${formatting.formatUsd(position.price)}`;
}
})
],