4

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?

3

Check out the Uniswap example 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.

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. 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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.