Skip to content

Commit

Permalink
adds more robustness to sync sigs scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDEnYO committed Nov 25, 2024
1 parent 6dabea3 commit eb8820b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
12 changes: 11 additions & 1 deletion script/tasks/diamondSyncSigs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 20 additions & 9 deletions script/tasks/diamondSyncSigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
zksync: 'zkSync',
Expand Down Expand Up @@ -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)
}
},
})
Expand Down

0 comments on commit eb8820b

Please sign in to comment.