> For the complete documentation index, see [llms.txt](https://docs.elara.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.elara.fi/protocol-reference/reference/api-reference/vault/contract.tokenregistry.md).

# TokenRegistry

[Git Source](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/9301de6eec32ceafb4021f4e7da883b507799ebc/contracts/vault/TokenRegistry.sol)

**Inherits:** [ElaraBase](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/contracts/base/ElaraBase.sol/abstract.ElaraBase.md), ITokenRegistry

**Title:** Token Registry

Manages token configurations and supported tokens for the Elara protocol

Centralized token configuration management for the Elara protocol Invariants:

* Only authorized accounts can add or update token configurations
* Token configurations are validated before being added
* Supported tokens list accurately reflects all registered tokens Upgradeability:
* Uses ElaraBase for UUPS upgradeability
* Initializer must be called exactly once; preserve storage layout

**Note:** security-contact: <security@elara.finance>

## State Variables

### MAX\_FEE\_BPS

Maximum allowed fee rate in basis points.

Units: bps (basis points, where 10\_000 = 100%); this registry caps mint/redeem fees at 1000 bps (10%).

```solidity
uint16 private constant MAX_FEE_BPS = 1000
```

### tokenConfigs

Mapping of token addresses to their configurations

Tracks token configurations including fees and enabled operations

* Key: Token contract address
* Value: TokenConfig struct containing decimals, fees, and enabled operations
* Updated via [addToken](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/contracts/vault/TokenRegistry.sol/contract.TokenRegistry.md#addtoken) and [updateTokenConfig](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/contracts/vault/TokenRegistry.sol/contract.TokenRegistry.md#updatetokenconfig)

```solidity
mapping(address => TokenConfig) public tokenConfigs
```

### supportedTokens

List of all supported tokens

Array of token addresses that are registered and supported in the protocol

* Maintained to allow enumeration of all supported tokens
* Tokens are added via [addToken](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/contracts/vault/TokenRegistry.sol/contract.TokenRegistry.md#addtoken) but never removed

```solidity
address[] public supportedTokens
```

### \_\_gap

Storage gap for future upgrades (EIP-1967)

```solidity
uint256[50] private __gap
```

## Functions

### initialize

Initializes registry storage and seeds initial token configurations

Security:

* Only callable during initialization via {initializer} modifier
* Sets up the base contract via {ElaraBase-\_\_ElaraBase\_init}
* Access control is managed by the {AccessManager} contract
* Validates that the initial tokens and configs arrays have matching lengths
* Adds all initial tokens using [\_addToken](https://github.com/TrueFi-Protocol/elara-contracts-v2/blob/docs/latest/contracts/vault/TokenRegistry.sol/contract.TokenRegistry.md#_addtoken) which emits {TokenAdded} events

```solidity
function initialize(
    address _accessManager,
    address[] memory _initialTokens,
    TokenConfig[] memory _initialConfigs
)
    external
    initializer;
```

**Parameters**

| Name              | Type            | Description                               |
| ----------------- | --------------- | ----------------------------------------- |
| `_accessManager`  | `address`       | Address of the AccessManager contract     |
| `_initialTokens`  | `address[]`     | Array of token addresses to seed          |
| `_initialConfigs` | `TokenConfig[]` | Configurations matching each seeded token |

### addToken

Reverts if token address is zero or already supported. Validates configuration parameters.

```solidity
function addToken(address token, TokenConfig calldata config) external override(ITokenRegistry) restricted;
```

### updateTokenConfig

Reverts if token is not supported. Validates configuration parameters.

```solidity
function updateTokenConfig(
    address token,
    TokenConfig calldata config
)
    external
    override(ITokenRegistry)
    restricted;
```

### toggleMint

Reverts if token is not supported.

```solidity
function toggleMint(address token, bool enabled) external override(ITokenRegistry) restricted;
```

### toggleRedeem

Reverts if token is not supported.

```solidity
function toggleRedeem(address token, bool enabled) external override(ITokenRegistry) restricted;
```

### getTokenConfig

```solidity
function getTokenConfig(address token) external view override returns (TokenConfig memory config);
```

### \_addToken

Internal function to add a token to the registry

Private helper that performs the actual token addition

* Stores the config in tokenConfigs mapping (existence is inferred from decimals > 0)
* Adds token address to supportedTokens array
* Emits {TokenAdded} event with configuration details

```solidity
function _addToken(address token, TokenConfig memory config) private;
```

**Parameters**

| Name     | Type          | Description                 |
| -------- | ------------- | --------------------------- |
| `token`  | `address`     | Token address to add        |
| `config` | `TokenConfig` | Configuration for the token |

### \_validateTokenConfig

Validates token configuration parameters

Private helper that validates configuration before storage

* Ensures decimals are between 1 and 18 (standard ERC20 range)
* Validates mint fee rate doesn't exceed MAX\_FEE\_RATE (1000 bps)
* Validates redeem fee rate doesn't exceed MAX\_FEE\_RATE (1000 bps)
* Reverts with specific errors for invalid parameters

```solidity
function _validateTokenConfig(TokenConfig memory config) private pure;
```

**Parameters**

| Name     | Type          | Description               |
| -------- | ------------- | ------------------------- |
| `config` | `TokenConfig` | Configuration to validate |

## Events

### TokenRegistryInitialized

Emitted when the contract is initialized

```solidity
event TokenRegistryInitialized(address accessManager, address[] initialTokens, TokenConfig[] initialConfigs);
```

**Parameters**

| Name             | Type            | Description                           |
| ---------------- | --------------- | ------------------------------------- |
| `accessManager`  | `address`       | Address of the access manager         |
| `initialTokens`  | `address[]`     | Array of initial token addresses      |
| `initialConfigs` | `TokenConfig[]` | Array of initial token configurations |
