From fad17377d0f368443f117289658887aba46a87e9 Mon Sep 17 00:00:00 2001 From: saucepoint <98790946+saucepoint@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:19:40 -0400 Subject: [PATCH] Replace MockERC20 with solmate's MockERC20 (#374) * rename MockERC20 -> UniMockERC20 * remove UniMockERC20 in favor of solmate/MockERC20 * update snapshots --- .forge-snapshots/donate gas with 1 token.snap | 2 +- .../donate gas with 2 tokens.snap | 2 +- .forge-snapshots/mint with empty hook.snap | 2 +- .forge-snapshots/mint.snap | 2 +- .forge-snapshots/swap against liquidity.snap | 2 +- test/foundry-tests/Fees.t.sol | 2 +- test/foundry-tests/Hooks.t.sol | 2 +- test/foundry-tests/PoolManager.t.sol | 2 +- .../PoolManagerReentrancyTest.t.sol | 2 +- test/foundry-tests/types/Currency.t.sol | 6 +++-- test/foundry-tests/utils/Deployers.sol | 5 ++-- test/foundry-tests/utils/MockERC20.sol | 24 ------------------- test/foundry-tests/utils/SortTokens.sol | 2 +- test/foundry-tests/utils/TokenFixture.sol | 8 ++++--- 14 files changed, 22 insertions(+), 41 deletions(-) delete mode 100644 test/foundry-tests/utils/MockERC20.sol diff --git a/.forge-snapshots/donate gas with 1 token.snap b/.forge-snapshots/donate gas with 1 token.snap index 21281b9f1..fad97b6f2 100644 --- a/.forge-snapshots/donate gas with 1 token.snap +++ b/.forge-snapshots/donate gas with 1 token.snap @@ -1 +1 @@ -96005 +95961 diff --git a/.forge-snapshots/donate gas with 2 tokens.snap b/.forge-snapshots/donate gas with 2 tokens.snap index 12c15ee43..ae1b854c3 100644 --- a/.forge-snapshots/donate gas with 2 tokens.snap +++ b/.forge-snapshots/donate gas with 2 tokens.snap @@ -1 +1 @@ -153358 +153292 diff --git a/.forge-snapshots/mint with empty hook.snap b/.forge-snapshots/mint with empty hook.snap index 4744c3a20..2edff9d5f 100644 --- a/.forge-snapshots/mint with empty hook.snap +++ b/.forge-snapshots/mint with empty hook.snap @@ -1 +1 @@ -307152 +307130 diff --git a/.forge-snapshots/mint.snap b/.forge-snapshots/mint.snap index f9dcdfbab..14d5d2da2 100644 --- a/.forge-snapshots/mint.snap +++ b/.forge-snapshots/mint.snap @@ -1 +1 @@ -293760 +293738 diff --git a/.forge-snapshots/swap against liquidity.snap b/.forge-snapshots/swap against liquidity.snap index 29e8a6fc1..78782f40c 100644 --- a/.forge-snapshots/swap against liquidity.snap +++ b/.forge-snapshots/swap against liquidity.snap @@ -1 +1 @@ -109692 +109721 diff --git a/test/foundry-tests/Fees.t.sol b/test/foundry-tests/Fees.t.sol index 1a3c99b2e..4b0500e65 100644 --- a/test/foundry-tests/Fees.t.sol +++ b/test/foundry-tests/Fees.t.sol @@ -16,7 +16,7 @@ import {Deployers} from "./utils/Deployers.sol"; import {TokenFixture} from "./utils/TokenFixture.sol"; import {PoolModifyPositionTest} from "../../contracts/test/PoolModifyPositionTest.sol"; import {Currency, CurrencyLibrary} from "../../contracts/types/Currency.sol"; -import {MockERC20} from "./utils/MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {MockHooks} from "../../contracts/test/MockHooks.sol"; import {PoolSwapTest} from "../../contracts/test/PoolSwapTest.sol"; import {GasSnapshot} from "forge-gas-snapshot/GasSnapshot.sol"; diff --git a/test/foundry-tests/Hooks.t.sol b/test/foundry-tests/Hooks.t.sol index 8b49d2a56..9435372e5 100644 --- a/test/foundry-tests/Hooks.t.sol +++ b/test/foundry-tests/Hooks.t.sol @@ -8,7 +8,7 @@ import {Hooks} from "../../contracts/libraries/Hooks.sol"; import {FeeLibrary} from "../../contracts/libraries/FeeLibrary.sol"; import {MockHooks} from "../../contracts/test/MockHooks.sol"; import {IPoolManager} from "../../contracts/interfaces/IPoolManager.sol"; -import {MockERC20} from "./utils/MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {IHooks} from "../../contracts/interfaces/IHooks.sol"; import {Currency} from "../../contracts/types/Currency.sol"; import {IERC20Minimal} from "../../contracts/interfaces/external/IERC20Minimal.sol"; diff --git a/test/foundry-tests/PoolManager.t.sol b/test/foundry-tests/PoolManager.t.sol index ef7b4361c..ff54a5ddb 100644 --- a/test/foundry-tests/PoolManager.t.sol +++ b/test/foundry-tests/PoolManager.t.sol @@ -15,7 +15,7 @@ import {Deployers} from "./utils/Deployers.sol"; import {TokenFixture} from "./utils/TokenFixture.sol"; import {PoolModifyPositionTest} from "../../contracts/test/PoolModifyPositionTest.sol"; import {Currency, CurrencyLibrary} from "../../contracts/types/Currency.sol"; -import {MockERC20} from "./utils/MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {MockHooks} from "../../contracts/test/MockHooks.sol"; import {MockContract} from "../../contracts/test/MockContract.sol"; import {EmptyTestHooks} from "../../contracts/test/EmptyTestHooks.sol"; diff --git a/test/foundry-tests/PoolManagerReentrancyTest.t.sol b/test/foundry-tests/PoolManagerReentrancyTest.t.sol index 090f35857..3e6748821 100644 --- a/test/foundry-tests/PoolManagerReentrancyTest.t.sol +++ b/test/foundry-tests/PoolManagerReentrancyTest.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.20; import {Test} from "forge-std/Test.sol"; -import {MockERC20} from "./utils/MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {Currency, CurrencyLibrary} from "../../contracts/types/Currency.sol"; import {LockDataLibrary} from "../../contracts/libraries/LockDataLibrary.sol"; import {IPoolManager} from "../../contracts/interfaces/IPoolManager.sol"; diff --git a/test/foundry-tests/types/Currency.t.sol b/test/foundry-tests/types/Currency.t.sol index 9a27adac7..5d07857c0 100644 --- a/test/foundry-tests/types/Currency.t.sol +++ b/test/foundry-tests/types/Currency.t.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.20; import {Test} from "forge-std/Test.sol"; -import {MockERC20} from "../utils/MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {Currency, CurrencyLibrary} from "../../../contracts/types/Currency.sol"; contract TestCurrency is Test { @@ -18,7 +18,9 @@ contract TestCurrency is Test { function setUp() public { nativeCurrency = Currency.wrap(address(0)); - erc20Currency = Currency.wrap(address(new MockERC20("TestA", "A", 18, initialERC20Balance))); + MockERC20 token = new MockERC20("TestA", "A", 18); + token.mint(address(this), initialERC20Balance); + erc20Currency = Currency.wrap(address(token)); erc20Currency.transfer(address(1), sentBalance); nativeCurrency.transfer(address(1), sentBalance); } diff --git a/test/foundry-tests/utils/Deployers.sol b/test/foundry-tests/utils/Deployers.sol index 55eadb7d9..02b1dcd29 100644 --- a/test/foundry-tests/utils/Deployers.sol +++ b/test/foundry-tests/utils/Deployers.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; -import {MockERC20} from "./MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {Hooks} from "../../../contracts/libraries/Hooks.sol"; import {Currency} from "../../../contracts/types/Currency.sol"; import {IHooks} from "../../../contracts/interfaces/IHooks.sol"; @@ -32,7 +32,8 @@ contract Deployers { function deployTokens(uint8 count, uint256 totalSupply) internal returns (MockERC20[] memory tokens) { tokens = new MockERC20[](count); for (uint8 i = 0; i < count; i++) { - tokens[i] = new MockERC20("TEST", "TEST", 18, totalSupply); + tokens[i] = new MockERC20("TEST", "TEST", 18); + tokens[i].mint(address(this), totalSupply); } } diff --git a/test/foundry-tests/utils/MockERC20.sol b/test/foundry-tests/utils/MockERC20.sol deleted file mode 100644 index cf0818096..000000000 --- a/test/foundry-tests/utils/MockERC20.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.20; - -import {ERC20} from "solmate/tokens/ERC20.sol"; - -contract MockERC20 is ERC20 { - constructor(string memory name, string memory symbol, uint8 decimals, uint256 amountToMint) - ERC20(name, symbol, decimals) - { - mint(msg.sender, amountToMint); - } - - function mint(address _to, uint256 _amount) public { - _mint(_to, _amount); - } - - function forceApprove(address _from, address _to, uint256 _amount) public returns (bool) { - allowance[_from][_to] = _amount; - - emit Approval(_from, _to, _amount); - - return true; - } -} diff --git a/test/foundry-tests/utils/SortTokens.sol b/test/foundry-tests/utils/SortTokens.sol index 858519e21..312a25549 100644 --- a/test/foundry-tests/utils/SortTokens.sol +++ b/test/foundry-tests/utils/SortTokens.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; -import {MockERC20} from "./MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {Currency} from "../../../contracts/types/Currency.sol"; library SortTokens { diff --git a/test/foundry-tests/utils/TokenFixture.sol b/test/foundry-tests/utils/TokenFixture.sol index 9a025d9a5..42c8838ec 100644 --- a/test/foundry-tests/utils/TokenFixture.sol +++ b/test/foundry-tests/utils/TokenFixture.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; -import {MockERC20} from "./MockERC20.sol"; +import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol"; import {Currency} from "../../../contracts/types/Currency.sol"; import {SortTokens} from "./SortTokens.sol"; @@ -10,8 +10,10 @@ contract TokenFixture { Currency internal currency0; function initializeTokens() internal { - MockERC20 tokenA = new MockERC20("TestA", "A", 18, 1000 ether); - MockERC20 tokenB = new MockERC20("TestB", "B", 18, 1000 ether); + MockERC20 tokenA = new MockERC20("TestA", "A", 18); + tokenA.mint(address(this), 1000 ether); + MockERC20 tokenB = new MockERC20("TestB", "B", 18); + tokenB.mint(address(this), 1000 ether); (currency0, currency1) = SortTokens.sort(tokenA, tokenB); }