From 034d5ac8c2845d7d279e0ed3933423ed2e87f9d9 Mon Sep 17 00:00:00 2001 From: PierreMkt Date: Fri, 2 Aug 2024 11:55:00 -0400 Subject: [PATCH 1/4] feat(adapters): Add new bytes parameter to swap that allows arbitrary data to be passed --- evm/src/angle/AngleAdapter.sol | 9 +++-- evm/src/balancer-v2/BalancerV2SwapAdapter.sol | 3 +- evm/src/etherfi/EtherfiAdapter.sol | 3 +- evm/src/integral/IntegralSwapAdapter.sol | 3 +- evm/src/interfaces/ISwapAdapter.sol | 4 +- evm/src/template/TemplateSwapAdapter.sol | 3 +- evm/src/uniswap-v2/UniswapV2SwapAdapter.sol | 3 +- evm/test/AdapterTest.sol | 17 ++++++-- evm/test/AngleAdapter.t.sol | 7 ++-- evm/test/BalancerV2SwapAdapter.t.sol | 16 ++++++-- evm/test/EtherfiAdapter.t.sol | 40 ++++++++++++++----- evm/test/IntegralSwapAdapter.t.sol | 6 ++- evm/test/UniswapV2SwapAdapter.t.sol | 5 ++- 13 files changed, 85 insertions(+), 34 deletions(-) diff --git a/evm/src/angle/AngleAdapter.sol b/evm/src/angle/AngleAdapter.sol index 9aaa50d..0ac5c50 100644 --- a/evm/src/angle/AngleAdapter.sol +++ b/evm/src/angle/AngleAdapter.sol @@ -56,7 +56,8 @@ contract AngleAdapter is ISwapAdapter { address sellToken, address buyToken, OrderSide side, - uint256 specifiedAmount + uint256 specifiedAmount, + bytes32 ) external returns (Trade memory trade) { if (specifiedAmount == 0) { return trade; @@ -223,7 +224,7 @@ contract AngleAdapter is ISwapAdapter { interface IAgToken is IERC20 { /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - MINTER ROLE ONLY FUNCTIONS + MINTER ROLE ONLY FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Lets a whitelisted contract mint agTokens @@ -254,7 +255,7 @@ interface IAgToken is IERC20 { function burnSelf(uint256 amount, address burner) external; /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - TREASURY ONLY FUNCTIONS + TREASURY ONLY FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Adds a minter in the contract @@ -274,7 +275,7 @@ interface IAgToken is IERC20 { function setTreasury(address _treasury) external; /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - EXTERNAL FUNCTIONS + EXTERNAL FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Checks whether an address has the right to mint agTokens diff --git a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol index 253f724..daf67d9 100644 --- a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol +++ b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol @@ -118,7 +118,8 @@ contract BalancerV2SwapAdapter is ISwapAdapter { address sellToken, address buyToken, OrderSide side, - uint256 specifiedAmount + uint256 specifiedAmount, + bytes32 data ) external override returns (Trade memory trade) { uint256 sellAmount; IVault.SwapKind kind; diff --git a/evm/src/etherfi/EtherfiAdapter.sol b/evm/src/etherfi/EtherfiAdapter.sol index a032a2e..f30c9d6 100644 --- a/evm/src/etherfi/EtherfiAdapter.sol +++ b/evm/src/etherfi/EtherfiAdapter.sol @@ -99,7 +99,8 @@ contract EtherfiAdapter is ISwapAdapter { address sellToken, address buyToken, OrderSide side, - uint256 specifiedAmount + uint256 specifiedAmount, + bytes32 ) external override diff --git a/evm/src/integral/IntegralSwapAdapter.sol b/evm/src/integral/IntegralSwapAdapter.sol index 36a0f11..c3ff1d0 100644 --- a/evm/src/integral/IntegralSwapAdapter.sol +++ b/evm/src/integral/IntegralSwapAdapter.sol @@ -59,7 +59,8 @@ contract IntegralSwapAdapter is ISwapAdapter { address sellToken, address buyToken, OrderSide side, - uint256 specifiedAmount + uint256 specifiedAmount, + bytes32 data ) external override returns (Trade memory trade) { if (specifiedAmount == 0) { return trade; diff --git a/evm/src/interfaces/ISwapAdapter.sol b/evm/src/interfaces/ISwapAdapter.sol index ab3bacc..397ed53 100644 --- a/evm/src/interfaces/ISwapAdapter.sol +++ b/evm/src/interfaces/ISwapAdapter.sol @@ -54,6 +54,7 @@ interface ISwapAdapter is ISwapAdapterTypes { * @param buyToken The token being bought. * @param side The side of the trade (Sell or Buy). * @param specifiedAmount The amount to be traded. + * @param data Additional arbitrary data for the swap. * @return trade Trade struct representing the executed trade. */ function swap( @@ -61,7 +62,8 @@ interface ISwapAdapter is ISwapAdapterTypes { address sellToken, address buyToken, OrderSide side, - uint256 specifiedAmount + uint256 specifiedAmount, + bytes32 data ) external returns (Trade memory trade); /// @notice Retrieves the limits for each token. diff --git a/evm/src/template/TemplateSwapAdapter.sol b/evm/src/template/TemplateSwapAdapter.sol index b64d64c..cd130b4 100644 --- a/evm/src/template/TemplateSwapAdapter.sol +++ b/evm/src/template/TemplateSwapAdapter.sol @@ -22,7 +22,8 @@ contract TemplateSwapAdapter is ISwapAdapter { address sellToken, address buyToken, OrderSide side, - uint256 specifiedAmount + uint256 specifiedAmount, + bytes32 ) external returns (Trade memory trade) { revert NotImplemented("TemplateSwapAdapter.swap"); } diff --git a/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol b/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol index 679a6b4..bd20f75 100644 --- a/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol +++ b/evm/src/uniswap-v2/UniswapV2SwapAdapter.sol @@ -69,7 +69,8 @@ contract UniswapV2SwapAdapter is ISwapAdapter { address sellToken, address buyToken, OrderSide side, - uint256 specifiedAmount + uint256 specifiedAmount, + bytes32 ) external override returns (Trade memory trade) { if (specifiedAmount == 0) { return trade; diff --git a/evm/test/AdapterTest.sol b/evm/test/AdapterTest.sol index 643064f..97b00a4 100644 --- a/evm/test/AdapterTest.sol +++ b/evm/test/AdapterTest.sol @@ -10,6 +10,7 @@ import "src/libraries/FractionMath.sol"; contract AdapterTest is Test, ISwapAdapterTypes { using FractionMath for Fraction; + bytes32 mockData = bytes32(abi.encodePacked(false)); uint256 constant pricePrecision = 10e24; string[] public stringPctgs = ["0%", "0.1%", "50%", "100%"]; @@ -99,7 +100,7 @@ contract AdapterTest is Test, ISwapAdapterTypes { console2.log("TEST: Swapping %d of %s", amounts[j], tokenIn); trade = adapter.swap( - poolId, tokenIn, tokenOut, OrderSide.Sell, amounts[j] + poolId, tokenIn, tokenOut, OrderSide.Sell, amounts[j], mockData ); uint256 executedPrice = trade.calculatedAmount * pricePrecision / amounts[j]; @@ -188,7 +189,12 @@ contract AdapterTest is Test, ISwapAdapterTypes { ); } try adapter.swap( - poolId, tokenIn, tokenOut, OrderSide.Sell, aboveLimitArray[0] + poolId, + tokenIn, + tokenOut, + OrderSide.Sell, + aboveLimitArray[0], + mockData ) { revert("Pool shouldn't be able to swap above the sell limit"); } catch Error(string memory s) { @@ -214,7 +220,12 @@ contract AdapterTest is Test, ISwapAdapterTypes { adapter.price(poolId, tokenIn, tokenOut, aboveLimitArray); adapter.swap( - poolId, tokenIn, tokenOut, OrderSide.Sell, aboveLimitArray[0] + poolId, + tokenIn, + tokenOut, + OrderSide.Sell, + aboveLimitArray[0], + mockData ); } diff --git a/evm/test/AngleAdapter.t.sol b/evm/test/AngleAdapter.t.sol index b8e50c6..8df15de 100644 --- a/evm/test/AngleAdapter.t.sol +++ b/evm/test/AngleAdapter.t.sol @@ -18,6 +18,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes { ITransmuter(0x00253582b2a3FE112feEC532221d9708c64cEFAb); uint256 constant TEST_ITERATIONS = 100; + bytes32 mockData = bytes32(abi.encodePacked(false)); function setUp() public { uint256 forkBlock = 18921770; @@ -55,7 +56,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes { uint256 agEUR_balance = agEUR.balanceOf(address(this)); Trade memory trade = adapter.swap( - pair, address(EURC), address(agEUR), side, specifiedAmount + pair, address(EURC), address(agEUR), side, specifiedAmount, mockData ); if (trade.calculatedAmount > 0) { @@ -106,7 +107,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes { uint256 agEUR_balance = agEUR.balanceOf(address(this)); Trade memory trade = adapter.swap( - pair, address(agEUR), address(EURC), side, specifiedAmount + pair, address(agEUR), address(EURC), side, specifiedAmount, mockData ); if (trade.calculatedAmount > 0) { @@ -159,7 +160,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes { agEUR.approve(address(adapter), type(uint256).max); } trades[i] = adapter.swap( - pair, address(agEUR), address(EURC), side, amounts[i] + pair, address(agEUR), address(EURC), side, amounts[i], mockData ); vm.revertTo(beforeSwap); } diff --git a/evm/test/BalancerV2SwapAdapter.t.sol b/evm/test/BalancerV2SwapAdapter.t.sol index e4cb188..c76400a 100644 --- a/evm/test/BalancerV2SwapAdapter.t.sol +++ b/evm/test/BalancerV2SwapAdapter.t.sol @@ -111,7 +111,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest { uint256 weth_balance = IERC20(WETH).balanceOf(address(this)); Trade memory trade = adapter.swap( - B_80BAL_20WETH_POOL_ID, BAL, WETH, side, specifiedAmount + B_80BAL_20WETH_POOL_ID, BAL, WETH, side, specifiedAmount, mockData ); if (trade.calculatedAmount > 0) { @@ -149,7 +149,12 @@ contract BalancerV2SwapAdapterTest is AdapterTest { deal(BAL, address(this), amounts[i]); IERC20(BAL).approve(address(adapter), amounts[i]); trades[i] = adapter.swap( - B_80BAL_20WETH_POOL_ID, BAL, WETH, OrderSide.Sell, amounts[i] + B_80BAL_20WETH_POOL_ID, + BAL, + WETH, + OrderSide.Sell, + amounts[i], + mockData ); vm.revertTo(beforeSwap); @@ -180,7 +185,12 @@ contract BalancerV2SwapAdapterTest is AdapterTest { deal(BAL, address(this), amountIn); IERC20(BAL).approve(address(adapter), amountIn); trades[i] = adapter.swap( - B_80BAL_20WETH_POOL_ID, BAL, WETH, OrderSide.Buy, amounts[i] + B_80BAL_20WETH_POOL_ID, + BAL, + WETH, + OrderSide.Buy, + amounts[i], + mockData ); vm.revertTo(beforeSwap); diff --git a/evm/test/EtherfiAdapter.t.sol b/evm/test/EtherfiAdapter.t.sol index 366561a..c98d74a 100644 --- a/evm/test/EtherfiAdapter.t.sol +++ b/evm/test/EtherfiAdapter.t.sol @@ -15,6 +15,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { IeEth eEth; uint256 constant TEST_ITERATIONS = 100; + bytes32 mockData = bytes32(abi.encodePacked(false)); function setUp() public { uint256 forkBlock = 19218495; @@ -72,7 +73,8 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { address(address(0)), address(eEth_), OrderSide.Buy, - limits[0] + limits[0], + mockData ); eEth_.approve(address(adapter), type(uint256).max); @@ -87,7 +89,8 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { address(address(0)), address(eEth_), OrderSide.Buy, - specifiedAmount + specifiedAmount, + mockData ); eEth_.approve(address(adapter), specifiedAmount); @@ -97,7 +100,12 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { uint256 weEth_balance = weEth_.balanceOf(address(this)); Trade memory trade = adapter.swap( - pair, address(eEth_), address(weEth_), side, specifiedAmount + pair, + address(eEth_), + address(weEth_), + side, + specifiedAmount, + mockData ); if (trade.calculatedAmount > 0) { @@ -164,7 +172,8 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { address(address(0)), address(weEth_), OrderSide.Buy, - limits[0] + limits[0], + mockData ); weEth_.approve(address(adapter), type(uint256).max); @@ -179,7 +188,8 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { address(address(0)), address(weEth_), OrderSide.Buy, - specifiedAmount + specifiedAmount, + mockData ); weEth_.approve(address(adapter), specifiedAmount); @@ -194,7 +204,12 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { uint256 realAmountWeEth_ = weEth_balance - weEth_bal_before; Trade memory trade = adapter.swap( - pair, address(weEth_), address(eEth_), side, realAmountWeEth_ + pair, + address(weEth_), + address(eEth_), + side, + realAmountWeEth_, + mockData ); if (trade.calculatedAmount > 0) { @@ -254,8 +269,9 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { uint256 eth_balance = address(adapter).balance; uint256 eEth_balance = eEth_.balanceOf(address(this)); - Trade memory trade = - adapter.swap(pair, eth_, address(eEth_), side, specifiedAmount); + Trade memory trade = adapter.swap( + pair, eth_, address(eEth_), side, specifiedAmount, mockData + ); if (trade.calculatedAmount > 0) { if (side == OrderSide.Buy) { @@ -309,8 +325,9 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { uint256 eth_balance = address(adapter).balance; uint256 weEth_balance = weEth_.balanceOf(address(this)); - Trade memory trade = - adapter.swap(pair, eth_, address(weEth_), side, specifiedAmount); + Trade memory trade = adapter.swap( + pair, eth_, address(weEth_), side, specifiedAmount, mockData + ); if (trade.calculatedAmount > 0) { if (side == OrderSide.Buy) { @@ -373,7 +390,8 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { address(address(weEth)), address(address(eEth)), side, - amounts[i] + amounts[i], + mockData ); vm.revertTo(beforeSwap); } diff --git a/evm/test/IntegralSwapAdapter.t.sol b/evm/test/IntegralSwapAdapter.t.sol index 8c3e129..abfa8bc 100644 --- a/evm/test/IntegralSwapAdapter.t.sol +++ b/evm/test/IntegralSwapAdapter.t.sol @@ -16,6 +16,7 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; address constant USDC_WETH_PAIR = 0x2fe16Dd18bba26e457B7dD2080d5674312b026a2; address constant relayerAddress = 0xd17b3c9784510E33cD5B87b490E79253BcD81e2E; + bytes32 mockData = bytes32(abi.encodePacked(false)); uint256 constant TEST_ITERATIONS = 100; @@ -83,7 +84,7 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { uint256 weth_balance_before = IERC20(WETH).balanceOf(address(this)); Trade memory trade = - adapter.swap(pair, USDC, WETH, side, specifiedAmount); + adapter.swap(pair, USDC, WETH, side, specifiedAmount, mockData); if (trade.calculatedAmount > 0) { if (side == OrderSide.Buy) { @@ -138,7 +139,8 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { deal(USDC, address(this), amounts[i]); IERC20(USDC).approve(address(adapter), amounts[i]); - trades[i] = adapter.swap(pair, USDC, WETH, side, amounts[i]); + trades[i] = + adapter.swap(pair, USDC, WETH, side, amounts[i], mockData); vm.revertTo(beforeSwap); } diff --git a/evm/test/UniswapV2SwapAdapter.t.sol b/evm/test/UniswapV2SwapAdapter.t.sol index d3aebbd..a149861 100644 --- a/evm/test/UniswapV2SwapAdapter.t.sol +++ b/evm/test/UniswapV2SwapAdapter.t.sol @@ -88,7 +88,7 @@ contract UniswapV2PairFunctionTest is AdapterTest { uint256 weth_balance = IERC20(WETH).balanceOf(address(this)); Trade memory trade = - adapter.swap(pair, USDC, WETH, side, specifiedAmount); + adapter.swap(pair, USDC, WETH, side, specifiedAmount, mockData); if (trade.calculatedAmount > 0) { if (side == OrderSide.Buy) { @@ -133,7 +133,8 @@ contract UniswapV2PairFunctionTest is AdapterTest { deal(USDC, address(this), amounts[i]); IERC20(USDC).approve(address(adapter), amounts[i]); - trades[i] = adapter.swap(pair, USDC, WETH, side, amounts[i]); + trades[i] = + adapter.swap(pair, USDC, WETH, side, amounts[i], mockData); vm.revertTo(beforeSwap); } From ec903734e0a2159ea4bdfd0856b881b319a9d833 Mon Sep 17 00:00:00 2001 From: PierreMkt Date: Fri, 2 Aug 2024 12:00:54 -0400 Subject: [PATCH 2/4] test(adapters): Fix balancer getCapabilities test returns HardLimits too --- evm/test/BalancerV2SwapAdapter.t.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/evm/test/BalancerV2SwapAdapter.t.sol b/evm/test/BalancerV2SwapAdapter.t.sol index c76400a..329b208 100644 --- a/evm/test/BalancerV2SwapAdapter.t.sol +++ b/evm/test/BalancerV2SwapAdapter.t.sol @@ -217,10 +217,11 @@ contract BalancerV2SwapAdapterTest is AdapterTest { { Capability[] memory res = adapter.getCapabilities(pool, t0, t1); - assertEq(res.length, 3); + assertEq(res.length, 4); assertEq(uint256(res[0]), uint256(Capability.SellOrder)); assertEq(uint256(res[1]), uint256(Capability.BuyOrder)); assertEq(uint256(res[2]), uint256(Capability.PriceFunction)); + assertEq(uint256(res[3]), uint256(Capability.HardLimits)); } function testGetTokens() public { From 6f41147f913b939b25282d091ab60939d29657ac Mon Sep 17 00:00:00 2001 From: PierreMkt Date: Fri, 2 Aug 2024 12:49:37 -0400 Subject: [PATCH 3/4] feat(adapters): decode reduceFee bool from bytes data TODO: apply reduce fee logic --- evm/src/balancer-v2/BalancerV2SwapAdapter.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol index daf67d9..d7328d6 100644 --- a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol +++ b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol @@ -123,6 +123,7 @@ contract BalancerV2SwapAdapter is ISwapAdapter { ) external override returns (Trade memory trade) { uint256 sellAmount; IVault.SwapKind kind; + bool reduceFee = abi.decode(abi.encodePacked(data), (bool)); uint256 limit; // TODO set this slippage limit properly if (side == OrderSide.Sell) { kind = IVault.SwapKind.GIVEN_IN; From 07ca52b2ff6cae221790b68cd4474ec95c672ad6 Mon Sep 17 00:00:00 2001 From: PierreMkt Date: Mon, 5 Aug 2024 13:56:28 -0400 Subject: [PATCH 4/4] chore(adapters): Address PR review keep mock data as empty bytes --- evm/src/integral/IntegralSwapAdapter.sol | 2 +- evm/test/AdapterTest.sol | 2 +- evm/test/AngleAdapter.t.sol | 7 ++++--- evm/test/BalancerV2SwapAdapter.t.sol | 15 +++++++++++---- evm/test/EtherfiAdapter.t.sol | 7 ++++--- evm/test/IntegralSwapAdapter.t.sol | 11 +++++++---- evm/test/UniswapV2SwapAdapter.t.sol | 11 +++++++---- 7 files changed, 35 insertions(+), 20 deletions(-) diff --git a/evm/src/integral/IntegralSwapAdapter.sol b/evm/src/integral/IntegralSwapAdapter.sol index c3ff1d0..d74ff0d 100644 --- a/evm/src/integral/IntegralSwapAdapter.sol +++ b/evm/src/integral/IntegralSwapAdapter.sol @@ -60,7 +60,7 @@ contract IntegralSwapAdapter is ISwapAdapter { address buyToken, OrderSide side, uint256 specifiedAmount, - bytes32 data + bytes32 ) external override returns (Trade memory trade) { if (specifiedAmount == 0) { return trade; diff --git a/evm/test/AdapterTest.sol b/evm/test/AdapterTest.sol index 8ef36d4..cdb2c58 100644 --- a/evm/test/AdapterTest.sol +++ b/evm/test/AdapterTest.sol @@ -10,7 +10,7 @@ import "src/libraries/FractionMath.sol"; contract AdapterTest is Test, ISwapAdapterTypes { using FractionMath for Fraction; - bytes32 mockData = bytes32(abi.encodePacked(false)); + bytes32 mockData; uint256 constant pricePrecision = 10e24; string[] public stringPctgs = ["0%", "0.1%", "50%", "100%"]; diff --git a/evm/test/AngleAdapter.t.sol b/evm/test/AngleAdapter.t.sol index 8df15de..082a475 100644 --- a/evm/test/AngleAdapter.t.sol +++ b/evm/test/AngleAdapter.t.sol @@ -18,7 +18,7 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes { ITransmuter(0x00253582b2a3FE112feEC532221d9708c64cEFAb); uint256 constant TEST_ITERATIONS = 100; - bytes32 mockData = bytes32(abi.encodePacked(false)); + bytes32 mockData; function setUp() public { uint256 forkBlock = 18921770; @@ -179,19 +179,20 @@ contract AngleAdapterTest is Test, ISwapAdapterTypes { function testGetCapabilitiesAngle(bytes32 pair, address t0, address t1) public + view { Capability[] memory res = adapter.getCapabilities(pair, t0, t1); assertEq(res.length, 2); } - function testGetTokensAngle() public { + function testGetTokensAngle() public view { address[] memory tokens = adapter.getTokens(bytes32(0)); assertGe(tokens.length, 2); } - function testGetLimitsAngle() public { + function testGetLimitsAngle() public view { bytes32 pair = bytes32(0); uint256[] memory limits = adapter.getLimits(pair, address(agEUR), address(EURC)); diff --git a/evm/test/BalancerV2SwapAdapter.t.sol b/evm/test/BalancerV2SwapAdapter.t.sol index 7cb610c..c1053ec 100644 --- a/evm/test/BalancerV2SwapAdapter.t.sol +++ b/evm/test/BalancerV2SwapAdapter.t.sol @@ -12,6 +12,7 @@ import {FractionMath} from "src/libraries/FractionMath.sol"; contract BalancerV2SwapAdapterTest is AdapterTest { using FractionMath for Fraction; + bytes32 mockBoolData = bytes32(abi.encode(false)); IVault constant balancerV2Vault = IVault(payable(0xBA12222222228d8Ba445958a75a0704d566BF2C8)); BalancerV2SwapAdapter adapter; @@ -111,7 +112,12 @@ contract BalancerV2SwapAdapterTest is AdapterTest { uint256 weth_balance = IERC20(WETH).balanceOf(address(this)); Trade memory trade = adapter.swap( - B_80BAL_20WETH_POOL_ID, BAL, WETH, side, specifiedAmount, mockData + B_80BAL_20WETH_POOL_ID, + BAL, + WETH, + side, + specifiedAmount, + mockBoolData ); if (trade.calculatedAmount > 0) { @@ -154,7 +160,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest { WETH, OrderSide.Sell, amounts[i], - mockData + mockBoolData ); vm.revertTo(beforeSwap); @@ -190,7 +196,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest { WETH, OrderSide.Buy, amounts[i], - mockData + mockBoolData ); vm.revertTo(beforeSwap); @@ -214,6 +220,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest { function testGetCapabilitiesFuzz(bytes32 pool, address t0, address t1) public + view { Capability[] memory res = adapter.getCapabilities(pool, t0, t1); @@ -224,7 +231,7 @@ contract BalancerV2SwapAdapterTest is AdapterTest { assertEq(uint256(res[3]), uint256(Capability.HardLimits)); } - function testGetTokens() public { + function testGetTokens() public view { address[] memory tokens = adapter.getTokens(B_80BAL_20WETH_POOL_ID); assertEq(tokens[0], BAL); diff --git a/evm/test/EtherfiAdapter.t.sol b/evm/test/EtherfiAdapter.t.sol index c98d74a..9f60173 100644 --- a/evm/test/EtherfiAdapter.t.sol +++ b/evm/test/EtherfiAdapter.t.sol @@ -15,7 +15,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { IeEth eEth; uint256 constant TEST_ITERATIONS = 100; - bytes32 mockData = bytes32(abi.encodePacked(false)); + bytes32 mockData; function setUp() public { uint256 forkBlock = 19218495; @@ -404,6 +404,7 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { function testGetCapabilitiesEtherfi(bytes32 pair, address t0, address t1) public + view { Capability[] memory res = adapter.getCapabilities(pair, address(t0), address(t1)); @@ -411,14 +412,14 @@ contract EtherfiAdapterTest is Test, ISwapAdapterTypes { assertEq(res.length, 3); } - function testGetTokensEtherfi() public { + function testGetTokensEtherfi() public view { bytes32 pair = bytes32(0); address[] memory tokens = adapter.getTokens(pair); assertEq(tokens.length, 3); } - function testGetLimitsEtherfi() public { + function testGetLimitsEtherfi() public view { bytes32 pair = bytes32(0); uint256[] memory limits = adapter.getLimits(pair, address(eEth), address(weEth)); diff --git a/evm/test/IntegralSwapAdapter.t.sol b/evm/test/IntegralSwapAdapter.t.sol index abfa8bc..18dde5c 100644 --- a/evm/test/IntegralSwapAdapter.t.sol +++ b/evm/test/IntegralSwapAdapter.t.sol @@ -16,7 +16,7 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; address constant USDC_WETH_PAIR = 0x2fe16Dd18bba26e457B7dD2080d5674312b026a2; address constant relayerAddress = 0xd17b3c9784510E33cD5B87b490E79253BcD81e2E; - bytes32 mockData = bytes32(abi.encodePacked(false)); + bytes32 mockData; uint256 constant TEST_ITERATIONS = 100; @@ -31,7 +31,10 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { vm.label(address(USDC_WETH_PAIR), "USDC_WETH_PAIR"); } - function testPriceFuzzIntegral(uint256 amount0, uint256 amount1) public { + function testPriceFuzzIntegral(uint256 amount0, uint256 amount1) + public + view + { bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); vm.assume(amount0 < limits[0]); @@ -159,14 +162,14 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { assertEq(res.length, 4); } - function testGetTokensIntegral() public { + function testGetTokensIntegral() public view { bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); address[] memory tokens = adapter.getTokens(pair); assertEq(tokens.length, 2); } - function testGetLimitsIntegral() public { + function testGetLimitsIntegral() public view { bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); diff --git a/evm/test/UniswapV2SwapAdapter.t.sol b/evm/test/UniswapV2SwapAdapter.t.sol index f2a3a1c..7be622d 100644 --- a/evm/test/UniswapV2SwapAdapter.t.sol +++ b/evm/test/UniswapV2SwapAdapter.t.sol @@ -29,7 +29,7 @@ contract UniswapV2PairFunctionTest is AdapterTest { vm.label(USDC_WETH_PAIR, "USDC_WETH_PAIR"); } - function testPriceFuzz(uint256 amount0, uint256 amount1) public { + function testPriceFuzz(uint256 amount0, uint256 amount1) public view { bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); vm.assume(amount0 < limits[0]); @@ -47,7 +47,7 @@ contract UniswapV2PairFunctionTest is AdapterTest { } } - function testPriceDecreasing() public { + function testPriceDecreasing() public view { bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); uint256[] memory amounts = new uint256[](TEST_ITERATIONS); @@ -149,13 +149,16 @@ contract UniswapV2PairFunctionTest is AdapterTest { executeIncreasingSwaps(OrderSide.Buy); } - function testGetCapabilities(bytes32 pair, address t0, address t1) public { + function testGetCapabilities(bytes32 pair, address t0, address t1) + public + view + { Capability[] memory res = adapter.getCapabilities(pair, t0, t1); assertEq(res.length, 4); } - function testGetLimits() public { + function testGetLimits() public view { bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); uint256[] memory limits = adapter.getLimits(pair, USDC, WETH);