@@ -15,7 +15,7 @@ import {
1515import { validatePOI , validateRequiredParams } from './command-helpers'
1616import gql from 'graphql-tag'
1717import { hexlify } from 'ethers'
18- import { parseGRT } from '@graphprotocol/common-ts'
18+ import { formatGRT , parseGRT } from '@graphprotocol/common-ts'
1919
2020export interface GenericActionInputParams {
2121 targetDeployment : string
@@ -235,6 +235,25 @@ const ACTION_PARAMS_PARSERS: Record<keyof ActionUpdateInput, (x: never) => any>
235235 isLegacy : x => parseBoolean ( x ) ,
236236}
237237
238+ const ACTION_CONVERTERS_TO_GRAPHQL : Record <
239+ keyof ActionUpdateInput ,
240+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
241+ ( x : never ) => any
242+ > = {
243+ deploymentID : x => x ,
244+ allocationID : x => x ,
245+ amount : nullPassThrough ( ( x : bigint ) => formatGRT ( x ) ) ,
246+ poi : x => x ,
247+ publicPOI : x => x ,
248+ poiBlockNumber : nullPassThrough ( ( x : number ) => x ) ,
249+ force : x => x ,
250+ type : x => x ,
251+ status : x => x ,
252+ reason : x => x ,
253+ protocolNetwork : x => x ,
254+ isLegacy : x => x ,
255+ }
256+
238257/**
239258 * Parses a user-provided action update input into a normalized form.
240259 */
@@ -252,6 +271,22 @@ export const parseActionUpdateInput = (input: object): ActionUpdateInput => {
252271 return obj as ActionUpdateInput
253272}
254273
274+ /**
275+ * Converts a normalized action to a representation
276+ * compatible with the indexer management GraphQL API.
277+ */
278+ export const actionToGraphQL = (
279+ action : Partial < ActionUpdateInput > ,
280+ ) : Partial < ActionUpdateInput > => {
281+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
282+ const obj = { } as any
283+ for ( const [ key , value ] of Object . entries ( action ) ) {
284+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
285+ obj [ key ] = ( ACTION_CONVERTERS_TO_GRAPHQL as any ) [ key ] ( value )
286+ }
287+ return obj as Partial < ActionUpdateInput >
288+ }
289+
255290export async function executeApprovedActions (
256291 client : IndexerManagementClient ,
257292) : Promise < ActionResult [ ] > {
@@ -530,7 +565,7 @@ export async function updateActions(
530565 }
531566 }
532567 ` ,
533- { filter, action } ,
568+ { filter, action : actionToGraphQL ( action ) } ,
534569 )
535570 . toPromise ( )
536571
0 commit comments