Skip to content

Commit

Permalink
Check emergency pause config (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 authored Dec 10, 2024
1 parent 3ac71b8 commit c689987
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
"wrappedNativeAddress": "0x4200000000000000000000000000000000000006",
"status": "inactive",
"type": "mainnet",
"rpcUrl": "https://worldchain-mainnet.g.alchemy.com/public",
"rpcUrl": "https://worldchain-mainnet.gateway.tenderly.co",
"verificationType": "etherscan",
"explorerUrl": "https://worldscan.org",
"explorerApiUrl": "https://api.worldscan.org/api",
Expand Down
83 changes: 80 additions & 3 deletions script/deploy/healthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { consola } from 'consola'
import { $, spinner } from 'zx'
import { defineCommand, runMain } from 'citty'
import * as chains from 'viem/chains'
import * as path from 'path'
import * as fs from 'fs'
import {
Address,
Chain,
Expand Down Expand Up @@ -240,6 +242,7 @@ const main = defineCommand({
address: deployedContracts['LiFiDiamond'],
abi: parseAbi([
'function approvedDexs() external view returns (address[])',
'function isFunctionApproved(bytes4) external returns (bool)',
]),
client: publicClient,
})
Expand Down Expand Up @@ -276,6 +279,53 @@ const main = defineCommand({
`Found ${numMissing} missing dex${numMissing === 1 ? '' : 's'}`
)

// ╭─────────────────────────────────────────────────────────╮
// │ Check approved sigs │
// ╰─────────────────────────────────────────────────────────╯

consola.box('Checking DEX signatures approved in diamond...')
// Check if function signatures are approved
const { sigs } = await import(`../../config/sigs.json`)

// Function to split array into chunks
const chunkArray = <T>(array: T[], chunkSize: number): T[][] => {
const chunks: T[][] = []
for (let i = 0; i < array.length; i += chunkSize) {
chunks.push(array.slice(i, i + chunkSize))
}
return chunks
}

const batchSize = 20
const sigBatches = chunkArray(sigs, batchSize)

const sigsToApprove: Hex[] = []

for (const batch of sigBatches) {
const calls = batch.map((sig: string) => {
return {
...dexManager,
functionName: 'isFunctionApproved',
args: [sig],
}
})

const results = await publicClient.multicall({ contracts: calls })

for (let i = 0; i < results.length; i++) {
if (results[i].status !== 'success' || !results[i].result) {
console.log('Function not approved:', batch[i])
sigsToApprove.push(batch[i] as Hex)
}
}
}

if (sigsToApprove.length > 0) {
logError(`Missing ${sigsToApprove.length} DEX signatures`)
} else {
consola.success('No missing signatures.')
}

// ╭─────────────────────────────────────────────────────────╮
// │ Check contract ownership │
// ╰─────────────────────────────────────────────────────────╯
Expand Down Expand Up @@ -320,6 +370,33 @@ const main = defineCommand({
publicClient
)

// ╭─────────────────────────────────────────────────────────╮
// │ Check emergency pause config │
// ╰─────────────────────────────────────────────────────────╯
consola.box('Checking emergency pause config...')
const filePath: string = path.join(
'.github',
'workflows',
'diamondEmergencyPause.yml'
)

try {
const fileContent: string = fs.readFileSync(filePath, 'utf8')

const networkUpper: string = network.toUpperCase()
const pattern = new RegExp(
`ETH_NODE_URI_${networkUpper}\\s*:\\s*\\$\\{\\{\\s*secrets\\.ETH_NODE_URI_${networkUpper}\\s*\\}\\}`
)

const exists: boolean = pattern.test(fileContent)

if (!exists) {
logError(`Missing ETH_NODE_URI config for ${network} in ${filePath}`)
}
} catch (error: any) {
logError(`Error checking workflow file: ${error.message}`)
}

// ╭─────────────────────────────────────────────────────────╮
// │ Check access permissions │
// ╰─────────────────────────────────────────────────────────╯
Expand Down Expand Up @@ -419,9 +496,9 @@ const main = defineCommand({
},
})

const logError = (string: string) => {
consola.error(string)
errors.push(string)
const logError = (msg: string) => {
consola.error(msg)
errors.push(msg)
}

const getOwnableContract = (address: Address, client: PublicClient) => {
Expand Down
1 change: 1 addition & 0 deletions script/utils/viemScriptHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
}

export const networks: NetworksObject = networksConfig

export const getViemChainForNetworkName = (networkName: string): Chain => {
Expand Down

0 comments on commit c689987

Please sign in to comment.