Guest User

Untitled

a guest
Aug 14th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.42 KB | None | 0 0
  1. pragma solidity ^0.4.0;
  2.  
  3. contract owned {
  4. address public owner;
  5.  
  6. constructor() public {
  7. owner = msg.sender;
  8. }
  9.  
  10. modifier onlyOwner {
  11. require(msg.sender == owner);
  12. _;
  13. }
  14.  
  15. function transferableOwnership(address newOwner) onlyOwner public {
  16. owner = newOwner;
  17. }
  18. }
  19.  
  20. interface tokenRecepient {
  21. function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external;
  22. }
  23.  
  24. contract TokenERC20 {
  25. // Public variables of Token
  26.  
  27. string public name;
  28. string public symbol;
  29. uint8 public decimal = 18; // 18 decimal values is strongly suggested. Avoid changing it
  30.  
  31. uint256 public totalSupply;
  32.  
  33. // This creates an array with all balances
  34. mapping (address => uint256) public balanceof;
  35. mapping (address => mapping (address => uint256)) public allowance;
  36.  
  37. // This generates a public events on blockchain that will notify clients
  38. event Transfer(address indexed from, address indexed to , uint256 value);
  39.  
  40. // This generates a public events on blockchain that will notify clients
  41. event Approval(address indexed _owner, address indexed _spender, uint256 _value);
  42.  
  43. // This notified client ablout the amount burns
  44. event Burn(address indexed From, uint256 value);
  45.  
  46. // /**
  47. // * constructor function
  48. // *
  49. // * Initializes contract with initial supply tokens with creator of contract
  50. // */
  51.  
  52. constructor(uint256 initialSupply, string tokenName, string tokenSymbol) public {
  53. totalSupply = initialSupply * 10 ** uint256(decimal); // update total supply with decimal amount
  54. balanceof[msg.sender] = totalSupply; // Give the creator all initial token
  55. name = tokenName; // the name for display purpose
  56. symbol = tokenSymbol; // the symbol for display purpose
  57. }
  58.  
  59. /**
  60. * Internal transfer, only can be handled by this contract
  61. */
  62.  
  63. function _transfer(address _from, address _to, uint _value) internal {
  64. // Prevent transfer to 0x0 address. Use burn() instead
  65. require(_to != 0x0);
  66.  
  67. // Check if the sender has enough
  68. require(balanceof[_from] >= _value);
  69.  
  70. // Check for overflow
  71. require(balanceof[_to] + _value > balanceof[_to]);
  72.  
  73. // Save this for assestion in future
  74. uint previousBalances = balanceof[_from] + balanceof[_to];
  75.  
  76. // Subtract from the sender
  77. balanceof[_from] -= _value;
  78.  
  79. // Add the same to the recipient
  80. balanceof[_to] += _value;
  81.  
  82. emit Transfer(_from, _to, _value);
  83.  
  84. // Assert are used to use static analysis to find bugs in your code. They should never fail.
  85. assert(balanceof[_to] + balanceof[_from] == previousBalances);
  86.  
  87. }
  88.  
  89. /**
  90. * Token Transfer
  91. *
  92. * Send '_value' tokens to '_to' in behalf of '_from'
  93. *
  94. * @param _to The address of the receiver
  95. * @param _value the amount to send
  96. *
  97. */
  98.  
  99. function transfer(address _to, uint256 _value) public returns (bool success) {
  100. _transfer(msg.sender, _to, _value);
  101. return true;
  102. }
  103.  
  104. /**
  105. * Token Transfer from other Address
  106. *
  107. * Send '_value' tokens to '_to' in behalf of '_from'
  108. *
  109. * @param _from The address of the sender
  110. * @param _to The address of the receiver
  111. * @param _value the amount to send
  112. *
  113. */
  114.  
  115. function transferFrom(address _to, address _from ,uint256 _value) public returns (bool success) {
  116. require(_value <= allowance[_from][msg.sender]); // check allowance
  117. _transfer(_from, _to, _value);
  118. return true;
  119. }
  120.  
  121. /**
  122. * Set allowance for other address
  123. *
  124. * Allows `_spender` to spend no more than `_value` tokens in your behalf
  125. *
  126. * @param _spender The address authorized to spend
  127. * @param _value the max amount they can spend
  128. *
  129. */
  130.  
  131. function approve(address _spender, uint256 _value) public returns (bool success) {
  132. allowance[msg.sender][_spender] = _value;
  133. emit Approval(msg.sender, _spender, _value);
  134. return true;
  135. }
  136.  
  137.  
  138. /**
  139. * Set allowance for other address and notify
  140. *
  141. * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
  142. *
  143. * @param _spender The address authorized to spend
  144. * @param _value the max amount they can spend
  145. * @param _extraData some extra information to send to the approved contract
  146. */
  147.  
  148. function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
  149. tokenRecepient spender = tokenRecepient(_spender);
  150. if(approve(_spender, _value)) {
  151. spender.receiveApproval(msg.sender, _value, this, _extraData);
  152. return true;
  153. }
  154. }
  155.  
  156. /**
  157. *
  158. * Remove '_value' token from the system irreversibly
  159. *
  160. * @param _value the amount to burn
  161. *
  162. */
  163.  
  164. function burn(uint256 _value) public returns (bool success) {
  165. require(balanceof[msg.sender] >= _value); // Check if sender has enough
  166. balanceof[msg.sender] -= _value; // Subtract from the sender
  167. totalSupply -= _value; // Updates total supply
  168. emit Burn(msg.sender, _value);
  169. return true;
  170. }
  171.  
  172.  
  173. /**
  174. * Destroy tokens from other account
  175. *
  176. * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
  177. *
  178. * @param _from the address of the sender
  179. * @param _value the amount of money to burn
  180. */
  181.  
  182. function burnFrom(address _from, uint256 _value) public returns (bool success) {
  183. require(balanceof[_from] >= _value); // Check if targeted balance is enough
  184. require(_value <= allowance[_from][msg.sender]); // Check allowance
  185. balanceof[_from] -= _value; // Subtract from the targeted balanceof
  186. allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
  187. totalSupply -= _value; // Update totalSupply
  188. emit Burn(_from, _value);
  189. return true;
  190. }
  191.  
  192. // function burnFrom(address _from, uint256 _value) public returns (bool success) {
  193. // require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
  194. // require(_value <= allowance[_from][msg.sender]); // Check allowance
  195. // balanceOf[_from] -= _value; // Subtract from the targeted balance
  196. // allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
  197. // totalSupply -= _value; // Update totalSupply
  198. // emit Burn(_from, _value);
  199. // return true;
  200. // }
  201.  
  202.  
  203. }
  204.  
  205. contract Sikka is owned, TokenERC20 {
  206. uint256 public sellPrice;
  207. uint256 public buyPrice;
  208.  
  209. mapping(address => bool) public frozenAccount;
  210.  
  211. /* This generates a public event in blockchain that will notify clients */
  212.  
  213. event FrozenFunds(address target, bool frozen);
  214.  
  215. /* Initialize contract with initial supply tokens to the creator of the contract */
  216.  
  217. constructor(
  218. uint256 initialSupply,
  219. string tokenName,
  220. string tokenSymbol
  221. ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}
  222.  
  223. /* Internal transfer, only can be called by this contract */
  224.  
  225. function _transfer(address _from, address _to, uint _value) internal {
  226. require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
  227. require (balanceof[_from] >= _value); // Check if the sender has enough
  228. require (balanceof[_to] + _value >= balanceof[_to]); // Check for overflows
  229. require(!frozenAccount[_from]); // Check if sender is frozen
  230. require(!frozenAccount[_to]); // Check if recipient is frozen
  231. balanceof[_from] -= _value; // Subtract from the sender
  232. balanceof[_to] += _value; // Add the same to the recipient
  233. emit Transfer(_from, _to, _value);
  234. }
  235.  
  236. /// @notice Create `mintedAmount` tokens and send it to `target`
  237. /// @param target Address to receive the tokens
  238. /// @param mintedAmount the amount of tokens it will receive
  239. function mintToken(address target, uint256 mintedAmount) onlyOwner public {
  240. balanceof[target] += mintedAmount;
  241. totalSupply += mintedAmount;
  242. emit Transfer(0, this, mintedAmount);
  243. emit Transfer(this, target, mintedAmount);
  244. }
  245.  
  246. /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
  247. /// @param target Address to be frozen
  248. /// @param freeze either to freeze it or not
  249. function freezeAccount(address target, bool freeze) onlyOwner public {
  250. frozenAccount[target] = freeze;
  251. emit FrozenFunds(target, freeze);
  252. }
  253.  
  254.  
  255. /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
  256. /// @param newSellPrice Price the users can sell to the contract
  257. /// @param newBuyPrice Price users can buy from the contract
  258. function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
  259. sellPrice = newSellPrice;
  260. buyPrice = newBuyPrice;
  261. }
  262. /// @notice Buy tokens from contract by sending ether
  263. function buy() payable public {
  264. uint amount = msg.value / buyPrice; // calculates the amount
  265. _transfer(this, msg.sender, amount); // makes the transfers
  266. }
  267. /// @notice Sell `amount` tokens to contract
  268. /// @param amount amount of tokens to be sold
  269. function sell(uint256 amount) public {
  270. address myAddress = this;
  271. require(myAddress.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
  272. _transfer(msg.sender, this, amount); // makes the transfers
  273. msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
  274. }
  275. }
Add Comment
Please, Sign In to add comment