Sound Protocol
Core Contracts
SoundCreatorV2

SoundCreatorV2

contracts/core/SoundCreatorV2.sol (opens in a new tab)

A factory that allows for a single transaction setup that:

  1. Clones and initializes a SoundEdition.
  2. Forwards calldata to an array of target contracts. These calldata can be used to set up the required authorizations and mint schedules.

This factory does not store the implementation address. Instead, it is provided as an argument to the function calls.

This factory allows for collectors to execute an artist-signed SoundCreation struct payload and mint in a single transaction.

Structs

SoundCreation

struct SoundCreation {
    // The address of the SoundEdition implementation.
    address implementation;
    // The initial owner of the deployed SoundEdition.
    address owner;
    // The salt used for deploying the SoundEdition via the SoundCreator factory.
    bytes32 salt;
    // The calldata passed to the SoundEdition to initialize it.
    bytes initData;
    // Array of contracts to call after initializing the SoundEdition.
    address[] contracts;
    // Array of abi encoded calldata to pass to each entry in `contracts`.
    bytes[] data;
    // The current nonce used to sign the SoundCreation struct, if required.
    // Just generate some really random number on the client side for this.
    uint256 nonce;
}

A struct containing all the data required for creating a SoundEdition and setting up all other relevant contracts.

Write Functions

create

function create(SoundCreation calldata creation)
    external
    returns (address soundEdition, bytes[] memory results)

Creates a SoundEdition and sets up all other relevant contracts.

Calling conditions:

  • The caller must be creation.owner.
Params:
creationThe SoundCreation struct.

Returns the address of the clone, and the results of calling each of the contracts.

createWithSignature

function createWithSignature(SoundCreation calldata creation, bytes calldata signature)
    external
    returns (address soundEdition, bytes[] memory results)

Creates a SoundEdition on behalf of creation.owner.

Params:
creationThe SoundCreation struct.
signatureThe signature for the SoundCreation struct, by creation.owner.

Returns the address of the clone, and the results of calling each of the contracts.

mint

function mint(
    address minter,
    bytes calldata mintData,
    address refundTo
) external payable

Calls minter with mintData.

After which, refunds any remaining ETH balance in the contract.

If minter is the zero address, the function is a no-op.

Params:
minterThe minter contract to call.
mintDataThe abi encoded calldata to the minter contract.
refundToThe address to transfer any remaining ETH in the contract after the calls.
If address(0),remaining ETH will NOT be refunded.
If address(1), remaining ETH will be refunded to msg.sender.
If anything else, remaining ETH will be refunded to refundTo.

Returns the address of the clone, and the results of calling each of the contracts.

createWithSignatureAndMint

function createWithSignatureAndMint(
    SoundCreation calldata creation,
    bytes calldata signature,
    address minter,
    bytes calldata mintData,
    address refundTo
) external payable returns (address soundEdition, bytes[] memory results)

Equivalent to calling createWithSignature, followed by mint.

Params:
creationThe SoundCreation struct.
signatureThe signature for the SoundCreation struct, by creation.owner.
minterThe minter contract to call.
mintDataThe abi encoded calldata to the minter contract.
refundToThe address to transfer any remaining ETH in the contract after the calls.
If address(0),remaining ETH will NOT be refunded.
If address(1), remaining ETH will be refunded to msg.sender.
If anything else, remaining ETH will be refunded to refundTo.

Returns the address of the clone, and the results of calling each of the contracts.

invalidateNonces

function invalidateNonces(uint256[] calldata nonces) external

Invalidates the nonces for the msg.sender.

Params:
noncesAn array of nonces.

Read-only Functions

noncesInvalidated

function noncesInvalidated(address signer, uint256[] calldata nonces) 
    external 
    view 
    returns (bool[] memory results)

Returns whether each of the nonces of signer has been invalidated.

Params:
signerThe signer of the signature.
noncesAn array of nonces.

soundEditionAddress

function soundEditionAddress(
    address by,
    bytes32 salt
) external view returns (address addr, bool exists)

Returns the deterministic address for the sound edition clone.

Params:
byThe caller of the createSoundAndMints function.
saltThe salt, generated on the client side.

isValidSignature

function isValidSignature(
    SoundCreation calldata creation,
    bytes calldata signature
) external view returns (bool isValid)

Returns if the signature for the creation struct is correctly signed, as well as the creation's nonce is still valid.

Params:
creationThe SoundCreation struct.
signatureThe signature for the SoundCreation struct.

computeDigest

function computeDigest(SoundCreation calldata creation)
    external
    view 
    returns (bytes32 digest)

Computes the EIP-712 hash of the SoundCreation struct.

Params:
creationThe SoundCreation struct.

SOUND_CREATION_TYPEHASH

function SOUND_CREATION_TYPEHASH() external view returns (bytes32)

Returns the SoundCreation struct's EIP-712 typehash.

DOMAIN_TYPEHASH

function DOMAIN_TYPEHASH() external view returns (bytes32)

Returns the EIP-712 domain typehash.

name

function name() external pure returns (string)

Returns the EIP-712 domain name.

version

function version() external pure returns (string)

Returns the EIP-712 domain version.

domainSeparator

function domainSeparator() external pure returns (string)

Returns the EIP-712 domain separator.

Events

Created

event Created(
    address indexed implementation,
    address indexed edition,
    address indexed owner,
    bytes initData,
    address[] contracts,
    bytes[] data,
    bytes[] results
)

Emitted when an edition is created.

Params:
implementationThe address of the SoundEdition implementation.
editionThe address of the deployed SoundEdition.
ownerThe address of the owner.
initDataThe calldata to initialize SoundEdition via abi.encodeWithSelector.
contractsThe list of contracts called.
dataThe list of calldata created via abi.encodeWithSelector.
resultsThe results of calling the contracts. Use abi.decode to decode them.

NoncesInvalidated

event NoncesInvalidated(address indexed signer, uint256[] nonces)

Emitted when the nonces of signer are invalidated.

Params:
signerThe signer of the nonce.
noncesThe array of invalidated nonces.

Errors

ImplementationAddressCantBeZero

error ImplementationAddressCantBeZero()

Thrown if the implementation address is zero.

ArrayLengthsMismatch

error ArrayLengthsMismatch()

Thrown if the lengths of the input arrays are not equal.

Unauthorized

error Unauthorized()

Not authorized to perform the action.

InvalidSignature

error InvalidSignature()

The signature for the SoundCreation struct is invalid. This could be caused be an invalid parameter, signer, or invalidated nonce.