@@ -192,23 +192,25 @@ func (eng *DebtEngine) CalculateSessionDebt(blockNum int64, sessionId string, cm
192192 // profiling
193193 tokenDetails := map [string ]core.TokenDetails {}
194194 for tokenAddr , balance := range * sessionSnapshot .Balances {
195- if ! balance .Linked {
196- continue
197- }
198195 decimal := eng .repo .GetToken (tokenAddr ).Decimals
199196 price := eng .GetTokenLastPrice (tokenAddr )
200- tokenValue := new (big.Int ).Mul (price , balance .BI .Convert ())
201- tokenValueInDecimal := utils .GetInt64Decimal (tokenValue , decimal - underlyingtoken .Decimals )
202197 tokenLiquidityThreshold := eng.allowedTokensThreshold [cmAddr ][tokenAddr ]
203- tokenThresholdValue := new (big.Int ).Mul (tokenValueInDecimal , tokenLiquidityThreshold .Convert ())
204- calThresholdValue = new (big.Int ).Add (calThresholdValue , tokenThresholdValue )
205- calTotalValue = new (big.Int ).Add (calTotalValue , tokenValueInDecimal )
206198 // profiling
207199 tokenDetails [tokenAddr ] = core.TokenDetails {
208200 Price : price ,
209201 Decimals : decimal ,
210202 TokenLiqThreshold : tokenLiquidityThreshold ,
211203 Symbol : eng .repo .GetToken (tokenAddr ).Symbol }
204+ // token not linked continue
205+ if ! balance .Linked {
206+ continue
207+ }
208+ tokenValue := new (big.Int ).Mul (price , balance .BI .Convert ())
209+ tokenValueInDecimal := utils .GetInt64Decimal (tokenValue , decimal - underlyingtoken .Decimals )
210+ tokenThresholdValue := new (big.Int ).Mul (tokenValueInDecimal , tokenLiquidityThreshold .Convert ())
211+ calThresholdValue = new (big.Int ).Add (calThresholdValue , tokenThresholdValue )
212+ calTotalValue = new (big.Int ).Add (calTotalValue , tokenValueInDecimal )
213+
212214 }
213215 // the value of credit account is in terms of underlying asset
214216 underlyingPrice := eng .GetTokenLastPrice (cumIndexAndUToken .Token )
@@ -242,7 +244,11 @@ func (eng *DebtEngine) CalculateSessionDebt(blockNum int64, sessionId string, cm
242244 ! core .CompareBalance (debt .CalBorrowedAmountPlusInterestBI , debt .BorrowedAmountPlusInterestBI , underlyingtoken ) ||
243245 core .ValueDifferSideOf10000 (debt .CalHealthFactor , debt .HealthFactor ) {
244246 mask := eng .repo .GetMask (blockNum , cmAddr , accountAddr )
245- profile .RPCBalances = eng .repo .ConvertToBalanceWithMask (data .Balances , mask )
247+ var err error
248+ profile .RPCBalances , err = eng .repo .ConvertToBalanceWithMask (data .Balances , mask )
249+ if err != nil {
250+ log .Fatalf ("DC wrong token values block:%d dc:%s" , blockNum , utils .ToJson (eng .repo .GetDCWrapper ()))
251+ }
246252 notMatched = true
247253 }
248254 // even if data compressor matching is disabled check the values with values at which last credit snapshot was taken
@@ -300,7 +306,6 @@ func (eng *DebtEngine) requestPriceFeed(blockNum int64, feed, token string) {
300306 if err != nil {
301307 log .Fatal (err )
302308 }
303- log .Info (token , roundData .Answer .String (), utils .GetFloat64Decimal (roundData .Answer , 18 ))
304309 eng .AddTokenLastPrice (& core.PriceFeed {
305310 BlockNumber : blockNum ,
306311 Token : token ,
0 commit comments