Skip to content

Commit 96c9628

Browse files
added erc20 token for testing web3swift lib
1 parent cf0e358 commit 96c9628

File tree

12 files changed

+372
-0
lines changed

12 files changed

+372
-0
lines changed

web3swiftToken/.DS_Store

8 KB
Binary file not shown.

web3swiftToken/Helpers/.DS_Store

6 KB
Binary file not shown.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
pragma solidity ^0.4.23;
2+
3+
4+
/**
5+
* @title Ownable
6+
* @dev The Ownable contract has an owner address, and provides basic authorization control
7+
* functions, this simplifies the implementation of "user permissions".
8+
*/
9+
contract Ownable {
10+
address public owner;
11+
12+
13+
event OwnershipRenounced(address indexed previousOwner);
14+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
15+
16+
17+
/**
18+
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
19+
* account.
20+
*/
21+
constructor() public {
22+
owner = msg.sender;
23+
}
24+
25+
/**
26+
* @dev Throws if called by any account other than the owner.
27+
*/
28+
modifier onlyOwner() {
29+
require(msg.sender == owner);
30+
_;
31+
}
32+
33+
/**
34+
* @dev Allows the current owner to transfer control of the contract to a newOwner.
35+
* @param newOwner The address to transfer ownership to.
36+
*/
37+
function transferOwnership(address newOwner) public onlyOwner {
38+
require(newOwner != address(0));
39+
emit OwnershipTransferred(owner, newOwner);
40+
owner = newOwner;
41+
}
42+
43+
/**
44+
* @dev Allows the current owner to relinquish control of the contract.
45+
*/
46+
function renounceOwnership() public onlyOwner {
47+
emit OwnershipRenounced(owner);
48+
owner = address(0);
49+
}
50+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
pragma solidity ^0.4.23;
2+
3+
4+
import "./Ownable.sol";
5+
6+
7+
/**
8+
* @title Pausable
9+
* @dev Base contract which allows children to implement an emergency stop mechanism.
10+
*/
11+
contract Pausable is Ownable {
12+
event Pause();
13+
event Unpause();
14+
event NotPausable();
15+
16+
bool public paused = false;
17+
bool public canPause = true;
18+
19+
/**
20+
* @dev Modifier to make a function callable only when the contract is not paused.
21+
*/
22+
modifier whenNotPaused() {
23+
require(!paused || msg.sender == owner);
24+
_;
25+
}
26+
27+
/**
28+
* @dev Modifier to make a function callable only when the contract is paused.
29+
*/
30+
modifier whenPaused() {
31+
require(paused);
32+
_;
33+
}
34+
35+
/**
36+
* @dev called by the owner to pause, triggers stopped state
37+
**/
38+
function pause() onlyOwner whenNotPaused public {
39+
require(canPause == true);
40+
paused = true;
41+
emit Pause();
42+
}
43+
44+
/**
45+
* @dev called by the owner to unpause, returns to normal state
46+
*/
47+
function unpause() onlyOwner whenPaused public {
48+
require(paused == true);
49+
paused = false;
50+
emit Unpause();
51+
}
52+
53+
/**
54+
* @dev Prevent the token from ever being paused again
55+
**/
56+
function notPauseable() onlyOwner public{
57+
paused = false;
58+
canPause = false;
59+
emit NotPausable();
60+
}
61+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
pragma solidity ^0.4.23;
2+
3+
/**
4+
* @title SafeMath
5+
* @dev Math operations with safety checks that throw on error
6+
* @notice https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/math/SafeMath.sol
7+
*/
8+
library SafeMath {
9+
/**
10+
* SafeMath mul function
11+
* @dev function for safe multiply, throws on overflow.
12+
**/
13+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
14+
uint256 c = a * b;
15+
assert(a == 0 || c / a == b);
16+
return c;
17+
}
18+
19+
/**
20+
* SafeMath div funciotn
21+
* @dev function for safe devide, throws on overflow.
22+
**/
23+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
24+
uint256 c = a / b;
25+
return c;
26+
}
27+
28+
/**
29+
* SafeMath sub function
30+
* @dev function for safe subtraction, throws on overflow.
31+
**/
32+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
33+
assert(b <= a);
34+
return a - b;
35+
}
36+
37+
/**
38+
* SafeMath add function
39+
* @dev Adds two numbers, throws on overflow.
40+
*/
41+
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
42+
c = a + b;
43+
assert(c >= a);
44+
return c;
45+
}
46+
}
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
pragma solidity ^0.4.23;
2+
3+
import "../SafeMath/SafeMath.sol";
4+
import "./ERC20Basic.sol";
5+
6+
/**
7+
* @title Basic token
8+
* @dev Basic version of StandardToken, with no allowances.
9+
*/
10+
contract BasicToken is ERC20Basic {
11+
using SafeMath for uint256;
12+
13+
mapping(address => uint256) balances;
14+
15+
uint256 totalSupply_;
16+
17+
/**
18+
* @dev total number of tokens in existence
19+
*/
20+
function totalSupply() public view returns (uint256) {
21+
return totalSupply_;
22+
}
23+
24+
/**
25+
* @dev transfer token for a specified address
26+
* @param _to The address to transfer to.
27+
* @param _value The amount to be transferred.
28+
*/
29+
function transfer(address _to, uint256 _value) public returns (bool) {
30+
require(_to != address(0));
31+
require(_value <= balances[msg.sender]);
32+
33+
balances[msg.sender] = balances[msg.sender].sub(_value);
34+
balances[_to] = balances[_to].add(_value);
35+
emit Transfer(msg.sender, _to, _value);
36+
return true;
37+
}
38+
39+
/**
40+
* @dev Gets the balance of the specified address.
41+
* @param _owner The address to query the the balance of.
42+
* @return An uint256 representing the amount owned by the passed address.
43+
*/
44+
function balanceOf(address _owner) public view returns (uint256) {
45+
return balances[_owner];
46+
}
47+
48+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pragma solidity ^0.4.23;
2+
3+
import "./ERC20Basic.sol";
4+
5+
/**
6+
* @title ERC20 interface
7+
* @dev see https://github.com/ethereum/EIPs/issues/20
8+
*/
9+
contract ERC20 is ERC20Basic {
10+
function allowance(address owner, address spender) public view returns (uint256);
11+
function transferFrom(address from, address to, uint256 value) public returns (bool);
12+
function approve(address spender, uint256 value) public returns (bool);
13+
event Approval(address indexed owner, address indexed spender, uint256 value);
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pragma solidity ^0.4.23;
2+
3+
/**
4+
* @title ERC20Basic
5+
* @dev Simpler version of ERC20 interface
6+
* @dev see https://github.com/ethereum/EIPs/issues/179
7+
*/
8+
contract ERC20Basic {
9+
function totalSupply() public view returns (uint256);
10+
function balanceOf(address who) public view returns (uint256);
11+
function transfer(address to, uint256 value) public returns (bool);
12+
event Transfer(address indexed from, address indexed to, uint256 value);
13+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
pragma solidity ^0.4.23;
2+
3+
import "./ERC20.sol";
4+
import "./BasicToken.sol";
5+
import "../SafeMath/SafeMath.sol";
6+
7+
/**
8+
* @title Standard ERC20 token
9+
*
10+
* @dev Implementation of the basic standard token.
11+
* @dev https://github.com/ethereum/EIPs/issues/20
12+
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
13+
*/
14+
contract StandardToken is ERC20, BasicToken {
15+
16+
mapping (address => mapping (address => uint256)) internal allowed;
17+
18+
/**
19+
* @dev Transfer tokens from one address to another
20+
* @param _from address The address which you want to send tokens from
21+
* @param _to address The address which you want to transfer to
22+
* @param _value uint256 the amount of tokens to be transferred
23+
*/
24+
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
25+
require(_to != address(0));
26+
require(_value <= balances[_from]);
27+
require(_value <= allowed[_from][msg.sender]);
28+
29+
balances[_from] = balances[_from].sub(_value);
30+
balances[_to] = balances[_to].add(_value);
31+
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
32+
emit Transfer(_from, _to, _value);
33+
return true;
34+
}
35+
36+
/**
37+
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
38+
*
39+
* Beware that changing an allowance with this method brings the risk that someone may use both the old
40+
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
41+
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
42+
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
43+
* @param _spender The address which will spend the funds.
44+
* @param _value The amount of tokens to be spent.
45+
*/
46+
function approve(address _spender, uint256 _value) public returns (bool) {
47+
allowed[msg.sender][_spender] = _value;
48+
emit Approval(msg.sender, _spender, _value);
49+
return true;
50+
}
51+
52+
/**
53+
* @dev Function to check the amount of tokens that an owner allowed to a spender.
54+
* @param _owner address The address which owns the funds.
55+
* @param _spender address The address which will spend the funds.
56+
* @return A uint256 specifying the amount of tokens still available for the spender.
57+
*/
58+
function allowance(address _owner, address _spender) public view returns (uint256) {
59+
return allowed[_owner][_spender];
60+
}
61+
62+
/**
63+
* @dev Increase the amount of tokens that an owner allowed to a spender.
64+
*
65+
* approve should be called when allowed[_spender] == 0. To increment
66+
* allowed value is better to use this function to avoid 2 calls (and wait until
67+
* the first transaction is mined)
68+
* From MonolithDAO Token.sol
69+
* @param _spender The address which will spend the funds.
70+
* @param _addedValue The amount of tokens to increase the allowance by.
71+
*/
72+
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
73+
allowed[msg.sender][_spender] = (
74+
allowed[msg.sender][_spender].add(_addedValue));
75+
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
76+
return true;
77+
}
78+
79+
/**
80+
* @dev Decrease the amount of tokens that an owner allowed to a spender.
81+
*
82+
* approve should be called when allowed[_spender] == 0. To decrement
83+
* allowed value is better to use this function to avoid 2 calls (and wait until
84+
* the first transaction is mined)
85+
* From MonolithDAO Token.sol
86+
* @param _spender The address which will spend the funds.
87+
* @param _subtractedValue The amount of tokens to decrease the allowance by.
88+
*/
89+
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
90+
uint oldValue = allowed[msg.sender][_spender];
91+
92+
if (_subtractedValue > oldValue) {
93+
allowed[msg.sender][_spender] = 0;
94+
} else {
95+
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
96+
}
97+
98+
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
99+
return true;
100+
}
101+
102+
}

0 commit comments

Comments
 (0)