Skip to content

Commit

Permalink
support polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 committed Feb 28, 2024
1 parent e48e09a commit 12c5fac
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Oracle and Relayer based Message Protocol.
- Crab
- Darwinia
- Ethereum
- Polygon

### Testnet
- Arbitrum Sepolia
Expand Down
9 changes: 5 additions & 4 deletions bin/dao.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ set -x
# seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain sepolia
# seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain arbitrum-sepolia

seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain crab
seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain darwinia
seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain ethereum
seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain arbitrum
# seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain crab
# seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain darwinia
# seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain ethereum
# seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain arbitrum
seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain polygon
2 changes: 1 addition & 1 deletion bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eo pipefail
# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 1 --broadcast --verify --slow
# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 44 --broadcast --verify --slow
# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 46 --broadcast --verify --slow
forge script script/deploy/Deploy.s.sol:Deploy --chain-id 137 --verify
forge script script/deploy/Deploy.s.sol:Deploy --chain-id 137 --broadcast --verify
# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 42161 --broadcast --verify --slow --legacy --skip-simulation

# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 43 --broadcast --verify --skip-simulation
Expand Down
6 changes: 4 additions & 2 deletions bin/fee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ set -x
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 46 --chain-id 1 --broadcast --slow
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 42161 --chain-id 1 --broadcast --slow
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 1 --chain-id 46 --broadcast --slow
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)" 44 --chain-id 46 --broadcast --slow --legacy
# 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)" 44 --chain-id 46 --broadcast --slow --legacy
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 46 --chain-id 42161 --broadcast --slow --legacy --skip-simulation
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 1 --chain-id 42161 --broadcast --slow --legacy --skip-simulation
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 46 --chain-id 44 --broadcast --slow --legacy
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 46 --chain-id 137 --broadcast
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 137 --chain-id 46 --broadcast --slow --legacy

# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 11155111 --chain-id 43 --broadcast
# forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 421614 --chain-id 43 --broadcast
Expand Down
11 changes: 7 additions & 4 deletions bin/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ verify() {
# verify $oracle 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/OracleV2.sol:OracleV2
# verify $oracle 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/OracleV2.sol:OracleV2

verify $oracle 1 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
verify $oracle 44 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
verify $oracle 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
verify $oracle 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
# verify $oracle 1 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
# verify $oracle 44 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
# verify $oracle 46 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
verify $oracle 137 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
# verify $oracle 42161 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
# verify $oracle 421614 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
# verify $oracle 11155111 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle

# 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 137 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP
# verify $oracle 42161 $(cast abi-encode "constructor(address,address,address)" $deployer $ormp $subapi) src/eco/Oracle.sol:Oracle
# verify $oracle 46 $(cast abi-encode "constructor(address,address,address)" $deployer $ormp $subapi) 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 $relayer 137 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Relayer.sol:Relayer

# verify $ormp 1 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP
# verify $oracle 1 $(cast abi-encode "constructor(address,address,address)" $deployer $ormp $subapi) src/eco/Oracle.sol:Oracle
Expand Down
18 changes: 9 additions & 9 deletions script/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ contract Deploy is Common {
function run() public {
require(deployer == msg.sender, "!deployer");

deployProtocol();
deployOralce();
deployRelayer();
// deployProtocol();
// deployOralce();
// deployRelayer();

setConfig();

Expand Down Expand Up @@ -127,15 +127,15 @@ contract Deploy is Common {

/// @notice Set the protocol config
function setConfig() public broadcast {
// ORMP(ORMP_ADDR).setDefaultConfig(ORACLE_ADDR, RELAYER_ADDR);
// (address o, address r) = ORMP(ORMP_ADDR).defaultUC();
// require(o == ORACLE_ADDR, "!oracle");
// require(r == RELAYER_ADDR, "!relayer");
ORMP(ORMP_ADDR).setDefaultConfig(ORACLE_ADDR, RELAYER_ADDR);
(address o, address r) = ORMP(ORMP_ADDR).defaultUC();
require(o == ORACLE_ADDR, "!oracle");
require(r == RELAYER_ADDR, "!relayer");

III(ORACLE_ADDR).setApproved(oracleOperator, true);
require(III(ORACLE_ADDR).isApproved(oracleOperator), "!o-operator");
// III(RELAYER_ADDR).setApproved(relayerOperator, true);
// require(III(RELAYER_ADDR).isApproved(relayerOperator), "!r-operator");
III(RELAYER_ADDR).setApproved(relayerOperator, true);
require(III(RELAYER_ADDR).isApproved(relayerOperator), "!r-operator");

// III(ORMP_ADDR).changeSetter(dao);
// require(III(ORMP_ADDR).setter() == dao, "!dao");
Expand Down
2 changes: 1 addition & 1 deletion script/fee/Fee.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract Fee is Common {

function run(uint256 chainId) public {
require(dao == msg.sender, "!dao");
// setOracleFee(chainId);
setOracleFee(chainId);
setRelayerFee(chainId);
}

Expand Down
1 change: 1 addition & 0 deletions script/output/137/ORMP.v.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions script/output/137/ORMPOracle.v.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions script/output/137/Relayer.v.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"language":"Solidity","sources":{"src/eco/Relayer.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.\n\npragma solidity 0.8.17;\n\nimport \"../interfaces/IORMP.sol\";\n\ncontract Relayer {\n event Assigned(bytes32 indexed msgHash, uint256 fee, bytes params, bytes32[32] proof);\n event SetDstPrice(uint256 indexed chainId, uint128 dstPriceRatio, uint128 dstGasPriceInWei);\n event SetDstConfig(uint256 indexed chainId, uint64 baseGas, uint64 gasPerByte);\n event SetApproved(address operator, bool approve);\n\n struct DstPrice {\n uint128 dstPriceRatio; // dstPrice / localPrice * 10^10\n uint128 dstGasPriceInWei;\n }\n\n struct DstConfig {\n uint64 baseGas;\n uint64 gasPerByte;\n }\n\n address public immutable PROTOCOL;\n\n address public owner;\n // chainId => price\n mapping(uint256 => DstPrice) public priceOf;\n mapping(uint256 => DstConfig) public configOf;\n mapping(address => bool) public approvedOf;\n\n modifier onlyOwner() {\n require(msg.sender == owner, \"!owner\");\n _;\n }\n\n modifier onlyApproved() {\n require(isApproved(msg.sender), \"!approve\");\n _;\n }\n\n constructor(address dao, address ormp) {\n PROTOCOL = ormp;\n owner = dao;\n }\n\n receive() external payable {}\n\n function withdraw(address to, uint256 amount) external onlyApproved {\n (bool success,) = to.call{value: amount}(\"\");\n require(success, \"!withdraw\");\n }\n\n function isApproved(address operator) public view returns (bool) {\n return approvedOf[operator];\n }\n\n function changeOwner(address owner_) external onlyOwner {\n owner = owner_;\n }\n\n function setApproved(address operator, bool approve) public onlyOwner {\n approvedOf[operator] = approve;\n emit SetApproved(operator, approve);\n }\n\n function setDstPrice(uint256 chainId, uint128 dstPriceRatio, uint128 dstGasPriceInWei) external onlyApproved {\n priceOf[chainId] = DstPrice(dstPriceRatio, dstGasPriceInWei);\n emit SetDstPrice(chainId, dstPriceRatio, dstGasPriceInWei);\n }\n\n function setDstConfig(uint256 chainId, uint64 baseGas, uint64 gasPerByte) external onlyApproved {\n configOf[chainId] = DstConfig(baseGas, gasPerByte);\n emit SetDstConfig(chainId, baseGas, gasPerByte);\n }\n\n // extraGas = gasLimit\n function fee(\n uint256 toChainId,\n address, /*ua*/\n uint256 gasLimit,\n bytes calldata encoded,\n bytes calldata /*params*/\n ) public view returns (uint256) {\n uint256 size = encoded.length;\n uint256 extraGas = gasLimit;\n DstPrice memory p = priceOf[toChainId];\n DstConfig memory c = configOf[toChainId];\n\n require(c.baseGas != 0, \"!baseGas\");\n // remoteToken = dstGasPriceInWei * (baseGas + extraGas)\n uint256 remoteToken = p.dstGasPriceInWei * (c.baseGas + extraGas);\n // dstPriceRatio = dstPrice / localPrice * 10^10\n // sourceToken = RemoteToken * dstPriceRatio\n uint256 sourceToken = remoteToken * p.dstPriceRatio / (10 ** 10);\n uint256 payloadToken = c.gasPerByte * size * p.dstGasPriceInWei * p.dstPriceRatio / (10 ** 10);\n return sourceToken + payloadToken;\n }\n\n function assign(bytes32 msgHash, bytes calldata params) external payable {\n require(msg.sender == PROTOCOL, \"!ormp\");\n emit Assigned(msgHash, msg.value, params, IORMP(PROTOCOL).prove());\n }\n\n function relay(Message calldata message, bytes calldata proof) external onlyApproved {\n IORMP(PROTOCOL).recv(message, proof);\n }\n}\n"},"src/interfaces/IORMP.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.\n\npragma solidity 0.8.17;\n\nimport \"../Common.sol\";\n\ninterface IORMP {\n /// @dev Send a cross-chain message over the endpoint.\n /// @notice follow https://eips.ethereum.org/EIPS/eip-5750\n /// @param toChainId The Message destination chain id.\n /// @param to User application contract address which receive the message.\n /// @param gasLimit Gas limit for destination user application used.\n /// @param encoded The calldata which encoded by ABI Encoding.\n /// @param refund Return extra fee to refund address.\n /// @param params General extensibility for relayer to custom functionality.\n /// @return Return the hash of the message as message id.\n function send(\n uint256 toChainId,\n address to,\n uint256 gasLimit,\n bytes calldata encoded,\n address refund,\n bytes calldata params\n ) external payable returns (bytes32);\n\n /// @notice Get a quote in source native gas, for the amount that send() requires to pay for message delivery.\n /// @param toChainId The Message destination chain id.\n // @param ua User application contract address which send the message.\n /// @param gasLimit Gas limit for destination user application used.\n /// @param encoded The calldata which encoded by ABI Encoding.\n /// @param params General extensibility for relayer to custom functionality.\n function fee(uint256 toChainId, address ua, uint256 gasLimit, bytes calldata encoded, bytes calldata params)\n external\n view\n returns (uint256);\n\n /// @dev Recv verified message and dispatch to destination user application address.\n /// @param message Verified receive message info.\n /// @param proof Message proof of this message.\n /// @return dispatchResult Result of the message dispatch.\n function recv(Message calldata message, bytes calldata proof) external returns (bool dispatchResult);\n\n function prove() external view returns (bytes32[32] memory);\n\n /// @dev Fetch user application config.\n /// @notice If user application has not configured, then the default config is used.\n /// @param ua User application contract address.\n /// @return user application config.\n function getAppConfig(address ua) external view returns (UC memory);\n\n /// @notice Set user application config.\n /// @param oracle Oracle which user application choose.\n /// @param relayer Relayer which user application choose.\n function setAppConfig(address oracle, address relayer) external;\n\n function defaultUC() external view returns (UC memory);\n}\n"},"src/Common.sol":{"content":"// This file is part of Darwinia.\n// Copyright (C) 2018-2023 Darwinia Network\n// SPDX-License-Identifier: GPL-3.0\n//\n// Darwinia is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Darwinia is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.\n\npragma solidity 0.8.17;\n\n/// @dev The block of control information and data for comminicate\n/// between user applications. Messages are the exchange medium\n/// used by channels to send and receive data through cross-chain networks.\n/// A message is sent from a source chain to a destination chain.\n/// @param index The leaf index lives in channel's incremental mekle tree.\n/// @param fromChainId The message source chain id.\n/// @param from User application contract address which send the message.\n/// @param toChainId The message destination chain id.\n/// @param to User application contract address which receive the message.\n/// @param gasLimit Gas limit for destination UA used.\n/// @param encoded The calldata which encoded by ABI Encoding.\nstruct Message {\n address channel;\n uint256 index;\n uint256 fromChainId;\n address from;\n uint256 toChainId;\n address to;\n uint256 gasLimit;\n bytes encoded; /*(abi.encodePacked(SELECTOR, PARAMS))*/\n}\n\n/// @dev User application custom configuration.\n/// @param oracle Oracle contract address.\n/// @param relayer Relayer contract address.\nstruct UC {\n address oracle;\n address relayer;\n}\n\n/// @dev Hash of the message.\nfunction hash(Message memory message) pure returns (bytes32) {\n return keccak256(abi.encode(message));\n}\n"}},"settings":{"remappings":["forge-std/=lib/forge-std/src/","ds-test/=lib/forge-std/lib/ds-test/src/","create3-deploy/=lib/create3-deploy/"],"optimizer":{"enabled":true,"runs":999999},"metadata":{"useLiteralContent":false,"bytecodeHash":"ipfs"},"outputSelection":{"*":{"":["ast"],"*":["abi","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","metadata","storageLayout","devdoc","userdoc"]}},"evmVersion":"london","libraries":{}}}
6 changes: 6 additions & 0 deletions script/output/137/deploy.a-latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORACLE": "0x0000000003ebeF32D8f0ED406a5CA8805c80AFba",
"ORMP": "0x00000000001523057a05d6293C1e5171eE33eE0A",
"RELAYER": "0x0000000000808fE9bDCc1d180EfbF5C53552a6b1"
}

0 comments on commit 12c5fac

Please sign in to comment.