|
| 1 | +pragma solidity ^0.5.16; |
| 2 | +pragma experimental ABIEncoderV2; |
| 3 | + |
| 4 | +// Inheritance |
| 5 | +import "./Owned.sol"; |
| 6 | +import "./MixinSystemSettings.sol"; |
| 7 | + |
| 8 | +// Internal references |
| 9 | +import "./interfaces/IOwnerRelayOnOptimism.sol"; |
| 10 | +import "@eth-optimism/contracts/iOVM/bridge/messaging/iAbs_BaseCrossDomainMessenger.sol"; |
| 11 | + |
| 12 | +contract OwnerRelayOnEthereum is MixinSystemSettings, Owned { |
| 13 | + /* ========== ADDRESS RESOLVER CONFIGURATION ========== */ |
| 14 | + |
| 15 | + bytes32 private constant CONTRACT_EXT_MESSENGER = "ext:Messenger"; |
| 16 | + bytes32 private constant CONTRACT_OVM_OWNER_RELAY_ON_OPTIMISM = "ovm:OwnerRelayOnOptimism"; |
| 17 | + |
| 18 | + // ========== CONSTRUCTOR ========== |
| 19 | + |
| 20 | + constructor(address _owner, address _resolver) public Owned(_owner) MixinSystemSettings(_resolver) {} |
| 21 | + |
| 22 | + /* ========== INTERNALS ============ */ |
| 23 | + |
| 24 | + function _messenger() private view returns (iAbs_BaseCrossDomainMessenger) { |
| 25 | + return iAbs_BaseCrossDomainMessenger(requireAndGetAddress(CONTRACT_EXT_MESSENGER)); |
| 26 | + } |
| 27 | + |
| 28 | + function _ownerRelayOnOptimism() private view returns (address) { |
| 29 | + return requireAndGetAddress(CONTRACT_OVM_OWNER_RELAY_ON_OPTIMISM); |
| 30 | + } |
| 31 | + |
| 32 | + function _getCrossDomainGasLimit(uint32 crossDomainGasLimit) private view returns (uint32) { |
| 33 | + // Use specified crossDomainGasLimit if specified value is not zero. |
| 34 | + // otherwise use the default in SystemSettings. |
| 35 | + return |
| 36 | + crossDomainGasLimit != 0 |
| 37 | + ? crossDomainGasLimit |
| 38 | + : uint32(getCrossDomainMessageGasLimit(CrossDomainMessageGasLimits.Relay)); |
| 39 | + } |
| 40 | + |
| 41 | + /* ========== VIEWS ========== */ |
| 42 | + |
| 43 | + function resolverAddressesRequired() public view returns (bytes32[] memory addresses) { |
| 44 | + bytes32[] memory existingAddresses = MixinSystemSettings.resolverAddressesRequired(); |
| 45 | + bytes32[] memory newAddresses = new bytes32[](2); |
| 46 | + newAddresses[0] = CONTRACT_EXT_MESSENGER; |
| 47 | + newAddresses[1] = CONTRACT_OVM_OWNER_RELAY_ON_OPTIMISM; |
| 48 | + addresses = combineArrays(existingAddresses, newAddresses); |
| 49 | + } |
| 50 | + |
| 51 | + /* ========== RESTRICTED ========== */ |
| 52 | + |
| 53 | + function initiateRelay( |
| 54 | + address target, |
| 55 | + bytes calldata payload, |
| 56 | + uint32 crossDomainGasLimit // If zero, uses default value in SystemSettings |
| 57 | + ) external onlyOwner { |
| 58 | + IOwnerRelayOnOptimism ownerRelayOnOptimism; |
| 59 | + bytes memory messageData = abi.encodeWithSelector(ownerRelayOnOptimism.finalizeRelay.selector, target, payload); |
| 60 | + |
| 61 | + _messenger().sendMessage(_ownerRelayOnOptimism(), messageData, _getCrossDomainGasLimit(crossDomainGasLimit)); |
| 62 | + |
| 63 | + emit RelayInitiated(target, payload); |
| 64 | + } |
| 65 | + |
| 66 | + function initiateRelayBatch( |
| 67 | + address[] calldata targets, |
| 68 | + bytes[] calldata payloads, |
| 69 | + uint32 crossDomainGasLimit // If zero, uses default value in SystemSettings |
| 70 | + ) external onlyOwner { |
| 71 | + // First check that the length of the arguments match |
| 72 | + require(targets.length == payloads.length, "Argument length mismatch"); |
| 73 | + |
| 74 | + IOwnerRelayOnOptimism ownerRelayOnOptimism; |
| 75 | + bytes memory messageData = |
| 76 | + abi.encodeWithSelector(ownerRelayOnOptimism.finalizeRelayBatch.selector, targets, payloads); |
| 77 | + |
| 78 | + _messenger().sendMessage(_ownerRelayOnOptimism(), messageData, _getCrossDomainGasLimit(crossDomainGasLimit)); |
| 79 | + |
| 80 | + emit RelayBatchInitiated(targets, payloads); |
| 81 | + } |
| 82 | + |
| 83 | + /* ========== EVENTS ========== */ |
| 84 | + |
| 85 | + event RelayInitiated(address target, bytes payload); |
| 86 | + event RelayBatchInitiated(address[] targets, bytes[] payloads); |
| 87 | +} |
0 commit comments