<p>Check out the <a href="https://github.com/input-output-hk/plutus-apps/tree/main/plutus-use-cases/src/Plutus/Contracts/Uniswap/" rel="nofollow noreferrer">Uniswap example</a> in the <code>plutus-use-cases</code>!</p>
<p>The way it works is there is an NFT they call the &quot;Uniswap coin.&quot; In order to create new liquidity pools, that NFT needs to included in the transaction and the new pool needs to be recorded in the <code>Factory</code> datum. That validation happens <a href="https://github.com/input-output-hk/plutus/blob/5c297af98d0049202458c3cd5e99bb3567a59f40/plutus-use-cases/src/Plutus/Contracts/Uniswap/OnChain.hs#L107" rel="nofollow noreferrer">here</a>.</p>
<blockquote>
<p>A pool can only be created by a &quot;create&quot; call to the top level contract, and everytime LP tokens are minted or burned, the top level contract updates its datum.</p>
</blockquote>
<p>Luckily you don't need to update the top level datum after each pool is created. The <code>validateCreate</code> path in the SC (what you refer to as the &quot;create&quot; call) also checks that a liquidity pool is created with a <code>Poolstate</code> token <a href="https://github.com/input-output-hk/plutus/blob/5c297af98d0049202458c3cd5e99bb3567a59f40/plutus-use-cases/src/Plutus/Contracts/Uniswap/OnChain.hs#L114" rel="nofollow noreferrer">here</a>. Since we can be sure that the <code>Poolstate</code> token was created using the <code>Uniswap</code> NFT, we only need to update the <code>Pool</code> datum on the <code>Poolstate</code> token in the future.</p>
<p>Hope that helps :)</p>

CC BY-SA 4.0
2021-09-04T23:07:05.990Z
2023-01-15T11:07:57.583Z
2023-01-15T11:07:57.583Z
Mitchell Turner
<p>If I want to create one top level contract for creating a bunch of other, similar contracts, lets say a top level Uniswap contract that creates liquidity pool contracts and keeps track of the total amount of LP tokens in each of the pool scripts below it. A pool can only be created by a &quot;create&quot; call to the top level contract, and everytime LP tokens are minted or burned, the top level contract updates its datum.</p>
<p>How exactly would I go about that?</p>

<plutus><smart-contract><plutus-pioneer-program>
How do I deploy a smart contract from another smart contract?
# How do I deploy a smart contract from another smart contract?

(Asked by: username_0 on 2021-09-04)

If I want to create one top level contract for creating a bunch of other, similar contracts, lets say a top level Uniswap contract that creates liquidity pool contracts and keeps track of the total amount of LP tokens in each of the pool scripts below it. A pool can only be created by a "create" call to the top level contract, and everytime LP tokens are minted or burned, the top level contract updates its datum.

How exactly would I go about that?

**Tags:** plutus, smart-contract, plutus-pioneer-program

---

## 1 answers

### Answer by username_1 on 2021-09-04. Score: 4 | Accepted answer

Check out the [Uniswap example](https://github.com/input-output-hk/plutus-apps/tree/main/plutus-use-cases/src/Plutus/Contracts/Uniswap/) in the `plutus-use-cases`!

The way it works is there is an NFT they call the "Uniswap coin." In order to create new liquidity pools, that NFT needs to included in the transaction and the new pool needs to be recorded in the `Factory` datum. That validation happens [here](https://github.com/input-output-hk/plutus/blob/5c297af98d0049202458c3cd5e99bb3567a59f40/plutus-use-cases/src/Plutus/Contracts/Uniswap/OnChain.hs#L107).

> A pool can only be created by a "create" call to the top level contract, and everytime LP tokens are minted or burned, the top level contract updates its datum.

Luckily you don't need to update the top level datum after each pool is created. The `validateCreate` path in the SC (what you refer to as the "create" call) also checks that a liquidity pool is created with a `Poolstate` token [here](https://github.com/input-output-hk/plutus/blob/5c297af98d0049202458c3cd5e99bb3567a59f40/plutus-use-cases/src/Plutus/Contracts/Uniswap/OnChain.hs#L114). Since we can be sure that the `Poolstate` token was created using the `Uniswap` NFT, we only need to update the `Pool` datum on the `Poolstate` token in the future.

Hope that helps :)


---

