Skip to content

Commit

Permalink
Update oracle (#87)
Browse files Browse the repository at this point in the history
* update oracle

* oracle clean

* deployed
  • Loading branch information
hujw77 authored Nov 21, 2023
1 parent 5785268 commit 01c0037
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 124 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Oracle and Relayer based Message Protocol.
| Contract | Canonical Cross-chain Deployment Address |
|------------|--------------------------------------------|
| ORMP | 0x00000000001523057a05d6293C1e5171eE33eE0A |
| Oracle | 0x0000000000ba03146Cc235509E802873D418a6bc |
| Oracle | 0x00000000046bc530804d66B6b64f7aF69B4E4E81 |
| Relayer | 0x0000000000808fE9bDCc1d180EfbF5C53552a6b1 |
| MsgDAO | 0x000000000879926D12aF396788C0785B7e581e53 |

Expand Down
10 changes: 0 additions & 10 deletions bin/config.sh

This file was deleted.

2 changes: 2 additions & 0 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ set -eo pipefail
# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 46 --broadcast --verify --slow
# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 42161 --broadcast --verify --slow --legacy

forge script script/deploy/Deploy.s.sol:Deploy --chain-id 44 --broadcast --verify
forge script script/deploy/Deploy.s.sol:Deploy --chain-id 421614 --broadcast --verify
forge script script/deploy/Deploy.s.sol:Deploy --chain-id 11155111 --broadcast --verify
8 changes: 6 additions & 2 deletions bin/fee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ set -x
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 42161 --chain-id 46 --broadcast --slow
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 46 --chain-id 42161 --broadcast --slow --legacy

forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 44 --broadcast
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 44 --chain-id 11155111 --broadcast
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 44 --broadcast
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 44 --broadcast
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 11155111 --broadcast
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 44 --chain-id 11155111 --broadcast
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 44 --chain-id 421614 --broadcast --skip-simulation --legacy
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 421614 --broadcast --skip-simulation --legacy
16 changes: 9 additions & 7 deletions bin/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ deployer=$(jq -r ".DEPLOYER" $c3)
ormp=$(jq -r ".ORMP_ADDR" $c3)
oracle=$(jq -r ".ORACLE_ADDR" $c3)
relayer=$(jq -r ".RELAYER_ADDR" $c3)
subapi=$(jq -r ".SUBAPI_ADDR" $c3)

verify() {
local addr; addr=$1
Expand All @@ -27,11 +28,12 @@ verify() {
$path > script/output/$chain_id/$name.v.json)
}

verify $ormp 42161 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP
verify $ormp 46 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP
# verify $ormp 42161 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP
# verify $ormp 46 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP
# verify $oracle 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Oracle.sol:Oracle
# verify $oracle 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Oracle.sol:Oracle
# verify $relayer 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Relayer.sol:Relayer
# verify $relayer 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Relayer.sol:Relayer

verify $oracle 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Oracle.sol:Oracle
verify $oracle 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Oracle.sol:Oracle

verify $relayer 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Relayer.sol:Relayer
verify $relayer 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Relayer.sol:Relayer
verify $oracle 44 $(cast abi-encode "constructor(address,address,address)" $deployer $ormp $subapi) src/eco/Oracle.sol:Oracle
verify $oracle 421614 $(cast abi-encode "constructor(address,address,address)" $deployer $ormp $subapi) src/eco/Oracle.sol:Oracle
55 changes: 0 additions & 55 deletions script/config/Oracle.s.sol

This file was deleted.

4 changes: 3 additions & 1 deletion script/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract Deploy is Common {
bytes32 ORACLE_SALT;
address RELAYER_ADDR;
bytes32 RELAYER_SALT;
address SUBAPI_ADDR;

string c3;
string config;
Expand Down Expand Up @@ -65,6 +66,7 @@ contract Deploy is Common {
ORACLE_SALT = c3.readBytes32(".ORACLE_SALT");
RELAYER_ADDR = c3.readAddress(".RELAYER_ADDR");
RELAYER_SALT = c3.readBytes32(".RELAYER_SALT");
SUBAPI_ADDR = c3.readAddress(".SUBAPI_ADDR");

deployer = config.readAddress(".DEPLOYER");
dao = config.readAddress(".DAO");
Expand Down Expand Up @@ -102,7 +104,7 @@ contract Deploy is Common {
/// @notice Deploy the Oracle
function deployOralce() public broadcast returns (address) {
bytes memory byteCode = type(Oracle).creationCode;
bytes memory initCode = bytes.concat(byteCode, abi.encode(deployer, ORMP_ADDR));
bytes memory initCode = bytes.concat(byteCode, abi.encode(deployer, ORMP_ADDR, SUBAPI_ADDR));
address oracle = _deploy3(ORACLE_SALT, initCode);
require(oracle == ORACLE_ADDR, "!oracle");

Expand Down
9 changes: 9 additions & 0 deletions script/input/11155111/fee.c.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"ORACLE": {
"44": {
"fee": 500000000000
},
"421614": {
"fee": 500000000000000
}
},
"RELAYER": {
Expand All @@ -10,6 +13,12 @@
"dstGasPriceInWei": 180000000000,
"baseGas": 200000,
"gasPerByte": 16
},
"421614": {
"dstPriceRatio": 10000000000,
"dstGasPriceInWei": 110000000,
"baseGas": 1,
"gasPerByte": 16
}
}
}
3 changes: 0 additions & 3 deletions script/input/11155111/oracle.c.json

This file was deleted.

9 changes: 9 additions & 0 deletions script/input/421614/fee.c.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"ORACLE": {
"44": {
"fee": 500000000000
},
"11155111": {
"fee": 500000000000000
}
},
"RELAYER": {
Expand All @@ -10,6 +13,12 @@
"dstGasPriceInWei": 180000000000,
"baseGas": 85000,
"gasPerByte": 16
},
"11155111": {
"dstPriceRatio": 10000000000,
"dstGasPriceInWei": 10000000000,
"baseGas": 1,
"gasPerByte": 16
}
}
}
3 changes: 0 additions & 3 deletions script/input/421614/oracle.c.json

This file was deleted.

4 changes: 0 additions & 4 deletions script/input/44/oracle.c.json

This file was deleted.

7 changes: 4 additions & 3 deletions script/input/c3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"MSGDAO": "0x000000000879926D12aF396788C0785B7e581e53",
"ORMP_ADDR": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"ORMP_SALT": "0x4d629bbdb40d29206f12a51aa81faf14553b218f96845742a89e02e55ecfcef6",
"ORACLE_ADDR": "0x0000000000ba03146Cc235509E802873D418a6bc",
"ORACLE_SALT": "0x7945140b3deab397a3ed2a87a716d03930e85e019b9bd2c21d28713feb5ab1de",
"ORACLE_ADDR": "0x00000000046bc530804d66B6b64f7aF69B4E4E81",
"ORACLE_SALT": "0x2f280285b23be5539441999307347b699ec014dc1acf3db714d3d133b1a3cfe5",
"RELAYER_ADDR": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1",
"RELAYER_SALT": "0x9d38bcb32422a45bc9c08605d4457bcd3dadddfee1573a352ace5f1defa45621"
"RELAYER_SALT": "0x9d38bcb32422a45bc9c08605d4457bcd3dadddfee1573a352ace5f1defa45621",
"SUBAPI_ADDR": "0x00000000096c285629Fe3EAb3dd042c27b9dcBa6"
}
2 changes: 1 addition & 1 deletion script/output/11155111/deploy.a-latest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORACLE": "0x0000000000ba03146Cc235509E802873D418a6bc",
"ORACLE": "0x00000000046bc530804d66B6b64f7aF69B4E4E81",
"ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1"
}
2 changes: 1 addition & 1 deletion script/output/421614/Oracle.v.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions script/output/421614/deploy.a-latest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORACLE": "0x0000000000ba03146Cc235509E802873D418a6bc",
"ORACLE": "0x00000000046bc530804d66B6b64f7aF69B4E4E81",
"ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1"
}
}
2 changes: 1 addition & 1 deletion script/output/44/Oracle.v.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions script/output/44/deploy.a-latest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORACLE": "0x0000000000ba03146Cc235509E802873D418a6bc",
"ORACLE": "0x00000000046bc530804d66B6b64f7aF69B4E4E81",
"ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1"
}
}
14 changes: 4 additions & 10 deletions src/eco/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ import "../interfaces/IFeedOracle.sol";
contract Oracle is Verifier {
event Assigned(bytes32 indexed msgHash, uint256 fee);
event SetFee(uint256 indexed chainId, uint256 fee);
event SetDapi(uint256 indexed chainId, address dapi);
event SetApproved(address operator, bool approve);

address public immutable PROTOCOL;
address public immutable SUBAPI;

address public owner;
// chainId => price
mapping(uint256 => uint256) public feeOf;
// chainId => dapi
mapping(uint256 => address) public dapiOf;
mapping(address => bool) public approvedOf;

modifier onlyOwner() {
Expand All @@ -45,7 +44,8 @@ contract Oracle is Verifier {
_;
}

constructor(address dao, address ormp) {
constructor(address dao, address ormp, address subapi) {
SUBAPI = subapi;
PROTOCOL = ormp;
owner = dao;
}
Expand Down Expand Up @@ -75,11 +75,6 @@ contract Oracle is Verifier {
emit SetFee(chainId, fee_);
}

function setDapi(uint256 chainId, address dapi) external onlyOwner {
dapiOf[chainId] = dapi;
emit SetDapi(chainId, dapi);
}

function fee(uint256 toChainId, address /*ua*/ ) public view returns (uint256) {
return feeOf[toChainId];
}
Expand All @@ -90,7 +85,6 @@ contract Oracle is Verifier {
}

function merkleRoot(uint256 chainId, uint256 /*blockNumber*/ ) public view override returns (bytes32) {
address dapi = dapiOf[chainId];
return IFeedOracle(dapi).messageRoot();
return IFeedOracle(SUBAPI).messageRootOf(chainId);
}
}
2 changes: 1 addition & 1 deletion src/interfaces/IFeedOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
pragma solidity 0.8.17;

interface IFeedOracle {
function messageRoot() external view returns (bytes32);
function messageRootOf(uint256 chainid) external view returns (bytes32);
}
2 changes: 1 addition & 1 deletion test/ORMP.m.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract ORMPMock is Verifier {
ORMP ormp;
address immutable caller;
address immutable self = address(this);
address constant oracle = 0x0000000000ba03146Cc235509E802873D418a6bc;
address constant oracle = 0x00000000046bc530804d66B6b64f7aF69B4E4E81;

struct P {
Message message;
Expand Down
6 changes: 3 additions & 3 deletions test/bench/ORMP.b.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract ORMPBenchmarkTest is Test {
using Chains for uint256;

ORMP ormp = ORMP(0x00000000001523057a05d6293C1e5171eE33eE0A);
Oracle oracle = Oracle(payable(0x0000000000ba03146Cc235509E802873D418a6bc));
Oracle oracle = Oracle(payable(0x00000000046bc530804d66B6b64f7aF69B4E4E81));
Relayer relayer = Relayer(payable(0x0000000000808fE9bDCc1d180EfbF5C53552a6b1));

bytes32 root;
Expand Down Expand Up @@ -74,15 +74,15 @@ contract ORMPBenchmarkTest is Test {
Verifier.Proof({blockNumber: block.number, messageIndex: message.index, messageProof: ormp.prove()});

vm.createSelectFork(message.toChainId.toChainName());
// TODO: setDefaltOracle
vm.store(address(oracle), bytes32(uint256(0)), bytes32(uint256(uint160(self))));
assertEq(oracle.owner(), self);
oracle.setDapi(message.fromChainId, self);

vm.prank(address(relayer));
ormp.recv(message, abi.encode(proof));
}

function messageRoot() public view returns (bytes32) {
function messageRootOf(uint256) external view returns (bytes32) {
return root;
}

Expand Down
15 changes: 2 additions & 13 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);
oracle = new Oracle(self, self, self);
oracle.setApproved(self, true);
}

Expand Down Expand Up @@ -66,28 +66,17 @@ contract OracleTest is Test {
oracle.setFee(1, 1);
}

function test_setDapi() public {
oracle.setDapi(1, address(1));
assertEq(oracle.dapiOf(1), address(1));
}

function testFail_setDapi() public {
vm.prank(address(1));
oracle.setDapi(1, address(1));
}

function test_assign() public {
oracle.setFee(1, 1);
oracle.assign{value: 1}(bytes32(0));
}

function test_merkleRoot() public {
oracle.setDapi(1, self);
bytes32 r = oracle.merkleRoot(1, 1);
assertEq(r, bytes32(uint256(1)));
}

function messageRoot() external pure returns (bytes32) {
function messageRootOf(uint256) external pure returns (bytes32) {
return bytes32(uint256(1));
}
}

0 comments on commit 01c0037

Please sign in to comment.