Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for ormp v2 #151

Merged
merged 3 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ORMP
Oracle and Relayer based Message Protocol.

## Deployments
## V1 Deployments
### Canonical Cross-chain Deployment Addresses
| Contract | Canonical Cross-chain Deployment Address |
|------------|--------------------------------------------|
Expand Down
4 changes: 2 additions & 2 deletions script/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ScriptTools} from "create3-deploy/script/ScriptTools.sol";

import {ORMP} from "../../src/ORMP.sol";
import {Relayer} from "../../src/eco/Relayer.sol";
import {ORMPOracle} from "../../src/eco/ORMPOracle.sol";
import {Oracle} from "../../src/eco/Oracle.sol";

interface III {
function PROTOCOL() external view returns (address);
Expand Down Expand Up @@ -101,7 +101,7 @@ contract Deploy is Common {

/// @notice Deploy the Oracle
function deployOralce() public broadcast returns (address) {
bytes memory byteCode = type(ORMPOracle).creationCode;
bytes memory byteCode = type(Oracle).creationCode;
bytes memory initCode = bytes.concat(byteCode, abi.encode(deployer, ORMP_ADDR));
address oracle = _deploy3(ORACLE_SALT, initCode);
require(oracle == ORACLE_ADDR, "!oracle");
Expand Down
4 changes: 4 additions & 0 deletions src/ORMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ contract ORMP is ReentrancyGuard, Channel {

constructor(address dao) Channel(dao) {}

function version() public pure returns (string memory) {
return "2.0.0";
}

/// @dev Send a cross-chain message over the endpoint.
/// @notice follow https://eips.ethereum.org/EIPS/eip-5750
/// @param toChainId The Message destination chain id.
Expand Down
101 changes: 0 additions & 101 deletions src/eco/ORMPOracle.sol

This file was deleted.

51 changes: 36 additions & 15 deletions src/eco/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
pragma solidity 0.8.17;

import "../Verifier.sol";
import "../interfaces/IFeedOracle.sol";

contract Oracle is Verifier {
event SetFee(uint256 indexed chainId, uint256 fee);
event SetApproved(address operator, bool approve);
event Withdrawal(address indexed to, uint256 amt);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event ImportedMessageRoot(uint256 indexed chainId, uint256 indexed blockHeight, bytes32 messageRoot);

address public immutable PROTOCOL;
address public immutable SUBAPI;

address public owner;
// chainId => price
mapping(uint256 => uint256) public feeOf;
// chainId => dapi
// chainId => blockNumber => messageRoot
mapping(uint256 => mapping(uint256 => bytes32)) rootOf;
// operator => isApproved
mapping(address => bool) public approvedOf;

modifier onlyOwner() {
Expand All @@ -43,42 +46,60 @@ contract Oracle is Verifier {
_;
}

constructor(address dao, address ormp, address subapi) {
SUBAPI = subapi;
constructor(address dao, address ormp) {
PROTOCOL = ormp;
owner = dao;
}

receive() external payable {}

function withdraw(address to, uint256 amount) external onlyApproved {
(bool success,) = to.call{value: amount}("");
require(success, "!withdraw");
function version() public pure returns (string memory) {
return "2.0.0";
}

function isApproved(address operator) public view returns (bool) {
return approvedOf[operator];
/// @dev Only could be called by owner.
/// @notice Each channel has a corresponding oracle, and the message root should match with it.
/// @param chainId The source chain id.
/// @param blockNumber The source chain block number.
/// @param messageRoot The source chain message root corresponding to the channel.
function importMessageRoot(uint256 chainId, uint256 blockNumber, bytes32 messageRoot) external onlyOwner {
rootOf[chainId][blockNumber] = messageRoot;
emit ImportedMessageRoot(chainId, blockNumber, messageRoot);
}

function changeOwner(address owner_) external onlyOwner {
owner = owner_;
function changeOwner(address newOwner) external onlyOwner {
address oldOwner = owner;
owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}

function setApproved(address operator, bool approve) external onlyOwner {
approvedOf[operator] = approve;
emit SetApproved(operator, approve);
}

function isApproved(address operator) public view returns (bool) {
return approvedOf[operator];
}

function withdraw(address to, uint256 amount) external onlyApproved {
(bool success,) = to.call{value: amount}("");
require(success, "!withdraw");
emit Withdrawal(to, amount);
}

function setFee(uint256 chainId, uint256 fee_) external onlyApproved {
feeOf[chainId] = fee_;
emit SetFee(chainId, fee_);
}

function fee(uint256 toChainId, address /*ua*/ ) public view returns (uint256) {
return feeOf[toChainId];
uint256 f = feeOf[toChainId];
require(f != 0, "!fee");
return f;
}

function merkleRoot(uint256 chainId, uint256 /*blockNumber*/ ) public view override returns (bytes32) {
return IFeedOracle(SUBAPI).messageRootOf(chainId);
function merkleRoot(uint256 chainId, uint256 blockNumber) public view override returns (bytes32) {
return rootOf[chainId][blockNumber];
}
}
4 changes: 4 additions & 0 deletions src/eco/Relayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ contract Relayer {
owner = dao;
}

function version() public pure returns (string memory) {
return "2.0.0";
}

receive() external payable {}

function withdraw(address to, uint256 amount) external onlyApproved {
Expand Down
4 changes: 2 additions & 2 deletions test/bench/ORMP.b.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import "forge-std/Test.sol";
import {Chains} from "create3-deploy/script/Chains.sol";
import "../../src/Verifier.sol";
import "../../src/ORMP.sol";
import "../../src/eco/ORMPOracle.sol";
import "../../src/eco/Oracle.sol";
import "../../src/eco/Relayer.sol";

contract ORMPBenchmarkTest is Test {
using Chains for uint256;

ORMP ormp = ORMP(0x00000000001523057a05d6293C1e5171eE33eE0A);
ORMPOracle oracle = ORMPOracle(payable(0x0000000003ebeF32D8f0ED406a5CA8805c80AFba));
Oracle oracle = Oracle(payable(0x0000000003ebeF32D8f0ED406a5CA8805c80AFba));
Relayer relayer = Relayer(payable(0x0000000000808fE9bDCc1d180EfbF5C53552a6b1));

address immutable self = address(this);
Expand Down
4 changes: 2 additions & 2 deletions test/eco/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract OracleTest is Test {
receive() external payable {}

function setUp() public {
oracle = new Oracle(self, self, self);
oracle = new Oracle(self, self);
oracle.setApproved(self, true);
}

Expand Down Expand Up @@ -71,7 +71,7 @@ contract OracleTest is Test {
assertEq(r, bytes32(uint256(1)));
}

function messageRootOf(uint256) external pure returns (bytes32) {
function merkleRoot(uint256, uint256) external pure returns (bytes32) {
return bytes32(uint256(1));
}
}
Loading