Skip to content

Commit f1cdac8

Browse files
committed
chore: added GraphTallyTokensCollected
1 parent 1f26e2f commit f1cdac8

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

schema.graphql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,22 @@ type PaymentsEscrowTransaction @entity(immutable: false) {
18541854
timestamp: BigInt!
18551855
}
18561856

1857+
"""
1858+
The tokens collected by the GraphTallyCollector
1859+
"""
1860+
type GraphTallyTokensCollected @entity(immutable: false) {
1861+
"The payer, receiver and collection id concatenated"
1862+
id: Bytes!
1863+
"The payer address of the account"
1864+
payer: Payer!
1865+
"The receiver address of the account"
1866+
receiver: Receiver!
1867+
"The collection id"
1868+
collectionId: Bytes!
1869+
"The tokens already collected"
1870+
tokens: BigInt!
1871+
}
1872+
18571873
"""
18581874
The signer of a PaymentsEscrow account
18591875
"""

src/mappings/graphTallyCollector.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Address, BigInt, Bytes } from '@graphprotocol/graph-ts'
2-
import { PaymentsEscrowTransaction, Signer } from '../types/schema'
2+
import { PaymentsEscrowTransaction, Signer, GraphTallyTokensCollected } from '../types/schema'
33
import {
44
SignerAuthorized,
55
SignerThawing,
@@ -53,6 +53,8 @@ export function handlePaymentCollected(event: PaymentCollected): void {
5353
let receiver = createOrLoadReceiver(event.params.receiver)
5454
let collector = Bytes.fromHexString(addresses.graphTallyCollector) as Bytes
5555
let escrow = createOrLoadEscrowAccount(event.params.payer, collector, event.params.receiver)
56+
let tokensCollected = createOrLoadGraphTallyTokensCollected(event.params.payer, event.params.receiver, event.params.collectionId)
57+
tokensCollected.tokens = tokensCollected.tokens.plus(event.params.tokens)
5658

5759
transaction.type = 'redeem'
5860
transaction.payer = payer.id
@@ -66,6 +68,7 @@ export function handlePaymentCollected(event: PaymentCollected): void {
6668

6769
transaction.save()
6870
escrow.save()
71+
tokensCollected.save()
6972
}
7073

7174
export function createOrLoadSigner(address: Address): Signer {
@@ -78,4 +81,18 @@ export function createOrLoadSigner(address: Address): Signer {
7881
signer.save()
7982
}
8083
return signer
84+
}
85+
86+
export function createOrLoadGraphTallyTokensCollected(payer: Address, receiver: Address, collectionId: Bytes): GraphTallyTokensCollected {
87+
let id = payer.concat(receiver).concat(collectionId)
88+
let tokensCollected = GraphTallyTokensCollected.load(id)
89+
if(tokensCollected == null) {
90+
tokensCollected = new GraphTallyTokensCollected(id)
91+
tokensCollected.payer = payer
92+
tokensCollected.receiver = receiver
93+
tokensCollected.collectionId = collectionId
94+
tokensCollected.tokens = BIGINT_ZERO
95+
tokensCollected.save()
96+
}
97+
return tokensCollected
8198
}

0 commit comments

Comments
 (0)