File size: 4,939 Bytes
dec6d5d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
pragma solidity ^0.4.24;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}
contract Claimable is Ownable {
address public pendingOwner;
modifier onlyPendingOwner() {
require(msg.sender == pendingOwner);
_;
}
function transferOwnership(address newOwner) onlyOwner public {
pendingOwner = newOwner;
}
function claimOwnership() onlyPendingOwner public {
emit OwnershipTransferred(owner, pendingOwner);
owner = pendingOwner;
pendingOwner = address(0);
}
}
contract SimpleFlyDropToken is Claimable {
using SafeMath for uint256;
ERC20 internal erc20tk;
function setToken(address _token) onlyOwner public {
require(_token != address(0));
erc20tk = ERC20(_token);
}
function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
require(_destAddrs.length == _values.length);
uint256 i = 0;
for (; i < _destAddrs.length; i = i.add(1)) {
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
break;
}
}
return (i);
}
}
contract DelayedClaimable is Claimable {
uint256 public end;
uint256 public start;
function setLimits(uint256 _start, uint256 _end) onlyOwner public {
require(_start <= _end);
end = _end;
start = _start;
}
function claimOwnership() onlyPendingOwner public {
require((block.number <= end) && (block.number >= start));
emit OwnershipTransferred(owner, pendingOwner);
owner = pendingOwner;
pendingOwner = address(0);
end = 0;
}
}
contract FlyDropTokenMgr is DelayedClaimable {
using SafeMath for uint256;
address[] dropTokenAddrs;
SimpleFlyDropToken currentDropTokenContract;
function prepare(uint256 _rand,
address _from,
address _token,
uint256 _value) onlyOwner public returns (bool) {
require(_token != address(0));
require(_from != address(0));
require(_rand > 0);
if (ERC20(_token).allowance(_from, this) < _value) {
return false;
}
if (_rand > dropTokenAddrs.length) {
SimpleFlyDropToken dropTokenContract = new SimpleFlyDropToken();
dropTokenAddrs.push(address(dropTokenContract));
currentDropTokenContract = dropTokenContract;
} else {
currentDropTokenContract = SimpleFlyDropToken(dropTokenAddrs[_rand.sub(1)]);
}
currentDropTokenContract.setToken(_token);
return ERC20(_token).transferFrom(_from, currentDropTokenContract, _value);
}
function flyDrop(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
require(address(currentDropTokenContract) != address(0));
return currentDropTokenContract.multiSend(_destAddrs, _values);
}
}
contract ERC20Basic {
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
}
contract ERC20 is ERC20Basic {
function allowance(address owner, address spender)
public view returns (uint256);
function transferFrom(address from, address to, uint256 value)
public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
} |