Skip to content

Instantly share code, notes, and snippets.

@Perseverance
Created September 2, 2020 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Perseverance/51fd3dd9b6958664c52bc7445806f3b7 to your computer and use it in GitHub Desktop.
Save Perseverance/51fd3dd9b6958664c52bc7445806f3b7 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol";
import "./Lockable.sol";
import "./VCoinRoles.sol";
/**
* @dev {VOCIN ERC20} token, including:
*
* - ability for holders to burn (destroy) their tokens
* - a minter role that allows for token minting (creation)
* - a pauser role that allows to stop all token transfers
**
* The account that deploys the contract will be granted the minter and pauser
* roles, as well as the default admin role, which will let it grant both minter
* and pauser roles to other accounts.
*/
contract VCoin is Context, Ownable, ERC20Burnable, ERC20Pausable, Lockable, VCoinRoles {
/**
* @dev sets up imvu contract address with the initial mint.
* Grants DEFAULT_ADMIN_ROLE to the imvu contract address.
* Grants `MINTER_ROLE`,`PAUSER_ROLE`,`LOCKER_ROLE` to the imvu contract address.
* Account that deploys the contract is no longer the owner of the contract.
*
* See {ERC20-constructor}.
*/
constructor(string memory name, string memory symbol, uint256 initialmint, address imvuContractAddress) ERC20(name, symbol) {
//Roles are assigned in the constructor of AccessControl.sol
//Adjust initialmint value against default 18 decimals
initialmint = initialmint * (10 ** 18);
//Setup initial mint to IMVU
_mint(imvuContractAddress, initialmint);
//transfer contract ownership to IMVU
transferOwnership(imvuContractAddress);
//grant roles to IMVU
_setupRolesForIMVU(imvuContractAddress);
}
//Burn is implemented thru Burnable base contract
/**
* @dev Creates `amount` new tokens for `to`.
*
* See {ERC20-_mint}.
*
* Requirements:
*
* - the caller must have the `MINTER_ROLE`.
*/
function mint(address to, uint256 amount) public whenNotLocked onlyMinter {
super._mint(to, amount);
}
/**
* @dev Pauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_pause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function pause() public onlyPauser {
_pause();
}
/**
* @dev Unpauses all token transfers.
*
* See {ERC20Pausable} and {Pausable-_unpause}.
*
* Requirements:
*
* - the caller must have the `PAUSER_ROLE`.
*/
function unpause() public onlyPauser {
_unpause();
}
/**
* @dev Locks all operations on this contract including minting/transfers. Lock is permanent
*
* See {ERC20Lockable}.
*
* Requirements:
*
* - the caller must have the `ADMIN_ROLE`.
*/
function lock() public onlyLocker {
_lock();
}
/**
* @dev Overriding the TokenTransfer hook. This hook is called before Transfer, Mint & Burn.
* This hook will act as a gatekeeper to check if the token transfers are paused or locked.
* Admins can mint/burn/pause/lock
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override(ERC20, ERC20Pausable) {
// //check for lock condition
// require(!locked(), "VCoin: token transfer while locked.");
//Pause condition is checked inside Pausable implementation
super._beforeTokenTransfer(from, to, amount);
}
/**
* @dev we need to prevent approvals during token pause and lock
*/
function approve(address spender, uint256 amount) public override whenNotPaused returns (bool) {
super.approve(spender, amount);
}
/**
* @dev we need to prevent allowances during token pause and lock
*/
function increaseAllowance(address spender, uint256 addedValue) public override whenNotPaused returns (bool) {
super.increaseAllowance(spender, addedValue);
}
/**
* @dev we need to prevent allowances during token pause and lock
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public override whenNotPaused returns (bool) {
super.increaseAllowance(spender, subtractedValue);
}
/**
* @dev we need to prevent allowances during token pause and lock
*/
function burnFrom(address account, uint256 amount) public override whenNotPaused {
super.burnFrom(account, amount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment