@@ -36,7 +36,7 @@ export function handleJoin(event: LOG_JOIN): void {
36
36
pool . joinCount = pool . joinCount . plus ( integer . ONE )
37
37
38
38
// get token, update pool transaction, poolSnapshot
39
- const poolSnapshot = getPoolSnapshot ( pool . id , event . block . timestamp . toI32 ( ) )
39
+
40
40
const token = getToken ( event . params . tokenIn , false )
41
41
const ammount = weiToDecimal (
42
42
event . params . tokenAmountIn . toBigDecimal ( ) ,
@@ -45,24 +45,36 @@ export function handleJoin(event: LOG_JOIN): void {
45
45
if ( token . isDatatoken ) {
46
46
poolTx . datatoken = token . id
47
47
poolTx . datatokenValue = ammount
48
-
49
- poolSnapshot . datatokenLiquidity =
50
- poolSnapshot . datatokenLiquidity . plus ( ammount )
48
+ if ( pool . isFinalized ) {
49
+ const poolSnapshot = getPoolSnapshot (
50
+ pool . id ,
51
+ event . block . timestamp . toI32 ( )
52
+ )
53
+ poolSnapshot . datatokenLiquidity =
54
+ poolSnapshot . datatokenLiquidity . plus ( ammount )
55
+
56
+ poolSnapshot . save ( )
57
+ }
51
58
52
59
pool . datatokenLiquidity = pool . datatokenLiquidity . plus ( ammount )
53
60
} else {
54
61
poolTx . baseToken = token . id
55
62
poolTx . baseTokenValue = ammount
56
63
57
- poolSnapshot . baseTokenLiquidity =
58
- poolSnapshot . baseTokenLiquidity . plus ( ammount )
59
-
64
+ if ( pool . isFinalized ) {
65
+ const poolSnapshot = getPoolSnapshot (
66
+ pool . id ,
67
+ event . block . timestamp . toI32 ( )
68
+ )
69
+ poolSnapshot . baseTokenLiquidity =
70
+ poolSnapshot . baseTokenLiquidity . plus ( ammount )
71
+ poolSnapshot . save ( )
72
+ }
60
73
pool . baseTokenLiquidity = pool . baseTokenLiquidity . plus ( ammount )
61
74
62
75
addLiquidity ( token . id , ammount )
63
76
}
64
77
65
- poolSnapshot . save ( )
66
78
poolTx . save ( )
67
79
pool . save ( )
68
80
}
@@ -225,15 +237,19 @@ export function handleSetup(event: LOG_SETUP): void {
225
237
poolTx . type = PoolTransactionType . SETUP
226
238
poolTx . baseToken = token . id
227
239
poolTx . datatoken = datatoken . id
240
+ pool . save ( )
241
+ poolTx . save ( )
242
+
228
243
const poolSnapshot = getPoolSnapshot ( pool . id , event . block . timestamp . toI32 ( ) )
229
244
poolSnapshot . spotPrice = spotPrice
245
+ poolSnapshot . baseTokenLiquidity = pool . baseTokenLiquidity
246
+ poolSnapshot . datatokenLiquidity = pool . datatokenLiquidity
247
+ poolSnapshot . totalShares = pool . totalShares
230
248
231
- poolTx . save ( )
232
249
poolSnapshot . save ( )
233
250
const globalStats = getGlobalStats ( )
234
251
globalStats . poolCount = globalStats . poolCount + 1
235
252
globalStats . save ( )
236
- pool . save ( )
237
253
datatoken . save ( )
238
254
}
239
255
@@ -243,10 +259,6 @@ export function handlerBptTransfer(event: Transfer): void {
243
259
const poolAddress = event . address . toHex ( )
244
260
const caller = getUser ( event . transaction . from . toHex ( ) )
245
261
const poolTx = getPoolTransaction ( event , caller . id , PoolTransactionType . SWAP )
246
- const poolSnapshot = getPoolSnapshot (
247
- poolAddress ,
248
- event . block . timestamp . toI32 ( )
249
- )
250
262
251
263
// btoken has 18 decimals
252
264
const ammount = weiToDecimal ( event . params . amt . toBigDecimal ( ) , 18 )
@@ -261,7 +273,15 @@ export function handlerBptTransfer(event: Transfer): void {
261
273
pool . totalShares = pool . totalShares . plus ( ammount )
262
274
263
275
// check tx?
264
- poolSnapshot . totalShares = pool . totalShares
276
+ if ( pool . isFinalized ) {
277
+ const poolSnapshot = getPoolSnapshot (
278
+ poolAddress ,
279
+ event . block . timestamp . toI32 ( )
280
+ )
281
+ poolSnapshot . totalShares = pool . totalShares
282
+ poolSnapshot . save ( )
283
+ }
284
+
265
285
pool . save ( )
266
286
} else {
267
287
if ( poolAddress != fromAddress ) {
@@ -275,7 +295,14 @@ export function handlerBptTransfer(event: Transfer): void {
275
295
// remove
276
296
const pool = getPool ( poolAddress )
277
297
pool . totalShares = pool . totalShares . minus ( ammount )
278
- poolSnapshot . totalShares = pool . totalShares
298
+ if ( pool . isFinalized ) {
299
+ const poolSnapshot = getPoolSnapshot (
300
+ poolAddress ,
301
+ event . block . timestamp . toI32 ( )
302
+ )
303
+ poolSnapshot . totalShares = pool . totalShares
304
+ poolSnapshot . save ( )
305
+ }
279
306
pool . save ( )
280
307
} else {
281
308
if ( poolAddress != toAddress ) {
@@ -286,7 +313,6 @@ export function handlerBptTransfer(event: Transfer): void {
286
313
}
287
314
288
315
poolTx . save ( )
289
- poolSnapshot . save ( )
290
316
}
291
317
292
318
export function handlePublishMarketFeeChanged (
0 commit comments