Skip to content

Instantly share code, notes, and snippets.

@bzpassersby
bzpassersby / L1ECOBridgeWithdrawSucceed.spec.ts
Created June 6, 2023 14:30
POC L1 finalize withdraw succeed with 0 hardcoded gas value.
/* eslint-disable camelcase */
import { ethers, network } from 'hardhat'
import { Signer, Contract, constants, BigNumber } from 'ethers'
import { smock, FakeContract, MockContract } from '@defi-wonderland/smock'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { expect } from 'chai'
import {
REGISTRY_DEPLOY_TX,
REGISTRY_DEPLOYER_ADDRESS,
/* eslint-disable camelcase */
import { ethers, upgrades } from 'hardhat'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { AddressZero } from '@ethersproject/constants'
import { NON_NULL_BYTES32, NON_ZERO_ADDRESS } from './utils/constants'
import { expect } from 'chai'
import { ERROR_STRINGS } from './utils/errors'
import { deployL2Test, transferOwnershipTest } from './utils/fixtures'
import { L2ECO, L2ECOBridge, ProxyAdmin } from '../typechain-types'
const hre = require('hardhat')
@bzpassersby
bzpassersby / L1L2ECOBridgeMEVAttack.spec.ts
Created May 25, 2023 14:27
L1 MEV attack or L2 sequencer front running
/* eslint-disable camelcase */
import { ethers } from 'hardhat'
import { Signer, Contract, constants, BigNumber } from 'ethers'
import { smock, FakeContract, MockContract } from '@defi-wonderland/smock'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import * as L1CrossDomainMessenger from '@eth-optimism/contracts/artifacts/contracts/L1/messaging/L1CrossDomainMessenger.sol/L1CrossDomainMessenger.json'
import * as L2CrossDomainMessenger from '@eth-optimism/contracts/artifacts/contracts/L2/messaging/L2CrossDomainMessenger.sol/L2CrossDomainMessenger.json'
import { expect } from 'chai'
import {
REGISTRY_DEPLOY_TX,
@bzpassersby
bzpassersby / liquidation-test-max-withdraw.ts
Last active May 10, 2023 14:54
a trader can maximally withdraw against temporary PnL and being liquidated instantly after with profits
////note: a trader can maximally withdraw against temporary PnL and being liquidated instantly after with profits
////note: Two tests conditions below. The first test results in bad debts not covered. The second test trader maximally withdraw before and after liquidation with profits.
////note: This test is in the context of JOJO unit tet file- liquidation-test.ts-"check position"
////note: a trader can maximally withdraw against temporary PnL leaving bad debts
it("trader withdraw maximally against temporary PnL leaving bad debts", async () => {
////note: withdraw
await context.dealer
.connect(trader1)
@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);
@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 / 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 / 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 / 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 / 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