# Factory

The Factory is used to deploy any [PrincipalToken](https://dev.spectra.finance/technical-reference/contract-functions/principal-token) and Curve pools permissionlessly.

Factory.sol code can be [found on GitHub](https://github.com/perspectivefi/core-v2/blob/main/src/factory/Factory.sol).&#x20;

## Methods

### deployPT

```solidity
function deployPT(address _ibt, uint256 _duration) external returns (address pt)
```

Deploys the PrincipalToken contract implementation.

See also [PrincipalToken](https://dev.spectra.finance/technical-reference/contract-functions/principal-token).

<table><thead><tr><th width="231.33333333333331">Input Parameter</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td>_<code>ibt</code></td><td>address</td><td>The <a href="../principal-token#ibt">IBT</a> of the PrincipalToken to be deployed</td></tr><tr><td><code>duration</code></td><td>uint256</td><td>The duration of the pt</td></tr></tbody></table>

<table><thead><tr><th width="222.33333333333331">Return Parameter</th><th width="121">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>pt</code></td><td>address</td><td>The address of the <a href="principal-token">PrincipalToken</a> that was deployed</td></tr></tbody></table>

### deployCurvePool

```solidity
function deployCurvePool(
        address _pt
        CurvePoolParams calldata curvePoolParams
) external returns (address curvePoolAddr)
```

Deploy a curve pool for the specific `_pt` instance with the specified `curvePoolParams`

<table><thead><tr><th width="231.33333333333331">Input Parameter</th><th width="213">Type</th><th>Description</th></tr></thead><tbody><tr><td>_<code>ibt</code></td><td>address</td><td>The <a href="../principal-token#ibt">IBT</a> of the PrincipalToken to be deployed</td></tr><tr><td><code>curvePoolParams</code></td><td><a href="#curvepoolparams"><code>CurvePoolParams</code></a></td><td>The parameters of the curve pool to be deployed</td></tr></tbody></table>

<table><thead><tr><th width="222.33333333333331">Return Parameter</th><th width="121">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>curvePoolAddr</code></td><td>address</td><td>The address of the curve pool that was deployed</td></tr></tbody></table>

#### CurvePoolParams

The curve pool parameters as defined in the [curve pool documentation](https://resources.curve.fi/factory-pools/creating-a-cryptoswap-pool/#parameters) is a struct that hold the curve pool parameters.

<table><thead><tr><th width="264.3333333333333">Struct Parameter</th><th width="115">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>A</code></td><td>uint256</td><td>Amplification Parameter [4,000 to 4,000,000,000] Larger values of A make the curve better resemble a straight line in the center (when pool is near balance). Highly volatile assets should use a lower value, while assets that are closer together may be best with a higher value.</td></tr><tr><td><code>gamma</code></td><td>uint256</td><td>The gamma parameter can further adjust the shape of the curve. Default values recommend .000145 for volatile assets and .0001 for less volatile assets.</td></tr><tr><td><code>mid_fee</code></td><td>uint256</td><td>[.005% to 1%] Percentage. Fee when the pool is maximally balanced. This is the minimum fee. The fee is calculated as <code>mid_fee * f + out_fee * (10^18 - f)</code></td></tr><tr><td><code>out_fee</code></td><td>uint256</td><td>[Mid Fee to 1%] Fee when the pool is imbalanced. Must be larger than the Mid Fee and represents the maximum fee.</td></tr><tr><td><code>allowed_extra_profit</code></td><td>uint256</td><td>[0 to .01] As the pool takes profit, the allowed extra profit parameter allows for greater values. Recommended 0.000002 for volatile assets and 0.00000001 for less volatile assets.</td></tr><tr><td><code>fee_gamma</code></td><td>uint256</td><td>[0 to 1] Adjusts how fast the fee increases from Mid Fee to Out Fee. Lower values cause fees to increase faster with imbalance. Recommended value of .0023 for volatile assets and .005 for less volatile assets.</td></tr><tr><td><code>adjustment_step</code></td><td>uint256</td><td>[0 to 1] As the pool rebalances, it will must do so in units larger than the adjustment step size. Volatile assets are suggested to use larger values (0.000146), while less volatile assets do not move as frequently and may use smaller step sizes (default 0.0000055)</td></tr><tr><td><code>admin_fee</code></td><td>uint256</td><td></td></tr><tr><td><code>ma_half_time</code></td><td>uint256</td><td>[0 to 604,800] In seconds -- the price oracle uses an exponential moving average to dampen the effect of changes. This parameter adjusts the half life used.</td></tr><tr><td><code>initial_price</code></td><td>uint256</td><td>The price of coin0 with respect to coin1. This price set the initial liquidity concentration</td></tr></tbody></table>

### deployAll

```solidity
function deployAll(
        address _ibt,
        uint256 _duration,
        CurvePoolParams calldata curvePoolParams
    ) external returns (address pt, address curvePoolAddr, address lpv)
```

Deploy a [Principal Token](https://dev.spectra.finance/technical-reference/contract-functions/principal-token), a curve pool and a [LP Vault](https://dev.spectra.finance/technical-reference/contract-functions/broken-reference) associated with the PT and the deployed curve pool in a single transaction.

<table><thead><tr><th width="231.33333333333331">Input Parameter</th><th width="190">Type</th><th>Description</th></tr></thead><tbody><tr><td>_<code>ibt</code></td><td>address</td><td>The <a href="../principal-token#ibt">IBT</a> of the PrincipalToken to be deployed</td></tr><tr><td><code>_duration</code></td><td>uint256</td><td>The duration of the <a href="principal-token">PT</a> contract to deploy</td></tr><tr><td><code>curvePoolParams</code></td><td><a href="#curvepoolparams"><code>CurvePoolParam</code></a></td><td>The parameters of the curve pool to be deployed</td></tr></tbody></table>

<table><thead><tr><th width="222.33333333333331">Return Parameter</th><th width="121">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>pt</code></td><td>address</td><td>The address of the <a href="principal-token">PT</a> that was deployed</td></tr><tr><td><code>curvePoolAddr</code></td><td>address</td><td>The address of the curve pool that was deployed</td></tr><tr><td><code>lpv</code></td><td>address</td><td>The address of the LP Vault that was deployed</td></tr></tbody></table>

## View Methods

### getRegistry

```solidity
function getRegistry() external view returns (address)
```

Returns the address of [Registry](https://dev.spectra.finance/technical-reference/contract-functions/registry) contract.

### getCurveAddressProvider

```solidity
function getCurveAddressProvider() external view returns (address)
```

Returns the address of the [Curve address provider](https://curve.readthedocs.io/registry-address-provider.html).

### getCurveFactory

```solidity
function getCurveFactory() external view returns (address)
```

Returns the address of the Curve Factory.

### getInitialPrice

```solidity
function getInitialPrice(address curvePool) external view returns (uint256)
```

Return the[ initial\_price parameter](#curvepoolparams) of the `curvePool`.

### getCurveFactoryAddress

```solidity
function getCurveFactoryAddress() public view returns (address)
```

Returns the address of the associated [Curve](https://curve.fi/) Factory.

###
