Skip to content

Commit 7df19ac

Browse files
committed
chore: include collateral pool migration into the indexer run
1 parent bf1c6a9 commit 7df19ac

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/fasset-indexer-core/src/run/run-indexer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ConfigLoader } from "../config/config"
55
import { Context } from "../context/context"
66
import { logger } from "../logger"
77
import { IndexerRunner } from "../indexer/runner"
8+
import { migrateCollateralPoolEvents } from "../scripts/migrate-collateral-pool-events"
89

910

1011
async function runIndexer(start?: number) {
@@ -22,8 +23,12 @@ async function runIndexer(start?: number) {
2223
logger.info("ensuring configuration integrity...")
2324
await ensureConfigIntegrity(context)
2425
await ensureData(context)
26+
2527
logger.info(`starting FAsset ${context.chain} indexer...`)
26-
await runner.run(start)
28+
await Promise.all([
29+
migrateCollateralPoolEvents(context.orm.em.fork()),
30+
runner.run(start)
31+
])
2732
}
2833

2934
runIndexer()

packages/fasset-indexer-core/src/scripts/migrate-collateral-pool-events.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { EventStorerCpMigration } from "../indexer/eventlib/event-storer-cp-migration"
2-
import { getVar, setVar } from "../orm"
32
import { CollateralPoolEntered, CollateralPoolExited } from "../orm/entities"
43
import { CollateralPoolClaimedReward, CollateralPoolPaidOut } from "../orm/entities/events/collateral-pool"
4+
import { logger } from "../logger"
55
import type { EntityManager } from "@mikro-orm/knex"
66

77

8-
const CP_MIGRATED_VAR = 'cp_migrated'
9-
10-
export async function migrateCollateralPoolEnterEvents(em: EntityManager) {
8+
async function migrateCollateralPoolEnterEvents(em: EntityManager) {
119
const enteredEvents = await em.findAll(CollateralPoolEntered)
1210
for (const entered of enteredEvents) {
1311
await em.transactional(em => {
@@ -18,7 +16,7 @@ export async function migrateCollateralPoolEnterEvents(em: EntityManager) {
1816
}
1917
}
2018

21-
export async function migrateCollateralPoolExitEvents(em: EntityManager) {
19+
async function migrateCollateralPoolExitEvents(em: EntityManager) {
2220
const exitedEvents = await em.findAll(CollateralPoolExited)
2321
for (const exited of exitedEvents) {
2422
await em.transactional(em => {
@@ -29,7 +27,7 @@ export async function migrateCollateralPoolExitEvents(em: EntityManager) {
2927
}
3028
}
3129

32-
export async function migrateCollateralPoolPaidOut(em: EntityManager) {
30+
async function migrateCollateralPoolPaidOut(em: EntityManager) {
3331
const paidOutEvents = await em.findAll(CollateralPoolPaidOut)
3432
for (const paidOut of paidOutEvents) {
3533
await em.transactional(em => {
@@ -40,7 +38,7 @@ export async function migrateCollateralPoolPaidOut(em: EntityManager) {
4038
}
4139
}
4240

43-
export async function migrateCollateralPoolClaimedReward(em: EntityManager) {
41+
async function migrateCollateralPoolClaimedReward(em: EntityManager) {
4442
const claimedRewardEvents = await em.findAll(CollateralPoolClaimedReward)
4543
for (const claimed of claimedRewardEvents) {
4644
await em.transactional(em => {
@@ -52,13 +50,12 @@ export async function migrateCollateralPoolClaimedReward(em: EntityManager) {
5250
}
5351

5452
export async function migrateCollateralPoolEvents(em: EntityManager) {
55-
/* const v = await getVar(context.orm.em.fork(), CP_MIGRATED_VAR)
56-
if (v != null && v.value == 'true') {
57-
return
58-
} */
5953
await migrateCollateralPoolEnterEvents(em)
54+
logger.info('migrated collateral pool enter events')
6055
await migrateCollateralPoolExitEvents(em)
56+
logger.info('migrated collateral pool exit events')
6157
await migrateCollateralPoolPaidOut(em)
58+
logger.info('migrated collateral pool paid out events')
6259
await migrateCollateralPoolClaimedReward(em)
63-
//await setVar(context.orm.em.fork(), CP_MIGRATED_VAR, 'true')
60+
logger.info('migrated collateral pool claimed reward events')
6461
}

0 commit comments

Comments
 (0)