-
Notifications
You must be signed in to change notification settings - Fork 781
/
Copy pathfactory.ts
27 lines (24 loc) · 1.23 KB
/
factory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { ByteArray, Bytes } from '@graphprotocol/graph-ts'
import { PairCreated as PairCreatedEvent } from '../../../generated/Factory/Factory'
import { PairCreated as PairCreatedEntity } from '../../../generated/schema'
import { Pair as PairTemplate } from '../../../generated/templates'
export function handleNewPair(event: PairCreatedEvent): void {
const transactionHash = event.transaction.hash
const logIndex = event.logIndex
const logIndexBytes = Bytes.fromByteArray(ByteArray.fromBigInt(logIndex))
const pairCreatedId = transactionHash.concat(logIndexBytes)
const pairCreatedEvent = new PairCreatedEntity(pairCreatedId)
pairCreatedEvent.transactionHash = transactionHash
pairCreatedEvent.transactionFrom = event.transaction.from
pairCreatedEvent.transactionTo = event.transaction.to
pairCreatedEvent.logAddress = event.address
pairCreatedEvent.blockNumber = event.block.number
pairCreatedEvent.logIndex = logIndex
pairCreatedEvent.timestamp = event.block.timestamp
pairCreatedEvent.token0 = event.params.token0
pairCreatedEvent.token1 = event.params.token1
pairCreatedEvent.pair = event.params.pair
pairCreatedEvent.pairIndex = event.params.param3
pairCreatedEvent.save()
PairTemplate.create(event.params.pair)
}