diff --git a/pkg/vault/contracts/Authorizer.sol b/pkg/vault/contracts/Authorizer.sol index 676191bf84..68bb96b466 100644 --- a/pkg/vault/contracts/Authorizer.sol +++ b/pkg/vault/contracts/Authorizer.sol @@ -19,6 +19,7 @@ import "./interfaces/IDelayProvider.sol"; import "./DelayedCall.sol"; import "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/AccessControl.sol"; import "@balancer-labs/v2-solidity-utils/contracts/helpers/InputHelpers.sol"; + /** * @dev Basic Authorizer implementation, based on OpenZeppelin's Access Control. * @@ -32,18 +33,25 @@ contract Authorizer is AccessControl, IAuthorizer, IDelayProvider { using EnumerableSet for EnumerableSet.AddressSet; mapping(bytes32 => uint256) private _actionDelays; mapping(bytes32 => EnumerableSet.AddressSet) private _delayedCalls; - uint256 constant public _MIN_DELAY = 3600; // 1h in seconds - bytes32 constant public _SET_ACTION_DELAY = keccak256(abi.encodePacked(Authorizer.setActionDelay.selector)); + uint256 public constant MIN_DELAY = 3600; // 1h in seconds + bytes32 public constant SET_ACTION_DELAY = keccak256(abi.encodePacked(Authorizer.setActionDelay.selector)); /** * @dev Emitted when a call is scheduled as part of operation `actionId`. */ - event DelayedCallScheduled(bytes32 indexed actionId, address callAddress, address where, uint256 value, bytes data, uint256 delay); + event DelayedCallScheduled( + bytes32 indexed actionId, + address callAddress, + address where, + uint256 value, + bytes data, + uint256 delay + ); event ActionDelaySet(bytes32 indexed actionId, uint256 delay); constructor(address admin) { _setupRole(DEFAULT_ADMIN_ROLE, admin); - _setActionDelay(_SET_ACTION_DELAY, _MIN_DELAY); + _setActionDelay(SET_ACTION_DELAY, MIN_DELAY); } /** @@ -66,16 +74,13 @@ contract Authorizer is AccessControl, IAuthorizer, IDelayProvider { Delayed actions */ - function setActionDelay( - bytes32 actionId, - uint256 delay - ) external { - require(canPerform(_SET_ACTION_DELAY, msg.sender, GLOBAL_ROLE_ADMIN), "Cannot schedule"); + function setActionDelay(bytes32 actionId, uint256 delay) external { + require(canPerform(SET_ACTION_DELAY, msg.sender, GLOBAL_ROLE_ADMIN), "Cannot schedule"); _setActionDelay(actionId, delay); } function _setActionDelay(bytes32 actionId, uint256 delay) internal { - require(delay >= _MIN_DELAY, "Delay too short"); + require(delay >= MIN_DELAY, "Delay too short"); _actionDelays[actionId] = delay; emit ActionDelaySet(actionId, delay); } @@ -101,7 +106,7 @@ contract Authorizer is AccessControl, IAuthorizer, IDelayProvider { uint256 value, bytes calldata data, bool permissionedTrigger - ) external returns(address) { + ) external returns (address) { require(AccessControl.hasRole(actionId, msg.sender, where), "Invalid permission"); uint256 delay = _actionDelays[actionId]; require(delay > 0, "Not a delayed action"); diff --git a/pkg/vault/contracts/DelayedCall.sol b/pkg/vault/contracts/DelayedCall.sol index 564d876243..d08ad1d488 100644 --- a/pkg/vault/contracts/DelayedCall.sol +++ b/pkg/vault/contracts/DelayedCall.sol @@ -16,8 +16,8 @@ pragma solidity ^0.7.0; import "./interfaces/IDelayProvider.sol"; import "./interfaces/IAuthorizer.sol"; -contract DelayedCall { +contract DelayedCall { IDelayProvider private _delayProvider; IAuthorizer private _authorizer; bool public triggered = false; @@ -30,16 +30,15 @@ contract DelayedCall { bool public cancelled; /** - * @dev Emitted when a call is performed as part of operation `id`. - */ + * @dev Emitted when a call is performed as part of operation `id`. + */ event DelayedCallExecuted(bytes32 indexed actionId, address where, uint256 value, bytes data); /** - * @dev Emitted when a call is cancelled - */ + * @dev Emitted when a call is cancelled + */ event DelayedCallCancelled(bytes32 indexed actionId, address where, uint256 value, bytes data); - constructor( bytes memory _data, address _where, @@ -63,7 +62,7 @@ contract DelayedCall { actionId = _actionId; cancelled = false; } - + function trigger() external { require(!cancelled, "Action is cancelled"); require(isReadyToCall(), "Action triggered too soon"); @@ -72,11 +71,11 @@ contract DelayedCall { } require(!triggered, "Action already triggered"); triggered = true; - (bool success, ) = where.call{value: value}(data); + (bool success, ) = where.call{ value: value }(data); require(success, "Underlying transaction reverted"); emit DelayedCallExecuted(actionId, where, value, data); } - + function cancel() external { require(_authorizer.canPerform(actionId, msg.sender, where), "Not Authorized"); require(!cancelled, "Action already cancelled"); @@ -85,9 +84,7 @@ contract DelayedCall { emit DelayedCallCancelled(actionId, where, value, data); } - function isReadyToCall() public view returns(bool) { - return block.timestamp > _delayProvider.getDelay(actionId) + start; + function isReadyToCall() public view returns (bool) { + return block.timestamp > _delayProvider.getDelay(actionId) + start; } - - } diff --git a/pkg/vault/test/Authorizer.test.ts b/pkg/vault/test/Authorizer.test.ts index 0cac7336b9..a0d07fca2b 100644 --- a/pkg/vault/test/Authorizer.test.ts +++ b/pkg/vault/test/Authorizer.test.ts @@ -310,8 +310,8 @@ describe('Authorizer', () => { }); context('initial conditions', () => { it('setActionDelay is delayed by minimum delay initially', async () => { - expect(await authorizer._SET_ACTION_DELAY()).to.equal(actionDelayId); - expect(await authorizer.getDelay(actionDelayId)).to.equal(await authorizer._MIN_DELAY()); + expect(await authorizer.SET_ACTION_DELAY()).to.equal(actionDelayId); + expect(await authorizer.getDelay(actionDelayId)).to.equal(await authorizer.MIN_DELAY()); }); }); diff --git a/pkg/vault/test/DelayedCall.test.ts b/pkg/vault/test/DelayedCall.test.ts index 7211527674..fed6bbff63 100644 --- a/pkg/vault/test/DelayedCall.test.ts +++ b/pkg/vault/test/DelayedCall.test.ts @@ -81,7 +81,7 @@ describe('DelayedCall', () => { await ethers.provider.send('evm_mine', []); const tx = await delayedCall.trigger(); const receipt = await tx.wait(); - console.log(receipt.events) + console.log(receipt.events); expect(await delayedCall.triggered()).to.equal(true); expect(await mockAuthorizer.triggeredValue()).to.equal(123); expectEvent.inReceipt(receipt, 'DelayedCallExecuted', { @@ -90,7 +90,6 @@ describe('DelayedCall', () => { value: 0, data: targetMethodData, }); - }); it('fails if early', async () => {