Skip to content

Commit

Permalink
bugfix: generous post maturity repay allowance
Browse files Browse the repository at this point in the history
  • Loading branch information
brucedonovan committed Mar 30, 2022
1 parent 93cef0f commit ec0747f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app-v2",
"version": "2.1.10",
"version": "2.1.11",
"private": true,
"dependencies": {
"@multiavatar/multiavatar": "^1.0.6",
Expand Down
14 changes: 11 additions & 3 deletions src/hooks/actionHooks/useRepayDebt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const useRepayDebt = () => {

const inputGreaterThanDebt: boolean = ethers.BigNumber.from(_inputAsFyToken).gte(vault.accruedArt);
const inputGreaterThanMaxBaseIn = _input.gt(_MaxBaseIn);

const _inputforClose = (vault.accruedArt.gt(ZERO_BN) && vault.accruedArt.lte(_input)) ? vault.accruedArt : _input;

/* if requested, and all debt will be repaid, automatically remove collateral */
Expand All @@ -104,13 +105,20 @@ export const useRepayDebt = () => {
reclaimToAddress = ladleAddress;
}

const alreadyApproved = (
const alreadyApproved = !series.seriesIsMature && (
await base.getAllowance(
account!,
series.seriesIsMature || inputGreaterThanMaxBaseIn ? base.joinAddress : ladleAddress
inputGreaterThanMaxBaseIn ? base.joinAddress : ladleAddress
)
).gte(_input);

const alreadyApprovedPostMaturity = series.seriesIsMature && (
await base.getAllowance(
account!,
base.joinAddress
)
).gte(_inputforClose.mul(2));

const permits: ICallData[] = await sign(
[
{
Expand All @@ -132,7 +140,7 @@ export const useRepayDebt = () => {
target: base,
spender: base.joinAddress,
amount: MAX_256,
ignoreIf: !series.seriesIsMature || alreadyApproved === true,
ignoreIf: !series.seriesIsMature || alreadyApprovedPostMaturity === true,
},
],
txCode
Expand Down

0 comments on commit ec0747f

Please sign in to comment.