Skip to content

Commit

Permalink
refactor: interfaces directories (hyperlane-xyz#157)
Browse files Browse the repository at this point in the history
* Rename Types -> BridgeMessage; Router -> BridgeRouter

* Add BridgeTokenInterface.sol

* Add MessageRecipientInterface.sol

* Add SortitionInterface.sol

* nit: rename Interface to I

* nit: rename Interface to I

Co-authored-by: Erin Hales <[email protected]>
  • Loading branch information
anna-carroll and ErinHales authored Mar 26, 2021
1 parent b969421 commit f44e60a
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 50 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

import {BridgeMessage} from "./Types.sol";
import {BridgeMessage} from "./BridgeMessage.sol";
import {TokenRegistry} from "./TokenRegistry.sol";
import {BridgeTokenI, BridgeToken} from "./BridgeToken.sol";
import {BridgeToken} from "./BridgeToken.sol";
import {BridgeTokenI} from "../interfaces/BridgeTokenI.sol";

import {TypeCasts} from "@celo-org/optics-sol/contracts/UsingOptics.sol";
import {
TypeCasts,
OpticsHandlerI
} from "@celo-org/optics-sol/contracts/UsingOptics.sol";
MessageRecipientI
} from "@celo-org/optics-sol/interfaces/MessageRecipientI.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";

contract BridgeRouter is OpticsHandlerI, TokenRegistry {
contract BridgeRouter is MessageRecipientI, TokenRegistry {
using TypedMemView for bytes;
using TypedMemView for bytes29;
using BridgeMessage for bytes29;
Expand Down
23 changes: 2 additions & 21 deletions solidity/optics-bridge/contracts/BridgeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,9 @@
pragma solidity >=0.6.11;

import {ERC20} from "./OZERC20.sol";

import {TypeCasts} from "@celo-org/optics-sol/contracts/UsingOptics.sol";

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

interface BridgeTokenI {
function name() external returns (string memory);

function symbol() external returns (string memory);

function decimals() external returns (uint8);

function burn(address from, uint256 amnt) external;

function mint(address to, uint256 amnt) external;

function setDetails(
bytes32 _name,
bytes32 _symbol,
uint8 _decimals
) external;
}
import {TypeCasts} from "@celo-org/optics-sol/contracts/UsingOptics.sol";
import {BridgeTokenI} from "../interfaces/BridgeTokenI.sol";

contract BridgeToken is BridgeTokenI, Ownable, ERC20 {
/**
Expand Down
5 changes: 3 additions & 2 deletions solidity/optics-bridge/contracts/TokenRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

import {BridgeMessage} from "./Types.sol";
import {BridgeTokenI, BridgeToken} from "./BridgeToken.sol";
import {BridgeMessage} from "./BridgeMessage.sol";
import {BridgeToken} from "./BridgeToken.sol";
import {BridgeTokenI} from "../interfaces/BridgeTokenI.sol";

import {
UsingOptics,
Expand Down
20 changes: 20 additions & 0 deletions solidity/optics-bridge/interfaces/BridgeTokenI.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

interface BridgeTokenI {
function name() external returns (string memory);

function symbol() external returns (string memory);

function decimals() external returns (uint8);

function burn(address from, uint256 amnt) external;

function mint(address to, uint256 amnt) external;

function setDetails(
bytes32 _name,
bytes32 _symbol,
uint8 _decimals
) external;
}
8 changes: 4 additions & 4 deletions solidity/optics-core/contracts/Home.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.6.11;
import "./Common.sol";
import "./Merkle.sol";
import "./Queue.sol";
import "./Sortition.sol";
import "../interfaces/SortitionI.sol";

/**
* @title Home
Expand All @@ -20,7 +20,7 @@ contract Home is MerkleTreeManager, QueueManager, Common {
mapping(uint32 => uint32) public sequences;

// TODO: removing sortition?
ISortition internal sortition;
SortitionI internal sortition;

/**
* @notice Event emitted when new message is enqueued
Expand All @@ -47,8 +47,8 @@ contract Home is MerkleTreeManager, QueueManager, Common {
QueueManager()
Common(_originDomain, address(0), bytes32(0))
{
sortition = ISortition(_sortition);
updater = ISortition(_sortition).current();
sortition = SortitionI(_sortition);
updater = SortitionI(_sortition).current();
}

/// @notice Sets contract state to FAILED and slashes updater
Expand Down
4 changes: 2 additions & 2 deletions solidity/optics-core/contracts/Replica.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@summa-tx/memview-sol/contracts/TypedMemView.sol";
import "./Common.sol";
import "./Merkle.sol";
import "./Queue.sol";
import {OpticsHandlerI} from "./UsingOptics.sol";
import {MessageRecipientI} from "../interfaces/MessageRecipientI.sol";

/**
* @title Replica
Expand Down Expand Up @@ -227,7 +227,7 @@ contract ProcessingReplica is Replica {
// transparently return.

try
OpticsHandlerI(recipient).handle{gas: PROCESS_GAS}(
MessageRecipientI(recipient).handle{gas: PROCESS_GAS}(
_m.origin(),
_m.sender(),
payload
Expand Down
8 changes: 0 additions & 8 deletions solidity/optics-core/contracts/UsingOptics.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import "./Home.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@summa-tx/memview-sol/contracts/TypedMemView.sol";

interface OpticsHandlerI {
function handle(
uint32 origin,
bytes32 sender,
bytes memory message
) external returns (bytes memory);
}

abstract contract UsingOptics is Ownable {
mapping(address => uint32) public replicas;
Home public home;
Expand Down
4 changes: 2 additions & 2 deletions solidity/optics-core/contracts/test/MockRecipient.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

import {OpticsHandlerI} from "../UsingOptics.sol";
import {MessageRecipientI} from "../../interfaces/MessageRecipientI.sol";

contract MockRecipient is OpticsHandlerI {
contract MockRecipient is MessageRecipientI {
// solhint-disable-next-line no-empty-blocks
constructor() {}

Expand Down
4 changes: 2 additions & 2 deletions solidity/optics-core/contracts/test/TestSortition.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

import {ISortition} from "../Sortition.sol";
import {SortitionI} from "../../interfaces/SortitionI.sol";

contract TestSortition is ISortition {
contract TestSortition is SortitionI {
address internal updater;
address internal home;

Expand Down
10 changes: 10 additions & 0 deletions solidity/optics-core/interfaces/MessageRecipientI.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

interface MessageRecipientI {
function handle(
uint32 origin,
bytes32 sender,
bytes memory message
) external returns (bytes memory);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.6.11;

interface ISortition {
interface SortitionI {
function current() external view returns (address);

function slash(address payable _reporter) external;
Expand Down
7 changes: 5 additions & 2 deletions solidity/optics-governance/contracts/GovernanceRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ pragma experimental ABIEncoderV2;
import {TypedMemView} from "@summa-tx/memview-sol/contracts/TypedMemView.sol";

import {
OpticsHandlerI,
UsingOptics,
TypeCasts
} from "@celo-org/optics-sol/contracts/UsingOptics.sol";

import {
MessageRecipientI
} from "@celo-org/optics-sol/interfaces/MessageRecipientI.sol";

import {GovernanceMessage} from "./GovernanceMessage.sol";

contract GovernanceRouter is OpticsHandlerI {
contract GovernanceRouter is MessageRecipientI {
using TypedMemView for bytes;
using TypedMemView for bytes29;
using GovernanceMessage for bytes29;
Expand Down

0 comments on commit f44e60a

Please sign in to comment.