From 0576c9c9df5621e8bc18d91e9f3afb368c819aab Mon Sep 17 00:00:00 2001 From: tilacog Date: Tue, 19 Sep 2023 11:33:48 -0300 Subject: [PATCH] common: remove stakingABI workaround for exponential rebates --- packages/indexer-common/package.json | 1 - .../src/abi/stakingUpdatedABI.json | 1 - packages/indexer-common/src/transactions.ts | 35 +++++-------------- packages/indexer-common/tsconfig.json | 2 +- 4 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 packages/indexer-common/src/abi/stakingUpdatedABI.json diff --git a/packages/indexer-common/package.json b/packages/indexer-common/package.json index 0fac9a1b6..787e39508 100644 --- a/packages/indexer-common/package.json +++ b/packages/indexer-common/package.json @@ -40,7 +40,6 @@ "graphql-tag": "2.12.6", "jayson": "3.6.6", "lodash.groupby": "^4.6.0", - "lodash.intersection": "^4.4.0", "lodash.isequal": "4.5.0", "lodash.xor": "^4.5.0", "morgan": "1.10.0", diff --git a/packages/indexer-common/src/abi/stakingUpdatedABI.json b/packages/indexer-common/src/abi/stakingUpdatedABI.json deleted file mode 100644 index 472f7f7bb..000000000 --- a/packages/indexer-common/src/abi/stakingUpdatedABI.json +++ /dev/null @@ -1 +0,0 @@ -[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":true,"internalType":"bytes32","name":"subgraphDeploymentID","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"},{"indexed":true,"internalType":"address","name":"allocationID","type":"address"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"bytes32","name":"poi","type":"bytes32"},{"indexed":false,"internalType":"bool","name":"isPublic","type":"bool"}],"name":"AllocationClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":true,"internalType":"bytes32","name":"subgraphDeploymentID","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"},{"indexed":true,"internalType":"address","name":"allocationID","type":"address"},{"indexed":false,"internalType":"bytes32","name":"metadata","type":"bytes32"}],"name":"AllocationCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"assetHolder","type":"address"},{"indexed":false,"internalType":"bool","name":"allowed","type":"bool"}],"name":"AssetHolderUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"nameHash","type":"bytes32"},{"indexed":false,"internalType":"address","name":"contractAddress","type":"address"}],"name":"ContractSynced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":false,"internalType":"uint32","name":"indexingRewardCut","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"queryFeeCut","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"cooldownBlocks","type":"uint32"}],"name":"DelegationParametersUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"l2Delegator","type":"address"},{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":false,"internalType":"address","name":"l2Indexer","type":"address"},{"indexed":false,"internalType":"uint256","name":"transferredDelegationTokens","type":"uint256"}],"name":"DelegationTransferredToL2","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"extensionImpl","type":"address"}],"name":"ExtensionImplementationSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":true,"internalType":"address","name":"l2Indexer","type":"address"},{"indexed":false,"internalType":"uint256","name":"transferredStakeTokens","type":"uint256"}],"name":"IndexerStakeTransferredToL2","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"l1GraphTokenLockTransferTool","type":"address"}],"name":"L1GraphTokenLockTransferToolSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"param","type":"string"}],"name":"ParameterUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"assetHolder","type":"address"},{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":true,"internalType":"bytes32","name":"subgraphDeploymentID","type":"bytes32"},{"indexed":true,"internalType":"address","name":"allocationID","type":"address"},{"indexed":false,"internalType":"uint256","name":"epoch","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolTax","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curationFees","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"queryFees","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"queryRebates","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"delegationRewards","type":"uint256"}],"name":"RebateCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"controller","type":"address"}],"name":"SetController","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"allowed","type":"bool"}],"name":"SetOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":true,"internalType":"address","name":"destination","type":"address"}],"name":"SetRewardsDestination","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":true,"internalType":"address","name":"delegator","type":"address"}],"name":"StakeDelegatedUnlockedDueToL2Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"}],"name":"StakeDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"until","type":"uint256"}],"name":"StakeLocked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"indexer","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"}],"name":"StakeWithdrawn","type":"event"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[{"internalType":"contract IGraphProxy","name":"_proxy","type":"address"}],"name":"acceptProxy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IGraphProxy","name":"_proxy","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"acceptProxyAndCall","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_subgraphDeploymentID","type":"bytes32"},{"internalType":"uint256","name":"_tokens","type":"uint256"},{"internalType":"address","name":"_allocationID","type":"address"},{"internalType":"bytes32","name":"_metadata","type":"bytes32"},{"internalType":"bytes","name":"_proof","type":"bytes"}],"name":"allocate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"},{"internalType":"bytes32","name":"_subgraphDeploymentID","type":"bytes32"},{"internalType":"uint256","name":"_tokens","type":"uint256"},{"internalType":"address","name":"_allocationID","type":"address"},{"internalType":"bytes32","name":"_metadata","type":"bytes32"},{"internalType":"bytes","name":"_proof","type":"bytes"}],"name":"allocateFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_allocationID","type":"address"},{"internalType":"bytes32","name":"_poi","type":"bytes32"}],"name":"closeAllocation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokens","type":"uint256"},{"internalType":"address","name":"_allocationID","type":"address"}],"name":"collect","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"controller","outputs":[{"internalType":"contract IController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_allocationID","type":"address"}],"name":"getAllocation","outputs":[{"components":[{"internalType":"address","name":"indexer","type":"address"},{"internalType":"bytes32","name":"subgraphDeploymentID","type":"bytes32"},{"internalType":"uint256","name":"tokens","type":"uint256"},{"internalType":"uint256","name":"createdAtEpoch","type":"uint256"},{"internalType":"uint256","name":"closedAtEpoch","type":"uint256"},{"internalType":"uint256","name":"collectedFees","type":"uint256"},{"internalType":"uint256","name":"__DEPRECATED_effectiveAllocation","type":"uint256"},{"internalType":"uint256","name":"accRewardsPerAllocatedToken","type":"uint256"},{"internalType":"uint256","name":"distributedRebates","type":"uint256"}],"internalType":"struct IStakingData.Allocation","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_allocationID","type":"address"}],"name":"getAllocationState","outputs":[{"internalType":"enum IStakingBase.AllocationState","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"}],"name":"getIndexerCapacity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"}],"name":"getIndexerStakedTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_subgraphDeploymentID","type":"bytes32"}],"name":"getSubgraphAllocatedTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"}],"name":"hasStake","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"indexerTransferredToL2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_controller","type":"address"},{"internalType":"uint256","name":"_minimumIndexerStake","type":"uint256"},{"internalType":"uint32","name":"_thawingPeriod","type":"uint32"},{"internalType":"uint32","name":"_protocolPercentage","type":"uint32"},{"internalType":"uint32","name":"_curationPercentage","type":"uint32"},{"internalType":"uint32","name":"_maxAllocationEpochs","type":"uint32"},{"internalType":"uint32","name":"_delegationUnbondingPeriod","type":"uint32"},{"internalType":"uint32","name":"_delegationRatio","type":"uint32"},{"components":[{"internalType":"uint32","name":"alphaNumerator","type":"uint32"},{"internalType":"uint32","name":"alphaDenominator","type":"uint32"},{"internalType":"uint32","name":"lambdaNumerator","type":"uint32"},{"internalType":"uint32","name":"lambdaDenominator","type":"uint32"}],"internalType":"struct IStakingData.RebatesParameters","name":"_rebatesParameters","type":"tuple"},{"internalType":"address","name":"_extensionImpl","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_allocationID","type":"address"}],"name":"isAllocation","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"address","name":"_indexer","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_assetHolder","type":"address"},{"internalType":"bool","name":"_allowed","type":"bool"}],"name":"setAssetHolder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_controller","type":"address"}],"name":"setController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_counterpart","type":"address"}],"name":"setCounterpartStakingAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_percentage","type":"uint32"}],"name":"setCurationPercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_indexingRewardCut","type":"uint32"},{"internalType":"uint32","name":"_queryFeeCut","type":"uint32"},{"internalType":"uint32","name":"_cooldownBlocks","type":"uint32"}],"name":"setDelegationParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_extensionImpl","type":"address"}],"name":"setExtensionImpl","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IL1GraphTokenLockTransferTool","name":"_l1GraphTokenLockTransferTool","type":"address"}],"name":"setL1GraphTokenLockTransferTool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_maxAllocationEpochs","type":"uint32"}],"name":"setMaxAllocationEpochs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minimumIndexerStake","type":"uint256"}],"name":"setMinimumIndexerStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"bool","name":"_allowed","type":"bool"}],"name":"setOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_percentage","type":"uint32"}],"name":"setProtocolPercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_alphaNumerator","type":"uint32"},{"internalType":"uint32","name":"_alphaDenominator","type":"uint32"},{"internalType":"uint32","name":"_lambdaNumerator","type":"uint32"},{"internalType":"uint32","name":"_lambdaDenominator","type":"uint32"}],"name":"setRebateParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_destination","type":"address"}],"name":"setRewardsDestination","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_thawingPeriod","type":"uint32"}],"name":"setThawingPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokens","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"},{"internalType":"uint256","name":"_tokens","type":"uint256"}],"name":"stakeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"syncAllContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"},{"internalType":"address","name":"_l2Beneficiary","type":"address"},{"internalType":"uint256","name":"_maxGas","type":"uint256"},{"internalType":"uint256","name":"_gasPriceBid","type":"uint256"},{"internalType":"uint256","name":"_maxSubmissionCost","type":"uint256"}],"name":"transferDelegationToL2","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"},{"internalType":"uint256","name":"_maxGas","type":"uint256"},{"internalType":"uint256","name":"_gasPriceBid","type":"uint256"},{"internalType":"uint256","name":"_maxSubmissionCost","type":"uint256"}],"name":"transferLockedDelegationToL2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_maxGas","type":"uint256"},{"internalType":"uint256","name":"_gasPriceBid","type":"uint256"},{"internalType":"uint256","name":"_maxSubmissionCost","type":"uint256"}],"name":"transferLockedStakeToL2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_l2Beneficiary","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_maxGas","type":"uint256"},{"internalType":"uint256","name":"_gasPriceBid","type":"uint256"},{"internalType":"uint256","name":"_maxSubmissionCost","type":"uint256"}],"name":"transferStakeToL2","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_indexer","type":"address"}],"name":"unlockDelegationToTransferredIndexer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokens","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}] \ No newline at end of file diff --git a/packages/indexer-common/src/transactions.ts b/packages/indexer-common/src/transactions.ts index 7d691b641..390041f3a 100644 --- a/packages/indexer-common/src/transactions.ts +++ b/packages/indexer-common/src/transactions.ts @@ -22,8 +22,6 @@ import { IndexerError, indexerError, IndexerErrorCode } from './errors' import { TransactionConfig, TransactionType } from './types' import { NetworkSubgraph } from './network-subgraph' import gql from 'graphql-tag' -import intersection from 'lodash.intersection' -import updatedStakingAbi from './abi/stakingUpdatedABI.json' export class TransactionManager { ethereum: providers.BaseProvider @@ -413,42 +411,27 @@ export class TransactionManager { ): utils.Result | undefined { const events: Event[] | providers.Log[] = receipt.events || receipt.logs const decodedEvents: utils.Result[] = [] - const updatedStakingIface = new utils.Interface(updatedStakingAbi) - - // With exponential rebates, the AllocationClosed event changed signature - // so it has a different topic. Until these changes are deployed in both mainnet and - // testnet, we need to search for both. - // TODO: Update to a new common-ts and remove this hack once exponential rebates is on mainnet - const newAbiTopic = updatedStakingIface.getEventTopic('AllocationClosed') - const expectedTopics = [contractInterface.getEventTopic(eventType)] - if (eventType == 'AllocationClosed') { - expectedTopics.push(newAbiTopic) - } + const expectedTopic = contractInterface.getEventTopic(eventType) const result = events - .filter((event) => intersection(event.topics, expectedTopics).length > 0) + .filter((event) => event.topics.includes(expectedTopic)) .map((event) => { - let decoded: utils.Result - if (eventType == 'AllocationClosed' && event.topics.includes(newAbiTopic)) { - decoded = updatedStakingIface.decodeEventLog( - eventType, - event.data, - event.topics, - ) - } else { - decoded = contractInterface.decodeEventLog(eventType, event.data, event.topics) - } + const decoded = contractInterface.decodeEventLog( + eventType, + event.data, + event.topics, + ) decodedEvents.push(decoded) return decoded }) .find( - (eventLogs: utils.Result) => + (eventLogs) => eventLogs[logKey].toLocaleLowerCase() === logValue.toLocaleLowerCase(), ) logger.trace('Searched for event logs', { function: 'findEvent', - expectedTopics, + expectedTopic, events, decodedEvents, eventType, diff --git a/packages/indexer-common/tsconfig.json b/packages/indexer-common/tsconfig.json index e13a85d3a..7777d9321 100644 --- a/packages/indexer-common/tsconfig.json +++ b/packages/indexer-common/tsconfig.json @@ -19,7 +19,7 @@ ], "resolveJsonModule": true }, - "include": ["src/**/*.ts", "src/abi/stakingUpdatedABI.json"], + "include": ["src/**/*.ts"], "exclude": [], "references": [] }