Skip to content

Commit

Permalink
Small query fix for BatchRouter (#1089)
Browse files Browse the repository at this point in the history
  • Loading branch information
jubeira authored Nov 4, 2024
1 parent 65fbede commit c8b7fa8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/vault/contracts/BatchRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ contract BatchRouter is IBatchRouter, BatchRouterCommon, ReentrancyGuardTransien
// required amount when performing the operation. These tokens might be the output of a previous
// step, in which case the user will have a BPT credit.

if (stepLocals.isFirstStep && params.sender != address(this)) {
if (stepExactAmountIn > 0) {
if (stepLocals.isFirstStep) {
if (stepExactAmountIn > 0 && params.sender != address(this)) {
// If this is the first step, the sender must have the tokens. Therefore, we can transfer
// them to the Router, which acts as an intermediary. If the sender is the Router, we just
// skip this step (useful for queries).
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/contracts/CompositeLiquidityRouter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.26;
pragma solidity ^0.8.24;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IPermit2 } from "permit2/src/interfaces/IPermit2.sol";
Expand Down
27 changes: 27 additions & 0 deletions pkg/vault/test/foundry/BatchRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity ^0.8.24;

import "forge-std/Test.sol";

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { IBatchRouter } from "@balancer-labs/v3-interfaces/contracts/vault/IBatchRouter.sol";

import { MOCK_BATCH_ROUTER_VERSION } from "../../contracts/test/BatchRouterMock.sol";
Expand Down Expand Up @@ -32,4 +34,29 @@ contract BatchRouterTest is BaseVaultTest {
function testBatchRouterVersion() public view {
assertEq(batchRouter.version(), MOCK_BATCH_ROUTER_VERSION, "BatchRouter version mismatch");
}

function testQuerySingleStepRemove() public {
// create a swap step and query the batch router, where the first token is the bpt.
IBatchRouter.SwapPathStep[] memory step = new IBatchRouter.SwapPathStep[](1);
step[0] = IBatchRouter.SwapPathStep(address(pool), IERC20(address(dai)), false);

uint256 totalSupply = IERC20(pool).totalSupply();
console.log("total BPT supply", totalSupply);
uint256 bptAmountIn = 1e18;

require(bptAmountIn < totalSupply);

IBatchRouter.SwapPathExactAmountIn memory path = IBatchRouter.SwapPathExactAmountIn(
IERC20(address(pool)),
step,
bptAmountIn,
0
);

IBatchRouter.SwapPathExactAmountIn[] memory paths = new IBatchRouter.SwapPathExactAmountIn[](1);
paths[0] = path;

vm.prank(alice, address(0));
batchRouter.querySwapExactIn(paths, address(0), bytes(""));
}
}

0 comments on commit c8b7fa8

Please sign in to comment.