TLStacks1155
Inherits: Ownable, Pausable, ReentrancyGuard, TransferHelper, SanctionsCompliance, ITLStacks1155Events, DropErrors
Author: transientlabs.xyz
Transient Labs Stacks mint contract for ERC1155TL contracts
State Variables
VERSION
string public constant VERSION = "2.3.1";
ADMIN_ROLE
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
APPROVED_MINT_CONTRACT
bytes32 public constant APPROVED_MINT_CONTRACT = keccak256("APPROVED_MINT_CONTRACT");
protocolFeeReceiver
address public protocolFeeReceiver;
protocolFee
uint256 public protocolFee;
weth
address public weth;
_drops
mapping(address => mapping(uint256 => Drop)) internal _drops;
_numberMinted
mapping(address => mapping(uint256 => mapping(uint256 => mapping(address => uint256)))) internal _numberMinted;
_rounds
mapping(address => mapping(uint256 => uint256)) internal _rounds;
Functions
constructor
constructor(
address initOwner,
address initSanctionsOracle,
address initWethAddress,
address initProtocolFeeReceiver,
uint256 initProtocolFee
) Ownable(initOwner) Pausable ReentrancyGuard SanctionsCompliance(initSanctionsOracle);
setWethAddress
Function to set a new weth address
Requires owner
function setWethAddress(address newWethAddress) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
newWethAddress | address | The new weth address |
setProtocolFeeSettings
Function to set the protocol fee settings
Requires owner
function setProtocolFeeSettings(address newProtocolFeeReceiver, uint256 newProtocolFee) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
newProtocolFeeReceiver | address | The new protocol fee receiver |
newProtocolFee | uint256 | The new protocol fee in ETH |
pause
Function to pause the contract
Requires owner
function pause(bool status) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
status | bool | The boolean to set the internal pause variable |
setSanctionsOracle
Function to set the sanctions oracle
Requires owner
function setSanctionsOracle(address newOracle) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
newOracle | address | The new oracle address |
configureDrop
Function to configure a drop
Caller must be the nft contract owner or an admin on the contract
*Reverts if
- the payout receiver is the zero address
- a drop is already configured and live
- the
intiialSupplydoes not equal thesupply - the
decayRateis non-zero and there is a presale configured*
function configureDrop(address nftAddress, uint256 tokenId, Drop calldata drop) external whenNotPaused nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The token id of the ERC-1155 token |
drop | Drop | The drop to configure |
updateDropPayoutReceiver
Function to update the payout receiver of a drop
Caller must be the nft contract owner or an admin on the contract
function updateDropPayoutReceiver(address nftAddress, uint256 tokenId, address payoutReceiver)
external
whenNotPaused
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The token id of the ERC-1155 token |
payoutReceiver | address | The recipient of the funds from the mint |
updateDropAllowance
Function to update the drop public allowance
Caller must be the nft contract owner or an admin on the contract
function updateDropAllowance(address nftAddress, uint256 tokenId, uint256 allowance)
external
whenNotPaused
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The token id of the ERC-1155 token |
allowance | uint256 | The number of tokens allowed to be minted per wallet during the public phase of the drop |
updateDropPrices
Function to update the drop prices and currency
Caller must be the nft contract owner or an admin on the contract
function updateDropPrices(
address nftAddress,
uint256 tokenId,
address currencyAddress,
uint256 presaleCost,
uint256 publicCost
) external whenNotPaused nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The token id of the ERC-1155 token |
currencyAddress | address | The currency address (zero address represents ETH) |
presaleCost | uint256 | The cost of each token during the presale phase |
publicCost | uint256 | The cost of each token during the presale phase |
updateDropDuration
Function to adjust drop durations
Caller must be the nft contract owner or an admin on the contract
function updateDropDuration(
address nftAddress,
uint256 tokenId,
uint256 startTime,
uint256 presaleDuration,
uint256 publicDuration
) external whenNotPaused nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The token id of the ERC-1155 token |
startTime | uint256 | The timestamp at which the drop starts |
presaleDuration | uint256 | The duration of the presale phase of the drop, in seconds |
publicDuration | uint256 | The duration of the public phase |
updateDropPresaleMerkleRoot
Function to adjust the drop merkle root
Caller must be the nft contract owner or an admin on the contract
function updateDropPresaleMerkleRoot(address nftAddress, uint256 tokenId, bytes32 presaleMerkleRoot)
external
whenNotPaused
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The token id of the ERC-1155 token |
presaleMerkleRoot | bytes32 | The merkle root for the presale phase (each leaf is abi encoded with the recipient and number they can mint during presale) |
updateDropDecayRate
Function to adjust the drop decay rate
Caller must be the nft contract owner or an admin on the contract
function updateDropDecayRate(address nftAddress, uint256 tokenId, int256 decayRate)
external
whenNotPaused
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The token id of the ERC-1155 token |
decayRate | int256 | The merkle root for the presale phase (each leaf is abi encoded with the recipient and number they can mint during presale) |
closeDrop
function closeDrop(address nftAddress, uint256 tokenId) external nonReentrant;
purchase
Function to purchase a single token via a drop
*Reverts on any of the following conditions
- Drop isn't active or configured
- numberToMint is 0
- Invalid merkle proof during the presale phase
- Insufficent protocol fee
- Insufficient funds
- Already minted the allowance for the recipient
- Receiver is a contract that doesn't implement proper ERC-1155 receiving functions*
function purchase(
address nftAddress,
uint256 tokenId,
address recipient,
uint256 numberToMint,
uint256 presaleNumberCanMint,
bytes32[] calldata proof
) external payable whenNotPaused nonReentrant returns (uint256 refundAmount);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The nft token id |
recipient | address | The receiver of the nft (msg.sender is the payer but this allows delegation) |
numberToMint | uint256 | The number of tokens to mint |
presaleNumberCanMint | uint256 | The number of tokens the recipient can mint during presale |
proof | bytes32[] | The merkle proof for the presale page |
Returns
| Name | Type | Description |
|---|---|---|
refundAmount | uint256 | The amount of eth refunded bqck to the caller |
getDrop
Function to get a drop
function getDrop(address nftAddress, uint256 tokenId) external view returns (Drop memory);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The nft token id |
Returns
| Name | Type | Description |
|---|---|---|
<none> | Drop | Drop The drop for the nft contract and token id |
getDrops
Function to get a number of drops for a contract
function getDrops(address nftAddress, uint256[] calldata tokenIds) external view returns (Drop[] memory drops);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenIds | uint256[] | The nft token ids |
Returns
| Name | Type | Description |
|---|---|---|
drops | Drop[] | An array of Drops |
getNumberMinted
Function to get number minted on a drop for an address
function getNumberMinted(address nftAddress, uint256 tokenId, address recipient) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The nft token id |
recipient | address | The recipient of the nft |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | uint256 The number of tokens minted |
getDropPhase
Function to get the drop phase
function getDropPhase(address nftAddress, uint256 tokenId) external view returns (DropPhase);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The nft token id |
Returns
| Name | Type | Description |
|---|---|---|
<none> | DropPhase | DropPhase The drop phase |
getDropRound
Function to get the drop round
function getDropRound(address nftAddress, uint256 tokenId) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The nft token id |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | uint256 The round for the drop based on the nft contract and token id |
_setWethAddress
Internal function to set the weth address
function _setWethAddress(address newWethAddress) internal;
Parameters
| Name | Type | Description |
|---|---|---|
newWethAddress | address | The new weth address |
_setProtocolFeeSettings
Internal function to set the protocol fee settings
function _setProtocolFeeSettings(address newProtocolFeeReceiver, uint256 newProtocolFee) internal;
Parameters
| Name | Type | Description |
|---|---|---|
newProtocolFeeReceiver | address | The new protocol fee receiver |
newProtocolFee | uint256 | The new protocol fee in ETH |
_isDropAdmin
Internal function to check if msg.sender is the owner or an admin on the contract
function _isDropAdmin(address nftAddress) internal view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | bool Boolean indicating if msg.sender is the owner or an admin on the nft contract |
_isApprovedMintContract
Intenral function to check if this contract is an approved mint contract
function _isApprovedMintContract(address nftAddress) internal view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | bool Boolean indicating if this contract is approved or not |
_checkPayoutReceiver
Internal function to check if a payout address is a valid address
function _checkPayoutReceiver(address payoutReceiver) internal pure returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
payoutReceiver | address | The payout address to check |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | bool Indication of if the payout address is not the zero address |
_getDropPhase
Internal function to get the drop phase
function _getDropPhase(Drop memory drop) internal view returns (DropPhase);
Parameters
| Name | Type | Description |
|---|---|---|
drop | Drop | The drop in question |
Returns
| Name | Type | Description |
|---|---|---|
<none> | DropPhase | DropPhase The drop phase enum value |
_getNumberCanMint
Internal function to determine how many tokens can be minted by an address
function _getNumberCanMint(uint256 allowance, uint256 numberMinted, uint256 supply)
internal
pure
returns (uint256 numberCanMint);
Parameters
| Name | Type | Description |
|---|---|---|
allowance | uint256 | The amount allowed to mint |
numberMinted | uint256 | The amount already minted |
supply | uint256 | The drop supply |
Returns
| Name | Type | Description |
|---|---|---|
numberCanMint | uint256 | The number of tokens allowed to mint |
_updateDropState
Function to update the state of the drop
function _updateDropState(
address nftAddress,
uint256 tokenId,
uint256 round,
address recipient,
uint256 numberToMint,
Drop memory drop
) internal;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The nft token id |
round | uint256 | The drop round for number minted |
recipient | address | The receiver of the nft (msg.sender is the payer but this allows delegation) |
numberToMint | uint256 | The number of tokens to mint |
drop | Drop | The Drop cached in memory |
_settleUp
Internal function to distribute funds for a _purchase
function _settleUp(uint256 numberToMint, uint256 cost, Drop memory drop) internal returns (uint256 refundAmount);
Parameters
| Name | Type | Description |
|---|---|---|
numberToMint | uint256 | The number of tokens that can be minted |
cost | uint256 | The cost per token |
drop | Drop | The drop |
Returns
| Name | Type | Description |
|---|---|---|
refundAmount | uint256 | The amount of eth refunded to msg.sender |
_mintToken
Internal function to mint the token
function _mintToken(address nftAddress, uint256 tokenId, address recipient, uint256 numberToMint) internal;
Parameters
| Name | Type | Description |
|---|---|---|
nftAddress | address | The nft contract address |
tokenId | uint256 | The nft token id |
recipient | address | The receiver of the nft (msg.sender is the payer but this allows delegation) |
numberToMint | uint256 | The number of tokens to mint |