Skip to content

Commit

Permalink
(feat) Ignore validator binaries
Browse files Browse the repository at this point in the history
(fix) Fix routing scripts.
(feat) Centralise configuration
  • Loading branch information
rrw-zilliqa committed Jul 18, 2024
1 parent 5404b25 commit af55bd7
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 99 deletions.
1 change: 1 addition & 0 deletions bridge-validators/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
6 changes: 3 additions & 3 deletions docs/zilbridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ forge verify-contract <address> --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 <address> --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 <address> --rpc-url https://bsc-testnet.bnbchain.org --chain-id 97

```
Expand Down Expand Up @@ -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
```



Expand Down
16 changes: 7 additions & 9 deletions smart-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 4 additions & 8 deletions smart-contracts/script/bsc-testnet/deployZilBridgeTokens.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand All @@ -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
Expand All @@ -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));
}
}
35 changes: 0 additions & 35 deletions smart-contracts/script/bsc-testnet/registerZilBridgeTokens.s.sol

This file was deleted.

34 changes: 13 additions & 21 deletions smart-contracts/script/bsc-testnet/setZilBridgeRouting.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,51 @@ 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
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(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);
Expand Down
11 changes: 11 additions & 0 deletions smart-contracts/script/testnet_config.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
36 changes: 14 additions & 22 deletions smart-contracts/script/zq-testnet/setZilBridgeRouting.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

0 comments on commit af55bd7

Please sign in to comment.