As we gear up for public launch of the new sudoswap marketplace, we're open-sourcing the NFT AMM smart contract code that powers everything behind the scenes.
From a high-level overview, LPs create pools that hold NFTs or tokens, and traders can swap with those pools.
We use a modified minimal proxy pattern for low gas overhead. Deploying a new pool costs ~180k gas, excluding the gas for NFT transfers. Additionally, pre-existing pools can be reused for the same collection.
For pool pricing, we use a flexible bonding curve interface. Though we're launching with just a linear and exponential curve, the interface allows for a wide range of curves that can be stateful, including gradual dutch auction style curves and inventory-aware pricing.
Swaps are designed to be low gas even in the case where only 1 NFT is being transferred, with additional efficiency gains when buying/selling multiple NFTs at a time.
Contracts and tests on GitHub here, licensed under AGPL v3: