/** * Copyright 2017–2018, LaborX PTY * Licensed under the AGPL Version 3 license. */ pragma solidity ^0.4.25; import "@laborx/solidity-shared-contracts/contracts/ERC20Interface.sol"; import "@laborx/solidity-shared-contracts/contracts/Owned.sol"; import "./escrow/erc20/ERC20Manager.sol"; /// @title AssetDonator /// @notice Created only for test purposes! Do not allow to deploy this contract in production network. contract AssetDonator is Owned { address private erc20Manager; uint constant public COOLDOWN_PERIOD = 1 days; mapping (bytes32 => uint) public nextPeriods; mapping (bytes32 => uint) public donationSizes; mapping (bytes32 => bool) public onlyOnce; function setTokenManager(address _erc20Manager) onlyContractOwner external { require(_erc20Manager != 0x0); erc20Manager = _erc20Manager; } function setDonationSize( bytes32 _symbol, uint _donationSize, bool _onlyOnce ) external onlyContractOwner { donationSizes[_symbol] = _donationSize; onlyOnce[_symbol] = _onlyOnce; } /// @notice Sends `_tokenSymbol` `donationSizes[_tokenSymbol]` tokens to caller. /// @notice It is permitted to send in `COOLDOWN_PERIOD` period /// @return success or not function requestToken(bytes32 _tokenSymbol) public returns (bool) { bytes32 _faucetKey = keccak256(abi.encodePacked(_tokenSymbol, msg.sender)); if ( !onlyOnce[_tokenSymbol] && nextPeriods[_faucetKey] > block.timestamp || // need to wait onlyOnce[_tokenSymbol] && nextPeriods[_faucetKey] != 0 // it is not the first time for onlyOnce == true ) { return false; } address token = ERC20Manager(erc20Manager).getTokenAddressBySymbol(_tokenSymbol); if (!ERC20Interface(token).transfer(msg.sender, donationSizes[_tokenSymbol])) { return false; } nextPeriods[_faucetKey] = block.timestamp + COOLDOWN_PERIOD; return true; } }