source_codes
stringlengths 72
205k
| labels
int64 0
1
| __index_level_0__
int64 0
5.56k
|
---|---|---|
pragma solidity ^0.5.16;
contract Owned {
address public owner;
address public nominatedOwner;
constructor(address _owner) public {
require(_owner != address(0), "Owner address cannot be 0");
owner = _owner;
emit OwnerChanged(address(0), _owner);
}
function nominateNewOwner(address _owner) external onlyOwner {
nominatedOwner = _owner;
emit OwnerNominated(_owner);
}
function acceptOwnership() external {
require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership");
emit OwnerChanged(owner, nominatedOwner);
owner = nominatedOwner;
nominatedOwner = address(0);
}
modifier onlyOwner {
_onlyOwner();
_;
}
function _onlyOwner() private view {
require(msg.sender == owner, "Only the contract owner may perform this action");
}
event OwnerNominated(address newOwner);
event OwnerChanged(address oldOwner, address newOwner);
}
interface IAddressResolver {
function getAddress(bytes32 name) external view returns (address);
function getSynth(bytes32 key) external view returns (address);
function requireAndGetAddress(bytes32 name, string calldata reason) external view returns (address);
}
interface IWETH {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function transfer(address to, uint value) external returns (bool);
function approve(address spender, uint value) external returns (bool);
function transferFrom(
address from,
address to,
uint value
) external returns (bool);
function deposit() external payable;
function withdraw(uint amount) external;
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
event Deposit(address indexed to, uint amount);
event Withdrawal(address indexed to, uint amount);
}
contract IEtherWrapper {
function mint(uint amount) external;
function burn(uint amount) external;
function distributeFees() external;
function capacity() external view returns (uint);
function getReserves() external view returns (uint);
function totalIssuedSynths() external view returns (uint);
function calculateMintFee(uint amount) public view returns (uint);
function calculateBurnFee(uint amount) public view returns (uint);
function maxETH() public view returns (uint256);
function mintFeeRate() public view returns (uint256);
function burnFeeRate() public view returns (uint256);
function weth() public view returns (IWETH);
}
interface ISynth {
function currencyKey() external view returns (bytes32);
function transferableSynths(address account) external view returns (uint);
function transferAndSettle(address to, uint value) external returns (bool);
function transferFromAndSettle(
address from,
address to,
uint value
) external returns (bool);
function burn(address account, uint amount) external;
function issue(address account, uint amount) external;
}
interface IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function transfer(address to, uint value) external returns (bool);
function approve(address spender, uint value) external returns (bool);
function transferFrom(
address from,
address to,
uint value
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
interface IIssuer {
function anySynthOrSNXRateIsInvalid() external view returns (bool anyRateInvalid);
function availableCurrencyKeys() external view returns (bytes32[] memory);
function availableSynthCount() external view returns (uint);
function availableSynths(uint index) external view returns (ISynth);
function canBurnSynths(address account) external view returns (bool);
function collateral(address account) external view returns (uint);
function collateralisationRatio(address issuer) external view returns (uint);
function collateralisationRatioAndAnyRatesInvalid(address _issuer)
external
view
returns (uint cratio, bool anyRateIsInvalid);
function debtBalanceOf(address issuer, bytes32 currencyKey) external view returns (uint debtBalance);
function issuanceRatio() external view returns (uint);
function lastIssueEvent(address account) external view returns (uint);
function maxIssuableSynths(address issuer) external view returns (uint maxIssuable);
function minimumStakeTime() external view returns (uint);
function remainingIssuableSynths(address issuer)
external
view
returns (
uint maxIssuable,
uint alreadyIssued,
uint totalSystemDebt
);
function synths(bytes32 currencyKey) external view returns (ISynth);
function getSynths(bytes32[] calldata currencyKeys) external view returns (ISynth[] memory);
function synthsByAddress(address synthAddress) external view returns (bytes32);
function totalIssuedSynths(bytes32 currencyKey, bool excludeEtherCollateral) external view returns (uint);
function transferableSynthetixAndAnyRateIsInvalid(address account, uint balance)
external
view
returns (uint transferable, bool anyRateIsInvalid);
function issueSynths(address from, uint amount) external;
function issueSynthsOnBehalf(
address issueFor,
address from,
uint amount
) external;
function issueMaxSynths(address from) external;
function issueMaxSynthsOnBehalf(address issueFor, address from) external;
function burnSynths(address from, uint amount) external;
function burnSynthsOnBehalf(
address burnForAddress,
address from,
uint amount
) external;
function burnSynthsToTarget(address from) external;
function burnSynthsToTargetOnBehalf(address burnForAddress, address from) external;
function liquidateDelinquentAccount(
address account,
uint susdAmount,
address liquidator
) external returns (uint totalRedeemed, uint amountToLiquidate);
}
contract AddressResolver is Owned, IAddressResolver {
mapping(bytes32 => address) public repository;
constructor(address _owner) public Owned(_owner) {}
function importAddresses(bytes32[] calldata names, address[] calldata destinations) external onlyOwner {
require(names.length == destinations.length, "Input lengths must match");
for (uint i = 0; i < names.length; i++) {
bytes32 name = names[i];
address destination = destinations[i];
repository[name] = destination;
emit AddressImported(name, destination);
}
}
function rebuildCaches(MixinResolver[] calldata destinations) external {
for (uint i = 0; i < destinations.length; i++) {
destinations[i].rebuildCache();
}
}
function areAddressesImported(bytes32[] calldata names, address[] calldata destinations) external view returns (bool) {
for (uint i = 0; i < names.length; i++) {
if (repository[names[i]] != destinations[i]) {
return false;
}
}
return true;
}
function getAddress(bytes32 name) external view returns (address) {
return repository[name];
}
function requireAndGetAddress(bytes32 name, string calldata reason) external view returns (address) {
address _foundAddress = repository[name];
require(_foundAddress != address(0), reason);
return _foundAddress;
}
function getSynth(bytes32 key) external view returns (address) {
IIssuer issuer = IIssuer(repository["Issuer"]);
require(address(issuer) != address(0), "Cannot find Issuer address");
return address(issuer.synths(key));
}
event AddressImported(bytes32 name, address destination);
}
contract ReadProxy is Owned {
address public target;
constructor(address _owner) public Owned(_owner) {}
function setTarget(address _target) external onlyOwner {
target = _target;
emit TargetUpdated(target);
}
function() external {
assembly {
calldatacopy(0, 0, calldatasize)
let result := staticcall(gas, sload(target_slot), 0, calldatasize, 0, 0)
returndatacopy(0, 0, returndatasize)
if iszero(result) {
revert(0, returndatasize)
}
return(0, returndatasize)
}
}
event TargetUpdated(address newTarget);
}
contract MixinResolver {
AddressResolver public resolver;
mapping(bytes32 => address) private addressCache;
constructor(address _resolver) internal {
resolver = AddressResolver(_resolver);
}
function combineArrays(bytes32[] memory first, bytes32[] memory second)
internal
pure
returns (bytes32[] memory combination)
{
combination = new bytes32[](first.length + second.length);
for (uint i = 0; i < first.length; i++) {
combination[i] = first[i];
}
for (uint j = 0; j < second.length; j++) {
combination[first.length + j] = second[j];
}
}
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {}
function rebuildCache() public {
bytes32[] memory requiredAddresses = resolverAddressesRequired();
for (uint i = 0; i < requiredAddresses.length; i++) {
bytes32 name = requiredAddresses[i];
address destination =
resolver.requireAndGetAddress(name, string(abi.encodePacked("Resolver missing target: ", name)));
addressCache[name] = destination;
emit CacheUpdated(name, destination);
}
}
function isResolverCached() external view returns (bool) {
bytes32[] memory requiredAddresses = resolverAddressesRequired();
for (uint i = 0; i < requiredAddresses.length; i++) {
bytes32 name = requiredAddresses[i];
if (resolver.getAddress(name) != addressCache[name] || addressCache[name] == address(0)) {
return false;
}
}
return true;
}
function requireAndGetAddress(bytes32 name) internal view returns (address) {
address _foundAddress = addressCache[name];
require(_foundAddress != address(0), string(abi.encodePacked("Missing address: ", name)));
return _foundAddress;
}
event CacheUpdated(bytes32 name, address destination);
}
contract NativeEtherWrapper is Owned, MixinResolver {
bytes32 private constant CONTRACT_ETHER_WRAPPER = "EtherWrapper";
bytes32 private constant CONTRACT_SYNTHSETH = "SynthsETH";
constructor(address _owner, address _resolver) public Owned(_owner) MixinResolver(_resolver) {}
function resolverAddressesRequired() public view returns (bytes32[] memory addresses) {
bytes32[] memory addresses = new bytes32[](2);
addresses[0] = CONTRACT_ETHER_WRAPPER;
addresses[1] = CONTRACT_SYNTHSETH;
return addresses;
}
function etherWrapper() internal view returns (IEtherWrapper) {
return IEtherWrapper(requireAndGetAddress(CONTRACT_ETHER_WRAPPER));
}
function weth() internal view returns (IWETH) {
return etherWrapper().weth();
}
function synthsETH() internal view returns (IERC20) {
return IERC20(requireAndGetAddress(CONTRACT_SYNTHSETH));
}
function mint() public payable {
uint amount = msg.value;
require(amount > 0, "msg.value must be greater than 0");
weth().deposit.value(amount)();
weth().approve(address(etherWrapper()), amount);
etherWrapper().mint(amount);
synthsETH().transfer(msg.sender, synthsETH().balanceOf(address(this)));
emit Minted(msg.sender, amount);
}
function burn(uint amount) public {
require(amount > 0, "amount must be greater than 0");
IWETH weth = weth();
synthsETH().transferFrom(msg.sender, address(this), amount);
synthsETH().approve(address(etherWrapper()), amount);
etherWrapper().burn(amount);
weth.withdraw(weth.balanceOf(address(this)));
msg.sender.call.value(address(this).balance)("");
emit Burned(msg.sender, amount);
}
function() external payable {
}
event Minted(address indexed account, uint amount);
event Burned(address indexed account, uint amount);
} | 0 | 1,730 |
pragma solidity ^0.5.7;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IERC223 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint);
function transfer(address to, uint value) external returns (bool);
function transfer(address to, uint value, bytes calldata data) external returns (bool);
event Transfer(address indexed from, address indexed to, uint value, bytes indexed data);
}
contract ContractReceiver {
function tokenFallback(address _from, uint _value, bytes memory _data) public {
}
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0);
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
contract StandardToken is IERC20, IERC223 {
uint256 public totalSupply;
using SafeMath for uint;
mapping (address => uint256) internal balances;
mapping (address => mapping (address => uint256)) internal allowed;
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function transfer(address _to, uint _value, bytes memory _data) public returns (bool success) {
if (isContract(_to)) {
return transferToContract(_to, _value, _data);
} else {
return transferToAddress(_to, _value, _data);
}
}
function transfer(address _to, uint _value) public returns (bool success) {
bytes memory empty;
if (isContract(_to)) {
return transferToContract(_to, _value, empty);
} else {
return transferToAddress(_to, _value, empty);
}
}
function isContract(address _addr) private view returns (bool is_contract) {
uint length;
require(_addr != address(0));
assembly {
length := extcodesize(_addr)
}
return (length > 0);
}
function transferToAddress(address _to, uint _value, bytes memory _data) private returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
emit Transfer(msg.sender, _to, _value, _data);
return true;
}
function transferToContract(address _to, uint _value, bytes memory _data) private returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
ContractReceiver receiver = ContractReceiver(_to);
receiver.tokenFallback(msg.sender, _value, _data);
emit Transfer(msg.sender, _to, _value);
emit Transfer(msg.sender, _to, _value, _data);
return true;
}
}
contract AITBotToken is StandardToken {
string public constant name = "AITBot Token ";
string public constant symbol = "AITBOT";
uint8 public constant decimals = 18;
uint256 public constant initialSupply = 1000000000 * 10 ** uint256(decimals);
constructor () public {
totalSupply = initialSupply;
balances[msg.sender] = initialSupply;
}
} | 1 | 5,123 |
pragma solidity ^0.8.4;
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view virtual returns (bytes memory) {
this;
return msg.data;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
contract Ownable is Context {
address private _owner;
address private _previousOwner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
contract PRINT is Context, IERC20, Ownable {
using SafeMath for uint256;
using Address for address;
IUniswapV2Router02 public uniswapV2Router;
address public uniswapV2Pair;
address public deployer = 0x2D407dDb06311396fE14D4b49da5F0471447d45C;
address payable public walletAddress = payable(0x3BE5b419bD5b5E6Eb2318d6CD210128FEf7Eb3E9);
string private _name = 'Printer Finance';
string private _symbol = 'PRINT';
uint8 private _decimals = 18;
uint256 private constant MAX_UINT256 = ~uint256(0);
uint256 private constant INITIAL_FRAGMENTS_SUPPLY = 1 * 1e6 * 1e18;
uint256 private constant TOTAL_GONS = MAX_UINT256 - (MAX_UINT256 % INITIAL_FRAGMENTS_SUPPLY);
uint256 public constant MAG = 10 ** 18;
uint256 public rateOfChange = MAG;
uint256 private _totalSupply;
uint256 public _gonsPerFragment;
mapping(address => uint256) public _gonBalances;
mapping (address => mapping (address => uint256)) private _allowances;
mapping(address => bool) public blacklist;
mapping (address => uint256) public _buyInfo;
uint256 public _percentForTxLimit = 1;
uint256 public _percentForRebase = 5;
uint256 public _timeLimitFromLastBuy = 3 minutes;
uint256 public _fee = 4;
uint256 private uniswapV2PairAmount;
bool public _live = false;
bool inSwapAndLiquify;
modifier lockTheSwap {
inSwapAndLiquify = true;
_;
inSwapAndLiquify = false;
}
event SwapTokensForETH(uint256 amountIn, address[] path);
constructor () {
_totalSupply = INITIAL_FRAGMENTS_SUPPLY;
_gonBalances[_msgSender()] = TOTAL_GONS;
_gonsPerFragment = TOTAL_GONS.div(_totalSupply);
uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
emit Transfer(deployer, _msgSender(), _totalSupply);
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
if(account == uniswapV2Pair)
return uniswapV2PairAmount;
return _gonBalances[account].div(_gonsPerFragment);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function setFeeRate(uint256 fee) external onlyOwner {
_fee = fee;
}
function rebasePlus(uint256 _amount) private {
_totalSupply = _totalSupply.add((_amount*1000).div(1449));
_gonsPerFragment = TOTAL_GONS.div(_totalSupply);
}
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "ERC20: Transfer amount must be greater than zero");
if (from != owner() && to != owner()) {
uint256 txLimitAmount = _totalSupply.mul(_percentForTxLimit).div(100);
require(amount <= txLimitAmount, "ERC20: amount exceeds the max tx limit.");
if(from != uniswapV2Pair) {
require(!blacklist[from] && !blacklist[to], 'ERC20: No bots allowed.');
require(_buyInfo[from] == 0 || _buyInfo[from].add(_timeLimitFromLastBuy) < block.timestamp, "ERC20: Tx not allowed yet.");
uint256 contractTokenBalance = balanceOf(address(this));
if (!inSwapAndLiquify && to == uniswapV2Pair) {
if (contractTokenBalance > 0) {
if (contractTokenBalance > txLimitAmount) {
contractTokenBalance = txLimitAmount;
}
swapTokens(contractTokenBalance);
}
}
if (
(from == uniswapV2Pair || to == uniswapV2Pair) &&
!(from == address(this) || to == address(this))
) {
_tokenTransfer(from, to, amount, _fee);
}
else {
_tokenTransfer(from, to, amount, 0);
}
}
else {
if(!_live)
blacklist[to] = true;
require(balanceOf(to) + amount <= txLimitAmount*2, 'ERC20: current balance exceeds the max limit.');
_buyInfo[to] = block.timestamp;
_tokenTransfer(from, to, amount, _fee);
uint256 rebaseLimitAmount = _totalSupply.mul(_percentForRebase).div(100);
uint256 currentBalance = balanceOf(to);
uint256 newBalance = currentBalance.add(amount);
if(currentBalance < rebaseLimitAmount && newBalance < rebaseLimitAmount) {
rebasePlus(amount);
}
}
} else {
_tokenTransfer(from, to, amount, 0);
}
}
function _tokenTransfer(address from, address to, uint256 amount, uint256 taxFee) internal {
if(to == uniswapV2Pair)
uniswapV2PairAmount = uniswapV2PairAmount.add(amount);
else if(from == uniswapV2Pair)
uniswapV2PairAmount = uniswapV2PairAmount.sub(amount);
uint256 feeAmount = 0;
if (taxFee != 0) {
feeAmount = amount.mul(taxFee).div(100);
}
uint256 transferAmount = amount.sub(feeAmount);
uint256 gonTotalValue = amount.mul(_gonsPerFragment);
uint256 gonValue = transferAmount.mul(_gonsPerFragment);
uint256 gonFeeAmount = feeAmount.mul(_gonsPerFragment);
_gonBalances[from] = _gonBalances[from].sub(gonTotalValue);
_gonBalances[to] = _gonBalances[to].add(gonValue);
emit Transfer(from, to, transferAmount);
if(gonFeeAmount > 0)
_gonBalances[address(this)] = _gonBalances[address(this)].add(gonFeeAmount);
}
function swapTokens(uint256 contractTokenBalance) private lockTheSwap {
swapTokensForEth(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if (contractETHBalance > 0) {
sendETHToWallet(address(this).balance);
}
}
function sendETHToWallet(uint256 amount) private {
walletAddress.call{value: amount}("");
}
function swapTokensForEth(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
emit SwapTokensForETH(tokenAmount, path);
}
receive() external payable {}
function emergencyWithdraw() external onlyOwner {
payable(owner()).send(address(this).balance);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0,
0,
owner(),
block.timestamp
);
}
function setWalletAddress(address _walletAddress) external onlyOwner {
walletAddress = payable(_walletAddress);
}
function updateLive() external {
if(!_live) {
_live = true;
}
}
function unblockWallet(address account) public onlyOwner {
blacklist[account] = false;
}
function updatePercentForTxLimit(uint256 percentForTxLimit) public onlyOwner {
require(percentForTxLimit >= 1, 'ERC20: max tx limit should be greater than 1');
_percentForTxLimit = percentForTxLimit;
}
} | 0 | 1,476 |
pragma solidity ^0.4.23;
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 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 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 Distributable {
using SafeMath for uint256;
bool public distributed;
address[] public partners = [
0xb68342f2f4dd35d93b88081b03a245f64331c95c,
0x16CCc1e68D2165fb411cE5dae3556f823249233e,
0x8E176EDA10b41FA072464C29Eb10CfbbF4adCd05,
0x7c387c57f055993c857067A0feF6E81884656Cb0,
0x4F21c073A9B8C067818113829053b60A6f45a817,
0xcB4b6B7c4a72754dEb99bB72F1274129D9C0A109,
0x7BF84E0244c05A11c57984e8dF7CC6481b8f4258,
0x20D2F4Be237F4320386AaaefD42f68495C6A3E81,
0x12BEA633B83aA15EfF99F68C2E7e14f2709802A9,
0xC1a29a165faD532520204B480D519686B8CB845B,
0xf5f5Eb6Ab1411935b321042Fa02a433FcbD029AC,
0xaBff978f03d5ca81B089C5A2Fc321fB8152DC8f1];
address[] public partnerFixedAmount = [
0xA482D998DA4d361A6511c6847562234077F09748,
0xFa92F80f8B9148aDFBacC66aA7bbE6e9F0a0CD0e
];
mapping(address => uint256) public percentages;
mapping(address => uint256) public fixedAmounts;
constructor() public{
percentages[0xb68342f2f4dd35d93b88081b03a245f64331c95c] = 40;
percentages[0x16CCc1e68D2165fb411cE5dae3556f823249233e] = 5;
percentages[0x8E176EDA10b41FA072464C29Eb10CfbbF4adCd05] = 100;
percentages[0x7c387c57f055993c857067A0feF6E81884656Cb0] = 50;
percentages[0x4F21c073A9B8C067818113829053b60A6f45a817] = 10;
percentages[0xcB4b6B7c4a72754dEb99bB72F1274129D9C0A109] = 20;
percentages[0x7BF84E0244c05A11c57984e8dF7CC6481b8f4258] = 20;
percentages[0x20D2F4Be237F4320386AaaefD42f68495C6A3E81] = 20;
percentages[0x12BEA633B83aA15EfF99F68C2E7e14f2709802A9] = 20;
percentages[0xC1a29a165faD532520204B480D519686B8CB845B] = 30;
percentages[0xf5f5Eb6Ab1411935b321042Fa02a433FcbD029AC] = 30;
percentages[0xaBff978f03d5ca81B089C5A2Fc321fB8152DC8f1] = 52;
fixedAmounts[0xA482D998DA4d361A6511c6847562234077F09748] = 886228 * 10**16;
fixedAmounts[0xFa92F80f8B9148aDFBacC66aA7bbE6e9F0a0CD0e] = 697 ether;
}
}
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
);
}
contract Crowdsale {
using SafeMath for uint256;
ERC20 public token;
address public wallet;
uint256 public rate;
uint256 public weiRaised;
event TokenPurchase(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
constructor(uint256 _rate, address _wallet, ERC20 _token) public {
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));
rate = _rate;
wallet = _wallet;
token = _token;
}
function () external payable {
buyTokens(msg.sender);
}
function buyTokens(address _beneficiary) public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_beneficiary, weiAmount);
uint256 tokens = _getTokenAmount(weiAmount);
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
emit TokenPurchase(
msg.sender,
_beneficiary,
weiAmount,
tokens
);
_updatePurchasingState(_beneficiary, weiAmount);
_forwardFunds();
_postValidatePurchase(_beneficiary, weiAmount);
}
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
require(_beneficiary != address(0));
require(_weiAmount != 0);
}
function _postValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
}
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
token.transfer(_beneficiary, _tokenAmount);
}
function _processPurchase(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
_deliverTokens(_beneficiary, _tokenAmount);
}
function _updatePurchasingState(
address _beneficiary,
uint256 _weiAmount
)
internal
{
}
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
return _weiAmount.mul(rate);
}
function _forwardFunds() internal {
wallet.transfer(msg.value);
}
}
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
returns (bool)
{
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(
address _owner,
address _spender
)
public
view
returns (uint256)
{
return allowed[_owner][_spender];
}
function increaseApproval(
address _spender,
uint _addedValue
)
public
returns (bool)
{
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(
address _spender,
uint _subtractedValue
)
public
returns (bool)
{
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
modifier hasMintPermission() {
require(msg.sender == owner);
_;
}
function mint(
address _to,
uint256 _amount
)
hasMintPermission
canMint
public
returns (bool)
{
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
emit MintFinished();
return true;
}
}
contract MintedCrowdsale is Crowdsale {
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
require(MintableToken(token).mint(_beneficiary, _tokenAmount));
}
}
contract WhitelistedCrowdsale is Crowdsale, Ownable {
mapping(address => bool) public whitelist;
modifier isWhitelisted(address _beneficiary) {
require(whitelist[_beneficiary]);
_;
}
function addToWhitelist(address _beneficiary) external onlyOwner {
whitelist[_beneficiary] = true;
}
function addManyToWhitelist(address[] _beneficiaries) external onlyOwner {
for (uint256 i = 0; i < _beneficiaries.length; i++) {
whitelist[_beneficiaries[i]] = true;
}
}
function removeFromWhitelist(address _beneficiary) external onlyOwner {
whitelist[_beneficiary] = false;
}
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
isWhitelisted(_beneficiary)
{
super._preValidatePurchase(_beneficiary, _weiAmount);
}
}
contract SolidToken is MintableToken {
string public constant name = "SolidToken";
string public constant symbol = "SOLID";
uint8 public constant decimals = 18;
uint256 constant private DECIMAL_PLACES = 10 ** 18;
uint256 constant SUPPLY_CAP = 4000000 * DECIMAL_PLACES;
bool public transfersEnabled = false;
uint256 public transferEnablingDate;
function setTransferEnablingDate(uint256 date) public onlyOwner returns(bool success) {
transferEnablingDate = date;
return true;
}
function enableTransfer() public {
require(transferEnablingDate != 0 && now >= transferEnablingDate);
transfersEnabled = true;
}
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
require(totalSupply_.add(_amount) <= SUPPLY_CAP);
require(super.mint(_to, _amount));
return true;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(transfersEnabled, "Tranfers are disabled");
require(super.transfer(_to, _value));
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(transfersEnabled, "Tranfers are disabled");
require(super.transferFrom(_from, _to, _value));
return true;
}
}
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
modifier whenNotPaused() {
require(!paused);
_;
}
modifier whenPaused() {
require(paused);
_;
}
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
}
contract TokenSale is MintedCrowdsale, WhitelistedCrowdsale, Pausable, Distributable {
mapping(address => uint256) public contributions;
Stages public currentStage;
uint256 constant MINIMUM_CONTRIBUTION = 0.5 ether;
uint256 constant MAXIMUM_CONTRIBUTION = 100 ether;
uint256 constant BONUS_PERCENT = 250;
uint256 constant TOKENS_ON_SALE_PERCENT = 600;
uint256 constant BONUSSALE_MAX_DURATION = 30 days ;
uint256 constant MAINSALE_MAX_DURATION = 62 days;
uint256 constant TOKEN_RELEASE_DELAY = 182 days;
uint256 constant HUNDRED_PERCENT = 1000;
uint256 public bonussale_Cap = 14400 ether;
uint256 public bonussale_TokenCap = 1200000 ether;
uint256 public bonussale_StartDate;
uint256 public bonussale_EndDate;
uint256 public bonussale_TokesSold;
uint256 public bonussale_WeiRaised;
uint256 public mainSale_Cap = 18000 ether;
uint256 public mainSale_TokenCap = 1200000 ether;
uint256 public mainSale_StartDate;
uint256 public mainSale_EndDate;
uint256 public mainSale_TokesSold;
uint256 public mainSale_WeiRaised;
uint256 private changeDue;
bool private capReached;
enum Stages{
SETUP,
READY,
BONUSSALE,
MAINSALE,
FINALIZED
}
modifier atStage(Stages _currentStage){
require(currentStage == _currentStage);
_;
}
modifier timedTransition(){
if(currentStage == Stages.READY && now >= bonussale_StartDate){
currentStage = Stages.BONUSSALE;
}
if(currentStage == Stages.BONUSSALE && now > bonussale_EndDate){
finalizePresale();
}
if(currentStage == Stages.MAINSALE && now > mainSale_EndDate){
finalizeSale();
}
_;
}
constructor(uint256 _rate, address _wallet, ERC20 _token) public Crowdsale(_rate,_wallet,_token) {
require(_rate == 15);
currentStage = Stages.SETUP;
}
function setupSale(uint256 initialDate, address tokenAddress) onlyOwner atStage(Stages.SETUP) public {
bonussale_StartDate = initialDate;
bonussale_EndDate = bonussale_StartDate + BONUSSALE_MAX_DURATION;
token = ERC20(tokenAddress);
require(SolidToken(tokenAddress).totalSupply() == 0, "Tokens have already been distributed");
require(SolidToken(tokenAddress).owner() == address(this), "Token has the wrong ownership");
currentStage = Stages.READY;
}
function getCurrentCap() public view returns(uint256 cap){
cap = bonussale_Cap;
if(currentStage == Stages.MAINSALE){
cap = mainSale_Cap;
}
}
function getRaisedForCurrentStage() public view returns(uint256 raised){
raised = bonussale_WeiRaised;
if(currentStage == Stages.MAINSALE)
raised = mainSale_WeiRaised;
}
function saleOpen() public timedTransition whenNotPaused returns(bool open) {
open = ((now >= bonussale_StartDate && now < bonussale_EndDate) ||
(now >= mainSale_StartDate && now < mainSale_EndDate)) &&
(currentStage == Stages.BONUSSALE || currentStage == Stages.MAINSALE);
}
function distributeTokens() public onlyOwner atStage(Stages.FINALIZED) {
require(!distributed);
distributed = true;
uint256 totalTokens = (bonussale_TokesSold.add(mainSale_TokesSold)).mul(HUNDRED_PERCENT).div(TOKENS_ON_SALE_PERCENT);
for(uint i = 0; i < partners.length; i++){
uint256 amount = percentages[partners[i]].mul(totalTokens).div(HUNDRED_PERCENT);
_deliverTokens(partners[i], amount);
}
for(uint j = 0; j < partnerFixedAmount.length; j++){
_deliverTokens(partnerFixedAmount[j], fixedAmounts[partnerFixedAmount[j]]);
}
require(SolidToken(token).finishMinting());
}
function finalizePresale() atStage(Stages.BONUSSALE) internal{
bonussale_EndDate = now;
mainSale_StartDate = now;
mainSale_EndDate = mainSale_StartDate + MAINSALE_MAX_DURATION;
mainSale_TokenCap = mainSale_TokenCap.add(bonussale_TokenCap.sub(bonussale_TokesSold));
mainSale_Cap = mainSale_Cap.add(bonussale_Cap.sub(weiRaised.sub(changeDue)));
currentStage = Stages.MAINSALE;
}
function finalizeSale() atStage(Stages.MAINSALE) internal {
mainSale_EndDate = now;
require(SolidToken(token).setTransferEnablingDate(now + TOKEN_RELEASE_DELAY));
currentStage = Stages.FINALIZED;
}
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) isWhitelisted(_beneficiary) internal {
require(_beneficiary == msg.sender);
require(saleOpen(), "Sale is Closed");
uint256 acceptedValue = _weiAmount;
uint256 currentCap = getCurrentCap();
uint256 raised = getRaisedForCurrentStage();
if(contributions[_beneficiary].add(acceptedValue) > MAXIMUM_CONTRIBUTION){
changeDue = (contributions[_beneficiary].add(acceptedValue)).sub(MAXIMUM_CONTRIBUTION);
acceptedValue = acceptedValue.sub(changeDue);
}
if(raised.add(acceptedValue) >= currentCap){
changeDue = changeDue.add(raised.add(acceptedValue).sub(currentCap));
acceptedValue = _weiAmount.sub(changeDue);
capReached = true;
}
require(capReached || contributions[_beneficiary].add(acceptedValue) >= MINIMUM_CONTRIBUTION ,"Contribution below minimum");
}
function _getTokenAmount(uint256 _weiAmount) internal view returns (uint256 amount) {
amount = (_weiAmount.sub(changeDue)).mul(HUNDRED_PERCENT).div(rate);
if(currentStage == Stages.BONUSSALE){
amount = amount.add(amount.mul(BONUS_PERCENT).div(HUNDRED_PERCENT));
}
}
function _postValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
if(currentStage == Stages.MAINSALE && capReached) finalizeSale();
if(currentStage == Stages.BONUSSALE && capReached) finalizePresale();
changeDue = 0;
capReached = false;
}
function _updatePurchasingState(address _beneficiary, uint256 _weiAmount) internal {
uint256 tokenAmount = _getTokenAmount(_weiAmount);
if(currentStage == Stages.BONUSSALE){
bonussale_TokesSold = bonussale_TokesSold.add(tokenAmount);
bonussale_WeiRaised = bonussale_WeiRaised.add(_weiAmount.sub(changeDue));
} else {
mainSale_TokesSold = mainSale_TokesSold.add(tokenAmount);
mainSale_WeiRaised = mainSale_WeiRaised.add(_weiAmount.sub(changeDue));
}
contributions[_beneficiary] = contributions[_beneficiary].add(_weiAmount).sub(changeDue);
weiRaised = weiRaised.sub(changeDue);
}
function _forwardFunds() internal {
wallet.transfer(msg.value.sub(changeDue));
msg.sender.transfer(changeDue);
}
} | 1 | 2,867 |
pragma solidity ^ 0.4 .9;
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns(uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant returns(uint256) {
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal constant returns(uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns(uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract EthereumGold {
using SafeMath
for uint256;
mapping(address => mapping(address => uint256)) allowed;
mapping(address => uint256) balances;
uint256 public totalSupply;
uint256 public decimals;
address public owner;
bytes32 public symbol;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed _owner, address indexed spender, uint256 value);
function EthereumGold() {
totalSupply = 210000000;
symbol = 'ETHG';
owner = 0x03edd437b2dab71ae7bfbf5a112ccb92f10de9b2;
balances[owner] = totalSupply;
decimals = 0;
}
function balanceOf(address _owner) constant returns(uint256 balance) {
return balances[_owner];
}
function allowance(address _owner, address _spender) constant returns(uint256 remaining) {
return allowed[_owner][_spender];
}
function transfer(address _to, uint256 _value) returns(bool) {
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) returns(bool) {
var _allowance = allowed[_from][msg.sender];
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = _allowance.sub(_value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) returns(bool) {
require((_value == 0) || (allowed[msg.sender][_spender] == 0));
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function() {
revert();
}
} | 1 | 4,896 |
pragma solidity ^0.4.23;
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);
}
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 BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
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
);
}
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
returns (bool)
{
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(
address _owner,
address _spender
)
public
view
returns (uint256)
{
return allowed[_owner][_spender];
}
function increaseApproval(
address _spender,
uint _addedValue
)
public
returns (bool)
{
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(
address _spender,
uint _subtractedValue
)
public
returns (bool)
{
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
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 MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
modifier hasMintPermission() {
require(msg.sender == owner);
_;
}
function mint(
address _to,
uint256 _amount
)
hasMintPermission
canMint
public
returns (bool)
{
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
emit MintFinished();
return true;
}
}
contract FreezableToken is StandardToken {
mapping (bytes32 => uint64) internal chains;
mapping (bytes32 => uint) internal freezings;
mapping (address => uint) internal freezingBalance;
event Freezed(address indexed to, uint64 release, uint amount);
event Released(address indexed owner, uint amount);
function balanceOf(address _owner) public view returns (uint256 balance) {
return super.balanceOf(_owner) + freezingBalance[_owner];
}
function actualBalanceOf(address _owner) public view returns (uint256 balance) {
return super.balanceOf(_owner);
}
function freezingBalanceOf(address _owner) public view returns (uint256 balance) {
return freezingBalance[_owner];
}
function freezingCount(address _addr) public view returns (uint count) {
uint64 release = chains[toKey(_addr, 0)];
while (release != 0) {
count++;
release = chains[toKey(_addr, release)];
}
}
function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) {
for (uint i = 0; i < _index + 1; i++) {
_release = chains[toKey(_addr, _release)];
if (_release == 0) {
return;
}
}
_balance = freezings[toKey(_addr, _release)];
}
function freezeTo(address _to, uint _amount, uint64 _until) public {
require(_to != address(0));
require(_amount <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_amount);
bytes32 currentKey = toKey(_to, _until);
freezings[currentKey] = freezings[currentKey].add(_amount);
freezingBalance[_to] = freezingBalance[_to].add(_amount);
freeze(_to, _until);
emit Transfer(msg.sender, _to, _amount);
emit Freezed(_to, _until, _amount);
}
function releaseOnce() public {
bytes32 headKey = toKey(msg.sender, 0);
uint64 head = chains[headKey];
require(head != 0);
require(uint64(block.timestamp) > head);
bytes32 currentKey = toKey(msg.sender, head);
uint64 next = chains[currentKey];
uint amount = freezings[currentKey];
delete freezings[currentKey];
balances[msg.sender] = balances[msg.sender].add(amount);
freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount);
if (next == 0) {
delete chains[headKey];
} else {
chains[headKey] = next;
delete chains[currentKey];
}
emit Released(msg.sender, amount);
}
function releaseAll() public returns (uint tokens) {
uint release;
uint balance;
(release, balance) = getFreezing(msg.sender, 0);
while (release != 0 && block.timestamp > release) {
releaseOnce();
tokens += balance;
(release, balance) = getFreezing(msg.sender, 0);
}
}
function toKey(address _addr, uint _release) internal pure returns (bytes32 result) {
result = 0x5749534800000000000000000000000000000000000000000000000000000000;
assembly {
result := or(result, mul(_addr, 0x10000000000000000))
result := or(result, _release)
}
}
function freeze(address _to, uint64 _until) internal {
require(_until > block.timestamp);
bytes32 key = toKey(_to, _until);
bytes32 parentKey = toKey(_to, uint64(0));
uint64 next = chains[parentKey];
if (next == 0) {
chains[parentKey] = _until;
return;
}
bytes32 nextKey = toKey(_to, next);
uint parent;
while (next != 0 && _until > next) {
parent = next;
parentKey = nextKey;
next = chains[nextKey];
nextKey = toKey(_to, next);
}
if (_until == next) {
return;
}
if (next != 0) {
chains[key] = next;
}
chains[parentKey] = _until;
}
}
contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
function burn(uint256 _value) public {
_burn(msg.sender, _value);
}
function _burn(address _who, uint256 _value) internal {
require(_value <= balances[_who]);
balances[_who] = balances[_who].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(_who, _value);
emit Transfer(_who, address(0), _value);
}
}
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
modifier whenNotPaused() {
require(!paused);
_;
}
modifier whenPaused() {
require(paused);
_;
}
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
}
contract FreezableMintableToken is FreezableToken, MintableToken {
function mintAndFreeze(address _to, uint _amount, uint64 _until) public onlyOwner canMint returns (bool) {
totalSupply_ = totalSupply_.add(_amount);
bytes32 currentKey = toKey(_to, _until);
freezings[currentKey] = freezings[currentKey].add(_amount);
freezingBalance[_to] = freezingBalance[_to].add(_amount);
freeze(_to, _until);
emit Mint(_to, _amount);
emit Freezed(_to, _until, _amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
}
contract Consts {
uint public constant TOKEN_DECIMALS = 18;
uint8 public constant TOKEN_DECIMALS_UINT8 = 18;
uint public constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS;
string public constant TOKEN_NAME = "Saturn";
string public constant TOKEN_SYMBOL = "XSAT";
bool public constant PAUSED = false;
address public constant TARGET_USER = 0x56e3A05A7040089A35BD6441957577c9c5596b83;
bool public constant CONTINUE_MINTING = true;
}
contract MainToken is Consts, FreezableMintableToken, BurnableToken, Pausable
{
event Initialized();
bool public initialized = false;
constructor() public {
init();
transferOwnership(TARGET_USER);
}
function name() public pure returns (string _name) {
return TOKEN_NAME;
}
function symbol() public pure returns (string _symbol) {
return TOKEN_SYMBOL;
}
function decimals() public pure returns (uint8 _decimals) {
return TOKEN_DECIMALS_UINT8;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool _success) {
require(!paused);
return super.transferFrom(_from, _to, _value);
}
function transfer(address _to, uint256 _value) public returns (bool _success) {
require(!paused);
return super.transfer(_to, _value);
}
function init() private {
require(!initialized);
initialized = true;
if (PAUSED) {
pause();
}
address[4] memory addresses = [address(0x891fbdbb9971fa762a372f191dd31dc589ae3192),address(0x9b775c0ecdde2da17dc5404653d5bed3fe1dc0a4),address(0x81314df12c49b89760b564cfd854e9ea8b9d1cad),address(0xd6847207e8d9bcc5286af831184ba5d154e37999)];
uint[4] memory amounts = [uint(50000000000000000000000000),uint(100000000000000000000000000),uint(100000000000000000000000000),uint(750000000000000000000000000)];
uint64[4] memory freezes = [uint64(0),uint64(0),uint64(0),uint64(0)];
for (uint i = 0; i < addresses.length; i++) {
if (freezes[i] == 0) {
mint(addresses[i], amounts[i]);
} else {
mintAndFreeze(addresses[i], amounts[i], freezes[i]);
}
}
if (!CONTINUE_MINTING) {
finishMinting();
}
emit Initialized();
}
} | 1 | 2,611 |
pragma solidity ^0.4.24;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
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) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() internal {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract LescovexERC20 is Ownable {
using SafeMath for uint256;
mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) internal allowed;
mapping (address => timeHold) holded;
struct timeHold{
uint256[] amount;
uint256[] time;
uint256 length;
}
string public constant standard = "ERC20 Lescovex ISC Income Smart Contract";
uint8 public constant decimals = 8;
uint256 public holdMax = 100;
uint256 public totalSupply;
uint256 public holdTime;
string public name;
string public symbol;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
function holdedOf(address _owner) public view returns (uint256) {
uint256 requiredTime = block.timestamp - holdTime;
uint256 iValid = 0;
uint256 iNotValid = holded[_owner].length;
if (iNotValid == 0
|| holded[_owner].time[iValid] >= requiredTime) {
return 0;
}
uint256 i = iNotValid / 2;
while (i > iValid) {
if (holded[_owner].time[i] < requiredTime) {
iValid = i;
} else {
iNotValid = i;
}
i = (iNotValid + iValid) / 2;
}
return holded[_owner].amount[iValid];
}
function hold(address _to, uint256 _value) internal {
assert(holded[_to].length < holdMax);
uint256 len = holded[_to].length;
uint256 accumulatedValue = (len == 0 ) ?
_value :
_value + holded[_to].amount[len - 1];
holded[_to].amount.push(accumulatedValue);
holded[_to].time.push(block.timestamp);
holded[_to].length++;
}
function setHoldTime(uint256 _value) external onlyOwner{
holdTime = _value;
}
function setHoldMax(uint256 _value) external onlyOwner{
holdMax = _value;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
delete holded[msg.sender];
hold(msg.sender,balances[msg.sender]);
hold(_to,_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
delete holded[_from];
hold(_from,balances[_from]);
hold(_to,_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
tokenRecipient spender = tokenRecipient(_spender);
if (approve(_spender, _value)) {
spender.receiveApproval(msg.sender, _value, this, _extraData);
return true;
}
}
}
interface tokenRecipient {
function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external ;
}
contract Lescovex_ISC is LescovexERC20 {
uint256 public contractBalance = 0;
event LogDeposit(address sender, uint amount);
event LogWithdrawal(address receiver, uint amount);
address contractAddr = this;
constructor (
uint256 initialSupply,
string contractName,
string tokenSymbol,
uint256 contractHoldTime,
address contractOwner
) public {
totalSupply = initialSupply;
name = contractName;
symbol = tokenSymbol;
holdTime = contractHoldTime;
balances[contractOwner] = totalSupply;
}
function deposit() external payable onlyOwner returns(bool success) {
contractBalance = contractAddr.balance;
emit LogDeposit(msg.sender, msg.value);
return true;
}
function withdrawReward() external {
uint256 ethAmount = (holdedOf(msg.sender) * contractBalance) / totalSupply;
require(ethAmount > 0);
emit LogWithdrawal(msg.sender, ethAmount);
delete holded[msg.sender];
hold(msg.sender,balances[msg.sender]);
msg.sender.transfer(ethAmount);
}
function withdraw(uint256 value) external onlyOwner {
msg.sender.transfer(value);
emit LogWithdrawal(msg.sender, value);
}
} | 1 | 4,797 |
pragma solidity ^0.4.24;
contract PassiveIncome10 {
mapping (address => uint256) invested;
mapping (address => uint256) atBlock;
function () external payable {
if (invested[msg.sender] != 0) {
uint256 amount = invested[msg.sender] * 10/100 * (block.number - atBlock[msg.sender]) / 6000;
address sender = msg.sender;
sender.send(amount);
}
atBlock[msg.sender] = block.number;
invested[msg.sender] += msg.value;
}
} | 0 | 70 |
pragma solidity ^0.4.23;
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
);
}
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 Crowdsale {
using SafeMath for uint256;
ERC20 public token;
address public wallet;
uint256 public rate;
uint256 public weiRaised;
event TokenPurchase(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
constructor(uint256 _rate, address _wallet, ERC20 _token) public {
require(_rate > 0);
require(_wallet != address(0));
require(_token != address(0));
rate = _rate;
wallet = _wallet;
token = _token;
}
function () external payable {
buyTokens(msg.sender);
}
function buyTokens(address _beneficiary) public payable {
uint256 weiAmount = msg.value;
_preValidatePurchase(_beneficiary, weiAmount);
uint256 tokens = _getTokenAmount(weiAmount);
weiRaised = weiRaised.add(weiAmount);
_processPurchase(_beneficiary, tokens);
emit TokenPurchase(
msg.sender,
_beneficiary,
weiAmount,
tokens
);
_updatePurchasingState(_beneficiary, weiAmount);
_forwardFunds();
_postValidatePurchase(_beneficiary, weiAmount);
}
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
require(_beneficiary != address(0));
require(_weiAmount != 0);
}
function _postValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
}
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
token.transfer(_beneficiary, _tokenAmount);
}
function _processPurchase(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
_deliverTokens(_beneficiary, _tokenAmount);
}
function _updatePurchasingState(
address _beneficiary,
uint256 _weiAmount
)
internal
{
}
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
return _weiAmount.mul(rate);
}
function _forwardFunds() internal {
wallet.transfer(msg.value);
}
}
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 TimedCrowdsale is Crowdsale {
using SafeMath for uint256;
uint256 public openingTime;
uint256 public closingTime;
modifier onlyWhileOpen {
require(block.timestamp >= openingTime && block.timestamp <= closingTime);
_;
}
constructor(uint256 _openingTime, uint256 _closingTime) public {
require(_openingTime >= block.timestamp);
require(_closingTime >= _openingTime);
openingTime = _openingTime;
closingTime = _closingTime;
}
function hasClosed() public view returns (bool) {
return block.timestamp > closingTime;
}
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
onlyWhileOpen
{
super._preValidatePurchase(_beneficiary, _weiAmount);
}
}
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
}
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
function transferFrom(
address _from,
address _to,
uint256 _value
)
public
returns (bool)
{
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
function allowance(
address _owner,
address _spender
)
public
view
returns (uint256)
{
return allowed[_owner][_spender];
}
function increaseApproval(
address _spender,
uint _addedValue
)
public
returns (bool)
{
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(
address _spender,
uint _subtractedValue
)
public
returns (bool)
{
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
modifier hasMintPermission() {
require(msg.sender == owner);
_;
}
function mint(
address _to,
uint256 _amount
)
hasMintPermission
canMint
public
returns (bool)
{
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
emit MintFinished();
return true;
}
}
contract FreezableToken is StandardToken {
mapping (bytes32 => uint64) internal chains;
mapping (bytes32 => uint) internal freezings;
mapping (address => uint) internal freezingBalance;
event Freezed(address indexed to, uint64 release, uint amount);
event Released(address indexed owner, uint amount);
function balanceOf(address _owner) public view returns (uint256 balance) {
return super.balanceOf(_owner) + freezingBalance[_owner];
}
function actualBalanceOf(address _owner) public view returns (uint256 balance) {
return super.balanceOf(_owner);
}
function freezingBalanceOf(address _owner) public view returns (uint256 balance) {
return freezingBalance[_owner];
}
function freezingCount(address _addr) public view returns (uint count) {
uint64 release = chains[toKey(_addr, 0)];
while (release != 0) {
count++;
release = chains[toKey(_addr, release)];
}
}
function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) {
for (uint i = 0; i < _index + 1; i++) {
_release = chains[toKey(_addr, _release)];
if (_release == 0) {
return;
}
}
_balance = freezings[toKey(_addr, _release)];
}
function freezeTo(address _to, uint _amount, uint64 _until) public {
require(_to != address(0));
require(_amount <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_amount);
bytes32 currentKey = toKey(_to, _until);
freezings[currentKey] = freezings[currentKey].add(_amount);
freezingBalance[_to] = freezingBalance[_to].add(_amount);
freeze(_to, _until);
emit Transfer(msg.sender, _to, _amount);
emit Freezed(_to, _until, _amount);
}
function releaseOnce() public {
bytes32 headKey = toKey(msg.sender, 0);
uint64 head = chains[headKey];
require(head != 0);
require(uint64(block.timestamp) > head);
bytes32 currentKey = toKey(msg.sender, head);
uint64 next = chains[currentKey];
uint amount = freezings[currentKey];
delete freezings[currentKey];
balances[msg.sender] = balances[msg.sender].add(amount);
freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount);
if (next == 0) {
delete chains[headKey];
} else {
chains[headKey] = next;
delete chains[currentKey];
}
emit Released(msg.sender, amount);
}
function releaseAll() public returns (uint tokens) {
uint release;
uint balance;
(release, balance) = getFreezing(msg.sender, 0);
while (release != 0 && block.timestamp > release) {
releaseOnce();
tokens += balance;
(release, balance) = getFreezing(msg.sender, 0);
}
}
function toKey(address _addr, uint _release) internal pure returns (bytes32 result) {
result = 0x5749534800000000000000000000000000000000000000000000000000000000;
assembly {
result := or(result, mul(_addr, 0x10000000000000000))
result := or(result, _release)
}
}
function freeze(address _to, uint64 _until) internal {
require(_until > block.timestamp);
bytes32 key = toKey(_to, _until);
bytes32 parentKey = toKey(_to, uint64(0));
uint64 next = chains[parentKey];
if (next == 0) {
chains[parentKey] = _until;
return;
}
bytes32 nextKey = toKey(_to, next);
uint parent;
while (next != 0 && _until > next) {
parent = next;
parentKey = nextKey;
next = chains[nextKey];
nextKey = toKey(_to, next);
}
if (_until == next) {
return;
}
if (next != 0) {
chains[key] = next;
}
chains[parentKey] = _until;
}
}
contract BurnableToken is BasicToken {
event Burn(address indexed burner, uint256 value);
function burn(uint256 _value) public {
_burn(msg.sender, _value);
}
function _burn(address _who, uint256 _value) internal {
require(_value <= balances[_who]);
balances[_who] = balances[_who].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(_who, _value);
emit Transfer(_who, address(0), _value);
}
}
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
modifier whenNotPaused() {
require(!paused);
_;
}
modifier whenPaused() {
require(paused);
_;
}
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
}
contract FreezableMintableToken is FreezableToken, MintableToken {
function mintAndFreeze(address _to, uint _amount, uint64 _until) public onlyOwner canMint returns (bool) {
totalSupply_ = totalSupply_.add(_amount);
bytes32 currentKey = toKey(_to, _until);
freezings[currentKey] = freezings[currentKey].add(_amount);
freezingBalance[_to] = freezingBalance[_to].add(_amount);
freeze(_to, _until);
emit Mint(_to, _amount);
emit Freezed(_to, _until, _amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
}
contract Consts {
uint public constant TOKEN_DECIMALS = 18;
uint8 public constant TOKEN_DECIMALS_UINT8 = 18;
uint public constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS;
string public constant TOKEN_NAME = "PalladiumTokenMagic";
string public constant TOKEN_SYMBOL = "PTMX";
bool public constant PAUSED = true;
address public constant TARGET_USER = 0xdF15E9399B9F325D161c38F7f2aFd72C11a19500;
uint public constant START_TIME = 1533081600;
bool public constant CONTINUE_MINTING = true;
}
contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
using SafeMath for uint256;
bool public isFinalized = false;
event Finalized();
function finalize() onlyOwner public {
require(!isFinalized);
require(hasClosed());
finalization();
emit Finalized();
isFinalized = true;
}
function finalization() internal {
}
}
contract CappedCrowdsale is Crowdsale {
using SafeMath for uint256;
uint256 public cap;
constructor(uint256 _cap) public {
require(_cap > 0);
cap = _cap;
}
function capReached() public view returns (bool) {
return weiRaised >= cap;
}
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
super._preValidatePurchase(_beneficiary, _weiAmount);
require(weiRaised.add(_weiAmount) <= cap);
}
}
contract MintedCrowdsale is Crowdsale {
function _deliverTokens(
address _beneficiary,
uint256 _tokenAmount
)
internal
{
require(MintableToken(token).mint(_beneficiary, _tokenAmount));
}
}
contract MainToken is Consts, FreezableMintableToken, BurnableToken, Pausable
{
function name() public pure returns (string _name) {
return TOKEN_NAME;
}
function symbol() public pure returns (string _symbol) {
return TOKEN_SYMBOL;
}
function decimals() public pure returns (uint8 _decimals) {
return TOKEN_DECIMALS_UINT8;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool _success) {
require(!paused);
return super.transferFrom(_from, _to, _value);
}
function transfer(address _to, uint256 _value) public returns (bool _success) {
require(!paused);
return super.transfer(_to, _value);
}
}
contract MainCrowdsale is Consts, FinalizableCrowdsale, MintedCrowdsale, CappedCrowdsale {
function hasStarted() public view returns (bool) {
return now >= openingTime;
}
function startTime() public view returns (uint256) {
return openingTime;
}
function endTime() public view returns (uint256) {
return closingTime;
}
function hasClosed() public view returns (bool) {
return super.hasClosed() || capReached();
}
function hasEnded() public view returns (bool) {
return hasClosed();
}
function finalization() internal {
super.finalization();
if (PAUSED) {
MainToken(token).unpause();
}
if (!CONTINUE_MINTING) {
require(MintableToken(token).finishMinting());
}
Ownable(token).transferOwnership(TARGET_USER);
}
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
return _weiAmount.mul(rate).div(1 ether);
}
}
contract Checkable {
address private serviceAccount;
bool private triggered = false;
event Triggered(uint balance);
event Checked(bool isAccident);
constructor() public {
serviceAccount = msg.sender;
}
function changeServiceAccount(address _account) public onlyService {
require(_account != 0);
serviceAccount = _account;
}
function isServiceAccount() public view returns (bool) {
return msg.sender == serviceAccount;
}
function check() public payable onlyService notTriggered {
if (internalCheck()) {
emit Triggered(address(this).balance);
triggered = true;
internalAction();
}
}
function internalCheck() internal returns (bool);
function internalAction() internal;
modifier onlyService {
require(msg.sender == serviceAccount);
_;
}
modifier notTriggered {
require(!triggered);
_;
}
}
contract BonusableCrowdsale is Consts, Crowdsale {
function _getTokenAmount(uint256 _weiAmount)
internal view returns (uint256)
{
uint256 bonusRate = getBonusRate(_weiAmount);
return _weiAmount.mul(bonusRate).div(1 ether);
}
function getBonusRate(uint256 _weiAmount) internal view returns (uint256) {
uint256 bonusRate = rate;
uint[1] memory weiRaisedStartsBounds = [uint(0)];
uint[1] memory weiRaisedEndsBounds = [uint(115170575000000000000000)];
uint64[1] memory timeStartsBounds = [uint64(1533081600)];
uint64[1] memory timeEndsBounds = [uint64(1537027080)];
uint[1] memory weiRaisedAndTimeRates = [uint(50)];
for (uint i = 0; i < 1; i++) {
bool weiRaisedInBound = (weiRaisedStartsBounds[i] <= weiRaised) && (weiRaised < weiRaisedEndsBounds[i]);
bool timeInBound = (timeStartsBounds[i] <= now) && (now < timeEndsBounds[i]);
if (weiRaisedInBound && timeInBound) {
bonusRate += bonusRate * weiRaisedAndTimeRates[i] / 1000;
}
}
uint[6] memory weiAmountBounds = [uint(200000000000000000000),uint(80000000000000000000),uint(30000000000000000000),uint(10000000000000000000),uint(8000000000000000000),uint(5000000000000000000)];
uint[6] memory weiAmountRates = [uint(0),uint(250),uint(0),uint(150),uint(0),uint(50)];
for (uint j = 0; j < 6; j++) {
if (_weiAmount >= weiAmountBounds[j]) {
bonusRate += bonusRate * weiAmountRates[j] / 1000;
break;
}
}
return bonusRate;
}
}
contract TemplateCrowdsale is Consts, MainCrowdsale
, BonusableCrowdsale
, Checkable
{
event Initialized();
event TimesChanged(uint startTime, uint endTime, uint oldStartTime, uint oldEndTime);
bool public initialized = false;
constructor(MintableToken _token) public
Crowdsale(2000 * TOKEN_DECIMAL_MULTIPLIER, 0xa7c7e82a53BAEBe36f95B7Df4c447B21eADfB60B, _token)
TimedCrowdsale(START_TIME > now ? START_TIME : now, 1541001480)
CappedCrowdsale(115170575000000000000000)
{
}
function init() public onlyOwner {
require(!initialized);
initialized = true;
if (PAUSED) {
MainToken(token).pause();
}
address[5] memory addresses = [address(0xa7c7e82a53baebe36f95b7df4c447b21eadfb60b),address(0xa7c7e82a53baebe36f95b7df4c447b21eadfb60b),address(0xf3dec80a2d514096027a56110b3fc2b155838679),address(0x5eb83c9f93eeb6bf6eb02a1aa9a0815a03c53b2a),address(0xd3841ac09b2fe75e3d0486bce88d1f41298ada41)];
uint[5] memory amounts = [uint(13100000000000000000000000),uint(29800000000000000000000000),uint(600000000000000000000000),uint(58850000000000000000000),uint(14100000000000000000000000)];
uint64[5] memory freezes = [uint64(1604073601),uint64(0),uint64(1572451201),uint64(0),uint64(1572451201)];
for (uint i = 0; i < addresses.length; i++) {
if (freezes[i] == 0) {
MainToken(token).mint(addresses[i], amounts[i]);
} else {
MainToken(token).mintAndFreeze(addresses[i], amounts[i], freezes[i]);
}
}
transferOwnership(TARGET_USER);
emit Initialized();
}
function hasClosed() public view returns (bool) {
bool remainValue = cap.sub(weiRaised) < 3000000000000000000;
return super.hasClosed() || remainValue;
}
function internalCheck() internal returns (bool) {
bool result = !isFinalized && hasClosed();
emit Checked(result);
return result;
}
function internalAction() internal {
finalization();
emit Finalized();
isFinalized = true;
}
function _preValidatePurchase(
address _beneficiary,
uint256 _weiAmount
)
internal
{
require(msg.value >= 3000000000000000000);
require(msg.value <= 200000000000000000000);
super._preValidatePurchase(_beneficiary, _weiAmount);
}
} | 1 | 2,957 |
pragma solidity ^0.4.24;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
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) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Token {
function totalSupply() public view returns (uint256);
function balanceOf(address _owner) public view returns (uint256);
function transfer(address _to, uint256 _value) public returns (bool);
function transferFrom(address _from, address _to, uint256 _value) public returns (bool);
function approve(address _spender, uint256 _value) public returns (bool);
function allowance(address _owner, address _spender) public view returns (uint256);
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
contract FeeModifiersInterface {
function accountFeeModifiers(address _user) public view returns (uint256 feeDiscount, uint256 feeRebate);
function tradingFeeModifiers(address _maker, address _taker) public view returns (uint256 feeMakeDiscount, uint256 feeTakeDiscount, uint256 feeRebate);
}
contract TradeTrackerInterface {
function tradeEventHandler(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, address _maker, address _user, bytes32 _orderHash, uint256 _gasLimit) public;
}
contract TokenExchange is Ownable {
using SafeMath for uint256;
address public tradeTracker;
address public feeModifiers;
address public feeAccount;
uint256 public feeMake;
uint256 public feeTake;
mapping (address => mapping (address => uint256)) public tokens;
mapping (bytes32 => bool) public cancelledOrders;
mapping (bytes32 => uint256) public orderFills;
event Deposit(address token, address user, uint256 amount, uint256 balance);
event Withdraw(address token, address user, uint256 amount, uint256 balance);
event Cancel(address tokenGet, uint256 amountGet, address tokenGive, uint256 amountGive, uint256 expires, uint256 nonce, address maker, uint8 v, bytes32 r, bytes32 s, bytes32 orderHash, uint256 amountFilled);
event Trade(address tokenGet, uint256 amountGet, address tokenGive, uint256 amountGive, address maker, address taker, bytes32 orderHash);
constructor() public{
feeAccount = owner;
}
function() public {
revert();
}
function getAccountFeeModifiers(address _user) public view returns(uint256 feeDiscount, uint256 feeRebate) {
if (feeModifiers != address(0)) {
(feeDiscount, feeRebate) = FeeModifiersInterface(feeModifiers).accountFeeModifiers(_user);
}
}
function deposit() public payable {
tokens[address(0)][msg.sender] = tokens[address(0)][msg.sender].add(msg.value);
emit Deposit(address(0), msg.sender, msg.value, tokens[address(0)][msg.sender]);
}
function depositToken(address _token, uint256 _amount) public {
require(_token != address(0));
if (!Token(_token).transferFrom(msg.sender, this, _amount)) revert();
tokens[_token][msg.sender] = tokens[_token][msg.sender].add(_amount);
emit Deposit(_token, msg.sender, _amount, tokens[_token][msg.sender]);
}
function withdraw(uint256 _amount) public {
require(tokens[address(0)][msg.sender] >= _amount);
tokens[address(0)][msg.sender] = tokens[address(0)][msg.sender].sub(_amount);
msg.sender.transfer(_amount);
emit Withdraw(address(0), msg.sender, _amount, tokens[address(0)][msg.sender]);
}
function withdrawToken(address _token, uint256 _amount) public {
require(_token != address(0));
require(tokens[_token][msg.sender] >= _amount);
tokens[_token][msg.sender] = tokens[_token][msg.sender].sub(_amount);
if (!Token(_token).transfer(msg.sender, _amount)) revert();
emit Withdraw(_token, msg.sender, _amount, tokens[_token][msg.sender]);
}
function balanceOf(address _token, address _user) public view returns (uint256) {
return tokens[_token][_user];
}
function trade(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker, uint8 _v, bytes32 _r, bytes32 _s, uint256 _amountTrade) public {
uint256 executionGasLimit = gasleft();
bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker);
if (ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", orderHash)), _v, _r, _s) != _maker ||
cancelledOrders[orderHash] ||
block.number > _expires ||
orderFills[orderHash].add(_amountTrade) > _amountGet
) revert();
tradeBalances(_tokenGet, _amountGet, _tokenGive, _amountGive, _maker, _amountTrade);
orderFills[orderHash] = orderFills[orderHash].add(_amountTrade);
uint256 amountTradeGive = _amountGive.mul(_amountTrade) / _amountGet;
if(tradeTracker != address(0)){
TradeTrackerInterface(tradeTracker).tradeEventHandler(_tokenGet, _amountTrade, _tokenGive, amountTradeGive, _maker, msg.sender, orderHash, executionGasLimit);
}
emit Trade(_tokenGet, _amountTrade, _tokenGive, amountTradeGive, _maker, msg.sender, orderHash);
}
function tradeBalances(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, address _maker, uint256 _amountTrade) private {
uint256 feeMakeValue = _amountTrade.mul(feeMake) / (1 ether);
uint256 feeTakeValue = _amountTrade.mul(feeTake) / (1 ether);
uint256 feeRebateValue = 0;
if (feeModifiers != address(0)) {
uint256 feeMakeDiscount; uint256 feeTakeDiscount; uint256 feeRebate;
(feeMakeDiscount, feeTakeDiscount, feeRebate) = FeeModifiersInterface(feeModifiers).tradingFeeModifiers(_maker, msg.sender);
if (feeMakeValue > 0 && feeMakeDiscount > 0 && feeMakeDiscount <= 100 ) feeMakeValue = feeMakeValue.mul(100 - feeMakeDiscount) / 100;
if (feeTakeValue > 0 && feeTakeDiscount > 0 && feeTakeDiscount <= 100 ) feeTakeValue = feeTakeValue.mul(100 - feeTakeDiscount) / 100;
if (feeTakeValue > 0 && feeRebate > 0 && feeRebate <= 100) feeRebateValue = feeTakeValue.mul(feeRebate) / 100;
}
tokens[_tokenGet][msg.sender] = tokens[_tokenGet][msg.sender].sub(_amountTrade.add(feeTakeValue));
tokens[_tokenGet][_maker] = tokens[_tokenGet][_maker].add(_amountTrade.sub(feeMakeValue).add(feeRebateValue));
tokens[_tokenGive][msg.sender] = tokens[_tokenGive][msg.sender].add(_amountGive.mul(_amountTrade) / _amountGet);
tokens[_tokenGive][_maker] = tokens[_tokenGive][_maker].sub(_amountGive.mul(_amountTrade) / _amountGet);
tokens[_tokenGet][feeAccount] = tokens[_tokenGet][feeAccount].add(feeMakeValue.add(feeTakeValue).sub(feeRebateValue));
}
function validateTrade(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker, uint8 _v, bytes32 _r, bytes32 _s, uint256 _amountTrade, address _taker) public view returns (uint8) {
uint256 feeTakeValue = calculateTakerFee(_taker, _amountTrade);
if (_amountTrade.add(feeTakeValue) > tokens[_tokenGet][_taker]) return 1;
if (availableVolume(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker, _v, _r, _s) < _amountTrade) return 2;
return 0;
}
function calculateTakerFee(address _taker, uint256 _amountTrade) public view returns (uint256) {
uint256 feeTakeValue = _amountTrade.mul(feeTake) / (1 ether);
uint256 feeDiscount; uint256 feeRebate;
(feeDiscount, feeRebate) = getAccountFeeModifiers(_taker);
if (feeTakeValue > 0 && feeDiscount > 0 && feeDiscount <= 100 ) feeTakeValue = feeTakeValue.mul(100 - feeDiscount) / 100;
return feeTakeValue;
}
function getOrderHash(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker) public view returns (bytes32) {
return keccak256(abi.encodePacked(this, _tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker));
}
function availableVolume(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker, uint8 _v, bytes32 _r, bytes32 _s) public view returns (uint256) {
bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker);
if (ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", orderHash)), _v, _r, _s) != _maker ||
cancelledOrders[orderHash] ||
block.number > _expires ||
_amountGet <= orderFills[orderHash]
) return 0;
uint256[2] memory available;
available[0] = _amountGet.sub(orderFills[orderHash]);
available[1] = tokens[_tokenGive][_maker].mul(_amountGet) / _amountGive;
if (available[0] < available[1]) return available[0];
return available[1];
}
function amountFilled(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, address _maker) public view returns (uint256) {
bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, _maker);
return orderFills[orderHash];
}
function cancelOrder(address _tokenGet, uint256 _amountGet, address _tokenGive, uint256 _amountGive, uint256 _expires, uint256 _nonce, uint8 _v, bytes32 _r, bytes32 _s) public {
bytes32 orderHash = getOrderHash(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, msg.sender);
if (ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", orderHash)), _v, _r, _s) != msg.sender) revert();
cancelledOrders[orderHash] = true;
emit Cancel(_tokenGet, _amountGet, _tokenGive, _amountGive, _expires, _nonce, msg.sender, _v, _r, _s, orderHash, orderFills[orderHash]);
}
function changeFeeAccount(address _feeAccount) public onlyOwner {
require(_feeAccount != address(0));
feeAccount = _feeAccount;
}
function changeFeeMake(uint256 _feeMake) public onlyOwner {
require(_feeMake != feeMake);
feeMake = _feeMake;
}
function changeFeeTake(uint256 _feeTake) public onlyOwner {
require(_feeTake != feeTake);
feeTake = _feeTake;
}
function changeFeeModifiers(address _feeModifiers) public onlyOwner {
require(feeModifiers != _feeModifiers);
feeModifiers = _feeModifiers;
}
function changeTradeTracker(address _tradeTracker) public onlyOwner {
require(tradeTracker != _tradeTracker);
tradeTracker = _tradeTracker;
}
} | 0 | 2,412 |
pragma solidity ^0.4.19;
contract StandardToken {
function balanceOf(address _owner) constant public returns (uint256);
function transfer(address _to, uint256 _value) public returns (bool);
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
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) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
interface Token {
function transfer(address _to, uint256 _value) public returns (bool);
function totalSupply() constant public returns (uint256 supply);
function balanceOf(address _owner) constant public returns (uint256 balance);
}
contract CslTokenDistribution {
using SafeMath for uint256;
mapping (address => uint256) balances;
Token public cslToken;
address public owner;
uint256 public decimals = 10e17;
uint256 public value = 50000;
uint256 public bonus = 5000;
uint256 public drop;
bool public contractLocked = true;
bool public bonusTime = true;
event sendTokens(address indexed to, uint256 value);
event Locked();
event Unlocked();
event Bonustimer();
event NoBonustimer();
function CslTokenDistribution(address _tokenAddress, address _owner) public {
cslToken = Token(_tokenAddress);
owner = _owner;
}
function transferOwnership(address newOwner) onlyOwner public {
if (newOwner != address(0)) {
owner = newOwner;
}
}
function setAirdrop(uint256 _Drop) onlyOwner public {
drop = _Drop;
}
function setCrowdsale(uint256 _value, uint256 _bonus) onlyOwner public {
value = _value;
bonus = _bonus;
}
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
modifier isUnlocked() {
require(!contractLocked);
_;
}
function lockContract() onlyOwner public returns (bool) {
contractLocked = true;
Locked();
return true;
}
function unlockContract() onlyOwner public returns (bool) {
contractLocked = false;
Unlocked();
return false;
}
function bonusOn() onlyOwner public returns (bool) {
bonusTime = true;
Bonustimer();
return true;
}
function bonusOff() onlyOwner public returns (bool) {
bonusTime = false;
NoBonustimer();
return false;
}
function balanceOf(address _holder) constant public returns (uint256 balance) {
return balances[_holder];
}
function getTokenBalance(address who) constant public returns (uint){
uint bal = cslToken.balanceOf(who);
return bal;
}
function getEthBalance(address _addr) constant public returns(uint) {
return _addr.balance;
}
function airdrop(address[] addresses) onlyOwner public {
require(addresses.length <= 255);
for (uint i = 0; i < addresses.length; i++) {
sendTokens(addresses[i], drop);
cslToken.transfer(addresses[i], drop);
}
}
function distribution(address[] addresses, uint256 amount) onlyOwner public {
require(addresses.length <= 255);
for (uint i = 0; i < addresses.length; i++) {
sendTokens(addresses[i], amount);
cslToken.transfer(addresses[i], amount);
}
}
function distributeAmounts(address[] addresses, uint256[] amounts) onlyOwner public {
require(addresses.length <= 255);
require(addresses.length == amounts.length);
for (uint8 i = 0; i < addresses.length; i++) {
sendTokens(addresses[i], amounts[i]);
cslToken.transfer(addresses[i], amounts[i]);
}
}
function () external payable {
getTokens();
}
function getTokens() payable isUnlocked public {
address investor = msg.sender;
uint256 weiAmount = msg.value;
uint256 tokens = weiAmount.mul(value);
if (msg.value == 0) { return; }
if (bonusTime == true) {
uint256 bonusTokens = weiAmount.mul(bonus);
tokens = tokens.add(bonusTokens);
}
sendTokens(investor, tokens);
cslToken.transfer(investor, tokens);
}
function tokensAvailable() constant public returns (uint256) {
return cslToken.balanceOf(this);
}
function withdraw() onlyOwner public {
uint256 etherBalance = this.balance;
owner.transfer(etherBalance);
}
function withdrawStandardTokens(address _tokenContract) onlyOwner public returns (bool) {
StandardToken token = StandardToken(_tokenContract);
uint256 amount = token.balanceOf(address(this));
return token.transfer(owner, amount);
}
} | 0 | 2,586 |
pragma solidity ^0.4.19;
contract DistrictsCoreInterface {
function isDopeRaiderDistrictsCore() public pure returns (bool);
function increaseDistrictWeed(uint256 _district, uint256 _quantity) public;
function increaseDistrictCoke(uint256 _district, uint256 _quantity) public;
function distributeRevenue(uint256 _district , uint8 _splitW, uint8 _splitC) public payable;
function getNarcoLocation(uint256 _narcoId) public view returns (uint8 location);
}
contract SaleClockAuction {
function isSaleClockAuction() public pure returns (bool);
function createAuction(uint256 _tokenId, uint256 _startingPrice,uint256 _endingPrice,uint256 _duration,address _seller)public;
function withdrawBalance() public;
function averageGen0SalePrice() public view returns (uint256);
}
contract NarcoAccessControl {
event ContractUpgrade(address newContract);
address public ceoAddress;
address public cooAddress;
bool public paused = false;
modifier onlyCEO() {
require(msg.sender == ceoAddress);
_;
}
modifier onlyCLevel() {
require(
msg.sender == cooAddress ||
msg.sender == ceoAddress
);
_;
}
function setCEO(address _newCEO) public onlyCEO {
require(_newCEO != address(0));
ceoAddress = _newCEO;
}
function setCOO(address _newCOO) public onlyCEO {
require(_newCOO != address(0));
cooAddress = _newCOO;
}
function withdrawBalance() external onlyCLevel {
msg.sender.transfer(address(this).balance);
}
modifier whenNotPaused() {
require(!paused);
_;
}
modifier whenPaused {
require(paused);
_;
}
function pause() public onlyCLevel whenNotPaused {
paused = true;
}
function unpause() public onlyCLevel whenPaused {
paused = false;
}
address public districtContractAddress;
DistrictsCoreInterface public districtsCore;
function setDistrictAddress(address _address) public onlyCLevel {
_setDistrictAddresss(_address);
}
function _setDistrictAddresss(address _address) internal {
DistrictsCoreInterface candidateContract = DistrictsCoreInterface(_address);
require(candidateContract.isDopeRaiderDistrictsCore());
districtsCore = candidateContract;
districtContractAddress = _address;
}
modifier onlyDopeRaiderContract() {
require(msg.sender == districtContractAddress);
_;
}
}
contract NarcoBase is NarcoAccessControl {
event NarcoCreated(address indexed owner, uint256 narcoId, string genes);
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
struct Narco {
string genes;
string narcoName;
uint16 [9] stats;
uint16 weedTotal;
uint16 cokeTotal;
uint8 [4] consumables;
uint16 [6] skills;
uint256 [6] cooldowns;
uint8 homeLocation;
}
Narco[] narcos;
mapping (uint256 => address) public narcoIndexToOwner;
mapping (address => uint256) ownershipTokenCount;
mapping (uint256 => address) public narcoIndexToApproved;
function _transfer(address _from, address _to, uint256 _tokenId) internal {
ownershipTokenCount[_to]++;
narcoIndexToOwner[_tokenId] = _to;
if (_from != address(0)) {
ownershipTokenCount[_from]--;
delete narcoIndexToApproved[_tokenId];
}
Transfer(_from, _to, _tokenId);
}
function _createNarco(
string _genes,
string _name,
address _owner
)
internal
returns (uint)
{
uint16[6] memory randomskills= [
uint16(random(9)+1),
uint16(random(9)+1),
uint16(random(9)+1),
uint16(random(9)+1),
uint16(random(9)+1),
uint16(random(9)+31)
];
uint256[6] memory cools;
uint16[9] memory nostats;
Narco memory _narco = Narco({
genes: _genes,
narcoName: _name,
cooldowns: cools,
stats: nostats,
weedTotal: 0,
cokeTotal: 0,
consumables: [4,6,2,1],
skills: randomskills,
homeLocation: uint8(random(6)+1)
});
uint256 newNarcoId = narcos.push(_narco) - 1;
require(newNarcoId <= 4294967295);
if (newNarcoId==0){
narcos[0].homeLocation=7;
narcos[0].skills[4]=800;
narcos[0].skills[5]=65535;
}
NarcoCreated(_owner, newNarcoId, _narco.genes);
_transfer(0, _owner, newNarcoId);
return newNarcoId;
}
function subToZero(uint256 a, uint256 b) internal pure returns (uint256) {
if (b <= a){
return a - b;
}else{
return 0;
}
}
function getRemainingCapacity(uint256 _narcoId) public view returns (uint16 capacity){
uint256 usedCapacity = narcos[_narcoId].weedTotal + narcos[_narcoId].cokeTotal + narcos[_narcoId].consumables[0]+narcos[_narcoId].consumables[1]+narcos[_narcoId].consumables[2]+narcos[_narcoId].consumables[3];
capacity = uint16(subToZero(uint256(narcos[_narcoId].skills[5]), usedCapacity));
}
function getLevel(uint256 _narcoId) public view returns (uint16 rank){
rank = (narcos[_narcoId].stats[0]/12)+
(narcos[_narcoId].stats[1]/4)+
(narcos[_narcoId].stats[2]/4)+
(narcos[_narcoId].stats[3]/6)+
(narcos[_narcoId].stats[4]/6)+
(narcos[_narcoId].stats[5]/1)+
(narcos[_narcoId].stats[7]/12)
;
}
uint64 _seed = 0;
function random(uint64 upper) private returns (uint64 randomNumber) {
_seed = uint64(keccak256(keccak256(block.blockhash(block.number-1), _seed), now));
return _seed % upper;
}
function narcosByOwner(address _owner) public view returns(uint256[] ownedNarcos) {
uint256 tokenCount = ownershipTokenCount[_owner];
uint256 totalNarcos = narcos.length - 1;
uint256[] memory result = new uint256[](tokenCount);
uint256 narcoId;
uint256 resultIndex=0;
for (narcoId = 0; narcoId <= totalNarcos; narcoId++) {
if (narcoIndexToOwner[narcoId] == _owner) {
result[resultIndex] = narcoId;
resultIndex++;
}
}
return result;
}
}
contract ERC721 {
function implementsERC721() public pure returns (bool);
function totalSupply() public view returns (uint256 total);
function balanceOf(address _owner) public view returns (uint256 balance);
function ownerOf(uint256 _tokenId) public view returns (address owner);
function approve(address _to, uint256 _tokenId) public;
function transferFrom(address _from, address _to, uint256 _tokenId) public;
function transfer(address _to, uint256 _tokenId) public;
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
}
contract NarcoOwnership is NarcoBase, ERC721 {
string public name = "DopeRaider";
string public symbol = "DOPR";
function implementsERC721() public pure returns (bool)
{
return true;
}
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return narcoIndexToOwner[_tokenId] == _claimant;
}
function _approvedFor(address _claimant, uint256 _tokenId) internal view returns (bool) {
return narcoIndexToApproved[_tokenId] == _claimant;
}
function _approve(uint256 _tokenId, address _approved) internal {
narcoIndexToApproved[_tokenId] = _approved;
}
function balanceOf(address _owner) public view returns (uint256 count) {
return ownershipTokenCount[_owner];
}
function transfer(
address _to,
uint256 _tokenId
)
public
{
require(_to != address(0));
require(_owns(msg.sender, _tokenId));
_transfer(msg.sender, _to, _tokenId);
}
function approve(
address _to,
uint256 _tokenId
)
public
{
require(_owns(msg.sender, _tokenId));
_approve(_tokenId, _to);
Approval(msg.sender, _to, _tokenId);
}
function transferFrom(
address _from,
address _to,
uint256 _tokenId
)
public
{
require(_approvedFor(msg.sender, _tokenId));
require(_owns(_from, _tokenId));
require(_to != address(0));
_transfer(_from, _to, _tokenId);
}
function totalSupply() public view returns (uint) {
return narcos.length - 1;
}
function ownerOf(uint256 _tokenId)
public
view
returns (address owner)
{
owner = narcoIndexToOwner[_tokenId];
require(owner != address(0));
}
}
contract NarcoUpdates is NarcoOwnership {
function updateWeedTotal(uint256 _narcoId, bool _add, uint16 _total) public onlyDopeRaiderContract {
if(_add==true){
narcos[_narcoId].weedTotal+= _total;
}else{
narcos[_narcoId].weedTotal-= _total;
}
}
function updateCokeTotal(uint256 _narcoId, bool _add, uint16 _total) public onlyDopeRaiderContract {
if(_add==true){
narcos[_narcoId].cokeTotal+= _total;
}else{
narcos[_narcoId].cokeTotal-= _total;
}
}
function updateConsumable(uint256 _narcoId, uint256 _index, uint8 _new) public onlyDopeRaiderContract {
narcos[_narcoId].consumables[_index] = _new;
}
function updateSkill(uint256 _narcoId, uint256 _index, uint16 _new) public onlyDopeRaiderContract {
narcos[_narcoId].skills[_index] = _new;
}
function incrementStat(uint256 _narcoId , uint256 _index) public onlyDopeRaiderContract {
narcos[_narcoId].stats[_index]++;
}
function setCooldown(uint256 _narcoId , uint256 _index , uint256 _new) public onlyDopeRaiderContract {
narcos[_narcoId].cooldowns[_index]=_new;
}
}
contract NarcoAuction is NarcoUpdates {
SaleClockAuction public saleAuction;
function setSaleAuctionAddress(address _address) public onlyCLevel {
SaleClockAuction candidateContract = SaleClockAuction(_address);
require(candidateContract.isSaleClockAuction());
saleAuction = candidateContract;
}
function createSaleAuction(
uint256 _narcoId,
uint256 _startingPrice,
uint256 _endingPrice,
uint256 _duration
)
public
whenNotPaused
{
require(_owns(msg.sender, _narcoId));
_approve(_narcoId, saleAuction);
saleAuction.createAuction(
_narcoId,
_startingPrice,
_endingPrice,
_duration,
msg.sender
);
}
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
}
}
contract NarcoMinting is NarcoAuction {
uint256 public promoCreationLimit = 200;
uint256 public gen0CreationLimit = 5000;
uint256 public gen0StartingPrice = 1 ether;
uint256 public gen0EndingPrice = 20 finney;
uint256 public gen0AuctionDuration = 1 days;
uint256 public promoCreatedCount;
uint256 public gen0CreatedCount;
function createPromoNarco(
string _genes,
string _name,
address _owner
) public onlyCLevel {
if (_owner == address(0)) {
_owner = cooAddress;
}
require(promoCreatedCount < promoCreationLimit);
require(gen0CreatedCount < gen0CreationLimit);
promoCreatedCount++;
gen0CreatedCount++;
_createNarco(_genes, _name, _owner);
}
function createGen0Auction(
string _genes,
string _name
) public onlyCLevel {
require(gen0CreatedCount < gen0CreationLimit);
uint256 narcoId = _createNarco(_genes,_name,address(this));
_approve(narcoId, saleAuction);
saleAuction.createAuction(
narcoId,
_computeNextGen0Price(),
gen0EndingPrice,
gen0AuctionDuration,
address(this)
);
gen0CreatedCount++;
}
function _computeNextGen0Price() internal view returns (uint256) {
uint256 avePrice = saleAuction.averageGen0SalePrice();
require(avePrice < 340282366920938463463374607431768211455);
uint256 nextPrice = avePrice + (avePrice / 2);
if (nextPrice < gen0StartingPrice) {
nextPrice = gen0StartingPrice;
}
return nextPrice;
}
}
contract DopeRaiderCore is NarcoMinting {
address public newContractAddress;
bool public gamePaused = true;
modifier whenGameNotPaused() {
require(!gamePaused);
_;
}
modifier whenGamePaused {
require(gamePaused);
_;
}
function pause() public onlyCLevel whenGameNotPaused {
gamePaused = true;
}
function unpause() public onlyCLevel whenGamePaused {
gamePaused = false;
}
event GrowWeedCompleted(uint256 indexed narcoId, uint yield);
event RefineCokeCompleted(uint256 indexed narcoId, uint yield);
function DopeRaiderCore() public {
ceoAddress = msg.sender;
cooAddress = msg.sender;
}
function setNewAddress(address _v2Address) public onlyCLevel whenPaused {
newContractAddress = _v2Address;
ContractUpgrade(_v2Address);
}
function() external payable {
require(msg.sender == address(saleAuction));
}
function getNarco(uint256 _id)
public
view
returns (
string narcoName,
uint256 weedTotal,
uint256 cokeTotal,
uint16[6] skills,
uint8[4] consumables,
string genes,
uint8 homeLocation,
uint16 level,
uint256[6] cooldowns,
uint256 id,
uint16 [9] stats
) {
Narco storage narco = narcos[_id];
narcoName = narco.narcoName;
weedTotal = narco.weedTotal;
cokeTotal = narco.cokeTotal;
skills = narco.skills;
consumables = narco.consumables;
genes = narco.genes;
homeLocation = narco.homeLocation;
level = getLevel(_id);
cooldowns = narco.cooldowns;
id = _id;
stats = narco.stats;
}
uint256 public changeIdentityNarcoRespect = 30;
function setChangeIdentityNarcoRespect(uint256 _respect) public onlyCLevel {
changeIdentityNarcoRespect=_respect;
}
uint256 public personalisationCost = 0.01 ether;
function setPersonalisationCost(uint256 _cost) public onlyCLevel {
personalisationCost=_cost;
}
function updateNarco(uint256 _narcoId, string _genes, string _name) public payable whenGameNotPaused {
require(getLevel(_narcoId)>=changeIdentityNarcoRespect);
require(msg.sender==narcoIndexToOwner[_narcoId]);
require(msg.value>=personalisationCost);
narcos[_narcoId].genes = _genes;
narcos[_narcoId].narcoName = _name;
}
uint256 public respectRequiredToRecruit = 150;
function setRespectRequiredToRecruit(uint256 _respect) public onlyCLevel {
respectRequiredToRecruit=_respect;
}
function recruitNarco(uint256 _narcoId, string _genes, string _name) public whenGameNotPaused {
require(msg.sender==narcoIndexToOwner[_narcoId]);
require(getLevel(_narcoId)>=respectRequiredToRecruit);
require(narcos[_narcoId].stats[8]<getLevel(_narcoId)/respectRequiredToRecruit);
_createNarco(_genes,_name, msg.sender);
narcos[_narcoId].stats[8]+=1;
}
uint256 public growCost = 0.003 ether;
function setGrowCost(uint256 _cost) public onlyCLevel{
growCost=_cost;
}
function growWeed(uint256 _narcoId) public payable whenGameNotPaused{
require(msg.sender==narcoIndexToOwner[_narcoId]);
require(msg.value>=growCost);
require(now>narcos[_narcoId].cooldowns[1]);
uint16 growSkillLevel = narcos[_narcoId].skills[1];
uint16 maxYield = 9 + growSkillLevel;
uint yield = min(narcos[_narcoId].consumables[1],maxYield);
require(yield>0);
uint8 district = districtsCore.getNarcoLocation(_narcoId);
require(district==narcos[_narcoId].homeLocation);
uint256 cooldown = now + ((910-(10*growSkillLevel))* 1 seconds);
narcos[_narcoId].cooldowns[1]=cooldown;
narcos[_narcoId].consumables[1]=uint8(subToZero(uint256(narcos[_narcoId].consumables[1]),yield));
narcos[_narcoId].weedTotal+=uint8(yield);
narcos[_narcoId].stats[1]+=1;
districtsCore.increaseDistrictWeed(district , yield);
districtsCore.distributeRevenue.value(growCost)(uint256(district),50,50);
GrowWeedCompleted(_narcoId, yield);
}
uint256 public refineCost = 0.003 ether;
function setRefineCost(uint256 _cost) public onlyCLevel{
refineCost=_cost;
}
function refineCoke(uint256 _narcoId) public payable whenGameNotPaused{
require(msg.sender==narcoIndexToOwner[_narcoId]);
require(msg.value>=refineCost);
require(now>narcos[_narcoId].cooldowns[2]);
uint16 refineSkillLevel = narcos[_narcoId].skills[2];
uint16 maxYield = 3+(refineSkillLevel/3);
uint yield = min(narcos[_narcoId].consumables[2],maxYield);
require(yield>0);
uint8 district = districtsCore.getNarcoLocation(_narcoId);
require(district==narcos[_narcoId].homeLocation);
uint256 cooldown = now + ((910-(10*refineSkillLevel))* 1 seconds);
narcos[_narcoId].cooldowns[2]=cooldown;
narcos[_narcoId].consumables[2]=uint8(subToZero(uint256(narcos[_narcoId].consumables[2]),yield));
narcos[_narcoId].cokeTotal+=uint8(yield);
narcos[_narcoId].stats[2]+=1;
districtsCore.increaseDistrictCoke(district, yield);
districtsCore.distributeRevenue.value(refineCost)(uint256(district),50,50);
RefineCokeCompleted(_narcoId, yield);
}
function min(uint a, uint b) private pure returns (uint) {
return a < b ? a : b;
}
} | 1 | 5,526 |
pragma solidity ^0.4.20;
contract ERC20Basic {
uint256 public totalSupply;
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);
}
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a / b;
return c;
}
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) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
}
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);
}
contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply = totalSupply.add(_amount);
balances[_to] = balances[_to].add(_amount);
Mint(_to, _amount);
Transfer(address(0), _to, _amount);
return true;
}
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
MintFinished();
return true;
}
}
contract FreezableToken is StandardToken {
mapping (bytes32 => uint64) internal chains;
mapping (bytes32 => uint) internal freezings;
mapping (address => uint) internal freezingBalance;
event Freezed(address indexed to, uint64 release, uint amount);
event Released(address indexed owner, uint amount);
function balanceOf(address _owner) public view returns (uint256 balance) {
return super.balanceOf(_owner) + freezingBalance[_owner];
}
function actualBalanceOf(address _owner) public view returns (uint256 balance) {
return super.balanceOf(_owner);
}
function freezingBalanceOf(address _owner) public view returns (uint256 balance) {
return freezingBalance[_owner];
}
function freezingCount(address _addr) public view returns (uint count) {
uint64 release = chains[toKey(_addr, 0)];
while (release != 0) {
count ++;
release = chains[toKey(_addr, release)];
}
}
function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) {
for (uint i = 0; i < _index + 1; i ++) {
_release = chains[toKey(_addr, _release)];
if (_release == 0) {
return;
}
}
_balance = freezings[toKey(_addr, _release)];
}
function freezeTo(address _to, uint _amount, uint64 _until) public {
require(_to != address(0));
require(_amount <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_amount);
bytes32 currentKey = toKey(_to, _until);
freezings[currentKey] = freezings[currentKey].add(_amount);
freezingBalance[_to] = freezingBalance[_to].add(_amount);
freeze(_to, _until);
Freezed(_to, _until, _amount);
}
function releaseOnce() public {
bytes32 headKey = toKey(msg.sender, 0);
uint64 head = chains[headKey];
require(head != 0);
require(uint64(block.timestamp) > head);
bytes32 currentKey = toKey(msg.sender, head);
uint64 next = chains[currentKey];
uint amount = freezings[currentKey];
delete freezings[currentKey];
balances[msg.sender] = balances[msg.sender].add(amount);
freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount);
if (next == 0) {
delete chains[headKey];
}
else {
chains[headKey] = next;
delete chains[currentKey];
}
Released(msg.sender, amount);
}
function releaseAll() public returns (uint tokens) {
uint release;
uint balance;
(release, balance) = getFreezing(msg.sender, 0);
while (release != 0 && block.timestamp > release) {
releaseOnce();
tokens += balance;
(release, balance) = getFreezing(msg.sender, 0);
}
}
function toKey(address _addr, uint _release) internal pure returns (bytes32 result) {
result = 0x5749534800000000000000000000000000000000000000000000000000000000;
assembly {
result := or(result, mul(_addr, 0x10000000000000000))
result := or(result, _release)
}
}
function freeze(address _to, uint64 _until) internal {
require(_until > block.timestamp);
bytes32 key = toKey(_to, _until);
bytes32 parentKey = toKey(_to, uint64(0));
uint64 next = chains[parentKey];
if (next == 0) {
chains[parentKey] = _until;
return;
}
bytes32 nextKey = toKey(_to, next);
uint parent;
while (next != 0 && _until > next) {
parent = next;
parentKey = nextKey;
next = chains[nextKey];
nextKey = toKey(_to, next);
}
if (_until == next) {
return;
}
if (next != 0) {
chains[key] = next;
}
chains[parentKey] = _until;
}
}
contract ERC223Receiver {
function tokenFallback(address _from, uint _value, bytes _data) public;
}
contract ERC223Basic is ERC20Basic {
function transfer(address to, uint value, bytes data) public returns (bool);
event Transfer(address indexed from, address indexed to, uint value, bytes data);
}
contract SuccessfulERC223Receiver is ERC223Receiver {
event Invoked(address from, uint value, bytes data);
function tokenFallback(address _from, uint _value, bytes _data) public {
Invoked(_from, _value, _data);
}
}
contract FailingERC223Receiver is ERC223Receiver {
function tokenFallback(address, uint, bytes) public {
revert();
}
}
contract ERC223ReceiverWithoutTokenFallback {
}
contract BurnableToken is StandardToken {
event Burn(address indexed burner, uint256 value);
function burn(uint256 _value) public {
require(_value > 0);
require(_value <= balances[msg.sender]);
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
}
contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
modifier whenNotPaused() {
require(!paused);
_;
}
modifier whenPaused() {
require(paused);
_;
}
function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
}
function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
}
}
contract FreezableMintableToken is FreezableToken, MintableToken {
function mintAndFreeze(address _to, uint _amount, uint64 _until) onlyOwner canMint public returns (bool) {
totalSupply = totalSupply.add(_amount);
bytes32 currentKey = toKey(_to, _until);
freezings[currentKey] = freezings[currentKey].add(_amount);
freezingBalance[_to] = freezingBalance[_to].add(_amount);
freeze(_to, _until);
Mint(_to, _amount);
Freezed(_to, _until, _amount);
return true;
}
}
contract Consts {
uint constant TOKEN_DECIMALS = 8;
uint8 constant TOKEN_DECIMALS_UINT8 = 8;
uint constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS;
string constant TOKEN_NAME = "CryptoLink Network";
string constant TOKEN_SYMBOL = "CLN";
bool constant PAUSED = false;
address constant TARGET_USER = 0x70341461e043f4bF14c70018ff25Efb0a7DfEb64;
bool constant CONTINUE_MINTING = false;
}
contract ERC223Token is ERC223Basic, BasicToken, FailingERC223Receiver {
using SafeMath for uint;
function transfer(address _to, uint _value, bytes _data) public returns (bool) {
uint codeLength;
assembly {
codeLength := extcodesize(_to)
}
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
if(codeLength > 0) {
ERC223Receiver receiver = ERC223Receiver(_to);
receiver.tokenFallback(msg.sender, _value, _data);
}
Transfer(msg.sender, _to, _value, _data);
return true;
}
function transfer(address _to, uint256 _value) public returns (bool) {
bytes memory empty;
return transfer(_to, _value, empty);
}
}
contract CryptoLinkNet is Consts, FreezableMintableToken, BurnableToken, Pausable
{
event Initialized();
bool public initialized = false;
function CryptoLinkNet() public {
init();
transferOwnership(TARGET_USER);
}
function init() private {
require(!initialized);
initialized = true;
if (PAUSED) {
pause();
}
address[1] memory addresses = [address(0x70341461e043f4bF14c70018ff25Efb0a7DfEb64)];
uint[1] memory amounts = [uint(10000000000000000)];
uint64[1] memory freezes = [uint64(0)];
for (uint i = 0; i < addresses.length; i++) {
if (freezes[i] == 0) {
mint(addresses[i], amounts[i]);
} else {
mintAndFreeze(addresses[i], amounts[i], freezes[i]);
}
}
if (!CONTINUE_MINTING) {
finishMinting();
}
Initialized();
}
function name() pure public returns (string _name) {
return TOKEN_NAME;
}
function symbol() pure public returns (string _symbol) {
return TOKEN_SYMBOL;
}
function decimals() pure public returns (uint8 _decimals) {
return TOKEN_DECIMALS_UINT8;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool _success) {
require(!paused);
return super.transferFrom(_from, _to, _value);
}
function transfer(address _to, uint256 _value) public returns (bool _success) {
require(!paused);
return super.transfer(_to, _value);
}
} | 1 | 2,706 |
pragma solidity ^0.4.24;
contract AceDice {
uint constant HOUSE_EDGE_PERCENT = 2;
uint constant HOUSE_EDGE_MINIMUM_AMOUNT = 0.0004 ether;
uint constant MIN_JACKPOT_BET = 0.1 ether;
uint constant JACKPOT_MODULO = 1000;
uint constant JACKPOT_FEE = 0.001 ether;
uint constant MIN_BET = 0.01 ether;
uint constant MAX_AMOUNT = 300000 ether;
uint constant MAX_MASK_MODULO = 40;
uint constant MAX_BET_MASK = 2 ** MAX_MASK_MODULO;
uint constant BET_EXPIRATION_BLOCKS = 250;
address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address public owner;
address private nextOwner;
uint public maxProfit;
address public secretSigner;
uint128 public jackpotSize;
uint public todaysRewardSize;
uint128 public lockedInBets;
struct Bet {
uint amount;
uint8 rollUnder;
uint40 placeBlockNumber;
uint40 mask;
address gambler;
address inviter;
}
struct Profile{
uint avatarIndex;
string nickName;
}
mapping (uint => Bet) bets;
mapping (address => uint) accuBetAmount;
mapping (address => Profile) profiles;
address public croupier;
event FailedPayment(address indexed beneficiary, uint amount);
event Payment(address indexed beneficiary, uint amount, uint dice, uint rollUnder, uint betAmount);
event JackpotPayment(address indexed beneficiary, uint amount, uint dice, uint rollUnder, uint betAmount);
event VIPPayback(address indexed beneficiary, uint amount);
event Commit(uint commit);
event TodaysRankingPayment(address indexed beneficiary, uint amount);
constructor () public {
owner = msg.sender;
secretSigner = DUMMY_ADDRESS;
croupier = DUMMY_ADDRESS;
}
modifier onlyOwner {
require (msg.sender == owner, "OnlyOwner methods called by non-owner.");
_;
}
modifier onlyCroupier {
require (msg.sender == croupier, "OnlyCroupier methods called by non-croupier.");
_;
}
function approveNextOwner(address _nextOwner) external onlyOwner {
require (_nextOwner != owner, "Cannot approve current owner.");
nextOwner = _nextOwner;
}
function acceptNextOwner() external {
require (msg.sender == nextOwner, "Can only accept preapproved new owner.");
owner = nextOwner;
}
function () public payable {
}
function setSecretSigner(address newSecretSigner) external onlyOwner {
secretSigner = newSecretSigner;
}
function getSecretSigner() external onlyOwner view returns(address){
return secretSigner;
}
function setCroupier(address newCroupier) external onlyOwner {
croupier = newCroupier;
}
function setMaxProfit(uint _maxProfit) public onlyOwner {
require (_maxProfit < MAX_AMOUNT, "maxProfit should be a sane number.");
maxProfit = _maxProfit;
}
function increaseJackpot(uint increaseAmount) external onlyOwner {
require (increaseAmount <= address(this).balance, "Increase amount larger than balance.");
require (jackpotSize + lockedInBets + increaseAmount <= address(this).balance, "Not enough funds.");
jackpotSize += uint128(increaseAmount);
}
function withdrawFunds(address beneficiary, uint withdrawAmount) external onlyOwner {
require (withdrawAmount <= address(this).balance, "Increase amount larger than balance.");
require (jackpotSize + lockedInBets + withdrawAmount <= address(this).balance, "Not enough funds.");
sendFunds(beneficiary, withdrawAmount, withdrawAmount, 0, 0, 0);
}
function kill() external onlyOwner {
require (lockedInBets == 0, "All bets should be processed (settled or refunded) before self-destruct.");
selfdestruct(owner);
}
function encodePacketCommit(uint commitLastBlock, uint commit) private pure returns(bytes memory){
return abi.encodePacked(uint40(commitLastBlock), commit);
}
function verifyCommit(uint commitLastBlock, uint commit, uint8 v, bytes32 r, bytes32 s) private view {
require (block.number <= commitLastBlock, "Commit has expired.");
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes memory message = encodePacketCommit(commitLastBlock, commit);
bytes32 messageHash = keccak256(abi.encodePacked(prefix, keccak256(message)));
require (secretSigner == ecrecover(messageHash, v, r, s), "ECDSA signature is not valid.");
}
function placeBet(uint betMask, uint commitLastBlock, uint commit, uint8 v, bytes32 r, bytes32 s) external payable {
Bet storage bet = bets[commit];
require (bet.gambler == address(0), "Bet should be in a 'clean' state.");
uint amount = msg.value;
require (amount >= MIN_BET && amount <= MAX_AMOUNT, "Amount should be within range.");
require (betMask > 0 && betMask < MAX_BET_MASK, "Mask should be within range.");
verifyCommit(commitLastBlock, commit, v, r, s);
uint mask;
require (betMask > 0 && betMask <= 100, "High modulo range, betMask larger than modulo.");
uint possibleWinAmount;
uint jackpotFee;
(possibleWinAmount, jackpotFee) = getDiceWinAmount(amount, betMask);
require (possibleWinAmount <= amount + maxProfit, "maxProfit limit violation. ");
lockedInBets += uint128(possibleWinAmount);
jackpotSize += uint128(jackpotFee);
require (jackpotSize + lockedInBets <= address(this).balance, "Cannot afford to lose this bet.");
emit Commit(commit);
bet.amount = amount;
bet.rollUnder = uint8(betMask);
bet.placeBlockNumber = uint40(block.number);
bet.mask = uint40(mask);
bet.gambler = msg.sender;
uint accuAmount = accuBetAmount[msg.sender];
accuAmount = accuAmount + amount;
accuBetAmount[msg.sender] = accuAmount;
}
function applyVIPLevel(address gambler, uint amount) private {
uint accuAmount = accuBetAmount[gambler];
uint rate;
if(accuAmount >= 30 ether && accuAmount < 150 ether){
rate = 1;
} else if(accuAmount >= 150 ether && accuAmount < 300 ether){
rate = 2;
} else if(accuAmount >= 300 ether && accuAmount < 1500 ether){
rate = 4;
} else if(accuAmount >= 1500 ether && accuAmount < 3000 ether){
rate = 6;
} else if(accuAmount >= 3000 ether && accuAmount < 15000 ether){
rate = 8;
} else if(accuAmount >= 15000 ether && accuAmount < 30000 ether){
rate = 10;
} else if(accuAmount >= 30000 ether && accuAmount < 150000 ether){
rate = 12;
} else if(accuAmount >= 150000 ether){
rate = 15;
} else{
return;
}
uint vipPayback = amount * rate / 10000;
if(gambler.send(vipPayback)){
emit VIPPayback(gambler, vipPayback);
}
}
function placeBetWithInviter(uint betMask, uint commitLastBlock, uint commit, uint8 v, bytes32 r, bytes32 s, address inviter) external payable {
Bet storage bet = bets[commit];
require (bet.gambler == address(0), "Bet should be in a 'clean' state.");
uint amount = msg.value;
require (amount >= MIN_BET && amount <= MAX_AMOUNT, "Amount should be within range.");
require (betMask > 0 && betMask < MAX_BET_MASK, "Mask should be within range.");
require (address(this) != inviter && inviter != address(0), "cannot invite mysql");
verifyCommit(commitLastBlock, commit, v, r, s);
uint mask;
require (betMask > 0 && betMask <= 100, "High modulo range, betMask larger than modulo.");
uint possibleWinAmount;
uint jackpotFee;
(possibleWinAmount, jackpotFee) = getDiceWinAmount(amount, betMask);
require (possibleWinAmount <= amount + maxProfit, "maxProfit limit violation. ");
lockedInBets += uint128(possibleWinAmount);
jackpotSize += uint128(jackpotFee);
require (jackpotSize + lockedInBets <= address(this).balance, "Cannot afford to lose this bet.");
emit Commit(commit);
bet.amount = amount;
bet.rollUnder = uint8(betMask);
bet.placeBlockNumber = uint40(block.number);
bet.mask = uint40(mask);
bet.gambler = msg.sender;
bet.inviter = inviter;
uint accuAmount = accuBetAmount[msg.sender];
accuAmount = accuAmount + amount;
accuBetAmount[msg.sender] = accuAmount;
}
function getMyAccuAmount() external view returns (uint){
return accuBetAmount[msg.sender];
}
function settleBet(uint reveal, bytes32 blockHash) external onlyCroupier {
uint commit = uint(keccak256(abi.encodePacked(reveal)));
Bet storage bet = bets[commit];
uint placeBlockNumber = bet.placeBlockNumber;
require (block.number > placeBlockNumber, "settleBet in the same block as placeBet, or before.");
require (block.number <= placeBlockNumber + BET_EXPIRATION_BLOCKS, "Blockhash can't be queried by EVM.");
require (blockhash(placeBlockNumber) == blockHash);
settleBetCommon(bet, reveal, blockHash);
}
function settleBetUncleMerkleProof(uint reveal, uint40 canonicalBlockNumber) external onlyCroupier {
uint commit = uint(keccak256(abi.encodePacked(reveal)));
Bet storage bet = bets[commit];
require (block.number <= canonicalBlockNumber + BET_EXPIRATION_BLOCKS, "Blockhash can't be queried by EVM.");
requireCorrectReceipt(4 + 32 + 32 + 4);
bytes32 canonicalHash;
bytes32 uncleHash;
(canonicalHash, uncleHash) = verifyMerkleProof(commit, 4 + 32 + 32);
require (blockhash(canonicalBlockNumber) == canonicalHash);
settleBetCommon(bet, reveal, uncleHash);
}
function settleBetCommon(Bet storage bet, uint reveal, bytes32 entropyBlockHash) private {
uint amount = bet.amount;
uint rollUnder = bet.rollUnder;
address gambler = bet.gambler;
require (amount != 0, "Bet should be in an 'active' state");
applyVIPLevel(gambler, amount);
bet.amount = 0;
bytes32 entropy = keccak256(abi.encodePacked(reveal, entropyBlockHash));
uint modulo = 100;
uint dice = uint(entropy) % modulo;
uint diceWinAmount;
uint _jackpotFee;
(diceWinAmount, _jackpotFee) = getDiceWinAmount(amount, rollUnder);
uint diceWin = 0;
uint jackpotWin = 0;
if (modulo <= MAX_MASK_MODULO) {
if ((2 ** dice) & bet.mask != 0) {
diceWin = diceWinAmount;
}
} else {
if (dice < rollUnder) {
diceWin = diceWinAmount;
}
}
lockedInBets -= uint128(diceWinAmount);
if (amount >= MIN_JACKPOT_BET) {
if ((uint(entropy) / modulo) % JACKPOT_MODULO == 0) {
jackpotWin = jackpotSize;
jackpotSize = 0;
}
}
if (jackpotWin > 0) {
emit JackpotPayment(gambler, jackpotWin, dice, rollUnder, amount);
}
if(bet.inviter != address(0)){
bet.inviter.transfer(amount * HOUSE_EDGE_PERCENT / 100 * 15 /100);
}
todaysRewardSize += amount * HOUSE_EDGE_PERCENT / 100 * 9 /100;
sendFunds(gambler, diceWin + jackpotWin == 0 ? 1 wei : diceWin + jackpotWin, diceWin, dice, rollUnder, amount);
}
function refundBet(uint commit) external {
Bet storage bet = bets[commit];
uint amount = bet.amount;
require (amount != 0, "Bet should be in an 'active' state");
require (block.number > bet.placeBlockNumber + BET_EXPIRATION_BLOCKS, "Blockhash can't be queried by EVM.");
bet.amount = 0;
uint diceWinAmount;
uint jackpotFee;
(diceWinAmount, jackpotFee) = getDiceWinAmount(amount, bet.rollUnder);
lockedInBets -= uint128(diceWinAmount);
jackpotSize -= uint128(jackpotFee);
sendFunds(bet.gambler, amount, amount, 0, 0, 0);
}
function getDiceWinAmount(uint amount, uint rollUnder) private pure returns (uint winAmount, uint jackpotFee) {
require (0 < rollUnder && rollUnder <= 100, "Win probability out of range.");
jackpotFee = amount >= MIN_JACKPOT_BET ? JACKPOT_FEE : 0;
uint houseEdge = amount * HOUSE_EDGE_PERCENT / 100;
if (houseEdge < HOUSE_EDGE_MINIMUM_AMOUNT) {
houseEdge = HOUSE_EDGE_MINIMUM_AMOUNT;
}
require (houseEdge + jackpotFee <= amount, "Bet doesn't even cover house edge.");
winAmount = (amount - houseEdge - jackpotFee) * 100 / rollUnder;
}
function sendFunds(address beneficiary, uint amount, uint successLogAmount, uint dice, uint rollUnder, uint betAmount) private {
if (beneficiary.send(amount)) {
emit Payment(beneficiary, successLogAmount, dice, rollUnder, betAmount);
} else {
emit FailedPayment(beneficiary, amount);
}
}
uint constant POPCNT_MULT = 0x0000000000002000000000100000000008000000000400000000020000000001;
uint constant POPCNT_MASK = 0x0001041041041041041041041041041041041041041041041041041041041041;
uint constant POPCNT_MODULO = 0x3F;
function verifyMerkleProof(uint seedHash, uint offset) pure private returns (bytes32 blockHash, bytes32 uncleHash) {
uint scratchBuf1; assembly { scratchBuf1 := mload(0x40) }
uint uncleHeaderLength; uint blobLength; uint shift; uint hashSlot;
for (;; offset += blobLength) {
assembly { blobLength := and(calldataload(sub(offset, 30)), 0xffff) }
if (blobLength == 0) {
break;
}
assembly { shift := and(calldataload(sub(offset, 28)), 0xffff) }
require (shift + 32 <= blobLength, "Shift bounds check.");
offset += 4;
assembly { hashSlot := calldataload(add(offset, shift)) }
require (hashSlot == 0, "Non-empty hash slot.");
assembly {
calldatacopy(scratchBuf1, offset, blobLength)
mstore(add(scratchBuf1, shift), seedHash)
seedHash := sha3(scratchBuf1, blobLength)
uncleHeaderLength := blobLength
}
}
uncleHash = bytes32(seedHash);
uint scratchBuf2 = scratchBuf1 + uncleHeaderLength;
uint unclesLength; assembly { unclesLength := and(calldataload(sub(offset, 28)), 0xffff) }
uint unclesShift; assembly { unclesShift := and(calldataload(sub(offset, 26)), 0xffff) }
require (unclesShift + uncleHeaderLength <= unclesLength, "Shift bounds check.");
offset += 6;
assembly { calldatacopy(scratchBuf2, offset, unclesLength) }
memcpy(scratchBuf2 + unclesShift, scratchBuf1, uncleHeaderLength);
assembly { seedHash := sha3(scratchBuf2, unclesLength) }
offset += unclesLength;
assembly {
blobLength := and(calldataload(sub(offset, 30)), 0xffff)
shift := and(calldataload(sub(offset, 28)), 0xffff)
}
require (shift + 32 <= blobLength, "Shift bounds check.");
offset += 4;
assembly { hashSlot := calldataload(add(offset, shift)) }
require (hashSlot == 0, "Non-empty hash slot.");
assembly {
calldatacopy(scratchBuf1, offset, blobLength)
mstore(add(scratchBuf1, shift), seedHash)
blockHash := sha3(scratchBuf1, blobLength)
}
}
function requireCorrectReceipt(uint offset) view private {
uint leafHeaderByte; assembly { leafHeaderByte := byte(0, calldataload(offset)) }
require (leafHeaderByte >= 0xf7, "Receipt leaf longer than 55 bytes.");
offset += leafHeaderByte - 0xf6;
uint pathHeaderByte; assembly { pathHeaderByte := byte(0, calldataload(offset)) }
if (pathHeaderByte <= 0x7f) {
offset += 1;
} else {
require (pathHeaderByte >= 0x80 && pathHeaderByte <= 0xb7, "Path is an RLP string.");
offset += pathHeaderByte - 0x7f;
}
uint receiptStringHeaderByte; assembly { receiptStringHeaderByte := byte(0, calldataload(offset)) }
require (receiptStringHeaderByte == 0xb9, "Receipt string is always at least 256 bytes long, but less than 64k.");
offset += 3;
uint receiptHeaderByte; assembly { receiptHeaderByte := byte(0, calldataload(offset)) }
require (receiptHeaderByte == 0xf9, "Receipt is always at least 256 bytes long, but less than 64k.");
offset += 3;
uint statusByte; assembly { statusByte := byte(0, calldataload(offset)) }
require (statusByte == 0x1, "Status should be success.");
offset += 1;
uint cumGasHeaderByte; assembly { cumGasHeaderByte := byte(0, calldataload(offset)) }
if (cumGasHeaderByte <= 0x7f) {
offset += 1;
} else {
require (cumGasHeaderByte >= 0x80 && cumGasHeaderByte <= 0xb7, "Cumulative gas is an RLP string.");
offset += cumGasHeaderByte - 0x7f;
}
uint bloomHeaderByte; assembly { bloomHeaderByte := byte(0, calldataload(offset)) }
require (bloomHeaderByte == 0xb9, "Bloom filter is always 256 bytes long.");
offset += 256 + 3;
uint logsListHeaderByte; assembly { logsListHeaderByte := byte(0, calldataload(offset)) }
require (logsListHeaderByte == 0xf8, "Logs list is less than 256 bytes long.");
offset += 2;
uint logEntryHeaderByte; assembly { logEntryHeaderByte := byte(0, calldataload(offset)) }
require (logEntryHeaderByte == 0xf8, "Log entry is less than 256 bytes long.");
offset += 2;
uint addressHeaderByte; assembly { addressHeaderByte := byte(0, calldataload(offset)) }
require (addressHeaderByte == 0x94, "Address is 20 bytes long.");
uint logAddress; assembly { logAddress := and(calldataload(sub(offset, 11)), 0xffffffffffffffffffffffffffffffffffffffff) }
require (logAddress == uint(address(this)));
}
function memcpy(uint dest, uint src, uint len) pure private {
for(; len >= 32; len -= 32) {
assembly { mstore(dest, mload(src)) }
dest += 32; src += 32;
}
uint mask = 256 ** (32 - len) - 1;
assembly {
let srcpart := and(mload(src), not(mask))
let destpart := and(mload(dest), mask)
mstore(dest, or(destpart, srcpart))
}
}
function thisBalance() public view returns(uint) {
return address(this).balance;
}
function setAvatarIndex(uint index) external{
require (index >=0 && index <= 100, "avatar index should be in range");
Profile storage profile = profiles[msg.sender];
profile.avatarIndex = index;
}
function setNickName(string nickName) external{
Profile storage profile = profiles[msg.sender];
profile.nickName = nickName;
}
function getProfile() external view returns(uint, string){
Profile storage profile = profiles[msg.sender];
return (profile.avatarIndex, profile.nickName);
}
function payTodayReward(address to, uint rate) external onlyOwner {
uint prize = todaysRewardSize * rate / 10000;
todaysRewardSize = todaysRewardSize - prize;
if(to.send(prize)){
emit TodaysRankingPayment(to, prize);
}
}
} | 0 | 831 |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 39