Skip to content

Commit

Permalink
fix: migrate scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ameeshaagrawal committed Jun 25, 2024
1 parent 0ede188 commit 57f8cc7
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 9 deletions.
43 changes: 39 additions & 4 deletions scripts/deploy/em-migration/backward-migrate-em.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ import {
CORE_CONTRACTS,
DeploymentAddresses,
MainnetIds,
ROLES,
TestnetIds,
} from "../../../src";
import { configureRoles } from "../scripts/configureRoles";
import { configureSwitchboards } from "../scripts/configureSwitchboards";
import { deployForChains } from "../scripts/deploySocketFor";
import prompts from "prompts";
import { checkAndUpdateRoles } from "../scripts/roles";
import {
executorAddresses,
mode,
ownerAddresses,
transmitterAddresses,
} from "../config/config";
import { configureExecutionManagers } from "./migrate-em";

const deploy = async () => {
try {
Expand Down Expand Up @@ -53,8 +60,36 @@ const deploy = async () => {
emVersion
);

await configureRoles(addresses, chains, true, emVersion);
await configureSwitchboards(addresses, chains, emVersion);
await checkAndUpdateRoles(
{
userSpecificRoles: [
{
userAddress: ownerAddresses[mode],
filterRoles: [
ROLES.RESCUE_ROLE,
ROLES.GOVERNANCE_ROLE,
ROLES.WITHDRAW_ROLE,
ROLES.FEES_UPDATER_ROLE,
],
},
{
userAddress: transmitterAddresses[mode],
filterRoles: [ROLES.FEES_UPDATER_ROLE],
},
{
userAddress: executorAddresses[mode],
filterRoles: [ROLES.EXECUTOR_ROLE],
},
],
contractName: emVersion,
filterChains: chains,
filterSiblingChains: chains,
sendTransaction: true,
newRoleStatus: true,
},
addresses
);
await configureExecutionManagers(chains, addresses);
} catch (error) {
console.log("Error:", error);
}
Expand Down
119 changes: 114 additions & 5 deletions scripts/deploy/em-migration/migrate-em.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,128 @@ require("dotenv").config();
import {
CORE_CONTRACTS,
ChainSlug,
ChainSocketAddresses,
DeploymentAddresses,
DeploymentMode,
MainnetIds,
ROLES,
TestnetIds,
getAllAddresses,
} from "../../../src";
import { configureRoles } from "../scripts/configureRoles";
import { configureSwitchboards } from "../scripts/configureSwitchboards";
import { deployForChains } from "../scripts/deploySocketFor";
import prompts from "prompts";
import { checkAndUpdateRoles } from "../scripts/roles";
import {
executorAddresses,
mode,
ownerAddresses,
transmitterAddresses,
} from "../config/config";
import {
configureExecutionManager,
setManagers,
} from "../scripts/configureSocket";
import { Wallet } from "ethers";
import { getProviderFromChainSlug } from "../../constants";
import { storeAllAddresses } from "../utils";

const deploymentMode = process.env.DEPLOYMENT_MODE as DeploymentMode;
const emVersion = CORE_CONTRACTS.ExecutionManagerDF;

export const configureExecutionManagers = async (
chains: ChainSlug[],
addresses
) => {
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]!;

// todo: take siblings from address json
const siblingSlugs: ChainSlug[] = [];
// list.filter(
// (chainSlug) => chainSlug !== chain && chains.includes(chainSlug)
// );

await configureExecutionManager(
emVersion,
addr[emVersion]!,
addr[CORE_CONTRACTS.SocketBatcher],
chain,
siblingSlugs,
socketSigner
);

await setManagers(addr, socketSigner, emVersion);
})
);
} catch (error) {}
};

const deleteOldContracts = async (chains: ChainSlug[]) => {
try {
const addresses: DeploymentAddresses = getAllAddresses(mode);
await Promise.all(
Object.keys(addresses).map(async (chain) => {
if (chains.includes(parseInt(chain) as ChainSlug)) {
addresses[chain].SocketSimulator = "";
addresses[chain].SimulatorUtils = "";
addresses[chain].SwitchboardSimulator = "";
addresses[chain].Counter = "";
addresses[chain].SocketBatcher = "";
}
})
);

await storeAllAddresses(addresses, mode);
} catch (error) {
console.log("Error:", error);
}
};

const deploy = async (chains: ChainSlug[]) => {
try {
const addresses: DeploymentAddresses = await deployForChains(
chains,
emVersion
);
await configureRoles(addresses, chains, true, emVersion);

await checkAndUpdateRoles(
{
userSpecificRoles: [
{
userAddress: ownerAddresses[mode],
filterRoles: [
ROLES.RESCUE_ROLE,
ROLES.GOVERNANCE_ROLE,
ROLES.WITHDRAW_ROLE,
ROLES.FEES_UPDATER_ROLE,
],
},
{
userAddress: transmitterAddresses[mode],
filterRoles: [ROLES.FEES_UPDATER_ROLE],
},
{
userAddress: executorAddresses[mode],
filterRoles: [ROLES.EXECUTOR_ROLE],
},
],
contractName: emVersion,
filterChains: chains,
filterSiblingChains: chains,
sendTransaction: true,
newRoleStatus: true,
},
addresses
);
} catch (error) {
console.log("Error:", error);
}
Expand All @@ -34,7 +135,8 @@ const configure = async (chains: ChainSlug[]) => {
chains,
emVersion
);
await configureSwitchboards(addresses, chains, emVersion);

await configureExecutionManagers(chains, addresses);
} catch (error) {
console.log("Error:", error);
}
Expand All @@ -55,6 +157,10 @@ const main = async () => {
title: "Configure",
value: "configure",
},
{
title: "Delete",
value: "delete",
},
],
},
{
Expand Down Expand Up @@ -99,6 +205,9 @@ const main = async () => {
case "deploy":
await deploy(chains);
break;
case "delete":
await deleteOldContracts(chains);
break;
case "exit":
process.exit(0);
}
Expand Down

0 comments on commit 57f8cc7

Please sign in to comment.