import { BigDecimal , Bytes } from '@graphprotocol/graph-ts/index' ; import { AccountCToken , Account } from '../types/schema' ; export function exponentToBigDecimal ( decimals ) { let bd = BigDecimal . fromString ( '1' ) ; for ( let i = 0 ; i < decimals ; i ++ ) { bd = bd . times ( BigDecimal . fromString ( '10' ) ) ; } return bd ; } export let mantissaFactor = 18 ; export let cTokenDecimals = 8 ; export let mantissaFactorBD = exponentToBigDecimal ( 18 ) ; export let cTokenDecimalsBD = exponentToBigDecimal ( 8 ) ; export let zeroBD = BigDecimal . fromString ( '0' ) ; export function createAccountCToken ( cTokenStatsID , symbol , account , marketID ) { let cTokenStats = new AccountCToken ( cTokenStatsID ) ; cTokenStats . symbol = symbol ; cTokenStats . market = marketID ; cTokenStats . account = account ; cTokenStats . transactionHashes = [ ] ; cTokenStats . transactionTimes = [ ] ; cTokenStats . accrualBlockNumber = 0 ; cTokenStats . cTokenBalance = zeroBD ; cTokenStats . totalUnderlyingSupplied = zeroBD ; cTokenStats . totalUnderlyingRedeemed = zeroBD ; cTokenStats . accountBorrowIndex = zeroBD ; cTokenStats . totalUnderlyingBorrowed = zeroBD ; cTokenStats . totalUnderlyingRepaid = zeroBD ; cTokenStats . storedBorrowBalance = zeroBD ; cTokenStats . enteredMarket = false ; return cTokenStats ; } export function createAccount ( accountID ) { let account = new Account ( accountID ) ; account . countLiquidated = 0 ; account . countLiquidator = 0 ; account . hasBorrowed = false ; account . save ( ) ; return account ; } export function updateCommonCTokenStats ( marketID , marketSymbol , accountID , txHash , timestamp , blockNumber ) { let cTokenStatsID = marketID . concat ( '-' ) . concat ( accountID ) ; let cTokenStats = AccountCToken . load ( cTokenStatsID ) ; if ( cTokenStats == null ) { cTokenStats = createAccountCToken ( cTokenStatsID , marketSymbol , accountID , marketID ) ; } let txHashes = cTokenStats . transactionHashes ; txHashes . push ( txHash ) ; cTokenStats . transactionHashes = txHashes ; let txTimes = cTokenStats . transactionTimes ; txTimes . push ( timestamp ) ; cTokenStats . transactionTimes = txTimes ; cTokenStats . accrualBlockNumber = blockNumber ; return cTokenStats as AccountCToken ; }