Skip to content

Commit

Permalink
added mintCoin function
Browse files Browse the repository at this point in the history
  • Loading branch information
0xPilou committed Oct 31, 2023
1 parent 1da4b6c commit e3ef526
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
60 changes: 60 additions & 0 deletions forge-cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
Expand Up @@ -6193,6 +6193,66 @@
}
}
},
"src/token/ERC721/ERC721ABLECoin.sol": {
"lastModificationDate": 1698746174403,
"contentHash": "61ebbf85d298124e1dedf379947f13a3",
"sourceName": "src/token/ERC721/ERC721ABLECoin.sol",
"solcConfig": {
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"": [
"ast"
],
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
"metadata"
]
}
},
"evmVersion": "paris",
"libraries": {}
}
},
"imports": [
"lib/ERC721A-Upgradeable/contracts/ERC721AStorage.sol",
"lib/ERC721A-Upgradeable/contracts/ERC721AUpgradeable.sol",
"lib/ERC721A-Upgradeable/contracts/ERC721A__Initializable.sol",
"lib/ERC721A-Upgradeable/contracts/ERC721A__InitializableStorage.sol",
"lib/ERC721A-Upgradeable/contracts/IERC721AUpgradeable.sol",
"lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol",
"lib/openzeppelin-contracts/contracts/utils/Strings.sol",
"lib/openzeppelin-contracts/contracts/utils/math/Math.sol",
"lib/openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol",
"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol",
"lib/openzeppelin-contracts-upgradeable/contracts/utils/AddressUpgradeable.sol",
"lib/openzeppelin-contracts-upgradeable/contracts/utils/ContextUpgradeable.sol",
"src/libraries/ABDataTypes.sol",
"src/libraries/ABErrors.sol",
"src/libraries/ABEvents.sol",
"src/token/ERC721/ERC721AB.sol",
"src/utils/IABDataRegistry.sol",
"src/utils/IABVerifier.sol"
],
"versionRequirement": "^0.8.18",
"artifacts": {
"ERC721ABLECoin": {
"0.8.19+commit.7dd6d404.Darwin.appleclang": "ERC721ABLECoin.sol/ERC721ABLECoin.json"
}
}
},
"src/token/ERC721/ERC721ABOE.sol": {
"lastModificationDate": 1698654153570,
"contentHash": "f31648078435acf839a046f667fd03c2",
Expand Down
48 changes: 47 additions & 1 deletion src/token/ERC721/ERC721ABLECoin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

/* Openzeppelin Contract */
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/* anotherblock Contract */
import {ERC721AB} from "src/token/ERC721/ERC721AB.sol";

Expand Down Expand Up @@ -94,7 +97,7 @@ contract ERC721ABLECoin is ERC721AB {
* @param _quantity quantity of tokens requested (must be less than max mint per phase)
* @param _signature signature to verify allowlist status
*/
function mint(address _to, uint256 _phaseId, uint256 _quantity, bytes calldata _signature) external payable {
function mintETH(address _to, uint256 _phaseId, uint256 _quantity, bytes calldata _signature) external payable {
// Check that the requested minting phase has started
if (!_isPhaseActive(_phaseId)) revert ABErrors.PHASE_NOT_ACTIVE();

Expand Down Expand Up @@ -127,6 +130,49 @@ contract ERC721ABLECoin is ERC721AB {
_mint(_to, _quantity);
}

/**
* @notice
* Mint `_quantity` tokens to `_to` address based on the current `_phaseId` if `_signature` is valid
*
* @param _to token recipient address (must be whitelisted)
* @param _phaseId current minting phase (must be started)
* @param _quantity quantity of tokens requested (must be less than max mint per phase)
* @param _signature signature to verify allowlist status
*/
function mintCoin(address _to, uint256 _phaseId, uint256 _quantity, bytes calldata _signature) external {
// Check that the requested minting phase has started
if (!_isPhaseActive(_phaseId)) revert ABErrors.PHASE_NOT_ACTIVE();

// Get requested phase details
ABDataTypes.Phase memory phase = phases[_phaseId];

// Check that there are enough tokens available for sale
if (_totalMinted() + _quantity > maxSupply) {
revert ABErrors.NOT_ENOUGH_TOKEN_AVAILABLE();
}

// Check if the current phase is private
if (!phase.isPublic) {
// Check that the user is included in the allowlist
if (!abVerifier.verifySignature721(_to, address(this), _phaseId, _signature)) {
revert ABErrors.NOT_ELIGIBLE();
}
}

// Check that user did not mint / is not asking to mint more than the max mint per address for the current phase
if (mintedPerPhase[_to][_phaseId] + _quantity > phase.maxMint) revert ABErrors.MAX_MINT_PER_ADDRESS();

if (!IERC20(mintCurrency).transferFrom(msg.sender, address(this), priceCurrency * _quantity)) {
revert ABErrors.INCORRECT_ETH_SENT();
}

// Set quantity minted for `_to` during the current phase
mintedPerPhase[_to][_phaseId] += _quantity;

// Mint `_quantity` amount to `_to` address
_mint(_to, _quantity);
}

// ____ __ ___ __ _
// / __ \____ / /_ __ / | ____/ /___ ___ (_)___
// / / / / __ \/ / / / / / /| |/ __ / __ `__ \/ / __ \
Expand Down

0 comments on commit e3ef526

Please sign in to comment.