# Interactions

The **Factory** contract enables core interactions such as deploying protocols, creating markets, and retrieving protocol-related data. Key functionalities include deploying protocol instances, initializing markets, and querying metadata.

Below are some main methods. Additional methods are documented in the sections that follow

* **deployProtocol:** Deploys a new protocol instance, assigning an initial governor and configuring ownership shares.
* **deployMarket:** Deploys a new market under an existing protocol and connects it to the protocol’s risk engine.
* **getProtocolInfo:** Retrieves detailed information about a specific protocol using its unique ID.
* **getMarket:** Fetches the address of a market within a specific protocol using its protocol ID and market index.

#### **deployProtocol**

The function is called by protocol owner governance to deploy a new protocol

```solidity
function deployProtocol(address initialGovernor, address emergencyExecutor, uint256 ownerShareMantissa, uint256 configuratorShareMantissa)
```

**Parameters**

| **Name**                    | **Type**  | **Description**                                                                                   |
| --------------------------- | --------- | ------------------------------------------------------------------------------------------------- |
| `initialGovernor`           | `address` | Address of initial governor that will manage the governor timelock and risk engine configurations |
| `emergencyExecutor`         | `address` | Address of timelock executor that can manage emergency executions                                 |
| `ownerShareMantissa`        | `uint256` | Percentage of accumulated fees allocated to protocol owner (scaled by 1e18)                       |
| `configuratorShareMantissa` | `uint256` | Percentage of accumulated fees allocated to governor (scaled by 1e18)                             |

#### **deployMarket**

Deploys a new pToken for the deployed protocol and connects it to the protocol risk engine

```solidity
function deployMarket(PTokenSetup memory setupParams)
    external
    nonReentrant
    returns (address pToken);
```

**Parameters**

| **Name**      | **Type**      | **Description**                            |
| ------------- | ------------- | ------------------------------------------ |
| `setupParams` | `PTokenSetup` | struct with initial risk params of pToken: |

`PTokenSetup` contains params:

* **protocol Id**: The unique identifier for the deployed protocol that the governor timelock has access to.
* **underlying**: The address of the ERC20 underlying token.
* **initialExchangeRateMantissa**: The initial exchange rate scaled by 1e18.
* **reserveFactorMantissa**: The reserve factor as a percentage scaled by 1e18. (part of it split between owner and governor).
* **protocolSeizeShareMantissa**: The protocol’s share of seized collateral in the liquidation process scaled by 1e18 (part of it split between owner and governor).
* **borrowRateMaxMantissa**: The maximum borrow rate scaled by 1e18.
* **name**: The name of the pToken. (pike usdc)
* **symbol**: The symbol of the pToken. (pUSDC)
* **decimals**: The number of decimals for the pToken.

**Returns**

| **Name** | **Type**  | **Description**                    |
| -------- | --------- | ---------------------------------- |
| `pToken` | `address` | address of deployed proxy contract |

#### **getProtocolInfo**

Fetches the information of a protocol by its ID.

```solidity
function getProtocolInfo(uint256 protocolId)
    external
    view
    returns (ProtocolInfo memory);
```

**Parameters**

| **Name**     | **Type**  | **Description**         |
| ------------ | --------- | ----------------------- |
| `protocolId` | `uint256` | The ID of the protocol. |

**Returns**

| **Name**     | **Type** | **Description**   |
| ------------ | -------- | ----------------- |
| ProtocolInfo | `memory` | The protocol Info |

`ProtocolInfo` contains:

* protocol Id
* number of deployed markets (pTokens)
* address of assigned protocol owner
* address of assigned initial governor
* address of assigned emergencyExecutor
* address of risk engine
* address of oracle engine
* address of timelock contract

#### **getMarket**

Fetches the address of a market (pToken) by protocol ID and index.

```solidity
function getMarket(uint256 protocolId, uint256 index) external view returns (address);
```

**Parameters**

| **Name**     | **Type**  | **Description**                              |
| ------------ | --------- | -------------------------------------------- |
| `protocolId` | `uint256` | The ID of the protocol.                      |
| `index`      | `uint256` | The index of deployed pToken starting from 0 |

**Returns**

| **Name** | **Type**  | **Description**                      |
| -------- | --------- | ------------------------------------ |
| `none`   | `address` | The address of the specified market. |

#### upgradeTo

Allows the proxy to be upgraded to a new implementation.

```solidity

function upgradeTo(address newImplementation) external;

```

**Parameters**

| Name                | Type      | Description                                    |
| ------------------- | --------- | ---------------------------------------------- |
| `newImplementation` | `address` | The address of the proxy's new implementation. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pike.finance/developer-docs/smart-contracts/factory/interactions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
