Skip to content

Commit

Permalink
Merge pull request #18 from Marrmee/feature/#13-ERC20TimedMint
Browse files Browse the repository at this point in the history
Feature/#13 erc20 timed mint
  • Loading branch information
javier123454321 authored Jan 18, 2022
2 parents 924986d + 5e61e13 commit c63dec0
Show file tree
Hide file tree
Showing 7 changed files with 22,667 additions and 10,624 deletions.
65 changes: 51 additions & 14 deletions contracts/ERC20TimedMint.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,60 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;
//SPDX-License-Identifier: Unlicensed

import "./@openzeppelin/contracts/token/ERC20/ERC20.sol";
pragma solidity ^0.8.6;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/**
* @title ERC20TimedMint
* @author Javier Gonzalez
* @author Javier Gonzalez and Marco Huberts
* @dev Implementation of minting functionality for a mintable token.
* @notice ERC20TimedMint inherits the ERC20 functionality and prevents
* minting within a timeframe.
*/
contract ERC20TimedMint is ERC20 {
uint256 timeUntilNexMint
* @notice ERC20TimedMint inherits the ERC20 functionality and prevents
* minting within a timeframe.
*/
contract Erc20TimedMint is ERC20 {

constructor(
uint256 public timeUntilNextMint;
uint256 public mintCap;
uint256 public timeDelay;
bool public timeDelayActive = false;

constructor (
string memory name,
string memory symbol,
uint256 _timeDelay
) ERC20(name, symbol) {
timeUntilNexMint = block.timeStamp + _timeDelay
string memory symbol
)
ERC20(name, symbol)
{

}

function _mint(address to, uint256 amount)
internal
override(ERC20)
{
if(timeDelayActive) {
require(block.timestamp >= timeUntilNextMint, "ERC20: Cannot mint yet");
require(amount <= mintCap, "ERC20: Mint exceeds maximum amount");
_setNextMintTime();
}
super._mint(to, amount);
}
/**
* @dev Function has no guards against setting multiple time delays
* in one minting period
*/
function _setTimeDelay(uint256 _timeDelay) internal {
require(_timeDelay > 0, "time delay must be greater than zero");
timeDelay = _timeDelay;
_setNextMintTime();
if(!timeDelayActive) {
timeDelayActive = true;
}
}

function _setNextMintTime() internal {
timeUntilNextMint = block.timestamp + timeDelay;
}

function _setMintCap(uint256 _mintCap) internal {
mintCap = _mintCap;
}
}
41 changes: 41 additions & 0 deletions contracts/ExposedTimedMint.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//SPDX-License-Identifier: Unlicense

pragma solidity ^0.8.6;

import "./Erc20TimedMint.sol";

/**
* @title ERC20TimedMint
* @author Javier Gonzalez and Marco Huberts
* @dev Implementation of minting functionality for a mintable token.
* @notice ExposedTimedMint inherits the Erc20TimedMint functionality
* and prevents minting within a timeframe.
*/

contract ExposedTimedMint is Erc20TimedMint {

constructor (
string memory _name,
string memory _symbol
)
Erc20TimedMint(_name, _symbol)
{

}

function mint(address to, uint256 amount) public {
return _mint(to, amount);
}

function setTimeDelay(uint256 _timeDelay) public {
return _setTimeDelay(_timeDelay);
}

function setNextMintTime() public {
return _setNextMintTime();
}

function setMintCap(uint256 _mintCap) public {
return _setMintCap(_mintCap);
}
}
20 changes: 10 additions & 10 deletions contracts/SimpleToken.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;

import "./@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./@openzeppelin/contracts/access/AccessControl.sol";
import "./@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import "./@openzeppelin/contracts/utils/structs/BitMaps.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "./utils/MerkleProof.sol";
import "@openzeppelin/contracts/utils/structs/BitMaps.sol";

//import "hardhat/console.sol";

Expand Down Expand Up @@ -44,7 +44,7 @@ contract SimpleToken is ERC20, AccessControl {
constructor(
uint256 _freeSupply,
uint256 _airdropSupply,
address vault,
address vault,
string memory name,
string memory symbol,
address[] memory admins
Expand All @@ -60,7 +60,7 @@ contract SimpleToken is ERC20, AccessControl {
function getInitialSupply() public view returns (uint256) {
return initialSupply;
}

function newAirdrop(bytes32 _merkleRoot, uint256 _timeLimit) public onlyRole(DEFAULT_ADMIN_ROLE) returns (uint256 airdropId) {
airdropId = numberOfAirdrops;
if(numberOfAirdrops > 0) {
Expand All @@ -76,7 +76,7 @@ contract SimpleToken is ERC20, AccessControl {
function isClaimed(uint256 airdropIndex, uint256 claimIndex) public view returns (bool) {
return airdrops[airdropIndex].claimed.get(claimIndex);
}

/**
* @dev Uses merkle proofs to verify that the amount is equivalent to the user's claim
* @param claimAmount this must be calculated off chain and can be verified with the merkleProof
Expand All @@ -89,7 +89,7 @@ contract SimpleToken is ERC20, AccessControl {
require(valid, "Failed to verify proof");
require(!isClaimed(airdropIndex, claimIndex), "Tokens already claimed for this airdrop");
airdrops[airdropIndex].claimed.set(claimIndex);

emit Claimed(msg.sender, claimAmount);

_transfer(address(this), msg.sender, claimAmount);
Expand All @@ -100,8 +100,8 @@ contract SimpleToken is ERC20, AccessControl {
isComplete = airdrops[_index].isComplete;
claimPeriodEnds = airdrops[_index].claimPeriodEnds;
}


/**
* @dev Requires claimPeriod of airdrop to have finished
*/
Expand Down
Loading

0 comments on commit c63dec0

Please sign in to comment.