From 882a2e31fd81ead6ef412f2e7719c25582c8cf54 Mon Sep 17 00:00:00 2001 From: Michael de Hoog Date: Tue, 22 Oct 2024 10:59:17 -1000 Subject: [PATCH] forge fmt (#100) --- .github/workflows/test.yml | 9 +- script/deploy/Utils.sol | 15 +- script/deploy/l1/SetGasLimitBuilder.sol | 21 +-- .../l1/tests/DeployTestTokenContracts.s.sol | 10 +- script/deploy/l1/tests/TestDeposits.s.sol | 19 +- .../l2/tests/DeployTestTokenContracts.s.sol | 20 +-- script/deploy/l2/tests/TestWithdraw.s.sol | 22 +-- script/universal/IGnosisSafe.sol | 51 +----- script/universal/MultisigBase.sol | 42 +++-- script/universal/MultisigBuilder.sol | 37 ++-- script/universal/NestedMultisigBuilder.sol | 94 +++++----- script/universal/Signatures.sol | 18 +- script/universal/Simulation.sol | 85 +++++---- src/Challenger1of2.sol | 23 +-- src/TestOwner.sol | 2 +- src/fee-vault-fixes/FeeVault.sol | 2 +- src/revenue-share/BalanceTracker.sol | 78 ++++----- src/revenue-share/FeeDisburser.sol | 62 +++---- src/smart-escrow/SmartEscrow.sol | 10 +- test/Challenger1of2.t.sol | 62 +++---- test/CommonTest.t.sol | 2 +- test/MockERC20.t.sol | 5 +- test/fee-vault-fixes/e2e/FeeVault.t.sol | 39 ++--- test/revenue-share/BalanceTracker.t.sol | 165 ++++++------------ test/revenue-share/FeeDisburser.t.sol | 159 ++++++++--------- test/revenue-share/mocks/FeeVaultRevert.sol | 12 +- .../mocks/ReenterProcessFees.sol | 2 +- test/smart-escrow/BaseSmartEscrow.t.sol | 6 +- test/smart-escrow/Constructor.t.sol | 3 +- test/smart-escrow/Release.t.sol | 2 +- test/smart-escrow/Resume.t.sol | 4 +- test/smart-escrow/Terminate.t.sol | 4 +- test/smart-escrow/UpdateBenefactor.t.sol | 6 +- test/smart-escrow/UpdateBeneficiary.t.sol | 6 +- .../smart-escrow/WithdrawUnvestedTokens.t.sol | 6 +- test/universal/MultisigBuilder.t.sol | 11 +- test/universal/NestedMultisigBuilder.t.sol | 16 +- 37 files changed, 475 insertions(+), 655 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 793af69..3adbcd1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,11 +27,10 @@ jobs: run: | forge --version -# TODO reformat and enable in separate PR -# - name: Run Forge fmt -# run: | -# forge fmt --check -# id: fmt + - name: Run Forge fmt + run: | + forge fmt --check + id: fmt - name: Install dependencies run: | diff --git a/script/deploy/Utils.sol b/script/deploy/Utils.sol index 2f41c5b..1a9a3c2 100644 --- a/script/deploy/Utils.sol +++ b/script/deploy/Utils.sol @@ -20,7 +20,7 @@ contract Utils is Script { address l1FeeVaultRecipient; uint256 l2BlockTime; uint256 l2ChainId; - uint64 l2GenesisBlockGasLimit; + uint64 l2GenesisBlockGasLimit; address l2OutputOracleChallenger; address l2OutputOracleProposer; uint256 l2OutputOracleStartingBlockNumber; @@ -59,7 +59,7 @@ contract Utils is Script { address SequencerFeeVault; } - function getDeployBedrockConfig() external view returns(DeployBedrockConfig memory) { + function getDeployBedrockConfig() external view returns (DeployBedrockConfig memory) { string memory root = vm.projectRoot(); string memory path = string.concat(root, "/inputs/foundry-config.json"); string memory json = vm.readFile(path); @@ -84,7 +84,7 @@ contract Utils is Script { } function writeAddressesFile(AddressesConfig memory cfg) external { - string memory json= ""; + string memory json = ""; // Proxy contract addresses vm.serializeAddress(json, "ProxyAdmin", cfg.ProxyAdmin); @@ -96,7 +96,7 @@ contract Utils is Script { vm.serializeAddress(json, "OptimismMintableERC20FactoryProxy", cfg.OptimismMintableERC20FactoryProxy); vm.serializeAddress(json, "L1ERC721BridgeProxy", cfg.L1ERC721BridgeProxy); vm.serializeAddress(json, "SystemConfigProxy", cfg.SystemConfigProxy); - + string memory finalJson = vm.serializeAddress(json, "SystemDictatorProxy", cfg.SystemDictatorProxy); finalJson.write(string.concat("unsorted.json")); @@ -115,10 +115,9 @@ contract Utils is Script { vm.serializeAddress(json, "L2ToL1MessagePasser", cfg.L2ToL1MessagePasser); vm.serializeAddress(json, "SequencerFeeVault", cfg.SequencerFeeVault); vm.serializeAddress(json, "OptimismMintableERC20Factory", cfg.OptimismMintableERC20Factory); - string memory finalJson = vm.serializeAddress( - json, "OptimismMintableERC721Factory", cfg.OptimismMintableERC721Factory - ); + string memory finalJson = + vm.serializeAddress(json, "OptimismMintableERC721Factory", cfg.OptimismMintableERC721Factory); finalJson.write(string.concat("unsortedl2Impls.json")); } -} \ No newline at end of file +} diff --git a/script/deploy/l1/SetGasLimitBuilder.sol b/script/deploy/l1/SetGasLimitBuilder.sol index 4012a9f..e5e3381 100644 --- a/script/deploy/l1/SetGasLimitBuilder.sol +++ b/script/deploy/l1/SetGasLimitBuilder.sol @@ -2,13 +2,8 @@ pragma solidity 0.8.15; import {SystemConfig} from "@eth-optimism-bedrock/src/L1/SystemConfig.sol"; -import { - MultisigBuilder, - IMulticall3, - IGnosisSafe, - Simulation -} from "../../universal/MultisigBuilder.sol"; -import { Vm } from "forge-std/Vm.sol"; +import {MultisigBuilder, IMulticall3, IGnosisSafe, Simulation} from "../../universal/MultisigBuilder.sol"; +import {Vm} from "forge-std/Vm.sol"; abstract contract SetGasLimitBuilder is MultisigBuilder { address internal SYSTEM_CONFIG_OWNER = vm.envAddress("SYSTEM_CONFIG_OWNER"); @@ -19,20 +14,18 @@ abstract contract SetGasLimitBuilder is MultisigBuilder { * Virtual Functions * ----------------------------------------------------------- */ + function _fromGasLimit() internal view virtual returns (uint64); - function _fromGasLimit() internal virtual view returns (uint64); + function _toGasLimit() internal view virtual returns (uint64); - function _toGasLimit() internal virtual view returns (uint64); - - function _nonceOffset() internal virtual view returns (uint64); + function _nonceOffset() internal view virtual returns (uint64); /** * ----------------------------------------------------------- * Implemented Functions * ----------------------------------------------------------- */ - - function _postCheck() internal override view { + function _postCheck() internal view override { assert(SystemConfig(L1_SYSTEM_CONFIG).gasLimit() == _toGasLimit()); } @@ -63,7 +56,7 @@ abstract contract SetGasLimitBuilder is MultisigBuilder { Simulation.StorageOverride[] memory _storageOverrides = new Simulation.StorageOverride[](1); _storageOverrides[0] = Simulation.StorageOverride({ key: 0x0000000000000000000000000000000000000000000000000000000000000068, // slot of gas limit - value: bytes32(uint(_fromGasLimit())) + value: bytes32(uint256(_fromGasLimit())) }); _stateOverrides[0] = Simulation.StateOverride({contractAddress: L1_SYSTEM_CONFIG, overrides: _storageOverrides}); return _stateOverrides; diff --git a/script/deploy/l1/tests/DeployTestTokenContracts.s.sol b/script/deploy/l1/tests/DeployTestTokenContracts.s.sol index ee0f496..94c06b7 100644 --- a/script/deploy/l1/tests/DeployTestTokenContracts.s.sol +++ b/script/deploy/l1/tests/DeployTestTokenContracts.s.sol @@ -5,7 +5,8 @@ import "forge-std/console.sol"; import "forge-std/Script.sol"; import {ERC20PresetMinterPauser} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"; -import {ERC721PresetMinterPauserAutoId} from "@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol"; +import {ERC721PresetMinterPauserAutoId} from + "@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol"; // Deploys test token contracts on L1 to test Base Mainnet's bridging functionality contract DeployTestTokenContracts is Script { @@ -14,13 +15,14 @@ contract DeployTestTokenContracts is Script { ERC20PresetMinterPauser erc20 = new ERC20PresetMinterPauser("L1 TEST ERC20", "L1T20"); console.log("TEST ERC20 deployed to: %s", address(erc20)); - ERC721PresetMinterPauserAutoId erc721 = new ERC721PresetMinterPauserAutoId("L1 TEST ERC721", "L1T721", "not applicable"); + ERC721PresetMinterPauserAutoId erc721 = + new ERC721PresetMinterPauserAutoId("L1 TEST ERC721", "L1T721", "not applicable"); console.log("TEST ERC721 deployed to: %s", address(erc721)); - + erc20.mint(_tester, 1_000_000 ether); erc721.mint(_tester); console.log("Minting to tester complete"); - + vm.stopBroadcast(); } } diff --git a/script/deploy/l1/tests/TestDeposits.s.sol b/script/deploy/l1/tests/TestDeposits.s.sol index 4b28f76..c5139c0 100644 --- a/script/deploy/l1/tests/TestDeposits.s.sol +++ b/script/deploy/l1/tests/TestDeposits.s.sol @@ -5,7 +5,8 @@ import "forge-std/console.sol"; import "forge-std/Script.sol"; import {ERC20PresetMinterPauser} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol"; -import {ERC721PresetMinterPauserAutoId} from "@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol"; +import {ERC721PresetMinterPauserAutoId} from + "@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol"; import {L1StandardBridge} from "@eth-optimism-bedrock/src/L1/L1StandardBridge.sol"; import {L1ERC721Bridge} from "@eth-optimism-bedrock/src/L1/L1ERC721Bridge.sol"; @@ -27,23 +28,11 @@ contract DeployTestContracts is Script { console.log("Approvals to bridge contracts complete"); - L1StandardBridge(_l1StandardBirdge).depositERC20( - _l1erc20, - _l2erc20, - 1_000_000 ether, - 200_000, - bytes("") - ); + L1StandardBridge(_l1StandardBirdge).depositERC20(_l1erc20, _l2erc20, 1_000_000 ether, 200_000, bytes("")); console.log("L1StandardBridge erc20 deposit complete"); - L1ERC721Bridge(_l1erc721Bridge).bridgeERC721( - _l1erc721, - _l2erc721, - 0, - 200_000, - bytes("") - ); + L1ERC721Bridge(_l1erc721Bridge).bridgeERC721(_l1erc721, _l2erc721, 0, 200_000, bytes("")); console.log("L1ERC721Bridge erc721 deposit complete"); } diff --git a/script/deploy/l2/tests/DeployTestTokenContracts.s.sol b/script/deploy/l2/tests/DeployTestTokenContracts.s.sol index 40e1315..99a07e4 100644 --- a/script/deploy/l2/tests/DeployTestTokenContracts.s.sol +++ b/script/deploy/l2/tests/DeployTestTokenContracts.s.sol @@ -10,24 +10,14 @@ import {OptimismMintableERC721Factory} from "@eth-optimism-bedrock/src/universal // Deploys test token contracts on L2 to test Base Mainnet functionality contract DeployTestTokenContracts is Script { - function run( - address _tester, - address _l1erc20, - address _l1erc721 - ) public { + function run(address _tester, address _l1erc20, address _l1erc721) public { vm.startBroadcast(_tester); - address erc20 = OptimismMintableERC20Factory(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY).createOptimismMintableERC20( - _l1erc20, - "L2 TEST ERC20", - "L2T20" - ); + address erc20 = OptimismMintableERC20Factory(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY) + .createOptimismMintableERC20(_l1erc20, "L2 TEST ERC20", "L2T20"); console.log("Bridged erc20 deployed to: %s", address(erc20)); - address erc721 = OptimismMintableERC721Factory(payable(Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY)).createOptimismMintableERC721( - _l1erc721, - "L2 TEST ERC721", - "L1T721" - ); + address erc721 = OptimismMintableERC721Factory(payable(Predeploys.OPTIMISM_MINTABLE_ERC721_FACTORY)) + .createOptimismMintableERC721(_l1erc721, "L2 TEST ERC721", "L1T721"); console.log("Bridged erc721 deployed to: %s", address(erc721)); vm.stopBroadcast(); diff --git a/script/deploy/l2/tests/TestWithdraw.s.sol b/script/deploy/l2/tests/TestWithdraw.s.sol index 6c1e713..78591ed 100644 --- a/script/deploy/l2/tests/TestWithdraw.s.sol +++ b/script/deploy/l2/tests/TestWithdraw.s.sol @@ -10,28 +10,12 @@ import {L2ERC721Bridge} from "@eth-optimism-bedrock/src/L2/L2ERC721Bridge.sol"; // Withdraws tokens from L2 to L1 to test Base Mainnet's bridging functionality contract TestWithdraw is Script { - function run( - address _tester, - address _l2erc20, - address _l1erc721, - address _l2erc721 - ) public { + function run(address _tester, address _l2erc20, address _l1erc721, address _l2erc721) public { vm.startBroadcast(_tester); - L2StandardBridge(payable(Predeploys.L2_STANDARD_BRIDGE)).withdraw( - _l2erc20, - 10_000 ether, - 200_000, - bytes("") - ); + L2StandardBridge(payable(Predeploys.L2_STANDARD_BRIDGE)).withdraw(_l2erc20, 10_000 ether, 200_000, bytes("")); console.log("erc20 withdrawal initiated"); - L2ERC721Bridge(payable(Predeploys.L2_ERC721_BRIDGE)).bridgeERC721( - _l2erc721, - _l1erc721, - 0, - 200_000, - bytes("") - ); + L2ERC721Bridge(payable(Predeploys.L2_ERC721_BRIDGE)).bridgeERC721(_l2erc721, _l1erc721, 0, 200_000, bytes("")); console.log("erc721 withdrawal initiated"); vm.stopBroadcast(); diff --git a/script/universal/IGnosisSafe.sol b/script/universal/IGnosisSafe.sol index 6043436..fae736a 100644 --- a/script/universal/IGnosisSafe.sol +++ b/script/universal/IGnosisSafe.sol @@ -35,12 +35,7 @@ interface IGnosisSafe { function approveHash(bytes32 hashToApprove) external; function approvedHashes(address, bytes32) external view returns (uint256); function changeThreshold(uint256 _threshold) external; - function checkNSignatures( - bytes32 dataHash, - bytes memory data, - bytes memory signatures, - uint256 requiredSignatures - ) + function checkNSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures, uint256 requiredSignatures) external view; function checkSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures) external view; @@ -58,10 +53,7 @@ interface IGnosisSafe { address gasToken, address refundReceiver, uint256 _nonce - ) - external - view - returns (bytes memory); + ) external view returns (bytes memory); function execTransaction( address to, uint256 value, @@ -73,31 +65,15 @@ interface IGnosisSafe { address gasToken, address refundReceiver, bytes memory signatures - ) - external - payable - returns (bool success); - function execTransactionFromModule( - address to, - uint256 value, - bytes memory data, - Enum.Operation operation - ) + ) external payable returns (bool success); + function execTransactionFromModule(address to, uint256 value, bytes memory data, Enum.Operation operation) external returns (bool success); - function execTransactionFromModuleReturnData( - address to, - uint256 value, - bytes memory data, - Enum.Operation operation - ) + function execTransactionFromModuleReturnData(address to, uint256 value, bytes memory data, Enum.Operation operation) external returns (bool success, bytes memory returnData); function getChainId() external view returns (uint256); - function getModulesPaginated( - address start, - uint256 pageSize - ) + function getModulesPaginated(address start, uint256 pageSize) external view returns (address[] memory array, address next); @@ -115,20 +91,12 @@ interface IGnosisSafe { address gasToken, address refundReceiver, uint256 _nonce - ) - external - view - returns (bytes32); + ) external view returns (bytes32); function isModuleEnabled(address module) external view returns (bool); function isOwner(address owner) external view returns (bool); function nonce() external view returns (uint256); function removeOwner(address prevOwner, address owner, uint256 _threshold) external; - function requiredTxGas( - address to, - uint256 value, - bytes memory data, - Enum.Operation operation - ) + function requiredTxGas(address to, uint256 value, bytes memory data, Enum.Operation operation) external returns (uint256); function setFallbackHandler(address handler) external; @@ -142,8 +110,7 @@ interface IGnosisSafe { address paymentToken, uint256 payment, address paymentReceiver - ) - external; + ) external; function signedMessages(bytes32) external view returns (uint256); function simulateAndRevert(address targetContract, bytes memory calldataPayload) external; function swapOwner(address prevOwner, address oldOwner, address newOwner) external; diff --git a/script/universal/MultisigBase.sol b/script/universal/MultisigBase.sol index 792df56..b98ae64 100644 --- a/script/universal/MultisigBase.sol +++ b/script/universal/MultisigBase.sol @@ -41,16 +41,14 @@ abstract contract MultisigBase is CommonBase { if (_readFrom_SAFE_NONCE()) { try vm.envUint("SAFE_NONCE") { nonce = vm.envUint("SAFE_NONCE"); - } - catch {} + } catch {} } // then try SAFE_NONCE_{UPPERCASE_SAFE_ADDRESS} string memory envVarName = string.concat("SAFE_NONCE_", vm.toUppercase(vm.toString(address(safe)))); try vm.envUint(envVarName) { nonce = vm.envUint(envVarName); - } - catch {} + } catch {} // print if any override if (nonce != safeNonce) { @@ -74,7 +72,9 @@ abstract contract MultisigBase is CommonBase { console.log("^^^^^^^^\n"); console.log("########## IMPORTANT ##########"); - console.log("Please make sure that the 'Data to sign' displayed above matches what you see in the simulation and on your hardware wallet."); + console.log( + "Please make sure that the 'Data to sign' displayed above matches what you see in the simulation and on your hardware wallet." + ); console.log("This is a critical step that must not be skipped."); console.log("###############################"); } @@ -87,11 +87,7 @@ abstract contract MultisigBase is CommonBase { bytes32 hash = _getTransactionHash(_safe, data); _signatures = Signatures.prepareSignatures(_safe, hash, _signatures); - _safe.checkSignatures({ - dataHash: hash, - data: data, - signatures: _signatures - }); + _safe.checkSignatures({dataHash: hash, data: data, signatures: _signatures}); } function _executeTransaction(IGnosisSafe _safe, IMulticall3.Call3[] memory _calls, bytes memory _signatures) @@ -103,11 +99,7 @@ abstract contract MultisigBase is CommonBase { _signatures = Signatures.prepareSignatures(_safe, hash, _signatures); bytes memory simData = _execTransationCalldata(_safe, data, _signatures); - Simulation.logSimulationLink({ - _to: address(_safe), - _from: msg.sender, - _data: simData - }); + Simulation.logSimulationLink({_to: address(_safe), _from: msg.sender, _data: simData}); vm.startStateDiffRecording(); bool success = _execTransaction(_safe, data, _signatures); @@ -150,7 +142,11 @@ abstract contract MultisigBase is CommonBase { }); } - function _execTransationCalldata(IGnosisSafe _safe, bytes memory _data, bytes memory _signatures) internal pure returns (bytes memory) { + function _execTransationCalldata(IGnosisSafe _safe, bytes memory _data, bytes memory _signatures) + internal + pure + returns (bytes memory) + { return abi.encodeCall( _safe.execTransaction, ( @@ -168,7 +164,10 @@ abstract contract MultisigBase is CommonBase { ); } - function _execTransaction(IGnosisSafe _safe, bytes memory _data, bytes memory _signatures) internal returns (bool) { + function _execTransaction(IGnosisSafe _safe, bytes memory _data, bytes memory _signatures) + internal + returns (bool) + { return _safe.execTransaction({ to: MULTICALL3_ADDRESS, value: 0, @@ -187,12 +186,17 @@ abstract contract MultisigBase is CommonBase { // This allows simulation of the final transaction by overriding the threshold to 1. // State changes reflected in the simulation as a result of these overrides will // not be reflected in the prod execution. - function _safeOverrides(IGnosisSafe _safe, address _owner) internal virtual view returns (Simulation.StateOverride memory) { + function _safeOverrides(IGnosisSafe _safe, address _owner) + internal + view + virtual + returns (Simulation.StateOverride memory) + { uint256 _nonce = _getNonce(_safe); return Simulation.overrideSafeThresholdOwnerAndNonce(_safe, _owner, _nonce); } // Tenderly simulations can accept generic state overrides. This hook enables this functionality. // By default, an empty (no-op) override is returned. - function _simulationOverrides() internal virtual view returns (Simulation.StateOverride[] memory overrides_) {} + function _simulationOverrides() internal view virtual returns (Simulation.StateOverride[] memory overrides_) {} } diff --git a/script/universal/MultisigBuilder.sol b/script/universal/MultisigBuilder.sol index 2540aa0..655429f 100644 --- a/script/universal/MultisigBuilder.sol +++ b/script/universal/MultisigBuilder.sol @@ -3,9 +3,9 @@ pragma solidity ^0.8.15; import "./MultisigBase.sol"; -import { console } from "forge-std/console.sol"; -import { IMulticall3 } from "forge-std/interfaces/IMulticall3.sol"; -import { Vm } from "forge-std/Vm.sol"; +import {console} from "forge-std/console.sol"; +import {IMulticall3} from "forge-std/interfaces/IMulticall3.sol"; +import {Vm} from "forge-std/Vm.sol"; /** * @title MultisigBuilder @@ -21,12 +21,12 @@ abstract contract MultisigBuilder is MultisigBase { /** * @notice Returns the safe address to execute the transaction from */ - function _ownerSafe() internal virtual view returns (address); + function _ownerSafe() internal view virtual returns (address); /** * @notice Creates the calldata for both signatures (`sign`) and execution (`run`) */ - function _buildCalls() internal virtual view returns (IMulticall3.Call3[] memory); + function _buildCalls() internal view virtual returns (IMulticall3.Call3[] memory); /** * @notice Follow up assertions to ensure that the script ran to completion. @@ -36,14 +36,12 @@ abstract contract MultisigBuilder is MultisigBase { /** * @notice Follow up assertions on state and simulation after a `sign` call. */ - function _postSign(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual { - } + function _postSign(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual {} /** * @notice Follow up assertions on state and simulation after a `run` call. */ - function _postRun(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual { - } + function _postRun(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual {} /** * ----------------------------------------------------------- @@ -102,7 +100,8 @@ abstract contract MultisigBuilder is MultisigBase { IGnosisSafe safe = IGnosisSafe(_ownerSafe()); vm.store(address(safe), SAFE_NONCE_SLOT, bytes32(_getNonce(safe))); - (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = _executeTransaction(safe, _buildCalls(), _signatures); + (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = + _executeTransaction(safe, _buildCalls(), _signatures); _postRun(accesses, simPayload); _postCheck(); @@ -119,7 +118,8 @@ abstract contract MultisigBuilder is MultisigBase { */ function run(bytes memory _signatures) public { vm.startBroadcast(); - (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = _executeTransaction(IGnosisSafe(_ownerSafe()), _buildCalls(), _signatures); + (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = + _executeTransaction(IGnosisSafe(_ownerSafe()), _buildCalls(), _signatures); vm.stopBroadcast(); _postRun(accesses, simPayload); @@ -147,21 +147,12 @@ abstract contract MultisigBuilder is MultisigBase { Simulation.StateOverride[] memory overrides = _overrides(_safe); bytes memory txData = _execTransationCalldata(_safe, data, Signatures.genPrevalidatedSignature(msg.sender)); - Simulation.logSimulationLink({ - _to: address(_safe), - _data: txData, - _from: msg.sender, - _overrides: overrides - }); + Simulation.logSimulationLink({_to: address(_safe), _data: txData, _from: msg.sender, _overrides: overrides}); // Forge simulation of the data logged in the link. If the simulation fails // we revert to make it explicit that the simulation failed. - Simulation.Payload memory simPayload = Simulation.Payload({ - to: address(_safe), - data: txData, - from: msg.sender, - stateOverrides: overrides - }); + Simulation.Payload memory simPayload = + Simulation.Payload({to: address(_safe), data: txData, from: msg.sender, stateOverrides: overrides}); Vm.AccountAccess[] memory accesses = Simulation.simulateFromSimPayload(simPayload); return (accesses, simPayload); } diff --git a/script/universal/NestedMultisigBuilder.sol b/script/universal/NestedMultisigBuilder.sol index b0b0c1f..6a59bb6 100644 --- a/script/universal/NestedMultisigBuilder.sol +++ b/script/universal/NestedMultisigBuilder.sol @@ -3,8 +3,8 @@ pragma solidity ^0.8.15; import "./MultisigBase.sol"; -import { console } from "forge-std/console.sol"; -import { IMulticall3 } from "forge-std/interfaces/IMulticall3.sol"; +import {console} from "forge-std/console.sol"; +import {IMulticall3} from "forge-std/interfaces/IMulticall3.sol"; /** * @title NestedMultisigBuilder @@ -20,12 +20,12 @@ abstract contract NestedMultisigBuilder is MultisigBase { /** * @notice Returns the nested safe address to execute the final transaction from */ - function _ownerSafe() internal virtual view returns (address); + function _ownerSafe() internal view virtual returns (address); /** * @notice Creates the calldata for both signatures (`sign`) and execution (`run`) */ - function _buildCalls() internal virtual view returns (IMulticall3.Call3[] memory); + function _buildCalls() internal view virtual returns (IMulticall3.Call3[] memory); /** * @notice Follow up assertions to ensure that the script ran to completion. @@ -36,20 +36,17 @@ abstract contract NestedMultisigBuilder is MultisigBase { /** * @notice Follow up assertions on state and simulation after a `sign` call. */ - function _postSign(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual { - } + function _postSign(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual {} /** * @notice Follow up assertions on state and simulation after a `approve` call. */ - function _postApprove(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual { - } + function _postApprove(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual {} /** * @notice Follow up assertions on state and simulation after a `run` call. */ - function _postRun(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual { - } + function _postRun(Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) internal virtual {} /** * ----------------------------------------------------------- @@ -77,7 +74,8 @@ abstract contract NestedMultisigBuilder is MultisigBase { IMulticall3.Call3[] memory nestedCalls = _buildCalls(); IMulticall3.Call3 memory call = _generateApproveCall(nestedSafe, nestedCalls); - (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = _simulateForSigner(_signerSafe, nestedSafe, nestedCalls); + (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = + _simulateForSigner(_signerSafe, nestedSafe, nestedCalls); _postSign(accesses, simPayload); _postCheck(); @@ -114,7 +112,8 @@ abstract contract NestedMultisigBuilder is MultisigBase { IMulticall3.Call3 memory call = _generateApproveCall(nestedSafe, nestedCalls); vm.startBroadcast(); - (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = _executeTransaction(_signerSafe, _toArray(call), _signatures); + (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = + _executeTransaction(_signerSafe, _toArray(call), _signatures); vm.stopBroadcast(); _postApprove(accesses, simPayload); @@ -134,7 +133,8 @@ abstract contract NestedMultisigBuilder is MultisigBase { bytes memory signatures; vm.startBroadcast(); - (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = _executeTransaction(nestedSafe, nestedCalls, signatures); + (Vm.AccountAccess[] memory accesses, Simulation.Payload memory simPayload) = + _executeTransaction(nestedSafe, nestedCalls, signatures); vm.stopBroadcast(); _postRun(accesses, simPayload); @@ -145,7 +145,11 @@ abstract contract NestedMultisigBuilder is MultisigBase { return false; } - function _generateApproveCall(IGnosisSafe _safe, IMulticall3.Call3[] memory _calls) internal view returns (IMulticall3.Call3 memory) { + function _generateApproveCall(IGnosisSafe _safe, IMulticall3.Call3[] memory _calls) + internal + view + returns (IMulticall3.Call3 memory) + { bytes32 hash = _getTransactionHash(_safe, _calls); console.log("---\nNested hash:"); @@ -170,59 +174,55 @@ abstract contract NestedMultisigBuilder is MultisigBase { bytes memory txData = abi.encodeCall(IMulticall3.aggregate3, (calls)); console.log("---\nSimulation link:"); - Simulation.logSimulationLink({ - _to: MULTICALL3_ADDRESS, - _data: txData, - _from: msg.sender, - _overrides: overrides - }); + Simulation.logSimulationLink({_to: MULTICALL3_ADDRESS, _data: txData, _from: msg.sender, _overrides: overrides}); // Forge simulation of the data logged in the link. If the simulation fails // we revert to make it explicit that the simulation failed. - Simulation.Payload memory simPayload = Simulation.Payload({ - to: MULTICALL3_ADDRESS, - data: txData, - from: msg.sender, - stateOverrides: overrides - }); + Simulation.Payload memory simPayload = + Simulation.Payload({to: MULTICALL3_ADDRESS, data: txData, from: msg.sender, stateOverrides: overrides}); Vm.AccountAccess[] memory accesses = Simulation.simulateFromSimPayload(simPayload); return (accesses, simPayload); } function _simulateForSignerCalls(IGnosisSafe _signerSafe, IGnosisSafe _safe, bytes memory _data) - internal view + internal + view returns (IMulticall3.Call3[] memory) { IMulticall3.Call3[] memory calls = new IMulticall3.Call3[](2); bytes32 hash = _getTransactionHash(_safe, _data); // simulate an approveHash, so that signer can verify the data they are signing - bytes memory approveHashData = abi.encodeCall(IMulticall3.aggregate3, (_toArray( - IMulticall3.Call3({ - target: address(_safe), - allowFailure: false, - callData: abi.encodeCall(_safe.approveHash, (hash)) - }) - ))); - bytes memory approveHashExec = _execTransationCalldata(_signerSafe, approveHashData, Signatures.genPrevalidatedSignature(MULTICALL3_ADDRESS)); - calls[0] = IMulticall3.Call3({ - target: address(_signerSafe), - allowFailure: false, - callData: approveHashExec - }); + bytes memory approveHashData = abi.encodeCall( + IMulticall3.aggregate3, + ( + _toArray( + IMulticall3.Call3({ + target: address(_safe), + allowFailure: false, + callData: abi.encodeCall(_safe.approveHash, (hash)) + }) + ) + ) + ); + bytes memory approveHashExec = _execTransationCalldata( + _signerSafe, approveHashData, Signatures.genPrevalidatedSignature(MULTICALL3_ADDRESS) + ); + calls[0] = IMulticall3.Call3({target: address(_signerSafe), allowFailure: false, callData: approveHashExec}); // simulate the final state changes tx, so that signer can verify the final results - bytes memory finalExec = _execTransationCalldata(_safe, _data, Signatures.genPrevalidatedSignature(address(_signerSafe))); - calls[1] = IMulticall3.Call3({ - target: address(_safe), - allowFailure: false, - callData: finalExec - }); + bytes memory finalExec = + _execTransationCalldata(_safe, _data, Signatures.genPrevalidatedSignature(address(_signerSafe))); + calls[1] = IMulticall3.Call3({target: address(_safe), allowFailure: false, callData: finalExec}); return calls; } - function _overrides(IGnosisSafe _signerSafe, IGnosisSafe _safe) internal view returns (Simulation.StateOverride[] memory) { + function _overrides(IGnosisSafe _signerSafe, IGnosisSafe _safe) + internal + view + returns (Simulation.StateOverride[] memory) + { Simulation.StateOverride[] memory simOverrides = _simulationOverrides(); Simulation.StateOverride[] memory overrides = new Simulation.StateOverride[](2 + simOverrides.length); overrides[0] = _safeOverrides(_signerSafe, MULTICALL3_ADDRESS); diff --git a/script/universal/Signatures.sol b/script/universal/Signatures.sol index 7d1b2e9..d515715 100644 --- a/script/universal/Signatures.sol +++ b/script/universal/Signatures.sol @@ -6,7 +6,11 @@ import {LibSort} from "@solady/utils/LibSort.sol"; import {IGnosisSafe} from "./IGnosisSafe.sol"; library Signatures { - function prepareSignatures(IGnosisSafe _safe, bytes32 hash, bytes memory _signatures) internal view returns (bytes memory) { + function prepareSignatures(IGnosisSafe _safe, bytes32 hash, bytes memory _signatures) + internal + view + returns (bytes memory) + { // prepend the prevalidated signatures to the signatures address[] memory approvers = getApprovers(_safe, hash); bytes memory prevalidatedSignatures = genPrevalidatedSignatures(approvers); @@ -68,7 +72,11 @@ library Signatures { * Can be used to accomodate any additional signatures prepended to the array. * If prevalidated signatures were prepended, this should be the length of those signatures. */ - function sortUniqueSignatures(bytes memory _signatures, bytes32 dataHash, uint256 threshold, uint256 dynamicOffset) internal pure returns (bytes memory) { + function sortUniqueSignatures(bytes memory _signatures, bytes32 dataHash, uint256 threshold, uint256 dynamicOffset) + internal + pure + returns (bytes memory) + { bytes memory sorted; uint256 count = uint256(_signatures.length / 0x41); uint256[] memory addressesAndIndexes = new uint256[](threshold); @@ -127,7 +135,11 @@ library Signatures { } // see https://github.com/safe-global/safe-contracts/blob/1ed486bb148fe40c26be58d1b517cec163980027/contracts/common/SignatureDecoder.sol - function signatureSplit(bytes memory signatures, uint256 pos) internal pure returns (uint8 v, bytes32 r, bytes32 s) { + function signatureSplit(bytes memory signatures, uint256 pos) + internal + pure + returns (uint8 v, bytes32 r, bytes32 s) + { assembly { let signaturePos := mul(0x41, pos) r := mload(add(signatures, add(signaturePos, 0x20))) diff --git a/script/universal/Simulation.sol b/script/universal/Simulation.sol index 77445b3..a8612bc 100644 --- a/script/universal/Simulation.sol +++ b/script/universal/Simulation.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.15; -import { console } from "forge-std/console.sol"; -import { Vm } from "forge-std/Vm.sol"; -import { IGnosisSafe } from "./IGnosisSafe.sol"; +import {console} from "forge-std/console.sol"; +import {Vm} from "forge-std/Vm.sol"; +import {IGnosisSafe} from "./IGnosisSafe.sol"; library Simulation { address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); @@ -51,29 +51,36 @@ library Simulation { return accesses; } - function overrideSafeThresholdOwnerAndNonce(IGnosisSafe _safe, address _owner, uint256 _nonce) public view returns (StateOverride memory) { - StateOverride memory state = StateOverride({ - contractAddress: address(_safe), - overrides: new StorageOverride[](0) - }); + function overrideSafeThresholdOwnerAndNonce(IGnosisSafe _safe, address _owner, uint256 _nonce) + public + view + returns (StateOverride memory) + { + StateOverride memory state = + StateOverride({contractAddress: address(_safe), overrides: new StorageOverride[](0)}); state = addThresholdOverride(_safe, state); state = addOwnerOverride(_safe, state, _owner); state = addNonceOverride(_safe, state, _nonce); return state; } - function addThresholdOverride(IGnosisSafe _safe, StateOverride memory _state) internal view returns (StateOverride memory) { + function addThresholdOverride(IGnosisSafe _safe, StateOverride memory _state) + internal + view + returns (StateOverride memory) + { // get the threshold and check if we need to override it if (_safe.getThreshold() == 1) return _state; // set the threshold (slot 4) to 1 - return addOverride(_state, StorageOverride({ - key: bytes32(uint256(0x4)), - value: bytes32(uint256(0x1)) - })); + return addOverride(_state, StorageOverride({key: bytes32(uint256(0x4)), value: bytes32(uint256(0x1))})); } - function addOwnerOverride(IGnosisSafe _safe, StateOverride memory _state, address _owner) internal view returns (StateOverride memory) { + function addOwnerOverride(IGnosisSafe _safe, StateOverride memory _state, address _owner) + internal + view + returns (StateOverride memory) + { // get the owners and check if _owner is an owner address[] memory owners = _safe.getOwners(); for (uint256 i; i < owners.length; i++) { @@ -81,49 +88,53 @@ library Simulation { } // set the ownerCount (slot 3) to 1 - _state = addOverride(_state, StorageOverride({ - key: bytes32(uint256(0x3)), - value: bytes32(uint256(0x1)) - })); + _state = addOverride(_state, StorageOverride({key: bytes32(uint256(0x3)), value: bytes32(uint256(0x1))})); // override the owner mapping (slot 2), which requires two key/value pairs: { 0x1: _owner, _owner: 0x1 } - _state = addOverride(_state, StorageOverride({ - key: bytes32(0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0), // keccak256(1 || 2) - value: bytes32(uint256(uint160(_owner))) - })); - return addOverride(_state, StorageOverride({ - key: keccak256(abi.encode(_owner, uint256(2))), - value: bytes32(uint256(0x1)) - })); + _state = addOverride( + _state, + StorageOverride({ + key: bytes32(0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0), // keccak256(1 || 2) + value: bytes32(uint256(uint160(_owner))) + }) + ); + return addOverride( + _state, StorageOverride({key: keccak256(abi.encode(_owner, uint256(2))), value: bytes32(uint256(0x1))}) + ); } - function addNonceOverride(IGnosisSafe _safe, StateOverride memory _state, uint256 _nonce) internal view returns (StateOverride memory) { + function addNonceOverride(IGnosisSafe _safe, StateOverride memory _state, uint256 _nonce) + internal + view + returns (StateOverride memory) + { // get the nonce and check if we need to override it if (_safe.nonce() == _nonce) return _state; // set the nonce (slot 5) to the desired value - return addOverride(_state, StorageOverride({ - key: bytes32(uint256(0x5)), - value: bytes32(_nonce) - })); + return addOverride(_state, StorageOverride({key: bytes32(uint256(0x5)), value: bytes32(_nonce)})); } - function addOverride(StateOverride memory _state, StorageOverride memory _override) internal pure returns (StateOverride memory) { + function addOverride(StateOverride memory _state, StorageOverride memory _override) + internal + pure + returns (StateOverride memory) + { StorageOverride[] memory overrides = new StorageOverride[](_state.overrides.length + 1); for (uint256 i; i < _state.overrides.length; i++) { overrides[i] = _state.overrides[i]; } overrides[_state.overrides.length] = _override; - return StateOverride({ - contractAddress: _state.contractAddress, - overrides: overrides - }); + return StateOverride({contractAddress: _state.contractAddress, overrides: overrides}); } function logSimulationLink(address _to, bytes memory _data, address _from) public view { logSimulationLink(_to, _data, _from, new StateOverride[](0)); } - function logSimulationLink(address _to, bytes memory _data, address _from, StateOverride[] memory _overrides) public view { + function logSimulationLink(address _to, bytes memory _data, address _from, StateOverride[] memory _overrides) + public + view + { string memory proj = vm.envOr("TENDERLY_PROJECT", string("TENDERLY_PROJECT")); string memory username = vm.envOr("TENDERLY_USERNAME", string("TENDERLY_USERNAME")); diff --git a/src/Challenger1of2.sol b/src/Challenger1of2.sol index fbbc6c9..64d5b5f 100644 --- a/src/Challenger1of2.sol +++ b/src/Challenger1of2.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { Address } from "@openzeppelin/contracts/utils/Address.sol"; +import {Address} from "@openzeppelin/contracts/utils/Address.sol"; /** * @title Challenger1of2 @@ -40,11 +40,7 @@ contract Challenger1of2 { * @param _data The data of the call being made. * @param _result The result of the call being made. */ - event ChallengerCallExecuted( - address indexed _caller, - bytes _data, - bytes _result - ); + event ChallengerCallExecuted(address indexed _caller, bytes _data, bytes _result); /*////////////////////////////////////////////////////////////// Constructor @@ -58,10 +54,7 @@ contract Challenger1of2 { constructor(address _opSigner, address _otherSigner, address _l2OutputOracleProxy) { require(_opSigner != address(0), "Challenger1of2: opSigner cannot be zero address"); require(_otherSigner != address(0), "Challenger1of2: otherSigner cannot be zero address"); - require( - _l2OutputOracleProxy.isContract(), - "Challenger1of2: l2OutputOracleProxy must be a contract" - ); + require(_l2OutputOracleProxy.isContract(), "Challenger1of2: l2OutputOracleProxy must be a contract"); OP_SIGNER = _opSigner; OTHER_SIGNER = _otherSigner; @@ -72,7 +65,7 @@ contract Challenger1of2 { External Functions //////////////////////////////////////////////////////////////*/ /** - * @dev Executes a call as the Challenger (must be called by + * @dev Executes a call as the Challenger (must be called by * Optimism or counter party signer). * @param _data Data for function call. */ @@ -82,12 +75,8 @@ contract Challenger1of2 { "Challenger1of2: must be an approved signer to execute" ); - bytes memory result = Address.functionCall( - L2_OUTPUT_ORACLE_PROXY, - _data, - "Challenger1of2: failed to execute" - ); + bytes memory result = Address.functionCall(L2_OUTPUT_ORACLE_PROXY, _data, "Challenger1of2: failed to execute"); emit ChallengerCallExecuted(msg.sender, _data, result); } -} \ No newline at end of file +} diff --git a/src/TestOwner.sol b/src/TestOwner.sol index 7be8eaa..3273023 100644 --- a/src/TestOwner.sol +++ b/src/TestOwner.sol @@ -5,7 +5,7 @@ contract TestOwner { uint256 public number; address public owner; - constructor (address _owner) { + constructor(address _owner) { require(_owner != address(0), "Owner cannot be zero address"); number = 0; owner = _owner; diff --git a/src/fee-vault-fixes/FeeVault.sol b/src/fee-vault-fixes/FeeVault.sol index 4ed717b..bf6b0ec 100644 --- a/src/fee-vault-fixes/FeeVault.sol +++ b/src/fee-vault-fixes/FeeVault.sol @@ -22,4 +22,4 @@ contract FeeVault { * @notice Allow the contract to receive ETH. */ receive() external payable {} -} \ No newline at end of file +} diff --git a/src/revenue-share/BalanceTracker.sol b/src/revenue-share/BalanceTracker.sol index 239bef9..df867b1 100644 --- a/src/revenue-share/BalanceTracker.sol +++ b/src/revenue-share/BalanceTracker.sol @@ -1,12 +1,11 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { Address } from "@openzeppelin/contracts/utils/Address.sol"; -import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; -import { ReentrancyGuardUpgradeable } - from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; +import {Address} from "@openzeppelin/contracts/utils/Address.sol"; +import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; +import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; -import { SafeCall } from "@eth-optimism-bedrock/src/libraries/SafeCall.sol"; +import {SafeCall} from "@eth-optimism-bedrock/src/libraries/SafeCall.sol"; /** * @title BalanceTracker @@ -20,8 +19,9 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { /** * @dev The maximum number of system addresses that can be funded. */ + uint256 public constant MAX_SYSTEM_ADDRESS_COUNT = 20; - + /*////////////////////////////////////////////////////////////// Immutables //////////////////////////////////////////////////////////////*/ @@ -29,7 +29,7 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { * @dev The address of the wallet receiving profits. */ address payable public immutable PROFIT_WALLET; - + /*////////////////////////////////////////////////////////////// VARIABLES //////////////////////////////////////////////////////////////*/ @@ -53,10 +53,7 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { * @param _balanceSent The amount of funds sent to the system address. */ event ProcessedFunds( - address indexed _systemAddress, - bool indexed _success, - uint256 _balanceNeeded, - uint256 _balanceSent + address indexed _systemAddress, bool indexed _success, uint256 _balanceNeeded, uint256 _balanceSent ); /** * @dev Emitted when the BalanceTracker attempts to send funds to the profit wallet. @@ -64,21 +61,14 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { * @param _success A boolean denoting the success or failure of fund send. * @param _balanceSent The amount of funds sent to the profit wallet. */ - event SentProfit( - address indexed _profitWallet, - bool indexed _success, - uint256 _balanceSent - ); + event SentProfit(address indexed _profitWallet, bool indexed _success, uint256 _balanceSent); /** * @dev Emitted when funds are received. * @param _sender The address sending funds. * @param _amount The amount of funds received from the sender. */ - event ReceivedFunds( - address indexed _sender, - uint256 _amount - ); - + event ReceivedFunds(address indexed _sender, uint256 _amount); + /*////////////////////////////////////////////////////////////// Constructor //////////////////////////////////////////////////////////////*/ @@ -86,11 +76,9 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { * @dev Constructor for the BalanceTracker contract that sets an immutable variable. * @param _profitWallet The address to send remaining ETH profits to. */ - constructor( - address payable _profitWallet - ) { + constructor(address payable _profitWallet) { require(_profitWallet != address(0), "BalanceTracker: PROFIT_WALLET cannot be address(0)"); - + PROFIT_WALLET = _profitWallet; _disableInitializers(); @@ -104,21 +92,26 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { * @param _systemAddresses The system addresses being funded. * @param _targetBalances The target balances for system addresses. */ - function initialize( - address payable[] memory _systemAddresses, - uint256[] memory _targetBalances - ) external reinitializer(2) { + function initialize(address payable[] memory _systemAddresses, uint256[] memory _targetBalances) + external + reinitializer(2) + { uint256 systemAddresesLength = _systemAddresses.length; - require(systemAddresesLength > 0, - "BalanceTracker: systemAddresses cannot have a length of zero"); - require(systemAddresesLength <= MAX_SYSTEM_ADDRESS_COUNT, - "BalanceTracker: systemAddresses cannot have a length greater than 20"); - require(systemAddresesLength == _targetBalances.length, - "BalanceTracker: systemAddresses and targetBalances length must be equal"); + require(systemAddresesLength > 0, "BalanceTracker: systemAddresses cannot have a length of zero"); + require( + systemAddresesLength <= MAX_SYSTEM_ADDRESS_COUNT, + "BalanceTracker: systemAddresses cannot have a length greater than 20" + ); + require( + systemAddresesLength == _targetBalances.length, + "BalanceTracker: systemAddresses and targetBalances length must be equal" + ); for (uint256 i; i < systemAddresesLength;) { require(_systemAddresses[i] != address(0), "BalanceTracker: systemAddresses cannot contain address(0)"); require(_targetBalances[i] > 0, "BalanceTracker: targetBalances cannot contain 0 target"); - unchecked { i++; } + unchecked { + i++; + } } systemAddresses = _systemAddresses; @@ -129,16 +122,17 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { /** * @dev Funds system addresses and sends remaining profits to the profit wallet. - * + * */ function processFees() external nonReentrant { uint256 systemAddresesLength = systemAddresses.length; - require(systemAddresesLength > 0, - "BalanceTracker: systemAddresses cannot have a length of zero"); + require(systemAddresesLength > 0, "BalanceTracker: systemAddresses cannot have a length of zero"); // Refills balances of systems addresses up to their target balances for (uint256 i; i < systemAddresesLength;) { refillBalanceIfNeeded(systemAddresses[i], targetBalances[i]); - unchecked { i++; } + unchecked { + i++; + } } // Send remaining profits to profit wallet @@ -164,12 +158,12 @@ contract BalanceTracker is ReentrancyGuardUpgradeable { * @param _targetBalance The target balance for the system address being funded. */ function refillBalanceIfNeeded(address _systemAddress, uint256 _targetBalance) internal { - uint256 systemAddressBalance = _systemAddress.balance; + uint256 systemAddressBalance = _systemAddress.balance; if (systemAddressBalance >= _targetBalance) { emit ProcessedFunds(_systemAddress, false, 0, 0); return; } - + uint256 valueNeeded = _targetBalance - systemAddressBalance; uint256 balanceTrackerBalance = address(this).balance; uint256 valueToSend = valueNeeded > balanceTrackerBalance ? balanceTrackerBalance : valueNeeded; diff --git a/src/revenue-share/FeeDisburser.sol b/src/revenue-share/FeeDisburser.sol index 616afc8..892f3b5 100644 --- a/src/revenue-share/FeeDisburser.sol +++ b/src/revenue-share/FeeDisburser.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; +import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; -import { L2StandardBridge } from "@eth-optimism-bedrock/src/L2/L2StandardBridge.sol"; -import { FeeVault } from "@eth-optimism-bedrock/src/universal/FeeVault.sol"; -import { Predeploys } from "@eth-optimism-bedrock/src/libraries/Predeploys.sol"; -import { SafeCall } from "@eth-optimism-bedrock/src/libraries/SafeCall.sol"; +import {L2StandardBridge} from "@eth-optimism-bedrock/src/L2/L2StandardBridge.sol"; +import {FeeVault} from "@eth-optimism-bedrock/src/universal/FeeVault.sol"; +import {Predeploys} from "@eth-optimism-bedrock/src/libraries/Predeploys.sol"; +import {SafeCall} from "@eth-optimism-bedrock/src/libraries/SafeCall.sol"; /** * @title FeeDisburser - * @dev Withdraws funds from system FeeVault contracts, shares revenue with Optimism, + * @dev Withdraws funds from system FeeVault contracts, shares revenue with Optimism, * and bridges the rest of funds to L1. */ contract FeeDisburser { @@ -51,7 +51,7 @@ contract FeeDisburser { * @dev The minimum amount of time in seconds that must pass between fee disbursals. */ uint256 public immutable FEE_DISBURSEMENT_INTERVAL; - + /*////////////////////////////////////////////////////////////// Variables //////////////////////////////////////////////////////////////*/ @@ -66,7 +66,6 @@ contract FeeDisburser { */ uint256 public netFeeRevenue; - /*////////////////////////////////////////////////////////////// Events //////////////////////////////////////////////////////////////*/ @@ -97,14 +96,12 @@ contract FeeDisburser { * @param _l1Wallet The L1 address which receives the remainder of the revenue. * @param _feeDisbursementInterval The minimum amount of time in seconds that must pass between fee disbursals. */ - constructor( - address payable _optimismWallet, - address _l1Wallet, - uint256 _feeDisbursementInterval - ) { + constructor(address payable _optimismWallet, address _l1Wallet, uint256 _feeDisbursementInterval) { require(_optimismWallet != address(0), "FeeDisburser: OptimismWallet cannot be address(0)"); require(_l1Wallet != address(0), "FeeDisburser: L1Wallet cannot be address(0)"); - require(_feeDisbursementInterval >= 24 hours, "FeeDisburser: FeeDisbursementInterval cannot be less than 24 hours"); + require( + _feeDisbursementInterval >= 24 hours, "FeeDisburser: FeeDisbursementInterval cannot be less than 24 hours" + ); OPTIMISM_WALLET = _optimismWallet; L1_WALLET = _l1Wallet; @@ -136,7 +133,7 @@ contract FeeDisburser { // Gross revenue is the sum of all fees uint256 feeBalance = address(this).balance; - + // Stop execution if no fees were collected if (feeBalance == 0) { emit NoFeesCollected(); @@ -161,23 +158,20 @@ contract FeeDisburser { ); // Send remaining funds to L1 wallet on L1 - L2StandardBridge(payable(Predeploys.L2_STANDARD_BRIDGE)).bridgeETHTo{ value: address(this).balance }( - L1_WALLET, - WITHDRAWAL_MIN_GAS, - bytes("") + L2StandardBridge(payable(Predeploys.L2_STANDARD_BRIDGE)).bridgeETHTo{value: address(this).balance}( + L1_WALLET, WITHDRAWAL_MIN_GAS, bytes("") ); emit FeesDisbursed(lastDisbursementTime, optimismRevenueShare, feeBalance); } /** - * @dev Receives ETH fees withdrawn from L2 FeeVaults. - * @dev Will revert if ETH is not sent from L2 FeeVaults. - */ - receive() external virtual payable { - if (msg.sender == Predeploys.SEQUENCER_FEE_WALLET || - msg.sender == Predeploys.BASE_FEE_VAULT) { + * @dev Receives ETH fees withdrawn from L2 FeeVaults. + * @dev Will revert if ETH is not sent from L2 FeeVaults. + */ + receive() external payable virtual { + if (msg.sender == Predeploys.SEQUENCER_FEE_WALLET || msg.sender == Predeploys.BASE_FEE_VAULT) { // Adds value received to net fee revenue if the sender is the sequencer or base FeeVault - netFeeRevenue += msg.value; + netFeeRevenue += msg.value; } else if (msg.sender != Predeploys.L1_FEE_VAULT) { revert("FeeDisburser: Only FeeVaults can send ETH to FeeDisburser"); } @@ -188,22 +182,22 @@ contract FeeDisburser { Internal Functions //////////////////////////////////////////////////////////////*/ /** - * @dev Withdraws fees from a FeeVault. - * @param _feeVault The address of the FeeVault to withdraw from. - * @dev Withdrawal will only occur if the given FeeVault's balance is greater than or equal to - the minimum withdrawal amount. - */ + * @dev Withdraws fees from a FeeVault. + * @param _feeVault The address of the FeeVault to withdraw from. + * @dev Withdrawal will only occur if the given FeeVault's balance is greater than or equal to + * the minimum withdrawal amount. + */ function feeVaultWithdrawal(address payable _feeVault) internal { require( - FeeVault(_feeVault).WITHDRAWAL_NETWORK() == FeeVault.WithdrawalNetwork.L2, + FeeVault(_feeVault).WITHDRAWAL_NETWORK() == FeeVault.WithdrawalNetwork.L2, "FeeDisburser: FeeVault must withdraw to L2" ); require( - FeeVault(_feeVault).RECIPIENT() == address(this), + FeeVault(_feeVault).RECIPIENT() == address(this), "FeeDisburser: FeeVault must withdraw to FeeDisburser contract" ); if (_feeVault.balance >= FeeVault(_feeVault).MIN_WITHDRAWAL_AMOUNT()) { FeeVault(_feeVault).withdraw(); } } -} \ No newline at end of file +} diff --git a/src/smart-escrow/SmartEscrow.sol b/src/smart-escrow/SmartEscrow.sol index 2bb9e23..7272210 100644 --- a/src/smart-escrow/SmartEscrow.sol +++ b/src/smart-escrow/SmartEscrow.sol @@ -86,7 +86,7 @@ contract SmartEscrow is AccessControlDefaultAdminRules { /// @param endTimestamp The provided end time of the contract. error StartTimeAfterEndTime(uint256 startTimestamp, uint256 endTimestamp); - /// @notice The error is thrown when the cliffStart timestamp is less than the start time. + /// @notice The error is thrown when the cliffStart timestamp is less than the start time. /// @param cliffStartTimestamp The provided start time of the contract. /// @param startTime The start time error CliffStartTimeInvalid(uint256 cliffStartTimestamp, uint256 startTime); @@ -142,8 +142,10 @@ contract SmartEscrow is AccessControlDefaultAdminRules { uint256 _initialTokens, uint256 _vestingEventTokens ) AccessControlDefaultAdminRules(5 days, _escrowOwner) { - if (_benefactor == address(0) || _beneficiary == address(0) || - _beneficiaryOwner == address(0) || _benefactorOwner == address(0)) { + if ( + _benefactor == address(0) || _beneficiary == address(0) || _beneficiaryOwner == address(0) + || _benefactorOwner == address(0) + ) { revert AddressIsZeroAddress(); } if (_start >= _end) revert StartTimeAfterEndTime(_start, _end); @@ -193,7 +195,7 @@ contract SmartEscrow is AccessControlDefaultAdminRules { /// @notice Allow benefactor owner to update benefactor address. /// @dev This method does not adjust the BENEFACTOR_OWNER_ROLE. Ensure to pair calling this - /// with a role change by DEFAULT_ADMIN if this is the desired outcome. + /// with a role change by DEFAULT_ADMIN if this is the desired outcome. /// @param _newBenefactor New benefactor address. /// @notice Emits a {BenefactorUpdated} event. function updateBenefactor(address _newBenefactor) external onlyRole(BENEFACTOR_OWNER_ROLE) { diff --git a/test/Challenger1of2.t.sol b/test/Challenger1of2.t.sol index 7df9d96..d005210 100644 --- a/test/Challenger1of2.t.sol +++ b/test/Challenger1of2.t.sol @@ -2,14 +2,14 @@ pragma solidity ^0.8.15; import {console} from "forge-std/console.sol"; -import { Test, StdUtils } from "forge-std/Test.sol"; +import {Test, StdUtils} from "forge-std/Test.sol"; -import { L2OutputOracle } from "@eth-optimism-bedrock/src/L1/L2OutputOracle.sol"; -import { ProxyAdmin } from "@eth-optimism-bedrock/src/universal/ProxyAdmin.sol"; -import { Proxy } from "@eth-optimism-bedrock/src/universal/Proxy.sol"; +import {L2OutputOracle} from "@eth-optimism-bedrock/src/L1/L2OutputOracle.sol"; +import {ProxyAdmin} from "@eth-optimism-bedrock/src/universal/ProxyAdmin.sol"; +import {Proxy} from "@eth-optimism-bedrock/src/universal/Proxy.sol"; -import { Address } from "@openzeppelin/contracts/utils/Address.sol"; -import { Challenger1of2 } from "src/Challenger1of2.sol"; +import {Address} from "@openzeppelin/contracts/utils/Address.sol"; +import {Challenger1of2} from "src/Challenger1of2.sol"; contract Challenger1of2Test is Test { address deployer = address(1000); @@ -22,7 +22,7 @@ contract Challenger1of2Test is Test { Proxy l2OutputOracleProxy; L2OutputOracle l2OutputOracle; Challenger1of2 challenger; - + bytes DELETE_OUTPUTS_SIGNATURE = abi.encodeWithSignature("deleteL2Outputs(uint256)", 1); bytes NONEXISTENT_SIGNATURE = abi.encodeWithSignature("something()"); bytes ZERO_OUTPUT = new bytes(0); @@ -30,26 +30,18 @@ contract Challenger1of2Test is Test { uint256 ZERO = 0; uint256 NONZERO_INTEGER = 100; - event ChallengerCallExecuted( - address indexed _caller, - bytes _data, - bytes _result - ); + event ChallengerCallExecuted(address indexed _caller, bytes _data, bytes _result); event OutputsDeleted( - address indexed _caller, - uint256 indexed prevNextOutputIndex, - uint256 indexed newNextOutputIndex + address indexed _caller, uint256 indexed prevNextOutputIndex, uint256 indexed newNextOutputIndex ); - + function setUp() public { vm.prank(deployer); proxyAdmin = new ProxyAdmin(deployer); l2OutputOracleProxy = new Proxy(address(proxyAdmin)); - challenger = new Challenger1of2( - optimismWallet, coinbaseWallet, address(l2OutputOracleProxy) - ); + challenger = new Challenger1of2(optimismWallet, coinbaseWallet, address(l2OutputOracleProxy)); // Initialize L2OutputOracle implementation. l2OutputOracle = new L2OutputOracle(); @@ -90,9 +82,7 @@ contract Challenger1of2Test is Test { } function test_constructor_success() external { - Challenger1of2 challenger2 = new Challenger1of2( - optimismWallet, coinbaseWallet, address(l2OutputOracleProxy) - ); + Challenger1of2 challenger2 = new Challenger1of2(optimismWallet, coinbaseWallet, address(l2OutputOracleProxy)); assertEq(challenger2.OP_SIGNER(), optimismWallet); assertEq(challenger2.OTHER_SIGNER(), coinbaseWallet); assertEq(challenger2.L2_OUTPUT_ORACLE_PROXY(), address(l2OutputOracleProxy)); @@ -112,9 +102,8 @@ contract Challenger1of2Test is Test { function test_unauthorized_challenger_fails() external { // Try to make a call from a second challenger contract (not the official one) - Challenger1of2 otherChallenger = new Challenger1of2( - optimismWallet, coinbaseWallet, address(l2OutputOracleProxy) - ); + Challenger1of2 otherChallenger = + new Challenger1of2(optimismWallet, coinbaseWallet, address(l2OutputOracleProxy)); vm.prank(optimismWallet); vm.expectRevert("L2OutputOracle: only the challenger address can delete outputs"); otherChallenger.execute(DELETE_OUTPUTS_SIGNATURE); @@ -135,12 +124,9 @@ contract Challenger1of2Test is Test { emit ChallengerCallExecuted(optimismWallet, DELETE_OUTPUTS_SIGNATURE, ZERO_OUTPUT); // We expect deleteOutputs to be called - vm.expectCall( - address(l2OutputOracleProxy), - abi.encodeWithSignature("deleteL2Outputs(uint256)", 1) - ); + vm.expectCall(address(l2OutputOracleProxy), abi.encodeWithSignature("deleteL2Outputs(uint256)", 1)); - // Make the call + // Make the call vm.prank(optimismWallet); challenger.execute(DELETE_OUTPUTS_SIGNATURE); @@ -163,12 +149,9 @@ contract Challenger1of2Test is Test { emit ChallengerCallExecuted(coinbaseWallet, DELETE_OUTPUTS_SIGNATURE, ZERO_OUTPUT); // We expect deleteOutputs to be called - vm.expectCall( - address(l2OutputOracleProxy), - abi.encodeWithSignature("deleteL2Outputs(uint256)", 1) - ); + vm.expectCall(address(l2OutputOracleProxy), abi.encodeWithSignature("deleteL2Outputs(uint256)", 1)); - // Make the call + // Make the call vm.prank(coinbaseWallet); challenger.execute(DELETE_OUTPUTS_SIGNATURE); @@ -181,12 +164,7 @@ contract Challenger1of2Test is Test { vm.warp(oracle.computeL2Timestamp(oracle.nextBlockNumber()) + 1); vm.startPrank(proposer); - oracle.proposeL2Output( - bytes32("something"), - oracle.nextBlockNumber(), - blockhash(10), - 10 - ); + oracle.proposeL2Output(bytes32("something"), oracle.nextBlockNumber(), blockhash(10), 10); vm.stopPrank(); } -} \ No newline at end of file +} diff --git a/test/CommonTest.t.sol b/test/CommonTest.t.sol index 0166944..21728ef 100644 --- a/test/CommonTest.t.sol +++ b/test/CommonTest.t.sol @@ -22,7 +22,7 @@ contract CommonTest is Test { string NON_EMPTY_STRING = "non-empty"; bytes NULL_BYTES = bytes(""); bytes NON_NULL_BYTES = abi.encodePacked(uint256(1)); - + function setUp() public virtual { // Give alice and bob some ETH vm.deal(alice, 1 << 16); diff --git a/test/MockERC20.t.sol b/test/MockERC20.t.sol index ef53a44..0425a20 100644 --- a/test/MockERC20.t.sol +++ b/test/MockERC20.t.sol @@ -3,13 +3,12 @@ pragma solidity 0.8.15; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; - contract MockERC20 is ERC20 { - /** + /** * See {ERC20-constructor}. */ constructor(string memory name, string memory symbol) ERC20(name, symbol) {} - + /** * @dev Mints `amount` tokens to the caller. * diff --git a/test/fee-vault-fixes/e2e/FeeVault.t.sol b/test/fee-vault-fixes/e2e/FeeVault.t.sol index 777222c..496b514 100644 --- a/test/fee-vault-fixes/e2e/FeeVault.t.sol +++ b/test/fee-vault-fixes/e2e/FeeVault.t.sol @@ -1,26 +1,26 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { CommonTest } from "test/CommonTest.t.sol"; -import { Predeploys } from "@eth-optimism-bedrock/src/libraries/Predeploys.sol"; -import { Proxy } from "@eth-optimism-bedrock/src/universal/Proxy.sol"; -import { L1FeeVault as L1FeeVault_Final, FeeVault as FeeVault_Final } from "@eth-optimism-bedrock/src/L2/L1FeeVault.sol"; -import { FeeVault as FeeVault_Fix } from "src/fee-vault-fixes/FeeVault.sol"; +import {CommonTest} from "test/CommonTest.t.sol"; +import {Predeploys} from "@eth-optimism-bedrock/src/libraries/Predeploys.sol"; +import {Proxy} from "@eth-optimism-bedrock/src/universal/Proxy.sol"; +import {L1FeeVault as L1FeeVault_Final, FeeVault as FeeVault_Final} from "@eth-optimism-bedrock/src/L2/L1FeeVault.sol"; +import {FeeVault as FeeVault_Fix} from "src/fee-vault-fixes/FeeVault.sol"; contract L1FeeVaultTest is CommonTest { - uint256 constant BASE_MAINNET_BLOCK = 2116000; - - string BASE_MAINNET_URL = vm.envString("BASE_MAINNET_URL"); - address recipient; - FeeVault_Final.WithdrawalNetwork withdrawalNetwork; - uint256 minimumWithdrawalAmount; - FeeVault_Fix l1FeeVaultFix; - L1FeeVault_Final l1FeeVaultFinal; - + uint256 constant BASE_MAINNET_BLOCK = 2116000; + + string BASE_MAINNET_URL = vm.envString("BASE_MAINNET_URL"); + address recipient; + FeeVault_Final.WithdrawalNetwork withdrawalNetwork; + uint256 minimumWithdrawalAmount; + FeeVault_Fix l1FeeVaultFix; + L1FeeVault_Final l1FeeVaultFinal; + function setUp() public virtual override { super.setUp(); vm.createSelectFork(BASE_MAINNET_URL, BASE_MAINNET_BLOCK); - + recipient = L1FeeVault_Final(payable(Predeploys.SEQUENCER_FEE_WALLET)).RECIPIENT(); minimumWithdrawalAmount = L1FeeVault_Final(payable(Predeploys.SEQUENCER_FEE_WALLET)).MIN_WITHDRAWAL_AMOUNT(); withdrawalNetwork = L1FeeVault_Final(payable(Predeploys.SEQUENCER_FEE_WALLET)).WITHDRAWAL_NETWORK(); @@ -30,10 +30,7 @@ contract L1FeeVaultTest is CommonTest { } function test_upgradeToFixImplementationThenFinalImplementation_succeeds() public { - bytes memory setTotalProcessedCall = abi.encodeCall( - FeeVault_Fix.setTotalProcessed, - ZERO_VALUE - ); + bytes memory setTotalProcessedCall = abi.encodeCall(FeeVault_Fix.setTotalProcessed, ZERO_VALUE); assertNotEq(L1FeeVault_Final(payable(Predeploys.L1_FEE_VAULT)).totalProcessed(), ZERO_VALUE); vm.prank(Predeploys.PROXY_ADMIN); @@ -41,7 +38,7 @@ contract L1FeeVaultTest is CommonTest { assertEq(FeeVault_Fix(payable(Predeploys.L1_FEE_VAULT)).totalProcessed(), ZERO_VALUE); vm.prank(Predeploys.PROXY_ADMIN); - Proxy(payable(Predeploys.L1_FEE_VAULT)).upgradeTo(address(l1FeeVaultFinal)); + Proxy(payable(Predeploys.L1_FEE_VAULT)).upgradeTo(address(l1FeeVaultFinal)); assertEq(L1FeeVault_Final(payable(Predeploys.L1_FEE_VAULT)).totalProcessed(), ZERO_VALUE); } -} \ No newline at end of file +} diff --git a/test/revenue-share/BalanceTracker.t.sol b/test/revenue-share/BalanceTracker.t.sol index 0a63db0..d96b9bb 100644 --- a/test/revenue-share/BalanceTracker.t.sol +++ b/test/revenue-share/BalanceTracker.t.sol @@ -1,16 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { CommonTest } from "test/CommonTest.t.sol"; -import { ReenterProcessFees } from "test/revenue-share/mocks/ReenterProcessFees.sol"; +import {CommonTest} from "test/CommonTest.t.sol"; +import {ReenterProcessFees} from "test/revenue-share/mocks/ReenterProcessFees.sol"; -import { Proxy } from "@eth-optimism-bedrock/src/universal/Proxy.sol"; -import { Address } from "@openzeppelin/contracts/utils/Address.sol"; +import {Proxy} from "@eth-optimism-bedrock/src/universal/Proxy.sol"; +import {Address} from "@openzeppelin/contracts/utils/Address.sol"; -import { BalanceTracker } from "src/revenue-share/BalanceTracker.sol"; +import {BalanceTracker} from "src/revenue-share/BalanceTracker.sol"; contract BalanceTrackerTest is CommonTest { - event ProcessedFunds(address indexed _systemAddress, bool indexed _success, uint256 _balanceNeeded, uint256 _balanceSent); + event ProcessedFunds( + address indexed _systemAddress, bool indexed _success, uint256 _balanceNeeded, uint256 _balanceSent + ); event SentProfit(address indexed _profitWallet, bool indexed _success, uint256 _balanceSent); event ReceivedFunds(address indexed _sender, uint256 _amount); @@ -20,7 +22,7 @@ contract BalanceTrackerTest is CommonTest { Proxy balanceTrackerProxy; BalanceTracker balanceTrackerImplementation; BalanceTracker balanceTracker; - + address payable l1StandardBridge = payable(address(1000)); address payable profitWallet = payable(address(1001)); address payable batchSender = payable(address(1002)); @@ -30,13 +32,11 @@ contract BalanceTrackerTest is CommonTest { address payable[] systemAddresses = [batchSender, l2OutputProposer]; uint256[] targetBalances = [batchSenderTargetBalance, l2OutputProposerTargetBalance]; address proxyAdminOwner = address(2048); - + function setUp() public override { super.setUp(); - balanceTrackerImplementation = new BalanceTracker( - profitWallet - ); + balanceTrackerImplementation = new BalanceTracker(profitWallet); balanceTrackerProxy = new Proxy(proxyAdminOwner); vm.prank(proxyAdminOwner); balanceTrackerProxy.upgradeTo(address(balanceTrackerImplementation)); @@ -44,19 +44,12 @@ contract BalanceTrackerTest is CommonTest { } function test_constructor_fail_profitWallet_zeroAddress() external { - vm.expectRevert( - "BalanceTracker: PROFIT_WALLET cannot be address(0)" - ); - new BalanceTracker( - payable(ZERO_ADDRESS) - ); + vm.expectRevert("BalanceTracker: PROFIT_WALLET cannot be address(0)"); + new BalanceTracker(payable(ZERO_ADDRESS)); } - function test_constructor_success() external { - balanceTracker = new BalanceTracker( - profitWallet - ); + balanceTracker = new BalanceTracker(profitWallet); assertEq(balanceTracker.MAX_SYSTEM_ADDRESS_COUNT(), MAX_SYSTEM_ADDRESS_COUNT); assertEq(balanceTracker.PROFIT_WALLET(), profitWallet); @@ -64,68 +57,42 @@ contract BalanceTrackerTest is CommonTest { function test_initializer_fail_systemAddresses_zeroLength() external { delete systemAddresses; - vm.expectRevert( - "BalanceTracker: systemAddresses cannot have a length of zero" - ); - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + vm.expectRevert("BalanceTracker: systemAddresses cannot have a length of zero"); + balanceTracker.initialize(systemAddresses, targetBalances); } function test_initializer_fail_systemAddresses_greaterThanMaxLength() external { - for (;systemAddresses.length <= balanceTracker.MAX_SYSTEM_ADDRESS_COUNT();) systemAddresses.push(payable(address(0))); - - vm.expectRevert( - "BalanceTracker: systemAddresses cannot have a length greater than 20" - ); - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + for (; systemAddresses.length <= balanceTracker.MAX_SYSTEM_ADDRESS_COUNT();) { + systemAddresses.push(payable(address(0))); + } + + vm.expectRevert("BalanceTracker: systemAddresses cannot have a length greater than 20"); + balanceTracker.initialize(systemAddresses, targetBalances); } - + function test_initializer_fail_systemAddresses_lengthNotEqualToTargetBalancesLength() external { systemAddresses.push(payable(address(0))); - - vm.expectRevert( - "BalanceTracker: systemAddresses and targetBalances length must be equal" - ); - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + + vm.expectRevert("BalanceTracker: systemAddresses and targetBalances length must be equal"); + balanceTracker.initialize(systemAddresses, targetBalances); } function test_initializer_fail_systemAddresses_containsZeroAddress() external { systemAddresses[1] = payable(address(0)); - - vm.expectRevert( - "BalanceTracker: systemAddresses cannot contain address(0)" - ); - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + + vm.expectRevert("BalanceTracker: systemAddresses cannot contain address(0)"); + balanceTracker.initialize(systemAddresses, targetBalances); } function test_initializer_fail_targetBalances_containsZero() external { targetBalances[1] = ZERO_VALUE; - - vm.expectRevert( - "BalanceTracker: targetBalances cannot contain 0 target" - ); - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + + vm.expectRevert("BalanceTracker: targetBalances cannot contain 0 target"); + balanceTracker.initialize(systemAddresses, targetBalances); } function test_initializer_success() external { - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + balanceTracker.initialize(systemAddresses, targetBalances); assertEq(balanceTracker.systemAddresses(0), systemAddresses[0]); assertEq(balanceTracker.systemAddresses(1), systemAddresses[1]); @@ -138,10 +105,7 @@ contract BalanceTrackerTest is CommonTest { uint256 expectedProfitWalletBalance = INITIAL_BALANCE_TRACKER_BALANCE - l2OutputProposerTargetBalance; address payable reentrancySystemAddress = payable(address(new ReenterProcessFees())); systemAddresses[0] = reentrancySystemAddress; - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + balanceTracker.initialize(systemAddresses, targetBalances); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit ProcessedFunds(reentrancySystemAddress, false, batchSenderTargetBalance, batchSenderTargetBalance); @@ -149,7 +113,7 @@ contract BalanceTrackerTest is CommonTest { emit ProcessedFunds(l2OutputProposer, true, l2OutputProposerTargetBalance, l2OutputProposerTargetBalance); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit SentProfit(profitWallet, true, expectedProfitWalletBalance); - + balanceTracker.processFees(); assertEq(address(balanceTracker).balance, ZERO_VALUE); @@ -159,25 +123,16 @@ contract BalanceTrackerTest is CommonTest { } function test_processFees_fail_whenNotInitialized() external { - vm.expectRevert( - "BalanceTracker: systemAddresses cannot have a length of zero" - ); - + vm.expectRevert("BalanceTracker: systemAddresses cannot have a length of zero"); + balanceTracker.processFees(); } function test_processFees_success_continuesWhenSystemAddressReverts() external { vm.deal(address(balanceTracker), INITIAL_BALANCE_TRACKER_BALANCE); uint256 expectedProfitWalletBalance = INITIAL_BALANCE_TRACKER_BALANCE - l2OutputProposerTargetBalance; - balanceTracker.initialize( - systemAddresses, - targetBalances - ); - vm.mockCallRevert( - batchSender, - bytes(""), - abi.encode("revert message") - ); + balanceTracker.initialize(systemAddresses, targetBalances); + vm.mockCallRevert(batchSender, bytes(""), abi.encode("revert message")); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit ProcessedFunds(batchSender, false, batchSenderTargetBalance, batchSenderTargetBalance); vm.expectEmit(true, true, true, true, address(balanceTracker)); @@ -195,11 +150,9 @@ contract BalanceTrackerTest is CommonTest { function test_processFees_success_fundsSystemAddresses() external { vm.deal(address(balanceTracker), INITIAL_BALANCE_TRACKER_BALANCE); - uint256 expectedProfitWalletBalance = INITIAL_BALANCE_TRACKER_BALANCE - batchSenderTargetBalance - l2OutputProposerTargetBalance; - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + uint256 expectedProfitWalletBalance = + INITIAL_BALANCE_TRACKER_BALANCE - batchSenderTargetBalance - l2OutputProposerTargetBalance; + balanceTracker.initialize(systemAddresses, targetBalances); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit ProcessedFunds(batchSender, true, batchSenderTargetBalance, batchSenderTargetBalance); vm.expectEmit(true, true, true, true, address(balanceTracker)); @@ -216,10 +169,7 @@ contract BalanceTrackerTest is CommonTest { } function test_processFees_success_noFunds() external { - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + balanceTracker.initialize(systemAddresses, targetBalances); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit ProcessedFunds(batchSender, true, batchSenderTargetBalance, ZERO_VALUE); vm.expectEmit(true, true, true, true, address(balanceTracker)); @@ -236,12 +186,9 @@ contract BalanceTrackerTest is CommonTest { } function test_processFees_success_partialFunds() external { - uint256 partialBalanceTrackerBalance = INITIAL_BALANCE_TRACKER_BALANCE/3; + uint256 partialBalanceTrackerBalance = INITIAL_BALANCE_TRACKER_BALANCE / 3; vm.deal(address(balanceTracker), partialBalanceTrackerBalance); - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + balanceTracker.initialize(systemAddresses, targetBalances); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit ProcessedFunds(batchSender, true, batchSenderTargetBalance, partialBalanceTrackerBalance); vm.expectEmit(true, true, true, true, address(balanceTracker)); @@ -261,10 +208,7 @@ contract BalanceTrackerTest is CommonTest { vm.deal(address(balanceTracker), INITIAL_BALANCE_TRACKER_BALANCE); vm.deal(batchSender, batchSenderTargetBalance); vm.deal(l2OutputProposer, l2OutputProposerTargetBalance); - balanceTracker.initialize( - systemAddresses, - targetBalances - ); + balanceTracker.initialize(systemAddresses, targetBalances); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit ProcessedFunds(batchSender, false, ZERO_VALUE, ZERO_VALUE); vm.expectEmit(true, true, true, true, address(balanceTracker)); @@ -273,7 +217,7 @@ contract BalanceTrackerTest is CommonTest { emit SentProfit(profitWallet, true, INITIAL_BALANCE_TRACKER_BALANCE); balanceTracker.processFees(); - + assertEq(address(balanceTracker).balance, ZERO_VALUE); assertEq(profitWallet.balance, INITIAL_BALANCE_TRACKER_BALANCE); assertEq(batchSender.balance, batchSenderTargetBalance); @@ -285,31 +229,28 @@ contract BalanceTrackerTest is CommonTest { delete systemAddresses; delete targetBalances; for (uint256 i = 0; i < balanceTracker.MAX_SYSTEM_ADDRESS_COUNT(); i++) { - systemAddresses.push(payable(address(uint160(i+100)))); + systemAddresses.push(payable(address(uint160(i + 100)))); targetBalances.push(l2OutputProposerTargetBalance); } - balanceTracker.initialize( - systemAddresses, - targetBalances - ); - + balanceTracker.initialize(systemAddresses, targetBalances); + balanceTracker.processFees(); assertEq(address(balanceTracker).balance, ZERO_VALUE); for (uint256 i = 0; i < balanceTracker.MAX_SYSTEM_ADDRESS_COUNT(); i++) { assertEq(systemAddresses[i].balance, l2OutputProposerTargetBalance); } - assertEq(profitWallet.balance, ZERO_VALUE); + assertEq(profitWallet.balance, ZERO_VALUE); } function test_receive_success() external { vm.deal(l1StandardBridge, NON_ZERO_VALUE); - + vm.prank(l1StandardBridge); vm.expectEmit(true, true, true, true, address(balanceTracker)); emit ReceivedFunds(l1StandardBridge, NON_ZERO_VALUE); - (bool success, ) = payable(address(balanceTracker)).call{ value: NON_ZERO_VALUE }(""); + (bool success,) = payable(address(balanceTracker)).call{value: NON_ZERO_VALUE}(""); assertTrue(success); assertEq(address(balanceTracker).balance, NON_ZERO_VALUE); diff --git a/test/revenue-share/FeeDisburser.t.sol b/test/revenue-share/FeeDisburser.t.sol index 26eefb4..f9ae0e1 100644 --- a/test/revenue-share/FeeDisburser.t.sol +++ b/test/revenue-share/FeeDisburser.t.sol @@ -1,21 +1,21 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { CommonTest } from "test/CommonTest.t.sol"; -import { FeeVaultRevert } from "test/revenue-share/mocks/FeeVaultRevert.sol"; -import { OptimismWalletRevert } from "test/revenue-share/mocks/OptimismWalletRevert.sol"; +import {CommonTest} from "test/CommonTest.t.sol"; +import {FeeVaultRevert} from "test/revenue-share/mocks/FeeVaultRevert.sol"; +import {OptimismWalletRevert} from "test/revenue-share/mocks/OptimismWalletRevert.sol"; -import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; -import { Address } from "@openzeppelin/contracts/utils/Address.sol"; -import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; +import {Address} from "@openzeppelin/contracts/utils/Address.sol"; +import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; -import { L2StandardBridge } from "@eth-optimism-bedrock/src/L2/L2StandardBridge.sol"; -import { SequencerFeeVault, FeeVault } from "@eth-optimism-bedrock/src/L2/SequencerFeeVault.sol"; -import { BaseFeeVault } from "@eth-optimism-bedrock/src/L2/BaseFeeVault.sol"; -import { L1FeeVault } from "@eth-optimism-bedrock/src/L2/L1FeeVault.sol"; -import { Predeploys } from "@eth-optimism-bedrock/src/libraries/Predeploys.sol"; +import {L2StandardBridge} from "@eth-optimism-bedrock/src/L2/L2StandardBridge.sol"; +import {SequencerFeeVault, FeeVault} from "@eth-optimism-bedrock/src/L2/SequencerFeeVault.sol"; +import {BaseFeeVault} from "@eth-optimism-bedrock/src/L2/BaseFeeVault.sol"; +import {L1FeeVault} from "@eth-optimism-bedrock/src/L2/L1FeeVault.sol"; +import {Predeploys} from "@eth-optimism-bedrock/src/libraries/Predeploys.sol"; -import { FeeDisburser } from "src/revenue-share/FeeDisburser.sol"; +import {FeeDisburser} from "src/revenue-share/FeeDisburser.sol"; contract FeeDisburserTest is CommonTest { event FeesDisbursed(uint256 _disbursementTime, uint256 _paidToOptimism, uint256 _totalFeesDisbursed); @@ -46,18 +46,23 @@ contract FeeDisburserTest is CommonTest { bytes MINIMUM_WITHDRAWAL_AMOUNT_SIGNATURE = abi.encodeWithSignature("MIN_WITHDRAWAL_AMOUNT()"); bytes WITHDRAW_SIGNATURE = abi.encodeWithSignature("withdraw()"); - + function setUp() public override { super.setUp(); vm.warp(feeDisbursementInterval); feeDisburserImplementation = new FeeDisburser(optimismWallet, l1Wallet, feeDisbursementInterval); - feeDisburserProxy = new TransparentUpgradeableProxy(address(feeDisburserImplementation), proxyAdminOwner, NULL_BYTES); + feeDisburserProxy = + new TransparentUpgradeableProxy(address(feeDisburserImplementation), proxyAdminOwner, NULL_BYTES); feeDisburser = FeeDisburser(payable(address(feeDisburserProxy))); - sequencerFeeVault = new SequencerFeeVault(payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); - baseFeeVault = new BaseFeeVault(payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); - l1FeeVault = new L1FeeVault(payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); + sequencerFeeVault = new SequencerFeeVault( + payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2 + ); + baseFeeVault = + new BaseFeeVault(payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); + l1FeeVault = + new L1FeeVault(payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); vm.etch(Predeploys.SEQUENCER_FEE_WALLET, address(sequencerFeeVault).code); vm.etch(Predeploys.BASE_FEE_VAULT, address(baseFeeVault).code); @@ -65,23 +70,17 @@ contract FeeDisburserTest is CommonTest { } function test_constructor_fail_optimismWallet_ZeroAddress() external { - vm.expectRevert( - "FeeDisburser: OptimismWallet cannot be address(0)" - ); + vm.expectRevert("FeeDisburser: OptimismWallet cannot be address(0)"); new FeeDisburser(payable(address(0)), l1Wallet, feeDisbursementInterval); } function test_constructor_fail_l1Wallet_ZeroAddress() external { - vm.expectRevert( - "FeeDisburser: L1Wallet cannot be address(0)" - ); + vm.expectRevert("FeeDisburser: L1Wallet cannot be address(0)"); new FeeDisburser(optimismWallet, payable(address(0)), feeDisbursementInterval); } function test_constructor_fail_feeDisbursementInterval_lessThan24Hours() external { - vm.expectRevert( - "FeeDisburser: FeeDisbursementInterval cannot be less than 24 hours" - ); + vm.expectRevert("FeeDisburser: FeeDisbursementInterval cannot be less than 24 hours"); new FeeDisburser(optimismWallet, l1Wallet, 24 hours - 1); } @@ -93,31 +92,25 @@ contract FeeDisburserTest is CommonTest { function test_disburseFees_fail_feeDisbursementInterval_Zero() external { // Setup so that the first disburse fees actually does a disbursal and doesn't return early - vm.deal(Predeploys.SEQUENCER_FEE_WALLET, minimumWithdrawalAmount*2); - vm.mockCall(Predeploys.L2_STANDARD_BRIDGE, - abi.encodeWithSignature( - "bridgeETHTo(address,uint256,bytes)", - l1Wallet, - WITHDRAWAL_MIN_GAS, - NULL_BYTES - ), + vm.deal(Predeploys.SEQUENCER_FEE_WALLET, minimumWithdrawalAmount * 2); + vm.mockCall( + Predeploys.L2_STANDARD_BRIDGE, + abi.encodeWithSignature("bridgeETHTo(address,uint256,bytes)", l1Wallet, WITHDRAWAL_MIN_GAS, NULL_BYTES), NULL_BYTES ); feeDisburser.disburseFees(); - vm.expectRevert( - "FeeDisburser: Disbursement interval not reached" - ); + vm.expectRevert("FeeDisburser: Disbursement interval not reached"); feeDisburser.disburseFees(); } function test_disburseFees_fail_feeVaultWithdrawalToL1() external { - sequencerFeeVault = new SequencerFeeVault(payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L1); + sequencerFeeVault = new SequencerFeeVault( + payable(address(feeDisburser)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L1 + ); vm.etch(Predeploys.SEQUENCER_FEE_WALLET, address(sequencerFeeVault).code); - vm.expectRevert( - "FeeDisburser: FeeVault must withdraw to L2" - ); + vm.expectRevert("FeeDisburser: FeeVault must withdraw to L2"); feeDisburser.disburseFees(); } @@ -125,30 +118,31 @@ contract FeeDisburserTest is CommonTest { sequencerFeeVault = new SequencerFeeVault(admin, minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); vm.etch(Predeploys.SEQUENCER_FEE_WALLET, address(sequencerFeeVault).code); - vm.expectRevert( - "FeeDisburser: FeeVault must withdraw to FeeDisburser contract" - ); + vm.expectRevert("FeeDisburser: FeeVault must withdraw to FeeDisburser contract"); feeDisburser.disburseFees(); } function test_disburseFees_fail_sendToOptimismFails() external { // Define a new feeDisburser for which the OP Wallet always reverts when receiving funds OptimismWalletRevert optimismWalletRevert = new OptimismWalletRevert(); - FeeDisburser feeDisburser2 = new FeeDisburser(payable(address(optimismWalletRevert)), l1Wallet, feeDisbursementInterval); + FeeDisburser feeDisburser2 = + new FeeDisburser(payable(address(optimismWalletRevert)), l1Wallet, feeDisbursementInterval); // Have the fee vaults point to the new fee disburser contract - sequencerFeeVault = new SequencerFeeVault(payable(address(feeDisburser2)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); + sequencerFeeVault = new SequencerFeeVault( + payable(address(feeDisburser2)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2 + ); vm.etch(Predeploys.SEQUENCER_FEE_WALLET, address(sequencerFeeVault).code); - baseFeeVault = new BaseFeeVault(payable(address(feeDisburser2)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); + baseFeeVault = + new BaseFeeVault(payable(address(feeDisburser2)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); vm.etch(Predeploys.BASE_FEE_VAULT, address(baseFeeVault).code); - l1FeeVault = new L1FeeVault(payable(address(feeDisburser2)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); + l1FeeVault = + new L1FeeVault(payable(address(feeDisburser2)), minimumWithdrawalAmount, FeeVault.WithdrawalNetwork.L2); vm.etch(Predeploys.L1_FEE_VAULT, address(l1FeeVault).code); vm.deal(Predeploys.SEQUENCER_FEE_WALLET, minimumWithdrawalAmount); - vm.expectRevert( - "FeeDisburser: Failed to send funds to Optimism" - ); + vm.expectRevert("FeeDisburser: Failed to send funds to Optimism"); feeDisburser2.disburseFees(); } @@ -156,18 +150,14 @@ contract FeeDisburserTest is CommonTest { FeeVaultRevert feeVaultRevert = new FeeVaultRevert(address(feeDisburser)); vm.etch(Predeploys.SEQUENCER_FEE_WALLET, address(feeVaultRevert).code); - vm.expectRevert( - "revert message" - ); + vm.expectRevert("revert message"); feeDisburser.disburseFees(); } function test_disburseFees_fail_withdrawalReversion() external { vm.mockCall(Predeploys.SEQUENCER_FEE_WALLET, MINIMUM_WITHDRAWAL_AMOUNT_SIGNATURE, abi.encode(ZERO_VALUE)); - vm.expectRevert( - "FeeVault: withdrawal amount must be greater than minimum withdrawal amount" - ); + vm.expectRevert("FeeVault: withdrawal amount must be greater than minimum withdrawal amount"); feeDisburser.disburseFees(); } @@ -191,16 +181,13 @@ contract FeeDisburserTest is CommonTest { uint256 netFeeVaultBalance = sequencerFeeVaultBalance + baseFeeVaultBalance; uint256 totalFeeVaultBalance = netFeeVaultBalance + l1FeeVaultBalance; - uint256 expectedOptimismWalletBalance = netFeeVaultBalance * optimismNetRevenueShareBasisPoints / BASIS_POINTS_SCALE; + uint256 expectedOptimismWalletBalance = + netFeeVaultBalance * optimismNetRevenueShareBasisPoints / BASIS_POINTS_SCALE; uint256 expectedBridgeWithdrawalBalance = totalFeeVaultBalance - expectedOptimismWalletBalance; - vm.mockCall(Predeploys.L2_STANDARD_BRIDGE, - abi.encodeWithSignature( - "bridgeETHTo(address,uint256,bytes)", - l1Wallet, - WITHDRAWAL_MIN_GAS, - NULL_BYTES - ), + vm.mockCall( + Predeploys.L2_STANDARD_BRIDGE, + abi.encodeWithSignature("bridgeETHTo(address,uint256,bytes)", l1Wallet, WITHDRAWAL_MIN_GAS, NULL_BYTES), NULL_BYTES ); @@ -224,16 +211,13 @@ contract FeeDisburserTest is CommonTest { vm.deal(Predeploys.L1_FEE_VAULT, l1FeeVaultBalance); uint256 totalFeeVaultBalance = sequencerFeeVaultBalance + baseFeeVaultBalance + l1FeeVaultBalance; - uint256 expectedOptimismWalletBalance = totalFeeVaultBalance * optimismGrossRevenueShareBasisPoints / BASIS_POINTS_SCALE; + uint256 expectedOptimismWalletBalance = + totalFeeVaultBalance * optimismGrossRevenueShareBasisPoints / BASIS_POINTS_SCALE; uint256 expectedBridgeWithdrawalBalance = totalFeeVaultBalance - expectedOptimismWalletBalance; - vm.mockCall(Predeploys.L2_STANDARD_BRIDGE, - abi.encodeWithSignature( - "bridgeETHTo(address,uint256,bytes)", - l1Wallet, - WITHDRAWAL_MIN_GAS, - NULL_BYTES - ), + vm.mockCall( + Predeploys.L2_STANDARD_BRIDGE, + abi.encodeWithSignature("bridgeETHTo(address,uint256,bytes)", l1Wallet, WITHDRAWAL_MIN_GAS, NULL_BYTES), NULL_BYTES ); @@ -252,17 +236,18 @@ contract FeeDisburserTest is CommonTest { uint256 baseFeeVaultBalance, uint256 l1FeeVaultBalance ) external { - vm.assume(sequencerFeeVaultBalance < 10**36); - vm.assume(baseFeeVaultBalance < 10**36); - vm.assume(l1FeeVaultBalance < 10**36); + vm.assume(sequencerFeeVaultBalance < 10 ** 36); + vm.assume(baseFeeVaultBalance < 10 ** 36); + vm.assume(l1FeeVaultBalance < 10 ** 36); vm.deal(Predeploys.SEQUENCER_FEE_WALLET, sequencerFeeVaultBalance); vm.deal(Predeploys.BASE_FEE_VAULT, baseFeeVaultBalance); vm.deal(Predeploys.L1_FEE_VAULT, l1FeeVaultBalance); uint256 netFeeVaultBalance = sequencerFeeVaultBalance >= minimumWithdrawalAmount ? sequencerFeeVaultBalance : 0; - netFeeVaultBalance += baseFeeVaultBalance >= minimumWithdrawalAmount ? baseFeeVaultBalance : 0; - uint256 totalFeeVaultBalance = netFeeVaultBalance + (l1FeeVaultBalance >= minimumWithdrawalAmount ? l1FeeVaultBalance : 0); + netFeeVaultBalance += baseFeeVaultBalance >= minimumWithdrawalAmount ? baseFeeVaultBalance : 0; + uint256 totalFeeVaultBalance = + netFeeVaultBalance + (l1FeeVaultBalance >= minimumWithdrawalAmount ? l1FeeVaultBalance : 0); uint256 optimismNetRevenue = netFeeVaultBalance * optimismNetRevenueShareBasisPoints / BASIS_POINTS_SCALE; uint256 optimismGrossRevenue = totalFeeVaultBalance * optimismGrossRevenueShareBasisPoints / BASIS_POINTS_SCALE; @@ -270,18 +255,14 @@ contract FeeDisburserTest is CommonTest { uint256 expectedBridgeWithdrawalBalance = totalFeeVaultBalance - expectedOptimismWalletBalance; - vm.mockCall(Predeploys.L2_STANDARD_BRIDGE, - abi.encodeWithSignature( - "bridgeETHTo(address,uint256,bytes)", - l1Wallet, - WITHDRAWAL_MIN_GAS, - NULL_BYTES - ), + vm.mockCall( + Predeploys.L2_STANDARD_BRIDGE, + abi.encodeWithSignature("bridgeETHTo(address,uint256,bytes)", l1Wallet, WITHDRAWAL_MIN_GAS, NULL_BYTES), NULL_BYTES ); vm.expectEmit(true, true, true, true, address(feeDisburser)); - if (totalFeeVaultBalance == 0) { + if (totalFeeVaultBalance == 0) { emit NoFeesCollected(); } else { emit FeesDisbursed(block.timestamp, expectedOptimismWalletBalance, totalFeeVaultBalance); @@ -297,13 +278,13 @@ contract FeeDisburserTest is CommonTest { function test_receive_fail_unauthorizedCaller() external { vm.expectRevert("FeeDisburser: Only FeeVaults can send ETH to FeeDisburser"); vm.prank(alice); - (bool success, ) = payable(address(feeDisburser)).call{ value: NON_ZERO_VALUE }(""); + (bool success,) = payable(address(feeDisburser)).call{value: NON_ZERO_VALUE}(""); assertTrue(success); } function test_receive_success() external { vm.deal(Predeploys.SEQUENCER_FEE_WALLET, NON_ZERO_VALUE); - + vm.prank(Predeploys.SEQUENCER_FEE_WALLET); Address.sendValue(payable(address(feeDisburser)), NON_ZERO_VALUE); @@ -317,7 +298,7 @@ contract FeeDisburserTest is CommonTest { vm.deal(Predeploys.L1_FEE_VAULT, NON_ZERO_VALUE); uint256 expectedNetFeeRevenue = NON_ZERO_VALUE * 2; uint256 expectedTotalValue = NON_ZERO_VALUE * 3; - + vm.prank(Predeploys.SEQUENCER_FEE_WALLET); Address.sendValue(payable(address(feeDisburser)), NON_ZERO_VALUE); diff --git a/test/revenue-share/mocks/FeeVaultRevert.sol b/test/revenue-share/mocks/FeeVaultRevert.sol index 745279f..0378e75 100644 --- a/test/revenue-share/mocks/FeeVaultRevert.sol +++ b/test/revenue-share/mocks/FeeVaultRevert.sol @@ -1,24 +1,24 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { FeeVault } from "@eth-optimism-bedrock/src/universal/FeeVault.sol"; +import {FeeVault} from "@eth-optimism-bedrock/src/universal/FeeVault.sol"; contract FeeVaultRevert { address internal immutable _RECIPIENT; - + constructor(address _recipient) { _RECIPIENT = _recipient; } - function RECIPIENT() external view returns(address) { + function RECIPIENT() external view returns (address) { return _RECIPIENT; } - - function WITHDRAWAL_NETWORK() external pure returns(FeeVault.WithdrawalNetwork) { + + function WITHDRAWAL_NETWORK() external pure returns (FeeVault.WithdrawalNetwork) { return FeeVault.WithdrawalNetwork.L2; } - function MIN_WITHDRAWAL_AMOUNT() external pure returns(uint256) { + function MIN_WITHDRAWAL_AMOUNT() external pure returns (uint256) { revert("revert message"); } } diff --git a/test/revenue-share/mocks/ReenterProcessFees.sol b/test/revenue-share/mocks/ReenterProcessFees.sol index 11b6d59..91b59c3 100644 --- a/test/revenue-share/mocks/ReenterProcessFees.sol +++ b/test/revenue-share/mocks/ReenterProcessFees.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { BalanceTracker } from "src/revenue-share/BalanceTracker.sol"; +import {BalanceTracker} from "src/revenue-share/BalanceTracker.sol"; contract ReenterProcessFees { receive() external payable { diff --git a/test/smart-escrow/BaseSmartEscrow.t.sol b/test/smart-escrow/BaseSmartEscrow.t.sol index ea6d364..79df8d1 100644 --- a/test/smart-escrow/BaseSmartEscrow.t.sol +++ b/test/smart-escrow/BaseSmartEscrow.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; -import { CommonTest } from "test/CommonTest.t.sol"; -import { MockERC20 } from "test/MockERC20.t.sol"; +import {CommonTest} from "test/CommonTest.t.sol"; +import {MockERC20} from "test/MockERC20.t.sol"; import "src/smart-escrow/SmartEscrow.sol"; contract BaseSmartEscrowTest is CommonTest { @@ -66,4 +66,4 @@ contract BaseSmartEscrowTest is CommonTest { ) ); } -} \ No newline at end of file +} diff --git a/test/smart-escrow/Constructor.t.sol b/test/smart-escrow/Constructor.t.sol index 33d3656..0c14d5d 100644 --- a/test/smart-escrow/Constructor.t.sol +++ b/test/smart-escrow/Constructor.t.sol @@ -185,7 +185,8 @@ contract ConstructorSmartEscrow is BaseSmartEscrowTest { } function test_constructor_vestingPeriodExceedsContractDuration_fails() public { - bytes4 vestingPeriodExceedsContractDurationSelector = bytes4(keccak256("VestingPeriodExceedsContractDuration(uint256)")); + bytes4 vestingPeriodExceedsContractDurationSelector = + bytes4(keccak256("VestingPeriodExceedsContractDuration(uint256)")); vm.expectRevert(abi.encodeWithSelector(vestingPeriodExceedsContractDurationSelector, end)); new SmartEscrow( benefactor, diff --git a/test/smart-escrow/Release.t.sol b/test/smart-escrow/Release.t.sol index 9b2c94c..c95c53f 100644 --- a/test/smart-escrow/Release.t.sol +++ b/test/smart-escrow/Release.t.sol @@ -85,4 +85,4 @@ contract ReleaseSmartEscrow is BaseSmartEscrowTest { assertEq(smartEscrow.released(), totalTokensToRelease); } } -} \ No newline at end of file +} diff --git a/test/smart-escrow/Resume.t.sol b/test/smart-escrow/Resume.t.sol index dda03c9..0dfbdea 100644 --- a/test/smart-escrow/Resume.t.sol +++ b/test/smart-escrow/Resume.t.sol @@ -38,7 +38,7 @@ contract ResumeSmartEscrow is BaseSmartEscrowTest { bytes4 selector = bytes4(keccak256("ContractIsTerminated()")); vm.expectRevert(abi.encodeWithSelector(selector)); smartEscrow.release(); - + // All tokens should remain in the contract assertEq(OP_TOKEN.balanceOf(address(smartEscrow)), totalTokensToRelease); } @@ -49,4 +49,4 @@ contract ResumeSmartEscrow is BaseSmartEscrowTest { vm.prank(escrowOwner); smartEscrow.resume(); } -} \ No newline at end of file +} diff --git a/test/smart-escrow/Terminate.t.sol b/test/smart-escrow/Terminate.t.sol index 9572318..9cd8eca 100644 --- a/test/smart-escrow/Terminate.t.sol +++ b/test/smart-escrow/Terminate.t.sol @@ -75,7 +75,7 @@ contract TerminateSmartEscrow is BaseSmartEscrowTest { vm.expectRevert(accessControlErrorMessage(alice, TERMINATOR_ROLE)); vm.prank(alice); smartEscrow.terminate(); - + // All tokens should remain in the contract assertEq(OP_TOKEN.balanceOf(address(smartEscrow)), totalTokensToRelease); } @@ -90,4 +90,4 @@ contract TerminateSmartEscrow is BaseSmartEscrowTest { vm.prank(benefactorOwner); smartEscrow.terminate(); } -} \ No newline at end of file +} diff --git a/test/smart-escrow/UpdateBenefactor.t.sol b/test/smart-escrow/UpdateBenefactor.t.sol index 36a99cf..2b489e6 100644 --- a/test/smart-escrow/UpdateBenefactor.t.sol +++ b/test/smart-escrow/UpdateBenefactor.t.sol @@ -31,7 +31,7 @@ contract UpdateBenefactorSmartEscrow is BaseSmartEscrowTest { vm.prank(benefactorOwner); smartEscrow.updateBenefactor(address(0)); - + // Benefactor remains the same assertEq(smartEscrow.benefactor(), benefactor); } @@ -40,7 +40,7 @@ contract UpdateBenefactorSmartEscrow is BaseSmartEscrowTest { vm.expectRevert(accessControlErrorMessage(escrowOwner, BENEFACTOR_OWNER_ROLE)); vm.prank(escrowOwner); smartEscrow.updateBenefactor(alice); - + // Benefactor owner remains the same assertEq(smartEscrow.benefactor(), benefactor); } @@ -57,4 +57,4 @@ contract UpdateBenefactorSmartEscrow is BaseSmartEscrowTest { // Benefactor owner remains the same assertEq(smartEscrow.benefactor(), benefactor); } -} \ No newline at end of file +} diff --git a/test/smart-escrow/UpdateBeneficiary.t.sol b/test/smart-escrow/UpdateBeneficiary.t.sol index 2f9e70c..fd5cc26 100644 --- a/test/smart-escrow/UpdateBeneficiary.t.sol +++ b/test/smart-escrow/UpdateBeneficiary.t.sol @@ -31,7 +31,7 @@ contract UpdateBeneficiarySmartEscrow is BaseSmartEscrowTest { vm.prank(beneficiaryOwner); smartEscrow.updateBeneficiary(address(0)); - + // Beneficiary remains the same assertEq(smartEscrow.beneficiary(), beneficiary); } @@ -40,7 +40,7 @@ contract UpdateBeneficiarySmartEscrow is BaseSmartEscrowTest { vm.expectRevert(accessControlErrorMessage(escrowOwner, BENEFICIARY_OWNER_ROLE)); vm.prank(escrowOwner); smartEscrow.updateBeneficiary(alice); - + // Beneficiary owner remains the same assertEq(smartEscrow.beneficiary(), beneficiary); } @@ -57,4 +57,4 @@ contract UpdateBeneficiarySmartEscrow is BaseSmartEscrowTest { // Beneficiary owner remains the same assertEq(smartEscrow.beneficiary(), beneficiary); } -} \ No newline at end of file +} diff --git a/test/smart-escrow/WithdrawUnvestedTokens.t.sol b/test/smart-escrow/WithdrawUnvestedTokens.t.sol index ba564c6..ab30fe7 100644 --- a/test/smart-escrow/WithdrawUnvestedTokens.t.sol +++ b/test/smart-escrow/WithdrawUnvestedTokens.t.sol @@ -33,7 +33,7 @@ contract WithdrawUnvestedTokensSmartEscrow is BaseSmartEscrowTest { vm.prank(escrowOwner); smartEscrow.withdrawUnvestedTokens(); - + // Tokens were released to benefactor on termination and to Alice on the additional withdraw assertEq(OP_TOKEN.balanceOf(benefactor), totalTokensToRelease); assertEq(OP_TOKEN.balanceOf(alice), totalTokensToRelease); @@ -48,7 +48,7 @@ contract WithdrawUnvestedTokensSmartEscrow is BaseSmartEscrowTest { vm.expectRevert(accessControlErrorMessage(beneficiaryOwner, DEFAULT_ADMIN_ROLE)); vm.prank(beneficiaryOwner); smartEscrow.withdrawUnvestedTokens(); - + // No tokens were released assertEq(OP_TOKEN.balanceOf(benefactor), 0); assertEq(OP_TOKEN.balanceOf(address(smartEscrow)), totalTokensToRelease); @@ -59,7 +59,7 @@ contract WithdrawUnvestedTokensSmartEscrow is BaseSmartEscrowTest { vm.expectRevert(abi.encodeWithSelector(notTerminatedSelector)); vm.prank(escrowOwner); smartEscrow.withdrawUnvestedTokens(); - + // No tokens were released assertEq(OP_TOKEN.balanceOf(address(smartEscrow)), totalTokensToRelease); } diff --git a/test/universal/MultisigBuilder.t.sol b/test/universal/MultisigBuilder.t.sol index 4618881..c5b8b86 100644 --- a/test/universal/MultisigBuilder.t.sol +++ b/test/universal/MultisigBuilder.t.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.15; import {Test} from "forge-std/Test.sol"; import {Vm} from "forge-std/Vm.sol"; -import { console } from "forge-std/console.sol"; +import {console} from "forge-std/console.sol"; import {IMulticall3} from "forge-std/interfaces/IMulticall3.sol"; import {Preinstalls} from "@eth-optimism-bedrock/src/libraries/Preinstalls.sol"; import {MultisigBuilder} from "../../script/universal/MultisigBuilder.sol"; @@ -17,7 +17,8 @@ contract MultisigBuilderTest is Test, MultisigBuilder { IGnosisSafe internal safe = IGnosisSafe(address(1001)); Counter internal counter = new Counter(address(safe)); - bytes internal dataToSign = hex"1901d4bb33110137810c444c1d9617abe97df097d587ecde64e6fcb38d7f49e1280c41dcff2c17a271265df60d1612a7387110475b6fc5178add5518196db5dba6bd"; + bytes internal dataToSign = + hex"1901d4bb33110137810c444c1d9617abe97df097d587ecde64e6fcb38d7f49e1280c41dcff2c17a271265df60d1612a7387110475b6fc5178add5518196db5dba6bd"; function setUp() public { vm.etch(address(safe), Preinstalls.getDeployedCode(Preinstalls.Safe_v130, block.chainid)); @@ -35,7 +36,7 @@ contract MultisigBuilderTest is Test, MultisigBuilder { require(counterValue == 1, "Counter value is not 1"); } - function _buildCalls() internal override view returns (IMulticall3.Call3[] memory) { + function _buildCalls() internal view override returns (IMulticall3.Call3[] memory) { IMulticall3.Call3[] memory calls = new IMulticall3.Call3[](1); calls[0] = IMulticall3.Call3({ @@ -47,7 +48,7 @@ contract MultisigBuilderTest is Test, MultisigBuilder { return calls; } - function _ownerSafe() internal override view returns (address) { + function _ownerSafe() internal view override returns (address) { return address(safe); } @@ -55,7 +56,7 @@ contract MultisigBuilderTest is Test, MultisigBuilder { vm.recordLogs(); sign(); Vm.Log[] memory logs = vm.getRecordedLogs(); - assertEq(keccak256(logs[logs.length-1].data), keccak256(abi.encode(dataToSign))); + assertEq(keccak256(logs[logs.length - 1].data), keccak256(abi.encode(dataToSign))); } function test_run() external { diff --git a/test/universal/NestedMultisigBuilder.t.sol b/test/universal/NestedMultisigBuilder.t.sol index f88cdf7..8131cc0 100644 --- a/test/universal/NestedMultisigBuilder.t.sol +++ b/test/universal/NestedMultisigBuilder.t.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.15; import {Test} from "forge-std/Test.sol"; import {Vm} from "forge-std/Vm.sol"; -import { console } from "forge-std/console.sol"; +import {console} from "forge-std/console.sol"; import {IMulticall3} from "forge-std/interfaces/IMulticall3.sol"; import {Preinstalls} from "@eth-optimism-bedrock/src/libraries/Preinstalls.sol"; import {NestedMultisigBuilder} from "../../script/universal/NestedMultisigBuilder.sol"; @@ -19,8 +19,10 @@ contract NestedMultisigBuilderTest is Test, NestedMultisigBuilder { IGnosisSafe internal safe3 = IGnosisSafe(address(1003)); Counter internal counter = new Counter(address(safe3)); - bytes internal dataToSign1 = hex"1901d4bb33110137810c444c1d9617abe97df097d587ecde64e6fcb38d7f49e1280c3afd48ea8b0056e1028951ba44695d612396f4a1c3851f4b8a262c53ee1f2503"; - bytes internal dataToSign2 = hex"190132640243d7aade8c72f3d90d2dbf359e9897feba5fce1453bc8d9e7ba10d17153afd48ea8b0056e1028951ba44695d612396f4a1c3851f4b8a262c53ee1f2503"; + bytes internal dataToSign1 = + hex"1901d4bb33110137810c444c1d9617abe97df097d587ecde64e6fcb38d7f49e1280c3afd48ea8b0056e1028951ba44695d612396f4a1c3851f4b8a262c53ee1f2503"; + bytes internal dataToSign2 = + hex"190132640243d7aade8c72f3d90d2dbf359e9897feba5fce1453bc8d9e7ba10d17153afd48ea8b0056e1028951ba44695d612396f4a1c3851f4b8a262c53ee1f2503"; function setUp() public { bytes memory safeCode = Preinstalls.getDeployedCode(Preinstalls.Safe_v130, block.chainid); @@ -49,7 +51,7 @@ contract NestedMultisigBuilderTest is Test, NestedMultisigBuilder { require(counterValue == 1, "Counter value is not 1"); } - function _buildCalls() internal override view returns (IMulticall3.Call3[] memory) { + function _buildCalls() internal view override returns (IMulticall3.Call3[] memory) { IMulticall3.Call3[] memory calls = new IMulticall3.Call3[](1); calls[0] = IMulticall3.Call3({ @@ -61,7 +63,7 @@ contract NestedMultisigBuilderTest is Test, NestedMultisigBuilder { return calls; } - function _ownerSafe() internal override view returns (address) { + function _ownerSafe() internal view override returns (address) { return address(safe3); } @@ -69,14 +71,14 @@ contract NestedMultisigBuilderTest is Test, NestedMultisigBuilder { vm.recordLogs(); sign(safe1); Vm.Log[] memory logs = vm.getRecordedLogs(); - assertEq(keccak256(logs[logs.length-1].data), keccak256(abi.encode(dataToSign1))); + assertEq(keccak256(logs[logs.length - 1].data), keccak256(abi.encode(dataToSign1))); } function test_sign_safe2() external { vm.recordLogs(); sign(safe2); Vm.Log[] memory logs = vm.getRecordedLogs(); - assertEq(keccak256(logs[logs.length-1].data), keccak256(abi.encode(dataToSign2))); + assertEq(keccak256(logs[logs.length - 1].data), keccak256(abi.encode(dataToSign2))); } function test_approve_safe1() external {