# RepoTokenList.sol#RepoTokenList

[Git Source](https://github.com/term-finance/yearn-v3-term-vault/blob/fdab68ac51eb0929f23686f72922fed45a3d7d1d/src/RepoTokenList.sol)

## State Variables

### NULL\_NODE

```solidity
address internal constant NULL_NODE = address(0);
```

### INVALID\_AUCTION\_RATE

```solidity
uint256 internal constant INVALID_AUCTION_RATE = 0;
```

### ZERO\_AUCTION\_RATE

```solidity
uint256 internal constant ZERO_AUCTION_RATE = 1;
```

## Functions

### getRepoTokenMaturity

Retrieves the redemption (maturity) timestamp of a repoToken

*This function calls the `config()` method on the repoToken to retrieve its configuration details, including the redemption timestamp, which it then returns.*

```solidity
function getRepoTokenMaturity(address repoToken) internal view returns (uint256 redemptionTimestamp);
```

**Parameters**

| Name        | Type      | Description                  |
| ----------- | --------- | ---------------------------- |
| `repoToken` | `address` | The address of the repoToken |

**Returns**

| Name                  | Type      | Description                                         |
| --------------------- | --------- | --------------------------------------------------- |
| `redemptionTimestamp` | `uint256` | The timestamp indicating when the repoToken matures |

### \_getNext

Get the next node in the list

```solidity
function _getNext(RepoTokenListData storage listData, address current) private view returns (address);
```

**Parameters**

| Name       | Type                | Description      |
| ---------- | ------------------- | ---------------- |
| `listData` | `RepoTokenListData` | The list data    |
| `current`  | `address`           | The current node |

**Returns**

| Name     | Type      | Description   |
| -------- | --------- | ------------- |
| `<none>` | `address` | The next node |

### \_count

Count the number of nodes in the list

```solidity
function _count(RepoTokenListData storage listData) private view returns (uint256 count);
```

**Parameters**

| Name       | Type                | Description   |
| ---------- | ------------------- | ------------- |
| `listData` | `RepoTokenListData` | The list data |

**Returns**

| Name    | Type      | Description                     |
| ------- | --------- | ------------------------------- |
| `count` | `uint256` | The number of nodes in the list |

### holdings

Returns an array of addresses representing the repoTokens currently held in the list data

*This function iterates through the list of repoTokens and returns their addresses in an array. It first counts the number of repoTokens, initializes an array of that size, and then populates the array with the addresses of the repoTokens.*

```solidity
function holdings(RepoTokenListData storage listData) internal view returns (address[] memory holdingsArray);
```

**Parameters**

| Name       | Type                | Description   |
| ---------- | ------------------- | ------------- |
| `listData` | `RepoTokenListData` | The list data |

**Returns**

| Name            | Type        | Description                                              |
| --------------- | ----------- | -------------------------------------------------------- |
| `holdingsArray` | `address[]` | An array of addresses of the repoTokens held in the list |

### getRepoTokenWeightedTimeToMaturity

Get the weighted time to maturity of the strategy's holdings of a specified repoToken

```solidity
function getRepoTokenWeightedTimeToMaturity(address repoToken, uint256 repoTokenBalanceInBaseAssetPrecision)
    internal
    view
    returns (uint256 weightedTimeToMaturity);
```

**Parameters**

| Name                                   | Type      | Description                                          |
| -------------------------------------- | --------- | ---------------------------------------------------- |
| `repoToken`                            | `address` | The address of the repoToken                         |
| `repoTokenBalanceInBaseAssetPrecision` | `uint256` | The balance of the repoToken in base asset precision |

**Returns**

| Name                     | Type      | Description                                                                          |
| ------------------------ | --------- | ------------------------------------------------------------------------------------ |
| `weightedTimeToMaturity` | `uint256` | The weighted time to maturity in seconds x repoToken balance in base asset precision |

### getCumulativeRepoTokenData

This function calculates the cumulative weighted time to maturity and cumulative amount of all repoTokens in the list.

*The `repoToken` and `repoTokenAmount` parameters are optional and provide flexibility to adjust the calculations to include the provided repoToken and amount. If `repoToken` is set to `address(0)` or `repoTokenAmount` is `0`, the function calculates the cumulative data without specific token adjustments.*

```solidity
function getCumulativeRepoTokenData(
    RepoTokenListData storage listData,
    ITermDiscountRateAdapter discountRateAdapter,
    address repoToken,
    uint256 repoTokenAmount,
    uint256 purchaseTokenPrecision
) internal view returns (uint256 cumulativeWeightedTimeToMaturity, uint256 cumulativeRepoTokenAmount, bool found);
```

**Parameters**

| Name                     | Type                       | Description                             |
| ------------------------ | -------------------------- | --------------------------------------- |
| `listData`               | `RepoTokenListData`        | The list data                           |
| `discountRateAdapter`    | `ITermDiscountRateAdapter` | The discount rate adapter               |
| `repoToken`              | `address`                  | The address of the repoToken (optional) |
| `repoTokenAmount`        | `uint256`                  | The amount of the repoToken (optional)  |
| `purchaseTokenPrecision` | `uint256`                  | The precision of the purchase token     |

**Returns**

| Name                               | Type      | Description                                                 |
| ---------------------------------- | --------- | ----------------------------------------------------------- |
| `cumulativeWeightedTimeToMaturity` | `uint256` | The cumulative weighted time to maturity for all repoTokens |
| `cumulativeRepoTokenAmount`        | `uint256` | The cumulative repoToken amount across all repoTokens       |
| `found`                            | `bool`    | Whether the specified repoToken was found in the list       |

### getPresentValue

Get the present value of repoTokens

*Aggregates the present value of all repoTokens in the list.*

```solidity
function getPresentValue(
    RepoTokenListData storage listData,
    ITermDiscountRateAdapter discountRateAdapter,
    uint256 purchaseTokenPrecision
) internal view returns (uint256 totalPresentValue);
```

**Parameters**

| Name                     | Type                       | Description                         |
| ------------------------ | -------------------------- | ----------------------------------- |
| `listData`               | `RepoTokenListData`        | The list data                       |
| `discountRateAdapter`    | `ITermDiscountRateAdapter` | The discount rate adapter           |
| `purchaseTokenPrecision` | `uint256`                  | The precision of the purchase token |

**Returns**

| Name                | Type      | Description                               |
| ------------------- | --------- | ----------------------------------------- |
| `totalPresentValue` | `uint256` | The total present value of the repoTokens |

### \_getRepoTokenTimeToMaturity

Calculates the time remaining until a repoToken matures

*This function calculates the difference between the redemption timestamp and the current block timestamp to determine how many seconds are left until the repoToken reaches its maturity.*

```solidity
function _getRepoTokenTimeToMaturity(uint256 redemptionTimestamp) private view returns (uint256);
```

**Parameters**

| Name                  | Type      | Description                               |
| --------------------- | --------- | ----------------------------------------- |
| `redemptionTimestamp` | `uint256` | The redemption timestamp of the repoToken |

**Returns**

| Name     | Type      | Description                                                         |
| -------- | --------- | ------------------------------------------------------------------- |
| `<none>` | `uint256` | uint256 The time remaining (in seconds) until the repoToken matures |

### removeAndRedeemMaturedTokens

Removes and redeems matured repoTokens from the list data

*Iterates through the list of repoTokens and removes those that have matured. If a matured repoToken has a balance, the function attempts to redeem it. This helps maintain the list by clearing out matured repoTokens and redeeming their balances.*

```solidity
function removeAndRedeemMaturedTokens(RepoTokenListData storage listData) internal;
```

**Parameters**

| Name       | Type                | Description   |
| ---------- | ------------------- | ------------- |
| `listData` | `RepoTokenListData` | The list data |

### validateRepoToken

Validates a repoToken against specific criteria

*early exit because list is sorted*

*Ensures the repoToken is deployed, matches the purchase token, is not matured, and meets collateral requirements. Reverts with `InvalidRepoToken` if any validation check fails.*

```solidity
function validateRepoToken(RepoTokenListData storage listData, ITermRepoToken repoToken, address asset)
    internal
    view
    returns (bool isRepoTokenValid, uint256 redemptionTimestamp);
```

**Parameters**

| Name        | Type                | Description                   |
| ----------- | ------------------- | ----------------------------- |
| `listData`  | `RepoTokenListData` | The list data                 |
| `repoToken` | `ITermRepoToken`    | The repoToken to validate     |
| `asset`     | `address`           | The address of the base asset |

**Returns**

| Name                  | Type      | Description                                         |
| --------------------- | --------- | --------------------------------------------------- |
| `isRepoTokenValid`    | `bool`    | Whether the repoToken is valid                      |
| `redemptionTimestamp` | `uint256` | The redemption timestamp of the validated repoToken |

### validateAndInsertRepoToken

Validate and insert a repoToken into the list data

```solidity
function validateAndInsertRepoToken(
    RepoTokenListData storage listData,
    ITermRepoToken repoToken,
    ITermDiscountRateAdapter discountRateAdapter,
    address asset
) internal returns (bool validRepoToken, uint256 redemptionTimestamp);
```

**Parameters**

| Name                  | Type                       | Description                          |
| --------------------- | -------------------------- | ------------------------------------ |
| `listData`            | `RepoTokenListData`        | The list data                        |
| `repoToken`           | `ITermRepoToken`           | The repoToken to validate and insert |
| `discountRateAdapter` | `ITermDiscountRateAdapter` | The discount rate adapter            |
| `asset`               | `address`                  | The address of the base asset        |

**Returns**

| Name                  | Type      | Description                                         |
| --------------------- | --------- | --------------------------------------------------- |
| `validRepoToken`      | `bool`    | Whether the repoToken is valid                      |
| `redemptionTimestamp` | `uint256` | The redemption timestamp of the validated repoToken |

### insertSorted

Insert a repoToken into the list in a sorted manner

*Inserts the `repoToken` into the `listData` while maintaining the list sorted by the repoTokens' maturity timestamps. The function iterates through the list to find the correct position for the new `repoToken` and updates the pointers accordingly.*

```solidity
function insertSorted(RepoTokenListData storage listData, address repoToken) internal;
```

**Parameters**

| Name        | Type                | Description                                 |
| ----------- | ------------------- | ------------------------------------------- |
| `listData`  | `RepoTokenListData` | The list data                               |
| `repoToken` | `address`           | The address of the repoToken to be inserted |

## Errors

### InvalidRepoToken

```solidity
error InvalidRepoToken(address token);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.term.finance/periphery-contracts/curated-vaults/solidity-api-latest/repotokenlist.sol-repotokenlist.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
