Created
October 23, 2021 03:02
-
-
Save bankrollnetwork/a0f4d7b380838efade8311eee294d472 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=true&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.8; | |
/* | |
SPDX-License-Identifier: MIT | |
A Bankteller Production | |
Bankroll Network | |
Copyright 2021 | |
*/ | |
abstract contract Context { | |
function _msgSender() internal view virtual returns (address payable) { | |
return msg.sender; | |
} | |
function _msgData() internal view virtual returns (bytes memory) { | |
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 | |
return msg.data; | |
} | |
} | |
/** | |
* @dev Contract module which provides a basic access control mechanism, where | |
* there is an account (an owner) that can be granted exclusive access to | |
* specific functions. | |
* | |
* By default, the owner account will be the one that deploys the contract. This | |
* can later be changed with {transferOwnership}. | |
* | |
* This module is used through inheritance. It will make available the modifier | |
* `onlyOwner`, which can be applied to your functions to restrict their use to | |
* the owner. | |
*/ | |
contract Ownable is Context { | |
address private _owner; | |
address private _previousOwner; | |
uint256 private _lockTime; | |
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
/** | |
* @dev Initializes the contract setting the deployer as the initial owner. | |
*/ | |
constructor () internal { | |
address msgSender = _msgSender(); | |
_owner = msgSender; | |
emit OwnershipTransferred(address(0), msgSender); | |
} | |
/** | |
* @dev Returns the address of the current owner. | |
*/ | |
function owner() public view returns (address) { | |
return _owner; | |
} | |
/** | |
* @dev Throws if called by any account other than the owner. | |
*/ | |
modifier onlyOwner() { | |
require(_owner == _msgSender(), "Ownable: caller is not the owner"); | |
_; | |
} | |
/** | |
* @dev Leaves the contract without owner. It will not be possible to call | |
* `onlyOwner` functions anymore. Can only be called by the current owner. | |
* | |
* NOTE: Renouncing ownership will leave the contract without an owner, | |
* thereby removing any functionality that is only available to the owner. | |
*/ | |
function renounceOwnership() public virtual onlyOwner { | |
emit OwnershipTransferred(_owner, address(0)); | |
_owner = address(0); | |
} | |
/** | |
* @dev Transfers ownership of the contract to a new account (`newOwner`). | |
* Can only be called by the current owner. | |
*/ | |
function transferOwnership(address newOwner) public virtual onlyOwner { | |
require(newOwner != address(0), "Ownable: new owner is the zero address"); | |
emit OwnershipTransferred(_owner, newOwner); | |
_owner = newOwner; | |
} | |
function getUnlockTime() public view returns (uint256) { | |
return _lockTime; | |
} | |
//Locks the contract for owner for the amount of time provided | |
function lock(uint256 time) public virtual onlyOwner { | |
_previousOwner = _owner; | |
_owner = address(0); | |
_lockTime = now + time; | |
emit OwnershipTransferred(_owner, address(0)); | |
} | |
//Unlocks the contract for owner when _lockTime is exceeds | |
function unlock() public virtual { | |
require(_previousOwner == msg.sender, "You don't have permission to unlock"); | |
require(now > _lockTime , "Contract is locked until 7 days"); | |
emit OwnershipTransferred(_owner, _previousOwner); | |
_owner = _previousOwner; | |
} | |
} | |
/** | |
* @title Whitelist | |
* @dev The Whitelist contract has a whitelist of addresses, and provides basic authorization control functions. | |
* @dev This simplifies the implementation of "user permissions". | |
*/ | |
contract Whitelist is Ownable { | |
mapping(address => bool) public whitelist; | |
event WhitelistedAddressAdded(address addr); | |
event WhitelistedAddressRemoved(address addr); | |
/** | |
* @dev Throws if called by any account that's not whitelisted. | |
*/ | |
modifier onlyWhitelisted() { | |
require(whitelist[msg.sender], 'not whitelisted'); | |
_; | |
} | |
/** | |
* @dev add an address to the whitelist | |
* @param addr address | |
* @return success true if the address was added to the whitelist, false if the address was already in the whitelist | |
*/ | |
function addAddressToWhitelist(address addr) onlyOwner public returns(bool success) { | |
if (!whitelist[addr]) { | |
whitelist[addr] = true; | |
emit WhitelistedAddressAdded(addr); | |
success = true; | |
} | |
} | |
/** | |
* @dev add addresses to the whitelist | |
* @param addrs addresses | |
* @return success true if at least one address was added to the whitelist, | |
* false if all addresses were already in the whitelist | |
*/ | |
function addAddressesToWhitelist(address[] calldata addrs) onlyOwner public returns(bool success) { | |
for (uint256 i = 0; i < addrs.length; i++) { | |
if (addAddressToWhitelist(addrs[i])) { | |
success = true; | |
} | |
} | |
} | |
/** | |
* @dev remove an address from the whitelist | |
* @param addr address | |
* @return success true if the address was removed from the whitelist, | |
* false if the address wasn't in the whitelist in the first place | |
*/ | |
function removeAddressFromWhitelist(address addr) onlyOwner public returns(bool success) { | |
if (whitelist[addr]) { | |
whitelist[addr] = false; | |
emit WhitelistedAddressRemoved(addr); | |
success = true; | |
} | |
} | |
/** | |
* @dev remove addresses from the whitelist | |
* @param addrs addresses | |
* @return success true if at least one address was removed from the whitelist, | |
* false if all addresses weren't in the whitelist in the first place | |
*/ | |
function removeAddressesFromWhitelist(address[] calldata addrs) onlyOwner public returns(bool success) { | |
for (uint256 i = 0; i < addrs.length; i++) { | |
if (removeAddressFromWhitelist(addrs[i])) { | |
success = true; | |
} | |
} | |
} | |
} | |
// File: openzeppelin-solidity/contracts/math/SafeMath.sol | |
/** | |
* @title SafeMath | |
* @dev Math operations with safety checks that throw on error | |
*/ | |
library SafeMath { | |
/** | |
* @dev Multiplies two numbers, throws on overflow. | |
*/ | |
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
if (a == 0) { | |
return 0; | |
} | |
c = a * b; | |
assert(c / a == b); | |
return c; | |
} | |
/** | |
* @dev Integer division of two numbers, truncating the quotient. | |
*/ | |
function div(uint256 a, uint256 b) internal pure returns (uint256) { | |
// assert(b > 0); // Solidity automatically throws when dividing by 0 | |
// uint256 c = a / b; | |
// assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
return a / b; | |
} | |
/** | |
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
*/ | |
function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
assert(b <= a); | |
return a - b; | |
} | |
/** | |
* @dev Adds two numbers, throws on overflow. | |
*/ | |
function add(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
} | |
interface BEP20Basic { | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address who) external view returns (uint256); | |
function transfer(address to, uint256 value) external returns (bool); | |
event Transfer(address indexed from, address indexed to, uint256 value); | |
} | |
/** | |
* @title Basic token | |
* @dev Basic version of StandardToken, with no allowances. | |
*/ | |
contract BasicToken is BEP20Basic { | |
using SafeMath for uint256; | |
mapping(address => uint256) balances; | |
uint256 totalSupply_; | |
/** | |
* @dev total number of tokens in existence | |
*/ | |
function totalSupply() public override view returns (uint256) { | |
return totalSupply_; | |
} | |
/** | |
* @dev transfer token for a specified address | |
* @param _to The address to transfer to. | |
* @param _value The amount to be transferred. | |
*/ | |
function transfer(address _to, uint256 _value) public override returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[msg.sender]); | |
balances[msg.sender] = balances[msg.sender].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
emit Transfer(msg.sender, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Gets the balance of the specified address. | |
* @param _owner The address to query the the balance of. | |
* @return An uint256 representing the amount owned by the passed address. | |
*/ | |
function balanceOf(address _owner) public override view returns (uint256) { | |
return balances[_owner]; | |
} | |
} | |
/** | |
* @title BEP20 interface | |
* @dev see https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
abstract contract BEP20 is BEP20Basic { | |
function allowance(address owner, address spender) public virtual view returns (uint256); | |
function transferFrom(address from, address to, uint256 value) public virtual returns (bool); | |
function approve(address spender, uint256 value) public virtual returns (bool); | |
event Approval(address indexed owner, address indexed spender, uint256 value); | |
} | |
/** | |
* @title Standard BEP20 token | |
* | |
* @dev Implementation of the basic standard token. | |
* @dev https://github.com/ethereum/EIPs/issues/20 | |
*/ | |
contract StandardToken is BEP20, BasicToken { | |
mapping(address => mapping(address => uint256)) internal allowed; | |
/** | |
* @dev Transfer tokens from one address to another | |
* @param _from address The address which you want to send tokens from | |
* @param _to address The address which you want to transfer to | |
* @param _value uint256 the amount of tokens to be transferred | |
*/ | |
function transferFrom(address _from, address _to, uint256 _value) public override virtual returns (bool) { | |
require(_to != address(0)); | |
require(_value <= balances[_from]); | |
require(_value <= allowed[_from][msg.sender]); | |
balances[_from] = balances[_from].sub(_value); | |
balances[_to] = balances[_to].add(_value); | |
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); | |
emit Transfer(_from, _to, _value); | |
return true; | |
} | |
/** | |
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
* | |
* Beware that changing an allowance with this method brings the risk that someone may use both the old | |
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
* @param _spender The address which will spend the funds. | |
* @param _value The amount of tokens to be spent. | |
*/ | |
function approve(address _spender, uint256 _value) public override returns (bool) { | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
/** | |
* @dev Function to check the amount of tokens that an owner allowed to a spender. | |
* @param _owner address The address which owns the funds. | |
* @param _spender address The address which will spend the funds. | |
* @return A uint256 specifying the amount of tokens still available for the spender. | |
*/ | |
function allowance(address _owner, address _spender) public override view returns (uint256) { | |
return allowed[_owner][_spender]; | |
} | |
/** | |
* @dev Increase the amount of tokens that an owner allowed to a spender. | |
* | |
* approve should be called when allowed[_spender] == 0. To increment | |
* allowed value is better to use this function to avoid 2 calls (and wait until | |
* the first transaction is mined) | |
* From MonolithDAO Token.sol | |
* @param _spender The address which will spend the funds. | |
* @param _addedValue The amount of tokens to increase the allowance by. | |
*/ | |
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
return true; | |
} | |
/** | |
* @dev Decrease the amount of tokens that an owner allowed to a spender. | |
* | |
* approve should be called when allowed[_spender] == 0. To decrement | |
* allowed value is better to use this function to avoid 2 calls (and wait until | |
* the first transaction is mined) | |
* From MonolithDAO Token.sol | |
* @param _spender The address which will spend the funds. | |
* @param _subtractedValue The amount of tokens to decrease the allowance by. | |
*/ | |
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { | |
uint oldValue = allowed[msg.sender][_spender]; | |
if (_subtractedValue > oldValue) { | |
allowed[msg.sender][_spender] = 0; | |
} else { | |
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); | |
} | |
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
return true; | |
} | |
} | |
/** | |
* @title Mintable token | |
* @dev Simple BEP20 Token example, with mintable token creation | |
* @dev Issue: * https://github.com/OpenZeppelin/openzeppelin-solidity/issues/120 | |
*/ | |
contract MintableToken is StandardToken, Whitelist { | |
event Mint(address indexed to, uint256 amount); | |
event MintFinished(); | |
bool public mintingFinished = false; | |
modifier canMint() { | |
require(!mintingFinished); | |
_; | |
} | |
/** | |
* @dev Function to mint tokens | |
* @param _to The address that will receive the minted tokens. | |
* @param _amount The amount of tokens to mint. | |
* @return A boolean that indicates if the operation was successful. | |
*/ | |
function mint(address _to, uint256 _amount) onlyWhitelisted canMint public virtual returns (bool) { | |
require(_to != address(0)); | |
totalSupply_ = totalSupply_.add(_amount); | |
balances[_to] = balances[_to].add(_amount); | |
emit Mint(_to, _amount); | |
emit Transfer(address(0), _to, _amount); | |
return true; | |
} | |
} | |
/** | |
* @title Burnable Token | |
* @dev Token that can be irreversibly burned (destroyed). | |
*/ | |
contract BurnableToken is MintableToken { | |
using SafeMath for uint256; | |
event Burn(address indexed burner, uint256 value); | |
/** | |
* @dev Burns a specific amount of tokens. | |
* @param _value The amount of token to be burned. | |
*/ | |
function burn(uint256 _value) public { | |
require(_value > 0); | |
require(_value <= balances[msg.sender]); | |
// no need to require value <= totalSupply, since that would imply the | |
// sender's balance is greater than the totalSupply, which *should* be an assertion failure | |
address burner = msg.sender; | |
balances[burner] = balances[burner].sub(_value); | |
totalSupply_ = totalSupply_.sub(_value); | |
Burn(burner, _value); | |
} | |
} | |
contract ElephantDollar is BurnableToken { | |
struct Stats { | |
uint256 txs; | |
} | |
string private _name; | |
string private _symbol; | |
uint8 public constant decimals = 18; | |
uint256 public constant MAX_INT = 2**256 - 1; | |
uint256 public constant targetSupply = MAX_INT; | |
uint256 public totalTxs; | |
uint256 public participants; | |
uint256 private mintedSupply_; | |
mapping(address => Stats) private stats; | |
/** | |
* @dev default constructor | |
*/ | |
constructor(string memory name, string memory symbol) Ownable() public { | |
require(bytes(name).length > 0 && bytes(symbol).length > 0, "Description information must be set"); | |
_name = name; | |
_symbol = symbol; | |
} | |
function name() public view returns (string memory) { | |
return _name; | |
} | |
function symbol() public view returns (string memory) { | |
return _symbol; | |
} | |
/** | |
* @dev Function to mint tokens (onlyOwner) | |
* @param _to The address that will receive the minted tokens. | |
* @param _amount The amount of tokens to mint. | |
* @return A boolean that indicates if the operation was successful. | |
*/ | |
function mint(address _to, uint256 _amount) public override returns (bool) { | |
//Never fail, just don't mint if over | |
require(_amount > 0 && totalSupply_.add(_amount) <= targetSupply); | |
//Mint | |
super.mint(_to, _amount); | |
if (totalSupply_ == targetSupply) { | |
mintingFinished = true; | |
emit MintFinished(); | |
} | |
/* Members */ | |
if (stats[_to].txs == 0) { | |
participants += 1; | |
} | |
stats[_to].txs += 1; | |
totalTxs += 1; | |
return true; | |
} | |
/** @dev Transfers (using transferFrom) */ | |
function transferFrom(address _from, address _to, uint256 _value) public override returns (bool) { | |
require(super.transferFrom(_from, _to, _value)); | |
/* Members */ | |
if (stats[_to].txs == 0) { | |
participants += 1; | |
} | |
stats[_to].txs += 1; | |
stats[_from].txs += 1; | |
totalTxs += 1; | |
return true; | |
} | |
/** @dev Transfers */ | |
function transfer(address _to, uint256 _value) public override returns (bool) { | |
require(super.transfer(_to, _value)); | |
/* Members */ | |
if (stats[_to].txs == 0) { | |
participants += 1; | |
} | |
stats[_to].txs += 1; | |
stats[msg.sender].txs += 1; | |
totalTxs += 1; | |
return true; | |
} | |
/** @dev Returns the supply still available to mint */ | |
function remainingMintableSupply() public view returns (uint256) { | |
return targetSupply.sub(totalSupply_); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment