Contract Name:
GenArt721MinterDAExp_PBAB
Contract Source Code:
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(value);
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(value);
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(value);
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(value);
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(value);
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
// SPDX-License-Identifier: LGPL-3.0-only
// Created By: Art Blocks Inc.
import "../interfaces/0.8.x/IGenArt721CoreV2_PBAB.sol";
import "@openzeppelin-4.5/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin-4.5/contracts/utils/math/SafeCast.sol";
pragma solidity 0.8.17;
/**
* @title A minter contract that allows tokens to be minted with ETH.
* Pricing is achieved using an automated Dutch-auction mechanism.
* This is a fork of MinterDAExpV2, which is intended to be used directly
* with IGenArt721CoreV2_PBAB contracts rather than with IGenArt721CoreContractV3
* and as such does not conform to IFilteredMinterV0 nor assume presence
* of a IMinterFilterV0 conforming minter filter.
* @author Art Blocks Inc.
* @notice Privileged Roles and Ownership:
* This contract is designed to be managed, with limited powers.
* Privileged roles and abilities are controlled by the core contract's allowlisted
* (`isWhitelisted` conforming) addresses and a project's artist. Both of these
* roles hold extensive power and can modify minter details.
* Care must be taken to ensure that the core contract permissions and artist
* addresses are secure behind a multi-sig or other access control mechanism.
* ----------------------------------------------------------------------------
* The following functions are restricted to the core contract's allowlisted
* (`isWhitelisted` conforming) address(es):
* - setAllowablePriceDecayHalfLifeRangeSeconds (note: this range is only
* enforced when creating new auctions)
* - resetAuctionDetails (note: this will prevent minting until a new auction
* is created)
* ----------------------------------------------------------------------------
* The following functions are restricted to a project's artist:
* - setAuctionDetails (note: this may only be called when there is no active
* auction)
* ----------------------------------------------------------------------------
* Additional admin and artist privileged roles may be described on other
* contracts that this minter integrates with.
*
* @dev Note that while this minter makes use of `block.timestamp` and it is
* technically possible that this value is manipulated by block producers, such
* manipulation will not have material impact on the price values of this minter
* given the business practices for how pricing is congfigured for this minter
* and that variations on the order of less than a minute should not
* meaningfully impact price given the minimum allowable price decay rate that
* this minter intends to support.
*/
contract GenArt721MinterDAExp_PBAB is ReentrancyGuard {
using SafeCast for uint256;
/// Auction details updated for project `projectId`.
event SetAuctionDetails(
uint256 indexed projectId,
uint256 _auctionTimestampStart,
uint256 _priceDecayHalfLifeSeconds,
uint256 _startPrice,
uint256 _basePrice
);
/// Auction details cleared for project `projectId`.
event ResetAuctionDetails(uint256 indexed projectId);
/// Maximum and minimum allowed price decay half lifes updated.
event AuctionHalfLifeRangeSecondsUpdated(
uint256 _minimumPriceDecayHalfLifeSeconds,
uint256 _maximumPriceDecayHalfLifeSeconds
);
/// Core contract address this minter interacts with
address public immutable genArt721CoreAddress;
/// This contract handles cores with interface IGenArt721CoreV2_PBAB
IGenArt721CoreV2_PBAB private immutable genArtCoreContract;
uint256 constant ONE_MILLION = 1_000_000;
address payable public ownerAddress;
uint256 public ownerPercentage;
struct ProjectConfig {
bool maxHasBeenInvoked;
uint24 maxInvocations;
// max uint64 ~= 1.8e19 sec ~= 570 billion years
uint64 timestampStart;
uint64 priceDecayHalfLifeSeconds;
uint256 startPrice;
uint256 basePrice;
}
mapping(uint256 => ProjectConfig) public projectConfig;
/// Minimum price decay half life: price must decay with a half life of at
/// least this amount (must cut in half at least every N seconds).
uint256 public minimumPriceDecayHalfLifeSeconds = 300; // 5 minutes
/// Maximum price decay half life: price may decay with a half life of no
/// more than this amount (may cut in half at no more than every N seconds).
uint256 public maximumPriceDecayHalfLifeSeconds = 3600; // 60 minutes
// modifier to restrict access to only addresses specified by the
// `onlyWhitelisted()` method on the associated core contract
modifier onlyCoreAllowlisted() {
require(
genArtCoreContract.isWhitelisted(msg.sender),
"Only Core allowlisted"
);
_;
}
// modifier to restrict access to only the artist for a given project
modifier onlyArtist(uint256 _projectId) {
require(
(msg.sender ==
genArtCoreContract.projectIdToArtistAddress(_projectId)),
"Only Artist"
);
_;
}
// modifier to restrict access to calls only involving a valid projectId
// (an existing project)
modifier onlyValidProjectId(uint256 _projectId) {
require(
_projectId < genArtCoreContract.nextProjectId(),
"Only existing projects"
);
_;
}
/**
* @notice Initializes contract to be integrated with
* Art Blocks core contract at address `_genArt721Address`.
* @param _genArt721Address Art Blocks core contract address for
* which this contract will be a minter.
*/
constructor(address _genArt721Address) ReentrancyGuard() {
genArt721CoreAddress = _genArt721Address;
genArtCoreContract = IGenArt721CoreV2_PBAB(_genArt721Address);
}
/**
* @notice Sets the minter owner (the platform provider) address to `_ownerAddress`.
* @param _ownerAddress New owner address.
*/
function setOwnerAddress(
address payable _ownerAddress
) public onlyCoreAllowlisted {
ownerAddress = _ownerAddress;
}
/**
* @notice Sets the minter owner (the platform provider) revenue % to `_ownerPercentage` percent.
* @param _ownerPercentage New owner percentage.
*/
function setOwnerPercentage(
uint256 _ownerPercentage
) public onlyCoreAllowlisted {
ownerPercentage = _ownerPercentage;
}
/**
* @notice Syncs local maximum invocations of project `_projectId` based on
* the value currently defined in the core contract. Only used for gas
* optimization of mints after maxInvocations has been reached.
* @param _projectId Project ID to set the maximum invocations for.
* @dev this enables gas reduction after maxInvocations have been reached -
* core contracts shall still enforce a maxInvocation check during mint.
* @dev function is intentionally not gated to any specific access control;
* it only syncs a local state variable to the core contract's state.
*/
function setProjectMaxInvocations(uint256 _projectId) external {
uint256 maxInvocations;
uint256 invocations;
(, , invocations, maxInvocations, , , , , ) = genArtCoreContract
.projectTokenInfo(_projectId);
// update storage with results
projectConfig[_projectId].maxInvocations = uint24(maxInvocations);
if (invocations < maxInvocations) {
projectConfig[_projectId].maxHasBeenInvoked = false;
}
}
/**
* @notice Warning: Disabling purchaseTo is not supported on this minter.
* This method exists purely for interface-conformance purposes.
*/
function togglePurchaseToDisabled(
uint256 _projectId
) external view onlyArtist(_projectId) {
revert("Action not supported");
}
/**
* @notice projectId => has project reached its maximum number of
* invocations? Note that this returns a local cache of the core contract's
* state, and may be out of sync with the core contract. This is
* intentional, as it only enables gas optimization of mints after a
* project's maximum invocations has been reached. A false negative will
* only result in a gas cost increase, since the core contract will still
* enforce a maxInvocation check during minting. A false positive is not
* possible because the V2 engine core contract only allows maximum invocations
* to be reduced, not increased. Based on this rationale, we intentionally
* do not do input validation in this method as to whether or not the input
* `_projectId` is an existing project ID.
*
*/
function projectMaxHasBeenInvoked(
uint256 _projectId
) external view returns (bool) {
return projectConfig[_projectId].maxHasBeenInvoked;
}
/**
* @notice projectId => project's maximum number of invocations.
* Optionally synced with core contract value, for gas optimization.
* Note that this returns a local cache of the core contract's
* state, and may be out of sync with the core contract. This is
* intentional, as it only enables gas optimization of mints after a
* project's maximum invocations has been reached.
* @dev A number greater than the core contract's project max invocations
* will only result in a gas cost increase, since the core contract will
* still enforce a maxInvocation check during minting. A number less than
* the core contract's project max invocations is only possible when the
* project's max invocations have not been synced on this minter, since the
* V2 engine core contract only allows maximum invocations to be reduced, not
* increased. When this happens, the minter will enable minting, allowing
* the core contract to enforce the max invocations check. Based on this
* rationale, we intentionally do not do input validation in this method as
* to whether or not the input `_projectId` is an existing project ID.
*/
function projectMaxInvocations(
uint256 _projectId
) external view returns (uint256) {
return uint256(projectConfig[_projectId].maxInvocations);
}
/**
* @notice projectId => auction parameters
*/
function projectAuctionParameters(
uint256 _projectId
)
external
view
returns (
uint256 timestampStart,
uint256 priceDecayHalfLifeSeconds,
uint256 startPrice,
uint256 basePrice
)
{
ProjectConfig storage _projectConfig = projectConfig[_projectId];
return (
_projectConfig.timestampStart,
_projectConfig.priceDecayHalfLifeSeconds,
_projectConfig.startPrice,
_projectConfig.basePrice
);
}
/**
* @notice Sets the minimum and maximum values that are settable for
* `_priceDecayHalfLifeSeconds` across all projects.
* @param _minimumPriceDecayHalfLifeSeconds Minimum price decay half life
* (in seconds).
* @param _maximumPriceDecayHalfLifeSeconds Maximum price decay half life
* (in seconds).
*/
function setAllowablePriceDecayHalfLifeRangeSeconds(
uint256 _minimumPriceDecayHalfLifeSeconds,
uint256 _maximumPriceDecayHalfLifeSeconds
) external onlyCoreAllowlisted {
require(
_maximumPriceDecayHalfLifeSeconds >
_minimumPriceDecayHalfLifeSeconds,
"Maximum half life must be greater than minimum"
);
require(
_minimumPriceDecayHalfLifeSeconds > 0,
"Half life of zero not allowed"
);
minimumPriceDecayHalfLifeSeconds = _minimumPriceDecayHalfLifeSeconds;
maximumPriceDecayHalfLifeSeconds = _maximumPriceDecayHalfLifeSeconds;
emit AuctionHalfLifeRangeSecondsUpdated(
_minimumPriceDecayHalfLifeSeconds,
_maximumPriceDecayHalfLifeSeconds
);
}
////// Auction Functions
/**
* @notice Sets auction details for project `_projectId`.
* @param _projectId Project ID to set auction details for.
* @param _auctionTimestampStart Timestamp at which to start the auction.
* @param _priceDecayHalfLifeSeconds The half life with which to decay the
* price (in seconds).
* @param _startPrice Price at which to start the auction, in Wei.
* @param _basePrice Resting price of the auction, in Wei.
* @dev Note that it is intentionally supported here that the configured
* price may be explicitly set to `0`.
*/
function setAuctionDetails(
uint256 _projectId,
uint256 _auctionTimestampStart,
uint256 _priceDecayHalfLifeSeconds,
uint256 _startPrice,
uint256 _basePrice
) external onlyValidProjectId(_projectId) onlyArtist(_projectId) {
// CHECKS
ProjectConfig storage _projectConfig = projectConfig[_projectId];
require(
_projectConfig.timestampStart == 0 ||
block.timestamp < _projectConfig.timestampStart,
"No modifications mid-auction"
);
require(
block.timestamp < _auctionTimestampStart,
"Only future auctions"
);
require(
_startPrice >= _basePrice,
"Auction start price must be greater than or equal to auction end price"
);
require(
(_priceDecayHalfLifeSeconds >= minimumPriceDecayHalfLifeSeconds) &&
(_priceDecayHalfLifeSeconds <=
maximumPriceDecayHalfLifeSeconds),
"Price decay half life must fall between min and max allowable values"
);
// EFFECTS
_projectConfig.timestampStart = _auctionTimestampStart.toUint64();
_projectConfig.priceDecayHalfLifeSeconds = _priceDecayHalfLifeSeconds
.toUint64();
_projectConfig.startPrice = _startPrice;
_projectConfig.basePrice = _basePrice;
emit SetAuctionDetails(
_projectId,
_auctionTimestampStart,
_priceDecayHalfLifeSeconds,
_startPrice,
_basePrice
);
}
/**
* @notice Resets auction details for project `_projectId`, zero-ing out all
* relevant auction fields. Not intended to be used in normal auction
* operation, but rather only in case of the need to halt an auction.
* @param _projectId Project ID to set auction details for.
*/
function resetAuctionDetails(
uint256 _projectId
) external onlyCoreAllowlisted onlyValidProjectId(_projectId) {
ProjectConfig storage _projectConfig = projectConfig[_projectId];
// reset to initial values
_projectConfig.timestampStart = 0;
_projectConfig.priceDecayHalfLifeSeconds = 0;
_projectConfig.startPrice = 0;
_projectConfig.basePrice = 0;
emit ResetAuctionDetails(_projectId);
}
/**
* @notice Purchases a token from project `_projectId`.
* @param _projectId Project ID to mint a token on.
* @return tokenId Token ID of minted token
*/
function purchase(
uint256 _projectId
) external payable returns (uint256 tokenId) {
tokenId = purchaseTo_do6(msg.sender, _projectId);
return tokenId;
}
/**
* @notice gas-optimized version of purchase(uint256).
*/
function purchase_H4M(
uint256 _projectId
) external payable returns (uint256 tokenId) {
tokenId = purchaseTo_do6(msg.sender, _projectId);
return tokenId;
}
/**
* @notice Purchases a token from project `_projectId` and sets
* the token's owner to `_to`.
* @param _to Address to be the new token's owner.
* @param _projectId Project ID to mint a token on.
* @return tokenId Token ID of minted token
*/
function purchaseTo(
address _to,
uint256 _projectId
) external payable returns (uint256 tokenId) {
return purchaseTo_do6(_to, _projectId);
}
/**
* @notice gas-optimized version of purchaseTo(address, uint256).
*/
function purchaseTo_do6(
address _to,
uint256 _projectId
) public payable nonReentrant returns (uint256 tokenId) {
// CHECKS
ProjectConfig storage _projectConfig = projectConfig[_projectId];
// Note that `maxHasBeenInvoked` is only checked here to reduce gas
// consumption after a project has been fully minted.
// `_projectConfig.maxHasBeenInvoked` is locally cached to reduce
// gas consumption, but if not in sync with the core contract's value,
// the core contract also enforces its own max invocation check during
// minting.
require(
!_projectConfig.maxHasBeenInvoked,
"Maximum number of invocations reached"
);
// _getPrice reverts if auction is unconfigured or has not started
uint256 currentPriceInWei = _getPrice(_projectId);
require(
msg.value >= currentPriceInWei,
"Must send minimum value to mint!"
);
// EFFECTS
tokenId = genArtCoreContract.mint(_to, _projectId, msg.sender);
// okay if this underflows because if statement will always eval false.
// this is only for gas optimization (core enforces maxInvocations).
unchecked {
if (tokenId % ONE_MILLION == _projectConfig.maxInvocations - 1) {
_projectConfig.maxHasBeenInvoked = true;
}
}
// INTERACTIONS
_splitFundsETHAuction(_projectId, currentPriceInWei);
return tokenId;
}
/**
* @dev splits ETH funds between sender (if refund), foundation,
* artist, and artist's additional payee for a token purchased on
* project `_projectId`.
* @dev possible DoS during splits is acknowledged, and mitigated by
* business practices, including end-to-end testing on mainnet, and
* admin-accepted artist payment addresses.
* @param _projectId Project ID for which funds shall be split.
* @param _currentPriceInWei Current price of token, in Wei.
*/
function _splitFundsETHAuction(
uint256 _projectId,
uint256 _currentPriceInWei
) internal {
if (msg.value > 0) {
bool success_;
// send refund to sender
uint256 refund = msg.value - _currentPriceInWei;
if (refund > 0) {
(success_, ) = msg.sender.call{value: refund}("");
require(success_, "Refund failed");
}
// split remaining funds between render provider, platform provider,
// artist, and artist's additional payee
uint256 remainingFunds = _currentPriceInWei;
// Render provider payment
uint256 renderProviderAmount = (remainingFunds *
genArtCoreContract.renderProviderPercentage()) / 100;
if (renderProviderAmount > 0) {
(success_, ) = genArtCoreContract.renderProviderAddress().call{
value: renderProviderAmount
}("");
require(success_, "Renderer payment failed");
remainingFunds -= renderProviderAmount;
}
// Owner (platform provider) payment
uint256 ownerFunds = (remainingFunds * ownerPercentage) / 100;
if (ownerFunds > 0) {
(success_, ) = ownerAddress.call{value: ownerFunds}("");
require(success_, "Owner payment failed");
remainingFunds -= ownerFunds;
}
// Artist additional payee payment
uint256 additionalPayeePercentage = genArtCoreContract
.projectIdToAdditionalPayeePercentage(_projectId);
if (additionalPayeePercentage > 0) {
uint256 additionalPayeeAmount = (remainingFunds *
additionalPayeePercentage) / 100;
if (additionalPayeeAmount > 0) {
(success_, ) = genArtCoreContract
.projectIdToAdditionalPayee(_projectId)
.call{value: additionalPayeeAmount}("");
require(success_, "Additional payment failed");
remainingFunds -= additionalPayeeAmount;
}
}
// Artist payment
if (remainingFunds > 0) {
(success_, ) = genArtCoreContract
.projectIdToArtistAddress(_projectId)
.call{value: remainingFunds}("");
require(success_, "Artist payment failed");
}
}
}
/**
* @notice Gets price of minting a token on project `_projectId` given
* the project's AuctionParameters and current block timestamp.
* Reverts if auction has not yet started or auction is unconfigured.
* @param _projectId Project ID to get price of token for.
* @return current price of token in Wei
* @dev This method calculates price decay using a linear interpolation
* of exponential decay based on the artist-provided half-life for price
* decay, `_priceDecayHalfLifeSeconds`.
*/
function _getPrice(uint256 _projectId) private view returns (uint256) {
ProjectConfig storage _projectConfig = projectConfig[_projectId];
// move parameters to memory if used more than once
uint256 _timestampStart = uint256(_projectConfig.timestampStart);
uint256 _priceDecayHalfLifeSeconds = uint256(
_projectConfig.priceDecayHalfLifeSeconds
);
uint256 _basePrice = _projectConfig.basePrice;
require(block.timestamp > _timestampStart, "Auction not yet started");
require(_priceDecayHalfLifeSeconds > 0, "Only configured auctions");
uint256 decayedPrice = _projectConfig.startPrice;
uint256 elapsedTimeSeconds;
// Return early if configured in "fixed price mode" for gas efficiency
if (decayedPrice /* startPrice */ == _basePrice) {
return _basePrice;
}
unchecked {
// already checked that block.timestamp > _timestampStart above
elapsedTimeSeconds = block.timestamp - _timestampStart;
}
// Divide by two (via bit-shifting) for the number of entirely completed
// half-lives that have elapsed since auction start time.
unchecked {
// already required _priceDecayHalfLifeSeconds > 0
decayedPrice >>= elapsedTimeSeconds / _priceDecayHalfLifeSeconds;
}
// Perform a linear interpolation between partial half-life points, to
// approximate the current place on a perfect exponential decay curve.
unchecked {
// value of expression is provably always less than decayedPrice,
// so no underflow is possible when the subtraction assignment
// operator is used on decayedPrice.
decayedPrice -=
(decayedPrice *
(elapsedTimeSeconds % _priceDecayHalfLifeSeconds)) /
_priceDecayHalfLifeSeconds /
2;
}
if (decayedPrice < _basePrice) {
// Price may not decay below stay `basePrice`.
return _basePrice;
}
return decayedPrice;
}
/**
* @notice Gets if price of token is configured, price of minting a
* token on project `_projectId`, and currency symbol and address to be
* used as payment. Supersedes any core contract price information.
* @param _projectId Project ID to get price information for.
* @return isConfigured true only if project's auction parameters have been
* configured on this minter
* @return tokenPriceInWei current price of token on this minter - invalid
* if auction has not yet been configured
* @return currencySymbol currency symbol for purchases of project on this
* minter. This minter always returns "ETH"
* @return currencyAddress currency address for purchases of project on
* this minter. This minter always returns null address, reserved for ether
*/
function getPriceInfo(
uint256 _projectId
)
external
view
returns (
bool isConfigured,
uint256 tokenPriceInWei,
string memory currencySymbol,
address currencyAddress
)
{
ProjectConfig storage _projectConfig = projectConfig[_projectId];
isConfigured = (_projectConfig.startPrice > 0);
if (block.timestamp <= _projectConfig.timestampStart) {
// Provide a reasonable value for `tokenPriceInWei` when it would
// otherwise revert, using the starting price before auction starts.
tokenPriceInWei = _projectConfig.startPrice;
} else if (_projectConfig.startPrice == 0) {
// In the case of unconfigured auction, return price of zero when
// it would otherwise revert
tokenPriceInWei = 0;
} else {
tokenPriceInWei = _getPrice(_projectId);
}
currencySymbol = "ETH";
currencyAddress = address(0);
}
}
// SPDX-License-Identifier: LGPL-3.0-only
// Created By: Art Blocks Inc.
pragma solidity ^0.8.0;
interface IGenArt721CoreV2_PBAB {
/**
* @notice Token ID `_tokenId` minted on project ID `_projectId` to `_to`.
*/
event Mint(
address indexed _to,
uint256 indexed _tokenId,
uint256 indexed _projectId
);
// getter function of public variable
function admin() external view returns (address);
// getter function of public variable
function nextProjectId() external view returns (uint256);
// getter function of public mapping
function tokenIdToProjectId(
uint256 tokenId
) external view returns (uint256 projectId);
function isWhitelisted(address sender) external view returns (bool);
function projectIdToCurrencySymbol(
uint256 _projectId
) external view returns (string memory);
function projectIdToCurrencyAddress(
uint256 _projectId
) external view returns (address);
function projectIdToArtistAddress(
uint256 _projectId
) external view returns (address payable);
function projectIdToPricePerTokenInWei(
uint256 _projectId
) external view returns (uint256);
function projectIdToAdditionalPayee(
uint256 _projectId
) external view returns (address payable);
function projectIdToAdditionalPayeePercentage(
uint256 _projectId
) external view returns (uint256);
function projectTokenInfo(
uint256 _projectId
)
external
view
returns (
address,
uint256,
uint256,
uint256,
bool,
address,
uint256,
string memory,
address
);
function renderProviderAddress() external view returns (address payable);
function renderProviderPercentage() external view returns (uint256);
function mint(
address _to,
uint256 _projectId,
address _by
) external returns (uint256 tokenId);
function getRoyaltyData(
uint256 _tokenId
)
external
view
returns (
address artistAddress,
address additionalPayee,
uint256 additionalPayeePercentage,
uint256 royaltyFeeByID
);
}