Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bzpassersby/3aaf06271af160f0283fd7998aeed0c3 to your computer and use it in GitHub Desktop.
Save bzpassersby/3aaf06271af160f0283fd7998aeed0c3 to your computer and use it in GitHub Desktop.
Key global and reserve settings such as borrowFeeRate, Reserve.liquidateMortgageRate and Reserve.initialMortgageRate not checked and reverted.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "./JUSDBankInit3.t.sol";
import "../../src/utils/JUSDError.sol";
import {DecimalMath} from "../../src/lib/DecimalMath.sol";
/**
* @notice Key global and reserve settings such as borrowFeeRate, Reserve.liquidateMortgageRate and Reserve.initialMortgageRate not checked and reverted.
* This tests when borrowFeeRate is set high and when liquidateMortageRate is eqaul or too close to initialMortgageRate,
* maximized borrowers may become almost instanly liquidated after borrow.
* @dev Global and token reserve settings in JUSDBankInit3.t.sol:
* borrowFeeRate= 1e17;
* mockToken1 reserve:
* initialMortgageRate= 8e17;
* liquidateMortgageRate= 8e17;
*/
contract MaximizedBorrowersLiquidatableTest is JUSDBankInitTest {
using DecimalMath for uint256;
function test_maximizedBorrowers_liquidatable() public {
mockToken1.transfer(alice, 10 * ONE);
vm.startPrank(alice);
mockToken1.approve(address(jusdBank), 10 * ONE);
jusdBank.deposit(alice, address(mockToken1), 10 * ONE, alice); //Alice deposited 10 weth
vm.warp(1000);
console.log("TRate", jusdBank.getTRate());
//log: 1000003167808219178
uint256 maxBorrowAmount = jusdBank.getDepositMaxMintAmount(alice);
console.log("Max Borrow Amount", maxBorrowAmount);
//log: 8000000000
jusdBank.borrow(maxBorrowAmount, alice, false); //Alice borrowed 8000 JUSD
assertEq(jusdBank.isAccountSafe(alice), true); ////Alice's account is safe
uint256 aliceBorrow = jusdBank.getBorrowBalance(alice);
console.log("Borrow Balance", aliceBorrow);
//log: 8000000000
vm.stopPrank();
vm.warp(1050); // 1050 seconds passed
console.log("TRate", jusdBank.getTRate());
//log: 1000003326357179096
aliceBorrow = jusdBank.getBorrowBalance(alice);
console.log("Borrow Balance", aliceBorrow);
//log: 8000001268
assertEq(jusdBank.isAccountSafe(alice), false); ////Alice's account is not safe and can be liquidated instantly!
uint256 usdcAmount = jojoOracle1.getAssetPrice().decimalMul(10 * ONE);
console.log(usdcAmount - maxBorrowAmount);
//log: 2000000000 (2000 usdc)
assertEq(usdcAmount - maxBorrowAmount > 0, true);
////Alice lost a value of 2000 usdc due to liquidation, even though she only borrowed for 1050 seconds!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment