From 457b22dfcfd517ba53e93be9e361c28fe3cdccfb Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Thu, 18 Jul 2024 10:22:21 +0100 Subject: [PATCH] (feat) Ignore validator binaries (fix) Fix routing scripts. (feat) Centralise configuration --- bridge-validators/.gitignore | 1 + docs/zilbridge.md | 6 ++-- smart-contracts/README.md | 16 ++++----- .../deployZilBridgeTokenManagers.s.sol | 2 +- .../bsc-testnet/deployZilBridgeTokens.s.sol | 12 +++---- .../bsc-testnet/registerZilBridgeTokens.s.sol | 35 ------------------ .../bsc-testnet/setZilBridgeRouting.s.sol | 34 +++++++----------- smart-contracts/script/testnet_config.s.sol | 11 ++++++ .../zq-testnet/setZilBridgeRouting.s.sol | 36 ++++++++----------- 9 files changed, 54 insertions(+), 99 deletions(-) create mode 100644 bridge-validators/.gitignore delete mode 100644 smart-contracts/script/bsc-testnet/registerZilBridgeTokens.s.sol diff --git a/bridge-validators/.gitignore b/bridge-validators/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/bridge-validators/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/docs/zilbridge.md b/docs/zilbridge.md index 1b6473d..a431802 100644 --- a/docs/zilbridge.md +++ b/docs/zilbridge.md @@ -93,7 +93,7 @@ forge verify-contract
--rpc-url https://bsc-testnet.bnbchain.org --cha forge script scripts/bsc-testnet/deployZilBridgeTokenManagers.s.sol --rpc-url https://bsc-testnet.bnbchain.org --broadcast forge verify-contract
--rpc-url https://bsc-testnet.bnbchain.org --chain-id 97 # and again.. -forge script script/bsc-testnet/deployZilBridgeTokens.s.sol --tc Deployment --rpc-url https://bsc-testnet.bnbchain.org --broadcast +forge script script/bsc-testnet/deployZilBridgeTokens.s.sol --rpc-url https://bsc-testnet.bnbchain.org --broadcast forge verify-contract
--rpc-url https://bsc-testnet.bnbchain.org --chain-id 97 ``` @@ -126,8 +126,8 @@ And now we can set up routing for the tokens we just deployed. This is "just" ca ``` forge script script/bsc-testnet/setZilBridgeRouting.s.sol --rpc-url https://bsc-testnet.bnbchain.org --broadcast -forge script script/zq-testnet/setZilBridgeRouting.s.sol --rpc-url https://bsc-testnet.bnbchain.org --broadcast -```il +forge script script/zq-testnet/setZilBridgeRouting.s.sol --rpc-url https://dev-api.zilliqa.com --broadcast --legacy +``` diff --git a/smart-contracts/README.md b/smart-contracts/README.md index d435ed1..e04b0ea 100644 --- a/smart-contracts/README.md +++ b/smart-contracts/README.md @@ -332,15 +332,13 @@ ZilBridge ChainID 6, bridging to ZilBridge chain ID 18. ``` -(up to deployZilBridgeTokenManagers.s.sol) - -//ZilBridge test Tokens -// -//``` -// ERC20: 0x43b1e04b72Aca6aA54c49f540Ef8ea3970d2A541 -// BridgedZRC2FromZilliqa: 0x190b6601E1D9bAF0c9413b08C27C5cBEa275D55F -// BridgedZIL: 0x09AbdfE544Ca946808261ce761e1e86b91581C6c -//``` +ZilBridge test tokens: + +``` +ERC20: 0x59A23d0957B63BC6c5682F211eE731513EECBB98 + BridgedZRC2FromZilliqa: 0x0d27244Ec509e7cbBde6d5c82DdD0e9F34873bF2 + BridgedZIL: 0x33aC4ae9c514213a51D529114523Dd168c1d3b73 +``` diff --git a/smart-contracts/script/bsc-testnet/deployZilBridgeTokenManagers.s.sol b/smart-contracts/script/bsc-testnet/deployZilBridgeTokenManagers.s.sol index 28d7ad6..d13d347 100644 --- a/smart-contracts/script/bsc-testnet/deployZilBridgeTokenManagers.s.sol +++ b/smart-contracts/script/bsc-testnet/deployZilBridgeTokenManagers.s.sol @@ -42,7 +42,7 @@ contract deployZilBridgeTokenManagers is Script, LockProxyTokenManagerDeployer, // 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)); + console.log("bsc_zilBridgeTokenManager: %s", address(tokenManager)); vm.stopBroadcast(); vm.startBroadcast(bridgePrivateKey); extendCCM.forciblyAddExtension(address(lockProxy), address(tokenManager), COUNTERPART_CHAIN_ID); diff --git a/smart-contracts/script/bsc-testnet/deployZilBridgeTokens.s.sol b/smart-contracts/script/bsc-testnet/deployZilBridgeTokens.s.sol index d4161f9..fb3e28b 100644 --- a/smart-contracts/script/bsc-testnet/deployZilBridgeTokens.s.sol +++ b/smart-contracts/script/bsc-testnet/deployZilBridgeTokens.s.sol @@ -8,6 +8,7 @@ import {BridgedToken} from "contracts/periphery/BridgedToken.sol"; import { ERC20 } from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH.sol"; import "forge-std/console.sol"; +import { TestnetConfig } from "script/testnet_config.s.sol"; contract MyERC20 is ERC20 { constructor(string memory name_, string memory symbol_, uint256 supply_) ERC20(name_, symbol_) { @@ -16,18 +17,13 @@ constructor(string memory name_, string memory symbol_, uint256 supply_) ERC20(n } -contract Deployment is Script { +contract Deployment is Script, TestnetConfig { function run() external { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); address owner = vm.addr(deployerPrivateKey); console.log("Owner is %s", owner); vm.startBroadcast(deployerPrivateKey); - // Address of the ZilBridge tokenmanager - // address tokenManagerAddress = 0x103617938D41f7bea62F0B5b4E8e50585083048F; - // Address of the lock proxy - address lockProxyAddress = 0x218D8aFE24bb2a0d1DE483Ff67aCADB45Ac8Bd2d; - // The other half of these tokens are deployed via the scilla-contracts/scripts/deploy.ts script. // Native on BSC @@ -38,11 +34,11 @@ contract Deployment is Script { console.log("ERC20: %s", address(theContract)); // Native on Zilliqa - SwitcheoToken bridgedFromZilliqa = new SwitcheoToken(lockProxyAddress, "Bridged ZTST", "eZTST", 18); + SwitcheoToken bridgedFromZilliqa = new SwitcheoToken(bsc_lockProxy, "Bridged ZTST", "eZTST", 18); console.log("BridgedZRC2FromZilliqa: %s", address(bridgedFromZilliqa)); // Bridged ZIL - SwitcheoToken bridgedZIL = new SwitcheoToken(lockProxyAddress, "eZIL", "Bridged ZIL", 12); + SwitcheoToken bridgedZIL = new SwitcheoToken(bsc_lockProxy, "eZIL", "Bridged ZIL", 12); console.log("BridgedZIL: %s", address(bridgedZIL)); } } diff --git a/smart-contracts/script/bsc-testnet/registerZilBridgeTokens.s.sol b/smart-contracts/script/bsc-testnet/registerZilBridgeTokens.s.sol deleted file mode 100644 index ba5c59d..0000000 --- a/smart-contracts/script/bsc-testnet/registerZilBridgeTokens.s.sol +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: MIT OR Apache-2.0 -pragma solidity ^0.8.20; - -import {Script} from "forge-std/Script.sol"; -import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol"; -import {ITokenManagerStructs} from "contracts/periphery/TokenManagerUpgradeable.sol"; -import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "forge-std/console.sol"; - -/*** @notice this script wires up the token manager for the zilbridge tests on zq_testnet. The corresponding code on Zilliqa is - * in a file of the same name in zq-testnet. - */ -contract Deployment is Script { - function run() external { - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); - address validator = vm.addr(deployerPrivateKey); - - // This is the LockAndReleaseOrNativeTokenManager token manager on zq-testnet. - address tokenManager = 0xBe90AB2cd65E207F097bEF733F8D239A59698b8A; - - // Native on BSC, bridged to Zilliqa - address nativeOnBSC = 0x43b1e04b72Aca6aA54c49f540Ef8ea3970d2A541; - - - - - // Native on BSC testnet, bridged to Zilliqa testnet. - address tokenContract = address(0x00839901f1e39De75301667C6bBbF7fB556Ea2510E); - // BSC, bridged to Zilliqa. - address bscBridgedToZilliqa = address(0x0006852e68A3c24917cfA4C2dbDaE4B308C69aDA5e); - // Native ZRC2 on Zilliqa, bridged to BSC. - address zrc2OnZilliqua = address(0x00155F0f76b660290F2F00Bb5674b80eDC208bF2e6); - - } -} diff --git a/smart-contracts/script/bsc-testnet/setZilBridgeRouting.s.sol b/smart-contracts/script/bsc-testnet/setZilBridgeRouting.s.sol index 65c50d5..e1a598d 100644 --- a/smart-contracts/script/bsc-testnet/setZilBridgeRouting.s.sol +++ b/smart-contracts/script/bsc-testnet/setZilBridgeRouting.s.sol @@ -10,13 +10,14 @@ import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH import "forge-std/console.sol"; import {LockProxyTokenManagerUpgradeable} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeable.sol"; import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol"; +import { TestnetConfig } from "script/testnet_config.s.sol"; /*** @title Route tokens from the BSC side. */ -contract Deployment is Script { +contract Deployment is Script, TestnetConfig { function run() external { - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); - address owner = vm.addr(deployerPrivateKey); + uint256 validatorPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); + address owner = vm.addr(validatorPrivateKey); console.log("Owner is %s", owner); // The BSC testnet chain id @@ -24,45 +25,36 @@ contract Deployment is Script { // Zilliqa chain id uint zilliqaChainId = 33101; - address bscERC20 = 0x43b1e04b72Aca6aA54c49f540Ef8ea3970d2A541; - address zilliqaBridgedERC20 = address(0x00839901f1e39De75301667C6bBbF7fB556Ea2510E); - - - address bscBridgedZRC2FromZilliqa = 0x190b6601E1D9bAF0c9413b08C27C5cBEa275D55F; - address zilliqaZRC2 = address(0x00155F0f76b660290F2F00Bb5674b80eDC208bF2e6); - - address bscBridgedZIL = 0x09AbdfE544Ca946808261ce761e1e86b91581C6c; - address zilliqaBridgedBNB = address(0x0006852e68A3c24917cfA4C2dbDaE4B308C69aDA5e); - - LockAndReleaseTokenManagerUpgradeable zilliqaTokenManager = LockAndReleaseTokenManagerUpgradeable(address(0x00Be90AB2cd65E207F097bEF733F8D239A59698b8A)); - LockProxyTokenManagerUpgradeable bscTokenManager = LockProxyTokenManagerUpgradeable(0x103617938D41f7bea62F0B5b4E8e50585083048F); + vm.startBroadcast(validatorPrivateKey); + LockAndReleaseTokenManagerUpgradeable zilliqaTokenManager = LockAndReleaseTokenManagerUpgradeable(zq_lockAndReleaseOrNativeTokenManager); + LockProxyTokenManagerUpgradeable bscTokenManager = LockProxyTokenManagerUpgradeable(bsc_zilBridgeTokenManager); // OK. Now set up the routing .. // When bscERC20 arrives at bscTokenManager, send it to zilliqaBridgedERC20 on zilliqaTokenManager ITokenManagerStructs.RemoteToken memory sourceBscERC20GasStruct = ITokenManagerStructs.RemoteToken({ - token: address(zilliqaBridgedERC20), + token: address(zq_bridged_erc20), tokenManager: address(zilliqaTokenManager), chainId: zilliqaChainId}); - bscTokenManager.registerToken(address(bscERC20), sourceBscERC20GasStruct); + bscTokenManager.registerToken(address(bsc_erc20), sourceBscERC20GasStruct); // When bscBridgedZRC2FromZilliqa arrives at bscTokenManager, send it to zilliqaZRC2 on zilliqaTokenManager ITokenManagerStructs.RemoteToken memory bridgedZRC2 = ITokenManagerStructs.RemoteToken({ - token: address(zilliqaZRC2), + token: address(zq_zrc2), tokenManager: address(zilliqaTokenManager), chainId: zilliqaChainId}); - bscTokenManager.registerToken(address(bscBridgedZRC2FromZilliqa), bridgedZRC2); + bscTokenManager.registerToken(address(bsc_bridgedzrc2), bridgedZRC2); // When bscBridgedZIL arrives at bscTokenManager, send it to 0 on zilliqaTokenManager ITokenManagerStructs.RemoteToken memory bridgedZIL = ITokenManagerStructs.RemoteToken({ token: address(0), tokenManager: address(zilliqaTokenManager), chainId: zilliqaChainId}); - bscTokenManager.registerToken(address(bscBridgedZIL), bridgedZIL); + bscTokenManager.registerToken(address(bsc_bridgedzil), bridgedZIL); // When BNB arrives at bscTokenManager, sent it to zilliqaBridgedBNB on zilliqaTokenManager ITokenManagerStructs.RemoteToken memory bridgedBNB = ITokenManagerStructs.RemoteToken({ - token: address(zilliqaBridgedBNB), + token: address(zq_bridged_bnb), tokenManager: address(zilliqaTokenManager), chainId: zilliqaChainId}); bscTokenManager.registerToken(address(0), bridgedBNB); diff --git a/smart-contracts/script/testnet_config.s.sol b/smart-contracts/script/testnet_config.s.sol index fed6b64..b77e10e 100644 --- a/smart-contracts/script/testnet_config.s.sol +++ b/smart-contracts/script/testnet_config.s.sol @@ -9,8 +9,19 @@ abstract contract TestnetConfig { address public constant bsc_lockProxy = 0x5B51e17837fc8F01b3C3ef29E882981e9414C159; // Can't be verified. address public constant bsc_extendCCM = 0x32ffa2C4c670A0fd0e94CF6457ac2FA7Ef007d55; + address public constant bsc_zilBridgeTokenManager = 0x36b8A9cd6Bf9bfA5984093005cf81CAfB1Bf06F7; + address public constant bsc_erc20 = 0x59A23d0957B63BC6c5682F211eE731513EECBB98; + address public constant bsc_bridgedzrc2 = 0x0d27244Ec509e7cbBde6d5c82DdD0e9F34873bF2; + address public constant bsc_bridgedzil = 0x33aC4ae9c514213a51D529114523Dd168c1d3b73; /// Deployed by XBridge testnet deployment address public constant bsc_chainGateway = 0xa9A14C90e53EdCD89dFd201A3bF94D867f8098fE; + address public constant zq_chainGateway = 0x7370e69565BB2313C4dA12F9062C282513919230; + address public constant zq_lockAndReleaseOrNativeTokenManager = 0xBe90AB2cd65E207F097bEF733F8D239A59698b8A; + + address public constant zq_bridged_erc20 = address(0x00839901f1e39De75301667C6bBbF7fB556Ea2510E); + address public constant zq_bridged_bnb = address(0x0006852e68A3c24917cfA4C2dbDaE4B308C69aDA5e); + address public constant zq_zrc2 = address(0x00155F0f76b660290F2F00Bb5674b80eDC208bF2e6); + } diff --git a/smart-contracts/script/zq-testnet/setZilBridgeRouting.s.sol b/smart-contracts/script/zq-testnet/setZilBridgeRouting.s.sol index e5b4aab..740fa74 100644 --- a/smart-contracts/script/zq-testnet/setZilBridgeRouting.s.sol +++ b/smart-contracts/script/zq-testnet/setZilBridgeRouting.s.sol @@ -10,52 +10,44 @@ import { SwitcheoToken } from "contracts/zilbridge/token/tokens/SwitcheoTokenETH import "forge-std/console.sol"; import {LockProxyTokenManagerUpgradeable} from "contracts/zilbridge/2/LockProxyTokenManagerUpgradeable.sol"; import {LockAndReleaseTokenManagerUpgradeable} from "contracts/periphery/LockAndReleaseTokenManagerUpgradeable.sol"; - +import { TestnetConfig } from "script/testnet_config.s.sol"; /*** @title Route tokens from the BSC side. */ -contract Deployment is Script { +contract Deployment is Script, TestnetConfig { function run() external { - uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); - address owner = vm.addr(deployerPrivateKey); - console.log("Owner is %s", owner); + uint256 validatorPrivateKey = vm.envUint("PRIVATE_KEY_TESTNET"); + address validator = vm.addr(validatorPrivateKey); + console.log("Owner is %s", validator); // The BSC testnet chain id (this is an XBridge ID, not a zilBridge one). uint bscChainId = 97; // Zilliqa chain id uint zilliqaChainId = 33101; - address bscERC20 = 0x43b1e04b72Aca6aA54c49f540Ef8ea3970d2A541; - address zilliqaBridgedERC20 = address(0x00839901f1e39De75301667C6bBbF7fB556Ea2510E); - - address bscBridgedZRC2FromZilliqa = 0x190b6601E1D9bAF0c9413b08C27C5cBEa275D55F; - address zilliqaZRC2 = address(0x00155F0f76b660290F2F00Bb5674b80eDC208bF2e6); - - address bscBridgedZIL = 0x09AbdfE544Ca946808261ce761e1e86b91581C6c; - address zilliqaBridgedBNB = address(0x0006852e68A3c24917cfA4C2dbDaE4B308C69aDA5e); - - LockAndReleaseTokenManagerUpgradeable zilliqaTokenManager = LockAndReleaseTokenManagerUpgradeable(address(0x00Be90AB2cd65E207F097bEF733F8D239A59698b8A)); - LockProxyTokenManagerUpgradeable bscTokenManager = LockProxyTokenManagerUpgradeable(0x103617938D41f7bea62F0B5b4E8e50585083048F); + vm.startBroadcast(validatorPrivateKey); + LockAndReleaseTokenManagerUpgradeable zilliqaTokenManager = LockAndReleaseTokenManagerUpgradeable(address(zq_lockAndReleaseOrNativeTokenManager)); + LockProxyTokenManagerUpgradeable bscTokenManager = LockProxyTokenManagerUpgradeable(bsc_zilBridgeTokenManager); // OK. Now set up the routing .. // When zilliqaBridgedERC20 arrives at zilliqaTokenManager, send it to bscERC20 on bscTokenManager ITokenManagerStructs.RemoteToken memory sourceBscERC20GasStruct = ITokenManagerStructs.RemoteToken({ - token: address(bscERC20), + token: address(bsc_erc20), tokenManager: address(bscTokenManager), chainId: bscChainId}); - zilliqaTokenManager.registerToken(address(zilliqaBridgedERC20), sourceBscERC20GasStruct); + zilliqaTokenManager.registerToken(address(zq_bridged_erc20), sourceBscERC20GasStruct); // When zilliqaZRC2 arrives at zilliqaTokenManager, send it to bscBridgedZRC2FromZilliqa on bscTokenManager ITokenManagerStructs.RemoteToken memory bridgedZRC2 = ITokenManagerStructs.RemoteToken({ - token: address(bscBridgedZRC2FromZilliqa), + token: address(bsc_bridgedzrc2), tokenManager: address(bscTokenManager), chainId: bscChainId}); - zilliqaTokenManager.registerToken(address(zilliqaZRC2), bridgedZRC2); + zilliqaTokenManager.registerToken(address(zq_zrc2), bridgedZRC2); // When ZIL arrives at zilliqaTokenManager, send it to bscBridgedZIL on bscTokenManager ITokenManagerStructs.RemoteToken memory bridgedZIL = ITokenManagerStructs.RemoteToken({ - token: address(bscBridgedZIL), + token: address(bsc_bridgedzil), tokenManager: address(bscTokenManager), chainId: bscChainId}); zilliqaTokenManager.registerToken(address(0), bridgedZIL); @@ -65,7 +57,7 @@ contract Deployment is Script { token: address(0), tokenManager: address(bscTokenManager), chainId: bscChainId}); - zilliqaTokenManager.registerToken(address(zilliqaBridgedBNB), bridgedBNB); + zilliqaTokenManager.registerToken(address(zq_bridged_bnb), bridgedBNB); } }