> For the complete documentation index, see [llms.txt](https://elektro.gitbook.io/elektro-protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://elektro.gitbook.io/elektro-protocol/smart-contracts/natspec-technical-documentation/token-management/tokenvalidator.md).

# 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)](broken://pages/iL7wn4wsdUehaHx97MBp)
* [validateTokens(address\[\] tokens)](broken://pages/iL7wn4wsdUehaHx97MBp)
* [validateToken(address token)](broken://pages/iL7wn4wsdUehaHx97MBp)
* [getTokenPrecision(address token)](broken://pages/iL7wn4wsdUehaHx97MBp)
* [addTokensToWhitelist(address\[\] tokens, uint256\[\] precisions)](broken://pages/iL7wn4wsdUehaHx97MBp)
* [removeTokenFromWhitelist(address token)](broken://pages/iL7wn4wsdUehaHx97MBp)

###

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 |
