Skip to content

Commit 1bca9b0

Browse files
authored
Create AmisErc223.sol
1 parent a4b33c4 commit 1bca9b0

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

Diff for: contracts/AmisErc223.sol

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// # https://remix.ethereum.org/#version=soljson-v0.5.24+commit.e67f0147.js&optimize=true&gist=7f2a15679aee59fba912aa929f70df1d
2+
//
3+
pragma solidity ^0.5.24;
4+
5+
contract ERC223 {
6+
uint public totalSupply;
7+
function balanceOf(address who) public view returns (uint);
8+
9+
function name() public view returns (string _name);
10+
function symbol() public view returns (string _symbol);
11+
function decimals() public view returns (uint8 _decimals);
12+
function totalSupply() public view returns (uint256 _supply);
13+
14+
function transfer(address to, uint value) public returns (bool ok);
15+
function transfer(address to, uint value, bytes data) public returns (bool ok);
16+
function transfer(address to, uint value, bytes data, string custom_fallback) public returns (bool ok);
17+
18+
event Transfer(address indexed from, address indexed to, uint value, bytes indexed data);
19+
20+
}
21+
22+
23+
library SafeMath {
24+
25+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
26+
uint256 c = a + b;
27+
require(c >= a, "SafeMath: addition overflow");
28+
29+
return c;
30+
}
31+
32+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
33+
require(b <= a, "SafeMath: subtraction overflow");
34+
uint256 c = a - b;
35+
36+
return c;
37+
}
38+
39+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
40+
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
41+
// benefit is lost if 'b' is also tested.
42+
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
43+
if (a == 0) {
44+
return 0;
45+
}
46+
47+
uint256 c = a * b;
48+
require(c / a == b, "SafeMath: multiplication overflow");
49+
50+
return c;
51+
}
52+
53+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
54+
// Solidity only automatically asserts when dividing by 0
55+
require(b > 0, "SafeMath: division by zero");
56+
uint256 c = a / b;
57+
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
58+
59+
return c;
60+
}
61+
62+
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
63+
require(b != 0, "SafeMath: modulo by zero");
64+
return a % b;
65+
}
66+
}
67+
68+
// change contract name to your contract's name
69+
// i.e. "contract AMIS is ERC223Token"
70+
contract YourNewToken is ERC223Token {
71+
using SafeMath for uint256;
72+
// for example, "AMIS"
73+
string public name = "AMIS";
74+
// for example, "BTC"
75+
string public symbol = "AMIS";
76+
// set token's precision
77+
// pick any number from 0 to 18
78+
// for example, 9 decimal points means that
79+
// smallest token unit will be 0.000000001 AMIS
80+
uint public decimals = 9;
81+
// total supply of the token
82+
// for example, for Bitcoin it would be 21000000
83+
uint public totalSupply = 100000000000000 * (10**decimals);
84+
85+
address private treasury = 0x5b878ba97bae92fc0aa6133edbf2f58d52350d65;
86+
87+
// ICE price. You will need to do a little bit of math to figure it out
88+
// given 9 decimals
89+
uint256 private priceDiv = 2000000000;
90+
event Purchase(address indexed purchaser, uint256 amount);
91+
92+
constructor() public {
93+
// This is how many tokens you want to allocate to yourself
94+
balances[msg.sender] = 9500000000000 * (10**decimals);
95+
// This is how many tokens you want to allocate for ICE
96+
balances[0x0] = 90500000000000 * (10**decimals);
97+
}
98+
function () public payable {
99+
bytes memory empty;
100+
if (msg.value == 0) { revert(); }
101+
uint256 purchasedAmount = msg.value.div(priceDiv);
102+
if (purchasedAmount == 0) { revert(); } // not enough ETC sent
103+
if (purchasedAmount > balances[0x0]) { revert(); } // too much ETC sent
104+
105+
treasury.transfer(msg.value);
106+
balances[0x0] = balances[0x0].sub(purchasedAmount);
107+
balances[msg.sender] = balances[msg.sender].add(purchasedAmount);
108+
109+
emit Transfer(0x0, msg.sender, purchasedAmount);
110+
emit ERC223Transfer(0x0, msg.sender, purchasedAmount, empty);
111+
emit Purchase(msg.sender, purchasedAmount);
112+
}
113+
}

0 commit comments

Comments
 (0)