From 593c831ea30a9d5c4285477b49d379aa48d46169 Mon Sep 17 00:00:00 2001 From: Ameesha Agrawal Date: Wed, 31 Jul 2024 02:02:02 +0530 Subject: [PATCH] feat: use socket signer in scripts --- scripts/admin/tripCommon.ts | 10 +++---- scripts/admin/untripPath.ts | 2 +- scripts/common/switchboards.ts | 1 - scripts/deploy/deploy.ts | 1 + scripts/deploy/em-migration/migrate-em.ts | 15 +++-------- scripts/deploy/scripts/configureSocket.ts | 22 +++++++-------- .../deploy/scripts/configureSwitchboards.ts | 15 +++-------- scripts/deploy/scripts/connect.ts | 16 ++++------- scripts/deploy/scripts/deploySocket.ts | 20 +++++++++++--- scripts/deploy/scripts/deploySocketFor.ts | 16 +++++------ scripts/deploy/scripts/deploySwitchboard.ts | 10 +++---- scripts/deploy/scripts/registerSwitchboard.ts | 5 ++-- scripts/deploy/scripts/roles.ts | 27 +++++++++++-------- scripts/deploy/utils/utils.ts | 6 ++--- src/socket-types.ts | 3 +++ 15 files changed, 80 insertions(+), 89 deletions(-) diff --git a/scripts/admin/tripCommon.ts b/scripts/admin/tripCommon.ts index 7f2625e12..5611d5121 100644 --- a/scripts/admin/tripCommon.ts +++ b/scripts/admin/tripCommon.ts @@ -1,4 +1,4 @@ -import { BigNumberish, Contract, Wallet, utils } from "ethers"; +import { BigNumberish } from "ethers"; import { IntegrationTypes, ChainSlug, @@ -6,12 +6,8 @@ import { isTestnet, isMainnet, } from "../../src"; -import { mode, overrides } from "../deploy/config/config"; -import { - getAllAddresses, - DeploymentAddresses, - ROLES, -} from "@socket.tech/dl-core"; +import { mode } from "../deploy/config/config"; +import { getAllAddresses, DeploymentAddresses } from "@socket.tech/dl-core"; import dotenv from "dotenv"; dotenv.config(); diff --git a/scripts/admin/untripPath.ts b/scripts/admin/untripPath.ts index 6480d1c84..aad8d83c7 100644 --- a/scripts/admin/untripPath.ts +++ b/scripts/admin/untripPath.ts @@ -1,4 +1,4 @@ -import { Contract, Wallet, utils } from "ethers"; +import { Contract } from "ethers"; import { IntegrationTypes, ChainSlug } from "../../src"; import { mode, overrides } from "../deploy/config/config"; import { arrayify, defaultAbiCoder, keccak256 } from "ethers/lib/utils"; diff --git a/scripts/common/switchboards.ts b/scripts/common/switchboards.ts index 2daeea209..041aabab1 100644 --- a/scripts/common/switchboards.ts +++ b/scripts/common/switchboards.ts @@ -9,7 +9,6 @@ import { import { getProviderFromChainSlug } from "../constants"; import FastSwitchboardABI from "@socket.tech/dl-core/artifacts/abi/FastSwitchboard.json"; import NativeSwitchboardABI from "@socket.tech/dl-core/artifacts/abi/NativeSwitchboardBase.json"; -import { ROLES } from "@socket.tech/dl-core"; import { getRoleHash } from "../deploy/utils/utils"; const sbContracts: { [key: string]: Contract } = {}; diff --git a/scripts/deploy/deploy.ts b/scripts/deploy/deploy.ts index 2acec3a6b..cda6fe88c 100644 --- a/scripts/deploy/deploy.ts +++ b/scripts/deploy/deploy.ts @@ -52,6 +52,7 @@ const main = async () => { console.log("No siblings selected!"); return; } + await configureRoles(addresses, chains, true, executionManagerVersion); addresses = await configureSwitchboards( addresses, diff --git a/scripts/deploy/em-migration/migrate-em.ts b/scripts/deploy/em-migration/migrate-em.ts index d3091ce2b..1c0eee245 100644 --- a/scripts/deploy/em-migration/migrate-em.ts +++ b/scripts/deploy/em-migration/migrate-em.ts @@ -22,10 +22,9 @@ import { configureExecutionManager, setManagers, } from "../scripts/configureSocket"; -import { Wallet } from "ethers"; -import { getProviderFromChainSlug } from "../../constants"; import { storeAllAddresses } from "../utils"; -import { getSiblingsFromAddresses } from "../../common"; +import { SocketSigner } from "@socket.tech/dl-common"; +import { getSocketSigner } from "../utils/socket-signer"; const emVersion = CORE_CONTRACTS.ExecutionManagerDF; @@ -36,15 +35,9 @@ export const configureExecutionManagers = async ( try { await Promise.all( chains.map(async (chain) => { - const providerInstance = getProviderFromChainSlug( - chain as any as ChainSlug - ); - const socketSigner: Wallet = new Wallet( - process.env.SOCKET_SIGNER_KEY as string, - providerInstance - ); - let addr: ChainSocketAddresses = addresses[chain]!; + const socketSigner: SocketSigner = await getSocketSigner(chain, addr); + const siblingSlugs = chains.filter((c) => c !== chain); await configureExecutionManager( diff --git a/scripts/deploy/scripts/configureSocket.ts b/scripts/deploy/scripts/configureSocket.ts index a5dbac8f4..bee867ba7 100644 --- a/scripts/deploy/scripts/configureSocket.ts +++ b/scripts/deploy/scripts/configureSocket.ts @@ -1,6 +1,6 @@ -import { Wallet, constants } from "ethers"; +import { constants } from "ethers"; -import { getProviderFromChainSlug, switchboards } from "../../constants"; +import { switchboards } from "../../constants"; import { getInstance, getSwitchboardAddress } from "../utils"; import { CORE_CONTRACTS, @@ -19,6 +19,8 @@ import { overrides, msgValueMaxThreshold, } from "../config/config"; +import { SocketSigner } from "@socket.tech/dl-common"; +import { getSocketSigner } from "../utils/socket-signer"; export const registerSwitchboards = async ( chain: ChainSlug, @@ -27,7 +29,7 @@ export const registerSwitchboards = async ( integrationType: IntegrationTypes, addr: ChainSocketAddresses, addresses: DeploymentAddresses, - socketSigner: Wallet + socketSigner: SocketSigner ) => { for (let sibling of siblingSlugs) { const siblingSwitchboard = getSwitchboardAddress( @@ -55,7 +57,7 @@ export const registerSwitchboards = async ( export const setManagers = async ( addr: ChainSocketAddresses, - socketSigner: Wallet, + socketSigner: SocketSigner, executionManagerVersion: CORE_CONTRACTS ) => { const socket = ( @@ -90,7 +92,7 @@ export const configureExecutionManager = async ( socketBatcherAddress: string, chain: ChainSlug, siblingSlugs: ChainSlug[], - socketSigner: Wallet + socketSigner: SocketSigner ) => { try { console.log("configuring execution manager for ", chain, emAddress); @@ -174,13 +176,9 @@ export const setupPolygonNativeSwitchboard = async (addresses) => { await Promise.all( srcChains.map(async (srcChain: ChainSlug) => { console.log(`Configuring for ${srcChain}`); - - const providerInstance = getProviderFromChainSlug( - srcChain as any as ChainSlug - ); - const socketSigner: Wallet = new Wallet( - process.env.SOCKET_SIGNER_KEY as string, - providerInstance + const socketSigner: SocketSigner = await getSocketSigner( + srcChain, + addresses[srcChain] ); for (let dstChain in addresses[srcChain]?.["integrations"]) { diff --git a/scripts/deploy/scripts/configureSwitchboards.ts b/scripts/deploy/scripts/configureSwitchboards.ts index 8eafaf106..9e41c3c96 100644 --- a/scripts/deploy/scripts/configureSwitchboards.ts +++ b/scripts/deploy/scripts/configureSwitchboards.ts @@ -1,6 +1,3 @@ -import { Wallet } from "ethers"; - -import { getProviderFromChainSlug } from "../../constants"; import { storeAllAddresses } from "../utils"; import { CORE_CONTRACTS, @@ -21,6 +18,8 @@ import { setManagers, setupPolygonNativeSwitchboard, } from "./configureSocket"; +import { SocketSigner } from "@socket.tech/dl-common"; +import { getSocketSigner } from "../utils/socket-signer"; export const configureSwitchboards = async ( addresses: DeploymentAddresses, @@ -31,16 +30,8 @@ export const configureSwitchboards = async ( await Promise.all( chains.map(async (chain) => { if (!addresses[chain]) return; - - const providerInstance = getProviderFromChainSlug( - chain as any as ChainSlug - ); - const socketSigner: Wallet = new Wallet( - process.env.SOCKET_SIGNER_KEY as string, - providerInstance - ); - let addr: ChainSocketAddresses = addresses[chain]!; + const socketSigner: SocketSigner = await getSocketSigner(chain, addr); const list = isTestnet(chain) ? TestnetIds : MainnetIds; const siblingSlugs: ChainSlug[] = list.filter( diff --git a/scripts/deploy/scripts/connect.ts b/scripts/deploy/scripts/connect.ts index d3387d9da..b9a1d548e 100644 --- a/scripts/deploy/scripts/connect.ts +++ b/scripts/deploy/scripts/connect.ts @@ -1,7 +1,4 @@ -import { - getDefaultIntegrationType, - getProviderFromChainSlug, -} from "../../constants"; +import { getDefaultIntegrationType } from "../../constants"; import { getInstance } from "../utils"; import { ChainSlug, @@ -12,9 +9,10 @@ import { TestnetIds, isTestnet, } from "../../../src"; -import { Contract, Wallet } from "ethers"; +import { Contract } from "ethers"; import { getSwitchboardAddressFromAllAddresses } from "../../../src"; import { overrides } from "../config/config"; +import { getSocketSigner } from "../utils/socket-signer"; export const connectPlugs = async ( addresses: DeploymentAddresses, @@ -25,13 +23,9 @@ export const connectPlugs = async ( chains.map(async (chain) => { if (!addresses[chain]) return; - const providerInstance = getProviderFromChainSlug(chain); - const socketSigner: Wallet = new Wallet( - process.env.SOCKET_SIGNER_KEY as string, - providerInstance - ); - const addr: ChainSocketAddresses = addresses[chain]!; + const socketSigner = await getSocketSigner(chain, addr); + if (!addr["integrations"]) return; const list = isTestnet(chain) ? TestnetIds : MainnetIds; diff --git a/scripts/deploy/scripts/deploySocket.ts b/scripts/deploy/scripts/deploySocket.ts index 2d457d3e3..05a13568e 100644 --- a/scripts/deploy/scripts/deploySocket.ts +++ b/scripts/deploy/scripts/deploySocket.ts @@ -1,4 +1,4 @@ -import { Contract, Wallet, constants } from "ethers"; +import { Contract, constants } from "ethers"; import { DeployParams, getInstance, @@ -13,9 +13,9 @@ import { version, } from "../../../src"; import deploySwitchboards from "./deploySwitchboard"; -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { socketOwner, overrides } from "../config/config"; import { maxAllowedPacketLength } from "../../constants"; +import { SocketSigner } from "@socket.tech/dl-common"; let allDeployed = false; @@ -29,7 +29,7 @@ export interface ReturnObj { */ export const deploySocket = async ( executionManagerVersion: string, - socketSigner: SignerWithAddress | Wallet, + socketSigner: SocketSigner, chainSlug: number, currentMode: DeploymentMode, deployedAddresses: ChainSocketAddresses @@ -102,7 +102,7 @@ export const deploySocket = async ( // switchboards deploy deployUtils.addresses = await deploySwitchboards( chainSlug, - socketSigner, + socketSigner as SocketSigner, deployUtils.addresses, currentMode ); @@ -124,6 +124,18 @@ export const deploySocket = async ( ); deployUtils.addresses["Counter"] = counter.address; + // safe wrapper deployment + if (!deployUtils.addresses["Safe"]) + deployUtils.addresses["Safe"] = constants.AddressZero; + + const multisigWrapper: Contract = await getOrDeploy( + "Counter", + "contracts/utils/MultiSigWrapper.sol", + [socketOwner, deployUtils.addresses["Safe"]], + deployUtils + ); + deployUtils.addresses["MultiSigWrapper"] = multisigWrapper.address; + // simulators const socketSimulator: Contract = await getOrDeploy( "SocketSimulator", diff --git a/scripts/deploy/scripts/deploySocketFor.ts b/scripts/deploy/scripts/deploySocketFor.ts index fa2299980..adc42fd3b 100644 --- a/scripts/deploy/scripts/deploySocketFor.ts +++ b/scripts/deploy/scripts/deploySocketFor.ts @@ -1,7 +1,4 @@ -import { ethers } from "hardhat"; -import { Wallet } from "ethers"; import { ReturnObj, deploySocket } from "../scripts/deploySocket"; -import { getProviderFromChainSlug } from "../../constants"; import { ChainSlug, ChainSocketAddresses, @@ -10,6 +7,8 @@ import { } from "../../../src"; import { mode } from "../config/config"; import { storeAddresses } from "../utils"; +import { SocketSigner } from "@socket.tech/dl-common"; +import { getSocketSigner } from "../utils/socket-signer"; export const deployForChains = async ( chains: ChainSlug[], @@ -27,16 +26,15 @@ export const deployForChains = async ( chains.map(async (chain: ChainSlug) => { let allDeployed = false; - const providerInstance = getProviderFromChainSlug(chain); - const signer: Wallet = new ethers.Wallet( - process.env.SOCKET_SIGNER_KEY as string, - providerInstance - ); - let chainAddresses: ChainSocketAddresses = addresses[chain] ? (addresses[chain] as ChainSocketAddresses) : ({} as ChainSocketAddresses); + const signer: SocketSigner = await getSocketSigner( + chain, + chainAddresses + ); + while (!allDeployed) { const results: ReturnObj = await deploySocket( executionManagerVersion, diff --git a/scripts/deploy/scripts/deploySwitchboard.ts b/scripts/deploy/scripts/deploySwitchboard.ts index 58e67efac..b0fc15841 100644 --- a/scripts/deploy/scripts/deploySwitchboard.ts +++ b/scripts/deploy/scripts/deploySwitchboard.ts @@ -12,12 +12,11 @@ import { ChainSlug, } from "../../../src"; import { getSwitchboardDeployData } from "../switchboards"; -import { Wallet } from "ethers"; -import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { SocketSigner } from "@socket.tech/dl-common"; export default async function deploySwitchboards( chainSlug: ChainSlug, - signer: SignerWithAddress | Wallet, + signer: SocketSigner, sourceConfig: ChainSocketAddresses, mode: DeploymentMode ): Promise { @@ -71,18 +70,19 @@ async function deploySwitchboard( integrationType: IntegrationTypes, chainSlug: ChainSlug, remoteChain: ChainSlug | string, - signer: SignerWithAddress | Wallet, + signer: SocketSigner, sourceConfig: ChainSocketAddresses, mode: DeploymentMode ): Promise { try { + let signerAddress: string = await signer.getAddress(); const { contractName, args, path } = getSwitchboardDeployData( integrationType, chainSlug, remoteChain, sourceConfig[CORE_CONTRACTS.Socket], sourceConfig[CORE_CONTRACTS.SignatureVerifier], - signer.address + signerAddress ); const switchboard = await deployContractWithArgs( diff --git a/scripts/deploy/scripts/registerSwitchboard.ts b/scripts/deploy/scripts/registerSwitchboard.ts index 9dd22a2be..c4249700f 100644 --- a/scripts/deploy/scripts/registerSwitchboard.ts +++ b/scripts/deploy/scripts/registerSwitchboard.ts @@ -1,9 +1,10 @@ -import { Wallet, constants } from "ethers"; +import { constants } from "ethers"; import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { createObj, getInstance } from "../utils"; import { ChainSlug, ChainSocketAddresses } from "../../../src"; import { initialPacketCount, overrides } from "../config/config"; +import { SocketSigner } from "@socket.tech/dl-common"; export default async function registerSwitchboardForSibling( switchBoardAddress: string, @@ -11,7 +12,7 @@ export default async function registerSwitchboardForSibling( remoteChainSlug: string | ChainSlug, capacitorType: number, maxPacketLength: number, - signer: Wallet | SignerWithAddress, + signer: SocketSigner | SignerWithAddress, integrationType: string, config: ChainSocketAddresses ) { diff --git a/scripts/deploy/scripts/roles.ts b/scripts/deploy/scripts/roles.ts index d77054065..be4a957ee 100644 --- a/scripts/deploy/scripts/roles.ts +++ b/scripts/deploy/scripts/roles.ts @@ -16,10 +16,12 @@ import { DeploymentAddresses, } from "../../../src"; import { getRoleHash, getChainRoleHash, getInstance } from "../utils"; -import { Wallet, ethers } from "ethers"; +import { ethers } from "ethers"; import { getProviderFromChainSlug } from "../../constants"; import { overrides } from "../config/config"; import AccessControlExtendedABI from "@socket.tech/dl-core/artifacts/abi/AccessControlExtended.json"; +import { SocketSigner } from "@socket.tech/dl-common"; +import { getSocketSigner } from "../utils/socket-signer"; let roleStatus: any = {}; @@ -104,7 +106,7 @@ const getRoleTxnData = ( const executeRoleTransactions = async ( chainSlug: ChainSlug, newRoleStatus: boolean, - wallet: Wallet + socketSigner: SocketSigner ) => { if (!roleTxns[chainSlug]) return; let contracts = Object.keys(roleTxns[chainSlug]!); @@ -141,7 +143,7 @@ const executeRoleTransactions = async ( } else { data = getRoleTxnData(roles, slugs, addresses, "REVOKE"); } - let tx = await wallet.sendTransaction({ + let tx = await socketSigner.sendTransaction({ to: contractAddress, data, ...overrides(chainSlug), @@ -160,14 +162,14 @@ const executeRoleTransactions = async ( const executeOtherTransactions = async ( chainSlug: ChainSlug, - wallet: Wallet + socketSigner: SocketSigner ) => { if (!otherTxns[chainSlug as any as keyof typeof otherTxns]) return; let txnDatas = otherTxns[chainSlug as any as keyof typeof otherTxns]!; for (let i = 0; i < txnDatas.length; i++) { let { to, data } = txnDatas[i]; - let tx = await wallet.sendTransaction({ + let tx = await socketSigner.sendTransaction({ to, data, ...overrides(chainSlug), @@ -180,14 +182,17 @@ const executeOtherTransactions = async ( const executeTransactions = async ( activeChainSlugs: ChainSlug[], - newRoleStatus: boolean + newRoleStatus: boolean, + allAddresses: DeploymentAddresses ) => { await Promise.all( activeChainSlugs.map(async (chainSlug) => { - let provider = getProviderFromChainSlug(chainSlug as any as ChainSlug); - let wallet = new Wallet(process.env.SOCKET_SIGNER_KEY!, provider); - await executeRoleTransactions(chainSlug, newRoleStatus, wallet); - await executeOtherTransactions(chainSlug, wallet); + const relaySigner = await getSocketSigner( + chainSlug, + allAddresses[chainSlug] + ); + await executeRoleTransactions(chainSlug, newRoleStatus, relaySigner); + await executeOtherTransactions(chainSlug, relaySigner); }) ); }; @@ -484,7 +489,7 @@ export const checkAndUpdateRoles = async ( (); if (sendTransaction) - await executeTransactions(activeChainSlugs, newRoleStatus); + await executeTransactions(activeChainSlugs, newRoleStatus, allAddresses); return { params, roleStatus }; } catch (error) { diff --git a/scripts/deploy/utils/utils.ts b/scripts/deploy/utils/utils.ts index f79af3c5c..0a691f28c 100644 --- a/scripts/deploy/utils/utils.ts +++ b/scripts/deploy/utils/utils.ts @@ -6,7 +6,6 @@ import { Address } from "hardhat-deploy/dist/types"; import path from "path"; import fs from "fs"; import { - ChainSlugToId, ChainSlug, ChainSocketAddresses, DeploymentAddresses, @@ -15,6 +14,7 @@ import { import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; import { overrides } from "../config/config"; import { VerifyArgs } from "../verify"; +import { SocketSigner } from "@socket.tech/dl-common"; export const deploymentsPath = path.join(__dirname, `/../../../deployments/`); @@ -35,7 +35,7 @@ export const getChainRoleHash = (role: string, chainSlug: number) => export interface DeployParams { addresses: ChainSocketAddresses; mode: DeploymentMode; - signer: SignerWithAddress | Wallet; + signer: SignerWithAddress | SocketSigner | Wallet; currentChainSlug: number; } @@ -81,7 +81,7 @@ export const getOrDeploy = async ( export async function deployContractWithArgs( contractName: string, args: Array, - signer: SignerWithAddress | Wallet + signer: SignerWithAddress | SocketSigner | Wallet ) { try { const Contract: ContractFactory = await ethers.getContractFactory( diff --git a/src/socket-types.ts b/src/socket-types.ts index fe23d3de2..f16ebbbdf 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -106,6 +106,8 @@ export interface ChainSocketAddresses { SocketSimulator?: string; SimulatorUtils?: string; SwitchboardSimulator?: string; + Safe?: string; + MultiSigWrapper?: string; } export type DeploymentAddresses = { @@ -138,6 +140,7 @@ export enum CORE_CONTRACTS { FastSwitchboard2 = "FastSwitchboard2", OptimisticSwitchboard = "OptimisticSwitchboard", NativeSwitchboard = "NativeSwitchboard", + MultiSigWrapper = "MultiSigWrapper", } export const REQUIRED_ROLES = {