Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vaultFactory): don't prevent repayment based on DebtLimit #9907

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/inter-protocol/src/contractSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions packages/inter-protocol/test/contractSupport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading