feat: Add integration tests for balancer v3

Refactor BalancerV3Executor to have an inner _swapCallback method with the real swapping logic. Then we have two external methods:
- handleCallback: called by the router. Here we need to remove the first 68 bytes (4 selector + 32 dataOffset + 32 dataLength)
- swapCallback: called by the Vault directly if we are swapping against the executor directly (no router involved)

Took 1 minute
This commit is contained in:
Diana Carvalho
2025-06-05 17:12:58 +01:00
parent 06ce28c8fd
commit 269e328b5f
5 changed files with 82 additions and 19 deletions

View File

@@ -33,7 +33,7 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback {
{
bytes memory result = VAULT.unlock(
abi.encodeCall(
BalancerV3Executor.handleCallback,
BalancerV3Executor.swapCallback,
abi.encodePacked(givenAmount, data)
)
);
@@ -46,8 +46,8 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback {
}
}
function handleCallback(bytes calldata data)
external
function _swapCallback(bytes calldata data)
internal
returns (bytes memory result)
{
verifyCallback(data);
@@ -82,6 +82,24 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback {
return abi.encode(amountCalculated);
}
function handleCallback(bytes calldata data)
external
returns (bytes memory result)
{
verifyCallback(data);
result = _swapCallback(data[68:]);
// Our general callback logic returns a not ABI encoded result.
// However, the Vault expects the result to be ABI encoded. That is why we need to encode it here again.
return abi.encode(result);
}
function swapCallback(bytes calldata data)
external
returns (bytes memory result)
{
return _swapCallback(data);
}
function _decodeData(bytes calldata data)
internal
pure
@@ -94,7 +112,7 @@ contract BalancerV3Executor is IExecutor, RestrictTransferFrom, ICallback {
address receiver
)
{
if (data.length != 113) {
if (data.length < 113) {
revert BalancerV3Executor__InvalidDataLength();
}