diff --git a/src/eco/Oracle.sol b/src/eco/Oracle.sol index f35af70..f1435f8 100644 --- a/src/eco/Oracle.sol +++ b/src/eco/Oracle.sol @@ -27,6 +27,7 @@ contract Oracle is Verifier { event SetApproved(address operator, bool approve); address public immutable PROTOCOL; + address public immutable SUBAPI; address public owner; // chainId => price @@ -45,7 +46,8 @@ contract Oracle is Verifier { _; } - constructor(address dao, address ormp) { + constructor(address dao, address ormp, address subapi) { + SUBAPI = subapi; PROTOCOL = ormp; owner = dao; } @@ -75,11 +77,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]; } @@ -90,7 +87,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); } } diff --git a/src/interfaces/IFeedOracle.sol b/src/interfaces/IFeedOracle.sol index b38fb15..5fa5851 100644 --- a/src/interfaces/IFeedOracle.sol +++ b/src/interfaces/IFeedOracle.sol @@ -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); } diff --git a/test/bench/ORMP.b.sol b/test/bench/ORMP.b.sol index 3247ab6..d16a7f9 100644 --- a/test/bench/ORMP.b.sol +++ b/test/bench/ORMP.b.sol @@ -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; } diff --git a/test/eco/Oracle.t.sol b/test/eco/Oracle.t.sol index 6a1bec7..e65bb27 100644 --- a/test/eco/Oracle.t.sol +++ b/test/eco/Oracle.t.sol @@ -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); } @@ -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)); } }