Skip to content

Commit

Permalink
Merge pull request #26 from johnashu/main
Browse files Browse the repository at this point in the history
Public Mint Values
  • Loading branch information
johnashu authored Jul 16, 2024
2 parents 2ff717c + ab5c386 commit c7a2992
Show file tree
Hide file tree
Showing 12 changed files with 664 additions and 82 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
/// dx '88~x. !88~ 8888> 9888 9888 888E 888F
/// .8888Xf.888x:! X888X.: 9888 9888 .888N..888
/// :""888":~"888" `888*" "888*""888" `"888*""
/// "~' "~ "" ^Y" ^Y' "" MADNFTs © 2022.
/// "~' "~ "" ^Y" ^Y' "" MADNFTs © 2024.
```

## Usage

## Sepolia BASE

Deployed Factory Address: 0xC29A0F9792c41Bfb58324aDd19Ba305f64DBBC7D
Deployed Router Address: 0xFE8537ED18D3FfC532456Fc6Bb38396fBeFB0c34
Deployed ERC20 Address: 0x19E689e473EA387667149bb0C7c99c3E3201BE50
Expand All @@ -30,6 +31,7 @@ Deployed Router Address: 0x8576C1bAD1e711b08e7E79896A9bAAaFE6e91830
Deployed ERC20 Address: 0x70D3Ee80802873D724E3a4F4cF44F99a15743d9c

## SERV TESTNET contracts

Deployed contracts with 0x263eCFccbA81214D625B5743aaF121A657847294
Deployed Factory Address: 0xC3963ACcD36Fc19b8b7bd4000E4439b993A5c0aB
Deployed Router Address: 0x552226C57f7D1E327cC4995015B2ea703bbcFf68
Expand Down Expand Up @@ -99,4 +101,3 @@ yarn deploy:network
## Contracts Dependency Tree

**_NOTE:_** See smart contracts natspec docs in [documentation](./docs/).

8 changes: 1 addition & 7 deletions contracts/Factory/MADFactoryBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,7 @@ abstract contract MADFactoryBase is
* @custom:selector 0xe04dc3ca
*/
function _royaltyLocker(uint96 _share) internal pure {
assembly {
// (_share > 1000) || (_share % 25 != 0)
if or(gt(_share, 0x3E8), iszero(iszero(mod(_share, 0x19)))) {
mstore(0x00, 0xe0e54ced)
revert(0x1c, 0x04)
}
}
if (_share > 1000 || _share % 25 != 0) revert InvalidRoyalty();
}

/**
Expand Down
209 changes: 191 additions & 18 deletions contracts/MADTokens/ERC1155/ERC1155Basic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ contract ERC1155Basic is ERC1155, ImplBase {
event PublicMintPriceSet(uint256 indexed _id, uint256 _price);
event BatchPublicMintPriceSet(uint256[] indexed _ids, uint256[] _prices);

event PublicMintDatesSet(
uint256 indexed _id, uint256 _startDate, uint256 _endDate
);
event BatchPublicMintDatesSet(
uint256[] indexed _ids, uint256[] _startDates, uint256[] _endDates
);

event PublicMintValuesSet(
uint256 indexed _id, PublicMintValues _publicMintValues
);

event BatchPublicMintValuesSet(
uint256[] indexed _ids, PublicMintValues[] _publicMintValues
);

////////////////////////////////////////////////////////////////
// STORAGE //
////////////////////////////////////////////////////////////////
Expand All @@ -46,16 +61,14 @@ contract ERC1155Basic is ERC1155, ImplBase {

mapping(uint256 id => uint256 maxSupply) public maxSupply;

mapping(uint256 id => bool publicMintState) public publicMintState;

mapping(uint256 id => uint256 publicMintPrice) public publicMintPrice;

/// max that public can mint per address
uint256 public publicMintLimitDefault = 10;
mapping(uint256 id => uint256 publicMintLimit) public publicMintLimit;
mapping(uint256 id => mapping(address minter => uint256 minted)) public
mintedByAddress;

mapping(uint256 id => PublicMintValues publicMintValues) public
publicMintValues;

////////////////////////////////////////////////////////////////
// CONSTRUCTOR //
////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -208,7 +221,10 @@ contract ERC1155Basic is ERC1155, ImplBase {
) private {
_publicMinted(_id, _minter, amount);
_preparePublicMint(
uint256(amount), _minter, publicMintState[_id], publicMintPrice[_id]
uint256(amount),
_minter,
publicMintValues[_id].publicMintState,
publicMintValues[_id].price
);
_mint(to, _id, amount, "");
}
Expand Down Expand Up @@ -252,12 +268,12 @@ contract ERC1155Basic is ERC1155, ImplBase {
bool publicMintStateCheck = true;
for (uint256 i = 0; i < len; i++) {
_publicMinted(ids[i], _to, amounts[i]);
if (publicMintState[ids[i]] == false) {
if (publicMintValues[ids[i]].publicMintState == false) {
publicMintStateCheck = false;
break; // Breakout and send false to _preparePublicMint for
// revert action.
}
mintPrice += publicMintPrice[ids[i]];
mintPrice += publicMintValues[ids[i]].price;
}
_preparePublicMint(
uint256(len * _sumAmounts(amounts)),
Expand Down Expand Up @@ -360,10 +376,89 @@ contract ERC1155Basic is ERC1155, ImplBase {
return _balanceRegistrar[id] >> _MINTCOUNT_BITPOS;
}

/**
* @notice Public mint state, a public view function.
* @param id The id (uint256).
* @return bool Result of publicMintState.
* @custom:signature publicMintState(uint256)
* @custom:selector 0xc363989f
*/
function publicMintState(uint256 id) public view returns (bool) {
return publicMintValues[id].publicMintState;
}

/**
* @notice Public mint price, a public view function.
* @param id The id (uint256).
* @return uint256 Result of publicMintPrice.
* @custom:signature publicMintPrice(uint256)
* @custom:selector 0xf723bbed
*/
function publicMintPrice(uint256 id) public view returns (uint256) {
return publicMintValues[id].price;
}

/**
* @notice Public mint limit, a public view function.
* @param id The id (uint256).
* @return uint256 Result of publicMintLimit.
* @custom:signature publicMintLimit(uint256)
* @custom:selector 0x795e15f0
*/
function publicMintLimit(uint256 id) public view returns (uint256) {
return publicMintValues[id].limit;
}

/**
* @notice Public mint dates, a public view function.
* @param id The id (uint256).
* @return uint256 Result of publicMintDates.
* @return uint256 Result of publicMintDates.
* @custom:signature publicMintDates(uint256)
* @custom:selector 0x0d78fbdd
*/
function publicMintDates(uint256 id)
public
view
returns (uint256, uint256)
{
return (publicMintValues[id].startDate, publicMintValues[id].endDate);
}

////////////////////////////////////////////////////////////////
// SETTERS //
////////////////////////////////////////////////////////////////

/**
* @notice Set public mint values, a public state-modifying function.
* @dev Has modifiers: onlyOwner.
* @param _id The id (uint256).
* @param _publicMintValues The public mint values (PublicMintValues).
* @custom:signature setPublicMintValues(uint256,address)
* @custom:selector 0x7b7d6d92
*/
function setPublicMintValues(
uint256 _id,
PublicMintValues calldata _publicMintValues
) public onlyOwner {
_setPublicMintValues(_id, _publicMintValues);
emit PublicMintValuesSet(_id, _publicMintValues);
}

function batchSetPublicMintValues(
uint256[] calldata _ids,
PublicMintValues[] calldata _publicMintValues
) public onlyOwner {
uint256 idsLength = _ids.length;
_loopArrayChecks(idsLength, _publicMintValues.length);

for (uint256 i = 0; i < idsLength; i++) {
_setPublicMintValues(_ids[i], _publicMintValues[i]);
}

emit BatchPublicMintValuesSet(_ids, _publicMintValues);
}

/**
* @notice Set public mint price, a public state-modifying function.
* @dev Has modifiers: onlyOwner.
Expand All @@ -373,7 +468,7 @@ contract ERC1155Basic is ERC1155, ImplBase {
* @custom:selector 0x91c8df12
*/
function setPublicMintPrice(uint256 _id, uint256 _price) public onlyOwner {
publicMintPrice[_id] = _price;
publicMintValues[_id].price = _price;
emit PublicMintPriceSet(_id, _price);
}

Expand All @@ -393,7 +488,7 @@ contract ERC1155Basic is ERC1155, ImplBase {
_loopArrayChecks(idsLength, _prices.length);
for (uint256 i = 0; i < idsLength; i++) {
if (_prices[i] != 0) {
publicMintPrice[_ids[i]] = _prices[i];
publicMintValues[_ids[i]].price = _prices[i];
}
}
emit BatchPublicMintPriceSet(_ids, _prices);
Expand All @@ -409,7 +504,7 @@ contract ERC1155Basic is ERC1155, ImplBase {
*/
function setPublicMintLimit(uint256 _id, uint256 _limit) public onlyOwner {
if (_limit == 0) revert ZeroPublicMintLimit();
publicMintLimit[_id] = _limit;
publicMintValues[_id].limit = _limit;
emit PublicMintLimitSet(_id, _limit);
}

Expand All @@ -429,18 +524,18 @@ contract ERC1155Basic is ERC1155, ImplBase {
_loopArrayChecks(idsLength, _limits.length);
for (uint256 i = 0; i < idsLength; i++) {
if (_limits[i] == 0) revert ZeroPublicMintLimit();
publicMintLimit[_ids[i]] = _limits[i];
publicMintValues[_ids[i]].limit = _limits[i];
}
emit BatchPublicMintLimitSet(_ids, _limits);
}

/**
* @notice Set max supply, a public state-modifying function.
* @param id The id (uint256).
* @param _maxSupply The max supply (uint256).
* @custom:signature setMaxSupply(uint256,uint256)
* @custom:selector 0x37da577c
*/

function setMaxSupply(uint256 id, uint256 _maxSupply) public authorised {
if (_maxSupply > 0) {
_maxSupplyChecks(id, _maxSupply);
Expand Down Expand Up @@ -486,7 +581,7 @@ contract ERC1155Basic is ERC1155, ImplBase {
onlyOwner
{
if (maxSupply[_id] == 0) revert MaxSupplyNotSet(_id);
publicMintState[_id] = _publicMintState;
publicMintValues[_id].publicMintState = _publicMintState;
emit PublicMintStateSet(_id, _publicMintState);
}

Expand All @@ -507,15 +602,93 @@ contract ERC1155Basic is ERC1155, ImplBase {
_loopArrayChecks(idsLength, _publicMintStates.length);
for (uint256 i = 0; i < idsLength; i++) {
if (maxSupply[_ids[i]] == 0) revert MaxSupplyNotSet(_ids[i]);
publicMintState[_ids[i]] = _publicMintStates[i];
publicMintValues[_ids[i]].publicMintState = _publicMintStates[i];
}
emit BatchPublicMintStateSet(_ids, _publicMintStates);
}

/**
* @notice Set public mint dates, a public state-modifying function.
* @dev Has modifiers: onlyOwner.
* @param id The id (uint256).
* @param _startDate The start date (uint256).
* @param _endDate The end date (uint256).
* @custom:signature setPublicMintDates(uint256,uint256,uint256)
* @custom:selector 0xe96c6b29
*/
function setPublicMintDates(
uint256 id,
uint256 _startDate,
uint256 _endDate
) public onlyOwner {
if (_startDate > _endDate || _endDate == 0) {
revert InvalidPublicMintDates();
}
publicMintValues[id].startDate = _startDate;
publicMintValues[id].endDate = _endDate;
emit PublicMintDatesSet(id, _startDate, _endDate);
}

/**
* @notice Batch set public mint dates, a public state-modifying function.
* @dev Has modifiers: onlyOwner.
* @param ids List of uint256s.
* @param _startDates List of uint256s.
* @param _endDates List of uint256s.
* @custom:signature batchSetPublicMintDates(uint256[],uint256[],uint256[])
* @custom:selector 0x8dccb1f3
*/
function batchSetPublicMintDates(
uint256[] calldata ids,
uint256[] calldata _startDates,
uint256[] calldata _endDates
) public onlyOwner {
uint256 idsLength = ids.length;
_loopArrayChecks(idsLength, _startDates.length);
_loopArrayChecks(idsLength, _endDates.length);
for (uint256 i = 0; i < idsLength; i++) {
if (_startDates[i] > _endDates[i] || _endDates[i] == 0) {
revert InvalidPublicMintDates();
}
publicMintValues[ids[i]].startDate = _startDates[i];
publicMintValues[ids[i]].endDate = _endDates[i];
}
emit BatchPublicMintDatesSet(ids, _startDates, _endDates);
}

////////////////////////////////////////////////////////////////
// PRIVATE FUNCTIONS //
////////////////////////////////////////////////////////////////

function _setPublicMintValues(
uint256 _id,
PublicMintValues calldata _publicMintValues
) private {
_publicMintValuesChecks(_id, _publicMintValues);
publicMintValues[_id] = _publicMintValues;
}

/**
* @notice Public mint values checks, a private view function.
* @param _id The id (uint256).
* @param _publicMintValues The public mint values (PublicMintValues).
* @custom:signature publicMintValuesChecks(uint256,address)
* @custom:selector 0xc2a084c7
*/
function _publicMintValuesChecks(
uint256 _id,
PublicMintValues calldata _publicMintValues
) private view {
if (_publicMintValues.limit == 0) revert ZeroPublicMintLimit();
if (maxSupply[_id] == 0) revert MaxSupplyNotSet(_id);
if (
_publicMintValues.startDate > _publicMintValues.endDate
|| _publicMintValues.endDate == 0
) {
revert InvalidPublicMintDates();
}
}

/**
* @notice Loop array checks, a private pure function.
* @param arr1Len The arr1 len (uint256).
Expand Down Expand Up @@ -559,7 +732,7 @@ contract ERC1155Basic is ERC1155, ImplBase {
private
{
uint256 amountMinted = mintedByAddress[id][_minter];
if (amountMinted + _amount > publicMintLimit[id]) {
if (amountMinted + _amount > publicMintValues[id].limit) {
revert MintLimitReached();
}
mintedByAddress[id][_minter] += _amount;
Expand Down Expand Up @@ -669,9 +842,9 @@ contract ERC1155Basic is ERC1155, ImplBase {
// "MaxSupplyNotSet(uint256)" to identify the error.
let ptr := mload(0x40) // Free memory pointer
mstore(ptr, 0x1a3ed2ab) // Error signature for
// MaxSupplyNotSet(uint256)
// MaxSupplyNotSet(uint256)
mstore(add(ptr, 4), id) // Append the _id parameter right
// after the error signature
// after the error signature
// Revert with the encoded error message.
// The total size is 4 bytes (error signature) + 32 bytes
// (uint256 _id) = 36 bytes
Expand Down
Loading

0 comments on commit c7a2992

Please sign in to comment.