From eb8820b57dbec30c01586eb71d23a0405a74045b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Bl=C3=A4cker?= Date: Mon, 25 Nov 2024 15:55:58 +0700 Subject: [PATCH] adds more robustness to sync sigs scripts --- script/tasks/diamondSyncSigs.sh | 12 +++++++++++- script/tasks/diamondSyncSigs.ts | 29 ++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/script/tasks/diamondSyncSigs.sh b/script/tasks/diamondSyncSigs.sh index 71fbdd442..a5810d389 100755 --- a/script/tasks/diamondSyncSigs.sh +++ b/script/tasks/diamondSyncSigs.sh @@ -63,19 +63,29 @@ function diamondSyncSigs { # go through all networks and execute the script for NETWORK in "${NETWORKS[@]}"; do + # Skip for localanvil or any testnet + if [[ "$NETWORK" == "localanvil" || \ + "$NETWORK" == "bsc-testnet" || \ + "$NETWORK" == "lineatest" || \ + "$NETWORK" == "mumbai" || \ + "$NETWORK" == "sepolia" ]]; then + continue + fi + # get RPC URL for given network RPC_URL=$(getRPCUrl "$NETWORK") # call batchSetFunctionApprovalBySignature function in diamond to add function selectors local ATTEMPTS=1 while [ $ATTEMPTS -le "$MAX_ATTEMPTS_PER_SCRIPT_EXECUTION" ]; do + echo "----------------------------------------------------------------------------------------" echo "[info] trying to add function selectors now - attempt ${ATTEMPTS} (max attempts: $MAX_ATTEMPTS_PER_SCRIPT_EXECUTION) " # ensure that gas price is below maximum threshold (for mainnet only) doNotContinueUnlessGasIsBelowThreshold "$NETWORK" # try to run the typescript script (will fail if the network is not yet supported by viem) - ts-node ./script/tasks/diamondSyncSigs.ts --network "$NETWORK" --rpcUrl "$RPC_URL" --privateKey "$PRIVATE_KEY" --environment "$ENVIRONMENT" + ts-node ./script/tasks/diamondSyncSigs.ts --network "$NETWORK" --rpcUrl "$RPC_URL" --privateKey "$(getPrivateKey "$NETWORK" "$ENVIRONMENT")" --environment "$ENVIRONMENT" RETURN_CODE=$? # check the typescript script failed diff --git a/script/tasks/diamondSyncSigs.ts b/script/tasks/diamondSyncSigs.ts index b055cd7e7..9374b91b5 100644 --- a/script/tasks/diamondSyncSigs.ts +++ b/script/tasks/diamondSyncSigs.ts @@ -12,6 +12,7 @@ import { ethers } from 'ethers6' import * as chains from 'viem/chains' import { privateKeyToAccount } from 'viem/accounts' import { getViemChainForNetworkName } from '../utils/viemScriptHelpers' +import consola from 'consola' export const chainNameMappings: Record = { zksync: 'zkSync', @@ -113,19 +114,29 @@ const main = defineCommand({ if (sigsToApprove.length > 0) { // Approve function signatures console.log('Approving function signatures...') - const tx = await walletClient.writeContract({ - address: deployedContracts['LiFiDiamond'], - abi: parseAbi([ - 'function batchSetFunctionApprovalBySignature(bytes4[],bool) external', - ]), - functionName: 'batchSetFunctionApprovalBySignature', - args: [sigsToApprove, true], - account, - }) + let tx + try { + tx = await walletClient.writeContract({ + address: deployedContracts['LiFiDiamond'], + abi: parseAbi([ + 'function batchSetFunctionApprovalBySignature(bytes4[],bool) external', + ]), + functionName: 'batchSetFunctionApprovalBySignature', + args: [sigsToApprove, true], + account, + }) + + await publicClient.waitForTransactionReceipt({ hash: tx }) + } catch (err) { + consola.error(JSON.stringify(err, null, 2)) + process.exit(1) + } console.log('Transaction:', tx) + process.exit(0) } else { console.log('All Signatures are already approved.') + process.exit(0) } }, })