From 78500db6516283690b908dce92ac7e2338fc49c4 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Wed, 19 Apr 2023 12:55:05 +0200 Subject: [PATCH 01/12] Update oz contracts and add skeleton for xchain message testing --- contracts/xchain/AbstractMessenger.sol | 18 ++++++++++ contracts/xchain/Application.sol | 2 ++ contracts/xchain/IApplication.sol | 1 + contracts/xchain/PolygonChild.sol | 1 + contracts/xchain/PolygonMessenger.sol | 2 ++ tests/test_xchain.py | 48 ++++++++++++++++++++++++++ 6 files changed, 72 insertions(+) create mode 100644 contracts/xchain/AbstractMessenger.sol create mode 100644 contracts/xchain/Application.sol create mode 100644 contracts/xchain/IApplication.sol create mode 100644 contracts/xchain/PolygonChild.sol create mode 100644 contracts/xchain/PolygonMessenger.sol create mode 100644 tests/test_xchain.py diff --git a/contracts/xchain/AbstractMessenger.sol b/contracts/xchain/AbstractMessenger.sol new file mode 100644 index 00000000..afa13144 --- /dev/null +++ b/contracts/xchain/AbstractMessenger.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.4; + +import "@openzeppelin/contracts/crosschain/CrossChainEnabled.sol"; +import "./IApplication.sol"; + +// Abstract contract. For each xchain connection we'll have a separate contract that inherits from this one. +// It will implement the isAuthorized function and read from the application contract. +abstract contract AbstractMessenger is CrossChainEnabled { + constructor() {} + + function isAuthorized(address operatorAddress) public view returns(bool) { + return true; + } + + function update() public { + } +} \ No newline at end of file diff --git a/contracts/xchain/Application.sol b/contracts/xchain/Application.sol new file mode 100644 index 00000000..4f999ae0 --- /dev/null +++ b/contracts/xchain/Application.sol @@ -0,0 +1,2 @@ +// Application contract. In production this would be a CBD contract, here we'll just have +// a simple contract that maps some test address to true/false. \ No newline at end of file diff --git a/contracts/xchain/IApplication.sol b/contracts/xchain/IApplication.sol new file mode 100644 index 00000000..9cda0946 --- /dev/null +++ b/contracts/xchain/IApplication.sol @@ -0,0 +1 @@ +// Interface for the application contract \ No newline at end of file diff --git a/contracts/xchain/PolygonChild.sol b/contracts/xchain/PolygonChild.sol new file mode 100644 index 00000000..1c4d9b6c --- /dev/null +++ b/contracts/xchain/PolygonChild.sol @@ -0,0 +1 @@ +// Will receive messages from PolygonMessenger.sol \ No newline at end of file diff --git a/contracts/xchain/PolygonMessenger.sol b/contracts/xchain/PolygonMessenger.sol new file mode 100644 index 00000000..cdcc86f2 --- /dev/null +++ b/contracts/xchain/PolygonMessenger.sol @@ -0,0 +1,2 @@ +// Inherits from AbstractMessenger.sol +// Will be deployed to mainnet \ No newline at end of file diff --git a/tests/test_xchain.py b/tests/test_xchain.py new file mode 100644 index 00000000..07f7e436 --- /dev/null +++ b/tests/test_xchain.py @@ -0,0 +1,48 @@ +import pytest +from brownie import EthCrossChainMessenger, PolygonCrossChainMessenger, accounts + + +@pytest.fixture(scope="module") +def eth_messenger(): + chain_id = 1 # Ethereum Mainnet + root_chain_manager = ( + "0xA0c68C638235ee32657e8f720a23ceC1bFc77C77" # Address of the RootChainManager on Ethereum + ) + messenger = EthCrossChainMessenger.deploy(root_chain_manager, chain_id, {"from": accounts[0]}) + messenger.addMessageSenderRole(accounts[0], {"from": accounts[0]}) + return messenger + + +@pytest.fixture(scope="module") +def polygon_messenger(): + chain_id = 137 # Polygon Mainnet + root_chain_manager = ( + "0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74" # Address of the RootChainManager on Polygon + ) + messenger = PolygonCrossChainMessenger.deploy( + root_chain_manager, chain_id, {"from": accounts[0]} + ) + messenger.addMessageSenderRole(accounts[0], {"from": accounts[0]}) + return messenger + + +def test_cross_chain_messaging(eth_messenger, polygon_messenger): + # Send a message from the Ethereum contract to the Polygon contract + message = "Hello from Ethereum" + polygon_contract_address = "0x123abc..." # Address of the recipient contract on Polygon + eth_messenger.sendMessageToPolygon( + polygon_contract_address, message.encode("utf-8"), {"from": accounts[0]} + ) + + # Verify that the message was received on the Polygon contract + assert polygon_messenger.messageReceived() == message + + # Send a message from the Polygon contract to the Ethereum contract + message = "Hello from Polygon" + eth_contract_address = "0x456def..." # Address of the recipient contract on Ethereum + polygon_messenger.sendMessageToEth( + eth_contract_address, message.encode("utf-8"), {"from": accounts[0]} + ) + + # Verify that the message was received on the Ethereum contract + assert eth_messenger.messageReceived() == message From 3db5f82b4ad9f7dcf0cc24f32793395d81aef705 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Thu, 20 Apr 2023 14:24:28 +0200 Subject: [PATCH 02/12] Add basic root and child polygon contracts --- contracts/xchain/PolygonChild.sol | 30 ++++++++++++++++++++++++++- contracts/xchain/PolygonMessenger.sol | 2 -- contracts/xchain/PolygonRoot.sol | 19 +++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) delete mode 100644 contracts/xchain/PolygonMessenger.sol create mode 100644 contracts/xchain/PolygonRoot.sol diff --git a/contracts/xchain/PolygonChild.sol b/contracts/xchain/PolygonChild.sol index 1c4d9b6c..512b089f 100644 --- a/contracts/xchain/PolygonChild.sol +++ b/contracts/xchain/PolygonChild.sol @@ -1 +1,29 @@ -// Will receive messages from PolygonMessenger.sol \ No newline at end of file +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@fx-portal/contracts/tunnel/FxBaseChildTunnel.sol"; + +/** + * @title FxStateChildTunnel + */ +contract PolygonChild is FxBaseChildTunnel { + uint256 public latestStateId; + address public latestRootMessageSender; + bytes public latestData; + + constructor(address _fxChild) FxBaseChildTunnel(_fxChild) {} + + function _processMessageFromRoot( + uint256 stateId, + address sender, + bytes memory data + ) internal override validateSender(sender) { + latestStateId = stateId; + latestRootMessageSender = sender; + latestData = data; + } + + function sendMessageToRoot(bytes memory message) public { + _sendMessageToRoot(message); + } +} \ No newline at end of file diff --git a/contracts/xchain/PolygonMessenger.sol b/contracts/xchain/PolygonMessenger.sol deleted file mode 100644 index cdcc86f2..00000000 --- a/contracts/xchain/PolygonMessenger.sol +++ /dev/null @@ -1,2 +0,0 @@ -// Inherits from AbstractMessenger.sol -// Will be deployed to mainnet \ No newline at end of file diff --git a/contracts/xchain/PolygonRoot.sol b/contracts/xchain/PolygonRoot.sol new file mode 100644 index 00000000..919a6187 --- /dev/null +++ b/contracts/xchain/PolygonRoot.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@fx-portal/contracts/tunnel/FxBaseRootTunnel.sol"; + + +contract PolygonRoot is FxBaseRootTunnel { + bytes public latestData; + + constructor(address _checkpointManager, address _fxRoot) FxBaseRootTunnel(_checkpointManager, _fxRoot) {} + + function _processMessageFromChild(bytes memory data) internal override { + latestData = data; + } + + function sendMessageToChild(bytes memory message) public { + _sendMessageToChild(message); + } +} \ No newline at end of file From 3ef73e219c7f12abe0f7946373caf06215c96204 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Thu, 20 Apr 2023 14:25:37 +0200 Subject: [PATCH 03/12] Add fx configuration and scripts for deploying to testnet --- scripts/deploy_xchain_test.py | 34 +++++++++++++++++++++++++ tests/test_xchain.py | 48 ----------------------------------- 2 files changed, 34 insertions(+), 48 deletions(-) create mode 100644 scripts/deploy_xchain_test.py diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py new file mode 100644 index 00000000..005f7840 --- /dev/null +++ b/scripts/deploy_xchain_test.py @@ -0,0 +1,34 @@ +from brownie import PolygonChild, PolygonRoot, accounts, config, network + + +def deploy_eth_contracts(): + # Connect to the Ethereum network + network.connect("goerli") + network_config = config["networks"]["goerli"] + + # Deploy the FxStateRootTunnel contract + polygon_root = PolygonRoot.deploy( + network_config.get("check_point_manager"), + network_config.get("fx_root"), + {"from": accounts[0]}, + ) + + # Print the address of the deployed contract + print("FxStateRootTunnel deployed at:", polygon_root.address) + return polygon_root.address + + +def deploy_polygon_contracts(): + # Connect to the Polygon network + network.connect("polygon-test") + network_config = config["networks"]["polygon-test"] + + # Deploy the FxStateChildTunnel contract + child_tunnel = PolygonChild.deploy(network_config.get("fx_child"), {"from": accounts[0]}) + + # Print the address of the deployed contract + print("FxStateChildTunnel deployed at:", child_tunnel.address) + + +polygon_root_address = deploy_eth_contracts() +deploy_polygon_contracts(polygon_root_address) diff --git a/tests/test_xchain.py b/tests/test_xchain.py index 07f7e436..e69de29b 100644 --- a/tests/test_xchain.py +++ b/tests/test_xchain.py @@ -1,48 +0,0 @@ -import pytest -from brownie import EthCrossChainMessenger, PolygonCrossChainMessenger, accounts - - -@pytest.fixture(scope="module") -def eth_messenger(): - chain_id = 1 # Ethereum Mainnet - root_chain_manager = ( - "0xA0c68C638235ee32657e8f720a23ceC1bFc77C77" # Address of the RootChainManager on Ethereum - ) - messenger = EthCrossChainMessenger.deploy(root_chain_manager, chain_id, {"from": accounts[0]}) - messenger.addMessageSenderRole(accounts[0], {"from": accounts[0]}) - return messenger - - -@pytest.fixture(scope="module") -def polygon_messenger(): - chain_id = 137 # Polygon Mainnet - root_chain_manager = ( - "0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74" # Address of the RootChainManager on Polygon - ) - messenger = PolygonCrossChainMessenger.deploy( - root_chain_manager, chain_id, {"from": accounts[0]} - ) - messenger.addMessageSenderRole(accounts[0], {"from": accounts[0]}) - return messenger - - -def test_cross_chain_messaging(eth_messenger, polygon_messenger): - # Send a message from the Ethereum contract to the Polygon contract - message = "Hello from Ethereum" - polygon_contract_address = "0x123abc..." # Address of the recipient contract on Polygon - eth_messenger.sendMessageToPolygon( - polygon_contract_address, message.encode("utf-8"), {"from": accounts[0]} - ) - - # Verify that the message was received on the Polygon contract - assert polygon_messenger.messageReceived() == message - - # Send a message from the Polygon contract to the Ethereum contract - message = "Hello from Polygon" - eth_contract_address = "0x456def..." # Address of the recipient contract on Ethereum - polygon_messenger.sendMessageToEth( - eth_contract_address, message.encode("utf-8"), {"from": accounts[0]} - ) - - # Verify that the message was received on the Ethereum contract - assert eth_messenger.messageReceived() == message From 82ee0962c3e293b1dd0886506d77507e7d60c3ea Mon Sep 17 00:00:00 2001 From: James Campbell Date: Fri, 21 Apr 2023 10:15:48 +0200 Subject: [PATCH 04/12] Fix deployment script for xchain test --- scripts/deploy_xchain_test.py | 38 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py index 005f7840..f8c28b4d 100644 --- a/scripts/deploy_xchain_test.py +++ b/scripts/deploy_xchain_test.py @@ -1,34 +1,48 @@ -from brownie import PolygonChild, PolygonRoot, accounts, config, network +from brownie import PolygonChild, PolygonRoot, config, network +from scripts.utils import get_account -def deploy_eth_contracts(): +def switch_network(network_name): + network.disconnect() + network.connect(network_name) + + +def deploy_eth_contracts(deployer): # Connect to the Ethereum network - network.connect("goerli") + switch_network("goerli") network_config = config["networks"]["goerli"] # Deploy the FxStateRootTunnel contract polygon_root = PolygonRoot.deploy( network_config.get("check_point_manager"), network_config.get("fx_root"), - {"from": accounts[0]}, + {"from": deployer}, + publish_source=network_config.get("verify"), ) # Print the address of the deployed contract - print("FxStateRootTunnel deployed at:", polygon_root.address) - return polygon_root.address + print("PolygonRoot deployed at:", polygon_root.address) + return polygon_root -def deploy_polygon_contracts(): +def deploy_polygon_contracts(deployer): # Connect to the Polygon network - network.connect("polygon-test") + switch_network("polygon-test") network_config = config["networks"]["polygon-test"] # Deploy the FxStateChildTunnel contract - child_tunnel = PolygonChild.deploy(network_config.get("fx_child"), {"from": accounts[0]}) + polygon_child = PolygonChild.deploy( + network_config.get("fx_child"), + {"from": deployer}, + publish_source=network_config.get("verify"), + ) # Print the address of the deployed contract - print("FxStateChildTunnel deployed at:", child_tunnel.address) + print("PolygonChild deployed at:", polygon_child.address) + return polygon_child -polygon_root_address = deploy_eth_contracts() -deploy_polygon_contracts(polygon_root_address) +def main(account_id=None): + deployer = get_account(account_id) + deploy_eth_contracts(deployer) + deploy_polygon_contracts(deployer) From fa33fb39097adcc69ced81f4845b1a4da8dcbfaf Mon Sep 17 00:00:00 2001 From: James Campbell Date: Tue, 25 Apr 2023 13:11:29 +0200 Subject: [PATCH 05/12] Add basic StakeInfo contract --- contracts/xchain/AbstractMessenger.sol | 18 ------------------ contracts/xchain/Application.sol | 2 -- contracts/xchain/IApplication.sol | 1 - contracts/xchain/PolygonChild.sol | 4 +--- contracts/xchain/StakeInfo.sol | 21 +++++++++++++++++++++ 5 files changed, 22 insertions(+), 24 deletions(-) delete mode 100644 contracts/xchain/AbstractMessenger.sol delete mode 100644 contracts/xchain/Application.sol delete mode 100644 contracts/xchain/IApplication.sol create mode 100644 contracts/xchain/StakeInfo.sol diff --git a/contracts/xchain/AbstractMessenger.sol b/contracts/xchain/AbstractMessenger.sol deleted file mode 100644 index afa13144..00000000 --- a/contracts/xchain/AbstractMessenger.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.4; - -import "@openzeppelin/contracts/crosschain/CrossChainEnabled.sol"; -import "./IApplication.sol"; - -// Abstract contract. For each xchain connection we'll have a separate contract that inherits from this one. -// It will implement the isAuthorized function and read from the application contract. -abstract contract AbstractMessenger is CrossChainEnabled { - constructor() {} - - function isAuthorized(address operatorAddress) public view returns(bool) { - return true; - } - - function update() public { - } -} \ No newline at end of file diff --git a/contracts/xchain/Application.sol b/contracts/xchain/Application.sol deleted file mode 100644 index 4f999ae0..00000000 --- a/contracts/xchain/Application.sol +++ /dev/null @@ -1,2 +0,0 @@ -// Application contract. In production this would be a CBD contract, here we'll just have -// a simple contract that maps some test address to true/false. \ No newline at end of file diff --git a/contracts/xchain/IApplication.sol b/contracts/xchain/IApplication.sol deleted file mode 100644 index 9cda0946..00000000 --- a/contracts/xchain/IApplication.sol +++ /dev/null @@ -1 +0,0 @@ -// Interface for the application contract \ No newline at end of file diff --git a/contracts/xchain/PolygonChild.sol b/contracts/xchain/PolygonChild.sol index 512b089f..ef7cac3e 100644 --- a/contracts/xchain/PolygonChild.sol +++ b/contracts/xchain/PolygonChild.sol @@ -3,9 +3,7 @@ pragma solidity ^0.8.0; import "@fx-portal/contracts/tunnel/FxBaseChildTunnel.sol"; -/** - * @title FxStateChildTunnel - */ + contract PolygonChild is FxBaseChildTunnel { uint256 public latestStateId; address public latestRootMessageSender; diff --git a/contracts/xchain/StakeInfo.sol b/contracts/xchain/StakeInfo.sol new file mode 100644 index 00000000..b29aa5b5 --- /dev/null +++ b/contracts/xchain/StakeInfo.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "@openzeppelin/contracts/access/AccessControl.sol"; + +contract StakeInfo is AccessControl { + address public polygonChild; + + bytes32 public constant UPDATOR_ROLE = keccak256("UPDATOR_ROLE"); + mapping (address => uint8) public operatorInfo; + + constructor(address _polygonChild) { + polygonChild = _polygonChild; + _grantRole(UPDATOR_ROLE, polygonChild); + } + + function setOperatorInfo(address _operator, uint8 _info) external { + require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); + operatorInfo[_operator] = _info; + } +} \ No newline at end of file From d3f01bcc62febbd57beed6c82e31e767e794e4ca Mon Sep 17 00:00:00 2001 From: James Campbell Date: Tue, 25 Apr 2023 14:16:14 +0200 Subject: [PATCH 06/12] Pass operator update messages through Root, Child, and into StakeInfo --- contracts/xchain/PolygonChild.sol | 19 ++++++++++--------- contracts/xchain/PolygonRoot.sol | 8 +++++++- contracts/xchain/StakeInfo.sol | 13 +++++++++++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/contracts/xchain/PolygonChild.sol b/contracts/xchain/PolygonChild.sol index ef7cac3e..911174bc 100644 --- a/contracts/xchain/PolygonChild.sol +++ b/contracts/xchain/PolygonChild.sol @@ -2,26 +2,27 @@ pragma solidity ^0.8.0; import "@fx-portal/contracts/tunnel/FxBaseChildTunnel.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; - -contract PolygonChild is FxBaseChildTunnel { - uint256 public latestStateId; - address public latestRootMessageSender; - bytes public latestData; +contract PolygonChild is FxBaseChildTunnel, Ownable { + address public stakeInfo; constructor(address _fxChild) FxBaseChildTunnel(_fxChild) {} function _processMessageFromRoot( - uint256 stateId, + uint256 /* stateId */, address sender, bytes memory data ) internal override validateSender(sender) { - latestStateId = stateId; - latestRootMessageSender = sender; - latestData = data; + (bool success, /* returnId */ ) = stakeInfo.call(data); + require(success, "Failed to call stakeInfo"); } function sendMessageToRoot(bytes memory message) public { _sendMessageToRoot(message); } + + function setStakeInfoAddress(address _stakeInfo) public onlyOwner { + stakeInfo = _stakeInfo; + } } \ No newline at end of file diff --git a/contracts/xchain/PolygonRoot.sol b/contracts/xchain/PolygonRoot.sol index 919a6187..8876571b 100644 --- a/contracts/xchain/PolygonRoot.sol +++ b/contracts/xchain/PolygonRoot.sol @@ -13,7 +13,13 @@ contract PolygonRoot is FxBaseRootTunnel { latestData = data; } - function sendMessageToChild(bytes memory message) public { + function updateOperator(address operator, uint8 info) public { + bytes memory message = abi.encodeWithSignature("updateOperatorInfo(address,uint8)", operator, info); + _sendMessageToChild(message); + } + + function batchUpdateOperators(address[] calldata operators, uint8[] calldata infos) public { + bytes memory message = abi.encodeWithSignature("batchUpdateOperatorInfo(address[],uint8[])", operators, infos); _sendMessageToChild(message); } } \ No newline at end of file diff --git a/contracts/xchain/StakeInfo.sol b/contracts/xchain/StakeInfo.sol index b29aa5b5..6bb40df5 100644 --- a/contracts/xchain/StakeInfo.sol +++ b/contracts/xchain/StakeInfo.sol @@ -2,8 +2,9 @@ pragma solidity ^0.8.0; import "@openzeppelin/contracts/access/AccessControl.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; -contract StakeInfo is AccessControl { +contract StakeInfo is AccessControl, Ownable { address public polygonChild; bytes32 public constant UPDATOR_ROLE = keccak256("UPDATOR_ROLE"); @@ -14,8 +15,16 @@ contract StakeInfo is AccessControl { _grantRole(UPDATOR_ROLE, polygonChild); } - function setOperatorInfo(address _operator, uint8 _info) external { + function updateOperatorInfo(address _operator, uint8 _info) external { require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); operatorInfo[_operator] = _info; } + + function batchUpdateOperatorInfo(address[] calldata _operators, uint8[] calldata _infos) external { + require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); + require(_operators.length == _infos.length, "Invalid input length"); + for (uint256 i = 0; i < _operators.length; i++) { + operatorInfo[_operators[i]] = _infos[i]; + } + } } \ No newline at end of file From 358966ef1a576f1ab5d6f529a2d8fd5ce49ab112 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Tue, 25 Apr 2023 21:43:11 +0200 Subject: [PATCH 07/12] Fix contracts such that data is written to StakeInfo correctly --- .gitignore | 2 +- contracts/xchain/PolygonChild.sol | 11 +++++++--- contracts/xchain/PolygonRoot.sol | 8 +++---- contracts/xchain/StakeInfo.sol | 10 +++++---- scripts/deploy_xchain_test.py | 36 +++++++++++++++++++++++-------- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 9abf0737..2372d930 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ node_modules/ .build contracts/.cache env -.cache/ \ No newline at end of file +.cache/ diff --git a/contracts/xchain/PolygonChild.sol b/contracts/xchain/PolygonChild.sol index 911174bc..c1876ffc 100644 --- a/contracts/xchain/PolygonChild.sol +++ b/contracts/xchain/PolygonChild.sol @@ -6,16 +6,21 @@ import "@openzeppelin/contracts/access/Ownable.sol"; contract PolygonChild is FxBaseChildTunnel, Ownable { address public stakeInfo; - + uint256 public latestStateId; + address public latestRootMessageSender; + bytes public latestData; + constructor(address _fxChild) FxBaseChildTunnel(_fxChild) {} function _processMessageFromRoot( - uint256 /* stateId */, + uint256 stateId, address sender, bytes memory data ) internal override validateSender(sender) { + latestStateId = stateId; + latestRootMessageSender = sender; + latestData = data; (bool success, /* returnId */ ) = stakeInfo.call(data); - require(success, "Failed to call stakeInfo"); } function sendMessageToRoot(bytes memory message) public { diff --git a/contracts/xchain/PolygonRoot.sol b/contracts/xchain/PolygonRoot.sol index 8876571b..a6cabff7 100644 --- a/contracts/xchain/PolygonRoot.sol +++ b/contracts/xchain/PolygonRoot.sol @@ -13,13 +13,13 @@ contract PolygonRoot is FxBaseRootTunnel { latestData = data; } - function updateOperator(address operator, uint8 info) public { - bytes memory message = abi.encodeWithSignature("updateOperatorInfo(address,uint8)", operator, info); + function updateOperator(address operator, uint32 info) public { + bytes memory message = abi.encodeWithSignature("updateOperatorInfo(address,uint32)", operator, info); _sendMessageToChild(message); } - function batchUpdateOperators(address[] calldata operators, uint8[] calldata infos) public { - bytes memory message = abi.encodeWithSignature("batchUpdateOperatorInfo(address[],uint8[])", operators, infos); + function batchUpdateOperators(address[] calldata operators, uint32[] calldata infos) public { + bytes memory message = abi.encodeWithSignature("batchUpdateOperatorInfo(address[],uint32[])", operators, infos); _sendMessageToChild(message); } } \ No newline at end of file diff --git a/contracts/xchain/StakeInfo.sol b/contracts/xchain/StakeInfo.sol index 6bb40df5..b22e58fa 100644 --- a/contracts/xchain/StakeInfo.sol +++ b/contracts/xchain/StakeInfo.sol @@ -8,19 +8,21 @@ contract StakeInfo is AccessControl, Ownable { address public polygonChild; bytes32 public constant UPDATOR_ROLE = keccak256("UPDATOR_ROLE"); - mapping (address => uint8) public operatorInfo; + mapping (address => uint32) public operatorInfo; constructor(address _polygonChild) { polygonChild = _polygonChild; _grantRole(UPDATOR_ROLE, polygonChild); + _grantRole(UPDATOR_ROLE, msg.sender); + _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); } - function updateOperatorInfo(address _operator, uint8 _info) external { - require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); + function updateOperatorInfo(address _operator, uint32 _info) external { + // require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); operatorInfo[_operator] = _info; } - function batchUpdateOperatorInfo(address[] calldata _operators, uint8[] calldata _infos) external { + function batchUpdateOperatorInfo(address[] calldata _operators, uint32[] calldata _infos) external { require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); require(_operators.length == _infos.length, "Invalid input length"); for (uint256 i = 0; i < _operators.length; i++) { diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py index f8c28b4d..5b8d0562 100644 --- a/scripts/deploy_xchain_test.py +++ b/scripts/deploy_xchain_test.py @@ -1,4 +1,4 @@ -from brownie import PolygonChild, PolygonRoot, config, network +from brownie import PolygonChild, PolygonRoot, StakeInfo, config, network from scripts.utils import get_account @@ -20,9 +20,7 @@ def deploy_eth_contracts(deployer): publish_source=network_config.get("verify"), ) - # Print the address of the deployed contract - print("PolygonRoot deployed at:", polygon_root.address) - return polygon_root + return polygon_root.address def deploy_polygon_contracts(deployer): @@ -36,13 +34,33 @@ def deploy_polygon_contracts(deployer): {"from": deployer}, publish_source=network_config.get("verify"), ) + stake_info = StakeInfo.deploy( + polygon_child.address, + {"from": deployer}, + publish_source=network_config.get("verify"), + ) - # Print the address of the deployed contract - print("PolygonChild deployed at:", polygon_child.address) - return polygon_child + return polygon_child.address, stake_info.address def main(account_id=None): deployer = get_account(account_id) - deploy_eth_contracts(deployer) - deploy_polygon_contracts(deployer) + _ = deploy_eth_contracts(deployer) + _, _ = deploy_polygon_contracts(deployer) + + # # Set the root contract address in the child contract + # # switch_network("polygon-test") + # tx = PolygonChild.at(child_address).setFxRootTunnel(root_address) + # tx.wait(1) + # tx = PolygonChild.at(child_address).setStakeInfoAddress(stake_info_address) + # tx.wait(1) + + # # Set the child contract address in the root contract + # switch_network("goerli") + # tx = PolygonRoot.at(root_address).setFxChildTunnel(child_address, {"from": deployer}) + # tx.wait(1) + + # tx = PolygonRoot.at(root_address).updateOperator( + # "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", 42069, {"from": deployer} + # ) + # tx.wait(1) From c6fbaf56f7bee995a271f91f635edc3a6aef4c23 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Wed, 26 Apr 2023 11:43:43 +0200 Subject: [PATCH 08/12] Send all setup transactions in script --- contracts/xchain/PolygonChild.sol | 16 +++++----------- contracts/xchain/StakeInfo.sol | 3 +-- scripts/deploy_xchain_test.py | 32 +++++++++++++++---------------- 3 files changed, 22 insertions(+), 29 deletions(-) diff --git a/contracts/xchain/PolygonChild.sol b/contracts/xchain/PolygonChild.sol index c1876ffc..59eff195 100644 --- a/contracts/xchain/PolygonChild.sol +++ b/contracts/xchain/PolygonChild.sol @@ -5,29 +5,23 @@ import "@fx-portal/contracts/tunnel/FxBaseChildTunnel.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract PolygonChild is FxBaseChildTunnel, Ownable { - address public stakeInfo; - uint256 public latestStateId; - address public latestRootMessageSender; - bytes public latestData; + address public stakeInfoAddress; constructor(address _fxChild) FxBaseChildTunnel(_fxChild) {} function _processMessageFromRoot( - uint256 stateId, + uint256 /* stateId */, address sender, bytes memory data ) internal override validateSender(sender) { - latestStateId = stateId; - latestRootMessageSender = sender; - latestData = data; - (bool success, /* returnId */ ) = stakeInfo.call(data); + (bool success, /* returnId */ ) = stakeInfoAddress.call(data); } function sendMessageToRoot(bytes memory message) public { _sendMessageToRoot(message); } - function setStakeInfoAddress(address _stakeInfo) public onlyOwner { - stakeInfo = _stakeInfo; + function setStakeInfoAddress(address _stakeInfoAddress) public onlyOwner { + stakeInfoAddress = _stakeInfoAddress; } } \ No newline at end of file diff --git a/contracts/xchain/StakeInfo.sol b/contracts/xchain/StakeInfo.sol index b22e58fa..766eef6e 100644 --- a/contracts/xchain/StakeInfo.sol +++ b/contracts/xchain/StakeInfo.sol @@ -6,7 +6,6 @@ import "@openzeppelin/contracts/access/Ownable.sol"; contract StakeInfo is AccessControl, Ownable { address public polygonChild; - bytes32 public constant UPDATOR_ROLE = keccak256("UPDATOR_ROLE"); mapping (address => uint32) public operatorInfo; @@ -18,7 +17,7 @@ contract StakeInfo is AccessControl, Ownable { } function updateOperatorInfo(address _operator, uint32 _info) external { - // require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); + require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); operatorInfo[_operator] = _info; } diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py index 5b8d0562..13f278fb 100644 --- a/scripts/deploy_xchain_test.py +++ b/scripts/deploy_xchain_test.py @@ -45,22 +45,22 @@ def deploy_polygon_contracts(deployer): def main(account_id=None): deployer = get_account(account_id) - _ = deploy_eth_contracts(deployer) - _, _ = deploy_polygon_contracts(deployer) + root_address = deploy_eth_contracts(deployer) + child_address, stake_info_address = deploy_polygon_contracts(deployer) - # # Set the root contract address in the child contract - # # switch_network("polygon-test") - # tx = PolygonChild.at(child_address).setFxRootTunnel(root_address) - # tx.wait(1) - # tx = PolygonChild.at(child_address).setStakeInfoAddress(stake_info_address) - # tx.wait(1) + # Set the root contract address in the child contract + # switch_network("polygon-test") + tx = PolygonChild.at(child_address).setFxRootTunnel(root_address) + tx.wait(1) + tx = PolygonChild.at(child_address).setStakeInfoAddress(stake_info_address) + tx.wait(1) - # # Set the child contract address in the root contract - # switch_network("goerli") - # tx = PolygonRoot.at(root_address).setFxChildTunnel(child_address, {"from": deployer}) - # tx.wait(1) + # Set the child contract address in the root contract + switch_network("goerli") + tx = PolygonRoot.at(root_address).setFxChildTunnel(child_address, {"from": deployer}) + tx.wait(1) - # tx = PolygonRoot.at(root_address).updateOperator( - # "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", 42069, {"from": deployer} - # ) - # tx.wait(1) + tx = PolygonRoot.at(root_address).updateOperator( + "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", 42069, {"from": deployer} + ) + tx.wait(1) From 930c7cecf4f4135d214b4e0300a79266775696dc Mon Sep 17 00:00:00 2001 From: James Campbell Date: Mon, 1 May 2023 10:57:02 +0200 Subject: [PATCH 09/12] Refactor xchain deployment to use ape --- ape-config.yaml | 10 ++++ scripts/deploy_xchain_test.py | 94 ++++++++++++++++------------------- 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/ape-config.yaml b/ape-config.yaml index 2264b2b4..08dd4d5f 100644 --- a/ape-config.yaml +++ b/ape-config.yaml @@ -15,6 +15,9 @@ dependencies: - name: openzeppelin-upgradeable github: OpenZeppelin/openzeppelin-contracts-upgradeable version: 4.8.1 + - name: fx-portal + github: 0xPolygon/fx-portal + version: 1.0.5 solidity: version: 0.8.20 @@ -22,8 +25,13 @@ solidity: import_remapping: - "@openzeppelin/contracts=openzeppelin/v4.8.1" - "@openzeppelin-upgradeable/contracts=openzeppelin-upgradeable/v4.8.1" + - "@fx-portal/contracts=fx-portal/v1.0.5" deployments: + polygon: + mumbai: + - fx_child: '0xCf73231F28B7331BBe3124B907840A94851f9f11' + - verify: True ethereum: local: - nu_token_supply: 1_000_000_000 @@ -63,6 +71,8 @@ deployments: max_dkg_size: 16 ritual_timeout: 86400 # one day in seconds verify: True + checkpoint_manager: '0x2890bA17EfE978480615e330ecB65333b880928e' + fx_root: '0x3d1d3E34f7fB6D26245E6640E1c50710eFFf15bA' mainnet: - nu_token: '0x4fE83213D56308330EC302a8BD641f1d0113A4Cc' t_staking: '0x01B67b1194C75264d06F808A921228a95C765dd7' diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py index 13f278fb..c801a1cf 100644 --- a/scripts/deploy_xchain_test.py +++ b/scripts/deploy_xchain_test.py @@ -1,66 +1,58 @@ -from brownie import PolygonChild, PolygonRoot, StakeInfo, config, network -from scripts.utils import get_account - - -def switch_network(network_name): - network.disconnect() - network.connect(network_name) +from ape import accounts, config, networks, project def deploy_eth_contracts(deployer): # Connect to the Ethereum network - switch_network("goerli") - network_config = config["networks"]["goerli"] + with networks.ethereum.goerli.use_provider("infura"): + DEPLOYMENTS_CONFIG = config.get_config("deployments")["ethereum"]["goerli"][0] - # Deploy the FxStateRootTunnel contract - polygon_root = PolygonRoot.deploy( - network_config.get("check_point_manager"), - network_config.get("fx_root"), - {"from": deployer}, - publish_source=network_config.get("verify"), - ) + # Deploy the FxStateRootTunnel contract + polygon_root = project.PolygonRoot.deploy( + DEPLOYMENTS_CONFIG.get("checkpoint_manager"), + DEPLOYMENTS_CONFIG.get("fx_root"), + sender=deployer, + publish=DEPLOYMENTS_CONFIG.get("verify"), + ) - return polygon_root.address + return polygon_root def deploy_polygon_contracts(deployer): # Connect to the Polygon network - switch_network("polygon-test") - network_config = config["networks"]["polygon-test"] + with networks.polygon.mumbai.use_provider("infura"): + DEPLOYMENTS_CONFIG = config.get_config("deployments")["polygon"]["mumbai"][0] - # Deploy the FxStateChildTunnel contract - polygon_child = PolygonChild.deploy( - network_config.get("fx_child"), - {"from": deployer}, - publish_source=network_config.get("verify"), - ) - stake_info = StakeInfo.deploy( - polygon_child.address, - {"from": deployer}, - publish_source=network_config.get("verify"), - ) + # Deploy the FxStateChildTunnel contract + polygon_child = project.PolygonChild.deploy( + DEPLOYMENTS_CONFIG.get("fx_child"), + sender=deployer, + publish=True, + ) + stake_info = project.StakeInfo.deploy( + polygon_child.address, + sender=deployer, + publish=True, + ) - return polygon_child.address, stake_info.address + return polygon_child, stake_info def main(account_id=None): - deployer = get_account(account_id) - root_address = deploy_eth_contracts(deployer) - child_address, stake_info_address = deploy_polygon_contracts(deployer) - - # Set the root contract address in the child contract - # switch_network("polygon-test") - tx = PolygonChild.at(child_address).setFxRootTunnel(root_address) - tx.wait(1) - tx = PolygonChild.at(child_address).setStakeInfoAddress(stake_info_address) - tx.wait(1) - - # Set the child contract address in the root contract - switch_network("goerli") - tx = PolygonRoot.at(root_address).setFxChildTunnel(child_address, {"from": deployer}) - tx.wait(1) - - tx = PolygonRoot.at(root_address).updateOperator( - "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", 42069, {"from": deployer} - ) - tx.wait(1) + deployer = accounts.load("TGoerli") + with accounts.use_sender(deployer): + root = deploy_eth_contracts(deployer) + child, stake_info = deploy_polygon_contracts(deployer) + + # Set the root contract address in the child contract + # switch_network("polygon-test") + with networks.polygon.mumbai.use_provider("infura"): + child.setFxRootTunnel(root.address) + child.setStakeInfoAddress(stake_info.address) + + # Set the child contract address in the root contract + with networks.ethereum.goerli.use_provider("infura"): + root.setFxChildTunnel(child.address) + root.updateOperator( + "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", + 42069, + ) From e18bb455d9cdc27affbd728a14047612fbfe1ba4 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Mon, 1 May 2023 11:00:56 +0200 Subject: [PATCH 10/12] Match PolygonRoot contract with updated StakeInfo contract --- contracts/xchain/PolygonRoot.sol | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/contracts/xchain/PolygonRoot.sol b/contracts/xchain/PolygonRoot.sol index a6cabff7..50ce0ba7 100644 --- a/contracts/xchain/PolygonRoot.sol +++ b/contracts/xchain/PolygonRoot.sol @@ -13,13 +13,18 @@ contract PolygonRoot is FxBaseRootTunnel { latestData = data; } - function updateOperator(address operator, uint32 info) public { - bytes memory message = abi.encodeWithSignature("updateOperatorInfo(address,uint32)", operator, info); + function updateOperator(address stakingProvider, address operator) public { + bytes memory message = abi.encodeWithSignature("updateOperator(address,address)", stakingProvider, operator); _sendMessageToChild(message); } - function batchUpdateOperators(address[] calldata operators, uint32[] calldata infos) public { - bytes memory message = abi.encodeWithSignature("batchUpdateOperatorInfo(address[],uint32[])", operators, infos); + function updateAmount(address stakingProvider, uint96 amount) public { + bytes memory message = abi.encodeWithSignature("updateAmount(address,uint96)", stakingProvider, amount); + _sendMessageToChild(message); + } + + function batchUpdate(bytes32[] calldata updateInfo) public { + bytes memory message = abi.encodeWithSignature("batchUpdate(bytes32[])", updateInfo); _sendMessageToChild(message); } } \ No newline at end of file From 23463d2baec9278df7e4b8bf5266deacee83ca77 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Mon, 1 May 2023 13:55:54 +0200 Subject: [PATCH 11/12] Add script to check the deployments of xchain contracts --- .../contracts/coordination/StakeInfo.sol | 6 ++-- contracts/xchain/StakeInfo.sol | 31 ------------------- scripts/check_xchain.py | 7 +++++ scripts/deploy_xchain_test.py | 5 ++- 4 files changed, 13 insertions(+), 36 deletions(-) delete mode 100644 contracts/xchain/StakeInfo.sol create mode 100644 scripts/check_xchain.py diff --git a/contracts/contracts/coordination/StakeInfo.sol b/contracts/contracts/coordination/StakeInfo.sol index 750e1092..478a90d8 100644 --- a/contracts/contracts/coordination/StakeInfo.sol +++ b/contracts/contracts/coordination/StakeInfo.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: AGPL-3.0-or-later +// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; @@ -13,6 +13,7 @@ import "../../threshold/IAccessControlApplication.sol"; contract StakeInfo is AccessControl, IUpdatableStakes, IAccessControlApplication { bytes32 public constant UPDATE_ROLE = keccak256("UPDATE_ROLE"); + address public polygonChild; struct Stake { address operator; @@ -20,10 +21,11 @@ contract StakeInfo is AccessControl, IUpdatableStakes, IAccessControlApplication // TODO: what about undelegations etc? } - constructor(address[] memory updaters){ + constructor(address _polygonChild, address[] memory updaters){ for(uint i = 0; i < updaters.length; i++){ _grantRole(UPDATE_ROLE, updaters[i]); } + polygonChild = _polygonChild; } mapping(address => Stake) public stakes; diff --git a/contracts/xchain/StakeInfo.sol b/contracts/xchain/StakeInfo.sol deleted file mode 100644 index 766eef6e..00000000 --- a/contracts/xchain/StakeInfo.sol +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "@openzeppelin/contracts/access/AccessControl.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; - -contract StakeInfo is AccessControl, Ownable { - address public polygonChild; - bytes32 public constant UPDATOR_ROLE = keccak256("UPDATOR_ROLE"); - mapping (address => uint32) public operatorInfo; - - constructor(address _polygonChild) { - polygonChild = _polygonChild; - _grantRole(UPDATOR_ROLE, polygonChild); - _grantRole(UPDATOR_ROLE, msg.sender); - _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); - } - - function updateOperatorInfo(address _operator, uint32 _info) external { - require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); - operatorInfo[_operator] = _info; - } - - function batchUpdateOperatorInfo(address[] calldata _operators, uint32[] calldata _infos) external { - require(hasRole(UPDATOR_ROLE, msg.sender), "Caller is not the updator"); - require(_operators.length == _infos.length, "Invalid input length"); - for (uint256 i = 0; i < _operators.length; i++) { - operatorInfo[_operators[i]] = _infos[i]; - } - } -} \ No newline at end of file diff --git a/scripts/check_xchain.py b/scripts/check_xchain.py new file mode 100644 index 00000000..e4333951 --- /dev/null +++ b/scripts/check_xchain.py @@ -0,0 +1,7 @@ +from ape import project + + +def main(): + stake_info = project.StakeInfo.at("0x40D0107ACa3503CB345E4117a9F92E8220EEEb3C") + print(stake_info.operatorToProvider("0xAe87D865F3A507185656aD0ef52a8E0B9f3d58f8")) + print(stake_info.operatorToProvider("0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600")) diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py index c801a1cf..3268a728 100644 --- a/scripts/deploy_xchain_test.py +++ b/scripts/deploy_xchain_test.py @@ -26,12 +26,11 @@ def deploy_polygon_contracts(deployer): polygon_child = project.PolygonChild.deploy( DEPLOYMENTS_CONFIG.get("fx_child"), sender=deployer, - publish=True, ) stake_info = project.StakeInfo.deploy( polygon_child.address, + [deployer.address, polygon_child.address], sender=deployer, - publish=True, ) return polygon_child, stake_info @@ -54,5 +53,5 @@ def main(account_id=None): root.setFxChildTunnel(child.address) root.updateOperator( "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", - 42069, + "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", ) From a6ed59be541db2690d69c5a86f66f770254bab0f Mon Sep 17 00:00:00 2001 From: James Campbell Date: Wed, 3 May 2023 13:21:21 +0200 Subject: [PATCH 12/12] Address PR comments --- ape-config.yaml | 2 +- .../contracts/coordination/StakeInfo.sol | 4 +--- contracts/xchain/PolygonChild.sol | 7 +++++++ scripts/check_xchain.py | 21 +++++++++++++++---- scripts/deploy_xchain_test.py | 8 ++----- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/ape-config.yaml b/ape-config.yaml index 08dd4d5f..7ef26a47 100644 --- a/ape-config.yaml +++ b/ape-config.yaml @@ -31,7 +31,7 @@ deployments: polygon: mumbai: - fx_child: '0xCf73231F28B7331BBe3124B907840A94851f9f11' - - verify: True + - verify: False ethereum: local: - nu_token_supply: 1_000_000_000 diff --git a/contracts/contracts/coordination/StakeInfo.sol b/contracts/contracts/coordination/StakeInfo.sol index 478a90d8..5e764313 100644 --- a/contracts/contracts/coordination/StakeInfo.sol +++ b/contracts/contracts/coordination/StakeInfo.sol @@ -13,7 +13,6 @@ import "../../threshold/IAccessControlApplication.sol"; contract StakeInfo is AccessControl, IUpdatableStakes, IAccessControlApplication { bytes32 public constant UPDATE_ROLE = keccak256("UPDATE_ROLE"); - address public polygonChild; struct Stake { address operator; @@ -21,11 +20,10 @@ contract StakeInfo is AccessControl, IUpdatableStakes, IAccessControlApplication // TODO: what about undelegations etc? } - constructor(address _polygonChild, address[] memory updaters){ + constructor(address[] memory updaters){ for(uint i = 0; i < updaters.length; i++){ _grantRole(UPDATE_ROLE, updaters[i]); } - polygonChild = _polygonChild; } mapping(address => Stake) public stakes; diff --git a/contracts/xchain/PolygonChild.sol b/contracts/xchain/PolygonChild.sol index 59eff195..166db1e0 100644 --- a/contracts/xchain/PolygonChild.sol +++ b/contracts/xchain/PolygonChild.sol @@ -5,6 +5,12 @@ import "@fx-portal/contracts/tunnel/FxBaseChildTunnel.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract PolygonChild is FxBaseChildTunnel, Ownable { + + event MessageReceived( + address indexed sender, + bytes data + ); + address public stakeInfoAddress; constructor(address _fxChild) FxBaseChildTunnel(_fxChild) {} @@ -14,6 +20,7 @@ contract PolygonChild is FxBaseChildTunnel, Ownable { address sender, bytes memory data ) internal override validateSender(sender) { + emit MessageReceived(sender, data); (bool success, /* returnId */ ) = stakeInfoAddress.call(data); } diff --git a/scripts/check_xchain.py b/scripts/check_xchain.py index e4333951..0b1ea5a3 100644 --- a/scripts/check_xchain.py +++ b/scripts/check_xchain.py @@ -1,7 +1,20 @@ -from ape import project +import time + +from ape import networks, project def main(): - stake_info = project.StakeInfo.at("0x40D0107ACa3503CB345E4117a9F92E8220EEEb3C") - print(stake_info.operatorToProvider("0xAe87D865F3A507185656aD0ef52a8E0B9f3d58f8")) - print(stake_info.operatorToProvider("0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600")) + print("*******") + print("WARNING: This script will take 40 mins to run to allow messages to sync from L1 to L2") + print("*******") + with networks.ethereum.goerli.use_provider("infura"): + root = project.PolygonRoot.at("0xdc90A337DF9561705EB85B92391ab8F55d114D53") + root.updateOperator( + "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", + "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", + ) + time.sleep(60 * 40) + with networks.polygon.mumbai.use_provider("infura"): + stake_info = project.StakeInfo.at("0x40D0107ACa3503CB345E4117a9F92E8220EEEb3C") + print(stake_info.operatorToProvider("0xAe87D865F3A507185656aD0ef52a8E0B9f3d58f8")) + print(stake_info.operatorToProvider("0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600")) diff --git a/scripts/deploy_xchain_test.py b/scripts/deploy_xchain_test.py index 3268a728..06cc59b8 100644 --- a/scripts/deploy_xchain_test.py +++ b/scripts/deploy_xchain_test.py @@ -26,11 +26,12 @@ def deploy_polygon_contracts(deployer): polygon_child = project.PolygonChild.deploy( DEPLOYMENTS_CONFIG.get("fx_child"), sender=deployer, + publish=DEPLOYMENTS_CONFIG.get("verify"), ) stake_info = project.StakeInfo.deploy( - polygon_child.address, [deployer.address, polygon_child.address], sender=deployer, + publish=DEPLOYMENTS_CONFIG.get("verify"), ) return polygon_child, stake_info @@ -43,7 +44,6 @@ def main(account_id=None): child, stake_info = deploy_polygon_contracts(deployer) # Set the root contract address in the child contract - # switch_network("polygon-test") with networks.polygon.mumbai.use_provider("infura"): child.setFxRootTunnel(root.address) child.setStakeInfoAddress(stake_info.address) @@ -51,7 +51,3 @@ def main(account_id=None): # Set the child contract address in the root contract with networks.ethereum.goerli.use_provider("infura"): root.setFxChildTunnel(child.address) - root.updateOperator( - "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", - "0x3B42d26E19FF860bC4dEbB920DD8caA53F93c600", - )