@@ -209,6 +209,22 @@ func (eng *DebtEngine) CalculateDebt() {
209209 log .Fatalf ("CM(%s):pool is missing stats at %d, so cumulative index of pool is unknown" , cmAddr , blockNum )
210210 }
211211 }
212+ for _ , session := range sessions {
213+ if (session .ClosedAt != 0 && session .ClosedAt <= blockNum ) || session .Since > blockNum {
214+ continue
215+ }
216+ pool := eng .priceHandler .GetPoolFromCM (session .CreditManager )
217+ adapter := eng .repo .GetAdapter (pool )
218+ state := adapter .GetUnderlyingState ()
219+ if state == nil {
220+ log .Fatal ("State for pool not found for address: " , pool )
221+ }
222+ //
223+ market := state .(* schemas.PoolState ).Market
224+ if debt := eng .lastDebts [session .ID ]; debt != nil {
225+ marketToTvl .add (market , 0 , 0 , 0 , debt .TotalValueInUSD )
226+ }
227+ }
212228 //
213229 eng .createTvlSnapshots (blockNum , marketToTvl )
214230 if len (sessionsUpdated ) > 0 {
@@ -260,6 +276,7 @@ func (eng *DebtEngine) createTvlSnapshots(blockNum int64, marketToTvl MarketToTv
260276 AvailableLiquidity : details .totalAvailableLiquidity ,
261277 CATotalValue : details .caTotalValue ,
262278 ExpectedLiq : details .expectedLiq ,
279+ CATotalValueCalc : details .caTotalValueCalculated ,
263280 Market : market ,
264281 }
265282 addedMarket = append (addedMarket , market )
0 commit comments