# TokenValidator

View Source: @nomisma/elektro-protocol-aux/contracts/tokens/validation/TokenValidator.sol

**↗ Extends: RoleAware** **↘ Derived Contracts: TokenValidatorProxy**

**TokenValidator**

Contract used for whitelisting tokens used in Elektro Markets Only user with "admin" role can add or remove tokens to whitelist If token is not valid, transaction is reverted Additionally contract is storing precision values for tokens. Precision is used in trade settlement calculations

## Structs

### Precision

```js
struct Precision {
 uint256 precision,
 uint256 toTokenPower
}
```

## Contract Members

**Constants & Variables**

```js
bytes32 private constant ADMIN_ROLE_NAME;
```

***

Mapping holding datd for Elektro whitelisted token precisions.Maps token address to a {Precision} struct holding precision values. Notice that a zero precision can NOT be passed since it serves as a sign that a precision for a certain token has not been initialized. See {Precision}

```js
mapping(address => struct TokenValidator.Precision) public whitelistedTokens;
```

***

## TokenWhitelisted

Event fired upon whitelisting a token for Elektro usage.

**Parameters**

| Name             | Type    | Description                                                                                                                                                                         |
| ---------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| whitelistedToken | address | - address of a whitelisted token                                                                                                                                                    |
| precision        | uint256 | - amount of decimals used/important for Elektro during rounding of values (always <= token decimals!)                                                                               |
| toTokenPower     | uint256 | - difference between decimals and precision, this value is used for calculations to convert (normalize) precision based amount to actual token denomination 10^(decimals-precision) |

## TokenRemovedFromWhitelist

Event fired upon token delisting.

**Parameters**

| Name         | Type    | Description |
| ------------ | ------- | ----------- |
| deletedToken | address |             |

## Functions

* [(address roleManager)](https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/broken-reference)
* [validateTokens(address\[\] tokens)](https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/broken-reference)
* [validateToken(address token)](https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/broken-reference)
* [getTokenPrecision(address token)](https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/broken-reference)
* [addTokensToWhitelist(address\[\] tokens, uint256\[\] precisions)](https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/broken-reference)
* [removeTokenFromWhitelist(address token)](https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/broken-reference)

###

Constructor setting {RoleManager} contract

```js
function (address roleManager) public nonpayable
```

**Arguments**

| Name        | Type    | Description                       |
| ----------- | ------- | --------------------------------- |
| roleManager | address | address of {RoleManager} contract |

### validateTokens

Function to bulk check if tokens can be used in Elektro as deposit in {FundLock} and traded with

```js
function validateTokens(address[] tokens) public view
```

**Arguments**

| Name   | Type       | Description                       |
| ------ | ---------- | --------------------------------- |
| tokens | address\[] | addresses of tokens to be checked |

### validateToken

Function to check if token can be used in Elektro as deposit in {FundLock} and traded with

```js
function validateToken(address token) public view
```

**Arguments**

| Name  | Type    | Description                    |
| ----- | ------- | ------------------------------ |
| token | address | address of token to be checked |

### getTokenPrecision

Function to get precision for token.

```js
function getTokenPrecision(address token) public view
returns(precision uint256, toTokenPower uint256)
```

**Returns**

precision of a requested token

**Arguments**

| Name  | Type    | Description                           |
| ----- | ------- | ------------------------------------- |
| token | address | address of token to get precision for |

### addTokensToWhitelist

Function to add addresses of tokens to be whitelisted for Elektro

```js
function addTokensToWhitelist(address[] tokens, uint256[] precisions) public nonpayable onlyRole 
```

**Arguments**

| Name       | Type       | Description                                                           |
| ---------- | ---------- | --------------------------------------------------------------------- |
| tokens     | address\[] | array of tokens addresses to be added to {TokenValidator}'s whitelist |
| precisions | uint256\[] | array of precision values to store in {TokenValidator} for tokens     |

### removeTokenFromWhitelist

Function to remove token address from {TokenValidator} whitelist

```js
function removeTokenFromWhitelist(address token) public nonpayable onlyRole 
```

**Arguments**

| Name  | Type    | Description                                                    |
| ----- | ------- | -------------------------------------------------------------- |
| token | address | address of token to be removed from {TokenValidator} whitelist |


---

# 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://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/tokenvalidator.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.
