Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script improvements #874

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions script/tasks/diamondSyncDEXs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ function diamondSyncDEXs {

# 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 diamond address from deployments script
DIAMOND_ADDRESS=$(getContractAddressFromDeploymentLogs "$NETWORK" "$ENVIRONMENT" "$DIAMOND_CONTRACT_NAME")

Expand Down
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"
0xDEnYO marked this conversation as resolved.
Show resolved Hide resolved
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)
0xDEnYO marked this conversation as resolved.
Show resolved Hide resolved
}
},
})
Expand Down
Loading