> For the complete documentation index, see [llms.txt](https://docs.redact.money/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redact.money/architecture/confidentialerc20.sol/redactcore.sol.md).

# RedactCore.sol

### Overview

[RedactCore.sol](https://github.com/FhenixProtocol/redact/blob/master/packages/hardhat/contracts/RedactCore.sol) is the central management contract for the Redact protocol. It handles the deployment and tracking of confidential tokens (ConfidentialERC20) and manages special cases like ConfidentialETH. The contract maintains a registry of all deployed confidential tokens and their relationships with underlying ERC20 tokens.

### Key Concepts

#### Token Registry

* Maintains a mapping between ERC20 tokens and their confidential wrappers
* Uses `EnumerableMap` for efficient iteration and lookup
* Prevents duplicate deployments of confidential wrappers

#### Special Token Handling

* Manages ConfidentialETH (eETH) as a special case
* Tracks stablecoins separately for potential special handling
* Maintains WETH integration for ETH operations

#### Access Control

* Implements `Ownable2Step` for secure ownership management
* Restricts critical operations to the contract owner (EX: renaming ConfidentialERC20s)

### External Functions

#### View Functions

**`getFherc20(address erc20)`**

* Returns the address of the confidential wrapper for a given ERC20 token
* Returns `address(0)` if no wrapper exists
* Used to look up confidential token addresses

**`getIsStablecoin(address erc20)`**

* Returns whether a token is registered as a stablecoin
* Used for special handling of stablecoin tokens

**`getIsWETH(address erc20)`**

* Returns whether a token is the WETH contract
* Used for ETH-specific operations

**`getDeployedFherc20s()`**

* Returns an array of all deployed confidential tokens
* Includes both the original ERC20 and its confidential wrapper
* Useful for UI integration and monitoring

#### State-Changing Functions

**`deployFherc20(IERC20 erc20)`**

* Deploys a new ConfidentialERC20 wrapper for the specified token
* Prevents deployment for:
  * Already wrapped tokens
  * Stablecoins
  * WETH (handled separately)
* Emits `Fherc20Deployed` event

**`updateStablecoin(address stablecoin, bool isStablecoin)`**

* Updates the stablecoin status of a token
* Restricted to contract owner
* Emits `StablecoinUpdated` event

**`updateFherc20Symbol(ConfidentialERC20 fherc20, string memory updatedSymbol)`**

* Updates the symbol of a deployed confidential token
* Restricted to contract owner
* Emits `Fherc20SymbolUpdated` event

### Special Cases

#### ConfidentialETH (eETH)

* Pre-configured during contract deployment
* Uses WETH as the underlying token
* Handles native ETH wrapping/unwrapping
* Special gas optimizations for ETH operations

#### Stablecoins

* Can be marked as stablecoins for special handling
* Prevents deployment of confidential wrappers for stablecoins
* Allows for future implementation of stablecoin-specific features
* Prepares for a future unified encrypted stablecoin.

### Events

#### `Fherc20Deployed(address indexed erc20, address indexed fherc20)`

* Emitted when a new confidential token is deployed
* Includes both the original and confidential token addresses

#### `StablecoinUpdated(address indexed erc20, bool isStablecoin)`

* Emitted when a token's stablecoin status is updated
* Includes the token address and new status

#### `Fherc20SymbolUpdated(address indexed fherc20, string symbol)`

* Emitted when a confidential token's symbol is updated
* Includes the token address and new symbol

### Error Handling

#### Custom Errors

* `Invalid_AlreadyDeployed()`: Attempted to deploy wrapper for already wrapped token
* `Invalid_Stablecoin()`: Attempted to deploy wrapper for stablecoin
* `Invalid_WETH()`: Invalid WETH address provided
* `Invalid_eETH()`: Invalid eETH address provided

### Integration Guide

#### Deployment

1. Deploy WETH contract if not already deployed
2. Deploy ConfidentialETH (eETH) contract
3. Deploy RedactCore with WETH and eETH addresses

#### Adding New Tokens

1. Check if token is already wrapped using `getFherc20`
2. If not wrapped, call `deployFherc20` with the token address
3. Monitor `Fherc20Deployed` event for confirmation

#### UI Integration

1. Use `getDeployedFherc20s` to list all available confidential tokens
2. Use `getFherc20` to look up specific token wrappers
3. Handle special cases for ETH and stablecoins appropriately

### Security Considerations

1. **Access Control**
   * Critical functions restricted to owner
   * Two-step ownership transfer process
   * Careful management of stablecoin status
2. **Deployment Safety**
   * Prevention of duplicate deployments
   * Validation of WETH and eETH addresses
   * Protection against stablecoin wrapping
3. **Token Management**
   * Secure symbol updates
   * Proper event emission for tracking
   * Safe handling of special cases


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.redact.money/architecture/confidentialerc20.sol/redactcore.sol.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
