Skip to content

Commit

Permalink
Put _calculateMoneyBoxUser in a library instead of an abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundedgar committed Nov 28, 2023
1 parent 0556a3a commit 1ebd8bc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
4 changes: 1 addition & 3 deletions contracts/AdjudicationFramework.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/*
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions contracts/L1GlobalForkRequester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions contracts/L2ForkArbitrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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}(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion test/MoneyBox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions test/testcontract/ExampleMoneyBoxUser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 1ebd8bc

Please sign in to comment.