Skip to content

Commit

Permalink
Merge pull request #510 from morpho-labs/build/remove-oz
Browse files Browse the repository at this point in the history
build(deps): remove oz
  • Loading branch information
MathisGD authored Sep 27, 2023
2 parents e34355e + 5630662 commit 5de3552
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 19 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
1 change: 0 additions & 1 deletion lib/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from fd81a9
2 changes: 0 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/
51 changes: 45 additions & 6 deletions src/mocks/ERC20Mock.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {ERC20} from "openzeppelin-contracts/token/ERC20/ERC20.sol";
import {IERC20} from "./interfaces/IERC20.sol";

contract ERC20Mock is ERC20 {
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}
contract ERC20Mock is IERC20 {
uint256 public totalSupply;

function setBalance(address account, uint256 amount) external {
_burn(account, balanceOf(account));
_mint(account, amount);
mapping(address account => uint256) public balanceOf;
mapping(address account => mapping(address spender => uint256)) public allowance;

function setBalance(address account, uint256 amount) public virtual {
if (amount > balanceOf[account]) totalSupply += amount - balanceOf[account];
else totalSupply -= balanceOf[account] - amount;

balanceOf[account] = amount;
}

function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;

emit Approval(msg.sender, spender, amount);

return true;
}

function transfer(address to, uint256 amount) public virtual returns (bool) {
require(balanceOf[msg.sender] >= amount, "insufficient balance");

balanceOf[msg.sender] -= amount;
balanceOf[to] += amount;

emit Transfer(msg.sender, to, amount);

return true;
}

function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
require(allowance[from][msg.sender] >= amount, "insufficient allowance");

allowance[from][msg.sender] -= amount;

require(balanceOf[from] >= amount, "insufficient balance");

balanceOf[from] -= amount;
balanceOf[to] += amount;

emit Transfer(from, to, amount);

return true;
}
}
5 changes: 2 additions & 3 deletions src/mocks/FlashBorrowerMock.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import {IERC20} from "./interfaces/IERC20.sol";
import {IMorpho} from "../interfaces/IMorpho.sol";
import {IMorphoFlashLoanCallback} from "../interfaces/IMorphoCallbacks.sol";

import {ERC20} from "openzeppelin-contracts/token/ERC20/ERC20.sol";

contract FlashBorrowerMock is IMorphoFlashLoanCallback {
IMorpho private immutable MORPHO;

Expand All @@ -20,6 +19,6 @@ contract FlashBorrowerMock is IMorphoFlashLoanCallback {
function onMorphoFlashLoan(uint256 assets, bytes calldata data) external {
require(msg.sender == address(MORPHO));
address token = abi.decode(data, (address));
ERC20(token).approve(address(MORPHO), assets);
IERC20(token).approve(address(MORPHO), assets);
}
}
24 changes: 24 additions & 0 deletions src/mocks/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

interface IERC20 {
/* EVENTS */

event Transfer(address indexed from, address indexed to, uint256 value);

event Approval(address indexed owner, address indexed spender, uint256 value);

/* FUNCTIONS */

function totalSupply() external view returns (uint256);

function balanceOf(address account) external view returns (uint256);

function transfer(address to, uint256 value) external returns (bool);

function allowance(address owner, address spender) external view returns (uint256);

function approve(address spender, uint256 value) external returns (bool);

function transferFrom(address from, address to, uint256 value) external returns (bool);
}
4 changes: 2 additions & 2 deletions test/forge/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ contract BaseTest is Test {

morpho = new Morpho(OWNER);

loanToken = new ERC20Mock("loan", "B");
loanToken = new ERC20Mock();
vm.label(address(loanToken), "LoanToken");

collateralToken = new ERC20Mock("collateral", "C");
collateralToken = new ERC20Mock();
vm.label(address(collateralToken), "CollateralToken");

oracle = new OracleMock();
Expand Down
4 changes: 2 additions & 2 deletions test/hardhat/Morpho.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ describe("Morpho", () => {

const ERC20MockFactory = await hre.ethers.getContractFactory("ERC20Mock", admin);

loanToken = await ERC20MockFactory.deploy("DAI", "DAI");
collateralToken = await ERC20MockFactory.deploy("Wrapped BTC", "WBTC");
loanToken = await ERC20MockFactory.deploy();
collateralToken = await ERC20MockFactory.deploy();

const OracleMockFactory = await hre.ethers.getContractFactory("OracleMock", admin);

Expand Down

0 comments on commit 5de3552

Please sign in to comment.