# FHERC20.sol

### Overview

[FHERC20.sol](https://github.com/FhenixProtocol/redact/blob/master/packages/hardhat/contracts/FHERC20.sol) is an implementation of the ERC20 standard that incorporates Fully Homomorphic Encryption (FHE) to enable confidential token balances and confidential transfers. To read more about the design of the FHERC20 standard go here: [fherc20-token-standard](https://docs.redact.money/architecture/fherc20-token-standard "mention")

### External Functions

#### View Functions

**`isFherc20()`**

* Returns `true` to indicate this is a FHERC20 token
* Intended to be used by explorers and wallets in the future to change how the encrypted balances and encrypted transactions are displayed.

**`name()`**

* Returns the token name.
* In Redact, the token name of a ConfidentialERC20 is prefixed with `Confidential` . For example `Chainlink Token` would become `Confidential Chainlink Token`.

**`symbol()`**

* Returns the token symbol.
* In Redact, the token name of a ConfidentialERC20 is prefixed with `e` . For example `LINK` would become `eLINK`.

**`decimals()`**

* Returns the number of decimals for token display
* In Redact, the number of decimals of a ConfidentialERC20 is the same as the underlying ERC20.

**`totalSupply()`**

* Returns the **indicated** total supply

**`encTotalSupply()`**

* Returns the `ctHash` of the encrypted total supply.&#x20;

**`balanceOfIsIndicator()`**

* Returns `true` to indicate that `balanceOf` returns an indicator value rather than a true balance value.

**`indicatorTick()`**

* Returns the size of the indicator tick

**`balanceOf(address account)`**

* Returns the **indicated** balance for an account
* Value ranges from 0.0000 to 0.9999
* Increases by 0.0001 when receiving confidential tokens, reduces by 0.0001 when sending.
* Read more here: [#indicated-balances](https://docs.redact.money/fherc20-token-standard#indicated-balances "mention")

**`encBalanceOf(address account)`**

* Returns a `ctHash` representing the true encrypted balance of an account

#### State-Changing Functions

**`encTransfer(address to, InEuint128 memory inValue)`**&#x20;

`encTransfer(address to, euint128 inValue)`&#x20;

* Transfers encrypted tokens from sender to recipient
* Can either accept an encrypted input variable, or an encrypted uint128, as the amount to transfer.
* Emits both a Transfer event (with an indicated amount) and an EncTransfer event (with an encrypted `ctHash` amount)

**`encTransferFrom(address from, address to, InEuint128 memory inValue, FHERC20_EIP712_Permit calldata permit)`**

* Transfers encrypted tokens on behalf of another address
* Requires valid FHERC20\_EIP712 permit signature
* Emits both a Transfer event (with an indicated amount) and an EncTransfer event (with an encrypted `ctHash` amount)

#### Restricted Functions

The following standard ERC20 functions are intentionally restricted to prevent accidental usage:

* `transfer(address, uint256)`
* `allowance(address, address)`
* `approve(address, uint256)`
* `transferFrom(address, address, uint256)`

These functions will revert with `FHERC20IncompatibleFunction()` to prevent the contract from being treated as a standard ERC20.

### Events

#### `Transfer(address indexed from, address indexed to, uint256 value)`

* Emitted on token transfers
* Uses **indicated** balance values for compatibility

#### `EncTransfer(address indexed from, address indexed to, uint256 value)`

* Emitted on token transfers
* Includes the encrypted transfer value as a `ctHash`

### Confidentiality Considerations

1. All balance operations use FHE to maintain confidentiality
2. Traditional allowances are replaced with FHENIX\_EIP712 permits to be used during a transaction
3. Indicated balances are used for UI/UX only and should not be used for any logic
