ERC721LazyMint

ERC721LazyMint

Git Source

Inherits: ERC721Base, EIP712

Author: cosimo.demedici.eth *

Self-sovereign ERC-721 minter preset *

*{ERC721} token **

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;

Functions

constructor

Constructs the contract and sets the factory address.

Parameters

Name
Type
Description

factory_

address

The address of the factory contract.

lazyMint

Mints a new token.

Ensures that signer has MINTER_ROLE and that tokenIds are incremented sequentially.

Parameters

Name
Type
Description

_voucher

EncodeType.TokenVoucher

voucher struct containing the tokenId metadata.

_signature

bytes

The signature of the voucher.

_data

bytes

_data bytes are passed to onErc1155Received function if the _to address is a contract, for example a marketplace. onErc1155Received is not being called on the minter's address when a new tokenId is minted however, even if it was contract.

_to

address

buyer, needed if using a external payment gateway, so that the minted tokenId value is sent to the address specified insead of msg.sender

lazyBuy

Buys a token.

ensuring that signer has MINTER_ROLE and that tokenIds are incremented sequentially

trying to replay the same voucher and signature will revert as the tokenURI will be the same, i.e. no need to void vouchers

_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.

Handles payment and transfers the token to the buyer.

Parameters

Name
Type
Description

_voucher

EncodeType.TokenVoucher

The voucher struct containing the tokenId metadata.

_signature

bytes

The signature of the voucher.

_data

bytes

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

_to

address

The address to receive the bought token.

_handlePayment

_handlePayment outside of if statement as it contains require statements that should be executed regardless of price. voucher.price is checked again inside _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, setting the initial state and granting roles.

Grants DEFAULT_ADMIN_ROLE, CURATOR_ROLE and MINTER_ROLE to the account that deploys the contract.

Parameters

Name
Type
Description

_data

bytes

The initialization data. It MUST be encoded in the following way: (symbol, deployer, defaultRoyaltyBps, name) = abi.decode(_data, (string, address, uint96, string));. The string name is passed to the overridden initialize function as data bytes.

name

required solidity override for EIP712

Returns

Name
Type
Description

<none>

string

The name of the token.

Last updated