TLStacks721

Git Source

Inherits: Ownable, Pausable, ReentrancyGuard, TransferHelper, SanctionsCompliance, ITLStacks721Events, DropErrors

Author: transientlabs.xyz

Transient Labs Stacks mint contract for ERC721TL-based 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 => Drop) internal _drops;

_numberMinted

mapping(address => mapping(uint256 => mapping(address => uint256))) internal _numberMinted;

_rounds

mapping(address => 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

NameTypeDescription
newWethAddressaddressThe new weth address

setProtocolFeeSettings

Function to set the protocol fee settings

Requires owner

function setProtocolFeeSettings(address newProtocolFeeReceiver, uint256 newProtocolFee) external onlyOwner;

Parameters

NameTypeDescription
newProtocolFeeReceiveraddressThe new protocol fee receiver
newProtocolFeeuint256The new protocol fee in ETH

pause

Function to pause the contract

Requires owner

function pause(bool status) external onlyOwner;

Parameters

NameTypeDescription
statusboolThe boolean to set the internal pause variable

setSanctionsOracle

Function to set the sanctions oracle

Requires owner

function setSanctionsOracle(address newOracle) external onlyOwner;

Parameters

NameTypeDescription
newOracleaddressThe 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 intialSupply does not equal the supply
  • the decayRate is non-zero and there is a presale configured*
function configureDrop(address nftAddress, Drop calldata drop) external whenNotPaused nonReentrant;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
dropDropThe 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, address payoutReceiver) external whenNotPaused nonReentrant;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
payoutReceiveraddressThe 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 allowance) external whenNotPaused nonReentrant;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
allowanceuint256The 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, address currencyAddress, uint256 presaleCost, uint256 publicCost)
    external
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
currencyAddressaddressThe currency address (zero address represents ETH)
presaleCostuint256The cost of each token during the presale phase
publicCostuint256The 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 startTime, uint256 presaleDuration, uint256 publicDuration)
    external
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
startTimeuint256The timestamp at which the drop starts
presaleDurationuint256The duration of the presale phase of the drop, in seconds
publicDurationuint256The duration of the public phase

updateDropPresaleMerkleRoot

Function to alter a drop merkle root

Caller must be the nft contract owner or an admin on the contract

function updateDropPresaleMerkleRoot(address nftAddress, bytes32 presaleMerkleRoot)
    external
    whenNotPaused
    nonReentrant;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
presaleMerkleRootbytes32The 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, int256 decayRate) external whenNotPaused nonReentrant;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
decayRateint256The 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) external nonReentrant;

purchase

Function to purchase tokens on 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*
function purchase(
    address nftAddress,
    address recipient,
    uint256 numberToMint,
    uint256 presaleNumberCanMint,
    bytes32[] calldata proof
) external payable whenNotPaused nonReentrant returns (uint256 refundAmount);

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
recipientaddressThe receiver of the nft (msg.sender is the payer but this allows delegation)
numberToMintuint256The number of tokens to mint
presaleNumberCanMintuint256The number of tokens the recipient can mint during presale
proofbytes32[]The merkle proof for the presale page

Returns

NameTypeDescription
refundAmountuint256The amount of eth refunded to the caller

getDrop

Function to get a drop

function getDrop(address nftAddress) external view returns (Drop memory);

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address

Returns

NameTypeDescription
<none>DropDrop The drop for the nft contract and token id

getNumberMinted

Function to get number minted on a drop for an address

function getNumberMinted(address nftAddress, address recipient) external view returns (uint256);

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
recipientaddressThe recipient of the nft

Returns

NameTypeDescription
<none>uint256uint256 The number of tokens minted

getDropPhase

Function to get the drop phase

function getDropPhase(address nftAddress) external view returns (DropPhase);

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address

Returns

NameTypeDescription
<none>DropPhaseDropPhase The drop phase

getDropRound

Function to get the drop round

function getDropRound(address nftAddress) external view returns (uint256);

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address

Returns

NameTypeDescription
<none>uint256uint256 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

NameTypeDescription
newWethAddressaddressThe new weth address

_setProtocolFeeSettings

Internal function to set the protocol fee settings

function _setProtocolFeeSettings(address newProtocolFeeReceiver, uint256 newProtocolFee) internal;

Parameters

NameTypeDescription
newProtocolFeeReceiveraddressThe new protocol fee receiver
newProtocolFeeuint256The 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

NameTypeDescription
nftAddressaddressThe nft contract address

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
nftAddressaddressThe nft contract address

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
payoutReceiveraddressThe payout address to check

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
dropDropThe drop in question

Returns

NameTypeDescription
<none>DropPhaseDropPhase 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

NameTypeDescription
allowanceuint256The amount allowed to mint
numberMinteduint256The amount already minted
supplyuint256The drop supply

Returns

NameTypeDescription
numberCanMintuint256The number of tokens allowed to mint

_updateDropState

Function to update the state of the drop

function _updateDropState(address nftAddress, uint256 round, address recipient, uint256 numberToMint, Drop memory drop)
    internal;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
rounduint256The drop round for number minted
recipientaddressThe receiver of the nft (msg.sender is the payer but this allows delegation)
numberToMintuint256The number of tokens to mint
dropDropThe 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

NameTypeDescription
numberToMintuint256The number of tokens that can be minted
costuint256The cost per token
dropDropThe drop

Returns

NameTypeDescription
refundAmountuint256The amount of eth refunded to msg.sender

_mintToken

Internal function to mint the token

function _mintToken(address nftAddress, address recipient, uint256 numberToMint, Drop memory drop) internal;

Parameters

NameTypeDescription
nftAddressaddressThe nft contract address
recipientaddressThe receiver of the nft (msg.sender is the payer but this allows delegation)
numberToMintuint256The number of tokens to mint
dropDropThe drop cached in memory (not read from storage again)