// "SPDX-License-Identifier: UNLICENSED "pragmasolidity ^0.6.0;/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*
*/librarySafeMath{
functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
if (a ==0) {
return0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't holdreturn c;
}
functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
assert(b <= a);
return a - b;
}
functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
functionceil(uint a, uint m) internalpurereturns (uint r) {
return (a + m -1) / m * m;
}
}
Contract Source Code
File 4 of 4: Token.sol
pragmasolidity ^0.6.0;// SPDX-License-Identifier: UNLICENSED// ----------------------------------------------------------------------------// 'Zeedex' token contract// Symbol : ZDEX// Name : Zeedex// Total supply: 10,000,000 (10 million)// Decimals : 18// ----------------------------------------------------------------------------import'./SafeMath.sol';
import'./ERC20contract.sol';
import'./Owned.sol';
// ----------------------------------------------------------------------------// ERC20 Token, with the addition of symbol, name and decimals and assisted// token transfers// ----------------------------------------------------------------------------contractTokenisERC20Interface, Owned{
usingSafeMathforuint256;
stringpublic symbol ="ZDEX";
stringpublic name ="Zeedex";
uint256public decimals =18;
uint256 _totalSupply =10*1000000*10** (decimals);
mapping(address=>uint256) balances;
mapping(address=>mapping(address=>uint256)) allowed;
// ------------------------------------------------------------------------// Constructor// ------------------------------------------------------------------------constructor() public{
owner =msg.sender;
balances[address(owner)] = totalSupply();
emit Transfer(address(0),address(owner), totalSupply());
}
/** ERC20Interface function's implementation **/functiontotalSupply() publicoverrideviewreturns (uint256){
return _totalSupply;
}
// ------------------------------------------------------------------------// Get the token balance for account `tokenOwner`// ------------------------------------------------------------------------functionbalanceOf(address tokenOwner) publicoverrideviewreturns (uint256 balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------// Transfer the balance from token owner's account to `to` account// - Owner's account must have sufficient balance to transfer// - 0 value transfers are allowed// ------------------------------------------------------------------------functiontransfer(address to, uint256 tokens) publicoverridereturns (bool success) {
// prevent transfer to 0x0, use burn insteadrequire(address(to) !=address(0));
require(balances[msg.sender] >= tokens );
require(balances[to] + tokens >= balances[to]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender,to,tokens);
returntrue;
}
// ------------------------------------------------------------------------// Token owner can approve for `spender` to transferFrom(...) `tokens`// from the token owner's account// ------------------------------------------------------------------------functionapprove(address spender, uint256 tokens) publicoverridereturns (bool success){
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender,spender,tokens);
returntrue;
}
// ------------------------------------------------------------------------// Transfer `tokens` from the `from` account to the `to` account// // The calling account must already have sufficient tokens approve(...)-d// for spending from the `from` account and// - From account must have sufficient balance to transfer// - Spender must have sufficient allowance to transfer// - 0 value transfers are allowed// ------------------------------------------------------------------------functiontransferFrom(addressfrom, address to, uint256 tokens) publicoverridereturns (bool success){
require(tokens <= allowed[from][msg.sender]); //check allowancerequire(balances[from] >= tokens);
balances[from] = balances[from].sub(tokens);
balances[to] = balances[to].add(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
emit Transfer(from,to,tokens);
returntrue;
}
// ------------------------------------------------------------------------// Returns the amount of tokens approved by the owner that can be// transferred to the spender's account// ------------------------------------------------------------------------functionallowance(address tokenOwner, address spender) publicoverrideviewreturns (uint256 remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------// Burn the `_amount` amount of tokens from the calling `account`// @params _amount the amount of tokens to burn// ------------------------------------------------------------------------functionburnTokens(uint256 _amount) public{
_burn(_amount, msg.sender);
}
// ------------------------------------------------------------------------// @dev Internal function that burns an amount of the token from a given account// @param _amount The amount that will be burnt// @param _account The tokens to burn from// ------------------------------------------------------------------------function_burn(uint256 _amount, address _account) internal{
require(balances[_account] >= _amount, "insufficient account balance");
_totalSupply = _totalSupply.sub(_amount);
balances[address(_account)] = balances[address(_account)].sub(_amount);
emit Transfer(address(_account), address(0), _amount);
}
}