Skip to content

Commit

Permalink
support blast (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 authored Mar 4, 2024
1 parent b16ee63 commit 7eb070d
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Oracle and Relayer based Message Protocol.
## Supported Chains
### Mainnet
- Arbitrum
- Blast
- Crab
- Darwinia
- Ethereum
Expand Down
6 changes: 4 additions & 2 deletions bin/dao.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ set -x
# 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
seth send -F $deployer $relayer "changeOwner(address)" $dao --chain polygon
seth send -F $deployer $ormp "changeSetter(address)" $dao --chain polygon
seth send -F $deployer $oracle "changeOwner(address)" $subapi_multisig --chain blast

# seth send -F $deployer $relayer "changeOwner(address)" $dao --chain polygon
# seth send -F $deployer $ormp "changeSetter(address)" $dao --chain polygon
3 changes: 2 additions & 1 deletion bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ 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 --broadcast --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 81457 --broadcast --verify --legacy --with-gas-price 1060000

# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 43 --broadcast --verify --skip-simulation
# forge script script/deploy/Deploy.s.sol:Deploy --chain-id 421614 --broadcast --verify --skip-simulation --slow
Expand Down
4 changes: 3 additions & 1 deletion bin/fee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ set -x
# 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)" 137 --chain-id 46 --broadcast --slow --legacy
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 81457 --chain-id 42161 --broadcast --legacy --skip-simulation
forge script script/fee/Fee.s.sol:Fee --sig "run(uint256)" 42161 --chain-id 81457 --broadcast --legacy --with-gas-price 1060000

# 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
9 changes: 6 additions & 3 deletions bin/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ verify() {
# 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 137 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/ORMPOracle.sol:ORMPOracle
verify $oracle 81457 $(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 $ormp 137 $(cast abi-encode "constructor(address)" $deployer) src/ORMP.sol:ORMP
verify $ormp 81457 $(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 $relayer 137 $(cast abi-encode "constructor(address,address)" $deployer $ormp) src/eco/Relayer.sol:Relayer
verify $relayer 81457 $(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
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ arbitrum = "https://arb1.arbitrum.io/rpc"
sepolia = "https://sepolia.infura.io/v3/${INFURA_KEY}"
ethereum = "https://mainnet.infura.io/v3/${INFURA_KEY}"
polygon = "https://polygon-mainnet.infura.io/v3/${INFURA_KEY}"
blast = "https://rpc.blast.io"

[etherscan]
polygon = { key = "${ETHERSCAN_POLYGON_KEY}" }
Expand Down
2 changes: 1 addition & 1 deletion lib/create3-deploy
6 changes: 3 additions & 3 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
4 changes: 2 additions & 2 deletions script/fee/Fee.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ contract Fee is Common {

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

function setOracleFee(uint256 chainId) public broadcast {
Expand Down
19 changes: 14 additions & 5 deletions script/input/42161/fee.c.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
{
"ORACLE": {
"1": {
"fee": 4000000000000000
},
"46": {
"fee": 20000000000000
},
"1": {
"fee": 4000000000000000
"81457": {
"fee": 200000000000000
}
},
"RELAYER": {
"1": {
"dstPriceRatio": 10000000000,
"dstGasPriceInWei": 50000000000,
"baseGas": 120000,
"gasPerByte": 16
},
"46": {
"dstPriceRatio": 12000,
"dstGasPriceInWei": 180000000000,
"baseGas": 200000,
"gasPerByte": 16
},
"1": {
"81457": {
"dstPriceRatio": 10000000000,
"dstGasPriceInWei": 50000000000,
"baseGas": 120000,
"dstGasPriceInWei": 1100000,
"baseGas": 200000,
"gasPerByte": 16
}
}
Expand Down
6 changes: 6 additions & 0 deletions script/input/81457/deploy.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"DAO": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"DEPLOYER": "0x0f14341A7f464320319025540E8Fe48Ad0fe5aec",
"ORACLE_OPERATOR": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05",
"RELAYER_OPERATOR": "0x912D7601569cBc2DF8A7f0aaE50BFd18e8C64d05"
}
15 changes: 15 additions & 0 deletions script/input/81457/fee.c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"ORACLE": {
"42161": {
"fee": 400000000000000
}
},
"RELAYER": {
"42161": {
"dstPriceRatio": 10000000000,
"dstGasPriceInWei": 110000000,
"baseGas": 1,
"gasPerByte": 16
}
}
}
1 change: 1 addition & 0 deletions script/output/81457/ORMP.v.json

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions script/output/81457/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/81457/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 7eb070d

Please sign in to comment.