Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity 0.4.24;
- import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
- import "openzeppelin-solidity/contracts/math/SafeMath.sol";
- contract FicWithdrawal is Ownable {
- using SafeMath for uint256;
- uint256 public constant ICO_COINS = 150000000000e18; // 150 000 000 000
- uint256 public constant MIN_WITHDRAW_AMOUNT = 1200e18; // min withdraw amount is 50 coins
- // maps an address to lockup time (only 0, 90 and 180 values are permitted) to balance
- mapping(address => mapping(uint8 => uint256)) internal coinBalance;
- // amount of raised money in USD
- uint256 internal coinTotalSupply = 0;
- address public coinMinter;
- /**
- * When there no coins left to mint and coin minter tries to manually mint coins
- * this event is raised to signal how many coins we have to charge back to purchaser
- */
- event ManualCoinMintRequiresRefund(address indexed purchaser, uint256 value);
- /**
- * event for coin convertion logging
- * @param who performed withdrawal. Can an user himself or owner
- * @param beneficiary who got the coins
- * @param publicKey user publicKey from FIC Network
- * @param amount of withdrawn coins
- * @param lockup how long to lock users coins in FIC Network
- */
- event Withdraw(address indexed who, address indexed beneficiary, bytes32 indexed publicKey, uint256 amount, uint8 lockup);
- /**
- * Function for user to withdraw purchased coins and converting them to FIC Network coins
- * @param publicKey user publicKey from FIC Network
- * @param amount of withdrawn coins
- * @param lockup how long to lock users coins in FIC Network
- */
- function withdraw(bytes32 publicKey, uint256 amount, uint8 lockup) external {
- performWithdraw(msg.sender, publicKey, amount, lockup);
- }
- /**
- * Function for owner to withdraw purchased coins for user, if he cannot do it himself for some reason
- * @param beneficiary user for whom coins are withdrawn
- * @param publicKey user publicKey from FIC Network
- * @param amount of withdrawn coins, including e18
- * @param lockup how long to lock users coins in FIC Network (0, 90 or 180)
- */
- function withdrawFor(address beneficiary, bytes32 publicKey, uint256 amount, uint8 lockup) external onlyOwner {
- performWithdraw(beneficiary, publicKey, amount, lockup);
- }
- function mintCoins(address[] _receivers, uint256[] _amounts, uint8[] _lockups) external {
- require(msg.sender == coinMinter || msg.sender == owner);
- require(_receivers.length > 0 && _receivers.length <= 100);
- require(_receivers.length == _amounts.length && _receivers.length == _lockups.length);
- uint256 coinsLeft = ICO_COINS.sub(coinTotalSupply);
- require(coinsLeft > 0);
- for (uint256 i = 0; i < _receivers.length; i++) {
- address receiver = _receivers[i];
- uint256 amount = _amounts[i];
- uint8 lockup = _lockups[i];
- require(lockup == 0 || lockup == 90 || lockup == 180);
- if (amount <= coinsLeft) {
- mint(receiver, amount, lockup);
- coinsLeft = coinsLeft.sub(amount);
- } else {
- if (coinsLeft > 0) {
- mint(receiver, coinsLeft, lockup);
- }
- emit ManualCoinMintRequiresRefund(receiver, amount.sub(coinsLeft));
- coinsLeft = 0;
- }
- }
- }
- function setCoinMinter(address _coinMinter) public onlyOwner {
- require(_coinMinter != address(0));
- coinMinter = _coinMinter;
- }
- function getBalances(address _holder) public view returns (uint256, uint256, uint256) {
- return (
- coinBalance[_holder][0],
- coinBalance[_holder][90],
- coinBalance[_holder][180]
- );
- }
- function getCoinTotalSupply() public view returns (uint256) {
- return coinTotalSupply;
- }
- function mint(address receiver, uint256 amount, uint8 lockup) internal {
- coinBalance[receiver][lockup] = coinBalance[receiver][lockup].add(amount);
- coinTotalSupply = coinTotalSupply.add(amount);
- }
- function performWithdraw(address beneficiary, bytes32 publicKey, uint256 amount, uint8 lockup) internal {
- require(publicKey != 0x0);
- require(amount >= MIN_WITHDRAW_AMOUNT);
- require(lockup == 0 || lockup == 90 || lockup == 180);
- uint256 actualAmount = amount;
- uint256 actualBalance = coinBalance[beneficiary][lockup];
- require(actualBalance >= actualAmount);
- coinBalance[beneficiary][lockup] = actualBalance.sub(actualAmount);
- coinTotalSupply = coinTotalSupply.sub(actualAmount);
- emit Withdraw(msg.sender, beneficiary, publicKey, amount, lockup);
- }
- function getNow() internal view returns (uint256) {
- return now;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement