Skip to content

Commit

Permalink
feat: use socket signer in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ameeshaagrawal committed Jul 30, 2024
1 parent 702341c commit 593c831
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 89 deletions.
10 changes: 3 additions & 7 deletions scripts/admin/tripCommon.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { BigNumberish, Contract, Wallet, utils } from "ethers";
import { BigNumberish } from "ethers";
import {
IntegrationTypes,
ChainSlug,
DeploymentMode,
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();
Expand Down
2 changes: 1 addition & 1 deletion scripts/admin/untripPath.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
1 change: 0 additions & 1 deletion scripts/common/switchboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {};
Expand Down
1 change: 1 addition & 0 deletions scripts/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const main = async () => {
console.log("No siblings selected!");
return;
}

await configureRoles(addresses, chains, true, executionManagerVersion);
addresses = await configureSwitchboards(
addresses,
Expand Down
15 changes: 4 additions & 11 deletions scripts/deploy/em-migration/migrate-em.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
Expand Down
22 changes: 10 additions & 12 deletions scripts/deploy/scripts/configureSocket.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -55,7 +57,7 @@ export const registerSwitchboards = async (

export const setManagers = async (
addr: ChainSocketAddresses,
socketSigner: Wallet,
socketSigner: SocketSigner,
executionManagerVersion: CORE_CONTRACTS
) => {
const socket = (
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"]) {
Expand Down
15 changes: 3 additions & 12 deletions scripts/deploy/scripts/configureSwitchboards.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { Wallet } from "ethers";

import { getProviderFromChainSlug } from "../../constants";
import { storeAllAddresses } from "../utils";
import {
CORE_CONTRACTS,
Expand All @@ -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,
Expand All @@ -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(
Expand Down
16 changes: 5 additions & 11 deletions scripts/deploy/scripts/connect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
getDefaultIntegrationType,
getProviderFromChainSlug,
} from "../../constants";
import { getDefaultIntegrationType } from "../../constants";
import { getInstance } from "../utils";
import {
ChainSlug,
Expand All @@ -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,
Expand All @@ -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;
Expand Down
20 changes: 16 additions & 4 deletions scripts/deploy/scripts/deploySocket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, Wallet, constants } from "ethers";
import { Contract, constants } from "ethers";
import {
DeployParams,
getInstance,
Expand All @@ -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;

Expand All @@ -29,7 +29,7 @@ export interface ReturnObj {
*/
export const deploySocket = async (
executionManagerVersion: string,
socketSigner: SignerWithAddress | Wallet,
socketSigner: SocketSigner,
chainSlug: number,
currentMode: DeploymentMode,
deployedAddresses: ChainSocketAddresses
Expand Down Expand Up @@ -102,7 +102,7 @@ export const deploySocket = async (
// switchboards deploy
deployUtils.addresses = await deploySwitchboards(
chainSlug,
socketSigner,
socketSigner as SocketSigner,
deployUtils.addresses,
currentMode
);
Expand All @@ -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",
Expand Down
16 changes: 7 additions & 9 deletions scripts/deploy/scripts/deploySocketFor.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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[],
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions scripts/deploy/scripts/deploySwitchboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChainSocketAddresses> {
Expand Down Expand Up @@ -71,18 +70,19 @@ async function deploySwitchboard(
integrationType: IntegrationTypes,
chainSlug: ChainSlug,
remoteChain: ChainSlug | string,
signer: SignerWithAddress | Wallet,
signer: SocketSigner,
sourceConfig: ChainSocketAddresses,
mode: DeploymentMode
): Promise<ChainSocketAddresses> {
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(
Expand Down
5 changes: 3 additions & 2 deletions scripts/deploy/scripts/registerSwitchboard.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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,
siblingSwitchBoardAddress: string,
remoteChainSlug: string | ChainSlug,
capacitorType: number,
maxPacketLength: number,
signer: Wallet | SignerWithAddress,
signer: SocketSigner | SignerWithAddress,
integrationType: string,
config: ChainSocketAddresses
) {
Expand Down
Loading

0 comments on commit 593c831

Please sign in to comment.