Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: batchSwap accounting #49

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/balancer/BalancerController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,34 @@ contract BalancerController is IController {
returns (bool, address[] memory, address[] memory)
{
(
,
IVault.SwapKind kind,
IVault.BatchSwapStep[] memory swaps,
IAsset[] memory assets,
,
,
) = abi.decode(data, (
uint8, IVault.BatchSwapStep[], IAsset[], IVault.FundManagement, uint256[], uint256
IVault.SwapKind,
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;
uint tokenInIndex;
uint tokenOutIndex;

if (kind == IVault.SwapKind.GIVEN_IN) {
tokenInIndex = swaps[swaps.length - 1].assetOutIndex;
tokenOutIndex = swaps[0].assetInIndex;
} else {
tokenOutIndex = swaps[swaps.length - 1].assetInIndex;
tokenInIndex = swaps[0].assetOutIndex;
}
r0ohafza marked this conversation as resolved.
Show resolved Hide resolved

address[] memory tokensIn;
address[] memory tokensOut;
Expand Down Expand Up @@ -235,7 +248,10 @@ contract BalancerController is IController {
{
uint steps = swaps.length;
for (uint i; i < steps - 1; i++) {
if (swaps[i].assetOutIndex != swaps[i+1].assetInIndex)
if (
swaps[i].assetOutIndex != swaps[i+1].assetInIndex ||
swaps[i+1].amount > 0
)
r0ohafza marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/balancer/IVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface IVault {
}

function batchSwap(
uint8 kind,
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds,
Expand All @@ -74,4 +74,6 @@ interface IVault {
uint256 amount;
bytes userData;
}

enum SwapKind { GIVEN_IN, GIVEN_OUT }
}