|
| 1 | +import { config as dotenvConfig } from "dotenv"; |
| 2 | +import { |
| 3 | + CORE_CONTRACTS, |
| 4 | + ChainSlug, |
| 5 | + ChainSocketAddresses, |
| 6 | + DeploymentAddresses, |
| 7 | + ROLES, |
| 8 | + getAllAddresses, |
| 9 | + isMainnet, |
| 10 | + isTestnet, |
| 11 | +} from "../../../src"; |
| 12 | +import { |
| 13 | + executionManagerVersion, |
| 14 | + mode, |
| 15 | + ownerAddresses, |
| 16 | +} from "../../deploy/config/config"; |
| 17 | +import { Wallet, ethers } from "ethers"; |
| 18 | +import { checkAndUpdateRoles } from "../../deploy/scripts/roles"; |
| 19 | +import { sleep } from "@socket.tech/dl-common"; |
| 20 | + |
| 21 | +dotenvConfig(); |
| 22 | + |
| 23 | +/** |
| 24 | + * Usage |
| 25 | + * |
| 26 | + * --sendtx Send nominate tx along with ownership check. |
| 27 | + * Default is only check owner, nominee. |
| 28 | + * Eg. npx --sendtx ts-node scripts/admin/rotate-owner/3-migrate-roles-to-multisig.ts |
| 29 | + * |
| 30 | + * --chains Run only for specified chains. |
| 31 | + * Default is all chains. |
| 32 | + * Eg. npx --chains=10,2999 ts-node scripts/admin/rotate-owner/3-migrate-roles-to-multisig.ts |
| 33 | + * |
| 34 | + * --testnets Run for testnets. |
| 35 | + * Default is false. |
| 36 | + */ |
| 37 | + |
| 38 | +const signerKey = process.env.SOCKET_SIGNER_KEY; |
| 39 | +if (!signerKey) { |
| 40 | + console.error("Error: SOCKET_SIGNER_KEY is required"); |
| 41 | +} |
| 42 | + |
| 43 | +const sendTransaction = process.env.npm_config_sendtx == "true"; |
| 44 | + |
| 45 | +const testnets = process.env.npm_config_testnets == "true"; |
| 46 | +const filterChainsParam = process.env.npm_config_chains |
| 47 | + ? process.env.npm_config_chains.split(",") |
| 48 | + : null; |
| 49 | + |
| 50 | +const addresses: DeploymentAddresses = getAllAddresses(mode); |
| 51 | +let allChainSlugs: string[]; |
| 52 | +if (testnets) |
| 53 | + allChainSlugs = Object.keys(addresses).filter((c) => isTestnet(parseInt(c))); |
| 54 | +else |
| 55 | + allChainSlugs = Object.keys(addresses).filter((c) => isMainnet(parseInt(c))); |
| 56 | + |
| 57 | +const filteredChainSlugs = !filterChainsParam |
| 58 | + ? allChainSlugs |
| 59 | + : allChainSlugs.filter((c) => filterChainsParam.includes(c)); |
| 60 | + |
| 61 | +const wallet: Wallet = new ethers.Wallet(signerKey); |
| 62 | +const signerAddress = wallet.address.toLowerCase(); |
| 63 | +const signingOwnerAddress = ownerAddresses[mode].toLowerCase(); |
| 64 | + |
| 65 | +if (signingOwnerAddress != signerAddress) { |
| 66 | + console.error("Error: signingOwnerAddress is not the same as signerAddress"); |
| 67 | + process.exit(1); |
| 68 | +} |
| 69 | + |
| 70 | +const sleepTime = 1; |
| 71 | +const summary: { params: any; roleStatus: any }[] = []; |
| 72 | + |
| 73 | +export const main = async () => { |
| 74 | + await Promise.all( |
| 75 | + filteredChainSlugs |
| 76 | + .map((c) => parseInt(c) as ChainSlug) |
| 77 | + .map(async (chainSlug) => { |
| 78 | + let chainAddresses: ChainSocketAddresses = addresses[chainSlug]; |
| 79 | + |
| 80 | + const safeAddress = chainAddresses["SocketSafeProxy"]; |
| 81 | + |
| 82 | + if (!safeAddress) { |
| 83 | + console.error(`Error: safeAddress not found for ${chainSlug}`); |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + const siblings = ( |
| 88 | + !!chainAddresses.integrations |
| 89 | + ? Object.keys(chainAddresses.integrations) |
| 90 | + : [] |
| 91 | + ).map((s) => parseInt(s) as ChainSlug); |
| 92 | + |
| 93 | + for (const contract of Object.keys(rolesToGrant)) { |
| 94 | + const roles = rolesToGrant[contract]; |
| 95 | + const s = await checkAndUpdateRoles( |
| 96 | + { |
| 97 | + userSpecificRoles: [ |
| 98 | + { |
| 99 | + userAddress: safeAddress, |
| 100 | + filterRoles: roles, |
| 101 | + }, |
| 102 | + ], |
| 103 | + contractName: contract as CORE_CONTRACTS, |
| 104 | + filterChains: [chainSlug], |
| 105 | + filterSiblingChains: siblings, |
| 106 | + safeChains: [chainSlug], |
| 107 | + sendTransaction, |
| 108 | + newRoleStatus: true, |
| 109 | + }, |
| 110 | + addresses |
| 111 | + ); |
| 112 | + |
| 113 | + summary.push(s); |
| 114 | + await sleep(sleepTime); |
| 115 | + } |
| 116 | + |
| 117 | + for (const contract of Object.keys(rolesToRevoke)) { |
| 118 | + const roles = rolesToRevoke[contract]; |
| 119 | + const s = await checkAndUpdateRoles( |
| 120 | + { |
| 121 | + userSpecificRoles: [ |
| 122 | + { |
| 123 | + userAddress: signingOwnerAddress, |
| 124 | + filterRoles: roles, |
| 125 | + }, |
| 126 | + ], |
| 127 | + contractName: contract as CORE_CONTRACTS, |
| 128 | + filterChains: [chainSlug], |
| 129 | + filterSiblingChains: siblings, |
| 130 | + safeChains: [chainSlug], |
| 131 | + sendTransaction, |
| 132 | + newRoleStatus: false, |
| 133 | + }, |
| 134 | + addresses |
| 135 | + ); |
| 136 | + |
| 137 | + summary.push(s); |
| 138 | + await sleep(sleepTime); |
| 139 | + } |
| 140 | + }) |
| 141 | + ); |
| 142 | + |
| 143 | + console.log(JSON.stringify(summary)); |
| 144 | +}; |
| 145 | + |
| 146 | +const rolesToGrant = { |
| 147 | + [executionManagerVersion]: [ |
| 148 | + ROLES.RESCUE_ROLE, |
| 149 | + ROLES.GOVERNANCE_ROLE, |
| 150 | + ROLES.WITHDRAW_ROLE, |
| 151 | + ROLES.FEES_UPDATER_ROLE, |
| 152 | + ], |
| 153 | + [CORE_CONTRACTS.TransmitManager]: [ |
| 154 | + ROLES.RESCUE_ROLE, |
| 155 | + ROLES.GOVERNANCE_ROLE, |
| 156 | + ROLES.WITHDRAW_ROLE, |
| 157 | + ROLES.FEES_UPDATER_ROLE, |
| 158 | + ], |
| 159 | + [CORE_CONTRACTS.Socket]: [ROLES.RESCUE_ROLE, ROLES.GOVERNANCE_ROLE], |
| 160 | + [CORE_CONTRACTS.FastSwitchboard]: [ |
| 161 | + ROLES.RESCUE_ROLE, |
| 162 | + ROLES.GOVERNANCE_ROLE, |
| 163 | + ROLES.TRIP_ROLE, |
| 164 | + ROLES.UN_TRIP_ROLE, |
| 165 | + ROLES.WITHDRAW_ROLE, |
| 166 | + ROLES.FEES_UPDATER_ROLE, |
| 167 | + ], |
| 168 | + [CORE_CONTRACTS.OptimisticSwitchboard]: [ |
| 169 | + ROLES.TRIP_ROLE, |
| 170 | + ROLES.UN_TRIP_ROLE, |
| 171 | + ROLES.RESCUE_ROLE, |
| 172 | + ROLES.GOVERNANCE_ROLE, |
| 173 | + ROLES.FEES_UPDATER_ROLE, |
| 174 | + ], |
| 175 | + [CORE_CONTRACTS.NativeSwitchboard]: [ |
| 176 | + ROLES.TRIP_ROLE, |
| 177 | + ROLES.UN_TRIP_ROLE, |
| 178 | + ROLES.GOVERNANCE_ROLE, |
| 179 | + ROLES.WITHDRAW_ROLE, |
| 180 | + ROLES.RESCUE_ROLE, |
| 181 | + ROLES.FEES_UPDATER_ROLE, |
| 182 | + ], |
| 183 | +}; |
| 184 | + |
| 185 | +const rolesToRevoke = { |
| 186 | + [executionManagerVersion]: [ |
| 187 | + ROLES.RESCUE_ROLE, |
| 188 | + ROLES.GOVERNANCE_ROLE, |
| 189 | + ROLES.WITHDRAW_ROLE, |
| 190 | + ], |
| 191 | + [CORE_CONTRACTS.TransmitManager]: [ |
| 192 | + ROLES.RESCUE_ROLE, |
| 193 | + ROLES.GOVERNANCE_ROLE, |
| 194 | + ROLES.WITHDRAW_ROLE, |
| 195 | + ], |
| 196 | + [CORE_CONTRACTS.Socket]: [ROLES.RESCUE_ROLE, ROLES.GOVERNANCE_ROLE], |
| 197 | + [CORE_CONTRACTS.FastSwitchboard]: [ |
| 198 | + ROLES.RESCUE_ROLE, |
| 199 | + ROLES.GOVERNANCE_ROLE, |
| 200 | + ROLES.WITHDRAW_ROLE, |
| 201 | + ], |
| 202 | + [CORE_CONTRACTS.OptimisticSwitchboard]: [ |
| 203 | + ROLES.RESCUE_ROLE, |
| 204 | + ROLES.GOVERNANCE_ROLE, |
| 205 | + ], |
| 206 | + [CORE_CONTRACTS.NativeSwitchboard]: [ |
| 207 | + ROLES.GOVERNANCE_ROLE, |
| 208 | + ROLES.WITHDRAW_ROLE, |
| 209 | + ROLES.RESCUE_ROLE, |
| 210 | + ], |
| 211 | +}; |
| 212 | + |
| 213 | +main() |
| 214 | + .then(() => process.exit(0)) |
| 215 | + .catch((error: Error) => { |
| 216 | + console.error(error); |
| 217 | + process.exit(1); |
| 218 | + }); |
0 commit comments