From f2ca5ba5246d6fa9ae99e64a434e0e81b5f24eb5 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Wed, 22 Jun 2022 20:00:04 +0300 Subject: [PATCH] Add afterUpgrade --- src/upgrade.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/upgrade.ts b/src/upgrade.ts index 42fe41b..2f14947 100644 --- a/src/upgrade.ts +++ b/src/upgrade.ts @@ -50,6 +50,7 @@ export async function getContractFactoryAndUpdateManifest(contract: string) { } type DeploymentAction = (safeTransactions: string[], abi: SkaleABIFile, contractManager: ContractManagerType) => Promise; +type MultiTransactionAction = (abi: SkaleABIFile, contractManager: ContractManagerType) => Promise; export async function upgrade( projectName: string, @@ -59,7 +60,8 @@ export async function upgrade( safeMockAccessRequirements: string[], contractNamesToUpgrade: string[], deployNewContracts: DeploymentAction, - initialize: DeploymentAction) + initialize: DeploymentAction, + afterUpgrade?: MultiTransactionAction) { if (!process.env.ABI) { console.log(chalk.red("Set path to file with ABI and addresses to ABI environment variables")); @@ -188,9 +190,19 @@ export async function upgrade( } const safeTx = await createMultiSendTransaction(ethers, safe, privateKey, safeTransactions, safeMock !== undefined); + let transactionsBatches: string[][] | undefined; + if (afterUpgrade !== undefined) { + transactionsBatches = await afterUpgrade(abi, contractManager); + } if (!safeMock) { const chainId = (await ethers.provider.getNetwork()).chainId; await sendSafeTransaction(safe, chainId, safeTx); + if (transactionsBatches !== undefined) { + for (const batch of transactionsBatches) { + const multiSendTransaction = await createMultiSendTransaction(ethers, safe, privateKey, batch, safeMock !== undefined); + await sendSafeTransaction(safe, chainId, multiSendTransaction); + } + } } else { console.log(chalk.blue("Send upgrade transactions to safe mock")); try { @@ -199,6 +211,16 @@ export async function upgrade( value: safeTx.value, data: safeTx.data, })).wait(); + if (transactionsBatches !== undefined) { + for (const batch of transactionsBatches) { + const multiSendTransaction = await createMultiSendTransaction(ethers, safe, privateKey, batch, safeMock !== undefined); + await (await deployer.sendTransaction({ + to: safeMock.address, + value: multiSendTransaction.value, + data: multiSendTransaction.data, + })).wait(); + } + } console.log(chalk.blue("Transactions have been sent")); } finally { console.log(chalk.blue("Return ownership to wallet"));