Skip to content

Commit

Permalink
fix: underwater repay
Browse files Browse the repository at this point in the history
  • Loading branch information
Macket committed May 19, 2023
1 parent ab2225e commit 8eab250
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/llammas/LlammaTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
isEth,
_cutZeros,
MAX_ALLOWANCE,
MAX_ACTIVE_BAND,
} from "../utils";
import { IDict } from "../interfaces";

Expand Down Expand Up @@ -933,13 +934,15 @@ export class LlammaTemplate {

const _debt = parseUnits(debt);
const contract = crvusd.contracts[this.controller].contract;
const [_, n] = await this.userBands(address);
const gas = await contract.estimateGas.repay(_debt, address, n-1, false, crvusd.constantOptions);
const [_, n1] = await this.userBands(address);
const { stablecoin } = await this.userState(address);
const n = (BN(stablecoin).gt(0)) ? MAX_ACTIVE_BAND : n1 - 1; // In liquidation mode it doesn't matter if active band moves
const gas = await contract.estimateGas.repay(_debt, address, n, false, crvusd.constantOptions);
if (estimateGas) return gas.toNumber();

await crvusd.updateFeeData();
const gasLimit = gas.mul(130).div(100);
return (await contract.repay(_debt, address, n-1, false, { ...crvusd.options, gasLimit })).hash
return (await contract.repay(_debt, address, n, false, { ...crvusd.options, gasLimit })).hash
}

public async repayEstimateGas(debt: number | string, address = ""): Promise<number> {
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { _getPoolsFromApi } from "./external-api";
import { crvusd } from "./crvusd";

export const MAX_ALLOWANCE = ethers.BigNumber.from(2).pow(ethers.BigNumber.from(256)).sub(ethers.BigNumber.from(1));
export const MAX_ACTIVE_BAND = ethers.BigNumber.from(2).pow(ethers.BigNumber.from(255)).sub(ethers.BigNumber.from(1));

// bignumber.js

Expand Down

0 comments on commit 8eab250

Please sign in to comment.