Skip to content

Commit

Permalink
(feat) Deploy to polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw-zilliqa committed Dec 20, 2024
1 parent 028da62 commit 4b64fac
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 3 deletions.
15 changes: 12 additions & 3 deletions docs/zilbridge_to_xbridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ forge script script/bsc/deploy/deployLockProxyProxy.s.sol --rpc-url rpc --broadc
forge verify-contract <address> --rpc-url rpc --chain-id 56
```

Polygon Amoy
Polygon

```
export PRIVATE_KEY_OWNER=<p>
export ETHERSCAN_API_KEY=<p>
forge script script/pol/deploy/deployLockProxyProxy.s.sol --rpc-url rpc --broadcast --chain-id 56 --verify
forge verify-contract <address> --rpc-url rpc --chain-id 56
forge script script/pol/deploy/deployLockProxyProxy.s.sol --rpc-url rpc --broadcast --chain-id 137 --verify
forge verify-contract <address> --rpc-url rpc --chain-id 137
```

Zil
Expand Down Expand Up @@ -75,6 +75,15 @@ forge script script/bsc/deploy/02_deployZilbridgeTokenManagers.s.sol --rpc-url $
forge script script/bsc/deploy/03_registerLockProxy.s.sol --rpc-url ${BSC_RPC_URL} --broadcast --chain-id 56 --verify --legacy
```

## pol

This requires the core to be deployed as well as the token managers.

```
export ETHERSCAN_API_KEY=...
export POL_RPC_URL=..
forge script script/pol/deploy/02_deployCoreUpgradeable.s.sol --rpc-url ${POL_RPC_URL} --broadcast --chain-id 137 --verify
Expand Down
20 changes: 20 additions & 0 deletions smart-contracts/script/bsc/admin/getValidators.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {ValidatorManager} from "contracts/core/ValidatorManager.sol";
import {ChainGateway} from "contracts/core/ChainGateway.sol";
import "forge-std/console.sol";
import "script/mainnetConfig.s.sol";

contract GetValidators is Script, MainnetConfig {
function run() external {
ChainGateway cg = ChainGateway(bscChainGatewayAddress);
ValidatorManager vm = ValidatorManager(cg.validatorManager());
console.log("Validator manager = %x", address(vm));
address[] memory validators = vm.getValidators();
for (uint256 i =0 ;i < validators.length; ++i) {
console.log("validator[%d] = %x", i, validators[i]);
}
}
}
6 changes: 6 additions & 0 deletions smart-contracts/script/mainnetConfig.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ abstract contract MainnetConfig {

address public constant polLockProxy = 0x43138036d1283413035B8eca403559737E8f7980;
address public constant polLockProxyProxy = 0x9121A67cA79B6778eAb477c5F76dF6de7C79cC4b;
address public constant polChainGatewayAddress = 0x796d796F28b3dB5287e560dDf75BC9B00F0CD609;
address public constant polLockAndReleaseOrNativeTokenManagerUpgradeable = 0x7519550ae8b6f9d32E9c1A939Fb5C186f660BE5b;
address public constant polLockProxyTokenManager = 0x3faC7cb5b45A3B59d76b6926bc704Cf3cc522437;



address public constant arbLockProxy = 0xb1E6F8820826491FCc5519f84fF4E2bdBb6e3Cad;
address public constant arbLockProxyProxy = 0x405e42de24Dc4894dB22595D041EBb170dC21D60;
address public constant ethLockProxy = 0x9a016Ce184a22DbF6c17daA59Eb7d3140DBd1c54;
Expand Down
69 changes: 69 additions & 0 deletions smart-contracts/script/pol/deploy/02_deployCoreUpgradeable.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.20;

import {Script} from "forge-std/Script.sol";
import {ValidatorManagerUpgradeable} from "contracts/core-upgradeable/ValidatorManagerUpgradeable.sol";
import {ChainGatewayUpgradeable} from "contracts/core-upgradeable/ChainGatewayUpgradeable.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/console.sol";

contract Deployment is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_OWNER");
address owner = vm.addr(deployerPrivateKey);
console.log("Owner is %s", owner);
address validator = address(0x250572Ed005BaD64Ff24FbDc0d41875dAF58944f);
console.log("Validator is %s", validator);

address[] memory validators = new address[](1);
validators[0] = owner;

vm.startBroadcast(deployerPrivateKey);

// Deploy Validator Manager
address vmImplementation = address(
new ValidatorManagerUpgradeable{salt: "pol"}()
);
bytes memory vmInitCall = abi.encodeWithSelector(
ValidatorManagerUpgradeable.initialize.selector,
owner,
validators
);
address vmProxy = address(
new ERC1967Proxy{salt: "pol"}(vmImplementation, vmInitCall)
);
ValidatorManagerUpgradeable validatorManager = ValidatorManagerUpgradeable(
vmProxy
);
console.log(
"ValidatorManager Deployed: %s, owner is validator: %s, and size %s",
address(validatorManager),
validatorManager.isValidator(validators[0]),
validatorManager.validatorsSize()
);

// Deploy Chain Gateway
address cgImplementation = address(
new ChainGatewayUpgradeable{salt: "pol"}()
);
bytes memory cgInitCall = abi.encodeWithSelector(
ChainGatewayUpgradeable.initialize.selector,
address(validatorManager),
owner
);
address cgProxy = address(
new ERC1967Proxy{salt: "pol"}(cgImplementation, cgInitCall)
);
ChainGatewayUpgradeable chainGateway = ChainGatewayUpgradeable(cgProxy);
console.log(
"ChainGateway Deployed: %s, with validatorManager %s",
address(chainGateway),
address(chainGateway.validatorManager())
);

console.log("polChainGatewayAddress = %s;", address(chainGateway));
console.log("polValidatorManager = %s;", address(validatorManager));

vm.stopBroadcast();
}
}
23 changes: 23 additions & 0 deletions smart-contracts/script/pol/deploy/03_deployTokenManagers.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 {LockProxyTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import {LockAndReleaseOrNativeTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol";
import { MainnetConfig } from "script/mainnetConfig.s.sol";
import { TokenManagerDeployerUtil } from "script/tokenManagerDeployerUtil.s.sol";

contract deployZilbridgeTokenManagers is Script, MainnetConfig, TokenManagerDeployerUtil {
function run() external {
// 0.00025 ZIL
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_OWNER");
uint fees = 0.00025 ether;
vm.startBroadcast(deployerPrivateKey);
LockAndReleaseOrNativeTokenManagerUpgradeableV3 lockAndReleaseOrNativeTokenManager = deployLockAndReleaseOrNativeTokenManager(polChainGatewayAddress, fees);
LockProxyTokenManagerUpgradeableV3 lockProxyTokenManager = deployLockProxyTokenManager(polChainGatewayAddress, fees);
console.log(" polLockAndReleaseOrNativeTokenManagerUpgradeable = %s;", address(lockAndReleaseOrNativeTokenManager));
console.log(" polLockProxyTokenManager = %s;", address(lockProxyTokenManager));
vm.stopBroadcast();
}
}
26 changes: 26 additions & 0 deletions smart-contracts/script/pol/deploy/04_registerTokenManagers.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 {LockProxyTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockProxyTokenManagerUpgradeableV3.sol";
import {LockAndReleaseOrNativeTokenManagerUpgradeableV3} from "contracts/periphery/TokenManagerV3/LockAndReleaseOrNativeTokenManagerUpgradeableV3.sol";
import {ChainGatewayUpgradeable} from "contracts/core-upgradeable/ChainGatewayUpgradeable.sol";
import { MainnetConfig } from "script/mainnetConfig.s.sol";

contract registerLockProxy is Script, MainnetConfig {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY_OWNER");
vm.startBroadcast(deployerPrivateKey);
// The lock proxy token manager needs to know where its lock proxy is.
LockProxyTokenManagerUpgradeableV3 lockProxyTokenManager = LockProxyTokenManagerUpgradeableV3(payable(polLockProxyTokenManager));
LockAndReleaseOrNativeTokenManagerUpgradeableV3 lockAndReleaseOrNativeTokenManager = LockAndReleaseOrNativeTokenManagerUpgradeableV3(payable(polLockAndReleaseOrNativeTokenManagerUpgradeable));
ChainGatewayUpgradeable chainGateway = ChainGatewayUpgradeable(polChainGatewayAddress);

lockProxyTokenManager.setLockProxyData(polLockProxy, polLockProxyProxy);
chainGateway.register(address(lockProxyTokenManager));
chainGateway.register(address(lockAndReleaseOrNativeTokenManager));
vm.stopBroadcast();
}

}

0 comments on commit 4b64fac

Please sign in to comment.