Liquidity pool UTXO

I’m trying to understand how liquidity pool like uniswap can be implemented in plutus.

Here is my understanding:
If I want to send a swap transaction, I have to consume the latest pool state (containing the token balances owned by the pool). Does it mean in any block there can be only one transaction per pool? If two or more users are trying to consume the latest UTXO, only one transaction will be successful and other users have to change their transactions to reference the new UTXO. Is my understanding correct?

1 Like

That’s an interesting concurrency issue for this particular case… I’d also like to understand how it’s handled, or can be handled, in the general case :nerd_face:

I imagine that the pool state would be distributed among multiple UTxOs to avoid bottlenecks like this. Also, the maximum 16kB transaction size limits how much state data could be contained in a single UTxO anyway, so it seems inevitable that the state of a large liquidity pool would have to be spread among multiple UTxOs. The contract would have to be carefully designed to manage distributed state. I would hope that the Plutus state machine isn’t limited by the 16kB limit and that it already distributes state.

The swap example in the 6th Plutus Pioneers lecture involves multiple UTxOs available in a swap contract, though it is not a liquidity pool. There, the off-chain code selects the appropriate UTxO for the swap.

1 Like

Hi guys, it look like there is an example in the plutus github.

1 Like