Skip to content

Commit

Permalink
Tasks: Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
PatricioHenderson committed Apr 15, 2024
1 parent 5a23c27 commit e411dcb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
12 changes: 1 addition & 11 deletions packages/tasks/contracts/swap/BalancerV2Swapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions packages/tasks/test/swap/BalancerV2Swapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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 })
})
})
})
Expand All @@ -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')
})
})

Expand Down

0 comments on commit e411dcb

Please sign in to comment.