Skip to content

Commit

Permalink
update oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 committed Nov 20, 2023
1 parent 5785268 commit c2b18ac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
12 changes: 4 additions & 8 deletions src/eco/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down Expand Up @@ -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];
}
Expand All @@ -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);
}
}
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);
}
4 changes: 2 additions & 2 deletions test/bench/ORMP.b.sol
Original file line number Diff line number Diff line change
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 c2b18ac

Please sign in to comment.