Keeping a sorted list of Vaults ordered by LACR

The jAsset protocol utilizes a specific data structure known as a sorted doubly-linked list of Vaults, 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 Vaultsto 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 Vault 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 Vault at the time it was inserted into the list.

The decision to sort Vaults by LACR rather than ICR is based on the fact that each Vault 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 Vault operation occurs—such as adding or removing collateral or debt from the position.

Last updated