# TermDiscountRateAdapter.sol#TermDiscountRateAdapter

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

**Inherits:** [ITermDiscountRateAdapter](https://github.com/term-finance/term-finance-developer-docs/blob/main/src/interfaces/term/ITermDiscountRateAdapter.sol/interface.ITermDiscountRateAdapter.md), AccessControl

## State Variables

### ORACLE\_ROLE

```solidity
bytes32 public constant ORACLE_ROLE = keccak256("ORACLE_ROLE");
```

### prevTermController

*Previous term controller*

```solidity
ITermController public prevTermController;
```

### currTermController

*Current term controller*

```solidity
ITermController public currTermController;
```

### rateInvalid

```solidity
mapping(address => mapping(bytes32 => bool)) public rateInvalid;
```

### repoRedemptionHaircut

```solidity
mapping(address => uint256) public repoRedemptionHaircut;
```

## Functions

### constructor

```solidity
constructor(address termController_, address oracleWallet_);
```

### getDiscountRate

Retrieves the discount rate for a given repo token

*This function fetches the auction results for the repo token's term repo ID and returns the clearing rate of the most recent auction*

```solidity
function getDiscountRate(address termController, address repoToken) public view virtual returns (uint256);
```

**Parameters**

| Name             | Type      | Description                        |
| ---------------- | --------- | ---------------------------------- |
| `termController` | `address` | The address of the term controller |
| `repoToken`      | `address` | The address of the repo token      |

**Returns**

| Name     | Type      | Description                                    |
| -------- | --------- | ---------------------------------------------- |
| `<none>` | `uint256` | The discount rate for the specified repo token |

### getDiscountRate

Retrieves the discount rate for a given repo token

*This function fetches the auction results for the repo token's term repo ID and returns the clearing rate of the most recent auction*

```solidity
function getDiscountRate(address repoToken) public view virtual returns (uint256);
```

**Parameters**

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

**Returns**

| Name     | Type      | Description                                    |
| -------- | --------- | ---------------------------------------------- |
| `<none>` | `uint256` | The discount rate for the specified repo token |

### setAuctionRateValidator

Sets the invalidity of the result of a specific auction for a given repo token

*This function is used to mark auction results as invalid or not, typically in cases of suspected manipulation*

```solidity
function setAuctionRateValidator(address repoToken, bytes32 termAuctionId, bool isInvalid)
    external
    onlyRole(ORACLE_ROLE);
```

**Parameters**

| Name            | Type      | Description                                                 |
| --------------- | --------- | ----------------------------------------------------------- |
| `repoToken`     | `address` | The address of the repo token associated with the auction   |
| `termAuctionId` | `bytes32` | The unique identifier of the term auction to be invalidated |
| `isInvalid`     | `bool`    | The status of the rate invalidation                         |

### setTermController

Sets the term controller

```solidity
function setTermController(address termController) external onlyRole(ORACLE_ROLE);
```

**Parameters**

| Name             | Type      | Description                        |
| ---------------- | --------- | ---------------------------------- |
| `termController` | `address` | The address of the term controller |

### setRepoRedemptionHaircut

Set the repo redemption haircut

```solidity
function setRepoRedemptionHaircut(address repoToken, uint256 haircut) external onlyRole(ORACLE_ROLE);
```

**Parameters**

| Name        | Type      | Description                                |
| ----------- | --------- | ------------------------------------------ |
| `repoToken` | `address` | The address of the repo token              |
| `haircut`   | `uint256` | The repo redemption haircut in 18 decimals |

### \_identifyTermController

```solidity
function _identifyTermController(address termRepoToken) internal view returns (ITermController);
```

### \_getDiscountRate

```solidity
function _getDiscountRate(ITermController termController, address repoToken) internal view returns (uint256);
```

### \_validateAuctionExistence

```solidity
function _validateAuctionExistence(AuctionMetadata[] memory auctionMetadata, bytes32 termAuctionId)
    private
    pure
    returns (bool auctionExists);
```


---

# 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/termdiscountrateadapter.sol-termdiscountrateadapter.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.
