Skip to content

Instantly share code, notes, and snippets.

@bzpassersby
bzpassersby / LiquidateRevert.t.sol
Created April 21, 2023 22:00
A proof of concept showing liquidation will fail on a vulnerable market when market parameter "paymentDefaultDuration" is 0
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../contracts/TellerV2.sol";
import "../contracts/TellerV2Storage.sol";
import "../contracts/interfaces/IMarketRegistry.sol";
import "../contracts/interfaces/IReputationManager.sol";
import {ReputationManager} from "../contracts/ReputationManager.sol";
@bzpassersby
bzpassersby / PrematureLiquidationMarket.t.sol
Created April 22, 2023 13:40
A proof of concept showing the case where a loan on a market with monthly payment cycle can be liquidated before any payment is due.
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../contracts/TellerV2.sol";
import "../contracts/TellerV2Storage.sol";
import "../contracts/interfaces/IMarketRegistry.sol";
import "../contracts/interfaces/IReputationManager.sol";
import {ReputationManager} from "../contracts/ReputationManager.sol";
@bzpassersby
bzpassersby / PrematureLiquidationUser.t.sol
Created April 22, 2023 14:23
This is a proof of concept showing how a user who pays early on a loan payment could have their loan liquidated before the next payment due date.
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../contracts/TellerV2.sol";
import "../contracts/TellerV2Storage.sol";
import "../contracts/interfaces/IMarketRegistry.sol";
import "../contracts/interfaces/IReputationManager.sol";
import {ReputationManager} from "../contracts/ReputationManager.sol";
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import {MathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol";
contract LenderCommitmentForwarderExcerpt {
enum CommitmentCollateralType {
NONE, // no collateral required
@bzpassersby
bzpassersby / BorrowersInstantlyLiquidatedWhenReserveDelists.t.sol
Created May 8, 2023 21:13
Borrowers in Good Standing Instantly Liquidated after a reserve delists without a chance to repay or withdraw
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "./JUSDBankInit2.t.sol";
import "../mocks/MockChainLink900.sol";
import "../../src/utils/JUSDError.sol";
import "../../src/Impl/flashloanImpl/FlashLoanLiquidate.sol";
contract BorrowersInstantlyLiquidatedWhenReserveDelistedTest is
JUSDBankInitTest
@bzpassersby
bzpassersby / SelfLiquidateFlashLoan.t.sol
Last active May 9, 2023 18:26
When a borrower's account becomes unsafe, they can call flashloan function to self-liquidate the account, making a profit without paying the insurance fee.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "./JUSDBankInit.t.sol";
import "../mocks/MockChainLink900.sol";
import "../../src/utils/JUSDError.sol";
import "../../src/Impl/flashloanImpl/FlashLoanLiquidate.sol";
contract SelfLiquidateFlashLoanTest is JUSDBankInitTest {
/**When a borrower's account becomes unsafe, they can call flashloan function to self-liquidate the account, making a profit without
@bzpassersby
bzpassersby / MaximizedBorrowersLiquidatable.t.sol
Created May 9, 2023 22:27
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,
@bzpassersby
bzpassersby / SecondaryOracleReverts.t.sol
Created May 9, 2023 23:31
JUSDView reverts when oracle adaptor is replaced with a secondary adaptor
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "./JUSDBankInit4.t.sol";
import "../../src/utils/JUSDError.sol";
import "../../src/oracle/UniswapPriceAdaptor.sol";
import "../mocks/MockUniswapOracle.sol";
import "../mocks/MockEmergencyOracle.sol";
contract SecondaryOracleRevertsTest is JUSDBankInitTest {
@bzpassersby
bzpassersby / liquidation-test.ts
Created May 10, 2023 02:13
Even with 0 collateral deposits, user can take on trades and protocol will acquire bad debts
////Even with 0 collateral deposits, user can take on trades and protocol will acquire bad debts
////This test is in the context of JOJO unit test file -liquidation-test.ts-"check position"
it("free riding position liquidatable", async () => {
////note: test preparation to ensure trader1 has zero deposits to begin the trade
await context.dealer
.connect(trader1)
.requestWithdraw(utils.parseEther("5000"), utils.parseEther("5000"));
await timeJump(100);
@bzpassersby
bzpassersby / liquidation-test-slippage.ts
Created May 10, 2023 02:44
trader may experience drastic loss at the point of order execution due to slippage
////note: trader may experience drastic loss at the point of order execution due to slippage
////note: This test is in the context of JoJo unit test file- liquidation-test.ts-"check position"
it("trader loss due to slippage and at brink of liquidation", async () => {
//note: test preparation so that trader1 starts a trade with sufficient deposits
//note: trader1 withdraw 5000-1885=3115 (1885 is calculated in trade-test.ts with transaction execution price of 29000)
await context.dealer
.connect(trader1)
.requestWithdraw(utils.parseEther("3115"), utils.parseEther("5000"));
await timeJump(100);