Skip to content

Commit

Permalink
Populating the VolumeByBlock entities
Browse files Browse the repository at this point in the history
	modified:   src/main.ts
  • Loading branch information
abernatskiy committed Aug 29, 2023
1 parent cf741cd commit 6da95b8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {TypeormDatabase} from '@subsquid/typeorm-store'
import {Trade} from './model'
import {Trade, VolumeByBlock} from './model'
import {processor, FRIENDTECH_CONTRACT} from './processor'
import * as friendTechAbi from './abi/friendTechAbi'

processor.run(new TypeormDatabase({supportHotBlocks: true}), async (ctx) => {
const trades: Trade[] = []
const volumes: VolumeByBlock[] = []

for (let block of ctx.blocks) {
let totalEthAmount = 0n

for (let log of block.logs) {
if (log.address === FRIENDTECH_CONTRACT &&
log.topics[0] === friendTechAbi.events.Trade.topic) {
Expand All @@ -21,6 +24,7 @@ processor.run(new TypeormDatabase({supportHotBlocks: true}), async (ctx) => {
subjectEthAmount,
supply,
} = friendTechAbi.events.Trade.decode(log)

trades.push(new Trade({
id: log.id,
block: block.header.height,
Expand All @@ -34,9 +38,18 @@ processor.run(new TypeormDatabase({supportHotBlocks: true}), async (ctx) => {
supply,
txnHash: log.transactionHash,
}))

totalEthAmount += ethAmount
}
}

volumes.push(new VolumeByBlock({
id: `${block.header.height}`,
block: block.header.height,
totalEthAmount
}))
}

await ctx.store.upsert(trades)
await ctx.store.upsert(volumes)
})

0 comments on commit 6da95b8

Please sign in to comment.