> For the complete documentation index, see [llms.txt](https://docs.shadow.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shadow.xyz/modify-contracts/how-tos/factory-contracts.md).

# Factory contracts

## What is a factory contract?

Factory contracts are a widely used pattern across DeFi in DEXs, lending pools, and yield vaults.

A factory is a contract that can deploy multiple instances of the same contract — we call these child contracts.

Generally, child contracts share the same functionality, but are typically initialized with different constructor arguments, which may alter the child contract’s runtime bytecode. Factory contracts are widely used across many protocols, including Uniswap, Compound, and Pendle – for example, there are 300K+ Uniswap V2 pools deployed by one factory contract.

Shadowing each pool contract individually would be a highly tedious and impractical process. Shadow provides powerful features that allow you to make one set of changes to a factory contract and link all of its child contracts to those changes.

## Product guide

### Identifying a factory contract

Shadow automatically detects if a contract is a factory contract, or a child contract deployed by a factory contract. On the contract page, you will:

1. See indicators that tell you:
   * That this is a factory contract
   * If the factory contract is current linked with all of its child contracts
   * The number of separately edited child contracts on your shadow fork
2. Have the ability to link the changes made on the factory contract with all of its child contracts.
   * If linked, your changes will apply to all existing children, and any new ones deployed by the factory in the future.
3. See a total count of all the child contracts deployed by this factory contract

<figure><img src="/files/Fd0lDHgUUjFHmvbmCfsC" alt=""><figcaption></figcaption></figure>

### Linking a factory contract to its child contracts

If you already have deployed changes to a factory contracts on your shadow fork, you can simply click the `Link Children` button from the factory contract page to link it with all of its children.

Once linked, any changes deployed to the factory contract will propagate to its child contracts; this includes all existing child contracts, as well as any child contracts deployed by the factory in the future.

<figure><img src="/files/gjeqeFZNlKlAdluSNx1b" alt=""><figcaption></figcaption></figure>

You can also link a factory contract to its child contracts from the Editor, while deploying changes.

<figure><img src="/files/kK4isRhP06EZW0zgoiUs" alt=""><figcaption></figcaption></figure>

## Demo

{% embed url="<https://www.veed.io/view/a547ec99-d861-4186-ba78-5953035390d3>" %}


---

# 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 dynamically by asking a question.

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

```
GET https://docs.shadow.xyz/modify-contracts/how-tos/factory-contracts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
