From 18a611d6a10b957acb0f560c4408c0d81b015820 Mon Sep 17 00:00:00 2001 From: patricio henderson Date: Wed, 10 Apr 2024 10:30:52 -0300 Subject: [PATCH 1/4] Tasks: Implement balancer v2 swapper task --- .../interfaces/swap/IBalancerV2Swapper.sol | 27 ++++ .../contracts/swap/BalancerV2Swapper.sol | 117 ++++++++++++++++++ .../tasks/test/swap/BalancerV2Swapper.test.ts | 53 ++++++++ 3 files changed, 197 insertions(+) create mode 100644 packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol create mode 100644 packages/tasks/contracts/swap/BalancerV2Swapper.sol create mode 100644 packages/tasks/test/swap/BalancerV2Swapper.test.ts diff --git a/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol new file mode 100644 index 00000000..5be41a35 --- /dev/null +++ b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity >=0.8.0; + +import './IBaseSwapTask.sol'; + +/** + * @dev Balancer v2 swapper task interface + */ +interface IBalancerV2Swapper is IBaseSwapTask { + /** + * @dev Execution function + */ + function call(address tokenIn, uint256 amountIn, uint256 slippage) external; +} diff --git a/packages/tasks/contracts/swap/BalancerV2Swapper.sol b/packages/tasks/contracts/swap/BalancerV2Swapper.sol new file mode 100644 index 00000000..5ec8659d --- /dev/null +++ b/packages/tasks/contracts/swap/BalancerV2Swapper.sol @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity ^0.8.0; + +import '@mimic-fi/v3-helpers/contracts/math/FixedPoint.sol'; +import '@mimic-fi/v3-helpers/contracts/utils/BytesHelpers.sol'; +import '@mimic-fi/v3-connectors/contracts/interfaces/balancer/IBalancerV2SwapConnector.sol'; + +import './BaseSwapTask.sol'; +import '../interfaces/swap/IBalancerV2Swapper.sol'; +import '../interfaces/liquidity/balancer/IBalancerPool.sol'; + +/** + * @title Balancer v2 swapper task + * @dev Task that extends the base swap task to use Balancer + */ +contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { + using FixedPoint for uint256; + using BytesHelpers for bytes; + + // Execution type for relayers + bytes32 public constant override EXECUTION_TYPE = keccak256('BALANCER_V2_SWAPPER'); + + /** + * @dev Balancer v2 swap config. Only used in the initalizer + */ + struct BalancerV2SwapConfig { + BaseSwapConfig baseSwapConfig; + } + + /** + * @dev Initializes the Balancer v2 swapper + * @param config Balancer v2 swap config + */ + function initialize(BalancerV2SwapConfig memory config) external initializer { + __BalancerV2Swapper_init(config); + } + + /** + * @dev Initializes the Balancer v2 swapper. It does call upper contracts. + * @param config Balancer v2 swap config + */ + function __BalancerV2Swapper_init(BalancerV2SwapConfig memory config) internal onlyInitializing { + __BaseSwapTask_init(config.baseSwapConfig); + __BalancerV2Swapper_init_unchained(config); + } + + /** + * @dev Initializes the balancer swapper. It does not call upper contracts + * @param config Balancer V2 swap config + */ + function __BalancerV2Swapper_init_unchained(BalancerV2SwapConfig memory config) internal onlyInitializing { + // solhint-disable-previous-line no-empty-blocks + } + + /** + * @dev Executes the Balancer v2 swapper task + */ + function call(address tokenIn, uint256 amountIn, uint256 slippage) + external + override + authP(authParams(tokenIn, amountIn, slippage)) + { + if (amountIn == 0) amountIn = getTaskAmount(tokenIn); + _beforeBalancerV2Swapper(tokenIn, amountIn, slippage); + + address tokenOut = getTokenOut(tokenIn); + uint256 price = _getPrice(tokenIn, tokenOut); + uint256 minAmountOut = amountIn.mulUp(price).mulUp(FixedPoint.ONE - slippage); + + bytes memory connectorData = abi.encodeWithSelector( + IBalancerV2SwapConnector.execute.selector, + tokenIn, + tokenOut, + amountIn, + minAmountOut, + IBalancerPool(tokenIn).getPoolId(), + new bytes32[](0), + new address[](0) + ); + + bytes memory result = ISmartVault(smartVault).execute(connector, connectorData); + _afterBalancerV2Swapper(tokenIn, amountIn, slippage, tokenOut, result.toUint256()); + } + + /** + * @dev Before Balancer V2 swapper hook + */ + function _beforeBalancerV2Swapper(address token, uint256 amount, uint256 slippage) internal virtual { + _beforeBaseSwapTask(token, amount, slippage); + } + + /** + * @dev After Balancer v2 swapper hook + */ + function _afterBalancerV2Swapper( + address tokenIn, + uint256 amountIn, + uint256 slippage, + address tokenOut, + uint256 amountOut + ) internal virtual { + _afterBaseSwapTask(tokenIn, amountIn, slippage, tokenOut, amountOut); + } +} diff --git a/packages/tasks/test/swap/BalancerV2Swapper.test.ts b/packages/tasks/test/swap/BalancerV2Swapper.test.ts new file mode 100644 index 00000000..a7ad8717 --- /dev/null +++ b/packages/tasks/test/swap/BalancerV2Swapper.test.ts @@ -0,0 +1,53 @@ +import { deploy, deployProxy, getSigners, ZERO_ADDRESS } from '@mimic-fi/v3-helpers' +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address' +import { Contract } from 'ethers' + +import { buildEmptyTaskConfig, deployEnvironment } from '../../src/setup' +import { itBehavesLikeBaseSwapTask } from './BaseSwapTask.behavior' + +describe('BalancerV2Swapper', () => { + let task: Contract + let smartVault: Contract, authorizer: Contract, connector: Contract, owner: SignerWithAddress + + before('setup', async () => { + // eslint-disable-next-line prettier/prettier + [, owner] = await getSigners() + ;({ authorizer, smartVault } = await deployEnvironment(owner)) + }) + + before('deploy connector', async () => { + connector = await deploy('BalancerV2SwapConnectorMock', [ZERO_ADDRESS]) + const overrideConnectorCheckRole = smartVault.interface.getSighash('overrideConnectorCheck') + await authorizer.connect(owner).authorize(owner.address, smartVault.address, overrideConnectorCheckRole, []) + await smartVault.connect(owner).overrideConnectorCheck(connector.address, true) + }) + + beforeEach('deploy task', async () => { + task = await deployProxy( + 'BalancerV2Swapper', + [], + [ + { + baseSwapConfig: { + connector: connector.address, + tokenOut: ZERO_ADDRESS, + maxSlippage: 0, + customTokensOut: [], + customMaxSlippages: [], + taskConfig: buildEmptyTaskConfig(owner, smartVault), + }, + }, + ] + ) + }) + + describe('swapper', () => { + beforeEach('set params', async function () { + this.owner = owner + this.task = task + this.authorizer = authorizer + }) + + itBehavesLikeBaseSwapTask('BALANCER_V2_SWAPPER') + }) +}) From 5a23c27e2ac7bca35ee7e390748425166dea9e0c Mon Sep 17 00:00:00 2001 From: patricio henderson Date: Fri, 12 Apr 2024 15:46:44 -0300 Subject: [PATCH 2/4] Tasks: Implement balancer v2 pool id setter --- .../contracts/AuthorizedHelpers.sol | 6 ++ .../interfaces/swap/IBalancerV2Swapper.sol | 20 ++++++ .../contracts/swap/BalancerV2Swapper.sol | 48 ++++++++++++- .../tasks/test/swap/BalancerV2Swapper.test.ts | 71 ++++++++++++++++++- 4 files changed, 143 insertions(+), 2 deletions(-) diff --git a/packages/authorizer/contracts/AuthorizedHelpers.sol b/packages/authorizer/contracts/AuthorizedHelpers.sol index fcd0c037..b90d9e46 100644 --- a/packages/authorizer/contracts/AuthorizedHelpers.sol +++ b/packages/authorizer/contracts/AuthorizedHelpers.sol @@ -136,4 +136,10 @@ contract AuthorizedHelpers { r[3] = p4; r[4] = p5; } + + function authParams(address p1, bytes32 p2) internal pure returns (uint256[] memory r) { + r = new uint256[](2); + r[0] = uint256(uint160(p1)); + r[1] = uint256(p2); + } } diff --git a/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol index 5be41a35..1f66cd08 100644 --- a/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol +++ b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol @@ -20,6 +20,26 @@ import './IBaseSwapTask.sol'; * @dev Balancer v2 swapper task interface */ interface IBalancerV2Swapper is IBaseSwapTask { + /** + * @dev The pool id for the token is not set + */ + error TaskMissingPoolId(); + + /** + * @dev The pool id for the token zero + */ + error PoolIdZero(); + + /** + * @dev Emitted every time a pool is set for a token + */ + event BalancerPoolIdSet(address indexed token, bytes32 poolId); + + /** + * @dev Tells pool id set for a token + */ + function tokenPoolId(address token) external view returns (bytes32); + /** * @dev Execution function */ diff --git a/packages/tasks/contracts/swap/BalancerV2Swapper.sol b/packages/tasks/contracts/swap/BalancerV2Swapper.sol index 5ec8659d..1f8f6763 100644 --- a/packages/tasks/contracts/swap/BalancerV2Swapper.sol +++ b/packages/tasks/contracts/swap/BalancerV2Swapper.sol @@ -33,10 +33,22 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { // Execution type for relayers bytes32 public constant override EXECUTION_TYPE = keccak256('BALANCER_V2_SWAPPER'); + // List of pool id's per token + mapping (address => bytes32) public balancerPoolId; + + /** + * @dev Pool id config. Only used in the initializer. + */ + struct BalancerPoolId { + address token; + bytes32 poolId; + } + /** * @dev Balancer v2 swap config. Only used in the initalizer */ struct BalancerV2SwapConfig { + BalancerPoolId[] balancerPoolIds; BaseSwapConfig baseSwapConfig; } @@ -65,6 +77,25 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { // solhint-disable-previous-line no-empty-blocks } + /** + * @dev Sets a balancer pool id for a Token + * @param token addres of the token + * @param poolId id of the poool to be set + */ + function setPoolId(address token, bytes32 poolId) external authP(authParams(token, poolId)) { + _setPoolId(token, poolId); + } + + /** + * @dev Tells pool id set for a token + * @param token address of the token + */ + function tokenPoolId(address token) external view returns (bytes32) { + bytes32 poolId = balancerPoolId[token]; + require(poolId != bytes32(0), 'Pool id not found for token'); + return poolId; + } + /** * @dev Executes the Balancer v2 swapper task */ @@ -79,6 +110,7 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { address tokenOut = getTokenOut(tokenIn); uint256 price = _getPrice(tokenIn, tokenOut); uint256 minAmountOut = amountIn.mulUp(price).mulUp(FixedPoint.ONE - slippage); + bytes32 poolId = balancerPoolId[tokenIn]; bytes memory connectorData = abi.encodeWithSelector( IBalancerV2SwapConnector.execute.selector, @@ -86,7 +118,7 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { tokenOut, amountIn, minAmountOut, - IBalancerPool(tokenIn).getPoolId(), + poolId, new bytes32[](0), new address[](0) ); @@ -100,6 +132,7 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { */ function _beforeBalancerV2Swapper(address token, uint256 amount, uint256 slippage) internal virtual { _beforeBaseSwapTask(token, amount, slippage); + if (balancerPoolId[token] == bytes32(0)) revert TaskMissingPoolId(); } /** @@ -114,4 +147,17 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { ) internal virtual { _afterBaseSwapTask(tokenIn, amountIn, slippage, tokenOut, amountOut); } + + /** + * @dev Sets a balancer pool id for a Token + * @param token addres of the token + * @param poolId id of the poool to be set + */ + function _setPoolId(address token, bytes32 poolId) internal { + if (token == address(0)) revert TaskTokenZero(); + if (poolId == bytes32(0)) revert PoolIdZero(); + + balancerPoolId[token] = poolId; + emit BalancerPoolIdSet(token, poolId); + } } diff --git a/packages/tasks/test/swap/BalancerV2Swapper.test.ts b/packages/tasks/test/swap/BalancerV2Swapper.test.ts index a7ad8717..043ebcd9 100644 --- a/packages/tasks/test/swap/BalancerV2Swapper.test.ts +++ b/packages/tasks/test/swap/BalancerV2Swapper.test.ts @@ -1,5 +1,15 @@ -import { deploy, deployProxy, getSigners, ZERO_ADDRESS } from '@mimic-fi/v3-helpers' +import { + assertEvent, + deploy, + deployProxy, + deployTokenMock, + getSigners, + ONES_BYTES32, + ZERO_ADDRESS, + ZERO_BYTES32, +} from '@mimic-fi/v3-helpers' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address' +import { expect } from 'chai' import { Contract } from 'ethers' import { buildEmptyTaskConfig, deployEnvironment } from '../../src/setup' @@ -28,6 +38,7 @@ describe('BalancerV2Swapper', () => { [], [ { + balancerPoolIds: [], baseSwapConfig: { connector: connector.address, tokenOut: ZERO_ADDRESS, @@ -50,4 +61,62 @@ describe('BalancerV2Swapper', () => { itBehavesLikeBaseSwapTask('BALANCER_V2_SWAPPER') }) + + describe('setPoolId', () => { + let token: Contract + + before('deploy token mock', async () => { + token = await deployTokenMock('TKN') + }) + + context('when the sender is authorized', () => { + beforeEach('set sender', async () => { + const setPoolIdRole = task.interface.getSighash('setPoolId') + await authorizer.connect(owner).authorize(owner.address, task.address, setPoolIdRole, []) + task = task.connect(owner) + }) + + context('when the pool id is not zero', () => { + const poolId = ONES_BYTES32 + + it('sets the pool id', async () => { + await task.setPoolId(token.address, poolId) + expect(await task.tokenPoolId(token.address)).to.be.equal(poolId) + }) + + it('emits an event', async () => { + const tx = await task.setPoolId(token.address, poolId) + await assertEvent(tx, 'BalancerPoolIdSet', { token: token.address, poolId }) + }) + + context('when modifying the pool id', () => { + beforeEach('set pool id', async () => { + await task.setPoolId(token.address, poolId) + }) + + it('updates the pool id', async () => { + const newPoolId = '0x0000000000000000000000000000000000000000000000000000000000000001' + await task.setPoolId(token.address, newPoolId) + expect(await task.tokenPoolId(token.address)).to.be.equal(newPoolId) + }) + }) + }) + + context('when the pool id is zero', () => { + const poolId = ZERO_BYTES32 + + it('reverts', async () => { + await expect(task.setPoolId(token.address, poolId)).to.be.revertedWith('PoolIdZero') + }) + }) + + context('when the token address is zero', () => { + it('reverts', async () => { + await expect( + task.setPoolId(ZERO_ADDRESS, '0x0000000000000000000000000000000000000000000000000000000000000001') + ).to.be.revertedWith('TaskTokenZero') + }) + }) + }) + }) }) From e411dcb76a09bdc8416860a62cafdb5226eb9d4d Mon Sep 17 00:00:00 2001 From: patricio henderson Date: Mon, 15 Apr 2024 09:33:27 -0300 Subject: [PATCH 3/4] Tasks: Apply suggestions from code review --- .../interfaces/swap/IBalancerV2Swapper.sol | 9 ++------- packages/tasks/contracts/swap/BalancerV2Swapper.sol | 12 +----------- packages/tasks/test/swap/BalancerV2Swapper.test.ts | 13 ++++--------- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol index 1f66cd08..4c448623 100644 --- a/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol +++ b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol @@ -26,20 +26,15 @@ interface IBalancerV2Swapper is IBaseSwapTask { error TaskMissingPoolId(); /** - * @dev The pool id for the token zero + * @dev The requested pool id to be set is zero */ - error PoolIdZero(); + error TaskPoolIdZero(); /** * @dev Emitted every time a pool is set for a token */ event BalancerPoolIdSet(address indexed token, bytes32 poolId); - /** - * @dev Tells pool id set for a token - */ - function tokenPoolId(address token) external view returns (bytes32); - /** * @dev Execution function */ diff --git a/packages/tasks/contracts/swap/BalancerV2Swapper.sol b/packages/tasks/contracts/swap/BalancerV2Swapper.sol index 1f8f6763..fb624512 100644 --- a/packages/tasks/contracts/swap/BalancerV2Swapper.sol +++ b/packages/tasks/contracts/swap/BalancerV2Swapper.sol @@ -86,16 +86,6 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { _setPoolId(token, poolId); } - /** - * @dev Tells pool id set for a token - * @param token address of the token - */ - function tokenPoolId(address token) external view returns (bytes32) { - bytes32 poolId = balancerPoolId[token]; - require(poolId != bytes32(0), 'Pool id not found for token'); - return poolId; - } - /** * @dev Executes the Balancer v2 swapper task */ @@ -155,7 +145,7 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { */ function _setPoolId(address token, bytes32 poolId) internal { if (token == address(0)) revert TaskTokenZero(); - if (poolId == bytes32(0)) revert PoolIdZero(); + if (poolId == bytes32(0)) revert TaskPoolIdZero(); balancerPoolId[token] = poolId; emit BalancerPoolIdSet(token, poolId); diff --git a/packages/tasks/test/swap/BalancerV2Swapper.test.ts b/packages/tasks/test/swap/BalancerV2Swapper.test.ts index 043ebcd9..6563f5a0 100644 --- a/packages/tasks/test/swap/BalancerV2Swapper.test.ts +++ b/packages/tasks/test/swap/BalancerV2Swapper.test.ts @@ -79,11 +79,6 @@ describe('BalancerV2Swapper', () => { context('when the pool id is not zero', () => { const poolId = ONES_BYTES32 - it('sets the pool id', async () => { - await task.setPoolId(token.address, poolId) - expect(await task.tokenPoolId(token.address)).to.be.equal(poolId) - }) - it('emits an event', async () => { const tx = await task.setPoolId(token.address, poolId) await assertEvent(tx, 'BalancerPoolIdSet', { token: token.address, poolId }) @@ -95,9 +90,9 @@ describe('BalancerV2Swapper', () => { }) it('updates the pool id', async () => { - const newPoolId = '0x0000000000000000000000000000000000000000000000000000000000000001' - await task.setPoolId(token.address, newPoolId) - expect(await task.tokenPoolId(token.address)).to.be.equal(newPoolId) + const poolId = '0x0000000000000000000000000000000000000000000000000000000000000001' + const tx = await task.setPoolId(token.address, poolId) + await assertEvent(tx, 'BalancerPoolIdSet', { token: token.address, poolId }) }) }) }) @@ -106,7 +101,7 @@ describe('BalancerV2Swapper', () => { const poolId = ZERO_BYTES32 it('reverts', async () => { - await expect(task.setPoolId(token.address, poolId)).to.be.revertedWith('PoolIdZero') + await expect(task.setPoolId(token.address, poolId)).to.be.revertedWith('TaskPoolIdZero') }) }) From 3a23c5300daac250511d6889e1b05fbb9a44a86b Mon Sep 17 00:00:00 2001 From: patricio henderson Date: Tue, 16 Apr 2024 21:07:46 -0300 Subject: [PATCH 4/4] Tasks: Apply suggestions from code review --- .../interfaces/swap/IBalancerV2Swapper.sol | 5 ----- .../tasks/contracts/swap/BalancerV2Swapper.sol | 17 ++++++++--------- .../tasks/test/swap/BalancerV2Swapper.test.ts | 9 --------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol index 4c448623..0eae4dda 100644 --- a/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol +++ b/packages/tasks/contracts/interfaces/swap/IBalancerV2Swapper.sol @@ -25,11 +25,6 @@ interface IBalancerV2Swapper is IBaseSwapTask { */ error TaskMissingPoolId(); - /** - * @dev The requested pool id to be set is zero - */ - error TaskPoolIdZero(); - /** * @dev Emitted every time a pool is set for a token */ diff --git a/packages/tasks/contracts/swap/BalancerV2Swapper.sol b/packages/tasks/contracts/swap/BalancerV2Swapper.sol index fb624512..1f09e32b 100644 --- a/packages/tasks/contracts/swap/BalancerV2Swapper.sol +++ b/packages/tasks/contracts/swap/BalancerV2Swapper.sol @@ -37,7 +37,7 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { mapping (address => bytes32) public balancerPoolId; /** - * @dev Pool id config. Only used in the initializer. + * @dev Balancer pool id config. Only used in the initializer. */ struct BalancerPoolId { address token; @@ -70,7 +70,7 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { } /** - * @dev Initializes the balancer swapper. It does not call upper contracts + * @dev Initializes the Balancer swapper. It does not call upper contracts * @param config Balancer V2 swap config */ function __BalancerV2Swapper_init_unchained(BalancerV2SwapConfig memory config) internal onlyInitializing { @@ -78,9 +78,9 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { } /** - * @dev Sets a balancer pool id for a Token - * @param token addres of the token - * @param poolId id of the poool to be set + * @dev Sets a Balancer pool ID for a token + * @param token Address of the token to set the pool ID of + * @param poolId ID of the pool to be set for the given token */ function setPoolId(address token, bytes32 poolId) external authP(authParams(token, poolId)) { _setPoolId(token, poolId); @@ -139,13 +139,12 @@ contract BalancerV2Swapper is IBalancerV2Swapper, BaseSwapTask { } /** - * @dev Sets a balancer pool id for a Token - * @param token addres of the token - * @param poolId id of the poool to be set + * @dev Sets a Balancer pool ID for a token + * @param token Address of the token to set the pool ID of + * @param poolId ID of the pool to be set for the given token */ function _setPoolId(address token, bytes32 poolId) internal { if (token == address(0)) revert TaskTokenZero(); - if (poolId == bytes32(0)) revert TaskPoolIdZero(); balancerPoolId[token] = poolId; emit BalancerPoolIdSet(token, poolId); diff --git a/packages/tasks/test/swap/BalancerV2Swapper.test.ts b/packages/tasks/test/swap/BalancerV2Swapper.test.ts index 6563f5a0..58ca1d73 100644 --- a/packages/tasks/test/swap/BalancerV2Swapper.test.ts +++ b/packages/tasks/test/swap/BalancerV2Swapper.test.ts @@ -6,7 +6,6 @@ import { getSigners, ONES_BYTES32, ZERO_ADDRESS, - ZERO_BYTES32, } from '@mimic-fi/v3-helpers' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address' import { expect } from 'chai' @@ -97,14 +96,6 @@ describe('BalancerV2Swapper', () => { }) }) - context('when the pool id is zero', () => { - const poolId = ZERO_BYTES32 - - it('reverts', async () => { - await expect(task.setPoolId(token.address, poolId)).to.be.revertedWith('TaskPoolIdZero') - }) - }) - context('when the token address is zero', () => { it('reverts', async () => { await expect(