From 52845480aa18dd76165b7997bcb2b4fad3e7c3be Mon Sep 17 00:00:00 2001 From: Dean Tribble Date: Mon, 5 Apr 2021 21:03:10 -0700 Subject: [PATCH] fix: allow liq margin plus fees for new loans (#2813) Co-authored-by: Dean Tribble --- packages/treasury/src/vault.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/treasury/src/vault.js b/packages/treasury/src/vault.js index 16efbea2532..5631d708d5f 100644 --- a/packages/treasury/src/vault.js +++ b/packages/treasury/src/vault.js @@ -82,7 +82,7 @@ export function makeVaultKit( runBrand, ); - return divideBy(getAmountOut(quoteAmount), manager.getInitialMargin()); + return divideBy(getAmountOut(quoteAmount), manager.getLiquidationMargin()); } async function assertSufficientCollateral(collateralAmount, wantedRun) { @@ -379,7 +379,6 @@ export function makeVaultKit( } = seat.getProposal(); const collateralPayoutP = E(userSeat).getPayouts(); - await assertSufficientCollateral(collateralAmount, wantedRun); // todo trigger process() check right away, in case the price dropped while we ran @@ -389,6 +388,8 @@ export function makeVaultKit( } runDebt = amountMath.add(wantedRun, fee); + await assertSufficientCollateral(collateralAmount, runDebt); + runMint.mintGains({ RUN: runDebt }, vaultSeat); const priorCollateral = getCollateralAllocated(vaultSeat);