# Factory Blueprint Deployment

If our blueprint Token or Connector meets your requirements, you can deploy the token using our Factory. You may also deploy the Token or Connector contracts on all desired chains (ensure that an existing UTS Router is available on these chains). See below for more information.

## Single-Chain Deployment via UTS Factory

### UTS Token

If you want to deploy UTS Token using our blueprint, you can call the function below on UTS Factory contract:

```solidity
/**
 * @notice Deploys a new {UTSToken} using the provided deployment parameters.
 * @param deployData the {DeployTokenData} struct containing deployment parameters.
 * @dev See the {UTSERC20DataTypes.DeployTokenData} for details.
 *
 * @return success call result.
 * @return newToken a newly deployed {UTSToken} contract address.
 */
function deployToken(DeployTokenData calldata deployData)
```

Use `DeployTokenData` :

```solidity
struct DeployTokenData {
    bytes     owner;
    string    name;
    string    symbol;
    uint8     decimals;
    uint256   initialSupply;
    uint256   mintedAmountToOwner;
    bool      pureToken;
    bool      mintable;
    bool      globalBurnable;
    bool      onlyRoleBurnable;
    bool      feeModule;
    bytes     router;
    uint256[] allowedChainIds;
    ChainConfig[] chainConfigs;
    bytes32   salt;
}
```

<table><thead><tr><th width="306">Field</th><th>Meaning</th></tr></thead><tbody><tr><td><pre><code>owner
</code></pre></td><td>Address encoded here will be setted as the owner of the token</td></tr><tr><td><pre><code>name
</code></pre></td><td>The name of new token</td></tr><tr><td><pre><code>symbol
</code></pre></td><td>The symbol of new token</td></tr><tr><td><pre><code>decimals
</code></pre></td><td>The decimals of new token</td></tr><tr><td><pre><code>initialSupply
</code></pre></td><td>Token initial supply, that will be minted</td></tr><tr><td><pre><code>mintedAmountToOwner
</code></pre></td><td>Token supply, that will be minted to owner (must be less than or equal initialSupply)</td></tr><tr><td><pre><code>pureToken
</code></pre></td><td>True/false flag is token should be without any extensions (non-mintable, non-burnable, without fee, working by lock/unlock scheme). If true, other flags should be false</td></tr><tr><td><pre><code>mintable
</code></pre></td><td>True/false flag is token mintable by owner (owner can mint arbitrary token amount)</td></tr><tr><td><pre><code>globalBurnable
</code></pre></td><td>True/false flag is token burnable (everyone can burn his tokens)</td></tr><tr><td><pre><code>onlyRoleBurnable
</code></pre></td><td>True/false flag is token burnable by BURNER_ROLE role only</td></tr><tr><td><pre><code>feeModule
</code></pre></td><td>True/false flag is token will supports fee extracting for bridging(currently unsupported, should be false by default)</td></tr><tr><td><pre><code>router
</code></pre></td><td>UTSRouter address on the deployment chain</td></tr><tr><td><pre><code>allowedChainIds
</code></pre></td><td>Array of initial destination chain IDs that token binded to</td></tr><tr><td><pre><code>chainConfigs
</code></pre></td><td>Array of ChainConfig structs, initial settings</td></tr><tr><td><pre><code>salt
</code></pre></td><td>Salt to deploy new token to specified address, you can specify it, if you want specific address</td></tr></tbody></table>

{% hint style="info" %}
If `PureToken` is set to `true`, then `initialSupply` should be equal or more than `mintedAmountToOwner`.
{% endhint %}

{% hint style="info" %}
If `PureToken` is set to `false`, then `initialSupply` should be equal to `mintedAmountToOwner`
{% endhint %}

### UTS Connector

If you want to deploy UTS Connector, you should use function below:

```solidity
/**
 * @notice Deploys a new {UTSConnector} using the provided deployment parameters.
 * @param deployData the {DeployConnectorData} struct containing deployment parameters.
 * @dev See the {UTSERC20DataTypes.DeployConnectorData} for details.
 *
 * @return success call result.
 * @return newConnector a newly deployed {UTSConnector} contract address.
 */
function deployConnector(DeployConnectorData calldata deployData)
```

Using struct `DeployConnectorData`&#x20;

```solidity
struct DeployConnectorData {
    bytes     owner;
    bytes     underlyingToken;
    bool      feeModule;
    bytes     router;
    uint256[] allowedChainIds;
    ChainConfig[] chainConfigs;
    bytes32   salt;
}
```

| Field             | Meaning                                                                                                                                                                                                                                   |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `owner`           | UTSConnector owner's address, encoded in bytes                                                                                                                                                                                            |
| `underlyingToken` | Address of the ERC20 token on top of which is UTSConnector built(you can also use a placeholder address `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`, if the desired connector have to interact with network native currency, e.g. Ether) |
| `feeModule`       | True/false flag is connector will supports fee extracting for bridging(currently unsupported, should be false by default)                                                                                                                 |
| `router`          | UTSRouter address                                                                                                                                                                                                                         |
| `allowedChainIds` | Array of initial destination chain IDs that connector binded to                                                                                                                                                                           |
| `chainConfigs`    | Array of ChainConfig structs, initial settings                                                                                                                                                                                            |
| `salt`            | Provided salt to deploy new connector to specified address                                                                                                                                                                                |

Chain Config struct should be built using struct below:

```solidity
struct ChainConfig {
    bytes   peerAddress;
    uint32  minGasLimit;
    uint8   decimals;
    bool    paused;
}
```

Ensure the chain configurations are properly set up to allow all your smart contracts to communicate with each other.

| Name          | Meaning                                                                                                                                                 |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `peerAddress` | Destination peer address, that can bridge or receive tokens to/from source chain. Normally it should be address of token/connector on destination chain |
| `minGasLimit` | Minimal gas amount that can be provided as function's input and will be used at redeem function                                                         |
| `decimals`    | Destination peer token decimals                                                                                                                         |
| `paused`      | True/false flag is destination peer paused                                                                                                              |

{% hint style="info" %}
`owner`, `router` ,`chainConfigs.peerAddress`and  `underlyingToken` are addresses, but since UTS is omnichain, we designed our protocol to be ready for non evm blockchains like Solana, Ton and others. So, to pass address like data use `abi.encodePacked(address)`, on evm chains
{% endhint %}

{% hint style="info" %}
You may configure `minGasLimit` parameter to take more gas for transfer execution on destination chain if you need so. Please do your own calculations.
{% endhint %}

{% hint style="info" %}
You can set this `minGasLimit` as 0, so, minGasLimit will be set from UTSRouter. You can find more information in [estimations](https://docs.entangle.fi/universal-token-standard/developer-guides/estimations "mention")
{% endhint %}

## Cross-Chain Deployment with UTS Deployment Router

You can use our Deployment Router for cross-chain deployment, allowing you to deploy and set up the entire cluster with a single function call. To do this, simply call the function below on the `UTSDeploymentRouter`.

```solidity
/**
 * @notice Sends UTSToken and UTSConnector deployment crosschain requests via UTS protocol V1.
 * @param deployMetadata array of {DeployMetadata} structs, containing destination chain Ids and deploy parameters:
 *        dstChainId: destination chain Id
 *        isConnector: flag indicating whether is request for deploy connector(true) or token(false)
 *        params: abi.encoded {DeployTokenData} struct or abi.encoded {DeployConnectorData} struct
 * @dev See the {UTSERC20DataTypes.DeployTokenData} and {UTSERC20DataTypes.DeployConnectorData} for details.
 *
 * @param paymentToken address of the token used for payment.
 * @dev Any {paymentToken} address different from the {PAYMENT_TOKEN} is identified as a payment in native currency.
 *
 * @return paymentAmount total payment required for send deployment requests.
 * @return currentChainDeployment deployment address on the current chain (if a relevant request was provided).
 */
function sendDeployRequest(
    DeployMetadata[] calldata deployMetadata,
    address paymentToken
) external payable whenNotPaused() returns(
    uint256 paymentAmount, 
    address currentChainDeployment
)
```

To do this you need to provide deployMetadata:

| Name          | Meaning                                                                                        |
| ------------- | ---------------------------------------------------------------------------------------------- |
| `dstChainId`  | Destination chain Id (or current)                                                              |
| `isConnector` | True/false flag is specified params for deploy UTSConnector                                    |
| `params`      | encoded deployData (encoded `DeployTokenData`  struct or encoded `DeployConnectorData` struct) |

{% hint style="info" %}
If you want to pay in ERC-20 token you can do it with `PAYMENT_TOKEN` in `UTSDeploymentRouter.` You also have a possibility to pay in native.  Currently it is NGL
{% endhint %}

{% hint style="info" %}
If you want to estimate deployment fee we have functions for that reason on UTSDeploymentRouter. You can find this information in [estimations](https://docs.entangle.fi/universal-token-standard/developer-guides/estimations "mention") section
{% endhint %}

That's it, now you are ready to make your first cross-chain token transfer!
