Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexer-common: Updates to deprecate old payment systems after exponential rebates contract changes #774

Merged
merged 14 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
},
"resolutions": {
"ethers": "5.7.0",
"sequelize": "6.31.1",
"sequelize": "6.33.0",
"@ethersproject/bignumber": "5.7.0",
"@ethersproject/providers": "5.7.0",
"@urql/core": "2.4.4",
"@urql/exchange-execute": "1.2.2"
},
"overrides": {
"ethers": "5.7.0",
"sequelize": "6.31.1",
"sequelize": "6.33.0",
"@ethersproject/bignumber": "5.7.0",
"@ethersproject/providers": "5.7.0",
"@urql/core": "2.4.4",
"@urql/exchange-execute": "1.2.2",
"graphql": "16.3.0"
"graphql": "16.8.0"
},
"engines": {
"node": ">=12.22.0"
Expand Down
28 changes: 14 additions & 14 deletions packages/indexer-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"graph-indexer-agent": "bin/graph-indexer-agent"
},
"dependencies": {
"@graphprotocol/common-ts": "2.0.3",
"@graphprotocol/common-ts": "2.0.7",
"@graphprotocol/indexer-common": "^0.20.21",
"@thi.ng/heaps": "^1.3.1",
"@uniswap/sdk": "3.0.3",
Expand All @@ -39,11 +39,11 @@
"ethers": "5.7.0",
"evt": "1.9.12",
"global": "4.4.0",
"graphql": "16.3.0",
"graphql": "16.8.0",
"graphql-tag": "2.12.6",
"isomorphic-fetch": "3.0.0",
"jayson": "3.6.6",
"lodash.isequal": "^4.5.0",
"lodash.isequal": "4.5.0",
"lodash.mapvalues": "^4.6.0",
"lodash.zip": "^4.2.0",
"ngeohash": "0.6.3",
Expand All @@ -61,28 +61,28 @@
"devDependencies": {
"@types/bs58": "4.0.1",
"@types/isomorphic-fetch": "0.0.36",
"@types/jest": "27.4.1",
"@types/jest": "29.5.4",
"@types/lodash.countby": "^4.6.7",
"@types/lodash.isequal": "^4.5.6",
"@types/lodash.isequal": "4.5.6",
"@types/lodash.mapvalues": "^4.6.7",
"@types/lodash.zip": "^4.2.7",
"@types/ngeohash": "0.6.4",
"@types/node": "17.0.23",
"@types/node": "20.6.1",
"@types/yargs": "17.0.10",
"@typescript-eslint/eslint-plugin": "5.19.0",
"@typescript-eslint/parser": "5.19.0",
"eslint": "8.13.0",
"@typescript-eslint/eslint-plugin": "6.7.0",
"@typescript-eslint/parser": "6.7.0",
"eslint": "8.49.0",
"eslint-config-prettier": "^8.5.0",
"jest": "27.5.1",
"prettier": "2.6.2",
"ts-jest": "27.1.4",
"jest": "<30.0.0-0",
"prettier": "3.0.3",
"ts-jest": "29.1.1",
"ts-node": "10.7.0",
"typechain": "8.0.0",
"typescript": "4.6.3"
"typescript": "5.2.2"
},
"resolutions": {
"ethers": "5.7.0",
"sequelize": "6.31.1",
"sequelize": "6.33.0",
"@ethersproject/bignumber": "5.7.0",
"@ethersproject/providers": "5.7.0"
},
Expand Down
94 changes: 0 additions & 94 deletions packages/indexer-agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,6 @@ import pFilter from 'p-filter'
import mapValues from 'lodash.mapvalues'
import zip from 'lodash.zip'

// The new Exponential Rebates for Indexes brought changes to the protocol contracts that deprecated
// the following methods:
// - channelDisputeEpochs
// - claimRebateRewards
// This variable acts as a signal to other parts of the code, showing that we've ignored the results
// of these calls early in the current process.
// This is important because the Exponential Rebates aren't active on the mainnet yet, which still
// uses their results. Once those contract changes have been deployed to all networks, these calls
// can be removed from the code.
const EXPONENTIAL_REBATES_MARKER = -1

type ActionReconciliationContext = [AllocationDecision[], number, number]

const deploymentInList = (
Expand Down Expand Up @@ -288,31 +277,6 @@ export class Agent {
},
)

const channelDisputeEpochs: Eventual<NetworkMapped<number>> = timer(
600_000,
).map(() =>
this.multiNetworks.map(async ({ network }) => {
logger.trace('Fetching channel dispute epochs', {
protocolNetwork: network.specification.networkIdentifier,
})
try {
return await network.contracts.staking.channelDisputeEpochs()
} catch (error) {
// Disregards `channelDisputeEpochs` value from this point forward.
// TODO: Investigate error to confirm it comes from a reverted call.
logger.warn(
'Failed to fetch channel dispute epochs. ' +
'Ignoring claimable allocations for this reconciliation cycle.',
{
error,
protocolNetwork: network.specification.networkIdentifier,
},
)
return EXPONENTIAL_REBATES_MARKER
}
}),
)

const maxAllocationEpochs: Eventual<NetworkMapped<number>> = timer(
600_000,
).tryMap(
Expand Down Expand Up @@ -657,40 +621,6 @@ export class Agent {
},
)

const claimableAllocations: Eventual<NetworkMapped<Allocation[]>> = join({
currentEpochNumber,
channelDisputeEpochs,
}).tryMap(
async ({ currentEpochNumber, channelDisputeEpochs }) =>
this.multiNetworks.mapNetworkMapped(
this.multiNetworks.zip(currentEpochNumber, channelDisputeEpochs),
async (
{ network }: NetworkAndOperator,
[currentEpochNumber, channelDisputeEpochs]: [number, number],
): Promise<Allocation[]> => {
logger.trace('Fetching claimable allocations', {
protocolNetwork: network.specification.networkIdentifier,
currentEpochNumber,
channelDisputeEpochs,
})
if (channelDisputeEpochs === EXPONENTIAL_REBATES_MARKER) {
return [] // Ignore claimable allocations in Exponential Rebates context
} else {
return network.networkMonitor.claimableAllocations(
currentEpochNumber - channelDisputeEpochs,
)
}
},
),

{
onError: () =>
logger.warn(
`Failed to obtain claimable allocations, trying again later`,
),
},
)

const disputableAllocations: Eventual<NetworkMapped<Allocation[]>> = join({
currentEpochNumber,
activeDeployments,
Expand Down Expand Up @@ -728,7 +658,6 @@ export class Agent {
activeAllocations,
networkDeploymentAllocationDecisions,
recentlyClosedAllocations,
claimableAllocations,
disputableAllocations,
}).pipe(
async ({
Expand All @@ -739,35 +668,12 @@ export class Agent {
activeAllocations,
networkDeploymentAllocationDecisions,
recentlyClosedAllocations,
claimableAllocations,
disputableAllocations,
}) => {
logger.info(`Reconcile with the network`, {
currentEpochNumber,
})

// Claim rebate pool rewards from finalized allocations
await this.multiNetworks.mapNetworkMapped(
claimableAllocations,
async (
{ network }: NetworkAndOperator,
allocations: Allocation[],
) => {
const protocolNetwork = network.specification.networkIdentifier
if (allocations.length) {
logger.debug(
`Claiming rebate rewards for ${allocations.length} allocations`,
{ allocations, protocolNetwork },
)
return network.claimRebateRewards(allocations)
} else {
logger.debug('Found no allocations to claim rebate rewards for', {
protocolNetwork,
})
}
},
)

try {
const disputableEpochs = await this.multiNetworks.mapNetworkMapped(
currentEpochNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ class Migration {
// Only for the UP step
async processMigrationInput(input: MigrationInput): Promise<MigrationTarget> {
this.logger.debug(`Inferring primary key name for table '${input.table}'`)
const oldPrimaryKeyConstraint = await this.getPrimaryKeyConstraintName(
input,
)
const oldPrimaryKeyConstraint =
await this.getPrimaryKeyConstraintName(input)
this.logger.debug(
`Table '${input.table}' existing primary key name is '${oldPrimaryKeyConstraint}'`,
)
Expand All @@ -259,9 +258,8 @@ class Migration {
async processMigrationInputDown(
input: MigrationInput,
): Promise<MigrationTarget> {
const currentPrimaryKeyConstraint = await this.getPrimaryKeyConstraintName(
input,
)
const currentPrimaryKeyConstraint =
await this.getPrimaryKeyConstraintName(input)
let previousPrimaryKeyConstraint
if (currentPrimaryKeyConstraint.endsWith(MANUAL_CONSTRAINT_NAME_FRAGMENT)) {
previousPrimaryKeyConstraint = currentPrimaryKeyConstraint.replace(
Expand Down
16 changes: 8 additions & 8 deletions packages/indexer-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test:watch": "jest --watch --detectOpenHandles --verbose"
},
"dependencies": {
"@graphprotocol/common-ts": "2.0.3",
"@graphprotocol/common-ts": "2.0.7",
"@graphprotocol/indexer-common": "^0.20.21",
"@iarna/toml": "2.2.5",
"@thi.ng/iterators": "5.1.74",
Expand All @@ -43,18 +43,18 @@
"devDependencies": {
"@types/isomorphic-fetch": "0.0.36",
"@types/lodash.clonedeep": "^4.5.7",
"@typescript-eslint/eslint-plugin": "5.19.0",
"@typescript-eslint/parser": "5.19.0",
"eslint": "8.13.0",
"@typescript-eslint/eslint-plugin": "6.7.0",
"@typescript-eslint/parser": "6.7.0",
"eslint": "8.49.0",
"eslint-config-prettier": "8.5.0",
"lodash.clonedeep": "^4.5.0",
"prettier": "2.6.2",
"ts-jest": "27.1.4",
"typescript": "4.6.3"
"prettier": "3.0.3",
"ts-jest": "29.1.1",
"typescript": "5.2.2"
},
"resolutions": {
"ethers": "5.7.0",
"sequelize": "6.31.1"
"sequelize": "6.33.0"
},
"gitHead": "972ab96774007b2aee15b1da169d2ff4be9f9d27"
}
38 changes: 18 additions & 20 deletions packages/indexer-cli/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,25 @@ export async function executeApprovedActions(
client: IndexerManagementClient,
): Promise<ActionResult[]> {
const result = await client
.mutation(
gql`
mutation executeApprovedActions {
executeApprovedActions {
id
protocolNetwork
status
type
deploymentID
allocationID
amount
poi
force
source
reason
transaction
failureReason
}
.mutation(gql`
mutation executeApprovedActions {
executeApprovedActions {
id
protocolNetwork
status
type
deploymentID
allocationID
amount
poi
force
source
reason
transaction
failureReason
}
`,
)
}
`)
.toPromise()

if (result.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
try {
poi = validatePOI(unformattedPoi)
} catch (error) {
spinner.fail(`Invalid POI provided, '${unformattedPoi}'. ` + error.message())
spinner.fail(`Invalid POI provided, '${unformattedPoi}'. ` + error.message)
process.exitCode = 1
return
}
Expand Down
18 changes: 8 additions & 10 deletions packages/indexer-cli/src/cost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,15 @@ export const costModels = async (
client: IndexerManagementClient,
): Promise<Partial<CostModelAttributes>[]> => {
const result = await client
.query(
gql`
{
costModels {
deployment
model
variables
}
.query(gql`
{
costModels {
deployment
model
variables
}
`,
)
}
`)
.toPromise()

if (result.error) {
Expand Down
Loading
Loading