ERC1155TL

Git Source

Inherits: ERC1155Upgradeable, EIP2981TLUpgradeable, OwnableAccessControlUpgradeable, ICreatorBase, IERC1155TL, IStory

Author: transientlabs.xyz

Sovereign ERC-1155 Creator Contract with Story Inscriptions

State Variables

VERSION

String representation for address

string public constant VERSION = "3.0.1";

ADMIN_ROLE

bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

APPROVED_MINT_CONTRACT

bytes32 public constant APPROVED_MINT_CONTRACT = keccak256("APPROVED_MINT_CONTRACT");

_counter

uint256 private _counter;

name

string public name;

symbol

string public symbol;

storyEnabled

bool public storyEnabled;

blocklistRegistry

IBlockListRegistry public blocklistRegistry;

_tokens

mapping(uint256 => Token) private _tokens;

Functions

constructor

constructor(bool disable);

Parameters

NameTypeDescription
disableboolBoolean to disable initialization for the implementation contract

initialize

tx.origin is used in the events here as these can be deployed via contract factories and we want to capture the true sender

function initialize(
    string memory name_,
    string memory symbol_,
    string memory personalization,
    address defaultRoyaltyRecipient,
    uint256 defaultRoyaltyPercentage,
    address initOwner,
    address[] memory admins,
    bool enableStory,
    address initBlockListRegistry
) external initializer;

Parameters

NameTypeDescription
name_stringThe name of the 721 contract
symbol_stringThe symbol of the 721 contract
personalizationstringA string to emit as a collection story. Can be ASCII art or something else that is a personalization of the contract.
defaultRoyaltyRecipientaddressThe default address for royalty payments
defaultRoyaltyPercentageuint256The default royalty percentage of basis points (out of 10,000)
initOwneraddressThe owner of the contract
adminsaddress[]Array of admin addresses to add to the contract
enableStoryboolA bool deciding whether to add story fuctionality or not
initBlockListRegistryaddressAddress of the blocklist registry to use

totalSupply

Function to get total supply minted so far

function totalSupply() external view returns (uint256);

getTokenDetails

Function to get token creation details

function getTokenDetails(uint256 tokenId) external view returns (Token memory);

Parameters

NameTypeDescription
tokenIduint256The token to lookup

setApprovedMintContracts

Function to set approved mint contracts

Access to owner or admin

function setApprovedMintContracts(address[] calldata minters, bool status) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
mintersaddress[]Array of minters to grant approval to
statusboolStatus for the minters

createToken

Function to create a token that can be minted to creator or airdropped

Requires owner or admin

function createToken(string calldata newUri, address[] calldata addresses, uint256[] calldata amounts)
    external
    onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
newUristringThe uri for the token to create
addressesaddress[]The addresses to mint the new token to
amountsuint256[]The amount of the new token to mint to each address

createToken

Function to create a token that can be minted to creator or airdropped

Requires owner or admin

function createToken(
    string calldata newUri,
    address[] calldata addresses,
    uint256[] calldata amounts,
    address royaltyAddress,
    uint256 royaltyPercent
) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
newUristringThe uri for the token to create
addressesaddress[]The addresses to mint the new token to
amountsuint256[]The amount of the new token to mint to each address
royaltyAddressaddress
royaltyPercentuint256

batchCreateToken

function to batch create tokens that can be minted to creator or airdropped

requires owner or admin

function batchCreateToken(string[] calldata newUris, address[][] calldata addresses, uint256[][] calldata amounts)
    external
    onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
newUrisstring[]the uris for the tokens to create
addressesaddress[][]2d dynamic array holding the addresses to mint the new tokens to
amountsuint256[][]2d dynamic array holding the amounts of the new tokens to mint to each address

batchCreateToken

function to batch create tokens that can be minted to creator or airdropped

requires owner or admin

function batchCreateToken(
    string[] calldata newUris,
    address[][] calldata addresses,
    uint256[][] calldata amounts,
    address[] calldata royaltyAddresses,
    uint256[] calldata royaltyPercents
) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
newUrisstring[]the uris for the tokens to create
addressesaddress[][]2d dynamic array holding the addresses to mint the new tokens to
amountsuint256[][]2d dynamic array holding the amounts of the new tokens to mint to each address
royaltyAddressesaddress[]
royaltyPercentsuint256[]

mintToken

Function to mint existing token to recipients

Requires owner or admin

function mintToken(uint256 tokenId, address[] calldata addresses, uint256[] calldata amounts)
    external
    onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
tokenIduint256The token to mint
addressesaddress[]The addresses to mint to
amountsuint256[]Amounts of the token to mint to each address

externalMint

External mint function

Requires caller to be an approved mint contract

function externalMint(uint256 tokenId, address[] calldata addresses, uint256[] calldata amounts)
    external
    onlyRole(APPROVED_MINT_CONTRACT);

Parameters

NameTypeDescription
tokenIduint256The token to mint
addressesaddress[]The addresses to mint to
amountsuint256[]Amounts of the token to mint to each address

burn

Function to burn tokens from an account

Msg.sender must be token owner or operator

function burn(address from, uint256[] calldata tokenIds, uint256[] calldata amounts) external;

Parameters

NameTypeDescription
fromaddressAddress to burn from
tokenIdsuint256[]Array of tokens to burn
amountsuint256[]Amount of each token to burn

setDefaultRoyalty

Function to set the default royalty specification

Requires owner or admin

function setDefaultRoyalty(address newRecipient, uint256 newPercentage) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
newRecipientaddressThe new royalty payout address
newPercentageuint256The new royalty percentage in basis (out of 10,000)

setTokenRoyalty

Function to override a token's royalty info

Requires owner or admin

function setTokenRoyalty(uint256 tokenId, address newRecipient, uint256 newPercentage)
    external
    onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
tokenIduint256The token to override royalty for
newRecipientaddressThe new royalty payout address for the token id
newPercentageuint256The new royalty percentage in basis (out of 10,000) for the token id

setTokenUri

Function to set a token uri

Requires owner or admin

function setTokenUri(uint256 tokenId, string calldata newUri) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
tokenIduint256The token to mint
newUristringThe new token uri

uri

function uri(uint256 tokenId) public view override(ERC1155Upgradeable) returns (string memory);

addCollectionStory

Function to let the creator add a story to the collection they have created

Depending on the implementation, this function may be restricted in various ways, such as limiting the number of times the creator may write a story.

function addCollectionStory(string calldata, string calldata story) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
<none>string
storystringThe story written and attached to the token id

addCreatorStory

Function to let the creator add a story to any token they have created

Depending on the implementation, this function may be restricted in various ways, such as limiting the number of times the creator may write a story.

function addCreatorStory(uint256 tokenId, string calldata, string calldata story)
    external
    onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
tokenIduint256The token id to which the story is attached
<none>string
storystringThe story written and attached to the token id

addStory

Function to let collectors add a story to any token they own

Depending on the implementation, this function may be restricted in various ways, such as limiting the number of times a collector may write a story.

function addStory(uint256 tokenId, string calldata, string calldata story) external;

Parameters

NameTypeDescription
tokenIduint256The token id to which the story is attached
<none>string
storystringThe story written and attached to the token id

setStoryStatus

Function to enable or disable collector story inscriptions

Requires owner or admin

function setStoryStatus(bool status) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
statusboolThe status to set for collector story inscriptions

setBlockListRegistry

Function to change the blocklist registry

Access to owner or admin

function setBlockListRegistry(address newBlockListRegistry) external onlyRoleOrOwner(ADMIN_ROLE);

Parameters

NameTypeDescription
newBlockListRegistryaddressThe new blocklist registry

setApprovalForAll

function setApprovalForAll(address operator, bool approved) public override(ERC1155Upgradeable);

tlNftDelegationRegistry

Function to get the delegation registry

function tlNftDelegationRegistry() external pure returns (ITLNftDelegationRegistry);

setNftDelegationRegistry

Function to change the TL NFT delegation registry

Access to owner or admin

function setNftDelegationRegistry(address) external pure;

Parameters

NameTypeDescription
<none>address

supportsInterface

function supportsInterface(bytes4 interfaceId)
    public
    view
    override(ERC1155Upgradeable, EIP2981TLUpgradeable)
    returns (bool);

_exists

Private helper function to verify a token exists

function _exists(uint256 tokenId) private view returns (bool);

Parameters

NameTypeDescription
tokenIduint256The token to check existence for

_createToken

Private helper function to create a new token

function _createToken(string memory newUri, address[] memory addresses, uint256[] memory amounts)
    private
    returns (uint256);

Parameters

NameTypeDescription
newUristringThe uri for the token to create
addressesaddress[]The addresses to mint the new token to
amountsuint256[]The amount of the new token to mint to each address

Returns

NameTypeDescription
<none>uint256uint256 Token id created

_mintToken

Private helper function

function _mintToken(uint256 tokenId, address[] calldata addresses, uint256[] calldata amounts) private;

Parameters

NameTypeDescription
tokenIduint256The token to mint
addressesaddress[]The addresses to mint to
amountsuint256[]Amounts of the token to mint to each address

_isOperatorBlocked

function _isOperatorBlocked(address operator) internal view returns (bool);

Errors

EmptyTokenURI

Token uri is an empty string

error EmptyTokenURI();

BatchSizeTooSmall

Batch size too small

error BatchSizeTooSmall();

MintToZeroAddresses

Mint to zero addresses

error MintToZeroAddresses();

ArrayLengthMismatch

Array length mismatch

error ArrayLengthMismatch();

CallerNotTokenOwner

Token not owned by the owner of the contract

error CallerNotTokenOwner();

CallerNotApprovedOrOwner

Caller is not approved or owner

error CallerNotApprovedOrOwner();

TokenDoesntExist

Token does not exist

error TokenDoesntExist();

BurnZeroTokens

Burning zero tokens

error BurnZeroTokens();

OperatorBlocked

Operator for token approvals blocked

error OperatorBlocked();

StoryNotEnabled

Story not enabled for collectors

error StoryNotEnabled();