Advertisement
Akuukis

FIC Network - Ethereum smart contract

Jul 11th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. pragma solidity 0.4.24;
  2.  
  3. import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
  4. import "openzeppelin-solidity/contracts/math/SafeMath.sol";
  5.  
  6. contract FicWithdrawal is Ownable {
  7. using SafeMath for uint256;
  8.  
  9. uint256 public constant ICO_COINS = 150000000000e18; // 150 000 000 000
  10. uint256 public constant MIN_WITHDRAW_AMOUNT = 1200e18; // min withdraw amount is 50 coins
  11.  
  12. // maps an address to lockup time (only 0, 90 and 180 values are permitted) to balance
  13. mapping(address => mapping(uint8 => uint256)) internal coinBalance;
  14.  
  15. // amount of raised money in USD
  16. uint256 internal coinTotalSupply = 0;
  17.  
  18. address public coinMinter;
  19.  
  20. /**
  21. * When there no coins left to mint and coin minter tries to manually mint coins
  22. * this event is raised to signal how many coins we have to charge back to purchaser
  23. */
  24. event ManualCoinMintRequiresRefund(address indexed purchaser, uint256 value);
  25.  
  26. /**
  27. * event for coin convertion logging
  28. * @param who performed withdrawal. Can an user himself or owner
  29. * @param beneficiary who got the coins
  30. * @param publicKey user publicKey from FIC Network
  31. * @param amount of withdrawn coins
  32. * @param lockup how long to lock users coins in FIC Network
  33. */
  34. event Withdraw(address indexed who, address indexed beneficiary, bytes32 indexed publicKey, uint256 amount, uint8 lockup);
  35.  
  36. /**
  37. * Function for user to withdraw purchased coins and converting them to FIC Network coins
  38. * @param publicKey user publicKey from FIC Network
  39. * @param amount of withdrawn coins
  40. * @param lockup how long to lock users coins in FIC Network
  41. */
  42. function withdraw(bytes32 publicKey, uint256 amount, uint8 lockup) external {
  43. performWithdraw(msg.sender, publicKey, amount, lockup);
  44. }
  45.  
  46. /**
  47. * Function for owner to withdraw purchased coins for user, if he cannot do it himself for some reason
  48. * @param beneficiary user for whom coins are withdrawn
  49. * @param publicKey user publicKey from FIC Network
  50. * @param amount of withdrawn coins, including e18
  51. * @param lockup how long to lock users coins in FIC Network (0, 90 or 180)
  52. */
  53. function withdrawFor(address beneficiary, bytes32 publicKey, uint256 amount, uint8 lockup) external onlyOwner {
  54. performWithdraw(beneficiary, publicKey, amount, lockup);
  55. }
  56.  
  57. function mintCoins(address[] _receivers, uint256[] _amounts, uint8[] _lockups) external {
  58. require(msg.sender == coinMinter || msg.sender == owner);
  59. require(_receivers.length > 0 && _receivers.length <= 100);
  60. require(_receivers.length == _amounts.length && _receivers.length == _lockups.length);
  61.  
  62. uint256 coinsLeft = ICO_COINS.sub(coinTotalSupply);
  63. require(coinsLeft > 0);
  64.  
  65. for (uint256 i = 0; i < _receivers.length; i++) {
  66. address receiver = _receivers[i];
  67. uint256 amount = _amounts[i];
  68. uint8 lockup = _lockups[i];
  69. require(lockup == 0 || lockup == 90 || lockup == 180);
  70.  
  71. if (amount <= coinsLeft) {
  72. mint(receiver, amount, lockup);
  73. coinsLeft = coinsLeft.sub(amount);
  74. } else {
  75. if (coinsLeft > 0) {
  76. mint(receiver, coinsLeft, lockup);
  77. }
  78.  
  79. emit ManualCoinMintRequiresRefund(receiver, amount.sub(coinsLeft));
  80. coinsLeft = 0;
  81. }
  82. }
  83. }
  84.  
  85. function setCoinMinter(address _coinMinter) public onlyOwner {
  86. require(_coinMinter != address(0));
  87. coinMinter = _coinMinter;
  88. }
  89.  
  90. function getBalances(address _holder) public view returns (uint256, uint256, uint256) {
  91. return (
  92. coinBalance[_holder][0],
  93. coinBalance[_holder][90],
  94. coinBalance[_holder][180]
  95. );
  96. }
  97.  
  98. function getCoinTotalSupply() public view returns (uint256) {
  99. return coinTotalSupply;
  100. }
  101.  
  102. function mint(address receiver, uint256 amount, uint8 lockup) internal {
  103. coinBalance[receiver][lockup] = coinBalance[receiver][lockup].add(amount);
  104. coinTotalSupply = coinTotalSupply.add(amount);
  105. }
  106.  
  107. function performWithdraw(address beneficiary, bytes32 publicKey, uint256 amount, uint8 lockup) internal {
  108. require(publicKey != 0x0);
  109. require(amount >= MIN_WITHDRAW_AMOUNT);
  110. require(lockup == 0 || lockup == 90 || lockup == 180);
  111.  
  112. uint256 actualAmount = amount;
  113. uint256 actualBalance = coinBalance[beneficiary][lockup];
  114.  
  115. require(actualBalance >= actualAmount);
  116.  
  117. coinBalance[beneficiary][lockup] = actualBalance.sub(actualAmount);
  118. coinTotalSupply = coinTotalSupply.sub(actualAmount);
  119.  
  120. emit Withdraw(msg.sender, beneficiary, publicKey, amount, lockup);
  121. }
  122.  
  123. function getNow() internal view returns (uint256) {
  124. return now;
  125. }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement