From 1ebd8bc291cd2efbc98025ad0853e1e5663f50ae Mon Sep 17 00:00:00 2001 From: Edmund Edgar Date: Tue, 28 Nov 2023 10:16:57 +0000 Subject: [PATCH] Put _calculateMoneyBoxUser in a library instead of an abstract class --- contracts/AdjudicationFramework.sol | 4 +--- contracts/L1GlobalForkRequester.sol | 6 +++--- contracts/L2ForkArbitrator.sol | 6 +++--- .../MoneyBoxUser.sol => lib/CalculateMoneyBoxAddress.sol} | 4 ++-- test/MoneyBox.t.sol | 2 +- test/testcontract/ExampleMoneyBoxUser.sol | 6 +++--- 6 files changed, 13 insertions(+), 15 deletions(-) rename contracts/{mixin/MoneyBoxUser.sol => lib/CalculateMoneyBoxAddress.sol} (85%) diff --git a/contracts/AdjudicationFramework.sol b/contracts/AdjudicationFramework.sol index 19a76757..2d337023 100644 --- a/contracts/AdjudicationFramework.sol +++ b/contracts/AdjudicationFramework.sol @@ -12,8 +12,6 @@ import {IRealityETH} from "./interfaces/IRealityETH.sol"; import {IArbitrator} from "./interfaces/IArbitrator.sol"; import {IERC20} from "./interfaces/IERC20.sol"; -import {MoneyBoxUser} from "./mixin/MoneyBoxUser.sol"; - import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; /* @@ -25,7 +23,7 @@ To Reality.eth it looks like a normal arbitrator, implementing the Arbitrator in To the normal Arbitrator contracts that does its arbitration jobs, it looks like Reality.eth. */ -contract AdjudicationFramework is BalanceHolder, MoneyBoxUser { +contract AdjudicationFramework is BalanceHolder { uint256 public constant ARB_DISPUTE_TIMEOUT = 86400; uint256 public constant QUESTION_UNHANDLED_TIMEOUT = 86400; diff --git a/contracts/L1GlobalForkRequester.sol b/contracts/L1GlobalForkRequester.sol index 48ad1997..ed4e333b 100644 --- a/contracts/L1GlobalForkRequester.sol +++ b/contracts/L1GlobalForkRequester.sol @@ -20,9 +20,9 @@ import {ForkableBridge} from "./ForkableBridge.sol"; import {IBridgeMessageReceiver} from "@RealityETH/zkevm-contracts/contracts/interfaces/IBridgeMessageReceiver.sol"; import {MoneyBox} from "./mixin/MoneyBox.sol"; -import {MoneyBoxUser} from "./mixin/MoneyBoxUser.sol"; +import {CalculateMoneyBoxAddress} from "./lib/CalculateMoneyBoxAddress.sol"; -contract L1GlobalForkRequester is MoneyBoxUser { +contract L1GlobalForkRequester { struct FailedForkRequest { uint256 amount; @@ -42,7 +42,7 @@ contract L1GlobalForkRequester is MoneyBoxUser { bytes32 salt = keccak256(abi.encodePacked(beneficiary, requestId)); // Check the MoneyBox has funds - address moneyBox = _calculateMoneyBoxAddress(address(this), salt, token); + address moneyBox = CalculateMoneyBoxAddress._calculateMoneyBoxAddress(address(this), salt, token); // If for some reason we've already got part of a payment, include it. uint256 initialBalance = failedRequests[token][beneficiary][requestId].amount; diff --git a/contracts/L2ForkArbitrator.sol b/contracts/L2ForkArbitrator.sol index fe061432..ec3afbc7 100644 --- a/contracts/L2ForkArbitrator.sol +++ b/contracts/L2ForkArbitrator.sol @@ -8,7 +8,7 @@ pragma solidity ^0.8.20; import {L2ChainInfo} from "./L2ChainInfo.sol"; import {L1GlobalForkRequester} from "./L1GlobalForkRequester.sol"; import {IRealityETH} from "./interfaces/IRealityETH.sol"; -import {MoneyBoxUser} from "./mixin/MoneyBoxUser.sol"; +import {CalculateMoneyBoxAddress} from "./lib/CalculateMoneyBoxAddress.sol"; import {IPolygonZkEVMBridge} from "@RealityETH/zkevm-contracts/contracts/interfaces/IPolygonZkEVMBridge.sol"; import {IBridgeMessageReceiver} from "@RealityETH/zkevm-contracts/contracts/interfaces/IBridgeMessageReceiver.sol"; @@ -21,7 +21,7 @@ If there is already a dispute in progress (ie another fork has been requested bu // NB This doesn't implement IArbitrator because that requires slightly more functions than we need // TODO: Would be good to make a stripped-down IArbitrator that only has the essential functions -contract L2ForkArbitrator is MoneyBoxUser, IBridgeMessageReceiver { +contract L2ForkArbitrator is IBridgeMessageReceiver { bool public isForkInProgress; IRealityETH public realitio; @@ -130,7 +130,7 @@ contract L2ForkArbitrator is MoneyBoxUser, IBridgeMessageReceiver { // The L1GlobalForkRequester will deploy this as and when it's needed. // TODO: For now we assume only 1 request is in-flight at a time. If there might be more, differentiate them in the salt. bytes32 salt = keccak256(abi.encodePacked(address(this), question_id)); - address moneyBox = _calculateMoneyBoxAddress(address(l1GlobalForkRequester), salt, address(forkonomicToken)); + address moneyBox = CalculateMoneyBoxAddress._calculateMoneyBoxAddress(address(l1GlobalForkRequester), salt, address(forkonomicToken)); bytes memory permitData; bridge.bridgeAsset{value: forkFee}( diff --git a/contracts/mixin/MoneyBoxUser.sol b/contracts/lib/CalculateMoneyBoxAddress.sol similarity index 85% rename from contracts/mixin/MoneyBoxUser.sol rename to contracts/lib/CalculateMoneyBoxAddress.sol index bb1c194e..0dda935e 100644 --- a/contracts/mixin/MoneyBoxUser.sol +++ b/contracts/lib/CalculateMoneyBoxAddress.sol @@ -2,10 +2,10 @@ pragma solidity ^0.8.20; -import {MoneyBox} from "./MoneyBox.sol"; +import {MoneyBox} from "../mixin/MoneyBox.sol"; import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; -abstract contract MoneyBoxUser { +library CalculateMoneyBoxAddress { function _calculateMoneyBoxAddress(address _creator, bytes32 _salt, address _token) internal pure returns (address) { diff --git a/test/MoneyBox.t.sol b/test/MoneyBox.t.sol index 00808225..6e2f7434 100644 --- a/test/MoneyBox.t.sol +++ b/test/MoneyBox.t.sol @@ -4,7 +4,7 @@ import {Test} from "forge-std/Test.sol"; import {Vm} from "forge-std/Vm.sol"; import {MoneyBox} from "../contracts/mixin/MoneyBox.sol"; -import {MoneyBoxUser} from "../contracts/mixin/MoneyBoxUser.sol"; +import {CalculateMoneyBoxAddress} from "../contracts/lib/CalculateMoneyBoxAddress.sol"; import {ExampleToken} from "./testcontract/ExampleToken.sol"; import {ExampleMoneyBoxUser} from "./testcontract/ExampleMoneyBoxUser.sol"; diff --git a/test/testcontract/ExampleMoneyBoxUser.sol b/test/testcontract/ExampleMoneyBoxUser.sol index a0f2d3bc..75036e0b 100644 --- a/test/testcontract/ExampleMoneyBoxUser.sol +++ b/test/testcontract/ExampleMoneyBoxUser.sol @@ -2,12 +2,12 @@ pragma solidity ^0.8.20; -import {MoneyBoxUser} from "../../contracts/mixin/MoneyBoxUser.sol"; +import {CalculateMoneyBoxAddress} from "../../contracts/lib/CalculateMoneyBoxAddress.sol"; -contract ExampleMoneyBoxUser is MoneyBoxUser { +contract ExampleMoneyBoxUser { function calculateMoneyBoxAddress(address _creator, bytes32 _salt, address _token) external pure returns (address) { - return _calculateMoneyBoxAddress(_creator, _salt, _token); + return CalculateMoneyBoxAddress._calculateMoneyBoxAddress(_creator, _salt, _token); } }