diff --git a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol index e93702b..846da0d 100644 --- a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol +++ b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol @@ -9,7 +9,7 @@ import { // Maximum Swap In/Out Ratio - 0.3 // https://balancer.gitbook.io/balancer/core-concepts/protocol/limitations#v2-limits -uint256 constant RESERVE_LIMIT_FACTOR = 4; +uint256 constant RESERVE_LIMIT_FACTOR = 3; uint256 constant SWAP_DEADLINE_SEC = 1000; contract BalancerV2SwapAdapter is ISwapAdapter { @@ -174,10 +174,10 @@ contract BalancerV2SwapAdapter is ISwapAdapter { for (uint256 i = 0; i < tokens.length; i++) { if (tokens[i] == sellToken) { - limits[0] = balances[i] / RESERVE_LIMIT_FACTOR; + limits[0] = balances[i] * RESERVE_LIMIT_FACTOR / 10; } if (tokens[i] == buyToken) { - limits[1] = balances[i] / RESERVE_LIMIT_FACTOR; + limits[1] = balances[i] * RESERVE_LIMIT_FACTOR / 10; } } } @@ -188,10 +188,11 @@ contract BalancerV2SwapAdapter is ISwapAdapter { override returns (Capability[] memory capabilities) { - capabilities = new Capability[](3); + capabilities = new Capability[](4); capabilities[0] = Capability.SellOrder; capabilities[1] = Capability.BuyOrder; capabilities[2] = Capability.PriceFunction; + capabilities[3] = Capability.HardLimits; } function getTokens(bytes32 poolId) diff --git a/evm/test/AdapterTest.sol b/evm/test/AdapterTest.sol index 1ca474d..643064f 100644 --- a/evm/test/AdapterTest.sol +++ b/evm/test/AdapterTest.sol @@ -87,6 +87,8 @@ contract AdapterTest is Test, ISwapAdapterTypes { Trade memory trade; deal(tokenIn, address(this), 5 * amounts[amounts.length - 1]); + uint256 initialState = vm.snapshot(); + for (uint256 j = 1; j < amounts.length; j++) { console2.log( "TEST: Testing behavior for price at %s of limit.", @@ -139,6 +141,8 @@ contract AdapterTest is Test, ISwapAdapterTypes { "Price should be or equal to price after swap." ); } + + vm.revertTo(initialState); } uint256 amountAboveLimit = sellLimit * 105 / 100; @@ -167,7 +171,10 @@ contract AdapterTest is Test, ISwapAdapterTypes { address tokenOut, uint256 amountAboveLimit ) internal { - console2.log("TEST: Testing revert behavior above the sell limit"); + console2.log( + "TEST: Testing revert behavior above the sell limit: %d", + amountAboveLimit + ); uint256[] memory aboveLimitArray = new uint256[](1); aboveLimitArray[0] = amountAboveLimit; @@ -198,7 +205,10 @@ contract AdapterTest is Test, ISwapAdapterTypes { address tokenOut, uint256 amountAboveLimit ) internal { - console2.log("TEST: Testing operations above the sell limit"); + console2.log( + "TEST: Testing operations above the sell limit: %d", + amountAboveLimit + ); uint256[] memory aboveLimitArray = new uint256[](1); aboveLimitArray[0] = amountAboveLimit;