Skip to content

Commit

Permalink
cli: Add support for approving actions by their syncing-network
Browse files Browse the repository at this point in the history
- Add -s,--syncing option to `indexer actions approve queued ...` so
user can approve actions by syncing-network.
  • Loading branch information
fordN committed Nov 18, 2024
1 parent fce97f8 commit 40091ff
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/indexer-cli/src/commands/indexer/actions/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import {
printObjectOrArray,
parseOutputFormat,
extractProtocolNetworkOption,
extractSyncingNetworkOption,
} from '../../../command-helpers'
import { approveActions, fetchActions } from '../../../actions'
import { ActionStatus, resolveChainAlias } from '@graphprotocol/indexer-common'

const HELP = `
${chalk.bold('graph indexer actions approve')} [options] [<actionID1> ...]
${chalk.bold('graph indexer actions approve')} [options] queued --network <networkName>
${chalk.bold(
'graph indexer actions approve',
)} [options] queued --network <networkName> --syncing <networkName>
${chalk.dim('Options:')}
-h, --help Show usage information
-n, --network <STRING> Filter action selection by their protocol network (mainnet, arbitrum-one, sepolia, arbitrum-sepolia)
-n, --network <STRING> Filter actions by their protocol network (mainnet, arbitrum-one, sepolia, arbitrum-sepolia)
-s, --syncing <STRING> Filter (optional) by the syncing network (see https://thegraph.com/networks/ for supported networks)
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
`

Expand Down Expand Up @@ -47,12 +51,17 @@ module.exports = {
return
}

const protocolNetwork = extractProtocolNetworkOption(parameters.options)
let numericActionIDs: number[]
let protocolNetwork: string | undefined = undefined
let syncingNetwork: string | undefined = undefined

const config = loadValidatedConfig()
const client = await createIndexerManagementClient({ url: config.api })
try {
protocolNetwork = extractProtocolNetworkOption(parameters.options)

syncingNetwork = extractSyncingNetworkOption(parameters.options)

if (!actionIDs || actionIDs.length === 0) {
throw Error(`Missing required argument: 'actionID'`)
}
Expand All @@ -67,6 +76,7 @@ module.exports = {
const queuedActions = await fetchActions(client, {
status: ActionStatus.QUEUED,
protocolNetwork,
syncingNetwork,
})

numericActionIDs = queuedActions.map(action => action.id)
Expand Down Expand Up @@ -101,15 +111,17 @@ module.exports = {
const queuedAction = await approveActions(client, numericActionIDs)

// Format Actions 'protocolNetwork' field to display human-friendly chain aliases instead of CAIP2-IDs
queuedAction.forEach(
action => (action.protocolNetwork = resolveChainAlias(action.protocolNetwork)),
)
queuedAction.forEach(action => {
action.protocolNetwork = resolveChainAlias(action.protocolNetwork)
action.syncingNetwork = resolveChainAlias(action.syncingNetwork)
})

actionSpinner.succeed(`Actions approved`)
printObjectOrArray(print, outputFormat, queuedAction, [
'id',
'type',
'protocolNetwork',
'syncingNetwork',
'deploymentID',
'allocationID',
'amount',
Expand Down

0 comments on commit 40091ff

Please sign in to comment.