Skip to content

Commit

Permalink
remove UniMockERC20 in favor of solmate/MockERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Nov 1, 2023
1 parent 458f755 commit 6065979
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 70 deletions.
20 changes: 10 additions & 10 deletions test/foundry-tests/Fees.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {UniMockERC20} from "./utils/UniMockERC20.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";
Expand Down Expand Up @@ -61,11 +61,11 @@ contract FeesTest is Test, Deployers, TokenFixture, GasSnapshot {
swapRouter = new PoolSwapTest(manager);
protocolFeeController = new ProtocolFeeControllerTest();

UniMockERC20(Currency.unwrap(currency0)).mint(address(this), 10 ether);
UniMockERC20(Currency.unwrap(currency1)).mint(address(this), 10 ether);
MockERC20(Currency.unwrap(currency0)).mint(address(this), 10 ether);
MockERC20(Currency.unwrap(currency1)).mint(address(this), 10 ether);

UniMockERC20(Currency.unwrap(currency0)).approve(address(modifyPositionRouter), 10 ether);
UniMockERC20(Currency.unwrap(currency1)).approve(address(modifyPositionRouter), 10 ether);
MockERC20(Currency.unwrap(currency0)).approve(address(modifyPositionRouter), 10 ether);
MockERC20(Currency.unwrap(currency1)).approve(address(modifyPositionRouter), 10 ether);

address hookAddr = address(99); // can't be a zero address, but does not have to have any other hook flags specified
MockHooks impl = new MockHooks();
Expand Down Expand Up @@ -419,7 +419,7 @@ contract FeesTest is Test, Deployers, TokenFixture, GasSnapshot {
params = IPoolManager.ModifyPositionParams(-60, 60, 10e18);
modifyPositionRouter.modifyPosition(key3, params, ZERO_BYTES);

UniMockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
MockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
swapRouter.swap(
key3,
IPoolManager.SwapParams(false, 10000, TickMath.MAX_SQRT_RATIO - 1),
Expand Down Expand Up @@ -454,7 +454,7 @@ contract FeesTest is Test, Deployers, TokenFixture, GasSnapshot {
IPoolManager.ModifyPositionParams memory params = IPoolManager.ModifyPositionParams(-120, 120, 10e18);
modifyPositionRouter.modifyPosition(key0, params, ZERO_BYTES);
// 1 for 0 swap
UniMockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
MockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
swapRouter.swap(
key0,
IPoolManager.SwapParams(false, 10000, TickMath.MAX_SQRT_RATIO - 1),
Expand Down Expand Up @@ -487,7 +487,7 @@ contract FeesTest is Test, Deployers, TokenFixture, GasSnapshot {
IPoolManager.ModifyPositionParams memory params = IPoolManager.ModifyPositionParams(-120, 120, 10e18);
modifyPositionRouter.modifyPosition(key0, params, ZERO_BYTES);
// 1 for 0 swap
UniMockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
MockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
swapRouter.swap(
key0,
IPoolManager.SwapParams(false, 10000, TickMath.MAX_SQRT_RATIO - 1),
Expand Down Expand Up @@ -522,7 +522,7 @@ contract FeesTest is Test, Deployers, TokenFixture, GasSnapshot {
IPoolManager.ModifyPositionParams memory params = IPoolManager.ModifyPositionParams(-120, 120, 10e18);
modifyPositionRouter.modifyPosition(key0, params, ZERO_BYTES);
// 1 for 0 swap
UniMockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
MockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
swapRouter.swap(
key0,
IPoolManager.SwapParams(false, 10000, TickMath.MAX_SQRT_RATIO - 1),
Expand Down Expand Up @@ -561,7 +561,7 @@ contract FeesTest is Test, Deployers, TokenFixture, GasSnapshot {
IPoolManager.ModifyPositionParams memory params = IPoolManager.ModifyPositionParams(-120, 120, 10e18);
modifyPositionRouter.modifyPosition(key0, params, ZERO_BYTES);
// 1 for 0 swap
UniMockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
MockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), type(uint256).max);
swapRouter.swap(
key0,
IPoolManager.SwapParams(false, 10000, TickMath.MAX_SQRT_RATIO - 1),
Expand Down
18 changes: 9 additions & 9 deletions test/foundry-tests/Hooks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {UniMockERC20} from "./utils/UniMockERC20.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";
Expand Down Expand Up @@ -65,7 +65,7 @@ contract HooksTest is Test, Deployers, GasSnapshot {
}

function testModifyPositionSucceedsWithHook() public {
UniMockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18);
modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 100), new bytes(111));
assertEq(mockHooks.beforeModifyPositionData(), new bytes(111));
Expand All @@ -74,22 +74,22 @@ contract HooksTest is Test, Deployers, GasSnapshot {

function testBeforeModifyPositionInvalidReturn() public {
mockHooks.setReturnValue(mockHooks.beforeModifyPosition.selector, bytes4(0xdeadbeef));
UniMockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 100), ZERO_BYTES);
}

function testAfterModifyPositionInvalidReturn() public {
mockHooks.setReturnValue(mockHooks.afterModifyPosition.selector, bytes4(0xdeadbeef));
UniMockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
modifyPositionRouter.modifyPosition(key, IPoolManager.ModifyPositionParams(0, 60, 100), ZERO_BYTES);
}

function testSwapSucceedsWithHook() public {
UniMockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency0)).approve(address(swapRouter), 10 ** 18);
swapRouter.swap(
key,
Expand All @@ -103,7 +103,7 @@ contract HooksTest is Test, Deployers, GasSnapshot {

function testBeforeSwapInvalidReturn() public {
mockHooks.setReturnValue(mockHooks.beforeSwap.selector, bytes4(0xdeadbeef));
UniMockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency0)).approve(address(swapRouter), 10 ** 18);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
swapRouter.swap(
Expand All @@ -116,7 +116,7 @@ contract HooksTest is Test, Deployers, GasSnapshot {

function testAfterSwapInvalidReturn() public {
mockHooks.setReturnValue(mockHooks.afterSwap.selector, bytes4(0xdeadbeef));
UniMockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency0)).approve(address(swapRouter), 10 ** 18);
vm.expectRevert(Hooks.InvalidHookResponse.selector);
swapRouter.swap(
Expand Down Expand Up @@ -633,8 +633,8 @@ contract HooksTest is Test, Deployers, GasSnapshot {
}

function addLiquidity(int24 tickLower, int24 tickUpper, int256 amount) internal {
UniMockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
UniMockERC20(Currency.unwrap(key.currency1)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency0)).mint(address(this), 10 ** 18);
MockERC20(Currency.unwrap(key.currency1)).mint(address(this), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency0)).approve(address(modifyPositionRouter), 10 ** 18);
IERC20Minimal(Currency.unwrap(key.currency1)).approve(address(modifyPositionRouter), 10 ** 18);
modifyPositionRouter.modifyPosition(
Expand Down
18 changes: 9 additions & 9 deletions test/foundry-tests/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {UniMockERC20} from "./utils/UniMockERC20.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 {IERC1155Receiver} from "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
Expand Down Expand Up @@ -87,17 +87,17 @@ contract PoolManagerTest is Test, Deployers, TokenFixture, GasSnapshot, IERC1155
swapRouter = new PoolSwapTest(manager);
protocolFeeController = new ProtocolFeeControllerTest();

UniMockERC20(Currency.unwrap(currency0)).mint(address(this), 10 ether);
UniMockERC20(Currency.unwrap(currency1)).mint(address(this), 10 ether);
MockERC20(Currency.unwrap(currency0)).mint(address(this), 10 ether);
MockERC20(Currency.unwrap(currency1)).mint(address(this), 10 ether);

UniMockERC20(Currency.unwrap(currency0)).approve(address(swapRouter), 10 ether);
UniMockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), 10 ether);
MockERC20(Currency.unwrap(currency0)).approve(address(swapRouter), 10 ether);
MockERC20(Currency.unwrap(currency1)).approve(address(swapRouter), 10 ether);

UniMockERC20(Currency.unwrap(currency0)).approve(address(modifyPositionRouter), 10 ether);
UniMockERC20(Currency.unwrap(currency1)).approve(address(modifyPositionRouter), 10 ether);
MockERC20(Currency.unwrap(currency0)).approve(address(modifyPositionRouter), 10 ether);
MockERC20(Currency.unwrap(currency1)).approve(address(modifyPositionRouter), 10 ether);

UniMockERC20(Currency.unwrap(currency0)).approve(address(donateRouter), 10 ether);
UniMockERC20(Currency.unwrap(currency1)).approve(address(donateRouter), 10 ether);
MockERC20(Currency.unwrap(currency0)).approve(address(donateRouter), 10 ether);
MockERC20(Currency.unwrap(currency1)).approve(address(donateRouter), 10 ether);
}

function testPoolManagerInitialize(PoolKey memory key, uint160 sqrtPriceX96) public {
Expand Down
10 changes: 5 additions & 5 deletions test/foundry-tests/PoolManagerReentrancyTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {UniMockERC20} from "./utils/UniMockERC20.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";
Expand Down Expand Up @@ -137,15 +137,15 @@ contract PoolManagerReentrancyTest is Test, Deployers, TokenFixture {

function testTokenLocker() public {
TokenLocker locker = new TokenLocker();
UniMockERC20(Currency.unwrap(currency0)).mint(address(locker), 1);
UniMockERC20(Currency.unwrap(currency0)).approve(address(locker), 1);
MockERC20(Currency.unwrap(currency0)).mint(address(locker), 1);
MockERC20(Currency.unwrap(currency0)).approve(address(locker), 1);
locker.main(manager, currency0, true);
}

function testTokenRevert() public {
TokenLocker locker = new TokenLocker();
UniMockERC20(Currency.unwrap(currency0)).mint(address(locker), 1);
UniMockERC20(Currency.unwrap(currency0)).approve(address(locker), 1);
MockERC20(Currency.unwrap(currency0)).mint(address(locker), 1);
MockERC20(Currency.unwrap(currency0)).approve(address(locker), 1);
vm.expectRevert(abi.encodeWithSelector(IPoolManager.CurrencyNotSettled.selector));
locker.main(manager, currency0, false);
}
Expand Down
6 changes: 4 additions & 2 deletions test/foundry-tests/types/Currency.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {UniMockERC20} from "../utils/UniMockERC20.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
import {Currency, CurrencyLibrary} from "../../../contracts/types/Currency.sol";

contract TestCurrency is Test {
Expand All @@ -18,7 +18,9 @@ contract TestCurrency is Test {

function setUp() public {
nativeCurrency = Currency.wrap(address(0));
erc20Currency = Currency.wrap(address(new UniMockERC20("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);
}
Expand Down
13 changes: 7 additions & 6 deletions test/foundry-tests/utils/Deployers.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import {UniMockERC20} from "./UniMockERC20.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";
Expand All @@ -25,14 +25,15 @@ contract Deployers {
uint160 constant SQRT_RATIO_4_1 = Constants.SQRT_RATIO_4_1;

function deployCurrencies(uint256 totalSupply) internal returns (Currency currency0, Currency currency1) {
UniMockERC20[] memory tokens = deployTokens(2, totalSupply);
MockERC20[] memory tokens = deployTokens(2, totalSupply);
return SortTokens.sort(tokens[0], tokens[1]);
}

function deployTokens(uint8 count, uint256 totalSupply) internal returns (UniMockERC20[] memory tokens) {
tokens = new UniMockERC20[](count);
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 UniMockERC20("TEST", "TEST", 18, totalSupply);
tokens[i] = new MockERC20("TEST", "TEST", 18);
tokens[i].mint(address(this), totalSupply);
}
}

Expand All @@ -47,7 +48,7 @@ contract Deployers {
private
returns (PoolKey memory key, PoolId id)
{
UniMockERC20[] memory tokens = deployTokens(2, 2 ** 255);
MockERC20[] memory tokens = deployTokens(2, 2 ** 255);
(Currency currency0, Currency currency1) = SortTokens.sort(tokens[0], tokens[1]);
key = PoolKey(currency0, currency1, fee, fee.isDynamicFee() ? int24(60) : int24(fee / 100 * 2), hooks);
id = key.toId();
Expand Down
4 changes: 2 additions & 2 deletions test/foundry-tests/utils/SortTokens.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import {UniMockERC20} from "./UniMockERC20.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
import {Currency} from "../../../contracts/types/Currency.sol";

library SortTokens {
function sort(UniMockERC20 tokenA, UniMockERC20 tokenB)
function sort(MockERC20 tokenA, MockERC20 tokenB)
internal
pure
returns (Currency _currency0, Currency _currency1)
Expand Down
8 changes: 5 additions & 3 deletions test/foundry-tests/utils/TokenFixture.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import {UniMockERC20} from "./UniMockERC20.sol";
import {MockERC20} from "solmate/test/utils/mocks/MockERC20.sol";
import {Currency} from "../../../contracts/types/Currency.sol";
import {SortTokens} from "./SortTokens.sol";

Expand All @@ -10,8 +10,10 @@ contract TokenFixture {
Currency internal currency0;

function initializeTokens() internal {
UniMockERC20 tokenA = new UniMockERC20("TestA", "A", 18, 1000 ether);
UniMockERC20 tokenB = new UniMockERC20("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);
}
Expand Down
24 changes: 0 additions & 24 deletions test/foundry-tests/utils/UniMockERC20.sol

This file was deleted.

0 comments on commit 6065979

Please sign in to comment.