diff --git a/docs/zilbridge.md b/docs/zilbridge.md index 2141e1d..2523f01 100644 --- a/docs/zilbridge.md +++ b/docs/zilbridge.md @@ -70,6 +70,36 @@ your ZIL to `lockProxy`, we will have to recover it for you with our admin rights, because obviously you won't be able to bridge it to anywhere else. +## BSC Testnet Deployment + +There are a group of scripts that allow you to deploy the EVM half of the ZilBridge transition code into BSC Testnet. + +The `smart-contracts/README.md` contains predeployed addresses; if you +decide to redeploy you will need to change the constants in the ` +scripts, since this is how the addresses of previous contracts are +baked in (sorry!). + + * `mockZilBridge.s.sol` - this is basically what `ZilBridgeFixture::deployOriginalContracts()` does; it deploys via `PRIVATE_KEY_ZILBRIDGE`. + * + + +Run with: + +```sh +export PRIVATE_KEY_ZILBRIDGE= +forge script script/bsc-testnet/deployMockZilBridge.s.sol --rpc-url https://bsc-testnet.bnbchain.org --broadcast + +forge verify-contract
--rpc-url https://bsc-testnet.bnbchain.org --chain-id 97 + + +# now put the data from ^^ into deployXBridgeOverMockZilBridge.s.sol +forge script script/bsc-testnet/deployXBridgeOverMockZilBridge.s.sol --rpc-url https://bsc-testnet.bnbchain.org --broadcast + + +``` + + + ## TODO diff --git a/smart-contracts/README.md b/smart-contracts/README.md index 2233f96..28ea448 100644 --- a/smart-contracts/README.md +++ b/smart-contracts/README.md @@ -301,6 +301,11 @@ Deterministic deployer not available, simple CREATE was used Deterministic deployer not available, simple CREATE was used +Zilliqa side tokens: + + + + ### BSC Testnet - `ChainId`: 97 @@ -308,3 +313,18 @@ Deterministic deployer not available, simple CREATE was used - `ValidatorManager`: `0xCc1CB36d981ae2907cea385F615e879434D20B1C` - `MintAndBurnTokenManager`: `0xA6D73210AF20a59832F264fbD991D2abf28401d0` - `BridgedTestToken`: `0x5190e8b4Bbe8C3a732BAdB600b57fD42ACbB9F4B` + +ZilBridge ChainID 6, bridging to ZilBridge chain ID 18. + +``` + Owner: 0x29543Acb166B6044B67979B858e743701C9bd1df + ECCD: 0xd677494525D25238Fedd554796eEa5733a9B86a2 + CCM: 0xff4AC43f368676765de511F82B816EED9b9D780c + CCMProxy: 0xd7a76e4454c4f4F80E6409DF361B7926a1789d93 + LockProxy: 0x218D8aFE24bb2a0d1DE483Ff67aCADB45Ac8Bd2d + + extendCCM: 0xF2eeaceDB35776412fe999D45aA81Ea674030aE1 + zilbridge tokenmanager: 0x103617938D41f7bea62F0B5b4E8e50585083048F +``` + + diff --git a/smart-contracts/contracts/zilbridge/1/ccmCrossChainManager.sol b/smart-contracts/contracts/zilbridge/1/ccmCrossChainManager.sol index c396c90..cbbffd1 100644 --- a/smart-contracts/contracts/zilbridge/1/ccmCrossChainManager.sol +++ b/smart-contracts/contracts/zilbridge/1/ccmCrossChainManager.sol @@ -2,6 +2,7 @@ *Submitted for verification at Etherscan.io on 2021-10-19 */ +// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; abstract contract Context { diff --git a/smart-contracts/contracts/zilbridge/1/ethCrossChainData.sol b/smart-contracts/contracts/zilbridge/1/ethCrossChainData.sol index 788d67b..0c71567 100644 --- a/smart-contracts/contracts/zilbridge/1/ethCrossChainData.sol +++ b/smart-contracts/contracts/zilbridge/1/ethCrossChainData.sol @@ -4,6 +4,7 @@ // File: eth-contracts/contracts/core/cross_chain_manager/interface/IEthCrossChainData.sol +// SPDX-License-Identifier: MIT pragma solidity ^0.8.2; diff --git a/smart-contracts/script/bsc-testnet/deployMockZilBridge.s.sol b/smart-contracts/script/bsc-testnet/deployMockZilBridge.s.sol new file mode 100644 index 0000000..772f8b7 --- /dev/null +++ b/smart-contracts/script/bsc-testnet/deployMockZilBridge.s.sol @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.20; + +import {Script} from "forge-std/Script.sol"; +import "forge-std/console.sol"; +import {Tester} from "test/Tester.sol"; +import {TestToken} from "test/Helpers.sol"; +import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol"; +import { EthCrossChainManagerProxy } from "contracts/zilbridge/1/ccmProxy.sol"; +import { EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol"; +import { EthCrossChainData } from "contracts/zilbridge/1/ethCrossChainData.sol"; +import { EthExtendCrossChainManager } from "contracts/zilbridge/2/ccmExtendCrossChainManager.sol"; +import { LockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol"; +import { LockProxyTokenManagerDeployer } from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol"; + +/*** @notice does what ZilBridgeFixture::deployOriginalContracts() does */ +contract deployMockZilBridge is Script { + uint64 constant CHAIN_ID=6; + uint64 constant COUNTERPART_CHAIN_ID=18; + + function run() external { + EthCrossChainManager ccm; + EthCrossChainManagerProxy ccmProxy; + EthCrossChainData eccd; + LockProxy lockProxy; + EthExtendCrossChainManager extendCCM; + + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_ZILBRIDGE"); + address owner = vm.addr(deployerPrivateKey); + address[] memory a = new address[](0); + bytes[] memory b = new bytes[](0); + vm.startBroadcast(deployerPrivateKey); + console.log("Owner: %s", owner); + eccd = new EthCrossChainData(); + console.log("ECCD: %s", address(eccd)); + ccm = new EthCrossChainManager(address(eccd), CHAIN_ID, a, b); + console.log("CCM: %s", address(ccm)); + ccmProxy = new EthCrossChainManagerProxy(address(ccm)); + console.log("CCMProxy: %s", address(ccmProxy)); + ccm.transferOwnership(address(ccmProxy)); + eccd.transferOwnership(address(ccm)); + lockProxy = new LockProxy(address(ccmProxy), COUNTERPART_CHAIN_ID); + console.log("LockProxy: %s",address(lockProxy)); + } +} diff --git a/smart-contracts/script/bsc-testnet/deployXBridgeOverMockZilBridge.s.sol b/smart-contracts/script/bsc-testnet/deployXBridgeOverMockZilBridge.s.sol new file mode 100644 index 0000000..0ae694f --- /dev/null +++ b/smart-contracts/script/bsc-testnet/deployXBridgeOverMockZilBridge.s.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.20; + +import {Script} from "forge-std/Script.sol"; +import "forge-std/console.sol"; +import {Tester} from "test/Tester.sol"; +import {TestToken} from "test/Helpers.sol"; +import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol"; +import { EthCrossChainManagerProxy } from "contracts/zilbridge/1/ccmProxy.sol"; +import { EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol"; +import { EthCrossChainData } from "contracts/zilbridge/1/ethCrossChainData.sol"; +import { EthExtendCrossChainManager } from "contracts/zilbridge/2/ccmExtendCrossChainManager.sol"; +import { LockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol"; +import { LockProxyTokenManagerDeployer } from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol"; + +/*** @notice ZilBridgeFixture::installExtendCrossManager() */ +contract deployXBridgeOverMockZilBridge is Script { + // Plug in the data from deployMockZilBridge here. + EthCrossChainData public constant eccd = EthCrossChainData(0xd677494525D25238Fedd554796eEa5733a9B86a2); + EthCrossChainManager public constant ccm = EthCrossChainManager(0xff4AC43f368676765de511F82B816EED9b9D780c); + EthCrossChainManagerProxy public constant ccmProxy = EthCrossChainManagerProxy(0xd7a76e4454c4f4F80E6409DF361B7926a1789d93); + LockProxy public constant lockProxy = LockProxy(payable(0x218D8aFE24bb2a0d1DE483Ff67aCADB45Ac8Bd2d)); + EthExtendCrossChainManager extendCCM; + + function run() external { + address[] memory a = new address[](0); + bytes[] memory b = new bytes[](0); + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_ZILBRIDGE"); + vm.startBroadcast(deployerPrivateKey); + address owner = vm.addr(deployerPrivateKey); + extendCCM = new EthExtendCrossChainManager(address(eccd), 2, a, b); + ccmProxy.pauseEthCrossChainManager(); + extendCCM.transferOwnership(address(ccmProxy)); + ccmProxy.upgradeEthCrossChainManager(address(extendCCM)); + ccmProxy.unpauseEthCrossChainManager(); + console.log("extendCCM: %s", address(extendCCM)); + } +} diff --git a/smart-contracts/script/bsc-testnet/deployZilBridgeTokenManagers.s.sol b/smart-contracts/script/bsc-testnet/deployZilBridgeTokenManagers.s.sol new file mode 100644 index 0000000..29de6c1 --- /dev/null +++ b/smart-contracts/script/bsc-testnet/deployZilBridgeTokenManagers.s.sol @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity ^0.8.20; + +import {Script} from "forge-std/Script.sol"; +import "forge-std/console.sol"; +import {Tester} from "test/Tester.sol"; +import {TestToken} from "test/Helpers.sol"; +import { LockProxy } from "contracts/zilbridge/1/lockProxy.sol"; +import { TestingLockProxy } from "test/zilbridge/TestingLockProxy.sol"; +import { EthCrossChainManagerProxy } from "contracts/zilbridge/1/ccmProxy.sol"; +import { EthCrossChainManager } from "contracts/zilbridge/1/ccmCrossChainManager.sol"; +import { EthCrossChainData } from "contracts/zilbridge/1/ethCrossChainData.sol"; +import { EthExtendCrossChainManager } from "contracts/zilbridge/2/ccmExtendCrossChainManager.sol"; +import { ChainGateway } from "contracts/core/ChainGateway.sol"; +import { LockProxyTokenManagerUpgradeableV3 } from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol"; +import { LockProxyTokenManagerDeployer } from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol"; +import {LockProxyTokenManagerUpgradeableV3} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol"; +import {LockProxyTokenManagerDeployer} from "test/zilbridge/TokenManagerDeployers/LockProxyTokenManagerDeployer.sol"; +import {MintAndBurnTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/MintAndBurnTokenManagerDeployer.sol"; +import {LockAndReleaseTokenManagerDeployer} from "test/periphery/TokenManagerDeployers/LockAndReleaseTokenManagerDeployer.sol"; +import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH.sol"; + +/*** @notice Deploy token managers over the extension manager + */ +contract deployZilBridgeTokenManagers is Script, LockProxyTokenManagerDeployer { + EthExtendCrossChainManager constant extendCCM = EthExtendCrossChainManager(0xF2eeaceDB35776412fe999D45aA81Ea674030aE1); + ChainGateway constant chainGateway = ChainGateway(0xa9A14C90e53EdCD89dFd201A3bF94D867f8098fE); + LockProxy constant lockProxy = LockProxy(payable(0x218D8aFE24bb2a0d1DE483Ff67aCADB45Ac8Bd2d)); + // Different from 0.00025 so that we can tell the difference! + uint fees = 0.00007 ether; + + // This has to be 18, because that is what the original (ZilBridge) contracts were + // deployed with. The mainnet value is 5. + uint64 constant COUNTERPART_CHAIN_ID = 18; + + function run() external { + uint256 validatorPrivateKey = vm.envUint("PRIVATE_KEY_VALIDATOR"); + uint256 bridgePrivateKey = vm.envUint("PRIVATE_KEY_ZILBRIDGE"); + address validator = vm.addr(validatorPrivateKey); + address bridgeOwner = vm.addr(bridgePrivateKey); + // token managers are apparently not pausable, so .. + vm.startBroadcast(validatorPrivateKey); + LockProxyTokenManagerUpgradeableV3 tokenManager = deployLatestLockProxyTokenManager(address(chainGateway), address(lockProxy), fees); + console.log("zilbridge tokenmanager: %s", address(tokenManager)); + vm.stopBroadcast(); + vm.startBroadcast(bridgePrivateKey); + extendCCM.forciblyAddExtension(address(lockProxy), address(tokenManager), COUNTERPART_CHAIN_ID); + vm.stopBroadcast(); + vm.startBroadcast(validatorPrivateKey); + chainGateway.register(address(tokenManager)); + vm.stopBroadcast(); + } +} diff --git a/smart-contracts/script/config.ts b/smart-contracts/script/config.ts index 47e0337..93269ae 100644 --- a/smart-contracts/script/config.ts +++ b/smart-contracts/script/config.ts @@ -1,5 +1,7 @@ import { parseUnits } from "ethers"; +// These turn out to be testnet addresses. + export const config = { zq: { tokenManager: "0x6D61eFb60C17979816E4cE12CD5D29054E755948", @@ -7,6 +9,7 @@ export const config = { token: "0x241c677D9969419800402521ae87C411897A029f", remoteToken: "0x351dA1E7500aBA1d168b9435DCE73415718d212F", remoteTokenManager: "0xF391A1Ee7b3ccad9a9451D2B7460Ac646F899f23", + remoteZilBridgeTokenManager: "0x103617938D41f7bea62F0B5b4E8e50585083048F", remoteChainId: 56, remoteRecipient: "0xb34b88220Fa1EAeDba5d50b271AF8c3eE14A24Dd", amount: parseUnits("1000000", 12), @@ -18,6 +21,7 @@ export const config = { token: "0x351dA1E7500aBA1d168b9435DCE73415718d212F", remoteToken: "0x241c677D9969419800402521ae87C411897A029f", remoteTokenManager: "0x6D61eFb60C17979816E4cE12CD5D29054E755948", + remoteZilBridgeTokenManager: "", remoteChainId: 32769, remoteRecipient: "0xb34b88220Fa1EAeDba5d50b271AF8c3eE14A24Dd", amount: parseUnits("1000000", 12),