mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
liquity projected debt position
This commit is contained in:
parent
67f6e463df
commit
f82f274453
|
@ -1,3 +1,4 @@
|
||||||
|
import BigNumber from "bignumber.js";
|
||||||
import abis from "~/constant/abis";
|
import abis from "~/constant/abis";
|
||||||
import addresses from "~/constant/addresses";
|
import addresses from "~/constant/addresses";
|
||||||
import {
|
import {
|
||||||
|
@ -96,6 +97,74 @@ export default defineStrategy({
|
||||||
defaults: ({ getTokenByKey, variables }) => ({
|
defaults: ({ getTokenByKey, variables }) => ({
|
||||||
token: getTokenByKey?.(variables.debtTokenKey)
|
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)}`;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,87 @@ export default defineStrategy({
|
||||||
defaults: ({ getTokenByKey }) => ({
|
defaults: ({ getTokenByKey }) => ({
|
||||||
token: getTokenByKey?.("eth")
|
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)}`;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user