From 6097a32ab3d84801868a986c7e014e4125f16b15 Mon Sep 17 00:00:00 2001 From: pistomat Date: Wed, 6 Dec 2023 09:37:20 +0100 Subject: [PATCH] Fix BAL#304 MAX_IN_RATIO --- evm/src/balancer-v2/BalancerV2SwapAdapter.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol index 9cbf25c..77b75c0 100644 --- a/evm/src/balancer-v2/BalancerV2SwapAdapter.sol +++ b/evm/src/balancer-v2/BalancerV2SwapAdapter.sol @@ -4,7 +4,8 @@ pragma solidity ^0.8.13; import {IERC20, ISwapAdapter} from "src/interfaces/ISwapAdapter.sol"; -uint256 constant RESERVE_LIMIT_FACTOR = 10; // TODO why is the factor so high? +// 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 SWAP_DEADLINE_SEC = 1000; contract BalancerV2SwapAdapter is ISwapAdapter { @@ -160,10 +161,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; } if (tokens[i] == buyToken) { - limits[1] = balances[i] * RESERVE_LIMIT_FACTOR; + limits[1] = balances[i] / RESERVE_LIMIT_FACTOR; } } }