Skip to content

Commit 2b44aaa

Browse files
committed
wip: full allocation management
Signed-off-by: Tomás Migone <[email protected]>
1 parent d2bfd5b commit 2b44aaa

File tree

16 files changed

+604
-300
lines changed

16 files changed

+604
-300
lines changed

packages/indexer-agent/src/agent.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class Agent {
252252
},
253253
)
254254

255-
this.reconciliationLoop()
255+
// this.reconciliationLoop()
256256
return this
257257
}
258258

@@ -1083,6 +1083,8 @@ export class Agent {
10831083
epoch,
10841084
})
10851085

1086+
const isHorizon = await network.isHorizon.value()
1087+
10861088
// TODO: Can we replace `filter` for `find` here? Is there such a case when we
10871089
// would have multiple allocations for the same subgraph?
10881090
const activeDeploymentAllocations = activeAllocations.filter(
@@ -1133,6 +1135,7 @@ export class Agent {
11331135
logger,
11341136
deploymentAllocationDecision,
11351137
mostRecentlyClosedAllocation,
1138+
isHorizon,
11361139
)
11371140
}
11381141
} else if (activeDeploymentAllocations.length > 0) {

packages/indexer-cli/src/actions.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface GenericActionInputParams {
2323
param2: string | undefined
2424
param3: string | undefined
2525
param4: string | undefined
26+
param5: string | undefined
27+
param6: string | undefined
2628
}
2729

2830
// Make separate functions for each action type parsing from generic?
@@ -35,9 +37,10 @@ export async function buildActionInput(
3537
priority: number,
3638
protocolNetwork: string,
3739
): Promise<ActionInput> {
40+
// TODO HORIZON: validate publicPOI and blockNumber for unallocate and reallocate only for horizon allocations
3841
await validateActionInput(type, actionParams)
3942

40-
// TODO: we could check isHorizon status here to set the proper value for isLegacy, but it requires multiNetworks
43+
// TODO HORIZON: we could check isHorizon status here to set the proper value for isLegacy, but it requires multiNetworks
4144
// The IndexerManagementServer will set the correct value anyways
4245
const isLegacy = false
4346

@@ -63,6 +66,8 @@ export async function buildActionInput(
6366
deploymentID: actionParams.targetDeployment,
6467
allocationID: actionParams.param1,
6568
poi: poi,
69+
publicPOI: actionParams.param5,
70+
blockNumber: actionParams.param6,
6671
force: actionParams.param3 === 'true',
6772
type,
6873
source,
@@ -83,6 +88,8 @@ export async function buildActionInput(
8388
allocationID: actionParams.param1,
8489
amount: actionParams.param2?.toString(),
8590
poi: poi,
91+
publicPOI: actionParams.param5,
92+
blockNumber: actionParams.param6,
8693
force: actionParams.param4 === 'true',
8794
type,
8895
source,
@@ -190,12 +197,15 @@ export async function queueActions(
190197
allocationID
191198
amount
192199
poi
200+
publicPOI
201+
blockNumber
193202
force
194203
source
195204
reason
196205
priority
197206
status
198207
protocolNetwork
208+
isLegacy
199209
}
200210
}
201211
`,
@@ -216,11 +226,14 @@ const ACTION_PARAMS_PARSERS: Record<keyof ActionUpdateInput, (x: never) => any>
216226
allocationID: x => x,
217227
amount: nullPassThrough(parseGRT),
218228
poi: nullPassThrough((x: string) => validatePOI(x)),
229+
publicPOI: nullPassThrough((x: string) => validatePOI(x)),
230+
blockNumber: nullPassThrough((x: string) => Number(x)),
219231
force: x => parseBoolean(x),
220232
type: x => validateActionType(x),
221233
status: x => validateActionStatus(x),
222234
reason: nullPassThrough,
223235
protocolNetwork: x => validateNetworkIdentifier(x),
236+
isLegacy: x => parseBoolean(x),
224237
}
225238

226239
/**
@@ -256,6 +269,8 @@ export async function executeApprovedActions(
256269
allocationID
257270
amount
258271
poi
272+
publicPOI
273+
blockNumber
259274
force
260275
source
261276
reason
@@ -291,6 +306,8 @@ export async function approveActions(
291306
deploymentID
292307
amount
293308
poi
309+
publicPOI
310+
blockNumber
294311
force
295312
source
296313
reason
@@ -329,6 +346,8 @@ export async function cancelActions(
329346
deploymentID
330347
amount
331348
poi
349+
publicPOI
350+
blockNumber
332351
force
333352
source
334353
reason
@@ -366,6 +385,8 @@ export async function fetchAction(
366385
deploymentID
367386
amount
368387
poi
388+
publicPOI
389+
blockNumber
369390
force
370391
source
371392
reason
@@ -416,6 +437,8 @@ export async function fetchActions(
416437
deploymentID
417438
amount
418439
poi
440+
publicPOI
441+
blockNumber
419442
force
420443
source
421444
reason
@@ -454,6 +477,8 @@ export async function deleteActions(
454477
deploymentID
455478
amount
456479
poi
480+
publicPOI
481+
blockNumber
457482
force
458483
source
459484
reason
@@ -492,6 +517,8 @@ export async function updateActions(
492517
deploymentID
493518
amount
494519
poi
520+
publicPOI
521+
blockNumber
495522
force
496523
source
497524
reason

packages/indexer-cli/src/allocations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export const closeAllocation = async (
255255
{
256256
allocation: allocationID,
257257
poi,
258-
blockNumber,
258+
blockNumber: blockNumber,
259259
publicPOI,
260260
force,
261261
protocolNetwork,
@@ -312,7 +312,7 @@ export const reallocateAllocation = async (
312312
{
313313
allocation: allocationID,
314314
poi,
315-
blockNumber,
315+
blockNumber: blockNumber,
316316
publicPOI,
317317
amount: amount.toString(),
318318
force,

packages/indexer-cli/src/commands/indexer/actions/queue.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ ${chalk.bold(
2121
${chalk.bold('graph indexer actions queue')} [options] allocate <deploymentID> <amount>
2222
${chalk.bold(
2323
'graph indexer actions queue',
24-
)} [options] unallocate <deploymentID> <allocationID> <poi> <force>
24+
)} [options] unallocate <deploymentID> <allocationID> <poi> <force> <publicPOI> <blockNumber>
2525
${chalk.bold(
2626
'graph indexer actions queue',
27-
)} [options] reallocate <deploymentID> <allocationID> <amount> <poi> <force>
27+
)} [options] reallocate <deploymentID> <allocationID> <amount> <poi> <force> <publicPOI> <blockNumber>
2828
2929
${chalk.dim('Options:')}
3030
3131
-h, --help Show usage information
32-
-n, --network <STRING> [Required] The protocol network for this action (mainnet, arbitrum-one, sepolia, arbitrum-sepolia)
32+
-n, --network <STRING> The protocol network for this action (mainnet, arbitrum-one, sepolia, arbitrum-sepolia)
3333
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
3434
-s, --source <STRING> Specify the source of the action decision
3535
-r, --reason <STRING> Specify the reason for the action to be taken
3636
-p, --priority <INT> Define a priority order for the action
37+
38+
For action type specific options, see the help for the specific action type.
3739
`
3840

3941
module.exports = {
@@ -62,7 +64,7 @@ module.exports = {
6264
return
6365
}
6466

65-
const [type, targetDeployment, param1, param2, param3, param4] =
67+
const [type, targetDeployment, param1, param2, param3, param4, param5, param6] =
6668
parameters.array || []
6769

6870
let actionInputParams: ActionInput
@@ -77,7 +79,7 @@ module.exports = {
7779

7880
actionInputParams = await buildActionInput(
7981
validateActionType(type),
80-
{ targetDeployment, param1, param2, param3, param4 },
82+
{ targetDeployment, param1, param2, param3, param4, param5, param6 },
8183
decisionSource,
8284
decisionReason,
8385
ActionStatus.QUEUED,

packages/indexer-cli/src/commands/indexer/allocations/close.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@ import chalk from 'chalk'
44
import { loadValidatedConfig } from '../../../config'
55
import { createIndexerManagementClient } from '../../../client'
66
import { closeAllocation } from '../../../allocations'
7-
import { validatePOI, printObjectOrArray } from '../../../command-helpers'
8-
import { validateNetworkIdentifier } from '@graphprotocol/indexer-common'
7+
import {
8+
validatePOI,
9+
printObjectOrArray,
10+
extractProtocolNetworkOption,
11+
} from '../../../command-helpers'
912

1013
const HELP = `
1114
${chalk.bold(
1215
'graph indexer allocations close',
13-
)} [options] <network> <id> <poi> <blockNumber> <publicPOI>
16+
)} [options] <id> <poi> <blockNumber> <publicPOI>
1417
1518
${chalk.dim('Options:')}
1619
1720
-h, --help Show usage information
21+
-n, --network <network> The network to close the allocation on: mainnet, arbitrum-one, sepolia or arbitrum sepolia
1822
-f, --force Bypass POI accuracy checks and submit transaction with provided data
1923
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
2024
2125
${chalk.dim('Arguments:')}
22-
<network> The network to close the allocation on: mainnet, arbitrum-one, sepolia or arbitrum sepolia
2326
<id> The allocation id to close
24-
<poi> The POI to close the allocation with
25-
<blockNumber> The block number the POI was computed at
26-
<publicPOI> [Horizon] The public POI to close the allocation with. Must be same block height as POI.
27+
<poi> (optional) The POI to close the allocation with
28+
<blockNumber> (optional, horizon only) The block number the POI was computed at. Must be set if POI is provided.
29+
<publicPOI> (optional, horizon only) The public POI to close the allocation with. Must be same block height as POI.
2730
`
2831

2932
module.exports = {
@@ -52,7 +55,7 @@ module.exports = {
5255
return
5356
}
5457

55-
const [network, id, unformattedPoi, unformattedBlockNumber, unformattedPublicPOI] =
58+
const [id, unformattedPoi, unformattedBlockNumber, unformattedPublicPOI] =
5659
parameters.array || []
5760

5861
if (id === undefined) {
@@ -62,37 +65,30 @@ module.exports = {
6265
return
6366
}
6467

65-
let protocolNetwork: string
66-
if (!network) {
67-
spinner.fail(`Missing required argument: 'network'`)
68-
print.info(HELP)
69-
process.exitCode = 1
70-
return
71-
} else {
72-
try {
73-
protocolNetwork = validateNetworkIdentifier(network)
74-
} catch (error) {
75-
spinner.fail(`Invalid value for argument 'network': '${network}' `)
76-
process.exitCode = 1
77-
return
78-
}
79-
}
80-
8168
let poi: string | undefined
8269
let blockNumber: number | undefined
8370
let publicPOI: string | undefined
8471
try {
8572
poi = validatePOI(unformattedPoi)
8673
publicPOI = validatePOI(unformattedPublicPOI)
87-
blockNumber = Number(unformattedBlockNumber)
74+
blockNumber =
75+
unformattedBlockNumber === undefined ? undefined : Number(unformattedBlockNumber)
8876
} catch (error) {
89-
spinner.fail(`Invalid POI provided, '${unformattedPoi}'. ` + error.message)
77+
spinner.fail(`Invalid value provided: ` + error.message)
9078
process.exitCode = 1
9179
return
9280
}
9381

9482
spinner.text = `Closing allocation '${id}`
9583
try {
84+
const protocolNetwork = extractProtocolNetworkOption(parameters.options, true)
85+
86+
if (!protocolNetwork) {
87+
throw new Error(
88+
'Must provide a network identifier' + `(network: '${protocolNetwork}')`,
89+
)
90+
}
91+
9692
const config = loadValidatedConfig()
9793
const client = await createIndexerManagementClient({ url: config.api })
9894
const closeResult = await closeAllocation(

packages/indexer-cli/src/commands/indexer/allocations/collect.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@ import chalk from 'chalk'
44
import { loadValidatedConfig } from '../../../config'
55
import { createIndexerManagementClient } from '../../../client'
66
import { submitCollectReceiptsJob } from '../../../allocations'
7-
import { validateNetworkIdentifier } from '@graphprotocol/indexer-common'
7+
import { extractProtocolNetworkOption } from '../../../command-helpers'
88

99
const HELP = `
1010
${chalk.bold('graph indexer allocations collect')} [options] <network> <id>
1111
1212
${chalk.dim('Options:')}
1313
1414
-h, --help Show usage information
15+
-n, --network <network> The protocol network for this action (mainnet, arbitrum-one, sepolia, arbitrum-sepolia)
1516
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
16-
17-
${chalk.dim('Networks:')}
18-
mainnet, arbitrum-one, sepolia or arbitrum sepolia
1917
`
2018

2119
module.exports = {
@@ -43,7 +41,7 @@ module.exports = {
4341
return
4442
}
4543

46-
const [network, id] = parameters.array || []
44+
const [id] = parameters.array || []
4745

4846
if (id === undefined) {
4947
spinner.fail(`Missing required argument: 'id'`)
@@ -52,24 +50,16 @@ module.exports = {
5250
return
5351
}
5452

55-
let protocolNetwork: string
56-
if (!network) {
57-
spinner.fail(`Missing required argument: 'network'`)
58-
print.info(HELP)
59-
process.exitCode = 1
60-
return
61-
} else {
62-
try {
63-
protocolNetwork = validateNetworkIdentifier(network)
64-
} catch (error) {
65-
spinner.fail(`Invalid value for argument 'network': '${network}' `)
66-
process.exitCode = 1
67-
return
68-
}
69-
}
70-
7153
spinner.text = `Collecting receipts for allocation '${id}`
7254
try {
55+
const protocolNetwork = extractProtocolNetworkOption(parameters.options, true)
56+
57+
if (!protocolNetwork) {
58+
throw new Error(
59+
'Must provide a network identifier' + `(network: '${protocolNetwork}')`,
60+
)
61+
}
62+
7363
const config = loadValidatedConfig()
7464
const client = await createIndexerManagementClient({ url: config.api })
7565
await submitCollectReceiptsJob(client, id, protocolNetwork)

0 commit comments

Comments
 (0)