Role Required: ROLE_POOL_CLEARING_MANAGERFunction: LendingPoolManager.doClearing()
Clearing must be executed for every lending pool, every epoch, during the clearing period. Before executing clearing, loyalty levels must be calculated for the current epoch.
Pre-Clearing Steps
Anyone calls SystemVariables.updateKsuEpochTokenPrice() to update the KSU price
Anyone calls UserManager.batchCalculateUserLoyaltyLevels() to update loyalty levels
Number of users to process per transaction in Step 2
acceptRequestsBatchSize
Number of users to process per transaction in Step 4
isConfigOverridden
Set to true to use clearingConfigOverride values
Clearing Configuration Override
These parameters override the pool's stored values for this clearing execution only.
Execution
Clearing executes 5 steps sequentially (see Epochs & Clearing for details):
Apply pool interest to tranches
Calculate pending request priority
Calculate accepted deposit/withdrawal amounts
Process accepted requests
Draw funds
Batched Execution
Steps 2 and 4 may require multiple transactions if the number of requests exceeds block gas limits. Set priorityCalculationBatchSize and acceptRequestsBatchSize to control how many users are processed per call. Call doClearing() multiple times until all requests are processed.
Missing the Clearing Period
If clearing is not completed during the clearing period:
Halted at Step 2: Call doClearing() to apply interest (Step 1) only. User requests are not processed for that epoch
Halted at Step 4: Some user requests have already been processed. The Pool Clearing Manager must finish executing clearing even after the clearing period has lapsed
In all cases, Step 1 (apply interest) must be processed for every epoch to maintain accounting continuity.
When to Execute
Clearing should be executed every epoch during the clearing period for every active lending pool. The clearing period is the final 48 hours of each 7-day epoch.