@@ -15,7 +15,7 @@ import {
15
15
import { validatePOI , validateRequiredParams } from './command-helpers'
16
16
import gql from 'graphql-tag'
17
17
import { hexlify } from 'ethers'
18
- import { parseGRT } from '@graphprotocol/common-ts'
18
+ import { formatGRT , parseGRT } from '@graphprotocol/common-ts'
19
19
20
20
export interface GenericActionInputParams {
21
21
targetDeployment : string
@@ -235,6 +235,25 @@ const ACTION_PARAMS_PARSERS: Record<keyof ActionUpdateInput, (x: never) => any>
235
235
isLegacy : x => parseBoolean ( x ) ,
236
236
}
237
237
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
+
238
257
/**
239
258
* Parses a user-provided action update input into a normalized form.
240
259
*/
@@ -252,6 +271,22 @@ export const parseActionUpdateInput = (input: object): ActionUpdateInput => {
252
271
return obj as ActionUpdateInput
253
272
}
254
273
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
+
255
290
export async function executeApprovedActions (
256
291
client : IndexerManagementClient ,
257
292
) : Promise < ActionResult [ ] > {
@@ -530,7 +565,7 @@ export async function updateActions(
530
565
}
531
566
}
532
567
` ,
533
- { filter, action } ,
568
+ { filter, action : actionToGraphQL ( action ) } ,
534
569
)
535
570
. toPromise ( )
536
571
0 commit comments