Skip to content

Commit

Permalink
ERC1155Sale supplycap is part of saledetails
Browse files Browse the repository at this point in the history
  • Loading branch information
ScreamingHawk committed Jul 23, 2024
1 parent cf0a574 commit f097647
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/tokens/ERC1155/utility/sale/ERC1155Sale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
SaleDetails private _globalSaleDetails;
mapping(uint256 => SaleDetails) private _tokenSaleDetails;

// Maximum supply globaly and per token. 0 indicates unlimited supply
uint256 internal totalSupplyCap;
mapping(uint256 => uint256) internal tokenSupplyCap;

/**
* Initialize the contract.
* @param owner Owner address
Expand All @@ -61,7 +57,7 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
* @param _endTime Latest acceptable timestamp (exclusive).
* @dev A zero endTime value is always considered out of bounds.
*/
function blockTimeOutOfBounds(uint256 _startTime, uint256 _endTime) private view returns (bool) {
function _blockTimeOutOfBounds(uint256 _startTime, uint256 _endTime) private view returns (bool) {
// 0 end time indicates inactive sale.
return _endTime == 0 || block.timestamp < _startTime || block.timestamp >= _endTime; // solhint-disable-line not-rely-on-time
}
Expand All @@ -88,7 +84,7 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
uint256 totalAmount;

SaleDetails memory gSaleDetails = _globalSaleDetails;
bool globalSaleInactive = blockTimeOutOfBounds(gSaleDetails.startTime, gSaleDetails.endTime);
bool globalSaleInactive = _blockTimeOutOfBounds(gSaleDetails.startTime, gSaleDetails.endTime);
bool globalMerkleCheckRequired = false;
for (uint256 i; i < _tokenIds.length; i++) {
uint256 tokenId = _tokenIds[i];
Expand All @@ -102,7 +98,7 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {

// Active sale test
SaleDetails memory saleDetails = _tokenSaleDetails[tokenId];
bool tokenSaleInactive = blockTimeOutOfBounds(saleDetails.startTime, saleDetails.endTime);
bool tokenSaleInactive = _blockTimeOutOfBounds(saleDetails.startTime, saleDetails.endTime);
if (tokenSaleInactive) {
// Prefer token sale
if (globalSaleInactive) {
Expand Down Expand Up @@ -184,13 +180,15 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
uint256 nMint = tokenIds.length;
for (uint256 i = 0; i < nMint; i++) {
// Update storage balance
uint256 tokenSupplyCap = _tokenSaleDetails[tokenIds[i]].supplyCap;
if (
tokenSupplyCap[tokenIds[i]] > 0 && items.tokenSupply(tokenIds[i]) + amounts[i] > tokenSupplyCap[tokenIds[i]]
tokenSupplyCap > 0 && items.tokenSupply(tokenIds[i]) + amounts[i] > tokenSupplyCap
) {
revert InsufficientSupply(items.tokenSupply(tokenIds[i]), amounts[i], tokenSupplyCap[tokenIds[i]]);
revert InsufficientSupply(items.tokenSupply(tokenIds[i]), amounts[i], tokenSupplyCap);
}
totalAmount += amounts[i];
}
uint256 totalSupplyCap = _globalSaleDetails.supplyCap;
if (totalSupplyCap > 0 && items.totalSupply() + totalAmount > totalSupplyCap) {
revert InsufficientSupply(items.totalSupply(), totalAmount, totalSupplyCap);
}
Expand Down Expand Up @@ -235,8 +233,7 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
if (endTime < startTime || endTime <= block.timestamp) {
revert InvalidSaleDetails();
}
_globalSaleDetails = SaleDetails(cost, startTime, endTime, merkleRoot);
totalSupplyCap = supplyCap;
_globalSaleDetails = SaleDetails(cost, supplyCap, startTime, endTime, merkleRoot);
emit GlobalSaleDetailsUpdated(cost, supplyCap, startTime, endTime, merkleRoot);
}

Expand Down Expand Up @@ -266,8 +263,7 @@ contract ERC1155Sale is IERC1155Sale, WithdrawControlled, MerkleProofSingleUse {
if (endTime < startTime || endTime <= block.timestamp) {
revert InvalidSaleDetails();
}
_tokenSaleDetails[tokenId] = SaleDetails(cost, startTime, endTime, merkleRoot);
tokenSupplyCap[tokenId] = supplyCap;
_tokenSaleDetails[tokenId] = SaleDetails(cost, supplyCap, startTime, endTime, merkleRoot);
emit TokenSaleDetailsUpdated(tokenId, cost, supplyCap, startTime, endTime, merkleRoot);
}

Expand Down
1 change: 1 addition & 0 deletions src/tokens/ERC1155/utility/sale/IERC1155Sale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface IERC1155SaleFunctions {

struct SaleDetails {
uint256 cost;
uint256 supplyCap; // 0 supply cap indicates unlimited supply
uint64 startTime;
uint64 endTime; // 0 end time indicates sale inactive
bytes32 merkleRoot; // Root of allowed addresses
Expand Down

0 comments on commit f097647

Please sign in to comment.