// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/extension/DropSinglePhase.sol";
import "@thirdweb-dev/contracts/base/ERC20Base.sol";
import "@thirdweb-dev/contracts/lib/CurrencyTransferLib.sol";
/// This is an EXAMPLE of the usage of `DropSinglePhase` for distributing ERC20 tokens.
contract MyContract is ERC20Base, DropSinglePhase {
/*//////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/
constructor(address _defaultAdmin, string memory _name, string memory _symbol)
ERC20Base(_defaultAdmin, _name, _symbol)
{}
/*//////////////////////////////////////////////////////////////
Internal (overrideable) functions
//////////////////////////////////////////////////////////////*/
/// @dev Runs before every `claim` function call.
function _beforeClaim(
uint256 _tokenId,
address _receiver,
uint256 _quantity,
address _currency,
uint256 _pricePerToken,
AllowlistProof calldata _allowlistProof,
bytes memory _data
) internal virtual override {
// Your custom implementation logic here
}
/// @dev Runs after every `claim` function call.
function _afterClaim(
uint256 _tokenId,
address _receiver,
uint256 _quantity,
address _currency,
uint256 _pricePerToken,
AllowlistProof calldata _allowlistProof,
bytes memory _data
) internal virtual override {
// Your custom implementation logic here
}
/// @dev Collects and distributes the primary sale value of tokens being claimed.
function _collectPriceOnClaim(
address _primarySaleRecipient,
uint256 _quantityToClaim,
address _currency,
uint256 _pricePerToken
) internal virtual override {
if (_pricePerToken == 0) {
return;
}
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
require(totalPrice > 0, "quantity too low");
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
require(msg.value == totalPrice, "Must send total price.");
}
address saleRecipient = _primarySaleRecipient;
CurrencyTransferLib.transferCurrency(
_currency,
msg.sender,
saleRecipient,
totalPrice
);
}
/// @dev Transfers the tokens being claimed.
function _transferTokensOnClaim(address _to, uint256 _quantityBeingClaimed)
internal
virtual
override
returns (uint256)
{
_mint(_to, _quantityBeingClaimed);
return 0;
}
/// @dev Checks whether platform fee info can be set in the given execution context.
function _canSetClaimConditions()
internal
view
virtual
override
returns (bool)
{
return msg.sender == owner();
}
}