Skip to content

Commit

Permalink
finish initial contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenadams committed Aug 29, 2019
1 parent 36a59fb commit 59d19b2
Show file tree
Hide file tree
Showing 11 changed files with 794 additions and 15 deletions.
45 changes: 45 additions & 0 deletions contracts/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
pragma solidity ^0.5.11;
import "./SafeMath.sol";


contract ERC20 {
using SafeMath for uint256;

mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

uint256 public totalSupply;
uint256 internal constant MAX_UINT256 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

function transfer(address to, uint256 value) public returns (bool) {
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}

function transferFrom(address from, address to, uint256 value) public returns (bool) {
if (allowance[from][msg.sender] < MAX_UINT256) {
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
}
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(from, to, value);
return true;
}

function approve(address spender, uint256 value) public returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}

function burn(uint256 value) public {
totalSupply = totalSupply.sub(value);
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
emit Transfer(msg.sender, address(0), value);
}
}
40 changes: 40 additions & 0 deletions contracts/SafeMath.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pragma solidity ^0.5.11;

library SafeMath {

function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}


function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}


function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}


function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}

}
Loading

0 comments on commit 59d19b2

Please sign in to comment.