Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We now have 3 aggregate trackers on the ActivePool, as per the simple compounding specification:
aggRecordedDebt (D)
recordedDebtSum (G)
weightedRecordedDebtSum (S)
G
is the original ActivePool debt tracker from Liquity v1. We keep it for now as a) it may be useful for computing a size-weighted average interest rate on the front end, and b) would be needed if we decide to add an emergency base interest rate to every position.Pseudocode for aggregate trackers in different operations
As in v1, we always apply any redistribution debt gain before handling interest accounting.
The redistribution gain is already included in G before we alter G from the specific operation.
The prefix “old” means the respective debt with no redistribution gains or interest applied, and “new” implies all debt changes (redist. gains, interest, debt drawn/repaid) are included.
openTrove:
closeTrove:
adjustTrove:
And for the individual Trove:
new_recorded_trove_debt = old_recorded_trove_debt + accrued_trove_interest + trove_debt_change
applyTroveInterestPermissionless:
adjustTroveInterestRate:
SP deposit/withdrawal:
D += agg_accrued_interest
Liquidation - Normal Mode, offset
This is effectively the same as closing the Trove:
Liquidation - Normal Mode, redistribution:
This is effectively the same as closing the Trove, except we add the entire debt to the DefaultPool:
Also:
DefaultPool.debt += (old_recorded_trove_debt + redistribution_gain + accrued_trove_interest)
TODOs:
** Liquidations in Recovery Mode**
Minting/applying interest has been implemented for RM liquidations to make tests pass, but if we keep RM we should double-check that minting/applying interest is correct for for every logical case of RM.
Redemption:
This is effectively a downward debt adjustment (since we will no longer close Troves on redemption):
This will be implemented in combination with #55 and #48, since these significantly change redemption logic anyway.
Testing TODOs:
D + S*delta_t == sum_individual_entire_trove_debts
)