# ERC1400

## ERC1400Upgradeable

[Git Source](https://github.com/Libertum-Project/security-token-contracts/blob/3464d5ab8850f3f8fc835299f95703c8793378ae/src/ERC1400Upgradeable.sol)

**Inherits:** IERC20, IERC1400, ERC1400Storage, OwnableUpgradeable, ERC1820Client, ERC1820Implementer, MinterRoleUpgradeable, DomainAwareUpgradeable

*ERC1400 logic*

### State Variables

#### ERC1400\_INTERFACE\_NAME

```solidity
string internal constant ERC1400_INTERFACE_NAME = "ERC1400Token";
```

#### ERC20\_INTERFACE\_NAME

```solidity
string internal constant ERC20_INTERFACE_NAME = "ERC20Token";
```

#### ERC1400\_TOKENS\_CHECKER

```solidity
string internal constant ERC1400_TOKENS_CHECKER = "ERC1400TokensChecker";
```

#### ERC1400\_TOKENS\_VALIDATOR

```solidity
string internal constant ERC1400_TOKENS_VALIDATOR = "ERC1400TokensValidator";
```

#### ERC1400\_TOKENS\_SENDER

```solidity
string internal constant ERC1400_TOKENS_SENDER = "ERC1400TokensSender";
```

#### ERC1400\_TOKENS\_RECIPIENT

```solidity
string internal constant ERC1400_TOKENS_RECIPIENT = "ERC1400TokensRecipient";
```

### Functions

#### \_\_ERC1400\_init

*Initialize ERC1400 + register the contract implementation in ERC1820Registry.*

```solidity
function __ERC1400_init(
    string memory tokenName,
    string memory tokenSymbol,
    uint256 tokenGranularity,
    address[] memory initialControllers,
    bytes32[] memory defaultPartitions,
    address owner,
    address minter
) internal onlyInitializing;
```

**Parameters**

| Name                 | Type        | Description                                                                                  |
| -------------------- | ----------- | -------------------------------------------------------------------------------------------- |
| `tokenName`          | `string`    | Name of the token.                                                                           |
| `tokenSymbol`        | `string`    | Symbol of the token.                                                                         |
| `tokenGranularity`   | `uint256`   | Granularity of the token.                                                                    |
| `initialControllers` | `address[]` | Array of initial controllers.                                                                |
| `defaultPartitions`  | `bytes32[]` | Partitions chosen by default, when partition is not specified, like the case ERC20 tranfers. |
| `owner`              | `address`   |                                                                                              |
| `minter`             | `address`   |                                                                                              |

#### isIssuableToken

Modifiers \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

*Modifier to verify if token is issuable.*

```solidity
modifier isIssuableToken();
```

#### isNotMigratedToken

*Modifier to make a function callable only when the contract is not migrated.*

```solidity
modifier isNotMigratedToken();
```

#### onlyMinter

*Modifier to verifiy if sender is a minter.*

```solidity
modifier onlyMinter() override;
```

#### totalSupply

*Get the total number of issued tokens.*

```solidity
function totalSupply() external view override returns (uint256);
```

**Returns**

| Name     | Type      | Description                                      |
| -------- | --------- | ------------------------------------------------ |
| `<none>` | `uint256` | Total supply of tokens currently in circulation. |

#### balanceOf

*Get the balance of the account with address 'tokenHolder'.*

```solidity
function balanceOf(address tokenHolder) external view override returns (uint256);
```

**Parameters**

| Name          | Type      | Description                                |
| ------------- | --------- | ------------------------------------------ |
| `tokenHolder` | `address` | Address for which the balance is returned. |

**Returns**

| Name     | Type      | Description                                                  |
| -------- | --------- | ------------------------------------------------------------ |
| `<none>` | `uint256` | Amount of token held by 'tokenHolder' in the token contract. |

#### transfer

*Transfer token for a specified address.*

```solidity
function transfer(address to, uint256 value) external override returns (bool);
```

**Parameters**

| Name    | Type      | Description                  |
| ------- | --------- | ---------------------------- |
| `to`    | `address` | The address to transfer to.  |
| `value` | `uint256` | The value to be transferred. |

**Returns**

| Name     | Type   | Description                                               |
| -------- | ------ | --------------------------------------------------------- |
| `<none>` | `bool` | A boolean that indicates if the operation was successful. |

#### allowance

*Check the value of tokens that an owner allowed to a spender.*

```solidity
function allowance(address owner, address spender) external view override returns (uint256);
```

**Parameters**

| Name      | Type      | Description                                     |
| --------- | --------- | ----------------------------------------------- |
| `owner`   | `address` | address The address which owns the funds.       |
| `spender` | `address` | address The address which will spend the funds. |

**Returns**

| Name     | Type      | Description                                                               |
| -------- | --------- | ------------------------------------------------------------------------- |
| `<none>` | `uint256` | A uint256 specifying the value of tokens still available for the spender. |

#### approve

*Approve the passed address to spend the specified amount of tokens on behalf of 'msg.sender'.*

```solidity
function approve(address spender, uint256 value) external override returns (bool);
```

**Parameters**

| Name      | Type      | Description                             |
| --------- | --------- | --------------------------------------- |
| `spender` | `address` | The address which will spend the funds. |
| `value`   | `uint256` | The amount of tokens to be spent.       |

**Returns**

| Name     | Type   | Description                                               |
| -------- | ------ | --------------------------------------------------------- |
| `<none>` | `bool` | A boolean that indicates if the operation was successful. |

#### transferFrom

*Transfer tokens from one address to another.*

```solidity
function transferFrom(address from, address to, uint256 value) external override returns (bool);
```

**Parameters**

| Name    | Type      | Description                                         |
| ------- | --------- | --------------------------------------------------- |
| `from`  | `address` | The address which you want to transfer tokens from. |
| `to`    | `address` | The address which you want to transfer to.          |
| `value` | `uint256` | The amount of tokens to be transferred.             |

**Returns**

| Name     | Type   | Description                                               |
| -------- | ------ | --------------------------------------------------------- |
| `<none>` | `bool` | A boolean that indicates if the operation was successful. |

#### getDocument

*Access a document associated with the token.*

```solidity
function getDocument(bytes32 documentName) external view override returns (string memory, bytes32, uint256);
```

**Parameters**

| Name           | Type      | Description                                                       |
| -------------- | --------- | ----------------------------------------------------------------- |
| `documentName` | `bytes32` | Short name (represented as a bytes32) associated to the document. |

**Returns**

| Name     | Type      | Description                                              |
| -------- | --------- | -------------------------------------------------------- |
| `<none>` | `string`  | Requested document + document hash + document timestamp. |
| `<none>` | `bytes32` |                                                          |
| `<none>` | `uint256` |                                                          |

#### setDocument

*Associate a document with the token.*

```solidity
function setDocument(bytes32 documentName, string calldata uri, bytes32 documentHash) external override;
```

**Parameters**

| Name           | Type      | Description                                                       |
| -------------- | --------- | ----------------------------------------------------------------- |
| `documentName` | `bytes32` | Short name (represented as a bytes32) associated to the document. |
| `uri`          | `string`  | Document content.                                                 |
| `documentHash` | `bytes32` | Hash of the document \[optional parameter].                       |

#### removeDocument

```solidity
function removeDocument(bytes32 documentName) external override;
```

#### getAllDocuments

```solidity
function getAllDocuments() external view override returns (bytes32[] memory);
```

#### balanceOfByPartition

*Get balance of a tokenholder for a specific partition.*

```solidity
function balanceOfByPartition(bytes32 partition, address tokenHolder) external view override returns (uint256);
```

**Parameters**

| Name          | Type      | Description                                |
| ------------- | --------- | ------------------------------------------ |
| `partition`   | `bytes32` | Name of the partition.                     |
| `tokenHolder` | `address` | Address for which the balance is returned. |

**Returns**

| Name     | Type      | Description                                                                           |
| -------- | --------- | ------------------------------------------------------------------------------------- |
| `<none>` | `uint256` | Amount of token of partition 'partition' held by 'tokenHolder' in the token contract. |

#### partitionsOf

*Get partitions index of a tokenholder.*

```solidity
function partitionsOf(address tokenHolder) external view override returns (bytes32[] memory);
```

**Parameters**

| Name          | Type      | Description                                          |
| ------------- | --------- | ---------------------------------------------------- |
| `tokenHolder` | `address` | Address for which the partitions index are returned. |

**Returns**

| Name     | Type        | Description                                 |
| -------- | ----------- | ------------------------------------------- |
| `<none>` | `bytes32[]` | Array of partitions index of 'tokenHolder'. |

#### transferWithData

*Transfer the amount of tokens from the address 'msg.sender' to the address 'to'.*

```solidity
function transferWithData(address to, uint256 value, bytes calldata data) external override;
```

**Parameters**

| Name    | Type      | Description                                                |
| ------- | --------- | ---------------------------------------------------------- |
| `to`    | `address` | Token recipient.                                           |
| `value` | `uint256` | Number of tokens to transfer.                              |
| `data`  | `bytes`   | Information attached to the transfer, by the token holder. |

#### transferFromWithData

*Transfer the amount of tokens on behalf of the address 'from' to the address 'to'.*

```solidity
function transferFromWithData(address from, address to, uint256 value, bytes calldata data) external virtual override;
```

**Parameters**

| Name    | Type      | Description                                                                       |
| ------- | --------- | --------------------------------------------------------------------------------- |
| `from`  | `address` | Token holder (or 'address(0)' to set from to 'msg.sender').                       |
| `to`    | `address` | Token recipient.                                                                  |
| `value` | `uint256` | Number of tokens to transfer.                                                     |
| `data`  | `bytes`   | Information attached to the transfer, and intended for the token holder ('from'). |

#### transferByPartition

*Transfer tokens from a specific partition.*

```solidity
function transferByPartition(bytes32 partition, address to, uint256 value, bytes calldata data)
    external
    override
    returns (bytes32);
```

**Parameters**

| Name        | Type      | Description                                                |
| ----------- | --------- | ---------------------------------------------------------- |
| `partition` | `bytes32` | Name of the partition.                                     |
| `to`        | `address` | Token recipient.                                           |
| `value`     | `uint256` | Number of tokens to transfer.                              |
| `data`      | `bytes`   | Information attached to the transfer, by the token holder. |

**Returns**

| Name     | Type      | Description            |
| -------- | --------- | ---------------------- |
| `<none>` | `bytes32` | Destination partition. |

#### operatorTransferByPartition

*Transfer tokens from a specific partition through an operator.*

```solidity
function operatorTransferByPartition(
    bytes32 partition,
    address from,
    address to,
    uint256 value,
    bytes calldata data,
    bytes calldata operatorData
) external override returns (bytes32);
```

**Parameters**

| Name           | Type      | Description                                                                    |
| -------------- | --------- | ------------------------------------------------------------------------------ |
| `partition`    | `bytes32` | Name of the partition.                                                         |
| `from`         | `address` | Token holder.                                                                  |
| `to`           | `address` | Token recipient.                                                               |
| `value`        | `uint256` | Number of tokens to transfer.                                                  |
| `data`         | `bytes`   | Information attached to the transfer. \[CAN CONTAIN THE DESTINATION PARTITION] |
| `operatorData` | `bytes`   | Information attached to the transfer, by the operator.                         |

**Returns**

| Name     | Type      | Description            |
| -------- | --------- | ---------------------- |
| `<none>` | `bytes32` | Destination partition. |

#### isControllable

*Know if the token can be controlled by operators. If a token returns 'false' for 'isControllable()'' then it MUST always return 'false' in the future.*

```solidity
function isControllable() external view override returns (bool);
```

**Returns**

| Name     | Type   | Description                                                                                 |
| -------- | ------ | ------------------------------------------------------------------------------------------- |
| `<none>` | `bool` | bool 'true' if the token can still be controlled by operators, 'false' if it can't anymore. |

#### authorizeOperator

*Set a third party operator address as an operator of 'msg.sender' to transfer and redeem tokens on its behalf.*

```solidity
function authorizeOperator(address operator) external override;
```

**Parameters**

| Name       | Type      | Description                                     |
| ---------- | --------- | ----------------------------------------------- |
| `operator` | `address` | Address to set as an operator for 'msg.sender'. |

#### revokeOperator

*Remove the right of the operator address to be an operator for 'msg.sender' and to transfer and redeem tokens on its behalf.*

```solidity
function revokeOperator(address operator) external override;
```

**Parameters**

| Name       | Type      | Description                                         |
| ---------- | --------- | --------------------------------------------------- |
| `operator` | `address` | Address to rescind as an operator for 'msg.sender'. |

#### authorizeOperatorByPartition

*Set 'operator' as an operator for 'msg.sender' for a given partition.*

```solidity
function authorizeOperatorByPartition(bytes32 partition, address operator) external override;
```

**Parameters**

| Name        | Type      | Description                                     |
| ----------- | --------- | ----------------------------------------------- |
| `partition` | `bytes32` | Name of the partition.                          |
| `operator`  | `address` | Address to set as an operator for 'msg.sender'. |

#### revokeOperatorByPartition

*Remove the right of the operator address to be an operator on a given partition for 'msg.sender' and to transfer and redeem tokens on its behalf.*

```solidity
function revokeOperatorByPartition(bytes32 partition, address operator) external override;
```

**Parameters**

| Name        | Type      | Description                                                            |
| ----------- | --------- | ---------------------------------------------------------------------- |
| `partition` | `bytes32` | Name of the partition.                                                 |
| `operator`  | `address` | Address to rescind as an operator on given partition for 'msg.sender'. |

#### isOperator

*Indicate whether the operator address is an operator of the tokenHolder address.*

```solidity
function isOperator(address operator, address tokenHolder) external view override returns (bool);
```

**Parameters**

| Name          | Type      | Description                                                                   |
| ------------- | --------- | ----------------------------------------------------------------------------- |
| `operator`    | `address` | Address which may be an operator of tokenHolder.                              |
| `tokenHolder` | `address` | Address of a token holder which may have the operator address as an operator. |

**Returns**

| Name     | Type   | Description                                                               |
| -------- | ------ | ------------------------------------------------------------------------- |
| `<none>` | `bool` | 'true' if operator is an operator of 'tokenHolder' and 'false' otherwise. |

#### isOperatorForPartition

*Indicate whether the operator address is an operator of the tokenHolder address for the given partition.*

```solidity
function isOperatorForPartition(bytes32 partition, address operator, address tokenHolder)
    external
    view
    override
    returns (bool);
```

**Parameters**

| Name          | Type      | Description                                                                                           |
| ------------- | --------- | ----------------------------------------------------------------------------------------------------- |
| `partition`   | `bytes32` | Name of the partition.                                                                                |
| `operator`    | `address` | Address which may be an operator of tokenHolder for the given partition.                              |
| `tokenHolder` | `address` | Address of a token holder which may have the operator address as an operator for the given partition. |

**Returns**

| Name     | Type   | Description                                                                                           |
| -------- | ------ | ----------------------------------------------------------------------------------------------------- |
| `<none>` | `bool` | 'true' if 'operator' is an operator of 'tokenHolder' for partition 'partition' and 'false' otherwise. |

#### isIssuable

*Know if new tokens can be issued in the future.*

```solidity
function isIssuable() external view override returns (bool);
```

**Returns**

| Name     | Type   | Description                                                                             |
| -------- | ------ | --------------------------------------------------------------------------------------- |
| `<none>` | `bool` | bool 'true' if tokens can still be issued by the issuer, 'false' if they can't anymore. |

#### issue

*Issue tokens from default partition.*

```solidity
function issue(address tokenHolder, uint256 value, bytes calldata data) external override onlyMinter isIssuableToken;
```

**Parameters**

| Name          | Type      | Description                                          |
| ------------- | --------- | ---------------------------------------------------- |
| `tokenHolder` | `address` | Address for which we want to issue tokens.           |
| `value`       | `uint256` | Number of tokens issued.                             |
| `data`        | `bytes`   | Information attached to the issuance, by the issuer. |

#### issueByPartition

*Issue tokens from a specific partition.*

```solidity
function issueByPartition(bytes32 partition, address tokenHolder, uint256 value, bytes calldata data)
    external
    override
    onlyMinter
    isIssuableToken;
```

**Parameters**

| Name          | Type      | Description                                          |
| ------------- | --------- | ---------------------------------------------------- |
| `partition`   | `bytes32` | Name of the partition.                               |
| `tokenHolder` | `address` | Address for which we want to issue tokens.           |
| `value`       | `uint256` | Number of tokens issued.                             |
| `data`        | `bytes`   | Information attached to the issuance, by the issuer. |

#### redeem

*Redeem the amount of tokens from the address 'msg.sender'.*

```solidity
function redeem(uint256 value, bytes calldata data) external override;
```

**Parameters**

| Name    | Type      | Description                                                  |
| ------- | --------- | ------------------------------------------------------------ |
| `value` | `uint256` | Number of tokens to redeem.                                  |
| `data`  | `bytes`   | Information attached to the redemption, by the token holder. |

#### redeemFrom

*Redeem the amount of tokens on behalf of the address from.*

```solidity
function redeemFrom(address from, uint256 value, bytes calldata data) external virtual override;
```

**Parameters**

| Name    | Type      | Description                                                                           |
| ------- | --------- | ------------------------------------------------------------------------------------- |
| `from`  | `address` | Token holder whose tokens will be redeemed (or address(0) to set from to msg.sender). |
| `value` | `uint256` | Number of tokens to redeem.                                                           |
| `data`  | `bytes`   | Information attached to the redemption.                                               |

#### redeemByPartition

*Redeem tokens of a specific partition.*

```solidity
function redeemByPartition(bytes32 partition, uint256 value, bytes calldata data) external override;
```

**Parameters**

| Name        | Type      | Description                                              |
| ----------- | --------- | -------------------------------------------------------- |
| `partition` | `bytes32` | Name of the partition.                                   |
| `value`     | `uint256` | Number of tokens redeemed.                               |
| `data`      | `bytes`   | Information attached to the redemption, by the redeemer. |

#### operatorRedeemByPartition

*Redeem tokens of a specific partition.*

```solidity
function operatorRedeemByPartition(bytes32 partition, address tokenHolder, uint256 value, bytes calldata operatorData)
    external
    override;
```

**Parameters**

| Name           | Type      | Description                                              |
| -------------- | --------- | -------------------------------------------------------- |
| `partition`    | `bytes32` | Name of the partition.                                   |
| `tokenHolder`  | `address` | Address for which we want to redeem tokens.              |
| `value`        | `uint256` | Number of tokens redeemed                                |
| `operatorData` | `bytes`   | Information attached to the redemption, by the operator. |

#### name

*Get the name of the token, e.g., "MyToken".*

```solidity
function name() external view returns (string memory);
```

**Returns**

| Name     | Type     | Description        |
| -------- | -------- | ------------------ |
| `<none>` | `string` | Name of the token. |

#### symbol

*Get the symbol of the token, e.g., "MYT".*

```solidity
function symbol() external view returns (string memory);
```

**Returns**

| Name     | Type     | Description          |
| -------- | -------- | -------------------- |
| `<none>` | `string` | Symbol of the token. |

#### decimals

*Get the number of decimals of the token.*

```solidity
function decimals() external pure returns (uint8);
```

**Returns**

| Name     | Type    | Description                                                                                        |
| -------- | ------- | -------------------------------------------------------------------------------------------------- |
| `<none>` | `uint8` | The number of decimals of the token. For retrocompatibility, decimals are forced to 18 in ERC1400. |

#### granularity

*Get the smallest part of the token that’s not divisible.*

```solidity
function granularity() external view returns (uint256);
```

**Returns**

| Name     | Type      | Description                                   |
| -------- | --------- | --------------------------------------------- |
| `<none>` | `uint256` | The smallest non-divisible part of the token. |

#### totalPartitions

*Get list of existing partitions.*

```solidity
function totalPartitions() external view returns (bytes32[] memory);
```

**Returns**

| Name     | Type        | Description                        |
| -------- | ----------- | ---------------------------------- |
| `<none>` | `bytes32[]` | Array of all exisiting partitions. |

#### totalSupplyByPartition

*Get the total number of issued tokens for a given partition.*

```solidity
function totalSupplyByPartition(bytes32 partition) external view returns (uint256);
```

**Parameters**

| Name        | Type      | Description            |
| ----------- | --------- | ---------------------- |
| `partition` | `bytes32` | Name of the partition. |

**Returns**

| Name     | Type      | Description                                                             |
| -------- | --------- | ----------------------------------------------------------------------- |
| `<none>` | `uint256` | Total supply of tokens currently in circulation, for a given partition. |

#### renounceControl

*Definitely renounce the possibility to control tokens on behalf of tokenHolders. Once set to false, '\_isControllable' can never be set to 'true' again.*

```solidity
function renounceControl() external onlyOwner;
```

#### renounceIssuance

*Definitely renounce the possibility to issue new tokens. Once set to false, '\_isIssuable' can never be set to 'true' again.*

```solidity
function renounceIssuance() external onlyOwner;
```

#### controllers

*Get the list of controllers as defined by the token contract.*

```solidity
function controllers() external view returns (address[] memory);
```

**Returns**

| Name     | Type        | Description                               |
| -------- | ----------- | ----------------------------------------- |
| `<none>` | `address[]` | List of addresses of all the controllers. |

#### controllersByPartition

*Get controllers for a given partition.*

```solidity
function controllersByPartition(bytes32 partition) external view returns (address[] memory);
```

**Parameters**

| Name        | Type      | Description            |
| ----------- | --------- | ---------------------- |
| `partition` | `bytes32` | Name of the partition. |

**Returns**

| Name     | Type        | Description                         |
| -------- | ----------- | ----------------------------------- |
| `<none>` | `address[]` | Array of controllers for partition. |

#### setControllers

*Set list of token controllers.*

```solidity
function setControllers(address[] calldata operators) external onlyOwner;
```

**Parameters**

| Name        | Type        | Description           |
| ----------- | ----------- | --------------------- |
| `operators` | `address[]` | Controller addresses. |

#### setPartitionControllers

*Set list of token partition controllers.*

```solidity
function setPartitionControllers(bytes32 partition, address[] calldata operators) external onlyOwner;
```

**Parameters**

| Name        | Type        | Description            |
| ----------- | ----------- | ---------------------- |
| `partition` | `bytes32`   | Name of the partition. |
| `operators` | `address[]` | Controller addresses.  |

#### getDefaultPartitions

*Get default partitions to transfer from. Function used for ERC20 retrocompatibility. For example, a security token may return the bytes32("unrestricted").*

```solidity
function getDefaultPartitions() external view returns (bytes32[] memory);
```

**Returns**

| Name     | Type        | Description                  |
| -------- | ----------- | ---------------------------- |
| `<none>` | `bytes32[]` | Array of default partitions. |

#### setDefaultPartitions

*Set default partitions to transfer from. Function used for ERC20 retrocompatibility.*

```solidity
function setDefaultPartitions(bytes32[] calldata partitions) external onlyOwner;
```

**Parameters**

| Name         | Type        | Description                                      |
| ------------ | ----------- | ------------------------------------------------ |
| `partitions` | `bytes32[]` | partitions to use by default when not specified. |

#### allowanceByPartition

*Check the value of tokens that an owner allowed to a spender.*

```solidity
function allowanceByPartition(bytes32 partition, address owner, address spender)
    external
    view
    override
    returns (uint256);
```

**Parameters**

| Name        | Type      | Description                                     |
| ----------- | --------- | ----------------------------------------------- |
| `partition` | `bytes32` | Name of the partition.                          |
| `owner`     | `address` | address The address which owns the funds.       |
| `spender`   | `address` | address The address which will spend the funds. |

**Returns**

| Name     | Type      | Description                                                               |
| -------- | --------- | ------------------------------------------------------------------------- |
| `<none>` | `uint256` | A uint256 specifying the value of tokens still available for the spender. |

#### approveByPartition

*Approve the passed address to spend the specified amount of tokens on behalf of 'msg.sender'.*

```solidity
function approveByPartition(bytes32 partition, address spender, uint256 value) external returns (bool);
```

**Parameters**

| Name        | Type      | Description                             |
| ----------- | --------- | --------------------------------------- |
| `partition` | `bytes32` | Name of the partition.                  |
| `spender`   | `address` | The address which will spend the funds. |
| `value`     | `uint256` | The amount of tokens to be spent.       |

**Returns**

| Name     | Type   | Description                                               |
| -------- | ------ | --------------------------------------------------------- |
| `<none>` | `bool` | A boolean that indicates if the operation was successful. |

#### setTokenExtension

*Set token extension contract address. The extension contract can for example verify "ERC1400TokensValidator" or "ERC1400TokensChecker" interfaces. If the extension is an "ERC1400TokensValidator", it will be called everytime a transfer is executed.*

```solidity
function setTokenExtension(
    address extension,
    string calldata interfaceLabel,
    bool removeOldExtensionRoles,
    bool addMinterRoleForExtension,
    bool addControllerRoleForExtension
) external onlyOwner;
```

**Parameters**

| Name                            | Type      | Description                                                                                     |
| ------------------------------- | --------- | ----------------------------------------------------------------------------------------------- |
| `extension`                     | `address` | Address of the extension contract.                                                              |
| `interfaceLabel`                | `string`  | Interface label of extension contract.                                                          |
| `removeOldExtensionRoles`       | `bool`    | If set to 'true', the roles of the old extension(minter, controller) will be removed extension. |
| `addMinterRoleForExtension`     | `bool`    | If set to 'true', the extension contract will be added as minter.                               |
| `addControllerRoleForExtension` | `bool`    | If set to 'true', the extension contract will be added as controller.                           |

#### migrate

\*Migrate contract. ===> CAUTION: DEFINITIVE ACTION This function shall be called once a new version of the smart contract has been created. Once this function is called:

* The address of the new smart contract is set in ERC1820 registry
* If the choice is definitive, the current smart contract is turned off and can never be used again\*

```solidity
function migrate(address newContractAddress, bool definitive) external onlyOwner;
```

**Parameters**

| Name                 | Type      | Description                                             |
| -------------------- | --------- | ------------------------------------------------------- |
| `newContractAddress` | `address` | Address of the new version of the smart contract.       |
| `definitive`         | `bool`    | If set to 'true' the contract is turned off definitely. |

#### \_transferWithData

*Perform the transfer of tokens.*

```solidity
function _transferWithData(address from, address to, uint256 value) internal isNotMigratedToken;
```

**Parameters**

| Name    | Type      | Description                   |
| ------- | --------- | ----------------------------- |
| `from`  | `address` | Token holder.                 |
| `to`    | `address` | Token recipient.              |
| `value` | `uint256` | Number of tokens to transfer. |

#### \_transferByPartition

*Transfer tokens from a specific partition.*

```solidity
function _transferByPartition(
    bytes32 fromPartition,
    address operator,
    address from,
    address to,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
) internal returns (bytes32);
```

**Parameters**

| Name            | Type      | Description                                                                    |
| --------------- | --------- | ------------------------------------------------------------------------------ |
| `fromPartition` | `bytes32` | Partition of the tokens to transfer.                                           |
| `operator`      | `address` | The address performing the transfer.                                           |
| `from`          | `address` | Token holder.                                                                  |
| `to`            | `address` | Token recipient.                                                               |
| `value`         | `uint256` | Number of tokens to transfer.                                                  |
| `data`          | `bytes`   | Information attached to the transfer. \[CAN CONTAIN THE DESTINATION PARTITION] |
| `operatorData`  | `bytes`   | Information attached to the transfer, by the operator (if any).                |

**Returns**

| Name     | Type      | Description            |
| -------- | --------- | ---------------------- |
| `<none>` | `bytes32` | Destination partition. |

#### \_transferByDefaultPartitions

*Transfer tokens from default partitions. Function used for ERC20 retrocompatibility.*

```solidity
function _transferByDefaultPartitions(address operator, address from, address to, uint256 value, bytes memory data)
    internal;
```

**Parameters**

| Name       | Type      | Description                                                                                                                |
| ---------- | --------- | -------------------------------------------------------------------------------------------------------------------------- |
| `operator` | `address` | The address performing the transfer.                                                                                       |
| `from`     | `address` | Token holder.                                                                                                              |
| `to`       | `address` | Token recipient.                                                                                                           |
| `value`    | `uint256` | Number of tokens to transfer.                                                                                              |
| `data`     | `bytes`   | Information attached to the transfer, and intended for the token holder ('from') \[CAN CONTAIN THE DESTINATION PARTITION]. |

#### \_getDestinationPartition

*Retrieve the destination partition from the 'data' field. By convention, a partition change is requested ONLY when 'data' starts with the flag: 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff When the flag is detected, the destination tranche is extracted from the 32 bytes following the flag.*

```solidity
function _getDestinationPartition(bytes32 fromPartition, bytes memory data)
    internal
    pure
    returns (bytes32 toPartition);
```

**Parameters**

| Name            | Type      | Description                                                                    |
| --------------- | --------- | ------------------------------------------------------------------------------ |
| `fromPartition` | `bytes32` | Partition of the tokens to transfer.                                           |
| `data`          | `bytes`   | Information attached to the transfer. \[CAN CONTAIN THE DESTINATION PARTITION] |

**Returns**

| Name          | Type      | Description            |
| ------------- | --------- | ---------------------- |
| `toPartition` | `bytes32` | Destination partition. |

#### \_removeTokenFromPartition

*Remove a token from a specific partition.*

```solidity
function _removeTokenFromPartition(address from, bytes32 partition, uint256 value) internal;
```

**Parameters**

| Name        | Type      | Description                   |
| ----------- | --------- | ----------------------------- |
| `from`      | `address` | Token holder.                 |
| `partition` | `bytes32` | Name of the partition.        |
| `value`     | `uint256` | Number of tokens to transfer. |

#### \_addTokenToPartition

*Add a token to a specific partition.*

```solidity
function _addTokenToPartition(address to, bytes32 partition, uint256 value) internal;
```

**Parameters**

| Name        | Type      | Description                   |
| ----------- | --------- | ----------------------------- |
| `to`        | `address` | Token recipient.              |
| `partition` | `bytes32` | Name of the partition.        |
| `value`     | `uint256` | Number of tokens to transfer. |

#### \_isMultiple

*Check if 'value' is multiple of the granularity.*

```solidity
function _isMultiple(uint256 value) internal view returns (bool);
```

**Parameters**

| Name    | Type      | Description                             |
| ------- | --------- | --------------------------------------- |
| `value` | `uint256` | The quantity that want's to be checked. |

**Returns**

| Name     | Type   | Description                                         |
| -------- | ------ | --------------------------------------------------- |
| `<none>` | `bool` | 'true' if 'value' is a multiple of the granularity. |

#### \_callSenderExtension

*Check for 'ERC1400TokensSender' user extension in ERC1820 registry and call it.*

```solidity
function _callSenderExtension(
    bytes32 partition,
    address operator,
    address from,
    address to,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
) internal;
```

**Parameters**

| Name           | Type      | Description                                                                                      |
| -------------- | --------- | ------------------------------------------------------------------------------------------------ |
| `partition`    | `bytes32` | Name of the partition (bytes32 to be left empty for transfers where partition is not specified). |
| `operator`     | `address` | Address which triggered the balance decrease (through transfer or redemption).                   |
| `from`         | `address` | Token holder.                                                                                    |
| `to`           | `address` | Token recipient for a transfer and 0x for a redemption.                                          |
| `value`        | `uint256` | Number of tokens the token holder balance is decreased by.                                       |
| `data`         | `bytes`   | Extra information.                                                                               |
| `operatorData` | `bytes`   | Extra information, attached by the operator (if any).                                            |

#### \_callTokenExtension

*Check for 'ERC1400TokensValidator' token extension in ERC1820 registry and call it.*

```solidity
function _callTokenExtension(
    bytes32 partition,
    address operator,
    address from,
    address to,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
) internal;
```

**Parameters**

| Name           | Type      | Description                                                                                      |
| -------------- | --------- | ------------------------------------------------------------------------------------------------ |
| `partition`    | `bytes32` | Name of the partition (bytes32 to be left empty for transfers where partition is not specified). |
| `operator`     | `address` | Address which triggered the balance decrease (through transfer or redemption).                   |
| `from`         | `address` | Token holder.                                                                                    |
| `to`           | `address` | Token recipient for a transfer and 0x for a redemption.                                          |
| `value`        | `uint256` | Number of tokens the token holder balance is decreased by.                                       |
| `data`         | `bytes`   | Extra information.                                                                               |
| `operatorData` | `bytes`   | Extra information, attached by the operator (if any).                                            |

#### \_callRecipientExtension

*Check for 'ERC1400TokensRecipient' user extension in ERC1820 registry and call it.*

```solidity
function _callRecipientExtension(
    bytes32 partition,
    address operator,
    address from,
    address to,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
) internal virtual;
```

**Parameters**

| Name           | Type      | Description                                                                                      |
| -------------- | --------- | ------------------------------------------------------------------------------------------------ |
| `partition`    | `bytes32` | Name of the partition (bytes32 to be left empty for transfers where partition is not specified). |
| `operator`     | `address` | Address which triggered the balance increase (through transfer or issuance).                     |
| `from`         | `address` | Token holder for a transfer and 0x for an issuance.                                              |
| `to`           | `address` | Token recipient.                                                                                 |
| `value`        | `uint256` | Number of tokens the recipient balance is increased by.                                          |
| `data`         | `bytes`   | Extra information, intended for the token holder ('from').                                       |
| `operatorData` | `bytes`   | Extra information attached by the operator (if any).                                             |

#### \_isOperator

*Indicate whether the operator address is an operator of the tokenHolder address.*

```solidity
function _isOperator(address operator, address tokenHolder) internal view returns (bool);
```

**Parameters**

| Name          | Type      | Description                                                                     |
| ------------- | --------- | ------------------------------------------------------------------------------- |
| `operator`    | `address` | Address which may be an operator of 'tokenHolder'.                              |
| `tokenHolder` | `address` | Address of a token holder which may have the 'operator' address as an operator. |

**Returns**

| Name     | Type   | Description                                                                 |
| -------- | ------ | --------------------------------------------------------------------------- |
| `<none>` | `bool` | 'true' if 'operator' is an operator of 'tokenHolder' and 'false' otherwise. |

#### \_isOperatorForPartition

*Indicate whether the operator address is an operator of the tokenHolder address for the given partition.*

```solidity
function _isOperatorForPartition(bytes32 partition, address operator, address tokenHolder)
    internal
    view
    returns (bool);
```

**Parameters**

| Name          | Type      | Description                                                                                           |
| ------------- | --------- | ----------------------------------------------------------------------------------------------------- |
| `partition`   | `bytes32` | Name of the partition.                                                                                |
| `operator`    | `address` | Address which may be an operator of tokenHolder for the given partition.                              |
| `tokenHolder` | `address` | Address of a token holder which may have the operator address as an operator for the given partition. |

**Returns**

| Name     | Type   | Description                                                                                           |
| -------- | ------ | ----------------------------------------------------------------------------------------------------- |
| `<none>` | `bool` | 'true' if 'operator' is an operator of 'tokenHolder' for partition 'partition' and 'false' otherwise. |

#### \_issue

*Perform the issuance of tokens.*

```solidity
function _issue(address operator, address to, uint256 value, bytes memory data) internal isNotMigratedToken;
```

**Parameters**

| Name       | Type      | Description                                                                |
| ---------- | --------- | -------------------------------------------------------------------------- |
| `operator` | `address` | Address which triggered the issuance.                                      |
| `to`       | `address` | Token recipient.                                                           |
| `value`    | `uint256` | Number of tokens issued.                                                   |
| `data`     | `bytes`   | Information attached to the issuance, and intended for the recipient (to). |

#### \_issueByPartition

*Issue tokens from a specific partition.*

```solidity
function _issueByPartition(bytes32 toPartition, address operator, address to, uint256 value, bytes memory data)
    internal;
```

**Parameters**

| Name          | Type      | Description                           |
| ------------- | --------- | ------------------------------------- |
| `toPartition` | `bytes32` | Name of the partition.                |
| `operator`    | `address` | The address performing the issuance.  |
| `to`          | `address` | Token recipient.                      |
| `value`       | `uint256` | Number of tokens to issue.            |
| `data`        | `bytes`   | Information attached to the issuance. |

#### \_redeem

*Perform the token redemption.*

```solidity
function _redeem(address operator, address from, uint256 value, bytes memory data) internal isNotMigratedToken;
```

**Parameters**

| Name       | Type      | Description                                 |
| ---------- | --------- | ------------------------------------------- |
| `operator` | `address` | The address performing the redemption.      |
| `from`     | `address` | Token holder whose tokens will be redeemed. |
| `value`    | `uint256` | Number of tokens to redeem.                 |
| `data`     | `bytes`   | Information attached to the redemption.     |

#### \_redeemByPartition

*Redeem tokens of a specific partition.*

```solidity
function _redeemByPartition(
    bytes32 fromPartition,
    address operator,
    address from,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
) internal;
```

**Parameters**

| Name            | Type      | Description                                                       |
| --------------- | --------- | ----------------------------------------------------------------- |
| `fromPartition` | `bytes32` | Name of the partition.                                            |
| `operator`      | `address` | The address performing the redemption.                            |
| `from`          | `address` | Token holder whose tokens will be redeemed.                       |
| `value`         | `uint256` | Number of tokens to redeem.                                       |
| `data`          | `bytes`   | Information attached to the redemption.                           |
| `operatorData`  | `bytes`   | Information attached to the redemption, by the operator (if any). |

#### \_redeemByDefaultPartitions

*Redeem tokens from a default partitions.*

```solidity
function _redeemByDefaultPartitions(address operator, address from, uint256 value, bytes memory data) internal;
```

**Parameters**

| Name       | Type      | Description                             |
| ---------- | --------- | --------------------------------------- |
| `operator` | `address` | The address performing the redeem.      |
| `from`     | `address` | Token holder.                           |
| `value`    | `uint256` | Number of tokens to redeem.             |
| `data`     | `bytes`   | Information attached to the redemption. |

#### \_canTransfer

*Know the reason on success or failure based on the EIP-1066 application-specific status codes.*

```solidity
function _canTransfer(
    bytes memory payload,
    bytes32 partition,
    address operator,
    address from,
    address to,
    uint256 value,
    bytes memory data,
    bytes memory operatorData
) internal view returns (bytes1, bytes32, bytes32);
```

**Parameters**

| Name           | Type      | Description                                                                    |
| -------------- | --------- | ------------------------------------------------------------------------------ |
| `payload`      | `bytes`   | Payload of the initial transaction.                                            |
| `partition`    | `bytes32` | Name of the partition.                                                         |
| `operator`     | `address` | The address performing the transfer.                                           |
| `from`         | `address` | Token holder.                                                                  |
| `to`           | `address` | Token recipient.                                                               |
| `value`        | `uint256` | Number of tokens to transfer.                                                  |
| `data`         | `bytes`   | Information attached to the transfer. \[CAN CONTAIN THE DESTINATION PARTITION] |
| `operatorData` | `bytes`   | Information attached to the transfer, by the operator (if any).                |

**Returns**

| Name     | Type      | Description                                                                                                                                                                                                          |
| -------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<none>` | `bytes1`  | ESC (Ethereum Status Code) following the EIP-1066 standard.                                                                                                                                                          |
| `<none>` | `bytes32` | Additional bytes32 parameter that can be used to define application specific reason codes with additional details (for example the transfer restriction rule responsible for making the transfer operation invalid). |
| `<none>` | `bytes32` | Destination partition.                                                                                                                                                                                               |

#### \_setControllers

*Set list of token controllers.*

```solidity
function _setControllers(address[] memory operators) internal;
```

**Parameters**

| Name        | Type        | Description           |
| ----------- | ----------- | --------------------- |
| `operators` | `address[]` | Controller addresses. |

#### \_setPartitionControllers

*Set list of token partition controllers.*

```solidity
function _setPartitionControllers(bytes32 partition, address[] memory operators) internal;
```

**Parameters**

| Name        | Type        | Description            |
| ----------- | ----------- | ---------------------- |
| `partition` | `bytes32`   | Name of the partition. |
| `operators` | `address[]` | Controller addresses.  |

#### \_setTokenExtension

*Set token extension contract address. The extension contract can for example verify "ERC1400TokensValidator" or "ERC1400TokensChecker" interfaces. If the extension is an "ERC1400TokensValidator", it will be called everytime a transfer is executed.*

```solidity
function _setTokenExtension(
    address extension,
    string memory interfaceLabel,
    bool removeOldExtensionRoles,
    bool addMinterRoleForExtension,
    bool addControllerRoleForExtension
) internal;
```

**Parameters**

| Name                            | Type      | Description                                                                                     |
| ------------------------------- | --------- | ----------------------------------------------------------------------------------------------- |
| `extension`                     | `address` | Address of the extension contract.                                                              |
| `interfaceLabel`                | `string`  | Interface label of extension contract.                                                          |
| `removeOldExtensionRoles`       | `bool`    | If set to 'true', the roles of the old extension(minter, controller) will be removed extension. |
| `addMinterRoleForExtension`     | `bool`    | If set to 'true', the extension contract will be added as minter.                               |
| `addControllerRoleForExtension` | `bool`    | If set to 'true', the extension contract will be added as controller.                           |

#### \_migrate

\*Migrate contract. ===> CAUTION: DEFINITIVE ACTION This function shall be called once a new version of the smart contract has been created. Once this function is called:

* The address of the new smart contract is set in ERC1820 registry
* If the choice is definitive, the current smart contract is turned off and can never be used again\*

```solidity
function _migrate(address newContractAddress, bool definitive) internal;
```

**Parameters**

| Name                 | Type      | Description                                             |
| -------------------- | --------- | ------------------------------------------------------- |
| `newContractAddress` | `address` | Address of the new version of the smart contract.       |
| `definitive`         | `bool`    | If set to 'true' the contract is turned off definitely. |

#### domainName

```solidity
function domainName() public view override returns (string memory);
```

#### domainVersion

```solidity
function domainVersion() public pure override returns (string memory);
```

### Events

#### ApprovalByPartition

```solidity
event ApprovalByPartition(bytes32 indexed partition, address indexed owner, address indexed spender, uint256 value);
```
