feat: Add TokenTransfer class to BalancerV2
- This needed to be in BalancerV2 so that the executor can also take care of transfers from the user into the tycho router, to avoid having transfer actions mixed between the router and executors
This commit is contained in:
committed by
Diana Carvalho
parent
462be5463b
commit
3a73fef933
@@ -10,14 +10,17 @@ 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 {
|
||||
contract BalancerV2Executor is IExecutor, TokenTransfer {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
address private constant VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
|
||||
|
||||
constructor(address _permit2) TokenTransfer(_permit2) {}
|
||||
|
||||
// slither-disable-next-line locked-ether
|
||||
function swap(uint256 givenAmount, bytes calldata data)
|
||||
external
|
||||
@@ -29,9 +32,20 @@ contract BalancerV2Executor is IExecutor {
|
||||
IERC20 tokenOut,
|
||||
bytes32 poolId,
|
||||
address receiver,
|
||||
bool needsApproval
|
||||
bool needsApproval,
|
||||
TransferType transferType
|
||||
) = _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.approve(VAULT, type(uint256).max);
|
||||
@@ -67,10 +81,11 @@ contract BalancerV2Executor is IExecutor {
|
||||
IERC20 tokenOut,
|
||||
bytes32 poolId,
|
||||
address receiver,
|
||||
bool needsApproval
|
||||
bool needsApproval,
|
||||
TransferType transferType
|
||||
)
|
||||
{
|
||||
if (data.length != 93) {
|
||||
if (data.length != 94) {
|
||||
revert BalancerV2Executor__InvalidDataLength();
|
||||
}
|
||||
|
||||
@@ -79,5 +94,6 @@ contract BalancerV2Executor is IExecutor {
|
||||
poolId = bytes32(data[40:72]);
|
||||
receiver = address(bytes20(data[72:92]));
|
||||
needsApproval = uint8(data[92]) > 0;
|
||||
transferType = TransferType(uint8(data[93]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,15 @@ contract CurveExecutor is IExecutor, TokenTransfer {
|
||||
TransferType transferType
|
||||
) = _decodeData(data);
|
||||
|
||||
_transfer(tokenIn, msg.sender, pool, amountIn, transferType);
|
||||
_transfer(
|
||||
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),
|
||||
amountIn,
|
||||
transferType
|
||||
);
|
||||
|
||||
if (tokenApprovalNeeded && tokenIn != nativeToken) {
|
||||
// slither-disable-next-line unused-return
|
||||
|
||||
@@ -53,7 +53,9 @@ contract UniswapV4Executor is IExecutor, V4Router, ICallback, TokenTransfer {
|
||||
_transfer(
|
||||
tokenIn,
|
||||
msg.sender,
|
||||
address(this), // irrelevant attribute
|
||||
// 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),
|
||||
amountIn,
|
||||
transferType
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user