> ## Documentation Index
> Fetch the complete documentation index at: https://rootsfi.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sorted Troves

Discover the sophisticated data structure that keeps Troves organized: Sorted Troves. This contract maintains a doubly-linked list of all Troves, sorted by their Individual Collateralization Ratio (ICR), enabling efficient liquidation and redemption processes. Explore its functions for navigating and managing this crucial list.

## Functions

### `contains`

Checks if a Trove ID is present in the sorted list. (View)

```solidity theme={null}
function contains(_id: address) -> bool [view]
```

### `data`

Returns internal data of the sorted list. (View)

```solidity theme={null}
function data() -> (address, address, uint256) [view]
```

### `findInsertPosition`

Finds the correct position (previous and next Trove IDs) to insert a new Trove based on its NICR. (View)

```solidity theme={null}
function findInsertPosition(_NICR: uint256, _prevId: address, _nextId: address) -> (address, address) [view]
```

### `getFirst`

Returns the ID of the first Trove in the sorted list (lowest ICR). (View)

```solidity theme={null}
function getFirst() -> address [view]
```

### `getLast`

Returns the ID of the last Trove in the sorted list (highest ICR). (View)

```solidity theme={null}
function getLast() -> address [view]
```

### `getNext`

Returns the ID of the next Trove in the list relative to a given Trove ID. (View)

```solidity theme={null}
function getNext(_id: address) -> address [view]
```

### `getPrev`

Returns the ID of the previous Trove in the list relative to a given Trove ID. (View)

```solidity theme={null}
function getPrev(_id: address) -> address [view]
```

### `getSize`

Returns the total number of Troves in the sorted list. (View)

```solidity theme={null}
function getSize() -> uint256 [view]
```

### `insert`

Inserts a new Trove ID into the sorted list at the correct position based on its NICR.

```solidity theme={null}
function insert(_id: address, _NICR: uint256, _prevId: address, _nextId: address) [nonpayable]
```

### `isEmpty`

Checks if the sorted list of Troves is empty. (View)

```solidity theme={null}
function isEmpty() -> bool [view]
```

### `reInsert`

Re-inserts a Trove ID into the sorted list when its NICR changes, finding its new correct position.

```solidity theme={null}
function reInsert(_id: address, _newNICR: uint256, _prevId: address, _nextId: address) [nonpayable]
```

### `remove`

Removes a Trove ID from the sorted list.

```solidity theme={null}
function remove(_id: address) [nonpayable]
```

### `setAddresses`

Sets the address of the Trove Manager contract.

```solidity theme={null}
function setAddresses(_troveManagerAddress: address) [nonpayable]
```

### `troveManager`

Returns the address of the associated `ITroveManager` contract. (View)

```solidity theme={null}
function troveManager() -> address (contract ITroveManager) [view]
```

### `validInsertPosition`

Validates if a given insert position (based on NICR, previous ID, and next ID) is correct. (View)

```solidity theme={null}
function validInsertPosition(_NICR: uint256, _prevId: address, _nextId: address) -> bool [view]
```

## Events

### `NodeAdded`

Emitted when a new Trove (node) is added to the sorted list.

```solidity theme={null}
event NodeAdded(_id: address, _NICR: uint256)
```

### `NodeRemoved`

Emitted when a Trove (node) is removed from the sorted list.

```solidity theme={null}
event NodeRemoved(_id: address)
```
