add close trove strategy for Liquity

This commit is contained in:
Georges KABBOUCHI 2021-09-05 13:25:42 +03:00
parent 90d0379510
commit 0b8eeab3ee
3 changed files with 69 additions and 8 deletions

View File

@ -1,11 +1,11 @@
import AaveV2 from "./protocols/aave-v2"
import Compound from "./protocols/compound"
import Liquity from "./protocols/liquity"
import AaveV2 from "./protocols/aave-v2";
import Compound from "./protocols/compound";
import Liquity from "./protocols/liquity";
export const protocolStrategies = {
aaveV2 : AaveV2,
compound : Compound,
liquity : Liquity,
}
aaveV2: AaveV2,
compound: Compound,
liquity: Liquity
};
export * from "./helpers"
export * from "./helpers";

View File

@ -0,0 +1,59 @@
import { defineStrategy, StrategyProtocol } from "../../helpers";
export default defineStrategy({
protocol: StrategyProtocol.LIQUITY,
name: "Close Trove",
description:
"Close trove: Payback debt, withdraw Collateral & Liquidation Reserve.",
author: "Instadapp Team",
submitText: "Close Trove",
details: `<p class="text-center">This strategy executes:</p>
<ul>
<li>Close Trove</li>
</ul>`,
inputs: [],
validate: async ({
position,
positionExtra,
toBN,
getTokenByKey,
dsaBalances
}) => {
const troveOpened =
!toBN(position.collateral).isZero() && !toBN(position.debt).isZero();
if (!troveOpened) {
return "You should open new trove first";
}
const troveOverallDetails = positionExtra["troveOverallDetails"];
const netDebt = toBN(position.debt).minus(
troveOverallDetails.liquidationReserve
);
const debtToken = getTokenByKey("lusd");
const debtTokenBalance = dsaBalances[debtToken.address].balance;
if (toBN(position.debt).gt(debtTokenBalance)) {
const lackOfBalance = netDebt.minus(debtTokenBalance).toPrecision(6, 0);
return `You need ${lackOfBalance} ${debtToken.symbol} more to close your Trove.`;
}
},
spells: async () => {
const setId = 0;
return [
{
connector: "LIQUITY-A",
method: "close",
args: [setId]
}
];
}
});

View File

@ -1,8 +1,10 @@
import depositAndBorrow from "./deposit-and-borrow"
import paybackAndWithdraw from "./payback-and-withdraw"
import closeTrove from "./close-trove"
export default [
depositAndBorrow,
paybackAndWithdraw,
closeTrove,
]