|
| 1 | +import { task } from "hardhat/config"; |
| 2 | + |
| 3 | +import { getNetworksConfig } from "../../test/deployments"; |
| 4 | +import { DEPLOYMENTS } from "../types"; |
| 5 | + |
| 6 | +const EMPTY_SET_RESOURCE_DATA = "0x"; |
| 7 | + |
| 8 | +task("configure-sygma", "Configures all Sygma contracts after deployments") |
| 9 | + .addParam("file", "Environment for which you want to configure Sygma") |
| 10 | + .setAction(async (_, hre) => { |
| 11 | + const networksConfig = getNetworksConfig(); |
| 12 | + const currentNetworkConfig = networksConfig[hre.network.name]; |
| 13 | + // remove the current network from networks config |
| 14 | + delete networksConfig[hre.network.name]; |
| 15 | + |
| 16 | + const accessSegregatorDeployment = await hre.deployments.get( |
| 17 | + DEPLOYMENTS.AccessSegregator, |
| 18 | + ); |
| 19 | + const accessControlInstance = await hre.ethers.getContractAt( |
| 20 | + DEPLOYMENTS.AccessSegregator, |
| 21 | + accessSegregatorDeployment.address, |
| 22 | + ); |
| 23 | + |
| 24 | + const spectreProxyDeployment = await hre.deployments.get( |
| 25 | + DEPLOYMENTS.SpectreProxy, |
| 26 | + ); |
| 27 | + const spectreProxyInstance = await hre.ethers.getContractAt( |
| 28 | + DEPLOYMENTS.SpectreProxy, |
| 29 | + spectreProxyDeployment.address, |
| 30 | + ); |
| 31 | + |
| 32 | + const bridgeDeployment = await hre.deployments.get(DEPLOYMENTS.Bridge); |
| 33 | + const bridgeInstance = await hre.ethers.getContractAt( |
| 34 | + DEPLOYMENTS.Bridge, |
| 35 | + bridgeDeployment.address, |
| 36 | + ); |
| 37 | + |
| 38 | + const erc20HandlerDeployment = await hre.deployments.get( |
| 39 | + DEPLOYMENTS.ERC20Handler, |
| 40 | + ); |
| 41 | + const erc20HandlerInstance = await hre.ethers.getContractAt( |
| 42 | + DEPLOYMENTS.ERC20Handler, |
| 43 | + erc20HandlerDeployment.address, |
| 44 | + ); |
| 45 | + |
| 46 | + const executorDeployment = await hre.deployments.get(DEPLOYMENTS.Executor); |
| 47 | + const executorInstance = await hre.ethers.getContractAt( |
| 48 | + DEPLOYMENTS.Executor, |
| 49 | + executorDeployment.address, |
| 50 | + ); |
| 51 | + |
| 52 | + await spectreProxyInstance.adminSetSpectreAddress( |
| 53 | + currentNetworkConfig.domainID, |
| 54 | + currentNetworkConfig.specterAddress, |
| 55 | + ); |
| 56 | + |
| 57 | + await bridgeInstance.adminChangeRouterAddress( |
| 58 | + currentNetworkConfig.routerAddress, |
| 59 | + ); |
| 60 | + |
| 61 | + await bridgeInstance.adminChangeExecutorAddress( |
| 62 | + currentNetworkConfig.executorAddress, |
| 63 | + ); |
| 64 | + |
| 65 | + for (const network of Object.values(networksConfig)) { |
| 66 | + await executorInstance.adminChangeSlotIndex( |
| 67 | + network.domainID, |
| 68 | + network.slotIndex, |
| 69 | + ); |
| 70 | + |
| 71 | + await executorInstance.adminSetVerifiers( |
| 72 | + network.securityModel, |
| 73 | + network.verifiersAddresses, |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + for (const erc20Token of currentNetworkConfig.erc20) { |
| 78 | + const erc20HandlerAddress = await erc20HandlerInstance.getAddress(); |
| 79 | + const erc20TokenInstance = await hre.ethers.getContractAt( |
| 80 | + "ERC20PresetMinterPauser", |
| 81 | + erc20Token.address, |
| 82 | + ); |
| 83 | + |
| 84 | + await bridgeInstance.adminSetResource( |
| 85 | + erc20HandlerAddress, |
| 86 | + erc20Token.resourceID, |
| 87 | + await erc20TokenInstance.getAddress(), |
| 88 | + EMPTY_SET_RESOURCE_DATA, |
| 89 | + ); |
| 90 | + |
| 91 | + // strategy can be either mb (mint/burn) or lr (lock/release) |
| 92 | + if (erc20Token.strategy == "mb") { |
| 93 | + await erc20TokenInstance.grantRole( |
| 94 | + await erc20TokenInstance.MINTER_ROLE(), |
| 95 | + erc20HandlerAddress, |
| 96 | + ); |
| 97 | + await bridgeInstance.adminSetBurnable( |
| 98 | + erc20HandlerAddress, |
| 99 | + erc20Token.address, |
| 100 | + ); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + // check json config if func access right should be renounced |
| 105 | + const reannounceAdminAddress = process.env.FUNCTIONS_ACCESS_ADMIN_ADDRESS; |
| 106 | + if (reannounceAdminAddress) { |
| 107 | + for (const [func, admin] of Object.entries( |
| 108 | + currentNetworkConfig.access.accessControl, |
| 109 | + )) { |
| 110 | + console.log("Granting access for function %s to %s", func, admin); |
| 111 | + await accessControlInstance.grantAccess(func, admin); |
| 112 | + console.log( |
| 113 | + `Granted all admin functions rights to: ${reannounceAdminAddress}`, |
| 114 | + ); |
| 115 | + await accessControlInstance.grantAccess(func, admin); |
| 116 | + } |
| 117 | + } |
| 118 | + console.log("Sygma-x successfully configured"); |
| 119 | + }); |
0 commit comments