contract_name
stringlengths 1
61
| file_path
stringlengths 5
50.4k
| contract_address
stringlengths 42
42
| language
stringclasses 1
value | class_name
stringlengths 1
61
| class_code
stringlengths 4
330k
| class_documentation
stringlengths 0
29.1k
| class_documentation_type
stringclasses 6
values | func_name
stringlengths 0
62
| func_code
stringlengths 1
303k
| func_documentation
stringlengths 2
14.9k
| func_documentation_type
stringclasses 4
values | compiler_version
stringlengths 15
42
| license_type
stringclasses 14
values | swarm_source
stringlengths 0
71
| meta
dict | __index_level_0__
int64 0
60.4k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
3188,
3471
]
} | 5,907 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
3931,
4066
]
} | 5,908 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
4546,
4717
]
} | 5,909 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
94,
154
]
} | 5,910 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
237,
310
]
} | 5,911 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
534,
616
]
} | 5,912 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) external view returns (uint256);
| /**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
895,
983
]
} | 5,913 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
1647,
1726
]
} | 5,914 |
tokenCustody | tokenCustody.sol | 0x5456ceeafed34dd82231f73610155f90f467377f | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.6+commit.6c089d02 | None | ipfs://b5e33be562957b6c8fc64c00bbdf31f13085800605a600d627d38a23e7249c3e | {
"func_code_index": [
2039,
2141
]
} | 5,915 |
MDULUCKYToken | MDULUCKYToken.sol | 0x5ebfaa7d023ed9bd71bb5349e3a5c5767aadf349 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
} | totalSupply | function totalSupply() constant returns (uint supply) {}
| /// @return total amount of tokens | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | None | bzzr://57baa2c11a247097f088e9d8e395cfd676f446624c913e5438b9355724da13fe | {
"func_code_index": [
60,
121
]
} | 5,916 |
||
MDULUCKYToken | MDULUCKYToken.sol | 0x5ebfaa7d023ed9bd71bb5349e3a5c5767aadf349 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
} | balanceOf | function balanceOf(address _owner) constant returns (uint balance) {}
| /// @param _owner The address from which the balance will be retrieved
/// @return The balance | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | None | bzzr://57baa2c11a247097f088e9d8e395cfd676f446624c913e5438b9355724da13fe | {
"func_code_index": [
229,
303
]
} | 5,917 |
||
MDULUCKYToken | MDULUCKYToken.sol | 0x5ebfaa7d023ed9bd71bb5349e3a5c5767aadf349 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
} | transfer | function transfer(address _to, uint _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | None | bzzr://57baa2c11a247097f088e9d8e395cfd676f446624c913e5438b9355724da13fe | {
"func_code_index": [
540,
614
]
} | 5,918 |
||
MDULUCKYToken | MDULUCKYToken.sol | 0x5ebfaa7d023ed9bd71bb5349e3a5c5767aadf349 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
} | transferFrom | function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | None | bzzr://57baa2c11a247097f088e9d8e395cfd676f446624c913e5438b9355724da13fe | {
"func_code_index": [
937,
1030
]
} | 5,919 |
||
MDULUCKYToken | MDULUCKYToken.sol | 0x5ebfaa7d023ed9bd71bb5349e3a5c5767aadf349 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
} | approve | function approve(address _spender, uint _value) returns (bool success) {}
| /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | None | bzzr://57baa2c11a247097f088e9d8e395cfd676f446624c913e5438b9355724da13fe | {
"func_code_index": [
1314,
1392
]
} | 5,920 |
||
MDULUCKYToken | MDULUCKYToken.sol | 0x5ebfaa7d023ed9bd71bb5349e3a5c5767aadf349 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint remaining) {}
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
} | allowance | function allowance(address _owner, address _spender) constant returns (uint remaining) {}
| /// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | None | bzzr://57baa2c11a247097f088e9d8e395cfd676f446624c913e5438b9355724da13fe | {
"func_code_index": [
1600,
1694
]
} | 5,921 |
||
MDULUCKYToken | MDULUCKYToken.sol | 0x5ebfaa7d023ed9bd71bb5349e3a5c5767aadf349 | Solidity | UnboundedRegularToken | contract UnboundedRegularToken is RegularToken {
uint constant MAX_UINT = 2**256 - 1;
/// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited amount.
/// @param _from Address to transfer from.
/// @param _to Address to transfer to.
/// @param _value Amount to transfer.
/// @return Success of transfer.
function transferFrom(address _from, address _to, uint _value)
public
returns (bool)
{
uint allowance = allowed[_from][msg.sender];
if (balances[_from] >= _value
&& allowance >= _value
&& balances[_to] + _value >= balances[_to]
) {
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT) {
allowed[_from][msg.sender] -= _value;
}
Transfer(_from, _to, _value);
return true;
} else {
return false;
}
}
} | transferFrom | function transferFrom(address _from, address _to, uint _value)
public
returns (bool)
{
uint allowance = allowed[_from][msg.sender];
if (balances[_from] >= _value
&& allowance >= _value
&& balances[_to] + _value >= balances[_to]
) {
balances[_to] += _value;
balances[_from] -= _value;
if (allowance < MAX_UINT) {
allowed[_from][msg.sender] -= _value;
}
Transfer(_from, _to, _value);
return true;
} else {
return false;
}
}
| /// @dev ERC20 transferFrom, modified such that an allowance of MAX_UINT represents an unlimited amount.
/// @param _from Address to transfer from.
/// @param _to Address to transfer to.
/// @param _value Amount to transfer.
/// @return Success of transfer. | NatSpecSingleLine | v0.4.19+commit.c4cbbb05 | None | bzzr://57baa2c11a247097f088e9d8e395cfd676f446624c913e5438b9355724da13fe | {
"func_code_index": [
383,
1016
]
} | 5,922 |
||
XChainTrade | IXChainTrade.sol | 0x3091008cdca6e6482698e8d34e5e543f6932eb4c | Solidity | IERC1155Receiver | interface IERC1155Receiver is IERC165 {
/**
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(address operator, address from, uint256 id, uint256 value, bytes calldata data) external returns (bytes4);
/**
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data) external returns (bytes4);
} | onERC1155Received | function onERC1155Received(address operator, address from, uint256 id, uint256 value, bytes calldata data) external returns (bytes4);
| /**
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | GNU GPLv3 | ipfs://8655bf97d399c1d95fba1b4db00c4af77576c87f62540e0be317af025b4557f5 | {
"func_code_index": [
503,
641
]
} | 5,923 |
||
XChainTrade | IXChainTrade.sol | 0x3091008cdca6e6482698e8d34e5e543f6932eb4c | Solidity | IERC1155Receiver | interface IERC1155Receiver is IERC165 {
/**
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(address operator, address from, uint256 id, uint256 value, bytes calldata data) external returns (bytes4);
/**
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data) external returns (bytes4);
} | onERC1155BatchReceived | function onERC1155BatchReceived(address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data) external returns (bytes4);
| /**
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | GNU GPLv3 | ipfs://8655bf97d399c1d95fba1b4db00c4af77576c87f62540e0be317af025b4557f5 | {
"func_code_index": [
1245,
1412
]
} | 5,924 |
||
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | totalSupply | function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
| // ************************************************************************
// Total supply
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
1671,
1790
]
} | 5,925 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | balanceOf | function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
| // ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
2010,
2135
]
} | 5,926 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | transfer | function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
| // ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
2479,
2835
]
} | 5,927 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | approve | function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
| // ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
3115,
3398
]
} | 5,928 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
| // ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
3937,
4408
]
} | 5,929 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | batchTransfer | function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
nt len = toAddresses.length;
quire(0 < len);
nt amount = tokens.mul(len);
quire(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
| // ************************************************************************
// Batch transfer for owner.
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
4607,
5204
]
} | 5,930 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | allowance | function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
| // ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
5485,
5637
]
} | 5,931 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | approveAndCall | function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
| // ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
5998,
6334
]
} | 5,932 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | function () public payable {
revert();
}
| // ************************************************************************
// Don't accept ETH
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
6524,
6583
]
} | 5,933 |
||
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | pause | function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
| // ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
6809,
6917
]
} | 5,934 |
|
AIC20Token | AIC20Token.sol | 0x7e6eb33d0dc079e249ab0df29be1a35117d1ba4a | Solidity | AIC20Token | contract AIC20Token is ERC20, Owned {
using SafeMath for uint;
event Pause();
event Unpause();
bool public paused = false;
string public symbol;
string public name;
uint8 public decimals;
uint private _totalSupply;
mapping(address => uint) balances;
mapping(address => mapping(address => uint)) allowed;
// ************************************************************************
// Modifier to make a function callable only when the contract is not paused.
// ************************************************************************
modifier whenNotPaused() {
require(!paused);
_;
}
// ************************************************************************
// Modifier to make a function callable only when the contract is paused.
// ************************************************************************
modifier whenPaused() {
require(paused);
_;
}
// ************************************************************************
// Constructor
// ************************************************************************
constructor() public {
symbol = "AIC20";
name = "Agricultural industrial chain 20";
decimals = 8;
_totalSupply = 1000000000 * 10**uint(decimals);
balances[owner] = _totalSupply;
emit Transfer(address(0), owner, _totalSupply);
}
// ************************************************************************
// Total supply
// ************************************************************************
function totalSupply() public view returns (uint) {
return _totalSupply.sub(balances[address(0)]);
}
// ************************************************************************
// Get the token balance for account `tokenOwner`
// ************************************************************************
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
// ************************************************************************
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transfer(address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(msg.sender, to, tokens);
return true;
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
// ************************************************************************
function approve(address spender, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != spender && 0 <= tokens);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
// ************************************************************************
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ************************************************************************
function transferFrom(address from, address to, uint tokens) public whenNotPaused returns (bool success) {
require(address(0) != to && tokens <= balances[msg.sender] && tokens <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
emit Transfer(from, to, tokens);
return true;
}
// ************************************************************************
// Batch transfer for owner.
// ************************************************************************
function batchTransfer(address[] toAddresses, uint tokens) public onlyOwner whenNotPaused returns (bool success) {
uint len = toAddresses.length;
require(0 < len);
uint amount = tokens.mul(len);
require(amount <= balances[msg.sender]);
for (uint i = 0; i < len; i++) {
address _to = toAddresses[i];
require(address(0) != _to);
balances[_to] = balances[_to].add(tokens);
balances[msg.sender] = balances[msg.sender].sub(tokens);
emit Transfer(msg.sender, _to, tokens);
}
return true;
}
// ************************************************************************
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ************************************************************************
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ************************************************************************
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ************************************************************************
function approveAndCall(address spender, uint tokens, bytes data) public whenNotPaused returns (bool success) {
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ************************************************************************
// Don't accept ETH
// ************************************************************************
function () public payable {
revert();
}
// ************************************************************************
// called by the owner to pause, triggers stopped state
// ************************************************************************
function pause() public onlyOwner whenNotPaused {
paused = true;
emit Pause();
}
// ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************
function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
} | // ****************************************************************************
// BECC Token, with the addition of symbol, name and decimals and a fixed supply
// **************************************************************************** | LineComment | unpause | function unpause() public onlyOwner whenPaused {
paused = false;
emit Unpause();
}
| // ************************************************************************
// called by the owner to unpause, returns to normal state
// ************************************************************************ | LineComment | v0.4.25+commit.59dbf8f1 | bzzr://19a9ba28f46c3c85d842e4a439c8549ab35be9a1f0780d997755a2c8a1f92a25 | {
"func_code_index": [
7146,
7256
]
} | 5,935 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | Ownable | function Ownable() public {
owner = msg.sender;
}
| /**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
273,
341
]
} | 5,936 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
| /**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
690,
882
]
} | 5,937 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
282,
705
]
} | 5,938 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
921,
1041
]
} | 5,939 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
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;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | 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;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
415,
903
]
} | 5,940 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
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;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
1555,
1761
]
} | 5,941 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
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;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
2097,
2236
]
} | 5,942 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
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;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | 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;
}
| /**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
2493,
2774
]
} | 5,943 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | BurnableToken | contract BurnableToken is StandardToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
} | /**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/ | NatSpecMultiLine | burn | function burn(uint256 _value) public {
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
Burn(burner, _value);
}
| /**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/ | NatSpecMultiLine | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
225,
683
]
} | 5,944 |
|
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | UniversalManager | contract UniversalManager is Ownable {
using SafeMath for uint256;
uint256 public constant ADDRESS_LIMIT = 300;
uint256 public constant TRANSFERS_PER_TRANSACTION = 150;
uint256 public airdrop;
UniversalCoin public token;
uint256 private currentPool = 0;
uint256 private index = 0;
uint256 private airdropIndex = 0;
address[] private participants;
address[] private airdropParticipants;
function UniversalManager(address uniFoundation) public {
token = new UniversalCoin(uniFoundation);
airdrop = token.airdropReserve().div(3);
}
// Set size of current week tokens pool
function setCurrentWeekPool(uint256 _currentPool) public onlyOwner {
require(_currentPool > 0);
currentPool = _currentPool;
}
// Adds participant for the current week
function addParticipants(address[] _participants) external onlyOwner {
require(_participants.length != 0 && _participants.length <= ADDRESS_LIMIT);
participants = _participants;
}
// Add all unique participants for receiving airdrop
function addAirdropParticipants(address[] _airdropParticipants) public onlyOwner {
require(_airdropParticipants.length != 0 && _airdropParticipants.length <= ADDRESS_LIMIT);
airdropParticipants = _airdropParticipants;
}
// Transfer tokens to current week participants
function transfer(uint256 _amount) public onlyOwner {
uint256 max;
uint256 length = participants.length;
if ((index + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = index + TRANSFERS_PER_TRANSACTION;
}
for (uint i = index; i < max; i++) {
token.transfer(participants[i], _amount);
}
if (max >= length) {
index = 0;
} else {
index += TRANSFERS_PER_TRANSACTION;
}
}
// Transfer airdrop tokens to all registered participants
function transferAidrop() public onlyOwner {
uint256 max;
uint256 length = airdropParticipants.length;
if ((airdropIndex + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = airdropIndex + TRANSFERS_PER_TRANSACTION;
}
uint256 share;
for (uint i = airdropIndex; i < max; i++) {
share = (airdrop.mul(token.balanceOf(airdropParticipants[i]))).div(token.totalSupply());
if (share == 0) {
continue;
}
token.transfer(airdropParticipants[i], share);
}
if (max >= length) {
airdropIndex = 0;
} else {
airdropIndex += TRANSFERS_PER_TRANSACTION;
}
}
} | setCurrentWeekPool | function setCurrentWeekPool(uint256 _currentPool) public onlyOwner {
require(_currentPool > 0);
currentPool = _currentPool;
}
| // Set size of current week tokens pool | LineComment | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
663,
816
]
} | 5,945 |
|||
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | UniversalManager | contract UniversalManager is Ownable {
using SafeMath for uint256;
uint256 public constant ADDRESS_LIMIT = 300;
uint256 public constant TRANSFERS_PER_TRANSACTION = 150;
uint256 public airdrop;
UniversalCoin public token;
uint256 private currentPool = 0;
uint256 private index = 0;
uint256 private airdropIndex = 0;
address[] private participants;
address[] private airdropParticipants;
function UniversalManager(address uniFoundation) public {
token = new UniversalCoin(uniFoundation);
airdrop = token.airdropReserve().div(3);
}
// Set size of current week tokens pool
function setCurrentWeekPool(uint256 _currentPool) public onlyOwner {
require(_currentPool > 0);
currentPool = _currentPool;
}
// Adds participant for the current week
function addParticipants(address[] _participants) external onlyOwner {
require(_participants.length != 0 && _participants.length <= ADDRESS_LIMIT);
participants = _participants;
}
// Add all unique participants for receiving airdrop
function addAirdropParticipants(address[] _airdropParticipants) public onlyOwner {
require(_airdropParticipants.length != 0 && _airdropParticipants.length <= ADDRESS_LIMIT);
airdropParticipants = _airdropParticipants;
}
// Transfer tokens to current week participants
function transfer(uint256 _amount) public onlyOwner {
uint256 max;
uint256 length = participants.length;
if ((index + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = index + TRANSFERS_PER_TRANSACTION;
}
for (uint i = index; i < max; i++) {
token.transfer(participants[i], _amount);
}
if (max >= length) {
index = 0;
} else {
index += TRANSFERS_PER_TRANSACTION;
}
}
// Transfer airdrop tokens to all registered participants
function transferAidrop() public onlyOwner {
uint256 max;
uint256 length = airdropParticipants.length;
if ((airdropIndex + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = airdropIndex + TRANSFERS_PER_TRANSACTION;
}
uint256 share;
for (uint i = airdropIndex; i < max; i++) {
share = (airdrop.mul(token.balanceOf(airdropParticipants[i]))).div(token.totalSupply());
if (share == 0) {
continue;
}
token.transfer(airdropParticipants[i], share);
}
if (max >= length) {
airdropIndex = 0;
} else {
airdropIndex += TRANSFERS_PER_TRANSACTION;
}
}
} | addParticipants | function addParticipants(address[] _participants) external onlyOwner {
require(_participants.length != 0 && _participants.length <= ADDRESS_LIMIT);
participants = _participants;
}
| // Adds participant for the current week | LineComment | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
865,
1072
]
} | 5,946 |
|||
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | UniversalManager | contract UniversalManager is Ownable {
using SafeMath for uint256;
uint256 public constant ADDRESS_LIMIT = 300;
uint256 public constant TRANSFERS_PER_TRANSACTION = 150;
uint256 public airdrop;
UniversalCoin public token;
uint256 private currentPool = 0;
uint256 private index = 0;
uint256 private airdropIndex = 0;
address[] private participants;
address[] private airdropParticipants;
function UniversalManager(address uniFoundation) public {
token = new UniversalCoin(uniFoundation);
airdrop = token.airdropReserve().div(3);
}
// Set size of current week tokens pool
function setCurrentWeekPool(uint256 _currentPool) public onlyOwner {
require(_currentPool > 0);
currentPool = _currentPool;
}
// Adds participant for the current week
function addParticipants(address[] _participants) external onlyOwner {
require(_participants.length != 0 && _participants.length <= ADDRESS_LIMIT);
participants = _participants;
}
// Add all unique participants for receiving airdrop
function addAirdropParticipants(address[] _airdropParticipants) public onlyOwner {
require(_airdropParticipants.length != 0 && _airdropParticipants.length <= ADDRESS_LIMIT);
airdropParticipants = _airdropParticipants;
}
// Transfer tokens to current week participants
function transfer(uint256 _amount) public onlyOwner {
uint256 max;
uint256 length = participants.length;
if ((index + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = index + TRANSFERS_PER_TRANSACTION;
}
for (uint i = index; i < max; i++) {
token.transfer(participants[i], _amount);
}
if (max >= length) {
index = 0;
} else {
index += TRANSFERS_PER_TRANSACTION;
}
}
// Transfer airdrop tokens to all registered participants
function transferAidrop() public onlyOwner {
uint256 max;
uint256 length = airdropParticipants.length;
if ((airdropIndex + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = airdropIndex + TRANSFERS_PER_TRANSACTION;
}
uint256 share;
for (uint i = airdropIndex; i < max; i++) {
share = (airdrop.mul(token.balanceOf(airdropParticipants[i]))).div(token.totalSupply());
if (share == 0) {
continue;
}
token.transfer(airdropParticipants[i], share);
}
if (max >= length) {
airdropIndex = 0;
} else {
airdropIndex += TRANSFERS_PER_TRANSACTION;
}
}
} | addAirdropParticipants | function addAirdropParticipants(address[] _airdropParticipants) public onlyOwner {
require(_airdropParticipants.length != 0 && _airdropParticipants.length <= ADDRESS_LIMIT);
airdropParticipants = _airdropParticipants;
}
| // Add all unique participants for receiving airdrop | LineComment | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
1133,
1380
]
} | 5,947 |
|||
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | UniversalManager | contract UniversalManager is Ownable {
using SafeMath for uint256;
uint256 public constant ADDRESS_LIMIT = 300;
uint256 public constant TRANSFERS_PER_TRANSACTION = 150;
uint256 public airdrop;
UniversalCoin public token;
uint256 private currentPool = 0;
uint256 private index = 0;
uint256 private airdropIndex = 0;
address[] private participants;
address[] private airdropParticipants;
function UniversalManager(address uniFoundation) public {
token = new UniversalCoin(uniFoundation);
airdrop = token.airdropReserve().div(3);
}
// Set size of current week tokens pool
function setCurrentWeekPool(uint256 _currentPool) public onlyOwner {
require(_currentPool > 0);
currentPool = _currentPool;
}
// Adds participant for the current week
function addParticipants(address[] _participants) external onlyOwner {
require(_participants.length != 0 && _participants.length <= ADDRESS_LIMIT);
participants = _participants;
}
// Add all unique participants for receiving airdrop
function addAirdropParticipants(address[] _airdropParticipants) public onlyOwner {
require(_airdropParticipants.length != 0 && _airdropParticipants.length <= ADDRESS_LIMIT);
airdropParticipants = _airdropParticipants;
}
// Transfer tokens to current week participants
function transfer(uint256 _amount) public onlyOwner {
uint256 max;
uint256 length = participants.length;
if ((index + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = index + TRANSFERS_PER_TRANSACTION;
}
for (uint i = index; i < max; i++) {
token.transfer(participants[i], _amount);
}
if (max >= length) {
index = 0;
} else {
index += TRANSFERS_PER_TRANSACTION;
}
}
// Transfer airdrop tokens to all registered participants
function transferAidrop() public onlyOwner {
uint256 max;
uint256 length = airdropParticipants.length;
if ((airdropIndex + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = airdropIndex + TRANSFERS_PER_TRANSACTION;
}
uint256 share;
for (uint i = airdropIndex; i < max; i++) {
share = (airdrop.mul(token.balanceOf(airdropParticipants[i]))).div(token.totalSupply());
if (share == 0) {
continue;
}
token.transfer(airdropParticipants[i], share);
}
if (max >= length) {
airdropIndex = 0;
} else {
airdropIndex += TRANSFERS_PER_TRANSACTION;
}
}
} | transfer | function transfer(uint256 _amount) public onlyOwner {
uint256 max;
uint256 length = participants.length;
if ((index + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = index + TRANSFERS_PER_TRANSACTION;
}
for (uint i = index; i < max; i++) {
token.transfer(participants[i], _amount);
}
if (max >= length) {
index = 0;
} else {
index += TRANSFERS_PER_TRANSACTION;
}
}
| // Transfer tokens to current week participants | LineComment | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
1436,
1986
]
} | 5,948 |
|||
UniversalManager | UniversalManager.sol | 0xde871faadf05a39aa3a871525696ff4c87ecd550 | Solidity | UniversalManager | contract UniversalManager is Ownable {
using SafeMath for uint256;
uint256 public constant ADDRESS_LIMIT = 300;
uint256 public constant TRANSFERS_PER_TRANSACTION = 150;
uint256 public airdrop;
UniversalCoin public token;
uint256 private currentPool = 0;
uint256 private index = 0;
uint256 private airdropIndex = 0;
address[] private participants;
address[] private airdropParticipants;
function UniversalManager(address uniFoundation) public {
token = new UniversalCoin(uniFoundation);
airdrop = token.airdropReserve().div(3);
}
// Set size of current week tokens pool
function setCurrentWeekPool(uint256 _currentPool) public onlyOwner {
require(_currentPool > 0);
currentPool = _currentPool;
}
// Adds participant for the current week
function addParticipants(address[] _participants) external onlyOwner {
require(_participants.length != 0 && _participants.length <= ADDRESS_LIMIT);
participants = _participants;
}
// Add all unique participants for receiving airdrop
function addAirdropParticipants(address[] _airdropParticipants) public onlyOwner {
require(_airdropParticipants.length != 0 && _airdropParticipants.length <= ADDRESS_LIMIT);
airdropParticipants = _airdropParticipants;
}
// Transfer tokens to current week participants
function transfer(uint256 _amount) public onlyOwner {
uint256 max;
uint256 length = participants.length;
if ((index + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = index + TRANSFERS_PER_TRANSACTION;
}
for (uint i = index; i < max; i++) {
token.transfer(participants[i], _amount);
}
if (max >= length) {
index = 0;
} else {
index += TRANSFERS_PER_TRANSACTION;
}
}
// Transfer airdrop tokens to all registered participants
function transferAidrop() public onlyOwner {
uint256 max;
uint256 length = airdropParticipants.length;
if ((airdropIndex + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = airdropIndex + TRANSFERS_PER_TRANSACTION;
}
uint256 share;
for (uint i = airdropIndex; i < max; i++) {
share = (airdrop.mul(token.balanceOf(airdropParticipants[i]))).div(token.totalSupply());
if (share == 0) {
continue;
}
token.transfer(airdropParticipants[i], share);
}
if (max >= length) {
airdropIndex = 0;
} else {
airdropIndex += TRANSFERS_PER_TRANSACTION;
}
}
} | transferAidrop | function transferAidrop() public onlyOwner {
uint256 max;
uint256 length = airdropParticipants.length;
if ((airdropIndex + TRANSFERS_PER_TRANSACTION) >= length) {
max = length;
} else {
max = airdropIndex + TRANSFERS_PER_TRANSACTION;
}
uint256 share;
for (uint i = airdropIndex; i < max; i++) {
share = (airdrop.mul(token.balanceOf(airdropParticipants[i]))).div(token.totalSupply());
if (share == 0) {
continue;
}
token.transfer(airdropParticipants[i], share);
}
if (max >= length) {
airdropIndex = 0;
} else {
airdropIndex += TRANSFERS_PER_TRANSACTION;
}
}
| // Transfer airdrop tokens to all registered participants | LineComment | v0.4.18+commit.9cf6e910 | bzzr://5ad898504699f47b2ac00309768645e031a3d2b97205469e9bc41cd670085d9e | {
"func_code_index": [
2052,
2839
]
} | 5,949 |
|||
DanmarksNationalbank | DanmarksNationalbank.sol | 0x44dac0d5235a0b4b84d0bd1d5f25ef027a0d33b4 | Solidity | DanmarksNationalbank | contract DanmarksNationalbank is ERC20
{using SafeMath for uint256;
string public constant symbol = ",000.DKK.DanishKrone";
string public constant name = "Danmarks Nationalbank";
uint public constant decimals = 18;
uint256 _totalSupply = 999000000000000000000 * 10 ** 18; // 999 Trillion Total Supply including 18 decimal
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
// Constructor
constructor () public {
owner = msg.sender;
balances[owner] = _totalSupply;
emit Transfer(0, owner, _totalSupply);
}
function burntokens(uint256 tokens) public onlyOwner {
_totalSupply = (_totalSupply).sub(tokens);
}
// what is the total supply of the ech tokens
function totalSupply() public view returns (uint256 total_Supply) {
total_Supply = _totalSupply;
}
// What is the balance of a particular account?
function balanceOf(address _owner)public view returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount)public returns (bool ok) {
require( _to != 0x0);
require(balances[msg.sender] >= _amount && _amount >= 0);
balances[msg.sender] = (balances[msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom( address _from, address _to, uint256 _amount )public returns (bool ok) {
require( _to != 0x0);
require(balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount >= 0);
balances[_from] = (balances[_from]).sub(_amount);
allowed[_from][msg.sender] = (allowed[_from][msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount)public returns (bool ok) {
require( _spender != 0x0);
allowed[msg.sender][_spender] = _amount;
emit Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender)public view returns (uint256 remaining) {
require( _owner != 0x0 && _spender !=0x0);
return allowed[_owner][_spender];
}
//In case the ownership needs to be transferred
function transferOwnership(address newOwner) external onlyOwner
{
uint256 x = balances[owner];
require( newOwner != 0x0);
balances[newOwner] = (balances[newOwner]).add(balances[owner]);
balances[owner] = 0;
owner = newOwner;
emit Transfer(msg.sender, newOwner, x);
}
} | totalSupply | function totalSupply() public view returns (uint256 total_Supply) {
total_Supply = _totalSupply;
}
| // what is the total supply of the ech tokens | LineComment | v0.4.24+commit.e67f0147 | bzzr://71ba33fc4decfb4d672bd7d5c8e9a1c8145312fc1fa62b8142afbf0fb02cd2e9 | {
"func_code_index": [
1210,
1330
]
} | 5,950 |
|||
DanmarksNationalbank | DanmarksNationalbank.sol | 0x44dac0d5235a0b4b84d0bd1d5f25ef027a0d33b4 | Solidity | DanmarksNationalbank | contract DanmarksNationalbank is ERC20
{using SafeMath for uint256;
string public constant symbol = ",000.DKK.DanishKrone";
string public constant name = "Danmarks Nationalbank";
uint public constant decimals = 18;
uint256 _totalSupply = 999000000000000000000 * 10 ** 18; // 999 Trillion Total Supply including 18 decimal
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
// Constructor
constructor () public {
owner = msg.sender;
balances[owner] = _totalSupply;
emit Transfer(0, owner, _totalSupply);
}
function burntokens(uint256 tokens) public onlyOwner {
_totalSupply = (_totalSupply).sub(tokens);
}
// what is the total supply of the ech tokens
function totalSupply() public view returns (uint256 total_Supply) {
total_Supply = _totalSupply;
}
// What is the balance of a particular account?
function balanceOf(address _owner)public view returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount)public returns (bool ok) {
require( _to != 0x0);
require(balances[msg.sender] >= _amount && _amount >= 0);
balances[msg.sender] = (balances[msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom( address _from, address _to, uint256 _amount )public returns (bool ok) {
require( _to != 0x0);
require(balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount >= 0);
balances[_from] = (balances[_from]).sub(_amount);
allowed[_from][msg.sender] = (allowed[_from][msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount)public returns (bool ok) {
require( _spender != 0x0);
allowed[msg.sender][_spender] = _amount;
emit Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender)public view returns (uint256 remaining) {
require( _owner != 0x0 && _spender !=0x0);
return allowed[_owner][_spender];
}
//In case the ownership needs to be transferred
function transferOwnership(address newOwner) external onlyOwner
{
uint256 x = balances[owner];
require( newOwner != 0x0);
balances[newOwner] = (balances[newOwner]).add(balances[owner]);
balances[owner] = 0;
owner = newOwner;
emit Transfer(msg.sender, newOwner, x);
}
} | balanceOf | function balanceOf(address _owner)public view returns (uint256 balance) {
return balances[_owner];
}
| // What is the balance of a particular account? | LineComment | v0.4.24+commit.e67f0147 | bzzr://71ba33fc4decfb4d672bd7d5c8e9a1c8145312fc1fa62b8142afbf0fb02cd2e9 | {
"func_code_index": [
1387,
1509
]
} | 5,951 |
|||
DanmarksNationalbank | DanmarksNationalbank.sol | 0x44dac0d5235a0b4b84d0bd1d5f25ef027a0d33b4 | Solidity | DanmarksNationalbank | contract DanmarksNationalbank is ERC20
{using SafeMath for uint256;
string public constant symbol = ",000.DKK.DanishKrone";
string public constant name = "Danmarks Nationalbank";
uint public constant decimals = 18;
uint256 _totalSupply = 999000000000000000000 * 10 ** 18; // 999 Trillion Total Supply including 18 decimal
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
// Constructor
constructor () public {
owner = msg.sender;
balances[owner] = _totalSupply;
emit Transfer(0, owner, _totalSupply);
}
function burntokens(uint256 tokens) public onlyOwner {
_totalSupply = (_totalSupply).sub(tokens);
}
// what is the total supply of the ech tokens
function totalSupply() public view returns (uint256 total_Supply) {
total_Supply = _totalSupply;
}
// What is the balance of a particular account?
function balanceOf(address _owner)public view returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount)public returns (bool ok) {
require( _to != 0x0);
require(balances[msg.sender] >= _amount && _amount >= 0);
balances[msg.sender] = (balances[msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom( address _from, address _to, uint256 _amount )public returns (bool ok) {
require( _to != 0x0);
require(balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount >= 0);
balances[_from] = (balances[_from]).sub(_amount);
allowed[_from][msg.sender] = (allowed[_from][msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount)public returns (bool ok) {
require( _spender != 0x0);
allowed[msg.sender][_spender] = _amount;
emit Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender)public view returns (uint256 remaining) {
require( _owner != 0x0 && _spender !=0x0);
return allowed[_owner][_spender];
}
//In case the ownership needs to be transferred
function transferOwnership(address newOwner) external onlyOwner
{
uint256 x = balances[owner];
require( newOwner != 0x0);
balances[newOwner] = (balances[newOwner]).add(balances[owner]);
balances[owner] = 0;
owner = newOwner;
emit Transfer(msg.sender, newOwner, x);
}
} | transfer | function transfer(address _to, uint256 _amount)public returns (bool ok) {
require( _to != 0x0);
require(balances[msg.sender] >= _amount && _amount >= 0);
balances[msg.sender] = (balances[msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
| // Transfer the balance from owner's account to another account | LineComment | v0.4.24+commit.e67f0147 | bzzr://71ba33fc4decfb4d672bd7d5c8e9a1c8145312fc1fa62b8142afbf0fb02cd2e9 | {
"func_code_index": [
1584,
1974
]
} | 5,952 |
|||
DanmarksNationalbank | DanmarksNationalbank.sol | 0x44dac0d5235a0b4b84d0bd1d5f25ef027a0d33b4 | Solidity | DanmarksNationalbank | contract DanmarksNationalbank is ERC20
{using SafeMath for uint256;
string public constant symbol = ",000.DKK.DanishKrone";
string public constant name = "Danmarks Nationalbank";
uint public constant decimals = 18;
uint256 _totalSupply = 999000000000000000000 * 10 ** 18; // 999 Trillion Total Supply including 18 decimal
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
// Constructor
constructor () public {
owner = msg.sender;
balances[owner] = _totalSupply;
emit Transfer(0, owner, _totalSupply);
}
function burntokens(uint256 tokens) public onlyOwner {
_totalSupply = (_totalSupply).sub(tokens);
}
// what is the total supply of the ech tokens
function totalSupply() public view returns (uint256 total_Supply) {
total_Supply = _totalSupply;
}
// What is the balance of a particular account?
function balanceOf(address _owner)public view returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount)public returns (bool ok) {
require( _to != 0x0);
require(balances[msg.sender] >= _amount && _amount >= 0);
balances[msg.sender] = (balances[msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom( address _from, address _to, uint256 _amount )public returns (bool ok) {
require( _to != 0x0);
require(balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount >= 0);
balances[_from] = (balances[_from]).sub(_amount);
allowed[_from][msg.sender] = (allowed[_from][msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount)public returns (bool ok) {
require( _spender != 0x0);
allowed[msg.sender][_spender] = _amount;
emit Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender)public view returns (uint256 remaining) {
require( _owner != 0x0 && _spender !=0x0);
return allowed[_owner][_spender];
}
//In case the ownership needs to be transferred
function transferOwnership(address newOwner) external onlyOwner
{
uint256 x = balances[owner];
require( newOwner != 0x0);
balances[newOwner] = (balances[newOwner]).add(balances[owner]);
balances[owner] = 0;
owner = newOwner;
emit Transfer(msg.sender, newOwner, x);
}
} | transferFrom | function transferFrom( address _from, address _to, uint256 _amount )public returns (bool ok) {
require( _to != 0x0);
require(balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount >= 0);
balances[_from] = (balances[_from]).sub(_amount);
allowed[_from][msg.sender] = (allowed[_from][msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
| // Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval: | LineComment | v0.4.24+commit.e67f0147 | bzzr://71ba33fc4decfb4d672bd7d5c8e9a1c8145312fc1fa62b8142afbf0fb02cd2e9 | {
"func_code_index": [
2469,
2956
]
} | 5,953 |
|||
DanmarksNationalbank | DanmarksNationalbank.sol | 0x44dac0d5235a0b4b84d0bd1d5f25ef027a0d33b4 | Solidity | DanmarksNationalbank | contract DanmarksNationalbank is ERC20
{using SafeMath for uint256;
string public constant symbol = ",000.DKK.DanishKrone";
string public constant name = "Danmarks Nationalbank";
uint public constant decimals = 18;
uint256 _totalSupply = 999000000000000000000 * 10 ** 18; // 999 Trillion Total Supply including 18 decimal
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
// Constructor
constructor () public {
owner = msg.sender;
balances[owner] = _totalSupply;
emit Transfer(0, owner, _totalSupply);
}
function burntokens(uint256 tokens) public onlyOwner {
_totalSupply = (_totalSupply).sub(tokens);
}
// what is the total supply of the ech tokens
function totalSupply() public view returns (uint256 total_Supply) {
total_Supply = _totalSupply;
}
// What is the balance of a particular account?
function balanceOf(address _owner)public view returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount)public returns (bool ok) {
require( _to != 0x0);
require(balances[msg.sender] >= _amount && _amount >= 0);
balances[msg.sender] = (balances[msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom( address _from, address _to, uint256 _amount )public returns (bool ok) {
require( _to != 0x0);
require(balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount >= 0);
balances[_from] = (balances[_from]).sub(_amount);
allowed[_from][msg.sender] = (allowed[_from][msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount)public returns (bool ok) {
require( _spender != 0x0);
allowed[msg.sender][_spender] = _amount;
emit Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender)public view returns (uint256 remaining) {
require( _owner != 0x0 && _spender !=0x0);
return allowed[_owner][_spender];
}
//In case the ownership needs to be transferred
function transferOwnership(address newOwner) external onlyOwner
{
uint256 x = balances[owner];
require( newOwner != 0x0);
balances[newOwner] = (balances[newOwner]).add(balances[owner]);
balances[owner] = 0;
owner = newOwner;
emit Transfer(msg.sender, newOwner, x);
}
} | approve | function approve(address _spender, uint256 _amount)public returns (bool ok) {
require( _spender != 0x0);
allowed[msg.sender][_spender] = _amount;
emit Approval(msg.sender, _spender, _amount);
return true;
}
| // Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value. | LineComment | v0.4.24+commit.e67f0147 | bzzr://71ba33fc4decfb4d672bd7d5c8e9a1c8145312fc1fa62b8142afbf0fb02cd2e9 | {
"func_code_index": [
3147,
3405
]
} | 5,954 |
|||
DanmarksNationalbank | DanmarksNationalbank.sol | 0x44dac0d5235a0b4b84d0bd1d5f25ef027a0d33b4 | Solidity | DanmarksNationalbank | contract DanmarksNationalbank is ERC20
{using SafeMath for uint256;
string public constant symbol = ",000.DKK.DanishKrone";
string public constant name = "Danmarks Nationalbank";
uint public constant decimals = 18;
uint256 _totalSupply = 999000000000000000000 * 10 ** 18; // 999 Trillion Total Supply including 18 decimal
// Owner of this contract
address public owner;
// Balances for each account
mapping(address => uint256) balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) allowed;
// Functions with this modifier can only be executed by the owner
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
// Constructor
constructor () public {
owner = msg.sender;
balances[owner] = _totalSupply;
emit Transfer(0, owner, _totalSupply);
}
function burntokens(uint256 tokens) public onlyOwner {
_totalSupply = (_totalSupply).sub(tokens);
}
// what is the total supply of the ech tokens
function totalSupply() public view returns (uint256 total_Supply) {
total_Supply = _totalSupply;
}
// What is the balance of a particular account?
function balanceOf(address _owner)public view returns (uint256 balance) {
return balances[_owner];
}
// Transfer the balance from owner's account to another account
function transfer(address _to, uint256 _amount)public returns (bool ok) {
require( _to != 0x0);
require(balances[msg.sender] >= _amount && _amount >= 0);
balances[msg.sender] = (balances[msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(msg.sender, _to, _amount);
return true;
}
// Send _value amount of tokens from address _from to address _to
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf, for example to "deposit" to a contract address and/or to charge
// fees in sub-currencies; the command should fail unless the _from account has
// deliberately authorized the sender of the message via some mechanism; we propose
// these standardized APIs for approval:
function transferFrom( address _from, address _to, uint256 _amount )public returns (bool ok) {
require( _to != 0x0);
require(balances[_from] >= _amount && allowed[_from][msg.sender] >= _amount && _amount >= 0);
balances[_from] = (balances[_from]).sub(_amount);
allowed[_from][msg.sender] = (allowed[_from][msg.sender]).sub(_amount);
balances[_to] = (balances[_to]).add(_amount);
emit Transfer(_from, _to, _amount);
return true;
}
// Allow _spender to withdraw from your account, multiple times, up to the _value amount.
// If this function is called again it overwrites the current allowance with _value.
function approve(address _spender, uint256 _amount)public returns (bool ok) {
require( _spender != 0x0);
allowed[msg.sender][_spender] = _amount;
emit Approval(msg.sender, _spender, _amount);
return true;
}
function allowance(address _owner, address _spender)public view returns (uint256 remaining) {
require( _owner != 0x0 && _spender !=0x0);
return allowed[_owner][_spender];
}
//In case the ownership needs to be transferred
function transferOwnership(address newOwner) external onlyOwner
{
uint256 x = balances[owner];
require( newOwner != 0x0);
balances[newOwner] = (balances[newOwner]).add(balances[owner]);
balances[owner] = 0;
owner = newOwner;
emit Transfer(msg.sender, newOwner, x);
}
} | transferOwnership | function transferOwnership(address newOwner) external onlyOwner
{
uint256 x = balances[owner];
require( newOwner != 0x0);
balances[newOwner] = (balances[newOwner]).add(balances[owner]);
balances[owner] = 0;
owner = newOwner;
emit Transfer(msg.sender, newOwner, x);
}
| //In case the ownership needs to be transferred | LineComment | v0.4.24+commit.e67f0147 | bzzr://71ba33fc4decfb4d672bd7d5c8e9a1c8145312fc1fa62b8142afbf0fb02cd2e9 | {
"func_code_index": [
3677,
3985
]
} | 5,955 |
|||
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | Roles | library Roles {
struct Role {
mapping (address => bool) bearer;
}
/**
* @dev give an account access to this role
*/
function add(Role storage role, address account) internal {
require(account != address(0));
require(!has(role, account));
role.bearer[account] = true;
}
/**
* @dev remove an account's access to this role
*/
function remove(Role storage role, address account) internal {
require(account != address(0));
require(has(role, account));
role.bearer[account] = false;
}
/**
* @dev check if an account has this role
* @return bool
*/
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0));
return role.bearer[account];
}
} | /**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/ | NatSpecMultiLine | add | function add(Role storage role, address account) internal {
require(account != address(0));
require(!has(role, account));
role.bearer[account] = true;
}
| /**
* @dev give an account access to this role
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
155,
346
]
} | 5,956 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | Roles | library Roles {
struct Role {
mapping (address => bool) bearer;
}
/**
* @dev give an account access to this role
*/
function add(Role storage role, address account) internal {
require(account != address(0));
require(!has(role, account));
role.bearer[account] = true;
}
/**
* @dev remove an account's access to this role
*/
function remove(Role storage role, address account) internal {
require(account != address(0));
require(has(role, account));
role.bearer[account] = false;
}
/**
* @dev check if an account has this role
* @return bool
*/
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0));
return role.bearer[account];
}
} | /**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/ | NatSpecMultiLine | remove | function remove(Role storage role, address account) internal {
require(account != address(0));
require(has(role, account));
role.bearer[account] = false;
}
| /**
* @dev remove an account's access to this role
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
420,
614
]
} | 5,957 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | Roles | library Roles {
struct Role {
mapping (address => bool) bearer;
}
/**
* @dev give an account access to this role
*/
function add(Role storage role, address account) internal {
require(account != address(0));
require(!has(role, account));
role.bearer[account] = true;
}
/**
* @dev remove an account's access to this role
*/
function remove(Role storage role, address account) internal {
require(account != address(0));
require(has(role, account));
role.bearer[account] = false;
}
/**
* @dev check if an account has this role
* @return bool
*/
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0));
return role.bearer[account];
}
} | /**
* @title Roles
* @dev Library for managing addresses assigned to a Role.
*/ | NatSpecMultiLine | has | function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0));
return role.bearer[account];
}
| /**
* @dev check if an account has this role
* @return bool
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
703,
873
]
} | 5,958 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
| /**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
106,
544
]
} | 5,959 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
674,
982
]
} | 5,960 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
| /**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
1115,
1270
]
} | 5,961 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
| /**
* @dev Adds two unsigned integers, reverts on overflow.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
1353,
1508
]
} | 5,962 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
| /**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
1664,
1793
]
} | 5,963 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return _totalSupply;
}
| /**
* @dev Total number of tokens in existence
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
297,
393
]
} | 5,964 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
608,
719
]
} | 5,965 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
1053,
1189
]
} | 5,966 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | transfer | function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
| /**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
1358,
1503
]
} | 5,967 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
2145,
2298
]
} | 5,968 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
| /**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
2766,
2999
]
} | 5,969 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | increaseAllowance | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
| /**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
3520,
3728
]
} | 5,970 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | decreaseAllowance | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
| /**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
4254,
4472
]
} | 5,971 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _transfer | function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
| /**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
4694,
4961
]
} | 5,972 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _mint | function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
| /**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
5308,
5582
]
} | 5,973 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _burn | function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
| /**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
5811,
6085
]
} | 5,974 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _approve | function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
| /**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
6353,
6612
]
} | 5,975 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20 | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowed;
uint256 private _totalSupply;
/**
* @dev Total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) public view returns (uint256) {
return _balances[owner];
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowed[owner][spender];
}
/**
* @dev Transfer token to a specified address
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function transfer(address to, uint256 value) public returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev Transfer tokens from one address to another.
* Note that while this function emits an Approval event, this is not required as per the specification,
* and other compliant implementations may not emit the event.
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param value uint256 the amount of tokens to be transferred
*/
function transferFrom(address from, address to, uint256 value) public returns (bool) {
_transfer(from, to, value);
_approve(from, msg.sender, _allowed[from][msg.sender].sub(value));
return true;
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param addedValue The amount of tokens to increase the allowance by.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when _allowed[msg.sender][spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* Emits an Approval event.
* @param spender The address which will spend the funds.
* @param subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowed[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Transfer token for a specified addresses
* @param from The address to transfer from.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(from, to, value);
}
/**
* @dev Internal function that mints an amount of the token and assigns it to
* an account. This encapsulates the modification of balances such that the
* proper events are emitted.
* @param account The account that will receive the created tokens.
* @param value The amount that will be created.
*/
function _mint(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.add(value);
_balances[account] = _balances[account].add(value);
emit Transfer(address(0), account, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account.
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0));
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Approve an address to spend another addresses' tokens.
* @param owner The address that owns the tokens.
* @param spender The address that will spend the tokens.
* @param value The number of tokens that can be spent.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(spender != address(0));
require(owner != address(0));
_allowed[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/
function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* https://eips.ethereum.org/EIPS/eip-20
* Originally based on code by FirstBlood:
* https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*
* This implementation emits additional Approval events, allowing applications to reconstruct the allowance status for
* all accounts just by listening to said events. Note that this isn't required by the specification, and other
* compliant implementations may not do it.
*/ | NatSpecMultiLine | _burnFrom | function _burnFrom(address account, uint256 value) internal {
_burn(account, value);
_approve(account, msg.sender, _allowed[account][msg.sender].sub(value));
}
| /**
* @dev Internal function that burns an amount of the token of a given
* account, deducting from the sender's allowance for said account. Uses the
* internal burn function.
* Emits an Approval event (reflecting the reduced allowance).
* @param account The account whose tokens will be burnt.
* @param value The amount that will be burnt.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
7006,
7193
]
} | 5,976 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20Mintable | contract ERC20Mintable is ERC20, MinterRole {
/**
* @dev Function to mint tokens
* @param to The address that will receive the minted tokens.
* @param value The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address to, uint256 value) public onlyMinter returns (bool) {
_mint(to, value);
return true;
}
} | /**
* @title ERC20Mintable
* @dev ERC20 minting logic
*/ | NatSpecMultiLine | mint | function mint(address to, uint256 value) public onlyMinter returns (bool) {
_mint(to, value);
return true;
}
| /**
* @dev Function to mint tokens
* @param to The address that will receive the minted tokens.
* @param value The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
294,
430
]
} | 5,977 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | /**
* @title ERC20Detailed token
* @dev The decimals are only for visualization purposes.
* All the operations are done using the smallest and indivisible token unit,
* just as on Ethereum all the operations are done in wei.
*/ | NatSpecMultiLine | name | function name() public view returns (string memory) {
return _name;
}
| /**
* @return the name of the token.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
356,
444
]
} | 5,978 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | /**
* @title ERC20Detailed token
* @dev The decimals are only for visualization purposes.
* All the operations are done using the smallest and indivisible token unit,
* just as on Ethereum all the operations are done in wei.
*/ | NatSpecMultiLine | symbol | function symbol() public view returns (string memory) {
return _symbol;
}
| /**
* @return the symbol of the token.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
506,
598
]
} | 5,979 |
YearnYinanceBeta2 | YearnYinanceBeta2.sol | 0x8ed045c13375477bff384ddd30575aacb6c4110b | Solidity | ERC20Detailed | contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @return the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @return the symbol of the token.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @return the number of decimals of the token.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
} | /**
* @title ERC20Detailed token
* @dev The decimals are only for visualization purposes.
* All the operations are done using the smallest and indivisible token unit,
* just as on Ethereum all the operations are done in wei.
*/ | NatSpecMultiLine | decimals | function decimals() public view returns (uint8) {
return _decimals;
}
| /**
* @return the number of decimals of the token.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | MIT | bzzr://39a8ec03a9b910b022c7d915768abcfd8745ad759c5dbd5b3c95e75a3ce2a19c | {
"func_code_index": [
672,
760
]
} | 5,980 |
SolidStampRegister | SolidStampRegister.sol | 0xffe73766ed803769cdaea47470e66fdfa5308c22 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | renounceOwnership | function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
| /**
* @dev Allows the current owner to relinquish control of the contract.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4eb466182666e995dfc10998ef4f664acd65ec46fb96148f4e720774e86d1df0 | {
"func_code_index": [
638,
755
]
} | 5,981 |
|
SolidStampRegister | SolidStampRegister.sol | 0xffe73766ed803769cdaea47470e66fdfa5308c22 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
| /**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4eb466182666e995dfc10998ef4f664acd65ec46fb96148f4e720774e86d1df0 | {
"func_code_index": [
920,
1028
]
} | 5,982 |
|
SolidStampRegister | SolidStampRegister.sol | 0xffe73766ed803769cdaea47470e66fdfa5308c22 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | _transferOwnership | function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
| /**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4eb466182666e995dfc10998ef4f664acd65ec46fb96148f4e720774e86d1df0 | {
"func_code_index": [
1166,
1344
]
} | 5,983 |
|
SolidStampRegister | SolidStampRegister.sol | 0xffe73766ed803769cdaea47470e66fdfa5308c22 | Solidity | SolidStampRegister | contract SolidStampRegister is Ownable
{
/// @dev address of the current SolidStamp contract which can add audits
address public contractSolidStamp;
/// @dev const value to indicate the contract is audited and approved
uint8 public constant NOT_AUDITED = 0x00;
/// @dev const value to indicate the contract is audited and approved
uint8 public constant AUDITED_AND_APPROVED = 0x01;
/// @dev const value to indicate the contract is audited and rejected
uint8 public constant AUDITED_AND_REJECTED = 0x02;
/// @dev Maps auditor and code hash to the outcome of the audit of
/// the particular contract by the particular auditor.
/// Map key is: keccack256(auditor address, contract codeHash)
/// @dev codeHash is a sha3 from the contract byte code
mapping (bytes32 => uint8) public AuditOutcomes;
/// @dev event fired when a contract is sucessfully audited
event AuditRegistered(address auditor, bytes32 codeHash, bool isApproved);
/// @notice SolidStampRegister constructor
/// @dev import audits from the SolidStamp v1 contract deployed to: 0x0aA7A4482780F67c6B2862Bd68CD67A83faCe355
/// @param _existingAuditors list of existing auditors
/// @param _existingCodeHashes list of existing code hashes
/// @param _outcomes list of existing audit outcomes
/// @dev each n-th element represents an existing audit conducted by _existingAuditors[n]
/// on code hash _existingCodeHashes[n] with an outcome _outcomes[n]
constructor(address[] _existingAuditors, bytes32[] _existingCodeHashes, bool[] _outcomes) public {
uint noOfExistingAudits = _existingAuditors.length;
require(noOfExistingAudits == _existingCodeHashes.length, "paramters mismatch");
require(noOfExistingAudits == _outcomes.length, "paramters mismatch");
// set contract address temporarily to owner so that registerAuditOutcome does not revert
contractSolidStamp = msg.sender;
for (uint i=0; i<noOfExistingAudits; i++){
registerAuditOutcome(_existingAuditors[i], _existingCodeHashes[i], _outcomes[i]);
}
contractSolidStamp = 0x0;
}
function getAuditOutcome(address _auditor, bytes32 _codeHash) public view returns (uint8)
{
bytes32 hashAuditorCode = keccak256(abi.encodePacked(_auditor, _codeHash));
return AuditOutcomes[hashAuditorCode];
}
function registerAuditOutcome(address _auditor, bytes32 _codeHash, bool _isApproved) public onlySolidStampContract
{
require(_auditor != 0x0, "auditor cannot be 0x0");
bytes32 hashAuditorCode = keccak256(abi.encodePacked(_auditor, _codeHash));
if ( _isApproved )
AuditOutcomes[hashAuditorCode] = AUDITED_AND_APPROVED;
else
AuditOutcomes[hashAuditorCode] = AUDITED_AND_REJECTED;
emit AuditRegistered(_auditor, _codeHash, _isApproved);
}
event SolidStampContractChanged(address newSolidStamp);
/**
* @dev Throws if called by any account other than the contractSolidStamp
*/
modifier onlySolidStampContract() {
require(msg.sender == contractSolidStamp, "cannot be run by not SolidStamp contract");
_;
}
/**
* @dev Transfers control of the registry to a _newSolidStamp.
* @param _newSolidStamp The address to transfer control registry to.
*/
function changeSolidStampContract(address _newSolidStamp) public onlyOwner {
require(_newSolidStamp != address(0), "SolidStamp contract cannot be 0x0");
emit SolidStampContractChanged(_newSolidStamp);
contractSolidStamp = _newSolidStamp;
}
} | changeSolidStampContract | function changeSolidStampContract(address _newSolidStamp) public onlyOwner {
require(_newSolidStamp != address(0), "SolidStamp contract cannot be 0x0");
emit SolidStampContractChanged(_newSolidStamp);
contractSolidStamp = _newSolidStamp;
}
| /**
* @dev Transfers control of the registry to a _newSolidStamp.
* @param _newSolidStamp The address to transfer control registry to.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://4eb466182666e995dfc10998ef4f664acd65ec46fb96148f4e720774e86d1df0 | {
"func_code_index": [
3452,
3722
]
} | 5,984 |
|||
Mingoes | contracts/src/ERC721/extensions/ERC721Tradable.sol | 0xe6f475c11ad693e48455fcaf7bca33fe84ce71b0 | Solidity | ERC721Tradable | abstract contract ERC721Tradable is ERC721 {
/* -------------------------------------------------------------------------- */
/* IMMUTABLE STORAGE */
/* -------------------------------------------------------------------------- */
/// @notice The OpenSea Proxy Registry address.
address public immutable openSeaProxyRegistry;
/// @notice The LooksRare Transfer Manager (ERC721) address.
address public immutable looksRareTransferManager;
/* -------------------------------------------------------------------------- */
/* MUTABLE STORAGE */
/* -------------------------------------------------------------------------- */
/// @notice Returns true if the stored marketplace addresses are whitelisted in {isApprovedForAll}.
/// @dev Enabled by default. Can be turned off with {setMarketplaceApprovalForAll}.
bool public marketPlaceApprovalForAll = true;
/* -------------------------------------------------------------------------- */
/* CONSTRUCTOR */
/* -------------------------------------------------------------------------- */
/// OpenSea proxy registry addresses:
/// - ETHEREUM MAINNET: 0xa5409ec958C83C3f309868babACA7c86DCB077c1
/// - ETHEREUM RINKEBY: 0xF57B2c51dED3A29e6891aba85459d600256Cf317
/// LooksRare Transfer Manager addresses (https://docs.looksrare.org/developers/deployed-contract-addresses):
/// - ETHEREUM MAINNET: 0xf42aa99F011A1fA7CDA90E5E98b277E306BcA83e
/// - ETHEREUM RINKEBY: 0x3f65A762F15D01809cDC6B43d8849fF24949c86a
/// @param _openSeaProxyRegistry The OpenSea proxy registry address.
constructor(address _openSeaProxyRegistry, address _looksRareTransferManager) {
require(_openSeaProxyRegistry != address(0) && _looksRareTransferManager != address(0), "INVALID_ADDRESS");
openSeaProxyRegistry = _openSeaProxyRegistry;
looksRareTransferManager = _looksRareTransferManager;
}
/* -------------------------------------------------------------------------- */
/* ERC721ATradable LOGIC */
/* -------------------------------------------------------------------------- */
/// @notice Enables or disables the marketplace whitelist in {isApprovedForAll}.
/// @dev Must be implemented in inheriting contracts.
/// Recommended to use in combination with an access control contract (e.g. OpenZeppelin's Ownable).
function setMarketplaceApprovalForAll(bool approved) public virtual;
/// @return True if `operator` is a whitelisted marketplace contract or if it was approved by `owner` with {ERC721A.setApprovalForAll}.
/// @inheritdoc ERC721
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
if (marketPlaceApprovalForAll && (operator == IProxyRegistry(openSeaProxyRegistry).proxies(owner) || operator == looksRareTransferManager)) return true;
return super.isApprovedForAll(owner, operator);
}
} | setMarketplaceApprovalForAll | function setMarketplaceApprovalForAll(bool approved) public virtual;
| /// @notice Enables or disables the marketplace whitelist in {isApprovedForAll}.
/// @dev Must be implemented in inheriting contracts.
/// Recommended to use in combination with an access control contract (e.g. OpenZeppelin's Ownable). | NatSpecSingleLine | v0.8.11+commit.d7f03943 | {
"func_code_index": [
2510,
2579
]
} | 5,985 |
||||
Mingoes | contracts/src/ERC721/extensions/ERC721Tradable.sol | 0xe6f475c11ad693e48455fcaf7bca33fe84ce71b0 | Solidity | ERC721Tradable | abstract contract ERC721Tradable is ERC721 {
/* -------------------------------------------------------------------------- */
/* IMMUTABLE STORAGE */
/* -------------------------------------------------------------------------- */
/// @notice The OpenSea Proxy Registry address.
address public immutable openSeaProxyRegistry;
/// @notice The LooksRare Transfer Manager (ERC721) address.
address public immutable looksRareTransferManager;
/* -------------------------------------------------------------------------- */
/* MUTABLE STORAGE */
/* -------------------------------------------------------------------------- */
/// @notice Returns true if the stored marketplace addresses are whitelisted in {isApprovedForAll}.
/// @dev Enabled by default. Can be turned off with {setMarketplaceApprovalForAll}.
bool public marketPlaceApprovalForAll = true;
/* -------------------------------------------------------------------------- */
/* CONSTRUCTOR */
/* -------------------------------------------------------------------------- */
/// OpenSea proxy registry addresses:
/// - ETHEREUM MAINNET: 0xa5409ec958C83C3f309868babACA7c86DCB077c1
/// - ETHEREUM RINKEBY: 0xF57B2c51dED3A29e6891aba85459d600256Cf317
/// LooksRare Transfer Manager addresses (https://docs.looksrare.org/developers/deployed-contract-addresses):
/// - ETHEREUM MAINNET: 0xf42aa99F011A1fA7CDA90E5E98b277E306BcA83e
/// - ETHEREUM RINKEBY: 0x3f65A762F15D01809cDC6B43d8849fF24949c86a
/// @param _openSeaProxyRegistry The OpenSea proxy registry address.
constructor(address _openSeaProxyRegistry, address _looksRareTransferManager) {
require(_openSeaProxyRegistry != address(0) && _looksRareTransferManager != address(0), "INVALID_ADDRESS");
openSeaProxyRegistry = _openSeaProxyRegistry;
looksRareTransferManager = _looksRareTransferManager;
}
/* -------------------------------------------------------------------------- */
/* ERC721ATradable LOGIC */
/* -------------------------------------------------------------------------- */
/// @notice Enables or disables the marketplace whitelist in {isApprovedForAll}.
/// @dev Must be implemented in inheriting contracts.
/// Recommended to use in combination with an access control contract (e.g. OpenZeppelin's Ownable).
function setMarketplaceApprovalForAll(bool approved) public virtual;
/// @return True if `operator` is a whitelisted marketplace contract or if it was approved by `owner` with {ERC721A.setApprovalForAll}.
/// @inheritdoc ERC721
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
if (marketPlaceApprovalForAll && (operator == IProxyRegistry(openSeaProxyRegistry).proxies(owner) || operator == looksRareTransferManager)) return true;
return super.isApprovedForAll(owner, operator);
}
} | isApprovedForAll | function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
if (marketPlaceApprovalForAll && (operator == IProxyRegistry(openSeaProxyRegistry).proxies(owner) || operator == looksRareTransferManager)) return true;
return super.isApprovedForAll(owner, operator);
}
| /// @return True if `operator` is a whitelisted marketplace contract or if it was approved by `owner` with {ERC721A.setApprovalForAll}.
/// @inheritdoc ERC721 | NatSpecSingleLine | v0.8.11+commit.d7f03943 | {
"func_code_index": [
2742,
3055
]
} | 5,986 |
||||
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | ExtendedMath | library ExtendedMath {
//return the smaller of the two inputs (a or b)
function limitLessThan(uint a, uint b) internal pure returns (uint c) {
if(a > b) return b;
return a;
}
} | limitLessThan | function limitLessThan(uint a, uint b) internal pure returns (uint c) {
if(a > b) return b;
return a;
}
| //return the smaller of the two inputs (a or b) | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
81,
218
]
} | 5,987 |
|||
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | SedoPoWToken | function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
| // ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
1546,
2530
]
} | 5,988 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | ParentCoinAddress | function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
| // ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
2819,
2924
]
} | 5,989 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | mint | function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
| // ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
3124,
4779
]
} | 5,990 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | merge | function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
| // ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
4984,
9932
]
} | 5,991 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | _startNewMiningEpoch | function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
| //a new 'block' to be mined | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
9976,
11155
]
} | 5,992 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | _reAdjustDifficulty | function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
| //https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
11385,
13116
]
} | 5,993 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | getChallengeNumber | function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
| //this is a recent ethereum block hash, used to prevent pre-mining future blocks | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
13207,
13317
]
} | 5,994 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | getMiningDifficulty | function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
| //the number of zeroes the digest of the PoW solution requires. Auto adjusts | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
13403,
13530
]
} | 5,995 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | getMiningReward | function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
| //50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined) | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
13755,
14034
]
} | 5,996 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | getMintDigest | function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
| //help debug mining software | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
14071,
14317
]
} | 5,997 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | checkMintSolution | function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
| //help debug mining software | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
14358,
14701
]
} | 5,998 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | totalSupply | function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
| // ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
14895,
15020
]
} | 5,999 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | balanceOf | function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
| // ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
15248,
15381
]
} | 6,000 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | transfer | function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
15737,
16014
]
} | 6,001 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | approve | function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
16541,
16757
]
} | 6,002 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | transferFrom | function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
| // ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
17313,
17668
]
} | 6,003 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | allowance | function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
| // ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
17961,
18121
]
} | 6,004 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | approveAndCall | function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
| // ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
18494,
18821
]
} | 6,005 |
|
SedoPoWToken | SedoPoWToken.sol | 0x0f00f1696218eaefa2d2330df3d6d1f94813b38f | Solidity | SedoPoWToken | contract SedoPoWToken is ERC20Interface, Owned {
using SafeMath for uint;
using ExtendedMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint public _totalSupply;
uint public latestDifficultyPeriodStarted;
uint public epochCount;//number of 'blocks' mined
uint public _BLOCKS_PER_READJUSTMENT = 1024;
//a little number
uint public _MINIMUM_TARGET = 2**16;
uint public _MAXIMUM_TARGET = 2**234;
uint public miningTarget;
bytes32 public challengeNumber; //generate a new one when a new reward is minted
uint public rewardEra;
uint public maxSupplyForEra;
address public lastRewardTo;
uint public lastRewardAmount;
uint public lastRewardEthBlockNumber;
bool locked = false;
mapping(bytes32 => bytes32) solutionForChallenge;
uint public tokensMinted;
address public parentAddress; //address of 0xbtc
uint public miningReward; //initial reward
mapping(address => uint) balances;
mapping(address => uint) merge_mint_ious;
mapping(address => uint) merge_mint_payout_threshold;
mapping(address => mapping(address => uint)) allowed;
event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
function SedoPoWToken() public onlyOwner{
symbol = "SEDO";
name = "SEDO PoW Token";
decimals = 8;
_totalSupply = 50000000 * 10**uint(decimals);
if(locked) revert();
locked = true;
tokensMinted = 1000000 * 10**uint(decimals);
miningReward = 25; //initial Mining reward for 1st half of totalSupply (50 000 000 / 2)
rewardEra = 0;
maxSupplyForEra = _totalSupply.div(2);
miningTarget = 2**220; //initial mining target
latestDifficultyPeriodStarted = block.number;
_startNewMiningEpoch();
parentAddress = 0x9D2Cc383E677292ed87f63586086CfF62a009010; //address of parent coin 0xBTC - need to be changed to actual in the mainnet !
//0xB6eD7644C69416d67B522e20bC294A9a9B405B31 - production
balances[owner] = balances[owner].add(tokensMinted);
Transfer(address(this), owner, tokensMinted);
}
// ------------------------------------------------------------------------
// Parent contract changing (it can be useful if parent will make a swap or in some other cases)
// ------------------------------------------------------------------------
function ParentCoinAddress(address parent) public onlyOwner{
parentAddress = parent;
}
// ------------------------------------------------------------------------
// Main mint function
// ------------------------------------------------------------------------
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
//the PoW must contain work that includes a recent ethereum block hash (challenge number) and the msg.sender's address to prevent MITM attacks
bytes32 digest = keccak256(challengeNumber, msg.sender, nonce );
//the challenge digest must match the expected
if (digest != challenge_digest) revert();
//the digest must be smaller than the target
if(uint256(digest) > miningTarget) revert();
//only allow one reward for each challenge
bytes32 solution = solutionForChallenge[challengeNumber];
solutionForChallenge[challengeNumber] = digest;
if(solution != 0x0) revert(); //prevent the same answer from awarding twice
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, challengeNumber );
emit Transfer(address(this), msg.sender, reward_amount); //we need add it to show token transfers in the etherscan
return true;
}
// ------------------------------------------------------------------------
// merge mint function
// ------------------------------------------------------------------------
function merge() public returns (bool success) {
// Function for the Merge mining (0xbitcoin as a parent coin)
// original idea by 0xbitcoin developers
// the idea is that the miner uses https://github.com/0xbitcoin/mint-helper/blob/master/contracts/MintHelper.sol
// to call mint() and then mergeMint() in the same transaction
// hard code a reference to the "Parent" ERC918 Contract ( in this case 0xBitcoin)
// Verify that the Parent contract was minted in this block, by the same person calling this contract
// then followthrough with the resulting mint logic
// don't call revert, but return true or false based on success
// this method shouldn't revert because it will be calleed in the same transaction as a "Parent" mint attempt
//ensure that mergeMint() can only be called once per Parent::mint()
//do this by ensuring that the "new" challenge number from Parent::challenge post mint can be called once
//and that this block time is the same as this mint, and the caller is msg.sender
//only allow one reward for each challenge
// do this by calculating what the new challenge will be in _startNewMiningEpoch, and verify that it is not that value
// this checks happen in the local contract, not in the parent
bytes32 future_challengeNumber = block.blockhash(block.number - 1);
if(challengeNumber == future_challengeNumber){
return false; // ( this is likely the second time that mergeMint() has been called in a transaction, so return false (don't revert))
}
if(ERC918Interface(parentAddress).lastRewardTo() != msg.sender){
return false; // a different address called mint last so return false ( don't revert)
}
if(ERC918Interface(parentAddress).lastRewardEthBlockNumber() != block.number){
return false; // parent::mint() was called in a different block number so return false ( don't revert)
}
//we have verified that _startNewMiningEpoch has not been run more than once this block by verifying that
// the challenge is not the challenge that will be set by _startNewMiningEpoch
//we have verified that this is the same block as a call to Parent::mint() and that the sender
// is the sender that has called mint
//SEDO will have the same challenge numbers as 0xBitcoin, this means that mining for one is literally the same process as mining for the other
// we want to make sure that one can't use a combination of merge and mint to get two blocks of SEDO for each valid nonce, since the same solution
// applies to each coin
// for this reason, we update the solutionForChallenge hashmap with the value of parent::challengeNumber when a solution is merge minted.
// when a miner finds a valid solution, if they call this::mint(), without the next few lines of code they can then subsequently use the mint helper and in one transaction
// call parent::mint() this::merge(). the following code will ensure that this::merge() does not give a block reward, because the challenge number will already be set in the
// solutionForChallenge map
//only allow one reward for each challenge based on parent::challengeNumber
bytes32 parentChallengeNumber = ERC918Interface(parentAddress).challengeNumber();
bytes32 solution = solutionForChallenge[parentChallengeNumber];
if(solution != 0x0) return false; //prevent the same answer from awarding twice
//now that we've checked that the next challenge wasn't reused, apply the current SEDO challenge
//this will prevent the 'previous' challenge from being reused
bytes32 digest = 'merge';
solutionForChallenge[challengeNumber] = digest;
//so now we may safely run the relevant logic to give an award to the sender, and update the contract
uint reward_amount = getMiningReward();
balances[msg.sender] = balances[msg.sender].add(reward_amount);
tokensMinted = tokensMinted.add(reward_amount);
//Cannot mint more tokens than there are
assert(tokensMinted <= maxSupplyForEra);
//set readonly diagnostics data
lastRewardTo = msg.sender;
lastRewardAmount = reward_amount;
lastRewardEthBlockNumber = block.number;
_startNewMiningEpoch();
Mint(msg.sender, reward_amount, epochCount, 0 ); // use 0 to indicate a merge mine
return true;
}
//a new 'block' to be mined
function _startNewMiningEpoch() internal {
//if max supply for the era will be exceeded next reward round then enter the new era before that happens
//40 is the final reward era, almost all tokens minted
//once the final era is reached, more tokens will not be given out because the assert function
if( tokensMinted.add(getMiningReward()) > maxSupplyForEra && rewardEra < 39)
{
rewardEra = rewardEra + 1;
}
//set the next minted supply at which the era will change
// total supply is 5000000000000000 because of 8 decimal places
maxSupplyForEra = _totalSupply - _totalSupply.div( 2**(rewardEra + 1));
epochCount = epochCount.add(1);
//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % _BLOCKS_PER_READJUSTMENT == 0)
{
_reAdjustDifficulty();
}
//make the latest ethereum block hash a part of the next challenge for PoW to prevent pre-mining future blocks
//do this last since this is a protection mechanism in the mint() function
challengeNumber = block.blockhash(block.number - 1);
}
//https://en.bitcoin.it/wiki/Difficulty#What_is_the_formula_for_difficulty.3F
//as of 2017 the bitcoin difficulty was up to 17 zeroes, it was only 8 in the early days
//readjust the target by 5 percent
function _reAdjustDifficulty() internal {
uint ethBlocksSinceLastDifficultyPeriod = block.number - latestDifficultyPeriodStarted;
uint epochsMined = _BLOCKS_PER_READJUSTMENT; //256
uint targetEthBlocksPerDiffPeriod = epochsMined * 60; //should be 60 times slower than ethereum
//if there were less eth blocks passed in time than expected
if( ethBlocksSinceLastDifficultyPeriod < targetEthBlocksPerDiffPeriod )
{
uint excess_block_pct = (targetEthBlocksPerDiffPeriod.mul(100)).div( ethBlocksSinceLastDifficultyPeriod );
uint excess_block_pct_extra = excess_block_pct.sub(100).limitLessThan(1000);
// If there were 5% more blocks mined than expected then this is 5. If there were 100% more blocks mined than expected then this is 100.
//make it harder
miningTarget = miningTarget.sub(miningTarget.div(2000).mul(excess_block_pct_extra)); //by up to 50 %
}else{
uint shortage_block_pct = (ethBlocksSinceLastDifficultyPeriod.mul(100)).div( targetEthBlocksPerDiffPeriod );
uint shortage_block_pct_extra = shortage_block_pct.sub(100).limitLessThan(1000); //always between 0 and 1000
//make it easier
miningTarget = miningTarget.add(miningTarget.div(2000).mul(shortage_block_pct_extra)); //by up to 50 %
}
latestDifficultyPeriodStarted = block.number;
if(miningTarget < _MINIMUM_TARGET) //very difficult
{
miningTarget = _MINIMUM_TARGET;
}
if(miningTarget > _MAXIMUM_TARGET) //very easy
{
miningTarget = _MAXIMUM_TARGET;
}
}
//this is a recent ethereum block hash, used to prevent pre-mining future blocks
function getChallengeNumber() public constant returns (bytes32) {
return challengeNumber;
}
//the number of zeroes the digest of the PoW solution requires. Auto adjusts
function getMiningDifficulty() public constant returns (uint) {
return _MAXIMUM_TARGET.div(miningTarget);
}
function getMiningTarget() public constant returns (uint) {
return miningTarget;
}
//50m coins total
//reward begins at miningReward and is cut in half every reward era (as tokens are mined)
function getMiningReward() public constant returns (uint) {
//once we get half way thru the coins, only get 25 per block
//every reward era, the reward amount halves.
return (miningReward * 10**uint(decimals) ).div( 2**rewardEra ) ;
}
//help debug mining software
function getMintDigest(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number) public view returns (bytes32 digesttest) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
return digest;
}
//help debug mining software
function checkMintSolution(uint256 nonce, bytes32 challenge_digest, bytes32 challenge_number, uint testTarget) public view returns (bool success) {
bytes32 digest = keccak256(challenge_number,msg.sender,nonce);
if(uint256(digest) > testTarget) revert();
return (digest == challenge_digest);
}
// ------------------------------------------------------------------------
// Total supply
// ------------------------------------------------------------------------
function totalSupply() public constant returns (uint) {
return _totalSupply - balances[address(0)];
}
// ------------------------------------------------------------------------
// Get the token balance for account `tokenOwner`
// ------------------------------------------------------------------------
function balanceOf(address tokenOwner) public constant returns (uint balance) {
return balances[tokenOwner];
}
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to `to` account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transfer(address to, uint tokens) public returns (bool success) {
balances[msg.sender] = balances[msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(msg.sender, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account
//
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
// recommends that there are no checks for the approval double-spend attack
// as this should be implemented in user interfaces
// ------------------------------------------------------------------------
function approve(address spender, uint tokens) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
return true;
}
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
//
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
balances[from] = balances[from].sub(tokens);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
balances[to] = balances[to].add(tokens);
Transfer(from, to, tokens);
return true;
}
// ------------------------------------------------------------------------
// Returns the amount of tokens approved by the owner that can be
// transferred to the spender's account
// ------------------------------------------------------------------------
function allowance(address tokenOwner, address spender) public constant returns (uint remaining) {
return allowed[tokenOwner][spender];
}
// ------------------------------------------------------------------------
// Token owner can approve for `spender` to transferFrom(...) `tokens`
// from the token owner's account. The `spender` contract function
// `receiveApproval(...)` is then executed
// ------------------------------------------------------------------------
function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) {
allowed[msg.sender][spender] = tokens;
Approval(msg.sender, spender, tokens);
ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data);
return true;
}
// ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------
function () public payable {
revert();
}
// ------------------------------------------------------------------------
// Owner can transfer out any accidentally sent ERC20 tokens
// ------------------------------------------------------------------------
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
return ERC20Interface(tokenAddress).transfer(owner, tokens);
}
} | // ----------------------------------------------------------------------------
// ERC20 Token, with the addition of symbol, name and decimals and an
// initial fixed supply
// ---------------------------------------------------------------------------- | LineComment | function () public payable {
revert();
}
| // ------------------------------------------------------------------------
// Don't accept ETH
// ------------------------------------------------------------------------ | LineComment | v0.4.24+commit.e67f0147 | bzzr://c4774b9768b3b751f21d10c61fa3e0c71800beaa69e1672013c69d5ace49c9fb | {
"func_code_index": [
19017,
19080
]
} | 6,006 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.