forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36a59fb
commit 59d19b2
Showing
11 changed files
with
794 additions
and
15 deletions.
There are no files selected for viewing
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
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); | ||
} | ||
} |
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
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; | ||
} | ||
|
||
} |
Oops, something went wrong.