From b3c26894b2e575273adc6f5e5a6aec9414b21135 Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Tue, 28 Nov 2023 20:17:14 -0800 Subject: [PATCH 1/2] possible fix for governance contract processing --- src/ogv/post-processors/governance.ts | 138 ++++++++++++++++---------- src/ogv/processors/ogv-supply.ts | 20 ++-- 2 files changed, 99 insertions(+), 59 deletions(-) diff --git a/src/ogv/post-processors/governance.ts b/src/ogv/post-processors/governance.ts index 93d53372..e06f9380 100644 --- a/src/ogv/post-processors/governance.ts +++ b/src/ogv/post-processors/governance.ts @@ -1,33 +1,31 @@ import { EvmBatchProcessor } from '@subsquid/evm-processor' -import * as erc20Abi from '../../abi/erc20' import * as governanceAbi from '../../abi/governance' -import { OGVAddress, OGVProposal, OGVProposalEvent, OGVProposalState, OGVProposalTxLog, OGVProposalVote, OGVVoteType } from '../../model' -import { Block, Context, Log } from '../../processor' import { - GOVERNANCE_ADDRESS, - OGV_ADDRESS, - VEOGV_ADDRESS, -} from '../../utils/addresses' + OGVAddress, + OGVProposal, + OGVProposalEvent, + OGVProposalState, + OGVProposalTxLog, + OGVProposalVote, + OGVVoteType, +} from '../../model' +import { Block, Context, Log } from '../../processor' +import { GOVERNANCE_ADDRESS } from '../../utils/addresses' export const from = 14439231 // https://etherscan.io/tx/0x9295cac246169f06a3d4ec33fdbd87fced7a9e19ea61177cae75034e45ae66f4 -export const veogvFrom = 15089597 // https://etherscan.io/tx/0x70c582e56ea1c49b7e9df70a0b40ddbfac9362b8b172cb527c329c2302d7d48a +export const governanceFrom = 15491391 // https://etherscan.io/tx/0x0e04e429248c384e6b36229edf8eb5a77bec7023c58808c21b702edfcbc0e0d6 interface IProcessResult { - addresses: Map, - proposals: Map, - proposalLogs: OGVProposalTxLog[], - votes: OGVProposalVote[], + addresses: Map + proposals: Map + proposalLogs: OGVProposalTxLog[] + votes: OGVProposalVote[] } export const setup = (processor: EvmBatchProcessor) => { processor.addLog({ - address: [OGV_ADDRESS], - topic0: [erc20Abi.events.Transfer.topic], - range: { from }, - }) - processor.addLog({ - address: [VEOGV_ADDRESS], + address: [GOVERNANCE_ADDRESS], topic0: [ governanceAbi.events.ProposalCreated, governanceAbi.events.ProposalExecuted, @@ -36,8 +34,8 @@ export const setup = (processor: EvmBatchProcessor) => { governanceAbi.events.ProposalCanceled, governanceAbi.events.VoteCast, governanceAbi.events.VoteCastWithParams, - ].map(ev => ev.topic), - range: { from: veogvFrom }, + ].map((ev) => ev.topic), + range: { from: governanceFrom }, }) } @@ -46,24 +44,35 @@ export const process = async (ctx: Context) => { addresses: new Map(), proposals: new Map(), proposalLogs: [], - votes: [] + votes: [], } for (const block of ctx.blocks) { for (const log of block.logs) { const firstTopic = log.topics[0] - if (![VEOGV_ADDRESS, OGV_ADDRESS].includes(log.address)) { + if (log.address !== GOVERNANCE_ADDRESS) { return } if (firstTopic == governanceAbi.events.ProposalCreated.topic) { - await _processProposalCreated(ctx, result, block, log); + await _processProposalCreated(ctx, result, block, log) } else if (firstTopic == governanceAbi.events.ProposalExtended.topic) { - await _processProposalExtended(ctx, result, block, log); - } else if ([governanceAbi.events.ProposalQueued.topic, governanceAbi.events.ProposalCanceled.topic, governanceAbi.events.ProposalExecuted.topic].includes(firstTopic)) { - await _processProposalEvents(ctx, result, block, log); - } else if ([governanceAbi.events.VoteCast.topic, governanceAbi.events.VoteCastWithParams.topic].includes(firstTopic)) { + await _processProposalExtended(ctx, result, block, log) + } else if ( + [ + governanceAbi.events.ProposalQueued.topic, + governanceAbi.events.ProposalCanceled.topic, + governanceAbi.events.ProposalExecuted.topic, + ].includes(firstTopic) + ) { + await _processProposalEvents(ctx, result, block, log) + } else if ( + [ + governanceAbi.events.VoteCast.topic, + governanceAbi.events.VoteCastWithParams.topic, + ].includes(firstTopic) + ) { await _processVoteCast(ctx, result, block, log) } } @@ -79,9 +88,15 @@ const _processProposalCreated = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { - const { proposalId, proposer: proposerAddr, description, startBlock, endBlock } = governanceAbi.events.ProposalCreated.decode(log) + const { + proposalId, + proposer: proposerAddr, + description, + startBlock, + endBlock, + } = governanceAbi.events.ProposalCreated.decode(log) const proposer = await _getAddress(ctx, proposerAddr, result) const blockTimestamp = new Date(block.header.timestamp) @@ -93,7 +108,7 @@ const _processProposalCreated = async ( startBlock, endBlock, lastUpdated: new Date(), - status: OGVProposalState.Pending + status: OGVProposalState.Pending, }) const proposalTxLog = new OGVProposalTxLog({ @@ -123,17 +138,17 @@ const eventMapper = { [governanceAbi.events.ProposalQueued.topic]: { decode: governanceAbi.events.ProposalQueued.decode, status: OGVProposalState.Queued, - event: OGVProposalEvent.Queued + event: OGVProposalEvent.Queued, }, [governanceAbi.events.ProposalCanceled.topic]: { decode: governanceAbi.events.ProposalCanceled.decode, status: OGVProposalState.Canceled, - event: OGVProposalEvent.Canceled + event: OGVProposalEvent.Canceled, }, [governanceAbi.events.ProposalExecuted.topic]: { decode: governanceAbi.events.ProposalExecuted.decode, status: OGVProposalState.Executed, - event: OGVProposalEvent.Executed + event: OGVProposalEvent.Executed, }, } @@ -141,7 +156,7 @@ const _processProposalEvents = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { const { decode, status, event } = eventMapper[log.topics[0]]! @@ -149,8 +164,7 @@ const _processProposalEvents = async ( const blockTimestamp = new Date(block.header.timestamp) const proposal = await _getProposal(ctx, proposalId.toString(), result) - proposal.status = status; - + proposal.status = status const proposalTxLog = new OGVProposalTxLog({ id: `${proposalId}:${log.transactionHash}:${log.logIndex}`, @@ -167,9 +181,10 @@ const _processProposalExtended = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { - const { proposalId, extendedDeadline } = governanceAbi.events.ProposalExtended.decode(log) + const { proposalId, extendedDeadline } = + governanceAbi.events.ProposalExtended.decode(log) const blockTimestamp = new Date(block.header.timestamp) const proposal = await _getProposal(ctx, proposalId.toString(), result) @@ -191,9 +206,12 @@ const _processVoteCast = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { - const decode = (log.topics[0] == governanceAbi.events.VoteCast.topic) ? governanceAbi.events.VoteCast.decode : governanceAbi.events.VoteCastWithParams.decode + const decode = + log.topics[0] == governanceAbi.events.VoteCast.topic + ? governanceAbi.events.VoteCast.decode + : governanceAbi.events.VoteCastWithParams.decode const { proposalId, voter: voterAddr, weight, support } = decode(log) const blockTimestamp = new Date(block.header.timestamp) @@ -207,20 +225,36 @@ const _processVoteCast = async ( txHash: log.transactionHash, timestamp: blockTimestamp, weight, - type: [OGVVoteType.Against, OGVVoteType.For, OGVVoteType.Abstain][parseInt(support.toString())] + type: [OGVVoteType.Against, OGVVoteType.For, OGVVoteType.Abstain][ + parseInt(support.toString()) + ], }) result.votes.push(proposalVote) } -const _getProposalState = async (ctx: Context, block: Block, proposalId: bigint): Promise => { - const governance = new governanceAbi.Contract(ctx, block.header, GOVERNANCE_ADDRESS) - return proposalStateMap[ - parseInt((await governance.state(proposalId)).toString()) - ] || OGVProposalState.Pending; +const _getProposalState = async ( + ctx: Context, + block: Block, + proposalId: bigint, +): Promise => { + const governance = new governanceAbi.Contract( + ctx, + block.header, + GOVERNANCE_ADDRESS, + ) + return ( + proposalStateMap[ + parseInt((await governance.state(proposalId)).toString()) + ] || OGVProposalState.Pending + ) } -const _getAddress = async (ctx: Context, id: string, result: IProcessResult): Promise => { +const _getAddress = async ( + ctx: Context, + id: string, + result: IProcessResult, +): Promise => { id = id.toLowerCase() const { addresses } = result @@ -229,7 +263,7 @@ const _getAddress = async (ctx: Context, id: string, result: IProcessResult): Pr } const address = await ctx.store.findOneByOrFail(OGVAddress, { - id + id, }) addresses.set(id, address) @@ -237,7 +271,11 @@ const _getAddress = async (ctx: Context, id: string, result: IProcessResult): Pr return address } -const _getProposal = async (ctx: Context, id: string, result: IProcessResult): Promise => { +const _getProposal = async ( + ctx: Context, + id: string, + result: IProcessResult, +): Promise => { const { proposals } = result if (proposals.has(id)) { @@ -245,7 +283,7 @@ const _getProposal = async (ctx: Context, id: string, result: IProcessResult): P } const proposal = await ctx.store.findOneByOrFail(OGVProposal, { - id + id, }) proposals.set(id, proposal) diff --git a/src/ogv/processors/ogv-supply.ts b/src/ogv/processors/ogv-supply.ts index eb082e77..a8796bef 100644 --- a/src/ogv/processors/ogv-supply.ts +++ b/src/ogv/processors/ogv-supply.ts @@ -1,28 +1,30 @@ -import { EvmBatchProcessor } from '@subsquid/evm-processor'; -import { Context } from '../../processor'; -import { blockFrequencyUpdater } from '../../utils/blockFrequencyUpdater'; -import { OGV } from '../../model'; +import { EvmBatchProcessor } from '@subsquid/evm-processor' import * as erc20Abi from '../../abi/erc20' -import { OGV_ADDRESS, VEOGV_ADDRESS } from '../../utils/addresses'; +import { OGV } from '../../model' +import { Context } from '../../processor' +import { OGV_ADDRESS, VEOGV_ADDRESS } from '../../utils/addresses' +import { blockFrequencyUpdater } from '../../utils/blockFrequencyUpdater' export const from = 14439231 // https://etherscan.io/tx/0x9295cac246169f06a3d4ec33fdbd87fced7a9e19ea61177cae75034e45ae66f4 export const setup = (processor: EvmBatchProcessor) => { processor.includeAllBlocks({ - from + from, }) } -const update = blockFrequencyUpdater({ from }) +const update = blockFrequencyUpdater({ from }) export const process = async (ctx: Context) => { const supplyData: OGV[] = [] await update(ctx, async (ctx, block) => { const ogvToken = new erc20Abi.Contract(ctx, block.header, OGV_ADDRESS) - const staked = await ogvToken.balanceOf(VEOGV_ADDRESS) - const total = await ogvToken.totalSupply() + const [staked, total] = await Promise.all([ + ogvToken.balanceOf(VEOGV_ADDRESS), + ogvToken.totalSupply(), + ]) const circulating = total - staked const supplyAtBlock = new OGV({ From 90752f20b5023daeb7f50988cdf76da5002dc148 Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Wed, 29 Nov 2023 10:23:06 -0800 Subject: [PATCH 2/2] fix governance/ogv (return statements, unbound functions, setup function not being called) --- src/ogv/post-processors/governance.ts | 59 ++++++----- src/ogv/processors/ogv.ts | 144 +++++++++++++++----------- src/processor.ts | 6 +- 3 files changed, 123 insertions(+), 86 deletions(-) diff --git a/src/ogv/post-processors/governance.ts b/src/ogv/post-processors/governance.ts index e06f9380..a23650b5 100644 --- a/src/ogv/post-processors/governance.ts +++ b/src/ogv/post-processors/governance.ts @@ -13,8 +13,7 @@ import { import { Block, Context, Log } from '../../processor' import { GOVERNANCE_ADDRESS } from '../../utils/addresses' -export const from = 14439231 // https://etherscan.io/tx/0x9295cac246169f06a3d4ec33fdbd87fced7a9e19ea61177cae75034e45ae66f4 -export const governanceFrom = 15491391 // https://etherscan.io/tx/0x0e04e429248c384e6b36229edf8eb5a77bec7023c58808c21b702edfcbc0e0d6 +export const from = 15491391 // https://etherscan.io/tx/0x0e04e429248c384e6b36229edf8eb5a77bec7023c58808c21b702edfcbc0e0d6 interface IProcessResult { addresses: Map @@ -27,19 +26,21 @@ export const setup = (processor: EvmBatchProcessor) => { processor.addLog({ address: [GOVERNANCE_ADDRESS], topic0: [ - governanceAbi.events.ProposalCreated, - governanceAbi.events.ProposalExecuted, - governanceAbi.events.ProposalExtended, - governanceAbi.events.ProposalQueued, - governanceAbi.events.ProposalCanceled, - governanceAbi.events.VoteCast, - governanceAbi.events.VoteCastWithParams, - ].map((ev) => ev.topic), - range: { from: governanceFrom }, + governanceAbi.events.ProposalCreated.topic, + governanceAbi.events.ProposalExecuted.topic, + governanceAbi.events.ProposalExtended.topic, + governanceAbi.events.ProposalQueued.topic, + governanceAbi.events.ProposalCanceled.topic, + governanceAbi.events.VoteCast.topic, + governanceAbi.events.VoteCastWithParams.topic, + ], + range: { from }, }) } export const process = async (ctx: Context) => { + if (ctx.blocks[ctx.blocks.length - 1]?.header.height < from) return + const result: IProcessResult = { addresses: new Map(), proposals: new Map(), @@ -49,12 +50,9 @@ export const process = async (ctx: Context) => { for (const block of ctx.blocks) { for (const log of block.logs) { - const firstTopic = log.topics[0] - - if (log.address !== GOVERNANCE_ADDRESS) { - return - } + if (log.address !== GOVERNANCE_ADDRESS) continue + const firstTopic = log.topics[0] if (firstTopic == governanceAbi.events.ProposalCreated.topic) { await _processProposalCreated(ctx, result, block, log) } else if (firstTopic == governanceAbi.events.ProposalExtended.topic) { @@ -90,6 +88,7 @@ const _processProposalCreated = async ( block: Block, log: Log, ) => { + // ctx.log.info('_processProposalCreated') const { proposalId, proposer: proposerAddr, @@ -136,17 +135,23 @@ const proposalStateMap = [ const eventMapper = { [governanceAbi.events.ProposalQueued.topic]: { - decode: governanceAbi.events.ProposalQueued.decode, + decode: governanceAbi.events.ProposalQueued.decode.bind( + governanceAbi.events.ProposalQueued, + ), status: OGVProposalState.Queued, event: OGVProposalEvent.Queued, }, [governanceAbi.events.ProposalCanceled.topic]: { - decode: governanceAbi.events.ProposalCanceled.decode, + decode: governanceAbi.events.ProposalCanceled.decode.bind( + governanceAbi.events.ProposalCanceled, + ), status: OGVProposalState.Canceled, event: OGVProposalEvent.Canceled, }, [governanceAbi.events.ProposalExecuted.topic]: { - decode: governanceAbi.events.ProposalExecuted.decode, + decode: governanceAbi.events.ProposalExecuted.decode.bind( + governanceAbi.events.ProposalExecuted, + ), status: OGVProposalState.Executed, event: OGVProposalEvent.Executed, }, @@ -158,6 +163,7 @@ const _processProposalEvents = async ( block: Block, log: Log, ) => { + // ctx.log.info('_processProposalEvents') const { decode, status, event } = eventMapper[log.topics[0]]! const { proposalId } = decode(log) @@ -183,6 +189,7 @@ const _processProposalExtended = async ( block: Block, log: Log, ) => { + // ctx.log.info('_processProposalExtended') const { proposalId, extendedDeadline } = governanceAbi.events.ProposalExtended.decode(log) const blockTimestamp = new Date(block.header.timestamp) @@ -208,11 +215,15 @@ const _processVoteCast = async ( block: Block, log: Log, ) => { - const decode = - log.topics[0] == governanceAbi.events.VoteCast.topic - ? governanceAbi.events.VoteCast.decode - : governanceAbi.events.VoteCastWithParams.decode - const { proposalId, voter: voterAddr, weight, support } = decode(log) + // ctx.log.info('_processVoteCast') + const { + proposalId, + voter: voterAddr, + weight, + support, + } = log.topics[0] == governanceAbi.events.VoteCast.topic + ? governanceAbi.events.VoteCast.decode(log) + : governanceAbi.events.VoteCastWithParams.decode(log) const blockTimestamp = new Date(block.header.timestamp) const proposal = await _getProposal(ctx, proposalId.toString(), result) diff --git a/src/ogv/processors/ogv.ts b/src/ogv/processors/ogv.ts index 65e528c3..fc4fab14 100644 --- a/src/ogv/processors/ogv.ts +++ b/src/ogv/processors/ogv.ts @@ -2,21 +2,22 @@ import { EvmBatchProcessor } from '@subsquid/evm-processor' import * as erc20Abi from '../../abi/erc20' import * as veogvAbi from '../../abi/veogv' -import { OGVAddress, OGVLockup, OGVLockupEventType, OGVLockupTxLog } from '../../model' -import { Block, Context, Log } from '../../processor' import { - ADDRESS_ZERO, - OGV_ADDRESS, - VEOGV_ADDRESS, -} from '../../utils/addresses' + OGVAddress, + OGVLockup, + OGVLockupEventType, + OGVLockupTxLog, +} from '../../model' +import { Block, Context, Log } from '../../processor' +import { ADDRESS_ZERO, OGV_ADDRESS, VEOGV_ADDRESS } from '../../utils/addresses' export const from = 14439231 // https://etherscan.io/tx/0x9295cac246169f06a3d4ec33fdbd87fced7a9e19ea61177cae75034e45ae66f4 export const veogvFrom = 15089597 // https://etherscan.io/tx/0x70c582e56ea1c49b7e9df70a0b40ddbfac9362b8b172cb527c329c2302d7d48a interface IProcessResult { - addresses: Map, - lockups: Map, - lockupEvents: OGVLockupTxLog[], + addresses: Map + lockups: Map + lockupEvents: OGVLockupTxLog[] } export const setup = (processor: EvmBatchProcessor) => { @@ -29,11 +30,11 @@ export const setup = (processor: EvmBatchProcessor) => { address: [VEOGV_ADDRESS], topic0: [ veogvAbi.events.Transfer, - veogvAbi.events.Stake, - veogvAbi.events.Unstake, - veogvAbi.events.DelegateChanged, - veogvAbi.events.DelegateVotesChanged - ].map(ev => ev.topic), + veogvAbi.events.Stake, + veogvAbi.events.Unstake, + veogvAbi.events.DelegateChanged, + veogvAbi.events.DelegateVotesChanged, + ].map((ev) => ev.topic), range: { from: veogvFrom }, }) } @@ -42,7 +43,7 @@ export const process = async (ctx: Context) => { const result: IProcessResult = { addresses: new Map(), lockups: new Map(), - lockupEvents: [] + lockupEvents: [], } for (const block of ctx.blocks) { @@ -50,7 +51,7 @@ export const process = async (ctx: Context) => { const firstTopic = log.topics[0] if (![VEOGV_ADDRESS, OGV_ADDRESS].includes(log.address.toLowerCase())) { - return + continue } if (firstTopic == veogvAbi.events.Transfer.topic) { @@ -66,10 +67,11 @@ export const process = async (ctx: Context) => { } } } - + await ctx.store.upsert( - Array.from(result.addresses.values()) - .sort((a, b) => a.delegatee?.id ? 1 : -1) + Array.from(result.addresses.values()).sort((a, b) => + a.delegatee?.id ? 1 : -1, + ), ) await ctx.store.upsert(Array.from(result.lockups.values())) await ctx.store.upsert(result.lockupEvents) @@ -79,7 +81,7 @@ const _processTransfer = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { const { addresses } = result let { from, to, value } = erc20Abi.events.Transfer.decode(log) @@ -95,9 +97,9 @@ const _processTransfer = async ( const sender = await _getAddress(ctx, from, result) // TODO: Check sender.balance >= value if (isVeOGV) { - sender.veogvBalance -= value; + sender.veogvBalance -= value } else { - sender.balance -= value; + sender.balance -= value } sender.lastUpdated = blockTimestamp addresses.set(from, sender) @@ -106,9 +108,9 @@ const _processTransfer = async ( if (to != ADDRESS_ZERO) { const receiver = await _getAddress(ctx, to, result) if (isVeOGV) { - receiver.veogvBalance += value; + receiver.veogvBalance += value } else { - receiver.balance += value; + receiver.balance += value } receiver.lastUpdated = blockTimestamp addresses.set(to, receiver) @@ -119,9 +121,8 @@ const _processDelegateChanged = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { - const { addresses } = result let { delegator, toDelegate } = veogvAbi.events.DelegateChanged.decode(log) delegator = delegator.toLowerCase() @@ -132,18 +133,19 @@ const _processDelegateChanged = async ( address.delegatee = await _getAddress(ctx, toDelegate, result) address.lastUpdated = new Date(block.header.timestamp) - addresses.set(toDelegate, address.delegatee); - addresses.set(delegator, address); + addresses.set(toDelegate, address.delegatee) + addresses.set(delegator, address) } const _processDelegateVotesChanged = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { const { addresses } = result - let { delegate, newBalance } = veogvAbi.events.DelegateVotesChanged.decode(log) + let { delegate, newBalance } = + veogvAbi.events.DelegateVotesChanged.decode(log) delegate = delegate.toLowerCase() const address = await _getAddress(ctx, delegate, result) @@ -151,18 +153,19 @@ const _processDelegateVotesChanged = async ( address.votingPower = newBalance address.lastUpdated = new Date(block.header.timestamp) - addresses.set(delegate, address); + addresses.set(delegate, address) } const _processStake = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { const { lockups } = result - const { lockupId, amount, user, points, end } = veogvAbi.events.Stake.decode(log) + const { lockupId, amount, user, points, end } = + veogvAbi.events.Stake.decode(log) const address = await _getAddress(ctx, user, result) const lockup = await _getLockup(ctx, lockupId.toString(), address, result) @@ -173,27 +176,30 @@ const _processStake = async ( lockups.set(lockup.id, lockup) // Find last Unstake txLog - const unstakeIndex = result.lockupEvents.findIndex(x => - x.event == OGVLockupEventType.Unstaked + const unstakeIndex = result.lockupEvents.findIndex( + (x) => + x.event == OGVLockupEventType.Unstaked && // Unstake is emitted just before Stake for Extend - && x.id == `${log.transactionHash}:${log.logIndex - 1}` + x.id == `${log.transactionHash}:${log.logIndex - 1}`, ) - + if (unstakeIndex >= 0) { // If it exists, it's an extend result.lockupEvents[unstakeIndex].event = OGVLockupEventType.Extended } else { // If not, it's just a new stake - result.lockupEvents.push(new OGVLockupTxLog({ - id: `${log.transactionHash}:${log.logIndex}`, - hash: log.transactionHash, - event: OGVLockupEventType.Staked, - timestamp: new Date(block.header.timestamp), - ogvLockup: lockup, - })) + result.lockupEvents.push( + new OGVLockupTxLog({ + id: `${log.transactionHash}:${log.logIndex}`, + hash: log.transactionHash, + event: OGVLockupEventType.Staked, + timestamp: new Date(block.header.timestamp), + ogvLockup: lockup, + }), + ) } - address.staked += amount; + address.staked += amount await _updateVotingPowers(ctx, result, block, address) } @@ -202,30 +208,32 @@ const _processUnstake = async ( ctx: Context, result: IProcessResult, block: Block, - log: Log + log: Log, ) => { const { lockupId, user, amount } = veogvAbi.events.Unstake.decode(log) const address = await _getAddress(ctx, user, result) const lockup = await _getLockup(ctx, lockupId.toString(), address, result) - result.lockupEvents.push(new OGVLockupTxLog({ - id: `${log.transactionHash}:${log.logIndex}`, - hash: log.transactionHash, - event: OGVLockupEventType.Unstaked, - timestamp: new Date(block.header.timestamp), - ogvLockup: lockup, - })) + result.lockupEvents.push( + new OGVLockupTxLog({ + id: `${log.transactionHash}:${log.logIndex}`, + hash: log.transactionHash, + event: OGVLockupEventType.Unstaked, + timestamp: new Date(block.header.timestamp), + ogvLockup: lockup, + }), + ) - address.staked -= amount; + address.staked -= amount await _updateVotingPowers(ctx, result, block, address) } -const _updateVotingPowers = async( +const _updateVotingPowers = async ( ctx: Context, result: IProcessResult, block: Block, - address: OGVAddress + address: OGVAddress, ) => { const { addresses } = result const veogv = new veogvAbi.Contract(ctx, block.header, VEOGV_ADDRESS) @@ -243,7 +251,11 @@ const _updateVotingPowers = async( } } -const _getAddress = async (ctx: Context, id: string, result: IProcessResult): Promise => { +const _getAddress = async ( + ctx: Context, + id: string, + result: IProcessResult, +): Promise => { id = id.toLowerCase() const { addresses } = result @@ -252,7 +264,7 @@ const _getAddress = async (ctx: Context, id: string, result: IProcessResult): Pr } let address = await ctx.store.findOneBy(OGVAddress, { - id + id, }) if (!address) { @@ -271,7 +283,12 @@ const _getAddress = async (ctx: Context, id: string, result: IProcessResult): Pr return address } -const _getLockup = async (ctx: Context, lockupId: string, address: OGVAddress, result: IProcessResult): Promise => { +const _getLockup = async ( + ctx: Context, + lockupId: string, + address: OGVAddress, + result: IProcessResult, +): Promise => { const id = `${address.id}:${lockupId}`.toLowerCase() const { lockups } = result @@ -280,14 +297,19 @@ const _getLockup = async (ctx: Context, lockupId: string, address: OGVAddress, r } let lockup = await ctx.store.findOneBy(OGVLockup, { - id + id, }) if (!lockup) { lockup = new OGVLockup({ id, address, - lockupId + lockupId, + amount: 0n, + veogv: 0n, + end: new Date(0), + logs: [], + timestamp: new Date(), }) } diff --git a/src/processor.ts b/src/processor.ts index 0eb9fc40..2589c18c 100644 --- a/src/processor.ts +++ b/src/processor.ts @@ -80,7 +80,7 @@ export const run = ({ }: { stateSchema?: string processors: Processor[] - postProcessors?: Pick[] + postProcessors?: Pick[] validators?: Pick[] }) => { const processor = createSquidProcessor() @@ -90,10 +90,14 @@ export const run = ({ ? Number(process.env.BLOCK_FROM) : Math.min( ...(processors.map((p) => p.from).filter((x) => x) as number[]), + ...((postProcessors ?? []) + .map((p) => p.from) + .filter((x) => x) as number[]), ), to: process.env.BLOCK_TO ? Number(process.env.BLOCK_TO) : undefined, }) processors.forEach((p) => p.setup?.(processor)) + postProcessors?.forEach((p) => p.setup?.(processor)) processor.run( new TypeormDatabase({ stateSchema,