feat: Support new transfer logic in all executors

TODO:
- Fix failing tests
- Remove permit2 from initialization of contracts
This commit is contained in:
TAMARA LIPOWSKI
2025-05-14 20:42:19 -04:00
parent 0f9af65846
commit 27dfde3118
22 changed files with 378 additions and 462 deletions

View File

@@ -10,16 +10,15 @@ import {
import {IAsset} from "@balancer-labs/v2-interfaces/contracts/vault/IAsset.sol";
// slither-disable-next-line solc-version
import {IVault} from "@balancer-labs/v2-interfaces/contracts/vault/IVault.sol";
import {TokenTransfer} from "./TokenTransfer.sol";
error BalancerV2Executor__InvalidDataLength();
contract BalancerV2Executor is IExecutor, TokenTransfer {
contract BalancerV2Executor is IExecutor {
using SafeERC20 for IERC20;
address private constant VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
constructor(address _permit2) TokenTransfer(_permit2) {}
constructor(address _permit2) {}
// slither-disable-next-line locked-ether
function swap(uint256 givenAmount, bytes calldata data)
@@ -33,19 +32,9 @@ contract BalancerV2Executor is IExecutor, TokenTransfer {
bytes32 poolId,
address receiver,
bool needsApproval,
TransferType transferType
bool transferNeeded
) = _decodeData(data);
_transfer(
address(tokenIn),
msg.sender,
// Receiver can never be the pool, since the pool expects funds in the router contract
// Thus, this call will only ever be used to transfer funds from the user into the router.
address(this),
givenAmount,
transferType
);
if (needsApproval) {
// slither-disable-next-line unused-return
tokenIn.forceApprove(VAULT, type(uint256).max);
@@ -82,7 +71,7 @@ contract BalancerV2Executor is IExecutor, TokenTransfer {
bytes32 poolId,
address receiver,
bool needsApproval,
TransferType transferType
bool transferNeeded
)
{
if (data.length != 94) {
@@ -94,6 +83,6 @@ contract BalancerV2Executor is IExecutor, TokenTransfer {
poolId = bytes32(data[40:72]);
receiver = address(bytes20(data[72:92]));
needsApproval = uint8(data[92]) > 0;
transferType = TransferType(uint8(data[93]));
transferNeeded = uint8(data[93]) > 0;
}
}