Migrate erc20-contracts to foundry (#664)

* Strip erc20 package of legacy nonsense and add foundry basics

* Make foundry build

* Remove obsoleted test/UntransferrableDummyERC20Token.sol contract

* Remove obsoleted ERC20 lib variant contracts

* Remove obsoleted DummyMultipleReturnERC20Token and DummyNoReturnERC20Token contracts

* Move test contract to dedicated folder
and remove obsoleted TypeScript contract wrappers

* Remove src/interfaces/IEtherToken.sol only used in
v3 staking which is being obsoleted [skip ci]

* Add foundry test for token

* Migrate ZRX token tests to foundry

* Fix paths to erc20 contracts

* Remove obsoleted references

* Pin erc20-contracts package on treasury

* Ignore foundry imports in link checker

* Run only forge tests for erc20 contracts

* Remove DummyERC20Token and its dependencies

* Merge IERC20TokenV06 and IERC20TokenV08
into range pragma to cover solidity 0.6.5 to 0.8.x

* Merge IEtherTokenV06 and IEtherTokenV08
into range pragma to cover solidity 0.6.5 to 0.8.x

* Migrate weth9 tests to foundry

* Upload code coverage for erc20 package

* Update changelog

* Fix review comments

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>

---------

Co-authored-by: duncancmt <1207590+duncancmt@users.noreply.github.com>
This commit is contained in:
Elena
2023-02-19 20:04:24 +02:00
committed by GitHub
parent f2f835591e
commit 9f30823d70
172 changed files with 945 additions and 2876 deletions

View File

@@ -20,8 +20,8 @@ import "src/features/TransformERC20Feature.sol";
import "src/external/TransformerDeployer.sol";
import "src/transformers/WethTransformer.sol";
import "src/transformers/FillQuoteTransformer.sol";
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
import "@0x/contracts-erc20/src/IEtherToken.sol";
import "@0x/contracts-erc20/src/IERC20Token.sol";
import "src/transformers/bridges/BridgeProtocols.sol";
import "src/transformers/bridges/EthereumBridgeAdapter.sol";
import "src/transformers/bridges/PolygonBridgeAdapter.sol";
@@ -82,10 +82,10 @@ struct Addresses {
}
struct TokenAddresses {
IERC20TokenV06 DAI;
IERC20TokenV06 USDC;
IERC20TokenV06 USDT;
IEtherTokenV06 WrappedNativeToken;
IERC20Token DAI;
IERC20Token USDC;
IERC20Token USDT;
IEtherToken WrappedNativeToken;
}
struct LiquiditySources {
@@ -146,13 +146,13 @@ interface IUniswapV3QuoterV2 {
}
interface IUniswapV3Factory {
function getPool(IERC20TokenV06 a, IERC20TokenV06 b, uint24 fee) external view returns (IUniswapV3Pool pool);
function getPool(IERC20Token a, IERC20Token b, uint24 fee) external view returns (IUniswapV3Pool pool);
}
interface IUniswapV3Pool {
function token0() external view returns (IERC20TokenV06);
function token0() external view returns (IERC20Token);
function token1() external view returns (IERC20TokenV06);
function token1() external view returns (IERC20Token);
function fee() external view returns (uint24);
}
@@ -253,7 +253,7 @@ contract ForkUtils is Test {
}
//creates the appropriate bridge adapter based on what chain the tests are currently executing on.
function createBridgeAdapter(IEtherTokenV06 weth) public returns (IBridgeAdapter bridgeAdapter) {
function createBridgeAdapter(IEtherToken weth) public returns (IBridgeAdapter bridgeAdapter) {
uint chainId;
assembly {
@@ -317,13 +317,13 @@ contract ForkUtils is Test {
//deploy a new FillQuoteTransformer
//executes in the context of the transformerDeployer
function createNewFQT(
IEtherTokenV06 wrappedNativeToken,
IEtherToken wrappedNativeToken,
address payable exchangeProxy,
address transformerDeployer
) public {
vm.startPrank(transformerDeployer);
// deploy a new instance of the bridge adapter from the transformerDeployer
bridgeAdapter = createBridgeAdapter(IEtherTokenV06(wrappedNativeToken));
bridgeAdapter = createBridgeAdapter(IEtherToken(wrappedNativeToken));
// deploy a new instance of the fill quote transformer from the transformerDeployer
fillQuoteTransformer = new FillQuoteTransformer(IBridgeAdapter(bridgeAdapter), IZeroEx(exchangeProxy));
vm.label(address(fillQuoteTransformer), "zeroEx/FillQuoteTransformer");
@@ -412,7 +412,7 @@ contract ForkUtils is Test {
/// @return makerTokenAmounts Maker amounts bought at each taker token amount.
function sampleSellsFromUniswapV3(
IUniswapV3QuoterV2 quoter,
IERC20TokenV06[] memory path,
IERC20Token[] memory path,
uint256[] memory takerTokenAmounts
)
public
@@ -471,13 +471,13 @@ contract ForkUtils is Test {
/// @return takerTokenAmounts Taker amounts sold at each maker token amount.
function sampleBuysFromUniswapV3(
IUniswapV3QuoterV2 quoter,
IERC20TokenV06[] memory path,
IERC20Token[] memory path,
uint256[] memory makerTokenAmounts
)
public
returns (bytes[] memory uniswapPaths, uint256[] memory uniswapGasUsed, uint256[] memory takerTokenAmounts)
{
IERC20TokenV06[] memory reversedPath = _reverseTokenPath(path);
IERC20Token[] memory reversedPath = _reverseTokenPath(path);
IUniswapV3Pool[][] memory poolPaths = _getPoolPaths(
quoter,
reversedPath,
@@ -526,7 +526,7 @@ contract ForkUtils is Test {
function _getPoolPaths(
IUniswapV3QuoterV2 quoter,
IERC20TokenV06[] memory path,
IERC20Token[] memory path,
uint256 inputAmount
) private returns (IUniswapV3Pool[][] memory poolPaths) {
if (path.length == 2) {
@@ -540,7 +540,7 @@ contract ForkUtils is Test {
function _getPoolPathSingleHop(
IUniswapV3QuoterV2 quoter,
IERC20TokenV06[] memory path,
IERC20Token[] memory path,
uint256 inputAmount
) public returns (IUniswapV3Pool[][] memory poolPaths) {
poolPaths = new IUniswapV3Pool[][](2);
@@ -563,7 +563,7 @@ contract ForkUtils is Test {
function _getPoolPathTwoHop(
IUniswapV3QuoterV2 quoter,
IERC20TokenV06[] memory path,
IERC20Token[] memory path,
uint256 inputAmount
) private returns (IUniswapV3Pool[][] memory poolPaths) {
IUniswapV3Factory factory = quoter.factory();
@@ -600,11 +600,11 @@ contract ForkUtils is Test {
function _getTopTwoPools(
IUniswapV3QuoterV2 quoter,
IUniswapV3Factory factory,
IERC20TokenV06 inputToken,
IERC20TokenV06 outputToken,
IERC20Token inputToken,
IERC20Token outputToken,
uint256 inputAmount
) private returns (IUniswapV3Pool[2] memory topPools, uint256[2] memory outputAmounts) {
IERC20TokenV06[] memory path = new IERC20TokenV06[](2);
IERC20Token[] memory path = new IERC20Token[](2);
path[0] = inputToken;
path[1] = outputToken;
@@ -638,10 +638,8 @@ contract ForkUtils is Test {
}
}
function _reverseTokenPath(
IERC20TokenV06[] memory tokenPath
) private pure returns (IERC20TokenV06[] memory reversed) {
reversed = new IERC20TokenV06[](tokenPath.length);
function _reverseTokenPath(IERC20Token[] memory tokenPath) private pure returns (IERC20Token[] memory reversed) {
reversed = new IERC20Token[](tokenPath.length);
for (uint256 i = 0; i < tokenPath.length; ++i) {
reversed[i] = tokenPath[tokenPath.length - i - 1];
}
@@ -687,7 +685,7 @@ contract ForkUtils is Test {
}
function _toUniswapPath(
IERC20TokenV06[] memory tokenPath,
IERC20Token[] memory tokenPath,
IUniswapV3Pool[] memory poolPath
) private view returns (bytes memory uniswapPath) {
require(
@@ -709,7 +707,7 @@ contract ForkUtils is Test {
o := add(o, 3)
}
}
IERC20TokenV06 token = tokenPath[i];
IERC20Token token = tokenPath[i];
assembly {
mstore(o, shl(96, token))
o := add(o, 20)