Skip to content

Commit c49ebe8

Browse files
committed
feat: upgrade to ethers v6, bump common-ts and use toolshed for contracts
Signed-off-by: Tomás Migone <[email protected]>
1 parent 32d8f17 commit c49ebe8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3133
-2661
lines changed

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@
2323
"lerna": "6.1.0"
2424
},
2525
"resolutions": {
26-
"ethers": "5.7.0",
26+
"ethers": "6.13.7",
2727
"sequelize": "6.33.0",
28-
"@ethersproject/bignumber": "5.7.0",
29-
"@ethersproject/providers": "5.7.0",
3028
"@urql/core": "3.1.0",
3129
"@urql/exchange-execute": "2.1.0",
3230
"punycode": "2.3.1",
3331
"uri-js": "4.2.2"
3432
},
3533
"overrides": {
36-
"ethers": "5.7.0",
34+
"ethers": "6.13.7",
3735
"sequelize": "6.33.0",
38-
"@ethersproject/bignumber": "5.7.0",
39-
"@ethersproject/providers": "5.7.0",
4036
"@urql/core": "3.1.0",
4137
"@urql/exchange-execute": "2.1.0",
4238
"graphql": "16.8.0"

packages/indexer-agent/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
preset: 'ts-jest',
1212
testEnvironment: 'node',
1313
testPathIgnorePatterns: ['/node_modules/', '/dist/', '.yalc'],
14+
transformIgnorePatterns: ['!node_modules/'],
1415
globals: {
1516
__DATABASE__: {
1617
host:

packages/indexer-agent/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
"graph-indexer-agent": "bin/graph-indexer-agent"
3030
},
3131
"dependencies": {
32-
"@graphprotocol/common-ts": "2.0.11",
32+
"@graphprotocol/common-ts": "3.0.1",
3333
"@graphprotocol/indexer-common": "^0.23.5",
3434
"@thi.ng/heaps": "^1.3.1",
3535
"axios": "0.26.1",
3636
"bs58": "5.0.0",
3737
"delay": "^5.0.0",
38-
"ethers": "5.7.0",
38+
"ethers": "6.13.7",
3939
"evt": "1.9.12",
4040
"global": "4.4.0",
4141
"graphql": "16.8.0",
@@ -80,10 +80,8 @@
8080
"typescript": "5.2.2"
8181
},
8282
"resolutions": {
83-
"ethers": "5.7.0",
84-
"sequelize": "6.33.0",
85-
"@ethersproject/bignumber": "5.7.0",
86-
"@ethersproject/providers": "5.7.0"
83+
"ethers": "6.13.7",
84+
"sequelize": "6.33.0"
8785
},
8886
"gitHead": "972ab96774007b2aee15b1da169d2ff4be9f9d27"
8987
}

packages/indexer-agent/src/__tests__/indexer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
MultiNetworks,
2222
loadTestYamlConfig,
2323
} from '@graphprotocol/indexer-common'
24-
import { BigNumber } from 'ethers'
2524
import { Sequelize } from 'sequelize'
2625

2726
const TEST_DISPUTE_1: POIDisputeAttributes = {
@@ -69,7 +68,7 @@ const TEST_DISPUTE_2: POIDisputeAttributes = {
6968

7069
const POI_DISPUTES_CONVERTERS_FROM_GRAPHQL: Record<
7170
keyof POIDisputeAttributes,
72-
(x: never) => string | BigNumber | number | undefined
71+
(x: never) => string | bigint | number | undefined
7372
> = {
7473
allocationID: x => x,
7574
subgraphDeploymentID: x => x,

packages/indexer-agent/src/agent.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import mapValues from 'lodash.mapvalues'
4747
import zip from 'lodash.zip'
4848
import { AgentConfigs, NetworkAndOperator } from './types'
4949

50-
type ActionReconciliationContext = [AllocationDecision[], number, number]
50+
type ActionReconciliationContext = [AllocationDecision[], number, bigint]
5151

5252
const deploymentInList = (
5353
list: SubgraphDeploymentID[],
@@ -270,15 +270,15 @@ export class Agent {
270270
},
271271
)
272272

273-
const maxAllocationEpochs: Eventual<NetworkMapped<number>> =
273+
const maxAllocationEpochs: Eventual<NetworkMapped<bigint>> =
274274
sequentialTimerMap(
275275
{ logger, milliseconds: requestIntervalLarge },
276276
() =>
277277
this.multiNetworks.map(({ network }) => {
278278
logger.trace('Fetching max allocation epochs', {
279279
protocolNetwork: network.specification.networkIdentifier,
280280
})
281-
return network.contracts.staking.maxAllocationEpochs()
281+
return network.contracts.LegacyStaking.maxAllocationEpochs()
282282
}),
283283
{
284284
onError: error =>
@@ -304,9 +304,9 @@ export class Agent {
304304
await network.networkMonitor.subgraphs(subgraphRuleIds)
305305
if (subgraphsMatchingRules.length >= 1) {
306306
const epochLength =
307-
await network.contracts.epochManager.epochLength()
307+
await network.contracts.EpochManager.epochLength()
308308
const blockPeriod = 15
309-
const bufferPeriod = epochLength.toNumber() * blockPeriod * 100 // 100 epochs
309+
const bufferPeriod = Number(epochLength) * blockPeriod * 100 // 100 epochs
310310
rules = convertSubgraphBasedRulesToDeploymentBased(
311311
rules,
312312
subgraphsMatchingRules,
@@ -486,7 +486,7 @@ export class Agent {
486486
const matchingTransfer = eligibleTransferDeployments.find(
487487
deployment =>
488488
deployment.ipfsHash == decision.deployment.ipfsHash &&
489-
deployment.startedTransferToL2At.toNumber() > oneWeekAgo,
489+
Number(deployment.startedTransferToL2At) > oneWeekAgo,
490490
)
491491
if (matchingTransfer) {
492492
logger.debug('Found a matching subgraph transfer', {
@@ -682,7 +682,8 @@ export class Agent {
682682
currentEpochNumber: number,
683683
) =>
684684
currentEpochNumber -
685-
network.specification.indexerOptions.poiDisputableEpochs,
685+
(network.specification.indexerOptions
686+
.poiDisputableEpochs as number),
686687
)
687688

688689
// Find disputable allocations
@@ -821,22 +822,22 @@ export class Agent {
821822
await network.networkProvider.getBlock(
822823
pool.previousEpochStartBlockHash!,
823824
)
824-
pool.closedAtEpochStartBlockNumber = closedAtEpochStartBlock.number
825+
pool.closedAtEpochStartBlockNumber = closedAtEpochStartBlock!.number
825826
pool.referencePOI = await this.graphNode.proofOfIndexing(
826827
pool.subgraphDeployment,
827828
{
828-
number: closedAtEpochStartBlock.number,
829-
hash: closedAtEpochStartBlock.hash,
829+
number: closedAtEpochStartBlock!.number,
830+
hash: closedAtEpochStartBlock!.hash!,
830831
},
831832
pool.allocationIndexer,
832833
)
833-
pool.previousEpochStartBlockHash = previousEpochStartBlock.hash
834-
pool.previousEpochStartBlockNumber = previousEpochStartBlock.number
834+
pool.previousEpochStartBlockHash = previousEpochStartBlock!.hash!
835+
pool.previousEpochStartBlockNumber = previousEpochStartBlock!.number
835836
pool.referencePreviousPOI = await this.graphNode.proofOfIndexing(
836837
pool.subgraphDeployment,
837838
{
838-
number: previousEpochStartBlock.number,
839-
hash: previousEpochStartBlock.hash,
839+
number: previousEpochStartBlock!.number,
840+
hash: previousEpochStartBlock!.hash!,
840841
},
841842
pool.allocationIndexer,
842843
)
@@ -1006,13 +1007,13 @@ export class Agent {
10061007
activeAllocations: Allocation[],
10071008
deploymentAllocationDecision: AllocationDecision,
10081009
epoch: number,
1009-
maxAllocationEpochs: number,
1010+
maxAllocationEpochs: bigint,
10101011
network: Network,
10111012
): Promise<Allocation[]> {
10121013
const desiredAllocationLifetime = deploymentAllocationDecision.ruleMatch
10131014
.rule?.allocationLifetime
10141015
? deploymentAllocationDecision.ruleMatch.rule.allocationLifetime
1015-
: Math.max(1, maxAllocationEpochs - 1)
1016+
: Math.max(1, Number(maxAllocationEpochs) - 1)
10161017

10171018
// Identify expiring allocations
10181019
let expiredAllocations = activeAllocations.filter(
@@ -1028,8 +1029,8 @@ export class Agent {
10281029
async (allocation: Allocation) => {
10291030
try {
10301031
const onChainAllocation =
1031-
await network.contracts.staking.getAllocation(allocation.id)
1032-
return onChainAllocation.closedAtEpoch.eq('0')
1032+
await network.contracts.LegacyStaking.getAllocation(allocation.id)
1033+
return onChainAllocation.closedAtEpoch == 0n
10331034
} catch (err) {
10341035
this.logger.warn(
10351036
`Failed to cross-check allocation state with contracts; assuming it needs to be closed`,
@@ -1050,7 +1051,7 @@ export class Agent {
10501051
deploymentAllocationDecision: AllocationDecision,
10511052
activeAllocations: Allocation[],
10521053
epoch: number,
1053-
maxAllocationEpochs: number,
1054+
maxAllocationEpochs: bigint,
10541055
network: Network,
10551056
operator: Operator,
10561057
): Promise<void> {
@@ -1145,7 +1146,7 @@ export class Agent {
11451146
async reconcileActions(
11461147
networkDeploymentAllocationDecisions: NetworkMapped<AllocationDecision[]>,
11471148
epoch: NetworkMapped<number>,
1148-
maxAllocationEpochs: NetworkMapped<number>,
1149+
maxAllocationEpochs: NetworkMapped<bigint>,
11491150
): Promise<void> {
11501151
// --------------------------------------------------------------------------------
11511152
// Filter out networks set to `manual` allocation management mode, and ensure the

packages/indexer-agent/src/commands/start.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { createSyncingServer } from '../syncing-server'
3131
import { injectCommonStartupOptions } from './common-options'
3232
import pMap from 'p-map'
3333
import { NetworkSpecification } from '@graphprotocol/indexer-common/dist/network-specification'
34-
import { BigNumber } from 'ethers'
3534
import { displayZodParsingError } from '@graphprotocol/indexer-common'
3635
import { readFileSync } from 'fs'
3736
import { AgentConfigs } from '../types'
@@ -601,7 +600,7 @@ export async function run(
601600
defaults: {
602601
globalIndexingRule: {
603602
// TODO: Update this, there will be defaults per network
604-
allocationAmount: BigNumber.from(100),
603+
allocationAmount: BigInt(100),
605604
parallelAllocations: 1,
606605
},
607606
},

packages/indexer-agent/src/db/migrations/14-cost-models-history.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Logger } from '@graphprotocol/common-ts'
2-
import { utils } from 'ethers'
2+
import { isHexString } from 'ethers'
33
import { QueryInterface, DataTypes } from 'sequelize'
44

55
interface MigrationContext {
@@ -45,7 +45,7 @@ export async function up({ context }: Context): Promise<void> {
4545
throw new Error('Deployment ID must be a string')
4646
}
4747
// "0x..." and "global" is ok
48-
if (utils.isHexString(value, 32) || value === COST_MODEL_GLOBAL) {
48+
if (isHexString(value, 32) || value === COST_MODEL_GLOBAL) {
4949
return
5050
}
5151

packages/indexer-cli/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
// The glob patterns Jest uses to detect test files
1414
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
1515
testPathIgnorePatterns: ['/node_modules/', '/dist/', '.yalc'],
16+
transformIgnorePatterns: ['!node_modules/'],
1617
testTimeout: 60000,
1718
globals: {
1819
__DATABASE__: {

packages/indexer-cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
"test:watch": "jest --watch --detectOpenHandles --verbose"
2727
},
2828
"dependencies": {
29-
"@graphprotocol/common-ts": "2.0.11",
29+
"@graphprotocol/common-ts": "3.0.1",
3030
"@graphprotocol/indexer-common": "^0.23.5",
3131
"@iarna/toml": "2.2.5",
3232
"@thi.ng/iterators": "5.1.74",
3333
"@urql/core": "3.1.0",
3434
"chalk": "4.1.2",
3535
"env-paths": "2.2.1",
36-
"ethers": "5.7.0",
36+
"ethers": "6.13.7",
3737
"gluegun": "4.7.0",
3838
"graphql-tag": "2.12.6",
3939
"isomorphic-fetch": "3.0.0",
@@ -53,7 +53,7 @@
5353
"typescript": "5.2.2"
5454
},
5555
"resolutions": {
56-
"ethers": "5.7.0",
56+
"ethers": "6.13.7",
5757
"sequelize": "6.33.0"
5858
},
5959
"gitHead": "972ab96774007b2aee15b1da169d2ff4be9f9d27"

packages/indexer-cli/src/actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from '@graphprotocol/indexer-common'
1515
import { validatePOI, validateRequiredParams } from './command-helpers'
1616
import gql from 'graphql-tag'
17-
import { utils } from 'ethers'
17+
import { hexlify } from 'ethers'
1818
import { parseGRT } from '@graphprotocol/common-ts'
1919

2020
export interface GenericActionInputParams {
@@ -51,7 +51,7 @@ export async function buildActionInput(
5151
case ActionType.UNALLOCATE: {
5252
let poi = actionParams.param2
5353
if (poi == '0' || poi == '0x0') {
54-
poi = utils.hexlify(Array(32).fill(0))
54+
poi = hexlify(new Uint8Array(32).fill(0))
5555
}
5656
return {
5757
deploymentID: actionParams.targetDeployment,
@@ -69,7 +69,7 @@ export async function buildActionInput(
6969
case ActionType.REALLOCATE: {
7070
let poi = actionParams.param3
7171
if (poi == '0' || poi == '0x0') {
72-
poi = utils.hexlify(Array(32).fill(0))
72+
poi = hexlify(new Uint8Array(32).fill(0))
7373
}
7474
return {
7575
deploymentID: actionParams.targetDeployment,

0 commit comments

Comments
 (0)