@@ -14,23 +14,23 @@ export function handleProductTransfer(event: TransferEvent): void {
14
14
return
15
15
}
16
16
17
- if ( shouldIgnoreContract ( event . params . from ) || shouldIgnoreContract ( event . params . to ) ) {
18
- log . debug ( "Ignoring transfer from/to ignored contract: {}" , [ event . transaction . hash . toHexString ( ) ] )
19
- return
20
- }
21
-
22
17
const tokenAddress = event . address
23
18
fetchAndSaveTokenData ( tokenAddress )
24
-
25
19
const statistic = getTokenStatistic ( tokenAddress )
26
20
27
21
if ( event . params . from . notEqual ( SHARE_TOKEN_MINT_ADDRESS ) && event . params . from . notEqual ( BURN_ADDRESS ) ) {
28
- const balDiff = updateAccountBalance ( tokenAddress , event . params . from , event . params . value . neg ( ) )
22
+ const holder = event . params . from
23
+ const rawAmountDiff = event . params . value . neg ( )
24
+ const amountDiff = shouldIgnoreContract ( holder ) ? ZERO_BI : event . params . value . neg ( )
25
+ const balDiff = updateAccountBalance ( tokenAddress , holder , amountDiff , rawAmountDiff )
29
26
statistic . holderCount = statistic . holderCount . plus ( balDiff . holderCountChange ( ) )
30
27
}
31
28
32
29
if ( event . params . to . notEqual ( SHARE_TOKEN_MINT_ADDRESS ) && event . params . to . notEqual ( BURN_ADDRESS ) ) {
33
- const balDiff = updateAccountBalance ( tokenAddress , event . params . to , event . params . value )
30
+ const receiver = event . params . to
31
+ const rawAmountDiff = event . params . value
32
+ const amountDiff = shouldIgnoreContract ( receiver ) ? ZERO_BI : event . params . value
33
+ const balDiff = updateAccountBalance ( tokenAddress , receiver , amountDiff , rawAmountDiff )
34
34
statistic . holderCount = statistic . holderCount . plus ( balDiff . holderCountChange ( ) )
35
35
}
36
36
@@ -44,22 +44,30 @@ export function handleProductTransfer(event: TransferEvent): void {
44
44
statistic . save ( )
45
45
}
46
46
47
- function updateAccountBalance ( tokenAddress : Bytes , accountAddress : Bytes , amountDiff : BigInt ) : BalanceDiff {
47
+ function updateAccountBalance ( tokenAddress : Bytes , accountAddress : Bytes , amountDiff : BigInt , rawAmountDiff : BigInt ) : BalanceDiff {
48
48
const account = createAccount ( accountAddress )
49
49
const token = getToken ( tokenAddress )
50
50
const balance = getTokenBalance ( token , account )
51
+
51
52
const before = balance . amount
52
53
const after = balance . amount . plus ( amountDiff )
53
54
balance . amount = after
55
+
56
+ const rawBefore = balance . rawAmount
57
+ const rawAfter = balance . rawAmount . plus ( rawAmountDiff )
58
+ balance . rawAmount = rawAfter
59
+
54
60
balance . save ( )
55
61
56
- return new BalanceDiff ( before , balance . amount )
62
+ return new BalanceDiff ( before , after , rawBefore , rawAfter )
57
63
}
58
64
59
65
class BalanceDiff {
60
66
constructor (
61
67
public before : BigInt ,
62
68
public after : BigInt ,
69
+ public rawBefore : BigInt ,
70
+ public rawAfter : BigInt ,
63
71
) { }
64
72
65
73
public holderCountChange ( ) : BigInt {
0 commit comments