sound.xyz

Posted on Apr 05, 2023Read on Mirror.xyz

Sound Swap Technical Deep Dive

Overview

Sound Swap is a automated market maker for buying and selling NFTs via bonding curves.

Buying a NFT mints it, and increases the price of the next NFT.

Selling a NFT burns it, and decreases the price of the next NFT.

Motivation

The typical NFT drop faces several risks and limitations:

  • Artists must accurately assess demand to set appropriate prices, supply, and minting windows.

  • Prices and supply cannot adjust dynamically to market interests over time, especially after the initial sales.

  • Ownership is limited to at most a few thousand unique holders, regardless of demand after the initial sales. This limits long-term virality and community growth.

  • Overemphasis on building maximum hype at the start, which is often difficult to sustain over time.

  • Potential secondary market buyers may be hesitant to purchase from a collection with a high floor price and low volume.

Sound Swap aims to alleviate these shortcomings.

Mechanism

After the initial sales, Sound Swap allows additional NFTs to be minted on a bonding curve.

Each additional NFT minted on the bonding curve enables an additional NFT to be sold back into the bonding curve, even if the NFT has been minted during the initial sale.

Bonding Curve

Sound Swap uses a sigmoid bonding curve consisting of a quadratic region and a square root region.

The quadratic region enables the price to increase rapidly when the holder pool is small. This encourages viral growth at the early stages.

Once a certain number of NFTs are in circulation, the curve transitions to the square root region. This allows the price to increase at a slowing rate, which provides better price stability and marks the transition of an NFT into a "blue chip."

Our sigmoid curve formulation enables a flexible, gas-efficient implementation that captures a good economic feel.

Sell Price

The bonding curve equation determines the sell price.

The inflection point is where the curve switches from quadratic to square root.

The curve is continuous for the zeroth and first derivatives at the inflection point.

The linear component allows us to finetune the curve if needed in the future.

Currently, we set the inflection price to 20.5 times the base price, and the inflection point to 1500. This results in the following behavior:

  • When the bonding curve supply reaches 1000, the selling price increases to 10 times the base price.

  • When the bonding curve supply reaches 10000, the selling price increases to 100 times the base price.

Buy Price

The buy price is simply the sell price plus all the royalties.

There are 3 types of royalties:

  • Artist fee (up to 7.5%)

  • Affiliate fee (2.5%)

  • Sound platform fee (2.5%)

These are denominated in basis points (BPS), with a denominator of 10000.

Implementation

Architecture

On a high level, the Sound Protocol comprises of a Sound Creator factory that creates minimal clones of a Sound Edition contract.

There are various singleton minter contracts, such as the Merkle Drop Minter, that can be configured to mint with customizable logic on the Sound Edition contracts.

Sound Swap is implemented as a singleton contract called Sound Automated Market (SAM), which connects to the Sound Edition contracts.

When configuring a Sound Edition for Sound Swap, a bonding curve is created on the SAM contract. Each Sound Edition can only be assigned to a single bonding curve.

Gas Optimizations

Gas efficiency is crucial for Sound Protocol because it ensures that transactions are processed quickly and cost-effectively, making it more accessible for users to interact with Sound Swap and Sound Editions on the blockchain.

To achieve gas efficiency, we use the following methods:

Security

Security is paramount. Despite heavy gas optimization, we spare no effort in ensuring that the code is correct and secure. The code has undergone thorough testing, review, and auditing.

In addition to sufficient safety measures, multiple layers of extra safety guards have been implemented for redundancy, as described in the Swiss cheese model. Our goal is to ensure peace of mind for all.

  • To avoid the risk of compromised artist accounts leading to unintended supply inflation, parameters for each bonding curve cannot be adjusted after they are opened for minting.

  • Individual liquidity pool balance tracking is implemented for each bonding curve to eliminate any risk of cross-pool drainage.

  • CREATE2 address checks are added to ensure that only Sound Editions created by the Sound Creator factory can be added to SAM.

  • Additional safety guardrails such as safe casting and reentrancy guards have been added.

  • Fee basis points cannot exceed hardcoded constant limits. This is to ensure that, in the worst-case scenario where an account that can set fees is compromised, the fees will still be within reasonable limits.

  • As much as possible, high-level logic is intentionally written in plain Solidity and heavily commented to improve auditability. After all, we are only human.

User Experience

Smart contracts should be designed with user experience in mind. This includes preventing honest collectors from losing money to frontrunners, minimizing the number of transactions, and providing users with flexibility.

  • Provides frontrunning protection for buys and sells using customizable slippage, which is dynamically filled by the frontend.

  • Protects against sandwich attacks by blocking NFTs from being transferred and sold back to the bonding curve in the same block.

  • Allows minting the NFTs bought via SAM to another address, and burning NFTs sold into SAM on behalf of another address.

    Future versions of minters will enable direct minting to another address.

  • Integrates with a new, highly-efficient multicaller contract that we have developed.

    This integration enables artists to update multiple parameters on SAM and Sound Editions in a single transaction.

    Future versions of minters will include multicaller integration.

Deployment

The first version of the SAM contract is deployed at https://etherscan.io/address/0xb77A65E680Ba99BDFB530D3Cc0692Cd75b088bA1.

As SAM is intentionally designed to be non-upgradable for security reasons, Sound Editions in the future may point to a different deployment.

To find out the exact deployment for a given Sound Edition, please refer to the following function on a Sound Edition.

On the SAM contract, you can find out all the bonding curve parameters and state variables with the the following function.

Credits

Sound Swap would not have been possible without the efforts of open-source collaborators, our internal reviewers at a16z, and external auditors. We would like to extend our thanks to: