diff --git a/src/helpers/stateSnapshot.ts b/src/helpers/stateSnapshot.ts index 6bdf440..c84732a 100644 --- a/src/helpers/stateSnapshot.ts +++ b/src/helpers/stateSnapshot.ts @@ -13,6 +13,7 @@ import { SubstrateBlock } from '@subql/types' * blockNumber fields) * @param block - the correspondint substrateBlock to provide additional state values to the snapshot * @param fkReferenceName - (optional) name of the foreignKey to save a reference to the originating entity. + * @param resetPeriodStates - (optional) reset properties ending in ByPeriod to 0 after snapshot (defaults to true). * @returns A promise resolving when all state manipulations in the DB is completed */ async function stateSnapshotter( @@ -24,6 +25,7 @@ async function stateSnapshotter { const entitySaves: Promise[] = [] @@ -47,11 +49,13 @@ async function stateSnapshotter propName.endsWith('ByPeriod')) as ResettableKey[] - for (const propName of propNamesToReset) { - logger.debug(`resetting ${stateEntity._name.toLowerCase()}.${propName} to 0`) - stateEntity[propName] = BigInt(0) + if (resetPeriodStates) { + for (const propName of propNamesToReset) { + logger.debug(`resetting ${stateEntity._name.toLowerCase()}.${propName} to 0`) + stateEntity[propName] = BigInt(0) + } + entitySaves.push(stateEntity.save()) } - entitySaves.push(stateEntity.save()) entitySaves.push(snapshotEntity.save()) } return Promise.all(entitySaves) @@ -64,7 +68,8 @@ export function evmStateSnapshotter { const formattedBlock = { number: block.number, timestamp: new Date(Number(block.timestamp) * 1000) } return stateSnapshotter( @@ -76,6 +81,7 @@ export function evmStateSnapshotter { const formattedBlock = { number: block.block.header.number.toNumber(), timestamp: block.timestamp } return stateSnapshotter( @@ -100,6 +107,7 @@ export function substrateStateSnapshotter & Required>) { logger.info(`Paying PoolFee ${data.feeId} with amount ${data.amount.toString(10)}`) - if (!this.isActive) throw new Error('Unable to payinactive PolFee') + if (!this.isActive) throw new Error('Unable to pay inactive PolFee') this.sumPaidAmount += data.amount this.sumPaidAmountByPeriod += data.amount this.pendingAmount -= data.amount @@ -109,7 +109,7 @@ export class PoolFeeService extends PoolFee { this.pendingAmount = pending + disbursement const newAccruedAmount = this.pendingAmount - this.sumAccruedAmountByPeriod = newAccruedAmount - this.sumAccruedAmount + this.sumAccruedAmountByPeriod = newAccruedAmount - this.sumAccruedAmount + this.sumPaidAmountByPeriod this.sumAccruedAmount = newAccruedAmount return this }