@@ -186,6 +186,10 @@ async function _handleEpochExecuted(event: SubstrateEvent<EpochClosedExecutedEve
186186 const pool = await PoolService . getById ( poolId . toString ( ) )
187187 if ( ! pool ) throw missingPool
188188
189+ assertPropInitialized ( pool , 'currencyId' , 'string' )
190+ const currency = await CurrencyService . get ( pool . currencyId ! )
191+ if ( ! currency ) throw new Error ( `Currency ${ pool . currencyId ! } not found for pool ${ pool . id } ` )
192+
189193 const epoch = await EpochService . getById ( poolId . toString ( ) , epochId . toNumber ( ) )
190194 if ( ! epoch ) throw new Error ( `Epoch ${ epochId . toString ( 10 ) } not found for pool ${ poolId . toString ( 10 ) } ` )
191195
@@ -195,7 +199,6 @@ async function _handleEpochExecuted(event: SubstrateEvent<EpochClosedExecutedEve
195199 await pool . executeEpoch ( epochId . toNumber ( ) )
196200 await pool . increaseInvestments ( epoch . sumInvestedAmount ! )
197201 await pool . increaseRedemptions ( epoch . sumRedeemedAmount ! )
198- await pool . save ( )
199202
200203 // Compute and save aggregated order fulfillment
201204 const tranches = await TrancheService . getByPoolId ( poolId . toString ( ) )
@@ -298,6 +301,12 @@ async function _handleEpochExecuted(event: SubstrateEvent<EpochClosedExecutedEve
298301 }
299302 await nextEpoch . saveWithStates ( )
300303
304+ // Update pool nav
305+ const partialNavs = tranches . map ( ( tranche ) => tranche . computePartialNav ( ) )
306+ await pool . setNav ( partialNavs . reduce ( ( nav , partialNav ) => nav + partialNav , BigInt ( 0 ) ) )
307+ await pool . updateNormalizedNAV ( currency . decimals )
308+ await pool . save ( )
309+
301310 // Track investments and redemptions for onchain cash
302311 if ( ! event . extrinsic ) throw new Error ( 'Event has no extrinsic' )
303312 const onChainCashAsset = await AssetService . getById ( pool . id , ONCHAIN_CASH_ASSET_ID )
0 commit comments