-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from theref/xchain
Add cross chain messaging for stake info from ETH to Polygon
- Loading branch information
Showing
8 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ node_modules/ | |
.build | ||
contracts/.cache | ||
env | ||
.cache/ | ||
.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
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) {} | ||
|
||
function _processMessageFromRoot( | ||
uint256 /* stateId */, | ||
address sender, | ||
bytes memory data | ||
) internal override validateSender(sender) { | ||
emit MessageReceived(sender, data); | ||
(bool success, /* returnId */ ) = stakeInfoAddress.call(data); | ||
} | ||
|
||
function sendMessageToRoot(bytes memory message) public { | ||
_sendMessageToRoot(message); | ||
} | ||
|
||
function setStakeInfoAddress(address _stakeInfoAddress) public onlyOwner { | ||
stakeInfoAddress = _stakeInfoAddress; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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 updateOperator(address stakingProvider, address operator) public { | ||
bytes memory message = abi.encodeWithSignature("updateOperator(address,address)", stakingProvider, operator); | ||
_sendMessageToChild(message); | ||
} | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import time | ||
|
||
from ape import networks, project | ||
|
||
|
||
def main(): | ||
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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from ape import accounts, config, networks, project | ||
|
||
|
||
def deploy_eth_contracts(deployer): | ||
# Connect to the Ethereum network | ||
with networks.ethereum.goerli.use_provider("infura"): | ||
DEPLOYMENTS_CONFIG = config.get_config("deployments")["ethereum"]["goerli"][0] | ||
|
||
# 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 | ||
|
||
|
||
def deploy_polygon_contracts(deployer): | ||
# Connect to the Polygon network | ||
with networks.polygon.mumbai.use_provider("infura"): | ||
DEPLOYMENTS_CONFIG = config.get_config("deployments")["polygon"]["mumbai"][0] | ||
|
||
# Deploy the FxStateChildTunnel contract | ||
polygon_child = project.PolygonChild.deploy( | ||
DEPLOYMENTS_CONFIG.get("fx_child"), | ||
sender=deployer, | ||
publish=DEPLOYMENTS_CONFIG.get("verify"), | ||
) | ||
stake_info = project.StakeInfo.deploy( | ||
[deployer.address, polygon_child.address], | ||
sender=deployer, | ||
publish=DEPLOYMENTS_CONFIG.get("verify"), | ||
) | ||
|
||
return polygon_child, stake_info | ||
|
||
|
||
def main(account_id=None): | ||
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 | ||
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) |
Empty file.