Skip to content

Commit

Permalink
fixup! fix(vaultFactory): don't prevent repayment based on DebtLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Aug 16, 2024
1 parent c35ab63 commit 5cc111c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
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
12 changes: 5 additions & 7 deletions packages/inter-protocol/src/vaultFactory/vaultManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,13 +867,11 @@ export const prepareVaultManagerKit = (
const { state } = this;
const { collateralBrand, totalDebt } = state;

if (!AmountMath.isEmpty(toMint)) {
checkDebtLimit(
factoryPowers.getGovernedParams(collateralBrand).getDebtLimit(),
totalDebt,
toMint,
);
}
checkDebtLimit(
factoryPowers.getGovernedParams(collateralBrand).getDebtLimit(),
totalDebt,
toMint,
);
factoryPowers.mintAndTransfer(mintReceiver, toMint, fee, transfers);
},
/**
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)));
});

0 comments on commit 5cc111c

Please sign in to comment.