Keeping a sorted list of Troves ordered by LACR

The jAsset protocol utilizes a specific data structure known as a sorted doubly-linked list of Troves, which remains ordered by the last active individual collateralization ratio (LACR). The LACR is calculated as the collateral amount in USD divided by the debt amount in USD at the time of the last update by the borrower.

This ordered list is crucial for efficient gas usage during redemption sequences, as it allows Troves to be targeted in ascending order of their individual collateralization ratios (ICR).

The implementation of this sorted doubly-linked list can be found in SortedTroves.sol.

Each node in this list corresponds to an active Trove in the system, identified by the owner's address. The list supports positional hints for efficient O(1) insertion, which is further detailed in the HintHelper section.

Additionally, each node stores the LACR of the Trove at the time it was inserted into the list.

The decision to sort Troves by LACR rather than ICR is based on the fact that each Trove can hold varying proportions of different collateral tokens. Changes in token prices affect individual collateralization ratios differently, making it impractical to maintain a sorted list based solely on ICR.

Nodes are re-inserted into the sorted list only when a Trove operation occurs—such as adding or removing collateral or debt from the position.

Last updated