From 5ba99b1ba13ee86ea3b83e0a77155782a3f0d016 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Mon, 5 Aug 2024 09:27:53 -0500 Subject: [PATCH 1/2] test(vaultFactory): repay works regardless of mintLimit --- .../vault-collateralization.test.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/inter-protocol/test/vaultFactory/vault-collateralization.test.js b/packages/inter-protocol/test/vaultFactory/vault-collateralization.test.js index 3aebc47a106..9d269e13141 100644 --- a/packages/inter-protocol/test/vaultFactory/vault-collateralization.test.js +++ b/packages/inter-protocol/test/vaultFactory/vault-collateralization.test.js @@ -30,6 +30,28 @@ test('excessive loan', async t => { ); }); +test('repay works regardless of debtLimit', async t => { + const { aeth, run } = t.context; + const md = await makeManagerDriver(t); + + // take debt that comes just shy of max + const vd = await md.makeVaultDriver(aeth.make(1000n), run.make(4500n)); + t.deepEqual(await E(vd.vault()).getCurrentDebt(), run.make(4725n)); + + const MARGIN_HOP = 20n; + + // we can take a loan and pay it back + await vd.giveCollateral(100n, aeth, MARGIN_HOP); + await vd.giveMinted(MARGIN_HOP, aeth, 100n); + + // EC lowers mint limit + await md.setGovernedParam('DebtLimit', run.make(1000n), { + key: { collateralBrand: aeth.brand }, + }); + // we can still repay debt + await vd.giveMinted(MARGIN_HOP, aeth); +}); + test('add debt to vault under LiquidationMarging + LiquidationPadding', async t => { const { aeth, run } = t.context; const md = await makeManagerDriver(t); From 1c94ac89b9e94d0855a524d5c0adba4212e1bbc5 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Fri, 16 Aug 2024 09:51:15 -0500 Subject: [PATCH 2/2] fix(vaultFactory): don't prevent repayment based on DebtLimit --- packages/inter-protocol/src/contractSupport.js | 5 +++++ packages/inter-protocol/test/contractSupport.test.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/inter-protocol/src/contractSupport.js b/packages/inter-protocol/src/contractSupport.js index bc1941561a0..119f819fc89 100644 --- a/packages/inter-protocol/src/contractSupport.js +++ b/packages/inter-protocol/src/contractSupport.js @@ -67,8 +67,13 @@ export const allEmpty = amounts => { * @param {Amount<'nat'>} totalDebt * @param {Amount<'nat'>} toMint * @throws if minting would exceed total debt + * + * Note: Succeeds regardless of debtLimit if toMint is empty. */ export const checkDebtLimit = (debtLimit, totalDebt, toMint) => { + if (AmountMath.isEmpty(toMint)) { + return; + } const debtPost = AmountMath.add(totalDebt, toMint); AmountMath.isGTE(debtLimit, debtPost) || Fail`Minting ${q(toMint)} past ${q( diff --git a/packages/inter-protocol/test/contractSupport.test.js b/packages/inter-protocol/test/contractSupport.test.js index c7a43bab1aa..cbea5608a91 100644 --- a/packages/inter-protocol/test/contractSupport.test.js +++ b/packages/inter-protocol/test/contractSupport.test.js @@ -20,3 +20,8 @@ test('checkDebtLimit allows at limit', t => { test('checkDebtLimit throws above', t => { t.throws(() => checkDebtLimit(limit, prior, debt.make(3n))); }); + +test('checkDebtLimit always succeeds if there is nothing to mint', t => { + const bigPrior = debt.make(5n); + t.notThrows(() => checkDebtLimit(limit, bigPrior, debt.make(0n))); +});