ERC1155LazyMint

ERC1155LazyMint

Git Source

Inherits: ERC1155Base, EIP712

Author: cosimo.demedici.eth *

Self-sovereign ERC-1155 minter & lazy minter preset *

State Variables

_VOUCHER_TYPEHASH

for verifying EOA signatures, i.e. recover(bytes32 _digest, bytes memory _signature)

for sending value to an address, i.e. sendValue(address _receiver, uint256 _amount)

for verifying EIP-1271 signatures, i.e. isValidSignatureNow(address _signer, bytes32 _hash, bytes memory _signature)

keccak256("EncodeType.TokenVoucher(bytes32 tokenURI,uint256 price,uint256 endTime,uint256 tokenId,uint256 ERC1155Value,uint256 salt,address buyer,address ERC1271Account,address royaltyRecipient,uint96 royaltyBps,uint96[] commissionBps,address[] commissionRecipients)");

bytes32 private constant _VOUCHER_TYPEHASH = 0x42496782cf3e7555d82117811afa0bdaee1320050e381001920fcb0da51bd83e;

_salesCounter

Keeps track of the sales counter for each byte signature.

mapping(bytes => uint256) private _salesCounter;

_mintedURI

Keeps track of the minted URIs. Each URI is mapped to a boolean indicating whether it has been minted.

Functions

lazyMint

Mints new tokens or increases the supply of existing ones.

Parameters

Name
Type
Description

_voucher

EncodeType.TokenVoucher

The voucher struct containing the tokenId metadata.

_signature

bytes

The signature bytes.

_data

bytes

The data bytes are passed to onErc1155Received function if the _to address is a contract, for example a marketplace.

_to

address

The buyer's address. Needed if using an external payment gateway, so that the minted tokenId value is sent to this address instead of msg.sender.

_value

uint256

The amount/supply of tokenId to be minted. A max supply limit must be handled at the contract level.

_tokenId

uint256

The tokenId to mint.

lazyBuy

since signer is the minter/artist as enforced by roles, and since the minter will not sell their own tokens via lazyBuy, it is not possible to replay the signature, i.e. to use a signed voucher meant for lazyBuy in order to mint.

ensuring that signer has MINTER_ROLE and that tokenIds are incremented sequentially

since signer is artist as enforced by roles, and since the minter will not sell their own tokens via lazyBuy, it is not possible to replay the signature, i.e. to use a signed voucher meant for lazyBuy

_voucher.tokenURI is prepended to the _data bytes, since it is bytes32 id doesn't need to be padded hence encodePacked is used.

since the new token is being minted to the signer, there is no risk of reentrancy due to untrusted external contracts.

placing this require statement after _mint saves gas as _value is added to the totalSupply

it is not a reentrancy issue because the current total supply is checked which is updated for each mint.

Buys tokens lazily.

Parameters

Name
Type
Description

_voucher

EncodeType.TokenVoucher

The voucher struct containing the tokenId metadata.

_signature

bytes

The signature bytes.

_data

bytes

The data bytes.

_to

address

The buyer's address.

_value

uint256

The amount of tokens to buy.

_handlePayment

lazyMint allows the owner of the voucher to mint or sell a token, the derived contract implements the logic for either minting or transfering a token after _handlePayment is called, and any additional logic needed for the specific use case such as payments, royalties, etc.

getTypedDataDigest

it is not necessary to check if bps and recipients arrays are the same length, since the voucher is signed by the artist. if they were different lengths by mistake, the tx would either revert with index out of bounds, or if (_voucher.commissionBps.length < _voucher.commissionRecipients.length), the loop would not revert but any additional address in _voucher.commissionRecipients would be ignored.

returns hashStruct(s : π•Š) = keccak256(typeHash β€– encodeData(s)) where typeHash = keccak256(encodeType(typeOf(s)))

initialize

Initializes the contract.

Parameters

Name
Type
Description

_data

bytes

The initialization data.

constructor

Creates DOMAIN_SEPARATOR and VOUCHER_TYPEHASH and assigns address to FACTORY.

Parameters

Name
Type
Description

factory_

address

The factory address is used for access control on self-sovereign ERC-1155 collection rather than using the initializer modifier. This is cheaper because the clones won't need to write initialized = true; to storage each time they are initialized. Instead FACTORY is only assigned once in the constructor of the master copy therefore it can be read by all clones.

name

Overrides the name function.

Returns

Name
Type
Description

<none>

string

The name of the token.

Last updated