Skip to content

Commit

Permalink
feat: remove batchSwap from balancer (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
r0ohafza authored Aug 26, 2022
1 parent 8b8593a commit e9d8c40
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 90 deletions.
78 changes: 5 additions & 73 deletions src/balancer/BalancerController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ contract BalancerController is IController {
/* CONSTANT VARIABLES */
/* -------------------------------------------------------------------------- */

/// @notice joinPool(bytes32,address,address,(address[],uint256[],bytes,bool))
bytes4 constant JOIN = 0xb95cac28;

/// @notice exitPool(bytes32,address,address,(address[],uint256[],bytes,bool))
bytes4 constant EXIT = 0x8bdb3913;

/// @notice swap((bytes32,uint8,address,address,uint256,bytes),(address,bool,address,bool),uint256,uint256)
bytes4 constant SWAP = 0x52bbbe29;
bytes4 constant BATCH_SWAP = 0x945bcec9;

/* -------------------------------------------------------------------------- */
/* STATE_VARIABLES */
Expand Down Expand Up @@ -56,8 +60,6 @@ contract BalancerController is IController {
return canExit(target, useEth, data[4:]);
if (sig == SWAP)
return canSwap(target, useEth, data[4:]);
if (sig == BATCH_SWAP)
return canBatchSwap(target, useEth, data[4:]);
return (false, new address[](0), new address[](0));
}

Expand Down Expand Up @@ -187,74 +189,4 @@ contract BalancerController is IController {
tokensOut
);
}

function canBatchSwap(address, bool, bytes calldata data)
internal
view
returns (bool, address[] memory, address[] memory)
{
(
,
IVault.BatchSwapStep[] memory swaps,
IAsset[] memory assets,
,
,
) = abi.decode(data, (
uint8, IVault.BatchSwapStep[], IAsset[], IVault.FundManagement, uint256[], uint256
)
);

if (!isMultiHopSwap(swaps))
return (false, new address[](0), new address[](0));

uint tokenInIndex = swaps[swaps.length - 1].assetOutIndex;
uint tokenOutIndex = swaps[0].assetInIndex;

address[] memory tokensIn;
address[] memory tokensOut;

if (address(assets[tokenOutIndex]) == address(0)) {
tokensIn = new address[](1);
tokensIn[0] = address(assets[tokenInIndex]);
return (
controllerFacade.isTokenAllowed(tokensIn[0]),
tokensIn,
new address[](0)
);
}

if (address(assets[tokenInIndex]) == address(0)) {
tokensOut = new address[](1);
tokensOut[0] = address(assets[tokenOutIndex]);
return (
true,
new address[](0),
tokensOut
);
}

tokensIn = new address[](1);
tokensOut = new address[](1);
tokensOut[0] = address(assets[tokenOutIndex]);
tokensIn[0] = address(assets[tokenInIndex]);

return (
controllerFacade.isTokenAllowed(tokensIn[0]),
tokensIn,
tokensOut
);
}

function isMultiHopSwap(IVault.BatchSwapStep[] memory swaps)
internal
pure
returns (bool)
{
uint steps = swaps.length;
for (uint i; i < steps - 1; i++) {
if (swaps[i].assetOutIndex != swaps[i+1].assetInIndex)
return false;
}
return true;
}
}
17 changes: 0 additions & 17 deletions src/balancer/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,4 @@ interface IVault {
address payable recipient;
bool toInternalBalance;
}

function batchSwap(
uint8 kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds,
int256[] memory limits,
uint256 deadline
) external payable returns (int256[] memory);

struct BatchSwapStep {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
uint256 amount;
bytes userData;
}
}

0 comments on commit e9d8c40

Please sign in to comment.