Skip to content

Commit 2d728d1

Browse files
committed
fix: extract all event topics from event and the interfaces
1 parent 606e697 commit 2d728d1

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

packages/fasset-indexer-core/src/context/events.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,28 @@ export class EventInterface {
6565
const iface = this.contractToIface(contractname)
6666
for (const event of Object.values(EVENTS[cname])) {
6767
if (eventNames?.includes(event) !== false) {
68-
const topic = this.getEventTopic(event, iface)
69-
mp.set(topic, cname)
68+
const topics = this.getEventTopics(event, iface)
69+
for (const topic of topics) {
70+
mp.set(topic, cname)
71+
}
7072
}
7173
}
7274
}
7375
return mp
7476
}
7577

76-
getEventTopic(eventName: string, ifaces: Interface[]): string {
78+
getEventTopics(eventName: string, ifaces: Interface[]): string[] {
79+
const topics = new Set<string>()
7780
for (const iface of ifaces) {
7881
const parsed = iface.getEvent(eventName)
7982
if (parsed != null) {
80-
return parsed.topicHash
83+
topics.add(parsed.topicHash)
8184
}
8285
}
83-
throw new Error(`Event ${eventName} not found in interface`)
86+
if (topics.size == 0) {
87+
new Error(`Event ${eventName} not found in interface`)
88+
}
89+
return Array.from(topics)
8490
}
8591

8692
contractToIface(name: string): Interface[] {

packages/fasset-indexer-core/src/indexer/eventlib/event-storer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export class EventStorer {
2222

2323
constructor(readonly orm: ORM, public readonly lookup: ContractLookup) {
2424
const oldIface = this.lookup.interfaces.assetManagerInterface[0]
25-
this.oldCollateralTypeAddedTopic = this.lookup.getEventTopic(EVENTS.ASSET_MANAGER.COLLATERAL_TYPE_ADDED, [oldIface])
26-
this.oldAgentVaultCreatedTopic = this.lookup.getEventTopic(EVENTS.ASSET_MANAGER.AGENT_VAULT_CREATED, [oldIface])
25+
this.oldCollateralTypeAddedTopic = this.lookup.getEventTopics(EVENTS.ASSET_MANAGER.COLLATERAL_TYPE_ADDED, [oldIface])[0]
26+
this.oldAgentVaultCreatedTopic = this.lookup.getEventTopics(EVENTS.ASSET_MANAGER.AGENT_VAULT_CREATED, [oldIface])[0]
2727
}
2828

2929
async processEvent(log: Event): Promise<void> {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ export class EventIndexer {
6363

6464
protected async storeLogs(logs: Log[]): Promise<void> {
6565
for (const log of logs) {
66+
if (log.index > 0) break
67+
console.log(log)
6668
const fullLog = await this.eventParser.logToEvent(log)
67-
if (fullLog !== null) {
69+
if (fullLog != null) {
6870
logger.info(`event indexer is processing event ${fullLog.name} (block: ${fullLog.blockNumber}, index: ${fullLog.logIndex})`)
6971
await this.stateUpdater.processEvent(fullLog)
7072
}

packages/fasset-indexer-core/src/scripts/find-event-changed-topics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ async function am(context: Context) {
1111
for (const iface of Object.keys(EVENTS)) {
1212
if (iface != 'ASSET_MANAGER') continue
1313
for (const event of Object.values(EVENTS[iface as keyof typeof EVENTS])) {
14-
const resp1 = context.getEventTopic(event, [iface1])
15-
const resp2 = context.getEventTopic(event, [iface2])
14+
const resp1 = context.getEventTopics(event, [iface1])[0]
15+
const resp2 = context.getEventTopics(event, [iface2])[0]
1616
if (resp1 != resp2) console.log(event)
1717
}
1818
}

0 commit comments

Comments
 (0)