> For the complete documentation index, see [llms.txt](https://docs.t-rex.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.t-rex.network/reference/token-suite/trexfactory.md).

# TREXFactory

`TREXFactory` deploys a complete token suite in one transaction: the token, its registry, its identity storage, its compliance and, unless one is supplied, its access manager. Every contract is a beacon proxy at a CREATE3 address derived from a salt. The concepts are in [Deterministic deployment (CREATE3)](/governance-and-infrastructure/deterministic-deployment-create3.md) and the operation in [01 Deploy a token suite](/guides/issuer/01.-deploy-a-token-suite.md).

### At a glance

|                          |                                                                                                                                                                         |
| ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Source**               | `contracts/factory/TREXFactory.sol`                                                                                                                                     |
| **Interface**            | `ITREXFactory`                                                                                                                                                          |
| **Deployed as**          | One contract per network, not upgradeable. Built with the implementation authority, the `IdentityFactory`, the `TrustedGatewayRegistry` and the platform access manager |
| **Roles**                | Platform roles: `ASSET_DEPLOYER` to deploy suites, `OWNER` for the three setters                                                                                        |
| **Limits at deployment** | 5 required claim topics, 5 trusted issuers, 25 compliance modules                                                                                                       |

### Deploy a suite

| Function                                                    | Access           | What it deploys                                                                                                                              |
| ----------------------------------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `deployTREXSuite(salt, tokenDetails, claimDetails)`         | `ASSET_DEPLOYER` | A suite behind the shared beacons of the implementation authority. It follows the versions the network publishes                             |
| `deployTREXSuiteIsolated(salt, tokenDetails, claimDetails)` | `ASSET_DEPLOYER` | A suite behind its own beacons, cloned from the active implementations. Later `publish` and `upgrade` calls on the authority do not reach it |

#### `TokenDetails`

| Field                | Type        | Content                                                                                                                                                                                                                                    |
| -------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `name`, `symbol`     | `string`    | Not empty                                                                                                                                                                                                                                  |
| `decimals`           | `uint8`     | 0 to 18                                                                                                                                                                                                                                    |
| `irs`                | `address`   | An existing `IdentityRegistryStorage` to reuse, or zero for a new one. A supplied storage must answer to the suite's access manager. The factory does not bind the new registry to it: the Issuer does. Must be zero for an isolated suite |
| `ONCHAINID`          | `address`   | The ONCHAINID of the token, or zero to have the factory create one of type `ASSET` through the `IdentityFactory`                                                                                                                           |
| `complianceModules`  | `address[]` | The modules to bind to the compliance                                                                                                                                                                                                      |
| `complianceSettings` | `bytes[]`   | One setting call per module, by index. Modules without a setting go at the end of `complianceModules`                                                                                                                                      |
| `accessManager`      | `address`   | An existing access manager, or zero to have the factory deploy a `TREXAccessManager` for the suite                                                                                                                                         |
| `accessManagerAdmin` | `address`   | The account that receives `ADMIN_ROLE` on the manager the factory deploys. Ignored when a manager is supplied                                                                                                                              |

#### `ClaimDetails`

| Field          | Type          | Content                                                 |
| -------------- | ------------- | ------------------------------------------------------- |
| `claimTopics`  | `uint256[]`   | The required claim topics                               |
| `issuers`      | `address[]`   | The trusted Claim Issuers                               |
| `issuerClaims` | `uint256[][]` | For each issuer, by index, the topics it is trusted for |

#### What a deployment does

* **With no access manager supplied.** The factory deploys a `TREXAccessManager`, creates a domain named after the token, assigns the token and its storage to it, maps every function of the suite to its role, commissions the suite and hands `ADMIN_ROLE` to `accessManagerAdmin`. The suite is operable at once.
* **With an access manager supplied.** The factory never calls it. The suite is deployed with no role wiring and is not operable until the Issuer commissions it: see [25 Commission a suite and grant roles](/guides/issuer/25.-commission-a-suite-and-grant-roles.md).
* **In both cases.** The token is left paused, with no supply. The factory emits `Deployed` for each proxy, then `TREXSuiteDeployed`, and `IsolatedSuiteDeployed` for an isolated suite.
* **Isolated suites.** The beacons of the suite contracts are owned by the suite's access manager. The beacon of an access manager the factory deploys is owned by `accessManagerAdmin`. Changing that administrator takes two steps: the `ADMIN_ROLE` inside the manager, and `transferOwnership` on that beacon.

#### Reverts

| Error                                             | Condition                                                                                       |
| ------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `TokenAlreadyDeployed`                            | The salt was already used                                                                       |
| `MaxClaimTopicsReached`, `MaxClaimIssuersReached` | More than 5 topics, more than 5 issuers                                                         |
| `MaxModulesReached`, `InvalidCompliancePattern`   | More than 25 modules, more settings than modules                                                |
| `ZeroAddress`, `InvalidAccessManagerAdmin`        | `accessManagerAdmin` is zero, the factory itself, or the address the new manager is deployed at |
| `AccessManagerNotAContract`                       | A supplied manager has no code                                                                  |
| `StorageAuthorityMismatch`                        | A supplied storage answers to another manager                                                   |
| `IsolatedSuiteCannotReuseIRS`                     | `irs` is not zero for an isolated suite                                                         |
| `TokenIdentityAlreadyBound`                       | The token address is already linked to another identity than the one supplied                   |
| The errors of each `init`                         | An empty name, decimals above 18, a duplicate topic or issuer                                   |

### Settings and reads

| Function                                                                        | Access       | Reverts with                                                                        |
| ------------------------------------------------------------------------------- | ------------ | ----------------------------------------------------------------------------------- |
| `setImplementationAuthority(implementationAuthorityAddress)`                    | `OWNER`      | `ZeroAddress`, `InvalidImplementationAuthority`. Emits `ImplementationAuthoritySet` |
| `setIdFactory(idFactoryAddress)`                                                | `OWNER`      | `ZeroAddress`. Emits `IdFactorySet`                                                 |
| `setTrustedGatewayRegistry(trustedGatewayRegistryAddress)`                      | `OWNER`      | `ZeroAddress`. Emits `TrustedGatewayRegistrySet`                                    |
| `getToken(salt)`                                                                | Anyone, read | The token deployed with a salt, or zero                                             |
| `getImplementationAuthority()`, `getIdFactory()`, `getTrustedGatewayRegistry()` | Anyone, read |                                                                                     |

A setter changes what later deployments use. It does not touch the suites already deployed.

### Events

| Event                                                                                                                                                         | Emitted when                                                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `TREXSuiteDeployed(address indexed token, address registry, address irs, address mc, string salt)`                                                            | A suite is deployed                                                                  |
| `IsolatedSuiteDeployed(address indexed token, ITREXImplementationAuthority.SuiteBeacons beacons)`                                                             | After it, for a suite with its own beacons                                           |
| `Deployed(address indexed addr)`                                                                                                                              | Each proxy the factory deploys: access manager, storage, registry, compliance, token |
| `ImplementationAuthoritySet(address implementationAuthority)`, `IdFactorySet(address idFactory)`, `TrustedGatewayRegistrySet(address trustedGatewayRegistry)` | A pointer of the factory is set, at construction too                                 |


---

# 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.t-rex.network/reference/token-suite/trexfactory.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.
