@@ -22,12 +22,11 @@ import {
22
22
Transfer ,
23
23
} from '../../generated/templates/VToken/VToken' ;
24
24
import { nullAddress } from '../constants/addresses' ;
25
- import { vTokenDecimals } from '../constants' ;
26
25
import { createAccount } from '../operations/create' ;
27
26
import { createMarket } from '../operations/create' ;
28
27
import { updateCommonVTokenStats } from '../operations/update' ;
29
28
import { updateMarket } from '../operations/update' ;
30
- import { exponentToBigDecimal , vTokenDecimalsBD } from '../utilities/exponentToBigDecimal' ;
29
+ import { exponentToBigDecimal } from '../utilities/exponentToBigDecimal' ;
31
30
32
31
/* Account supplies assets into market and receives vTokens in exchange
33
32
*
@@ -52,9 +51,11 @@ export const handleMint = (event: Mint): void => {
52
51
. concat ( '-' )
53
52
. concat ( event . transactionLogIndex . toString ( ) ) ;
54
53
54
+ const vTokenDecimals = market . vTokenDecimals ;
55
+
55
56
let vTokenAmount = event . params . mintTokens
56
57
. toBigDecimal ( )
57
- . div ( vTokenDecimalsBD )
58
+ . div ( exponentToBigDecimal ( vTokenDecimals ) )
58
59
. truncate ( vTokenDecimals ) ;
59
60
let underlyingAmount = event . params . mintAmount
60
61
. toBigDecimal ( )
@@ -89,14 +90,15 @@ export const handleRedeem = (event: Redeem): void => {
89
90
if ( ! market ) {
90
91
market = createMarket ( event . address . toHexString ( ) ) ;
91
92
}
93
+ let vTokenDecimals = market . vTokenDecimals ;
92
94
let redeemID = event . transaction . hash
93
95
. toHexString ( )
94
96
. concat ( '-' )
95
97
. concat ( event . transactionLogIndex . toString ( ) ) ;
96
98
97
99
let vTokenAmount = event . params . redeemTokens
98
100
. toBigDecimal ( )
99
- . div ( vTokenDecimalsBD )
101
+ . div ( exponentToBigDecimal ( vTokenDecimals ) )
100
102
. truncate ( vTokenDecimals ) ;
101
103
let underlyingAmount = event . params . redeemAmount
102
104
. toBigDecimal ( )
@@ -157,7 +159,7 @@ export const handleBorrow = (event: Borrow): void => {
157
159
. div ( exponentToBigDecimal ( market . underlyingDecimals ) )
158
160
. truncate ( market . underlyingDecimals ) ;
159
161
160
- vTokenStats . accountBorrowIndex = market . borrowIndex ;
162
+ vTokenStats . accountBorrowIndexMantissa = market . borrowIndexMantissa ;
161
163
vTokenStats . totalUnderlyingBorrowed = vTokenStats . totalUnderlyingBorrowed . plus ( borrowAmountBD ) ;
162
164
vTokenStats . save ( ) ;
163
165
@@ -232,7 +234,7 @@ export const handleRepayBorrow = (event: RepayBorrow): void => {
232
234
. div ( exponentToBigDecimal ( market . underlyingDecimals ) )
233
235
. truncate ( market . underlyingDecimals ) ;
234
236
235
- vTokenStats . accountBorrowIndex = market . borrowIndex ;
237
+ vTokenStats . accountBorrowIndexMantissa = market . borrowIndexMantissa ;
236
238
vTokenStats . totalUnderlyingRepaid = vTokenStats . totalUnderlyingRepaid . plus ( repayAmountBD ) ;
237
239
vTokenStats . save ( ) ;
238
240
@@ -311,10 +313,10 @@ export const handleLiquidateBorrow = (event: LiquidateBorrow): void => {
311
313
. toHexString ( )
312
314
. concat ( '-' )
313
315
. concat ( event . transactionLogIndex . toString ( ) ) ;
314
-
316
+ let vTokenDecimals = marketRepayToken . vTokenDecimals ;
315
317
let vTokenAmount = event . params . seizeTokens
316
318
. toBigDecimal ( )
317
- . div ( vTokenDecimalsBD )
319
+ . div ( exponentToBigDecimal ( vTokenDecimals ) )
318
320
. truncate ( vTokenDecimals ) ;
319
321
let underlyingRepayAmount = event . params . repayAmount
320
322
. toBigDecimal ( )
@@ -359,11 +361,14 @@ export const handleTransfer = (event: Transfer): void => {
359
361
if ( market . accrualBlockNumber != event . block . number . toI32 ( ) ) {
360
362
market = updateMarket ( event . address , event . block . number . toI32 ( ) , event . block . timestamp . toI32 ( ) ) ;
361
363
}
362
-
363
- let amountUnderlying = market . exchangeRate . times (
364
- event . params . amount . toBigDecimal ( ) . div ( vTokenDecimalsBD ) ,
364
+ let vTokenDecimals = market . vTokenDecimals ;
365
+ let amountUnderlying = market . exchangeRateMantissa . times (
366
+ event . params . amount ,
365
367
) ;
366
- let amountUnderylingTruncated = amountUnderlying . truncate ( market . underlyingDecimals ) ;
368
+ // const exchangeRateBigDecimal = getExchangeRateBigDecimal(exchangeRate, underlyingDecimals);
369
+ // const amountUnderlyingMantissa = exchangeRateBigDecimal
370
+ // .times(exponentToBigDecimal(underlyingDecimals))
371
+ // .times(amount.toBigDecimal());
367
372
368
373
// Checking if the tx is FROM the vToken contract (i.e. this will not run when minting)
369
374
// If so, it is a mint, and we don't need to run these calculations
@@ -387,11 +392,11 @@ export const handleTransfer = (event: Transfer): void => {
387
392
) ;
388
393
389
394
vTokenStatsFrom . vTokenBalance = vTokenStatsFrom . vTokenBalance . minus (
390
- event . params . amount . toBigDecimal ( ) . div ( vTokenDecimalsBD ) . truncate ( vTokenDecimals ) ,
395
+ event . params . amount . toBigDecimal ( ) . div ( exponentToBigDecimal ( vTokenDecimals ) ) . truncate ( vTokenDecimals ) ,
391
396
) ;
392
397
393
- vTokenStatsFrom . totalUnderlyingRedeemed =
394
- vTokenStatsFrom . totalUnderlyingRedeemed . plus ( amountUnderylingTruncated ) ;
398
+ vTokenStatsFrom . totalUnderlyingRedeemedMantissa =
399
+ vTokenStatsFrom . totalUnderlyingRedeemedMantissa . plus ( amountUnderlying ) ;
395
400
vTokenStatsFrom . save ( ) ;
396
401
}
397
402
@@ -419,11 +424,11 @@ export const handleTransfer = (event: Transfer): void => {
419
424
) ;
420
425
421
426
vTokenStatsTo . vTokenBalance = vTokenStatsTo . vTokenBalance . plus (
422
- event . params . amount . toBigDecimal ( ) . div ( vTokenDecimalsBD ) . truncate ( vTokenDecimals ) ,
427
+ event . params . amount . toBigDecimal ( ) . div ( exponentToBigDecimal ( vTokenDecimals ) ) . truncate ( vTokenDecimals ) ,
423
428
) ;
424
429
425
- vTokenStatsTo . totalUnderlyingSupplied =
426
- vTokenStatsTo . totalUnderlyingSupplied . plus ( amountUnderylingTruncated ) ;
430
+ vTokenStatsTo . totalUnderlyingSuppliedMantissa =
431
+ vTokenStatsTo . totalUnderlyingSuppliedMantissa . plus ( amountUnderlying ) ;
427
432
vTokenStatsTo . save ( ) ;
428
433
}
429
434
@@ -433,7 +438,7 @@ export const handleTransfer = (event: Transfer): void => {
433
438
. concat ( event . transactionLogIndex . toString ( ) ) ;
434
439
435
440
let transfer = new TransferEvent ( transferID ) ;
436
- transfer . amount = event . params . amount . toBigDecimal ( ) . div ( vTokenDecimalsBD ) ;
441
+ transfer . amount = event . params . amount . toBigDecimal ( ) . div ( exponentToBigDecimal ( vTokenDecimals ) ) ;
437
442
transfer . to = event . params . to ;
438
443
transfer . from = event . params . from ;
439
444
transfer . blockNumber = event . block . number . toI32 ( ) ;
0 commit comments