# Factory

Factory is the implementation of DEX-as-a-service way to use DEX pool. Factory is used for deploying new DEX pools as separate contracts for some fee in QUIPU tokens. Also factory contract store and manage developer config from [Developer module](/smart-contracts/quipuswap-stable-swap-dex/developer-module.md). Also `developer` represents **admin** of factory contract.

### Storage

Factory storage contains init lambda, DEX contract lambdas, configuration of deploy price and burn rate, whitelist, and mapping of deployed pools.

{% content-ref url="/pages/cc9PUoaCACLib0UoIvDb" %}
[Storage and types overview](/smart-contracts/quipuswap-stable-swap-dex/factory/storage-and-types-overview.md)
{% endcontent-ref %}

### Initialization of factory

Factory should store many methods, so some of that stored in lambdas inside storage. These lambdas should be set **before** usage of the contract.&#x20;

{% hint style="warning" %}
This section called only by `developer` address.
{% endhint %}

{% content-ref url="/pages/8Se1NJsiqg3vF85IYgos" %}
[Initial setup](/smart-contracts/quipuswap-stable-swap-dex/factory/initial-setup.md)
{% endcontent-ref %}

### Call deploy of DEX

Initialization of new DEX separated into 2 stages because of gas transaction limits.&#x20;

The first stage deploys the contract and all lambdas except `dex_lambdas` (the heaviest lambdas by size) and charges QUIPU tokens but the contract has not started yet (frozen).&#x20;

The second stage should be called by caller address of the first stage and performs set of DEX lambdas to deployed DEX, unfreezes the contract, and call invest (as initial invest) of underlying tokens.

{% content-ref url="/pages/w9gpnHIA7Wj5mJmIcCcV" %}
[Initialize new DEX flow](/smart-contracts/quipuswap-stable-swap-dex/factory/initialize-new-dex-flow.md)
{% endcontent-ref %}

### Deployed DEX

The link below describes the usage of deployed DEX contract and its storage.

{% content-ref url="/pages/B6Ce4Q1RCPeETBZL598h" %}
[Deployed from factory DEX](/smart-contracts/quipuswap-stable-swap-dex/factory/deployed-from-factory-dex.md)
{% endcontent-ref %}

### Developer-only (admin) methods

As a developer, you could manage the dev fee rate, set the deploy price, and its burn percent. Also, the developer could add and remove addresses to the whitelist (for deploying new pools without charging QUIPU).

{% content-ref url="/pages/gh2lVW1PZHAsc2lmHWIK" %}
[Developer methods](/smart-contracts/quipuswap-stable-swap-dex/factory/developer-methods.md)
{% endcontent-ref %}


---

# 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.quipuswap.com/smart-contracts/quipuswap-stable-swap-dex/factory.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.
