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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SatoshiAllotment | contracts/dependencies/SafeMath64.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SafeMath64 | library SafeMath64 {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint64 a, uint64 b) internal pure returns (uint64) {
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
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(uint64 a, uint64 b, string memory errorMessage) internal pure returns (uint64) {
require(b <= a, errorMessage);
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
// 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;
}
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
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(uint64 a, uint64 b, string memory errorMessage) internal pure returns (uint64) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
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(uint64 a, uint64 b, string memory errorMessage) internal pure returns (uint64) {
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(uint64 a, uint64 b) internal pure returns (uint64) {
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.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
3922,
4054
]
} | 56,861 |
SatoshiAllotment | contracts/dependencies/SafeMath64.sol | 0x30d72534c2d80736c66a535d657acf7328b965ca | Solidity | SafeMath64 | library SafeMath64 {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint64 a, uint64 b) internal pure returns (uint64) {
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
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(uint64 a, uint64 b, string memory errorMessage) internal pure returns (uint64) {
require(b <= a, errorMessage);
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
// 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;
}
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
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(uint64 a, uint64 b, string memory errorMessage) internal pure returns (uint64) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint64 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(uint64 a, uint64 b) internal pure returns (uint64) {
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(uint64 a, uint64 b, string memory errorMessage) internal pure returns (uint64) {
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(uint64 a, uint64 b, string memory errorMessage) internal pure returns (uint64) {
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.5.16+commit.9c3226ce | Unknown | bzzr://c9c4ee1b8720b1046f03191ba2378241876574b2524c7789219aad9afa6c239a | {
"func_code_index": [
4526,
4694
]
} | 56,862 |
MASTERDILL | MASTERDILL.sol | 0x9175757101d31317b16013570dda50403b00b0e2 | Solidity | MASTERDILL | contract MASTERDILL is Ownable{
using SafeMath for uint256;
mapping (address => uint256) public balanceOf;
mapping (address => bool) public whitelist;
string public name = "Master DILL";
string public symbol = "mDILL";
uint8 public decimals = 18;
uint256 public totalSupply = 1000000 * (uint256(10) ** decimals);
uint256 public totalPooled;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
event Transfer(address indexed from, address indexed to, uint256 value);
constructor() public {
totalPooled = 50 * (uint256(10) ** decimals);
// Initially assign all non-pooled tokens to the contract's creator.
balanceOf[msg.sender] = totalSupply.sub(totalPooled);
emit Transfer(address(0), msg.sender, totalSupply.sub(totalPooled));
}
// Ensure a redemption is profitable before allowing a redeem()
modifier profitable() {
require(is_profitable(), "Redeeming is not yet profitable.");
_;
}
// VIEWS
// Get the number of tokens to be redeemed from the pool
function numberRedeemed(uint256 amount)
public
view
returns (uint256 profit) {
uint256 numerator = amount.mul(totalPooled);
uint256 denominator = totalSupply.sub(totalPooled);
return numerator.div(denominator);
}
// Check if more than 50% of the token is pooled
function is_profitable()
public
view
returns (bool _profitable) {
return totalPooled > totalSupply.sub(totalPooled);
}
// SETTERS
function addToWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = true;
}
function removeFromWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = false;
}
// TRANSFER FUNCTIONS
// BOA-TOKEN <- Sell taxed
// TOKEN-BOA <- Buy (not taxed)
function transfer(address to, uint256 value)
public
returns (bool success) {
require(balanceOf[msg.sender] >= value);
if(whitelist[msg.sender]) return regular_transfer(to, value);
else return burn_transfer(to, value);
}
function burn_transfer(address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// withdraw from the user's balance
balanceOf[msg.sender] = balanceOf[msg.sender].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the remaining 99%
return regular_transfer(to, value);
}
function regular_transfer(address to, uint256 value)
private
returns (bool success) {
// perform a normal transfer
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value)
public
returns (bool success)
{
require(value <= balanceOf[from]);
require(value <= allowance[from][msg.sender]);
// allow feeless for the RED-BLUE uniswap pool
if(whitelist[msg.sender]) return regular_transferFrom(from, to, value);
else return burn_transferFrom(from, to, value);
}
function burn_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// remove from the spender's balance
balanceOf[from] = balanceOf[from].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
// burn allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the 99%
return regular_transferFrom(from, to, value);
}
function regular_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// transfer without adding to a pool
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
// remove allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
emit Transfer(from, to, value);
return true;
}
// REDEEM AND BURN FUNCTIONS
// amount = number of tokens to burn
function redeem(uint256 amount)
public
profitable
returns (bool success) {
// the amount must be less than the total amount pooled
require(amount <= balanceOf[msg.sender]);
require(totalPooled >= amount);
uint256 num_redeemed = numberRedeemed(amount);
// make sure the number available to be redeemed is smaller than the available pool
require(num_redeemed < totalPooled);
balanceOf[msg.sender] = balanceOf[msg.sender].add(num_redeemed);
emit Transfer(_owner, msg.sender, num_redeemed);
totalPooled = totalPooled.sub(num_redeemed);
// burn the amount sent
return burn(amount);
}
function burn(uint256 value)
private
returns (bool success) {
// burn from the user's ledger, transfer to 0x0
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[address(0)] = balanceOf[address(0)].add(value);
emit Transfer(msg.sender, address(0), value);
// remove the burned amount from the total supply
totalSupply = totalSupply.sub(value);
return true;
}
// APPROVAL FUNCTIONS
event Approval(address indexed owner, address indexed spender, uint256 value);
mapping(address => mapping(address => uint256)) public allowance;
function approve(address spender, uint256 value)
public
returns (bool success)
{
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
} | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | NatSpecSingleLine | numberRedeemed | function numberRedeemed(uint256 amount)
public
view
returns (uint256 profit) {
uint256 numerator = amount.mul(totalPooled);
uint256 denominator = totalSupply.sub(totalPooled);
return numerator.div(denominator);
}
| // VIEWS
// Get the number of tokens to be redeemed from the pool | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f6abef39fc9e0e6c7b2519a4fa38924d289d26f15a90ff89e648cb97867cc95b | {
"func_code_index": [
1509,
1792
]
} | 56,863 |
MASTERDILL | MASTERDILL.sol | 0x9175757101d31317b16013570dda50403b00b0e2 | Solidity | MASTERDILL | contract MASTERDILL is Ownable{
using SafeMath for uint256;
mapping (address => uint256) public balanceOf;
mapping (address => bool) public whitelist;
string public name = "Master DILL";
string public symbol = "mDILL";
uint8 public decimals = 18;
uint256 public totalSupply = 1000000 * (uint256(10) ** decimals);
uint256 public totalPooled;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
event Transfer(address indexed from, address indexed to, uint256 value);
constructor() public {
totalPooled = 50 * (uint256(10) ** decimals);
// Initially assign all non-pooled tokens to the contract's creator.
balanceOf[msg.sender] = totalSupply.sub(totalPooled);
emit Transfer(address(0), msg.sender, totalSupply.sub(totalPooled));
}
// Ensure a redemption is profitable before allowing a redeem()
modifier profitable() {
require(is_profitable(), "Redeeming is not yet profitable.");
_;
}
// VIEWS
// Get the number of tokens to be redeemed from the pool
function numberRedeemed(uint256 amount)
public
view
returns (uint256 profit) {
uint256 numerator = amount.mul(totalPooled);
uint256 denominator = totalSupply.sub(totalPooled);
return numerator.div(denominator);
}
// Check if more than 50% of the token is pooled
function is_profitable()
public
view
returns (bool _profitable) {
return totalPooled > totalSupply.sub(totalPooled);
}
// SETTERS
function addToWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = true;
}
function removeFromWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = false;
}
// TRANSFER FUNCTIONS
// BOA-TOKEN <- Sell taxed
// TOKEN-BOA <- Buy (not taxed)
function transfer(address to, uint256 value)
public
returns (bool success) {
require(balanceOf[msg.sender] >= value);
if(whitelist[msg.sender]) return regular_transfer(to, value);
else return burn_transfer(to, value);
}
function burn_transfer(address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// withdraw from the user's balance
balanceOf[msg.sender] = balanceOf[msg.sender].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the remaining 99%
return regular_transfer(to, value);
}
function regular_transfer(address to, uint256 value)
private
returns (bool success) {
// perform a normal transfer
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value)
public
returns (bool success)
{
require(value <= balanceOf[from]);
require(value <= allowance[from][msg.sender]);
// allow feeless for the RED-BLUE uniswap pool
if(whitelist[msg.sender]) return regular_transferFrom(from, to, value);
else return burn_transferFrom(from, to, value);
}
function burn_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// remove from the spender's balance
balanceOf[from] = balanceOf[from].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
// burn allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the 99%
return regular_transferFrom(from, to, value);
}
function regular_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// transfer without adding to a pool
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
// remove allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
emit Transfer(from, to, value);
return true;
}
// REDEEM AND BURN FUNCTIONS
// amount = number of tokens to burn
function redeem(uint256 amount)
public
profitable
returns (bool success) {
// the amount must be less than the total amount pooled
require(amount <= balanceOf[msg.sender]);
require(totalPooled >= amount);
uint256 num_redeemed = numberRedeemed(amount);
// make sure the number available to be redeemed is smaller than the available pool
require(num_redeemed < totalPooled);
balanceOf[msg.sender] = balanceOf[msg.sender].add(num_redeemed);
emit Transfer(_owner, msg.sender, num_redeemed);
totalPooled = totalPooled.sub(num_redeemed);
// burn the amount sent
return burn(amount);
}
function burn(uint256 value)
private
returns (bool success) {
// burn from the user's ledger, transfer to 0x0
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[address(0)] = balanceOf[address(0)].add(value);
emit Transfer(msg.sender, address(0), value);
// remove the burned amount from the total supply
totalSupply = totalSupply.sub(value);
return true;
}
// APPROVAL FUNCTIONS
event Approval(address indexed owner, address indexed spender, uint256 value);
mapping(address => mapping(address => uint256)) public allowance;
function approve(address spender, uint256 value)
public
returns (bool success)
{
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
} | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | NatSpecSingleLine | is_profitable | function is_profitable()
public
view
returns (bool _profitable) {
return totalPooled > totalSupply.sub(totalPooled);
}
| // Check if more than 50% of the token is pooled | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f6abef39fc9e0e6c7b2519a4fa38924d289d26f15a90ff89e648cb97867cc95b | {
"func_code_index": [
1853,
2020
]
} | 56,864 |
MASTERDILL | MASTERDILL.sol | 0x9175757101d31317b16013570dda50403b00b0e2 | Solidity | MASTERDILL | contract MASTERDILL is Ownable{
using SafeMath for uint256;
mapping (address => uint256) public balanceOf;
mapping (address => bool) public whitelist;
string public name = "Master DILL";
string public symbol = "mDILL";
uint8 public decimals = 18;
uint256 public totalSupply = 1000000 * (uint256(10) ** decimals);
uint256 public totalPooled;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
event Transfer(address indexed from, address indexed to, uint256 value);
constructor() public {
totalPooled = 50 * (uint256(10) ** decimals);
// Initially assign all non-pooled tokens to the contract's creator.
balanceOf[msg.sender] = totalSupply.sub(totalPooled);
emit Transfer(address(0), msg.sender, totalSupply.sub(totalPooled));
}
// Ensure a redemption is profitable before allowing a redeem()
modifier profitable() {
require(is_profitable(), "Redeeming is not yet profitable.");
_;
}
// VIEWS
// Get the number of tokens to be redeemed from the pool
function numberRedeemed(uint256 amount)
public
view
returns (uint256 profit) {
uint256 numerator = amount.mul(totalPooled);
uint256 denominator = totalSupply.sub(totalPooled);
return numerator.div(denominator);
}
// Check if more than 50% of the token is pooled
function is_profitable()
public
view
returns (bool _profitable) {
return totalPooled > totalSupply.sub(totalPooled);
}
// SETTERS
function addToWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = true;
}
function removeFromWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = false;
}
// TRANSFER FUNCTIONS
// BOA-TOKEN <- Sell taxed
// TOKEN-BOA <- Buy (not taxed)
function transfer(address to, uint256 value)
public
returns (bool success) {
require(balanceOf[msg.sender] >= value);
if(whitelist[msg.sender]) return regular_transfer(to, value);
else return burn_transfer(to, value);
}
function burn_transfer(address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// withdraw from the user's balance
balanceOf[msg.sender] = balanceOf[msg.sender].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the remaining 99%
return regular_transfer(to, value);
}
function regular_transfer(address to, uint256 value)
private
returns (bool success) {
// perform a normal transfer
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value)
public
returns (bool success)
{
require(value <= balanceOf[from]);
require(value <= allowance[from][msg.sender]);
// allow feeless for the RED-BLUE uniswap pool
if(whitelist[msg.sender]) return regular_transferFrom(from, to, value);
else return burn_transferFrom(from, to, value);
}
function burn_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// remove from the spender's balance
balanceOf[from] = balanceOf[from].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
// burn allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the 99%
return regular_transferFrom(from, to, value);
}
function regular_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// transfer without adding to a pool
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
// remove allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
emit Transfer(from, to, value);
return true;
}
// REDEEM AND BURN FUNCTIONS
// amount = number of tokens to burn
function redeem(uint256 amount)
public
profitable
returns (bool success) {
// the amount must be less than the total amount pooled
require(amount <= balanceOf[msg.sender]);
require(totalPooled >= amount);
uint256 num_redeemed = numberRedeemed(amount);
// make sure the number available to be redeemed is smaller than the available pool
require(num_redeemed < totalPooled);
balanceOf[msg.sender] = balanceOf[msg.sender].add(num_redeemed);
emit Transfer(_owner, msg.sender, num_redeemed);
totalPooled = totalPooled.sub(num_redeemed);
// burn the amount sent
return burn(amount);
}
function burn(uint256 value)
private
returns (bool success) {
// burn from the user's ledger, transfer to 0x0
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[address(0)] = balanceOf[address(0)].add(value);
emit Transfer(msg.sender, address(0), value);
// remove the burned amount from the total supply
totalSupply = totalSupply.sub(value);
return true;
}
// APPROVAL FUNCTIONS
event Approval(address indexed owner, address indexed spender, uint256 value);
mapping(address => mapping(address => uint256)) public allowance;
function approve(address spender, uint256 value)
public
returns (bool success)
{
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
} | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | NatSpecSingleLine | addToWhitelist | function addToWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = true;
}
| // SETTERS | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f6abef39fc9e0e6c7b2519a4fa38924d289d26f15a90ff89e648cb97867cc95b | {
"func_code_index": [
2043,
2166
]
} | 56,865 |
MASTERDILL | MASTERDILL.sol | 0x9175757101d31317b16013570dda50403b00b0e2 | Solidity | MASTERDILL | contract MASTERDILL is Ownable{
using SafeMath for uint256;
mapping (address => uint256) public balanceOf;
mapping (address => bool) public whitelist;
string public name = "Master DILL";
string public symbol = "mDILL";
uint8 public decimals = 18;
uint256 public totalSupply = 1000000 * (uint256(10) ** decimals);
uint256 public totalPooled;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
event Transfer(address indexed from, address indexed to, uint256 value);
constructor() public {
totalPooled = 50 * (uint256(10) ** decimals);
// Initially assign all non-pooled tokens to the contract's creator.
balanceOf[msg.sender] = totalSupply.sub(totalPooled);
emit Transfer(address(0), msg.sender, totalSupply.sub(totalPooled));
}
// Ensure a redemption is profitable before allowing a redeem()
modifier profitable() {
require(is_profitable(), "Redeeming is not yet profitable.");
_;
}
// VIEWS
// Get the number of tokens to be redeemed from the pool
function numberRedeemed(uint256 amount)
public
view
returns (uint256 profit) {
uint256 numerator = amount.mul(totalPooled);
uint256 denominator = totalSupply.sub(totalPooled);
return numerator.div(denominator);
}
// Check if more than 50% of the token is pooled
function is_profitable()
public
view
returns (bool _profitable) {
return totalPooled > totalSupply.sub(totalPooled);
}
// SETTERS
function addToWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = true;
}
function removeFromWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = false;
}
// TRANSFER FUNCTIONS
// BOA-TOKEN <- Sell taxed
// TOKEN-BOA <- Buy (not taxed)
function transfer(address to, uint256 value)
public
returns (bool success) {
require(balanceOf[msg.sender] >= value);
if(whitelist[msg.sender]) return regular_transfer(to, value);
else return burn_transfer(to, value);
}
function burn_transfer(address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// withdraw from the user's balance
balanceOf[msg.sender] = balanceOf[msg.sender].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the remaining 99%
return regular_transfer(to, value);
}
function regular_transfer(address to, uint256 value)
private
returns (bool success) {
// perform a normal transfer
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value)
public
returns (bool success)
{
require(value <= balanceOf[from]);
require(value <= allowance[from][msg.sender]);
// allow feeless for the RED-BLUE uniswap pool
if(whitelist[msg.sender]) return regular_transferFrom(from, to, value);
else return burn_transferFrom(from, to, value);
}
function burn_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// remove from the spender's balance
balanceOf[from] = balanceOf[from].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
// burn allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the 99%
return regular_transferFrom(from, to, value);
}
function regular_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// transfer without adding to a pool
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
// remove allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
emit Transfer(from, to, value);
return true;
}
// REDEEM AND BURN FUNCTIONS
// amount = number of tokens to burn
function redeem(uint256 amount)
public
profitable
returns (bool success) {
// the amount must be less than the total amount pooled
require(amount <= balanceOf[msg.sender]);
require(totalPooled >= amount);
uint256 num_redeemed = numberRedeemed(amount);
// make sure the number available to be redeemed is smaller than the available pool
require(num_redeemed < totalPooled);
balanceOf[msg.sender] = balanceOf[msg.sender].add(num_redeemed);
emit Transfer(_owner, msg.sender, num_redeemed);
totalPooled = totalPooled.sub(num_redeemed);
// burn the amount sent
return burn(amount);
}
function burn(uint256 value)
private
returns (bool success) {
// burn from the user's ledger, transfer to 0x0
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[address(0)] = balanceOf[address(0)].add(value);
emit Transfer(msg.sender, address(0), value);
// remove the burned amount from the total supply
totalSupply = totalSupply.sub(value);
return true;
}
// APPROVAL FUNCTIONS
event Approval(address indexed owner, address indexed spender, uint256 value);
mapping(address => mapping(address => uint256)) public allowance;
function approve(address spender, uint256 value)
public
returns (bool success)
{
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
} | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | NatSpecSingleLine | transfer | function transfer(address to, uint256 value)
public
returns (bool success) {
require(balanceOf[msg.sender] >= value);
if(whitelist[msg.sender]) return regular_transfer(to, value);
else return burn_transfer(to, value);
}
| // TRANSFER FUNCTIONS
// BOA-TOKEN <- Sell taxed
// TOKEN-BOA <- Buy (not taxed) | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f6abef39fc9e0e6c7b2519a4fa38924d289d26f15a90ff89e648cb97867cc95b | {
"func_code_index": [
2418,
2704
]
} | 56,866 |
MASTERDILL | MASTERDILL.sol | 0x9175757101d31317b16013570dda50403b00b0e2 | Solidity | MASTERDILL | contract MASTERDILL is Ownable{
using SafeMath for uint256;
mapping (address => uint256) public balanceOf;
mapping (address => bool) public whitelist;
string public name = "Master DILL";
string public symbol = "mDILL";
uint8 public decimals = 18;
uint256 public totalSupply = 1000000 * (uint256(10) ** decimals);
uint256 public totalPooled;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
event Transfer(address indexed from, address indexed to, uint256 value);
constructor() public {
totalPooled = 50 * (uint256(10) ** decimals);
// Initially assign all non-pooled tokens to the contract's creator.
balanceOf[msg.sender] = totalSupply.sub(totalPooled);
emit Transfer(address(0), msg.sender, totalSupply.sub(totalPooled));
}
// Ensure a redemption is profitable before allowing a redeem()
modifier profitable() {
require(is_profitable(), "Redeeming is not yet profitable.");
_;
}
// VIEWS
// Get the number of tokens to be redeemed from the pool
function numberRedeemed(uint256 amount)
public
view
returns (uint256 profit) {
uint256 numerator = amount.mul(totalPooled);
uint256 denominator = totalSupply.sub(totalPooled);
return numerator.div(denominator);
}
// Check if more than 50% of the token is pooled
function is_profitable()
public
view
returns (bool _profitable) {
return totalPooled > totalSupply.sub(totalPooled);
}
// SETTERS
function addToWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = true;
}
function removeFromWhitelist(address _addr)
public
onlyOwner {
whitelist[_addr] = false;
}
// TRANSFER FUNCTIONS
// BOA-TOKEN <- Sell taxed
// TOKEN-BOA <- Buy (not taxed)
function transfer(address to, uint256 value)
public
returns (bool success) {
require(balanceOf[msg.sender] >= value);
if(whitelist[msg.sender]) return regular_transfer(to, value);
else return burn_transfer(to, value);
}
function burn_transfer(address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// withdraw from the user's balance
balanceOf[msg.sender] = balanceOf[msg.sender].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the remaining 99%
return regular_transfer(to, value);
}
function regular_transfer(address to, uint256 value)
private
returns (bool success) {
// perform a normal transfer
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value)
public
returns (bool success)
{
require(value <= balanceOf[from]);
require(value <= allowance[from][msg.sender]);
// allow feeless for the RED-BLUE uniswap pool
if(whitelist[msg.sender]) return regular_transferFrom(from, to, value);
else return burn_transferFrom(from, to, value);
}
function burn_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// send 1% to the pooled ledger
uint256 burned_amount = value.div(5); //BURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRN
// remove from the spender's balance
balanceOf[from] = balanceOf[from].sub(burned_amount);
// increment the total pooled amount
totalPooled = totalPooled.add(burned_amount);
// burn allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(burned_amount);
value = value.sub(burned_amount);
// perform a normal transfer on the 99%
return regular_transferFrom(from, to, value);
}
function regular_transferFrom(address from, address to, uint256 value)
private
returns (bool success) {
// transfer without adding to a pool
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
// remove allowance (for approved spenders)
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
emit Transfer(from, to, value);
return true;
}
// REDEEM AND BURN FUNCTIONS
// amount = number of tokens to burn
function redeem(uint256 amount)
public
profitable
returns (bool success) {
// the amount must be less than the total amount pooled
require(amount <= balanceOf[msg.sender]);
require(totalPooled >= amount);
uint256 num_redeemed = numberRedeemed(amount);
// make sure the number available to be redeemed is smaller than the available pool
require(num_redeemed < totalPooled);
balanceOf[msg.sender] = balanceOf[msg.sender].add(num_redeemed);
emit Transfer(_owner, msg.sender, num_redeemed);
totalPooled = totalPooled.sub(num_redeemed);
// burn the amount sent
return burn(amount);
}
function burn(uint256 value)
private
returns (bool success) {
// burn from the user's ledger, transfer to 0x0
balanceOf[msg.sender] = balanceOf[msg.sender].sub(value);
balanceOf[address(0)] = balanceOf[address(0)].add(value);
emit Transfer(msg.sender, address(0), value);
// remove the burned amount from the total supply
totalSupply = totalSupply.sub(value);
return true;
}
// APPROVAL FUNCTIONS
event Approval(address indexed owner, address indexed spender, uint256 value);
mapping(address => mapping(address => uint256)) public allowance;
function approve(address spender, uint256 value)
public
returns (bool success)
{
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
} | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | NatSpecSingleLine | redeem | function redeem(uint256 amount)
public
profitable
returns (bool success) {
// the amount must be less than the total amount pooled
require(amount <= balanceOf[msg.sender]);
require(totalPooled >= amount);
uint256 num_redeemed = numberRedeemed(amount);
// make sure the number available to be redeemed is smaller than the available pool
require(num_redeemed < totalPooled);
balanceOf[msg.sender] = balanceOf[msg.sender].add(num_redeemed);
emit Transfer(_owner, msg.sender, num_redeemed);
totalPooled = totalPooled.sub(num_redeemed);
// burn the amount sent
return burn(amount);
}
| // REDEEM AND BURN FUNCTIONS
// amount = number of tokens to burn | LineComment | v0.6.12+commit.27d51765 | None | ipfs://f6abef39fc9e0e6c7b2519a4fa38924d289d26f15a90ff89e648cb97867cc95b | {
"func_code_index": [
5608,
6356
]
} | 56,867 |
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
| /**
* @dev Multiplies two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
89,
266
]
} | 56,868 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
| /**
* @dev Integer division of two numbers, truncating the quotient.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
350,
630
]
} | 56,869 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
| /**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
744,
860
]
} | 56,870 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
} | add | function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
| /**
* @dev Adds two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
924,
1054
]
} | 56,871 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | 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));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | 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.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
261,
321
]
} | 56,872 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | 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));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | transferOwnership | function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit 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.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
640,
821
]
} | 56,873 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | BITVesting | contract BITVesting is Ownable {
BITToken public token;
uint256 public releaseDate;
function BITVesting (
BITToken _token,
address _beneficiary,
uint256 _releaseDate
) public {
token = _token;
releaseDate = _releaseDate;
owner = _beneficiary;
}
/* After vesting period, this function transfers all available tokens
* from it's account to `_recipient` address. This address could either be
* a wallet or another smart contract. If the transfer was successful, it
* selfdestructs the contract.
*/
function claim (
address _recipient,
bytes _data
) external onlyOwner returns (bool success) {
require(_recipient != address(0));
require(block.timestamp > releaseDate);
uint256 funds = token.balanceOf(this);
require(token.transfer(_recipient, funds));
// require(token.transfer(_recipient, funds, _data)); // ERC-20 compatible string
selfdestruct(msg.sender);
return true;
}
/* From: https://github.com/ethereum/EIPs/issues/223
*
* A function for handling token transfers, which is called from the token
* contract, when a token holder sends tokens. `_from` is the address of the
* sender of the token, `_value` is the amount of incoming tokens, and
* `_data` is attached data similar to `msg.data` of Ether transactions.
* It works by analogy with the fallback function of Ether transactions and
* returns nothing.
*/
function tokenFallback(
address _from,
uint _value,
bytes _data
) external view {
require(msg.sender == address(token));
}
} | claim | function claim (
address _recipient,
bytes _data
) external onlyOwner returns (bool success) {
require(_recipient != address(0));
require(block.timestamp > releaseDate);
uint256 funds = token.balanceOf(this);
require(token.transfer(_recipient, funds));
// require(token.transfer(_recipient, funds, _data)); // ERC-20 compatible string
selfdestruct(msg.sender);
return true;
}
| /* After vesting period, this function transfers all available tokens
* from it's account to `_recipient` address. This address could either be
* a wallet or another smart contract. If the transfer was successful, it
* selfdestructs the contract.
*/ | Comment | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
616,
1093
]
} | 56,874 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | BITVesting | contract BITVesting is Ownable {
BITToken public token;
uint256 public releaseDate;
function BITVesting (
BITToken _token,
address _beneficiary,
uint256 _releaseDate
) public {
token = _token;
releaseDate = _releaseDate;
owner = _beneficiary;
}
/* After vesting period, this function transfers all available tokens
* from it's account to `_recipient` address. This address could either be
* a wallet or another smart contract. If the transfer was successful, it
* selfdestructs the contract.
*/
function claim (
address _recipient,
bytes _data
) external onlyOwner returns (bool success) {
require(_recipient != address(0));
require(block.timestamp > releaseDate);
uint256 funds = token.balanceOf(this);
require(token.transfer(_recipient, funds));
// require(token.transfer(_recipient, funds, _data)); // ERC-20 compatible string
selfdestruct(msg.sender);
return true;
}
/* From: https://github.com/ethereum/EIPs/issues/223
*
* A function for handling token transfers, which is called from the token
* contract, when a token holder sends tokens. `_from` is the address of the
* sender of the token, `_value` is the amount of incoming tokens, and
* `_data` is attached data similar to `msg.data` of Ether transactions.
* It works by analogy with the fallback function of Ether transactions and
* returns nothing.
*/
function tokenFallback(
address _from,
uint _value,
bytes _data
) external view {
require(msg.sender == address(token));
}
} | tokenFallback | function tokenFallback(
address _from,
uint _value,
bytes _data
) external view {
require(msg.sender == address(token));
}
| /* From: https://github.com/ethereum/EIPs/issues/223
*
* A function for handling token transfers, which is called from the token
* contract, when a token holder sends tokens. `_from` is the address of the
* sender of the token, `_value` is the amount of incoming tokens, and
* `_data` is attached data similar to `msg.data` of Ether transactions.
* It works by analogy with the fallback function of Ether transactions and
* returns nothing.
*/ | Comment | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
1593,
1772
]
} | 56,875 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | Pausable | contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
} | pause | function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
| /**
* @dev called by the owner to pause, triggers stopped state
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
513,
609
]
} | 56,876 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | Pausable | contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
} | unpause | function unpause() onlyOwner whenPaused public {
paused = false;
emit Unpause();
}
| /**
* @dev called by the owner to unpause, returns to normal state
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
693,
791
]
} | 56,877 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @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]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit 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];
}
} | totalSupply | function totalSupply() public view returns (uint256) {
return totalSupply_;
}
| /**
* @dev total number of tokens in existence
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
199,
287
]
} | 56,878 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @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]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit 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];
}
} | transfer | function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
445,
777
]
} | 56,879 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @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]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit 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];
}
} | 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.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
983,
1095
]
} | 56,880 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | 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);
emit 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;
emit 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];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | 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);
emit 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.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
401,
858
]
} | 56,881 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | 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);
emit 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;
emit 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];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | approve | function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit 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.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
1490,
1685
]
} | 56,882 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | 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);
emit 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;
emit 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];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | 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.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
2009,
2140
]
} | 56,883 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | 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);
emit 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;
emit 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];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | increaseApproval | function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
2606,
2875
]
} | 56,884 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | 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);
emit 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;
emit 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];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a 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
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | decreaseApproval | function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_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
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
3346,
3761
]
} | 56,885 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | MintableToken | contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
emit MintFinished();
return true;
}
} | mint | function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
| /**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
483,
766
]
} | 56,886 |
|||
BITToken | BITToken.sol | 0x1dc75212ca6489dd26f8dedb9411f230a4e493cc | Solidity | MintableToken | contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
modifier canMint() {
require(!mintingFinished);
_;
}
/**
* @dev Function to mint tokens
* @param _to The address that will receive the minted tokens.
* @param _amount The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
totalSupply_ = totalSupply_.add(_amount);
balances[_to] = balances[_to].add(_amount);
emit Mint(_to, _amount);
emit Transfer(address(0), _to, _amount);
return true;
}
/**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/
function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
emit MintFinished();
return true;
}
} | finishMinting | function finishMinting() onlyOwner canMint public returns (bool) {
mintingFinished = true;
emit MintFinished();
return true;
}
| /**
* @dev Function to stop minting new tokens.
* @return True if the operation was successful.
*/ | NatSpecMultiLine | v0.4.23+commit.124ca40d | bzzr://ddcb99bea43b8e49530322b245d9f7bdae76db57a79dc0f106c0e6cc04fe0e4c | {
"func_code_index": [
883,
1030
]
} | 56,887 |
|||
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Strings | library Strings {
// via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol
function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) {
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
bytes memory _bc = bytes(_c);
bytes memory _bd = bytes(_d);
bytes memory _be = bytes(_e);
string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
bytes memory babcde = bytes(abcde);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
for (i = 0; i < _be.length; i++) babcde[k++] = _be[i];
return string(babcde);
}
function strConcat(string _a, string _b, string _c, string _d) internal pure returns (string) {
return strConcat(_a, _b, _c, _d, "");
}
function strConcat(string _a, string _b, string _c) internal pure returns (string) {
return strConcat(_a, _b, _c, "", "");
}
function strConcat(string _a, string _b) internal pure returns (string) {
return strConcat(_a, _b, "", "", "");
}
function uint2str(uint i) internal pure returns (string) {
if (i == 0) return "0";
uint j = i;
uint len;
while (j != 0){
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len - 1;
while (i != 0){
bstr[k--] = byte(48 + i % 10);
i /= 10;
}
return string(bstr);
}
} | strConcat | function strConcat(string _a, string _b, string _c, string _d, string _e) internal pure returns (string) {
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
bytes memory _bc = bytes(_c);
bytes memory _bd = bytes(_d);
bytes memory _be = bytes(_e);
string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
bytes memory babcde = bytes(abcde);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
for (i = 0; i < _be.length; i++) babcde[k++] = _be[i];
return string(babcde);
}
| // via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol | LineComment | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
104,
947
]
} | 56,888 |
|||
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | _owns | function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
| /**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2318,
2469
]
} | 56,889 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | _approve | function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
| /**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2942,
3071
]
} | 56,890 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | rescueLostKydy | function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
| /**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3520,
3712
]
} | 56,891 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
| /**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3971,
4134
]
} | 56,892 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | approve | function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
| /**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
4606,
5112
]
} | 56,893 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
| /**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
5589,
6328
]
} | 56,894 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | safeTransferFrom | function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
| /**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
7011,
7200
]
} | 56,895 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | safeTransferFrom | function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
| /**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
7956,
8218
]
} | 56,896 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | _checkOnERC721Received | function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
| /**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
8755,
9106
]
} | 56,897 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | name | function name() external view returns (string) {
return _name;
}
| /**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
9265,
9348
]
} | 56,898 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | symbol | function symbol() external view returns (string) {
return _symbol;
}
| /**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
9507,
9594
]
} | 56,899 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | tokenURI | function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
| /**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
9845,
10073
]
} | 56,900 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
| /**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
10224,
10324
]
} | 56,901 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyOwnership | contract KydyOwnership is KydyBase {
using Strings for string;
/// @notice Name and symbol of the non fungible token, as defined in ERC721.
string public constant _name = "Dyverse";
string public constant _symbol = "KYDY";
// Base Server Address for Token MetaData URI
string internal tokenURIBase = "http://testapi.dyver.se/api/KydyMetadata/";
// Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
// which can be also obtained as `ERC721TokenReceiver(0).onERC721Received.selector`
bytes4 private constant _ERC721_RECEIVED = 0x150b7a02;
bytes4 private constant _InterfaceId_ERC165 = 0x01ffc9a7;
/**
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
bytes4 private constant _InterfaceId_ERC721 = 0x80ac58cd;
/*
* 0x80ac58cd ===
* bytes4(keccak256('balanceOf(address)')) ^
* bytes4(keccak256('ownerOf(uint256)')) ^
* bytes4(keccak256('approve(address,uint256)')) ^
* bytes4(keccak256('getApproved(uint256)')) ^
* bytes4(keccak256('setApprovalForAll(address,bool)')) ^
* bytes4(keccak256('isApprovedForAll(address,address)')) ^
* bytes4(keccak256('transferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^
* bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)'))
*/
bytes4 private constant _InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
constructor() public {
_registerInterface(_InterfaceId_ERC165);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721);
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(_InterfaceId_ERC721Metadata);
}
/**
* @dev Checks if a given address is the current owner of this Kydy.
* @param _claimant the address which we want to query the ownership of the Kydy ID.
* @param _tokenId Kydy id, only valid when > 0
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return kydyIndexToOwner[_tokenId] == _claimant;
}
/**
* @dev Grants an approval to the given address for safeTransferFrom(), overwriting any
* previous approval. Setting _approved to address(0) clears all transfer approval.
* Note that _approve() does NOT emit the Approval event. This is intentional because
* _approve() and safeTransferFrom() are used together when putting Kydys to the auction,
* and there is no need to spam the log with Approval events in that case.
*/
function _approve(uint256 _tokenId, address _approved) internal {
kydyIndexToApproved[_tokenId] = _approved;
}
/**
* @dev Transfers a Kydy owned by this contract to the specified address.
* Used to rescue lost Kydys. (There is no "proper" flow where this contract
* should be the owner of any Kydy. This function exists for us to reassign
* the ownership of Kydys that users may have accidentally sent to our address.)
* @param _kydyId ID of the lost Kydy
* @param _recipient address to send the Kydy to
*/
function rescueLostKydy(uint256 _kydyId, address _recipient) external onlyCOO whenNotPaused {
require(_owns(this, _kydyId));
_transfer(this, _recipient, _kydyId);
}
/**
* @dev Gets the number of Kydys owned by the given address.
* Required for ERC-721 compliance.
* @param _owner address to query the balance of
* @return uint256 representing the amount owned by the passed address
*/
function balanceOf(address _owner) public view returns (uint256) {
require(_owner != address(0));
return ownershipTokenCount[_owner];
}
/**
* @dev Approves another address to transfer the given Kydy ID.
* The zero address indicates that there is no approved address.
* There can only be one approved address per Kydy at a given time.
* Can only be called by the Kydy owner or an approved operator.
* Required for ERC-721 compliance.
* @param to address to be approved for the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be approved
*/
function approve(address to, uint256 tokenId) external whenNotPaused {
address owner = ownerOf(tokenId);
require(to != owner);
// Owner or approved operator by owner can approve the another address
// to transfer the Kydy.
require(msg.sender == owner || isApprovedForAll(owner, msg.sender));
// Approves the given address.
_approve(tokenId, to);
// Emits the Approval event.
emit Approval(owner, to, tokenId);
}
/**
* @dev Transfers the ownership of the Kydy to another address.
* Usage of this function is discouraged, use `safeTransferFrom` whenever possible.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function transferFrom(address from, address to, uint256 tokenId) public whenNotPaused {
// Checks the caller is the owner or approved one or an operator.
require(_isApprovedOrOwner(msg.sender, tokenId));
// Safety check to prevent from transferring Kydy to 0x0 address.
require(to != address(0));
// Clears approval from current owner.
_clearApproval(from, tokenId);
// Resets the ownership of this Kydy from current owner and sets it to 0x0.
_removeTokenFrom(from, tokenId);
// Grants the ownership of this Kydy to new owner.
_addTokenTo(to, tokenId);
// Emits the Transfer event.
emit Transfer(from, to, tokenId);
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public {
// solium-disable-next-line arg-overflow
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev Safely transfers the ownership of a given Kydy to another address.
* If the target address is a contract, it must implement `onERC721Received`,
* which is called upon a safe transfer, and return the magic value
* `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`;
* Otherwise, the transfer is reverted.
* Requires the msg sender to be the owner, approved, or operator.
* Required for ERC-721 compliance.
* @param from current owner of the Kydy
* @param to address to receive the ownership of the given Kydy ID
* @param tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes data to send along with a safe transfer check
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public {
transferFrom(from, to, tokenId);
// solium-disable-next-line arg-overflow
require(_checkOnERC721Received(from, to, tokenId, _data));
}
/**
* @dev Internal function to invoke `onERC721Received` on a target address.
* This function is not executed if the target address is not a contract.
* @param _from address representing the previous owner of the given Kydy ID
* @param _to target address that will receive the Kydys
* @param _tokenId uint256 ID of the Kydy to be transferred
* @param _data bytes optional data to send along with the call
* @return whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(address _from, address _to, uint256 _tokenId, bytes _data) internal returns (bool) {
if (!_to.isContract()) {
return true;
}
bytes4 retval = ERC721TokenReceiver(_to).onERC721Received(msg.sender, _from, _tokenId, _data);
return (retval == _ERC721_RECEIVED);
}
/**
* @dev Gets the token name.
* Required for ERC721Metadata compliance.
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol.
* Required for ERC721Metadata compliance.
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given Kydy ID.
* Throws if the token ID does not exist. May return an empty string.
* Required for ERC721Metadata compliance.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) external view returns (string) {
require(_exists(tokenId));
return Strings.strConcat(
tokenURIBase,
Strings.uint2str(tokenId)
);
}
/**
* @dev Gets the total amount of Kydys stored in the contract
* @return uint256 representing the total amount of Kydys
*/
function totalSupply() public view returns (uint256) {
return kydys.length - 1;
}
/**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/
function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
} | /**
* @title Part of the KydyCore contract that manages ownership, ERC-721 compliant.
* @author VREX Lab Co., Ltd
* @dev Ref: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
* See the KydyCore contract documentation to understand how the various contracts are arranged.
*/ | NatSpecMultiLine | tokensOfOwner | function tokensOfOwner(address _owner) external view returns(uint256[] ownerTokens) {
uint256 tokenCount = balanceOf(_owner);
if (tokenCount == 0) {
// Return an empty array
return new uint256[](0);
} else {
uint256[] memory result = new uint256[](tokenCount);
uint256 totalKydys = totalSupply();
uint256 resultIndex = 0;
// All Kydys have IDs starting at 1 and increasing sequentially up to the totalKydy count.
uint256 kydyId;
for (kydyId = 1; kydyId <= totalKydys; kydyId++) {
if (kydyIndexToOwner[kydyId] == _owner) {
result[resultIndex] = kydyId;
resultIndex++;
}
}
return result;
}
}
| /**
* @notice Returns a list of all Kydy IDs assigned to an address.
* @param _owner The owner whose Kydys we are interested in.
* @dev This function MUST NEVER be called by smart contract code. It's pretty
* expensive (it looks into the entire Kydy array looking for Kydys belonging to owner),
* and it also returns a dynamic array, which is only supported for web3 calls, and
* not contract-to-contract calls.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
10792,
11641
]
} | 56,902 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | setGeneSynthesisAddress | function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
| /**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
992,
1368
]
} | 56,903 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | _isReadyToSynthesize | function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
| /**
* @dev Checks that the Kydy is able to synthesize.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1447,
1698
]
} | 56,904 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | _isSynthesizingAllowed | function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
| /**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1806,
2117
]
} | 56,905 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | _triggerRecharge | function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
| /**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2372,
2830
]
} | 56,906 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | approveSynthesizing | function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
| /**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3112,
3338
]
} | 56,907 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | setAutoCreationFee | function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
| /**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3481,
3588
]
} | 56,908 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | _isReadyToBringKydyHome | function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
| /// @dev Checks if this Kydy is creating and if the creation period is complete. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3678,
3862
]
} | 56,909 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | isReadyToSynthesize | function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
| /**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3994,
4230
]
} | 56,910 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | isCreating | function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
| /**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
4358,
4556
]
} | 56,911 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | _isValidCouple | function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
| /**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
4876,
5908
]
} | 56,912 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | _canSynthesizeWithViaAuction | function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
| /**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
6050,
6343
]
} | 56,913 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | canSynthesizeWith | function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
| /**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
6570,
6968
]
} | 56,914 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | _synthesizeWith | function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
| /**
* @dev Internal function to start synthesizing, when all the conditions are met
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
7075,
7901
]
} | 56,915 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | synthesizeWithAuto | function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
| /**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
8252,
9405
]
} | 56,916 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydySynthesis | contract KydySynthesis is KydyOwnership {
/**
* @dev The Creating event is emitted when two Kydys synthesize and the creation
* timer begins by the yin.
*/
event Creating(address owner, uint256 yinId, uint256 yangId, uint256 rechargeEndBlock);
/**
* @notice The minimum payment required for synthesizeWithAuto(). This fee is for
* the gas cost paid by whoever calls bringKydyHome(), and can be updated by the COO address.
*/
uint256 public autoCreationFee = 14 finney;
// Number of the Kydys that are creating a new Kydy.
uint256 public creatingKydys;
/**
* @dev The address of the sibling contract that mixes and combines genes of the two parent Kydys.
*/
GeneSynthesisInterface public geneSynthesis;
/**
* @dev Updates the address of the genetic contract. Only CEO may call this function.
* @param _address An address of the new GeneSynthesis contract instance.
*/
function setGeneSynthesisAddress(address _address) external onlyCEO {
GeneSynthesisInterface candidateContract = GeneSynthesisInterface(_address);
// Verifies that the contract is valid.
require(candidateContract.isGeneSynthesis());
// Sets the new GeneSynthesis contract address.
geneSynthesis = candidateContract;
}
/**
* @dev Checks that the Kydy is able to synthesize.
*/
function _isReadyToSynthesize(Kydy _kyd) internal view returns (bool) {
// Double-checking if there is any pending creation event.
return (_kyd.synthesizingWithId == 0) && (_kyd.rechargeEndBlock <= uint64(block.number));
}
/**
* @dev Checks if a yang Kydy has been approved to synthesize with this yin Kydy.
*/
function _isSynthesizingAllowed(uint256 _yangId, uint256 _yinId) internal view returns (bool) {
address yinOwner = kydyIndexToOwner[_yinId];
address yangOwner = kydyIndexToOwner[_yangId];
return (yinOwner == yangOwner || synthesizeAllowedToAddress[_yangId] == yinOwner);
}
/**
* @dev Sets the rechargeEndTime for the given Kydy, based on its current rechargeIndex.
* The rechargeIndex increases until it hits the cap.
* @param _kyd A reference to the Kydy that needs its timer to be started.
*/
function _triggerRecharge(Kydy storage _kyd) internal {
// Computes the approximation of the end of recharge time in blocks (based on current rechargeIndex).
_kyd.rechargeEndBlock = uint64((recharges[_kyd.rechargeIndex] / secondsPerBlock) + block.number);
// Increases this Kydy's synthesizing count, and the cap is fixed at 12.
if (_kyd.rechargeIndex < 12) {
_kyd.rechargeIndex += 1;
}
}
/**
* @notice Grants approval to another user to synthesize with one of your Kydys.
* @param _address The approved address of the yin Kydy that can synthesize with your yang Kydy.
* @param _yangId Your kydy that _address can now synthesize with.
*/
function approveSynthesizing(address _address, uint256 _yangId)
external
whenNotPaused
{
require(_owns(msg.sender, _yangId));
synthesizeAllowedToAddress[_yangId] = _address;
}
/**
* @dev Updates the minimum payment required for calling bringKydyHome(). Only COO
* can call this function.
*/
function setAutoCreationFee(uint256 value) external onlyCOO {
autoCreationFee = value;
}
/// @dev Checks if this Kydy is creating and if the creation period is complete.
function _isReadyToBringKydyHome(Kydy _yin) private view returns (bool) {
return (_yin.synthesizingWithId != 0) && (_yin.rechargeEndBlock <= uint64(block.number));
}
/**
* @notice Checks if this Kydy is able to synthesize
* @param _kydyId reference the ID of the Kydy
*/
function isReadyToSynthesize(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
Kydy storage kyd = kydys[_kydyId];
return _isReadyToSynthesize(kyd);
}
/**
* @dev Checks if the Kydy is currently creating.
* @param _kydyId reference the ID of the Kydy
*/
function isCreating(uint256 _kydyId)
public
view
returns (bool)
{
require(_kydyId > 0);
return kydys[_kydyId].synthesizingWithId != 0;
}
/**
* @dev Internal check to see if these yang and yin are a valid couple.
* @param _yin A reference to the Kydy struct of the potential yin.
* @param _yinId The yin's ID.
* @param _yang A reference to the Kydy struct of the potential yang.
* @param _yangId The yang's ID
*/
function _isValidCouple(
Kydy storage _yin,
uint256 _yinId,
Kydy storage _yang,
uint256 _yangId
)
private
view
returns(bool)
{
// Kydy can't synthesize with itself.
if (_yinId == _yangId) {
return false;
}
// Kydys can't synthesize with their parents.
if (_yin.yinId == _yangId || _yin.yangId == _yangId) {
return false;
}
if (_yang.yinId == _yinId || _yang.yangId == _yinId) {
return false;
}
// Skip sibling check for Gen 0
if (_yang.yinId == 0 || _yin.yinId == 0) {
return true;
}
// Kydys can't synthesize with full or half siblings.
if (_yang.yinId == _yin.yinId || _yang.yinId == _yin.yangId) {
return false;
}
if (_yang.yangId == _yin.yinId || _yang.yangId == _yin.yangId) {
return false;
}
return true;
}
/**
* @dev Internal check to see if these yang and yin Kydys, connected via market, are a valid couple for synthesis.
*/
function _canSynthesizeWithViaAuction(uint256 _yinId, uint256 _yangId)
internal
view
returns (bool)
{
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId);
}
/**
* @dev Checks if the two Kydys can synthesize together, including checks for ownership and synthesizing approvals.
* @param _yinId ID of the yin Kydy
* @param _yangId ID of the yang Kydy
*/
function canSynthesizeWith(uint256 _yinId, uint256 _yangId)
external
view
returns(bool)
{
require(_yinId > 0);
require(_yangId > 0);
Kydy storage yin = kydys[_yinId];
Kydy storage yang = kydys[_yangId];
return _isValidCouple(yin, _yinId, yang, _yangId) &&
_isSynthesizingAllowed(_yangId, _yinId);
}
/**
* @dev Internal function to start synthesizing, when all the conditions are met
*/
function _synthesizeWith(uint256 _yinId, uint256 _yangId) internal {
Kydy storage yang = kydys[_yangId];
Kydy storage yin = kydys[_yinId];
// Marks this yin as creating, and make note of who the yang Kydy is.
yin.synthesizingWithId = uint32(_yangId);
// Triggers the recharge for both parents.
_triggerRecharge(yang);
_triggerRecharge(yin);
// Clears synthesizing permission for both parents, just in case.
delete synthesizeAllowedToAddress[_yinId];
delete synthesizeAllowedToAddress[_yangId];
// When a Kydy starts creating, this number is increased.
creatingKydys++;
// Emits the Creating event.
emit Creating(kydyIndexToOwner[_yinId], _yinId, _yangId, yin.rechargeEndBlock);
}
/**
* @dev Synthesis between two approved Kydys. Requires a pre-payment of the fee to the first caller of bringKydyHome().
* @param _yinId ID of the Kydy which will be a yin (will start creation if successful)
* @param _yangId ID of the Kydy which will be a yang (will begin its synthesizing cooldown if successful)
*/
function synthesizeWithAuto(uint256 _yinId, uint256 _yangId)
external
payable
whenNotPaused
{
// Checks for pre-payment.
require(msg.value >= autoCreationFee);
// Caller must be the yin's owner.
require(_owns(msg.sender, _yinId));
// Checks if the caller has valid authority for this synthesis
require(_isSynthesizingAllowed(_yangId, _yinId));
// Gets a reference of the potential yin.
Kydy storage yin = kydys[_yinId];
// Checks that the potential yin is ready to synthesize
require(_isReadyToSynthesize(yin));
// Gets a reference of the potential yang.
Kydy storage yang = kydys[_yangId];
// Checks that the potential yang is ready to synthesize
require(_isReadyToSynthesize(yang));
// Checks that these Kydys are a valid couple.
require(_isValidCouple(
yin,
_yinId,
yang,
_yangId
));
// All checks passed! Yin Kydy starts creating.
_synthesizeWith(_yinId, _yangId);
}
/**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/
function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
} | /**
* @title This manages synthesis and creation of Kydys.
* @author VREX Lab Co., Ltd
* @dev Please reference the KydyCore contract for details.
*/ | NatSpecMultiLine | bringKydyHome | function bringKydyHome(uint256 _yinId)
external
whenNotPaused
returns(uint256)
{
// Gets a reference of the yin from storage.
Kydy storage yin = kydys[_yinId];
// Checks that the yin is a valid Kydy.
require(yin.createdTime != 0);
// Checks that the yin is in creation mode, and the creating period is over.
require(_isReadyToBringKydyHome(yin));
// Gets a reference of the yang from storage.
uint256 yangId = yin.synthesizingWithId;
Kydy storage yang = kydys[yangId];
// Ascertains which has the higher generation number between the two parents.
uint16 parentGen = yin.generation;
if (yang.generation > yin.generation) {
parentGen = yang.generation;
}
// The baby Kydy receives its genes
uint256 childGenes = geneSynthesis.synthGenes(yin.genes, yang.genes);
// The baby Kydy is now on blockchain
address owner = kydyIndexToOwner[_yinId];
uint256 kydyId = _createKydy(_yinId, yin.synthesizingWithId, parentGen + 1, childGenes, owner);
// Clears the synthesis status of the parents
delete yin.synthesizingWithId;
// When a baby Kydy is created, this number is decreased back.
creatingKydys--;
// Sends the fee to the person who called this.
msg.sender.transfer(autoCreationFee);
// Returns the new Kydy's ID.
return kydyId;
}
| /**
* @notice Let's bring the new Kydy to it's home!
* @param _yinId A Kydy which is ready to bring the newly created Kydy to home.
* @return The Kydy ID of the newly created Kydy.
* @dev The newly created Kydy is transferred to the owner of the yin Kydy. Anyone is welcome to call this function.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
9743,
11279
]
} | 56,917 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | function() external {}
| /// @dev Disables sending funds to this contract. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
964,
991
]
} | 56,918 |
||
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _owns | function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
| /**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1593,
1757
]
} | 56,919 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _escrow | function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
| /**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2003,
2147
]
} | 56,920 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _transfer | function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
| /**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2356,
2508
]
} | 56,921 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _addAuction | function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
| /**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2718,
2958
]
} | 56,922 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _cancelAuction | function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
| /// @dev Cancels the auction which the _seller wants. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3020,
3216
]
} | 56,923 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _bid | function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
| /**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3367,
4731
]
} | 56,924 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _removeAuction | function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
| /**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
4880,
4988
]
} | 56,925 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _isOnAuction | function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
| /**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
5119,
5251
]
} | 56,926 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _currentPrice | function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
| /// @dev Returns the current price of an NFT on auction. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
5316,
5474
]
} | 56,927 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | AuctionBase | contract AuctionBase is ERC721Holder {
using SafeMath for uint256;
// Represents an auction on an NFT
struct Auction {
// Current owner of NFT
address seller;
// Price (in wei) of NFT
uint128 price;
// Time when the auction started
// NOTE: 0 if this auction has been concluded
uint64 startedAt;
}
// Reference to contract tracking NFT ownership
ERC721Basic public nonFungibleContract;
// The amount owner takes from the sale, (in basis points, which are 1/100 of a percent).
uint256 public ownerCut;
// Maps token ID to it's corresponding auction.
mapping (uint256 => Auction) tokenIdToAuction;
event AuctionCreated(uint256 tokenId, uint256 price);
event AuctionSuccessful(uint256 tokenId, uint256 totalPrice, address bidder);
event AuctionCanceled(uint256 tokenId);
/// @dev Disables sending funds to this contract.
function() external {}
/// @dev A modifier to check if the given value can fit in 64-bits.
modifier canBeStoredWith64Bits(uint256 _value) {
require(_value <= (2**64 - 1));
_;
}
/// @dev A modifier to check if the given value can fit in 128-bits.
modifier canBeStoredWith128Bits(uint256 _value) {
require(_value <= (2**128 - 1));
_;
}
/**
* @dev Returns true if the claimant owns the token.
* @param _claimant An address which to query the ownership of the token.
* @param _tokenId ID of the token to query the owner of.
*/
function _owns(address _claimant, uint256 _tokenId) internal view returns (bool) {
return (nonFungibleContract.ownerOf(_tokenId) == _claimant);
}
/**
* @dev Escrows the NFT. Grants the ownership of the NFT to this contract safely.
* Throws if the escrow fails.
* @param _owner Current owner of the token.
* @param _tokenId ID of the token to escrow.
*/
function _escrow(address _owner, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(_owner, this, _tokenId);
}
/**
* @dev Transfers an NFT owned by this contract to another address safely.
* @param _receiver The receiving address of NFT.
* @param _tokenId ID of the token to transfer.
*/
function _transfer(address _receiver, uint256 _tokenId) internal {
nonFungibleContract.safeTransferFrom(this, _receiver, _tokenId);
}
/**
* @dev Adds an auction to the list of open auctions.
* @param _tokenId ID of the token to be put on auction.
* @param _auction Auction information of this token to open.
*/
function _addAuction(uint256 _tokenId, Auction _auction) internal {
tokenIdToAuction[_tokenId] = _auction;
emit AuctionCreated(
uint256(_tokenId),
uint256(_auction.price)
);
}
/// @dev Cancels the auction which the _seller wants.
function _cancelAuction(uint256 _tokenId, address _seller) internal {
_removeAuction(_tokenId);
_transfer(_seller, _tokenId);
emit AuctionCanceled(_tokenId);
}
/**
* @dev Computes the price and sends it to the seller.
* Note that this does NOT transfer the ownership of the token.
*/
function _bid(uint256 _tokenId, uint256 _bidAmount)
internal
returns (uint256)
{
// Gets a reference of the token from auction storage.
Auction storage auction = tokenIdToAuction[_tokenId];
// Checks that this auction is currently open
require(_isOnAuction(auction));
// Checks that the bid is greater than or equal to the current token price.
uint256 price = _currentPrice(auction);
require(_bidAmount >= price);
// Gets a reference of the seller before the auction gets deleted.
address seller = auction.seller;
// Removes the auction before sending the proceeds to the sender
_removeAuction(_tokenId);
// Transfers proceeds to the seller.
if (price > 0) {
uint256 auctioneerCut = _computeCut(price);
uint256 sellerProceeds = price.sub(auctioneerCut);
seller.transfer(sellerProceeds);
}
// Computes the excess funds included with the bid and transfers it back to bidder.
uint256 bidExcess = _bidAmount - price;
// Returns the exceeded funds.
msg.sender.transfer(bidExcess);
// Emits the AuctionSuccessful event.
emit AuctionSuccessful(_tokenId, price, msg.sender);
return price;
}
/**
* @dev Removes an auction from the list of open auctions.
* @param _tokenId ID of the NFT on auction to be removed.
*/
function _removeAuction(uint256 _tokenId) internal {
delete tokenIdToAuction[_tokenId];
}
/**
* @dev Returns true if the NFT is on auction.
* @param _auction An auction to check if it exists.
*/
function _isOnAuction(Auction storage _auction) internal view returns (bool) {
return (_auction.startedAt > 0);
}
/// @dev Returns the current price of an NFT on auction.
function _currentPrice(Auction storage _auction)
internal
view
returns (uint256)
{
return _auction.price;
}
/**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/
function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
} | /**
* @title Base auction contract of the Dyverse
* @author VREX Lab Co., Ltd
* @dev Contains necessary functions and variables for the auction.
* Inherits `ERC721Holder` contract which is the implementation of the `ERC721TokenReceiver`.
* This is to accept safe transfers.
*/ | NatSpecMultiLine | _computeCut | function _computeCut(uint256 _price) internal view returns (uint256) {
return _price * ownerCut / 10000;
}
| /**
* @dev Computes the owner's receiving amount from the sale.
* @param _price Sale price of the NFT.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
5606,
5731
]
} | 56,928 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Auction | contract Auction is Pausable, AuctionBase {
/**
* @dev Removes all Ether from the contract to the NFT contract.
*/
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/
function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
/**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/
function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
/**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/
function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
/**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/
function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
/**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/
function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
} | /**
* @title Auction for NFT.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | withdrawBalance | function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
| /**
* @dev Removes all Ether from the contract to the NFT contract.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
135,
403
]
} | 56,929 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Auction | contract Auction is Pausable, AuctionBase {
/**
* @dev Removes all Ether from the contract to the NFT contract.
*/
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/
function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
/**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/
function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
/**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/
function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
/**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/
function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
/**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/
function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
} | /**
* @title Auction for NFT.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | createAuction | function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
| /**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
655,
1122
]
} | 56,930 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Auction | contract Auction is Pausable, AuctionBase {
/**
* @dev Removes all Ether from the contract to the NFT contract.
*/
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/
function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
/**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/
function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
/**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/
function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
/**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/
function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
/**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/
function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
} | /**
* @title Auction for NFT.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | bid | function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
| /**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1329,
1514
]
} | 56,931 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Auction | contract Auction is Pausable, AuctionBase {
/**
* @dev Removes all Ether from the contract to the NFT contract.
*/
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/
function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
/**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/
function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
/**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/
function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
/**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/
function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
/**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/
function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
} | /**
* @title Auction for NFT.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | cancelAuction | function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
| /**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1716,
2388
]
} | 56,932 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Auction | contract Auction is Pausable, AuctionBase {
/**
* @dev Removes all Ether from the contract to the NFT contract.
*/
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/
function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
/**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/
function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
/**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/
function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
/**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/
function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
/**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/
function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
} | /**
* @title Auction for NFT.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | cancelAuctionWhenPaused | function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
| /**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2606,
2887
]
} | 56,933 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Auction | contract Auction is Pausable, AuctionBase {
/**
* @dev Removes all Ether from the contract to the NFT contract.
*/
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/
function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
/**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/
function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
/**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/
function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
/**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/
function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
/**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/
function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
} | /**
* @title Auction for NFT.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | getAuction | function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
| /**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3013,
3425
]
} | 56,934 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | Auction | contract Auction is Pausable, AuctionBase {
/**
* @dev Removes all Ether from the contract to the NFT contract.
*/
function withdrawBalance() external {
address nftAddress = address(nonFungibleContract);
require(
msg.sender == owner ||
msg.sender == nftAddress
);
nftAddress.transfer(address(this).balance);
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of the token to creat an auction, caller must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
whenNotPaused
canBeStoredWith128Bits(_price)
{
require(_owns(msg.sender, _tokenId));
_escrow(msg.sender, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Bids on an open auction, completing the auction and transferring
* ownership of the NFT if enough Ether is supplied.
* @param _tokenId - ID of token to bid on.
*/
function bid(uint256 _tokenId)
external
payable
whenNotPaused
{
_bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
}
/**
* @dev Cancels an auction and returns the NFT to the current owner.
* @param _tokenId ID of the token on auction to cancel.
* @param _seller The seller's address.
*/
function cancelAuction(uint256 _tokenId, address _seller)
external
{
// Requires that this function should only be called from the
// `cancelSaleAuction()` of NFT ownership contract. This function gets
// the _seller directly from it's arguments, so if this check doesn't
// exist, then anyone can cancel the auction! OMG!
require(msg.sender == address(nonFungibleContract));
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
address seller = auction.seller;
require(_seller == seller);
_cancelAuction(_tokenId, seller);
}
/**
* @dev Cancels an auction when the contract is paused.
* Only the owner may do this, and NFTs are returned to the seller.
* @param _tokenId ID of the token on auction to cancel.
*/
function cancelAuctionWhenPaused(uint256 _tokenId)
external
whenPaused
onlyOwner
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
_cancelAuction(_tokenId, auction.seller);
}
/**
* @dev Returns the auction information for an NFT
* @param _tokenId ID of the NFT on auction
*/
function getAuction(uint256 _tokenId)
external
view
returns
(
address seller,
uint256 price,
uint256 startedAt
) {
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return (
auction.seller,
auction.price,
auction.startedAt
);
}
/**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/
function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
} | /**
* @title Auction for NFT.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | getCurrentPrice | function getCurrentPrice(uint256 _tokenId)
external
view
returns (uint256)
{
Auction storage auction = tokenIdToAuction[_tokenId];
require(_isOnAuction(auction));
return _currentPrice(auction);
}
| /**
* @dev Returns the current price of the token on auction.
* @param _tokenId ID of the token
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3550,
3814
]
} | 56,935 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | SynthesizingAuction | contract SynthesizingAuction is Auction {
/**
* @dev Sanity check that allows us to ensure that we are pointing to the
* right auction in our `setSynthesizingAuctionAddress()` call.
*/
bool public isSynthesizingAuction = true;
/**
* @dev Creates a reference to the NFT ownership contract and checks the owner cut is valid
* @param _nftAddress Address of a deployed NFT interface contract
* @param _cut Percent cut which the owner takes on each auction, between 0-10,000.
*/
constructor(address _nftAddress, uint256 _cut) public {
require(_cut <= 10000);
ownerCut = _cut;
ERC721Basic candidateContract = ERC721Basic(_nftAddress);
nonFungibleContract = candidateContract;
}
/**
* @dev Creates and begins a new auction. Since this function is wrapped,
* requires the caller to be KydyCore contract.
* @param _tokenId ID of token to auction, sender must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
canBeStoredWith128Bits(_price)
{
require(msg.sender == address(nonFungibleContract));
_escrow(_seller, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Places a bid for synthesizing. Requires the caller
* is the KydyCore contract because all bid functions
* should be wrapped. Also returns the Kydy to the
* seller rather than the bidder.
*/
function bid(uint256 _tokenId)
external
payable
{
require(msg.sender == address(nonFungibleContract));
address seller = tokenIdToAuction[_tokenId].seller;
// _bid() checks that the token ID is valid and will throw if bid fails
_bid(_tokenId, msg.value);
// Transfers the Kydy back to the seller, and the bidder will get
// the baby Kydy.
_transfer(seller, _tokenId);
}
} | /**
* @title Auction for synthesizing
* @author VREX Lab Co., Ltd
* @notice Reset fallback function to prevent accidental fund sending to this contract.
*/ | NatSpecMultiLine | createAuction | function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
canBeStoredWith128Bits(_price)
{
require(msg.sender == address(nonFungibleContract));
_escrow(_seller, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
| /**
* @dev Creates and begins a new auction. Since this function is wrapped,
* requires the caller to be KydyCore contract.
* @param _tokenId ID of token to auction, sender must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1107,
1563
]
} | 56,936 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | SynthesizingAuction | contract SynthesizingAuction is Auction {
/**
* @dev Sanity check that allows us to ensure that we are pointing to the
* right auction in our `setSynthesizingAuctionAddress()` call.
*/
bool public isSynthesizingAuction = true;
/**
* @dev Creates a reference to the NFT ownership contract and checks the owner cut is valid
* @param _nftAddress Address of a deployed NFT interface contract
* @param _cut Percent cut which the owner takes on each auction, between 0-10,000.
*/
constructor(address _nftAddress, uint256 _cut) public {
require(_cut <= 10000);
ownerCut = _cut;
ERC721Basic candidateContract = ERC721Basic(_nftAddress);
nonFungibleContract = candidateContract;
}
/**
* @dev Creates and begins a new auction. Since this function is wrapped,
* requires the caller to be KydyCore contract.
* @param _tokenId ID of token to auction, sender must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
canBeStoredWith128Bits(_price)
{
require(msg.sender == address(nonFungibleContract));
_escrow(_seller, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Places a bid for synthesizing. Requires the caller
* is the KydyCore contract because all bid functions
* should be wrapped. Also returns the Kydy to the
* seller rather than the bidder.
*/
function bid(uint256 _tokenId)
external
payable
{
require(msg.sender == address(nonFungibleContract));
address seller = tokenIdToAuction[_tokenId].seller;
// _bid() checks that the token ID is valid and will throw if bid fails
_bid(_tokenId, msg.value);
// Transfers the Kydy back to the seller, and the bidder will get
// the baby Kydy.
_transfer(seller, _tokenId);
}
} | /**
* @title Auction for synthesizing
* @author VREX Lab Co., Ltd
* @notice Reset fallback function to prevent accidental fund sending to this contract.
*/ | NatSpecMultiLine | bid | function bid(uint256 _tokenId)
external
payable
{
require(msg.sender == address(nonFungibleContract));
address seller = tokenIdToAuction[_tokenId].seller;
// _bid() checks that the token ID is valid and will throw if bid fails
_bid(_tokenId, msg.value);
// Transfers the Kydy back to the seller, and the bidder will get
// the baby Kydy.
_transfer(seller, _tokenId);
}
| /**
* @dev Places a bid for synthesizing. Requires the caller
* is the KydyCore contract because all bid functions
* should be wrapped. Also returns the Kydy to the
* seller rather than the bidder.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1805,
2269
]
} | 56,937 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | SaleAuction | contract SaleAuction is Auction {
/**
* @dev To make sure we are addressing to the right auction.
*/
bool public isSaleAuction = true;
// Last 5 sale price of Generation 0 Kydys.
uint256[5] public lastGen0SalePrices;
// Total number of Generation 0 Kydys sold.
uint256 public gen0SaleCount;
/**
* @dev Creates a reference to the NFT ownership contract and checks the owner cut is valid
* @param _nftAddress Address of a deployed NFT interface contract
* @param _cut Percent cut which the owner takes on each auction, between 0-10,000.
*/
constructor(address _nftAddress, uint256 _cut) public {
require(_cut <= 10000);
ownerCut = _cut;
ERC721Basic candidateContract = ERC721Basic(_nftAddress);
nonFungibleContract = candidateContract;
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of token to auction, sender must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
canBeStoredWith128Bits(_price)
{
require(msg.sender == address(nonFungibleContract));
_escrow(_seller, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Updates lastSalePrice only if the seller is nonFungibleContract.
*/
function bid(uint256 _tokenId)
external
payable
{
// _bid verifies token ID
address seller = tokenIdToAuction[_tokenId].seller;
uint256 price = _bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
// If the last sale was not Generation 0 Kydy's, the lastSalePrice doesn't change.
if (seller == address(nonFungibleContract)) {
// Tracks gen0's latest sale prices.
lastGen0SalePrices[gen0SaleCount % 5] = price;
gen0SaleCount++;
}
}
/// @dev Gives the new average Generation 0 sale price after each Generation 0 Kydy sale.
function averageGen0SalePrice() external view returns (uint256) {
uint256 sum = 0;
for (uint256 i = 0; i < 5; i++) {
sum = sum.add(lastGen0SalePrices[i]);
}
return sum / 5;
}
} | /**
* @title Auction for sale of Kydys.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | createAuction | function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
canBeStoredWith128Bits(_price)
{
require(msg.sender == address(nonFungibleContract));
_escrow(_seller, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
| /**
* @dev Creates and begins a new auction.
* @param _tokenId ID of token to auction, sender must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1107,
1563
]
} | 56,938 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | SaleAuction | contract SaleAuction is Auction {
/**
* @dev To make sure we are addressing to the right auction.
*/
bool public isSaleAuction = true;
// Last 5 sale price of Generation 0 Kydys.
uint256[5] public lastGen0SalePrices;
// Total number of Generation 0 Kydys sold.
uint256 public gen0SaleCount;
/**
* @dev Creates a reference to the NFT ownership contract and checks the owner cut is valid
* @param _nftAddress Address of a deployed NFT interface contract
* @param _cut Percent cut which the owner takes on each auction, between 0-10,000.
*/
constructor(address _nftAddress, uint256 _cut) public {
require(_cut <= 10000);
ownerCut = _cut;
ERC721Basic candidateContract = ERC721Basic(_nftAddress);
nonFungibleContract = candidateContract;
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of token to auction, sender must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
canBeStoredWith128Bits(_price)
{
require(msg.sender == address(nonFungibleContract));
_escrow(_seller, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Updates lastSalePrice only if the seller is nonFungibleContract.
*/
function bid(uint256 _tokenId)
external
payable
{
// _bid verifies token ID
address seller = tokenIdToAuction[_tokenId].seller;
uint256 price = _bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
// If the last sale was not Generation 0 Kydy's, the lastSalePrice doesn't change.
if (seller == address(nonFungibleContract)) {
// Tracks gen0's latest sale prices.
lastGen0SalePrices[gen0SaleCount % 5] = price;
gen0SaleCount++;
}
}
/// @dev Gives the new average Generation 0 sale price after each Generation 0 Kydy sale.
function averageGen0SalePrice() external view returns (uint256) {
uint256 sum = 0;
for (uint256 i = 0; i < 5; i++) {
sum = sum.add(lastGen0SalePrices[i]);
}
return sum / 5;
}
} | /**
* @title Auction for sale of Kydys.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | bid | function bid(uint256 _tokenId)
external
payable
{
// _bid verifies token ID
address seller = tokenIdToAuction[_tokenId].seller;
uint256 price = _bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
// If the last sale was not Generation 0 Kydy's, the lastSalePrice doesn't change.
if (seller == address(nonFungibleContract)) {
// Tracks gen0's latest sale prices.
lastGen0SalePrices[gen0SaleCount % 5] = price;
gen0SaleCount++;
}
}
| /**
* @dev Updates lastSalePrice only if the seller is nonFungibleContract.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1663,
2237
]
} | 56,939 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | SaleAuction | contract SaleAuction is Auction {
/**
* @dev To make sure we are addressing to the right auction.
*/
bool public isSaleAuction = true;
// Last 5 sale price of Generation 0 Kydys.
uint256[5] public lastGen0SalePrices;
// Total number of Generation 0 Kydys sold.
uint256 public gen0SaleCount;
/**
* @dev Creates a reference to the NFT ownership contract and checks the owner cut is valid
* @param _nftAddress Address of a deployed NFT interface contract
* @param _cut Percent cut which the owner takes on each auction, between 0-10,000.
*/
constructor(address _nftAddress, uint256 _cut) public {
require(_cut <= 10000);
ownerCut = _cut;
ERC721Basic candidateContract = ERC721Basic(_nftAddress);
nonFungibleContract = candidateContract;
}
/**
* @dev Creates and begins a new auction.
* @param _tokenId ID of token to auction, sender must be it's owner.
* @param _price Price of the token (in wei).
* @param _seller Seller of this token.
*/
function createAuction(
uint256 _tokenId,
uint256 _price,
address _seller
)
external
canBeStoredWith128Bits(_price)
{
require(msg.sender == address(nonFungibleContract));
_escrow(_seller, _tokenId);
Auction memory auction = Auction(
_seller,
uint128(_price),
uint64(now)
);
_addAuction(_tokenId, auction);
}
/**
* @dev Updates lastSalePrice only if the seller is nonFungibleContract.
*/
function bid(uint256 _tokenId)
external
payable
{
// _bid verifies token ID
address seller = tokenIdToAuction[_tokenId].seller;
uint256 price = _bid(_tokenId, msg.value);
_transfer(msg.sender, _tokenId);
// If the last sale was not Generation 0 Kydy's, the lastSalePrice doesn't change.
if (seller == address(nonFungibleContract)) {
// Tracks gen0's latest sale prices.
lastGen0SalePrices[gen0SaleCount % 5] = price;
gen0SaleCount++;
}
}
/// @dev Gives the new average Generation 0 sale price after each Generation 0 Kydy sale.
function averageGen0SalePrice() external view returns (uint256) {
uint256 sum = 0;
for (uint256 i = 0; i < 5; i++) {
sum = sum.add(lastGen0SalePrices[i]);
}
return sum / 5;
}
} | /**
* @title Auction for sale of Kydys.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | averageGen0SalePrice | function averageGen0SalePrice() external view returns (uint256) {
uint256 sum = 0;
for (uint256 i = 0; i < 5; i++) {
sum = sum.add(lastGen0SalePrices[i]);
}
return sum / 5;
}
| /// @dev Gives the new average Generation 0 sale price after each Generation 0 Kydy sale. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2335,
2568
]
} | 56,940 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | setSaleAuctionAddress | function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
| /**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
546,
894
]
} | 56,941 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | setSynthesizingAuctionAddress | function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
| /**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1067,
1349
]
} | 56,942 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | createSaleAuction | function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
| /**
* @dev Creates a Kydy sale.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1404,
1793
]
} | 56,943 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | createSynthesizingAuction | function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
| /**
* @dev Creates a synthesis auction.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1857,
2277
]
} | 56,944 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | bidOnSynthesizingAuction | function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
| /**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2535,
3147
]
} | 56,945 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | cancelSaleAuction | function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
| /**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3315,
3860
]
} | 56,946 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | cancelSynthesizingAuction | function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
| /**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
3990,
4348
]
} | 56,947 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyAuction | contract KydyAuction is KydySynthesis {
/**
* @dev The address of the Auction contract which handles ALL sales of Kydys, both user-generated and Generation 0.
*/
SaleAuction public saleAuction;
/**
* @dev The address of another Auction contract which handles synthesis auctions.
*/
SynthesizingAuction public synthesizingAuction;
/**
* @dev Sets the address for the sales auction. Only CEO may call this function.
* @param _address The address of the sale contract.
*/
function setSaleAuctionAddress(address _address) external onlyCEO {
SaleAuction candidateContract = SaleAuction(_address);
// Verifies that the contract is correct
require(candidateContract.isSaleAuction());
// Sets the new sale auction contract address.
saleAuction = candidateContract;
}
/**
* @dev Sets the address to the synthesis auction. Only CEO may call this function.
* @param _address The address of the synthesis contract.
*/
function setSynthesizingAuctionAddress(address _address) external onlyCEO {
SynthesizingAuction candidateContract = SynthesizingAuction(_address);
require(candidateContract.isSynthesizingAuction());
synthesizingAuction = candidateContract;
}
/**
* @dev Creates a Kydy sale.
*/
function createSaleAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(!isCreating(_kydyId));
_approve(_kydyId, saleAuction);
saleAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev Creates a synthesis auction.
*/
function createSynthesizingAuction(
uint256 _kydyId,
uint256 _price
)
external
whenNotPaused
{
require(_owns(msg.sender, _kydyId));
require(isReadyToSynthesize(_kydyId));
_approve(_kydyId, synthesizingAuction);
synthesizingAuction.createAuction(
_kydyId,
_price,
msg.sender
);
}
/**
* @dev After bidding for a synthesis auction is accepted, this starts the actual synthesis process.
* @param _yangId ID of the yang Kydy on the synthesis auction.
* @param _yinId ID of the yin Kydy owned by the bidder.
*/
function bidOnSynthesizingAuction(
uint256 _yangId,
uint256 _yinId
)
external
payable
whenNotPaused
{
require(_owns(msg.sender, _yinId));
require(isReadyToSynthesize(_yinId));
require(_canSynthesizeWithViaAuction(_yinId, _yangId));
uint256 currentPrice = synthesizingAuction.getCurrentPrice(_yangId);
require (msg.value >= currentPrice + autoCreationFee);
synthesizingAuction.bid.value(msg.value - autoCreationFee)(_yangId);
_synthesizeWith(uint32(_yinId), uint32(_yangId));
}
/**
* @dev Cancels a sale and returns the Kydy back to the owner.
* @param _kydyId ID of the Kydy on sale that the owner wishes to cancel.
*/
function cancelSaleAuction(
uint256 _kydyId
)
external
whenNotPaused
{
// Checks if the Kydy is in auction.
require(_owns(saleAuction, _kydyId));
// Gets the seller of the Kydy.
(address seller,,) = saleAuction.getAuction(_kydyId);
// Checks that the caller is the real seller.
require(msg.sender == seller);
// Cancels the sale auction of this kydy by it's seller's request.
saleAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Cancels an synthesis auction.
* @param _kydyId ID of the Kydy on the synthesis auction.
*/
function cancelSynthesizingAuction(
uint256 _kydyId
)
external
whenNotPaused
{
require(_owns(synthesizingAuction, _kydyId));
(address seller,,) = synthesizingAuction.getAuction(_kydyId);
require(msg.sender == seller);
synthesizingAuction.cancelAuction(_kydyId, msg.sender);
}
/**
* @dev Transfers the balance.
*/
function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
} | /**
* @title This contract defines how sales and synthesis auctions for Kydys are created.
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | withdrawAuctionBalances | function withdrawAuctionBalances() external onlyCLevel {
saleAuction.withdrawBalance();
synthesizingAuction.withdrawBalance();
}
| /**
* @dev Transfers the balance.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
4406,
4562
]
} | 56,948 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyMinting | contract KydyMinting is KydyAuction {
// Limits of the number of Kydys that COO can create.
uint256 public constant promoCreationLimit = 888;
uint256 public constant gen0CreationLimit = 8888;
uint256 public constant gen0StartingPrice = 10 finney;
// Counts the number of Kydys that COO has created.
uint256 public promoCreatedCount;
uint256 public gen0CreatedCount;
/**
* @dev Creates promo Kydys, up to a limit. Only COO can call this function.
* @param _genes Encoded genes of the Kydy to be created.
* @param _owner Future owner of the created Kydys. COO is the default owner.
*/
function createPromoKydy(uint256 _genes, address _owner) external onlyCOO {
address kydyOwner = _owner;
if (kydyOwner == address(0)) {
kydyOwner = cooAddress;
}
require(promoCreatedCount < promoCreationLimit);
promoCreatedCount++;
_createKydy(0, 0, 0, _genes, kydyOwner);
}
/**
* @dev Creates a new gen0 Kydy with the given genes and
* creates an sale auction of it.
*/
function createGen0Auction(uint256 _genes) external onlyCOO {
require(gen0CreatedCount < gen0CreationLimit);
uint256 kydyId = _createKydy(0, 0, 0, _genes, address(this));
_approve(kydyId, saleAuction);
saleAuction.createAuction(
kydyId,
_computeNextGen0Price(),
address(this)
);
gen0CreatedCount++;
}
/**
* @dev Computes the next gen0 auction price. It will be
* the average of the past 5 prices + 50%.
*/
function _computeNextGen0Price() internal view returns (uint256) {
uint256 averagePrice = saleAuction.averageGen0SalePrice();
// Sanity check to ensure not to overflow arithmetic.
require(averagePrice == uint256(uint128(averagePrice)));
uint256 nextPrice = averagePrice.add(averagePrice / 2);
// New gen0 auction price will not be less than the
// starting price always.
if (nextPrice < gen0StartingPrice) {
nextPrice = gen0StartingPrice;
}
return nextPrice;
}
} | /**
* @title All functions related to creating Kydys
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | createPromoKydy | function createPromoKydy(uint256 _genes, address _owner) external onlyCOO {
address kydyOwner = _owner;
if (kydyOwner == address(0)) {
kydyOwner = cooAddress;
}
require(promoCreatedCount < promoCreationLimit);
promoCreatedCount++;
_createKydy(0, 0, 0, _genes, kydyOwner);
}
| /**
* @dev Creates promo Kydys, up to a limit. Only COO can call this function.
* @param _genes Encoded genes of the Kydy to be created.
* @param _owner Future owner of the created Kydys. COO is the default owner.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
656,
1008
]
} | 56,949 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyMinting | contract KydyMinting is KydyAuction {
// Limits of the number of Kydys that COO can create.
uint256 public constant promoCreationLimit = 888;
uint256 public constant gen0CreationLimit = 8888;
uint256 public constant gen0StartingPrice = 10 finney;
// Counts the number of Kydys that COO has created.
uint256 public promoCreatedCount;
uint256 public gen0CreatedCount;
/**
* @dev Creates promo Kydys, up to a limit. Only COO can call this function.
* @param _genes Encoded genes of the Kydy to be created.
* @param _owner Future owner of the created Kydys. COO is the default owner.
*/
function createPromoKydy(uint256 _genes, address _owner) external onlyCOO {
address kydyOwner = _owner;
if (kydyOwner == address(0)) {
kydyOwner = cooAddress;
}
require(promoCreatedCount < promoCreationLimit);
promoCreatedCount++;
_createKydy(0, 0, 0, _genes, kydyOwner);
}
/**
* @dev Creates a new gen0 Kydy with the given genes and
* creates an sale auction of it.
*/
function createGen0Auction(uint256 _genes) external onlyCOO {
require(gen0CreatedCount < gen0CreationLimit);
uint256 kydyId = _createKydy(0, 0, 0, _genes, address(this));
_approve(kydyId, saleAuction);
saleAuction.createAuction(
kydyId,
_computeNextGen0Price(),
address(this)
);
gen0CreatedCount++;
}
/**
* @dev Computes the next gen0 auction price. It will be
* the average of the past 5 prices + 50%.
*/
function _computeNextGen0Price() internal view returns (uint256) {
uint256 averagePrice = saleAuction.averageGen0SalePrice();
// Sanity check to ensure not to overflow arithmetic.
require(averagePrice == uint256(uint128(averagePrice)));
uint256 nextPrice = averagePrice.add(averagePrice / 2);
// New gen0 auction price will not be less than the
// starting price always.
if (nextPrice < gen0StartingPrice) {
nextPrice = gen0StartingPrice;
}
return nextPrice;
}
} | /**
* @title All functions related to creating Kydys
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | createGen0Auction | function createGen0Auction(uint256 _genes) external onlyCOO {
require(gen0CreatedCount < gen0CreationLimit);
uint256 kydyId = _createKydy(0, 0, 0, _genes, address(this));
_approve(kydyId, saleAuction);
saleAuction.createAuction(
kydyId,
_computeNextGen0Price(),
address(this)
);
gen0CreatedCount++;
}
| /**
* @dev Creates a new gen0 Kydy with the given genes and
* creates an sale auction of it.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1131,
1540
]
} | 56,950 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyMinting | contract KydyMinting is KydyAuction {
// Limits of the number of Kydys that COO can create.
uint256 public constant promoCreationLimit = 888;
uint256 public constant gen0CreationLimit = 8888;
uint256 public constant gen0StartingPrice = 10 finney;
// Counts the number of Kydys that COO has created.
uint256 public promoCreatedCount;
uint256 public gen0CreatedCount;
/**
* @dev Creates promo Kydys, up to a limit. Only COO can call this function.
* @param _genes Encoded genes of the Kydy to be created.
* @param _owner Future owner of the created Kydys. COO is the default owner.
*/
function createPromoKydy(uint256 _genes, address _owner) external onlyCOO {
address kydyOwner = _owner;
if (kydyOwner == address(0)) {
kydyOwner = cooAddress;
}
require(promoCreatedCount < promoCreationLimit);
promoCreatedCount++;
_createKydy(0, 0, 0, _genes, kydyOwner);
}
/**
* @dev Creates a new gen0 Kydy with the given genes and
* creates an sale auction of it.
*/
function createGen0Auction(uint256 _genes) external onlyCOO {
require(gen0CreatedCount < gen0CreationLimit);
uint256 kydyId = _createKydy(0, 0, 0, _genes, address(this));
_approve(kydyId, saleAuction);
saleAuction.createAuction(
kydyId,
_computeNextGen0Price(),
address(this)
);
gen0CreatedCount++;
}
/**
* @dev Computes the next gen0 auction price. It will be
* the average of the past 5 prices + 50%.
*/
function _computeNextGen0Price() internal view returns (uint256) {
uint256 averagePrice = saleAuction.averageGen0SalePrice();
// Sanity check to ensure not to overflow arithmetic.
require(averagePrice == uint256(uint128(averagePrice)));
uint256 nextPrice = averagePrice.add(averagePrice / 2);
// New gen0 auction price will not be less than the
// starting price always.
if (nextPrice < gen0StartingPrice) {
nextPrice = gen0StartingPrice;
}
return nextPrice;
}
} | /**
* @title All functions related to creating Kydys
* @author VREX Lab Co., Ltd
*/ | NatSpecMultiLine | _computeNextGen0Price | function _computeNextGen0Price() internal view returns (uint256) {
uint256 averagePrice = saleAuction.averageGen0SalePrice();
// Sanity check to ensure not to overflow arithmetic.
require(averagePrice == uint256(uint128(averagePrice)));
uint256 nextPrice = averagePrice.add(averagePrice / 2);
// New gen0 auction price will not be less than the
// starting price always.
if (nextPrice < gen0StartingPrice) {
nextPrice = gen0StartingPrice;
}
return nextPrice;
}
| /**
* @dev Computes the next gen0 auction price. It will be
* the average of the past 5 prices + 50%.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
1672,
2244
]
} | 56,951 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyCore | contract KydyCore is KydyMinting {
// This is the main Kydy contract. To keep the code upgradable and secure, we broke up the code in two different ways.
// First, we separated auction and gene combination functions into several sibling contracts. This allows us to securely
// fix bugs and upgrade contracts, if necessary. Please note that while we try to make most code open source,
// some code regarding gene combination is not open-source to make it more intriguing for users.
// However, as always, advanced users will be able to figure out how it works.
//
// We also break the core function into a few files, having one contract for each of the major functionalities of the Dyverse.
// The breakdown is as follows:
//
// - KydyBase: This contract defines the most fundamental core functionalities, including data storage and management.
//
// - KydyAccessControl: This contract manages the roles, addresses and constraints for CEO, CFO and COO.
//
// - KydyOwnership: This contract provides the methods required for basic non-fungible token transactions.
//
// - KydySynthesis: This contract contains how new baby Kydy is created via a process called the Synthesis.
//
// - KydyAuction: This contract manages auction creation and bidding.
//
// - KydyMinting: This contract defines how we create new Generation 0 Kydys. There is a limit of 8,888 Gen 0 Kydys.
// Upgraded version of the core contract.
// Should be used when the core contract is broken and an upgrade is required.
address public newContractAddress;
/// @notice Creates the main Kydy smart contract instance.
constructor() public {
// Starts with the contract is paused.
paused = true;
// The creator of the contract is the initial CEO
ceoAddress = msg.sender;
// Starts with the Kydy ID 0 which is invalid one.
// So we don't have generation-0 parent issues.
_createKydy(0, 0, 0, uint256(-1), address(0));
}
/**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/
function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
/**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/
function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
/**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/
function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
/**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/
function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
/// @dev CFO can withdraw the balance available from the contract.
function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
/// @dev Sets new tokenURI API for token metadata.
function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
// An address of Kydy Travel Plugin.
KydyTravelInterface public travelCore;
/**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/
function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
} | /**
* @title The Dyverse : A decentralized universe of Kydys, the unique 3D characters and avatars on the Blockchain.
* @author VREX Lab Co., Ltd
* @dev This is the main KydyCore contract. It keeps track of the kydys over the blockchain, and manages
* general operation of the contracts, metadata and important addresses, including defining who can withdraw
* the balance from the contract.
*/ | NatSpecMultiLine | setNewAddress | function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
| /**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2294,
2516
]
} | 56,952 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyCore | contract KydyCore is KydyMinting {
// This is the main Kydy contract. To keep the code upgradable and secure, we broke up the code in two different ways.
// First, we separated auction and gene combination functions into several sibling contracts. This allows us to securely
// fix bugs and upgrade contracts, if necessary. Please note that while we try to make most code open source,
// some code regarding gene combination is not open-source to make it more intriguing for users.
// However, as always, advanced users will be able to figure out how it works.
//
// We also break the core function into a few files, having one contract for each of the major functionalities of the Dyverse.
// The breakdown is as follows:
//
// - KydyBase: This contract defines the most fundamental core functionalities, including data storage and management.
//
// - KydyAccessControl: This contract manages the roles, addresses and constraints for CEO, CFO and COO.
//
// - KydyOwnership: This contract provides the methods required for basic non-fungible token transactions.
//
// - KydySynthesis: This contract contains how new baby Kydy is created via a process called the Synthesis.
//
// - KydyAuction: This contract manages auction creation and bidding.
//
// - KydyMinting: This contract defines how we create new Generation 0 Kydys. There is a limit of 8,888 Gen 0 Kydys.
// Upgraded version of the core contract.
// Should be used when the core contract is broken and an upgrade is required.
address public newContractAddress;
/// @notice Creates the main Kydy smart contract instance.
constructor() public {
// Starts with the contract is paused.
paused = true;
// The creator of the contract is the initial CEO
ceoAddress = msg.sender;
// Starts with the Kydy ID 0 which is invalid one.
// So we don't have generation-0 parent issues.
_createKydy(0, 0, 0, uint256(-1), address(0));
}
/**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/
function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
/**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/
function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
/**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/
function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
/**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/
function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
/// @dev CFO can withdraw the balance available from the contract.
function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
/// @dev Sets new tokenURI API for token metadata.
function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
// An address of Kydy Travel Plugin.
KydyTravelInterface public travelCore;
/**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/
function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
} | /**
* @title The Dyverse : A decentralized universe of Kydys, the unique 3D characters and avatars on the Blockchain.
* @author VREX Lab Co., Ltd
* @dev This is the main KydyCore contract. It keeps track of the kydys over the blockchain, and manages
* general operation of the contracts, metadata and important addresses, including defining who can withdraw
* the balance from the contract.
*/ | NatSpecMultiLine | function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
| /**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2655,
2833
]
} | 56,953 |
||
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyCore | contract KydyCore is KydyMinting {
// This is the main Kydy contract. To keep the code upgradable and secure, we broke up the code in two different ways.
// First, we separated auction and gene combination functions into several sibling contracts. This allows us to securely
// fix bugs and upgrade contracts, if necessary. Please note that while we try to make most code open source,
// some code regarding gene combination is not open-source to make it more intriguing for users.
// However, as always, advanced users will be able to figure out how it works.
//
// We also break the core function into a few files, having one contract for each of the major functionalities of the Dyverse.
// The breakdown is as follows:
//
// - KydyBase: This contract defines the most fundamental core functionalities, including data storage and management.
//
// - KydyAccessControl: This contract manages the roles, addresses and constraints for CEO, CFO and COO.
//
// - KydyOwnership: This contract provides the methods required for basic non-fungible token transactions.
//
// - KydySynthesis: This contract contains how new baby Kydy is created via a process called the Synthesis.
//
// - KydyAuction: This contract manages auction creation and bidding.
//
// - KydyMinting: This contract defines how we create new Generation 0 Kydys. There is a limit of 8,888 Gen 0 Kydys.
// Upgraded version of the core contract.
// Should be used when the core contract is broken and an upgrade is required.
address public newContractAddress;
/// @notice Creates the main Kydy smart contract instance.
constructor() public {
// Starts with the contract is paused.
paused = true;
// The creator of the contract is the initial CEO
ceoAddress = msg.sender;
// Starts with the Kydy ID 0 which is invalid one.
// So we don't have generation-0 parent issues.
_createKydy(0, 0, 0, uint256(-1), address(0));
}
/**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/
function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
/**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/
function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
/**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/
function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
/**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/
function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
/// @dev CFO can withdraw the balance available from the contract.
function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
/// @dev Sets new tokenURI API for token metadata.
function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
// An address of Kydy Travel Plugin.
KydyTravelInterface public travelCore;
/**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/
function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
} | /**
* @title The Dyverse : A decentralized universe of Kydys, the unique 3D characters and avatars on the Blockchain.
* @author VREX Lab Co., Ltd
* @dev This is the main KydyCore contract. It keeps track of the kydys over the blockchain, and manages
* general operation of the contracts, metadata and important addresses, including defining who can withdraw
* the balance from the contract.
*/ | NatSpecMultiLine | getKydy | function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
| /**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
2968,
3941
]
} | 56,954 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyCore | contract KydyCore is KydyMinting {
// This is the main Kydy contract. To keep the code upgradable and secure, we broke up the code in two different ways.
// First, we separated auction and gene combination functions into several sibling contracts. This allows us to securely
// fix bugs and upgrade contracts, if necessary. Please note that while we try to make most code open source,
// some code regarding gene combination is not open-source to make it more intriguing for users.
// However, as always, advanced users will be able to figure out how it works.
//
// We also break the core function into a few files, having one contract for each of the major functionalities of the Dyverse.
// The breakdown is as follows:
//
// - KydyBase: This contract defines the most fundamental core functionalities, including data storage and management.
//
// - KydyAccessControl: This contract manages the roles, addresses and constraints for CEO, CFO and COO.
//
// - KydyOwnership: This contract provides the methods required for basic non-fungible token transactions.
//
// - KydySynthesis: This contract contains how new baby Kydy is created via a process called the Synthesis.
//
// - KydyAuction: This contract manages auction creation and bidding.
//
// - KydyMinting: This contract defines how we create new Generation 0 Kydys. There is a limit of 8,888 Gen 0 Kydys.
// Upgraded version of the core contract.
// Should be used when the core contract is broken and an upgrade is required.
address public newContractAddress;
/// @notice Creates the main Kydy smart contract instance.
constructor() public {
// Starts with the contract is paused.
paused = true;
// The creator of the contract is the initial CEO
ceoAddress = msg.sender;
// Starts with the Kydy ID 0 which is invalid one.
// So we don't have generation-0 parent issues.
_createKydy(0, 0, 0, uint256(-1), address(0));
}
/**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/
function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
/**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/
function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
/**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/
function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
/**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/
function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
/// @dev CFO can withdraw the balance available from the contract.
function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
/// @dev Sets new tokenURI API for token metadata.
function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
// An address of Kydy Travel Plugin.
KydyTravelInterface public travelCore;
/**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/
function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
} | /**
* @title The Dyverse : A decentralized universe of Kydys, the unique 3D characters and avatars on the Blockchain.
* @author VREX Lab Co., Ltd
* @dev This is the main KydyCore contract. It keeps track of the kydys over the blockchain, and manages
* general operation of the contracts, metadata and important addresses, including defining who can withdraw
* the balance from the contract.
*/ | NatSpecMultiLine | unpause | function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
| /**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
4130,
4461
]
} | 56,955 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyCore | contract KydyCore is KydyMinting {
// This is the main Kydy contract. To keep the code upgradable and secure, we broke up the code in two different ways.
// First, we separated auction and gene combination functions into several sibling contracts. This allows us to securely
// fix bugs and upgrade contracts, if necessary. Please note that while we try to make most code open source,
// some code regarding gene combination is not open-source to make it more intriguing for users.
// However, as always, advanced users will be able to figure out how it works.
//
// We also break the core function into a few files, having one contract for each of the major functionalities of the Dyverse.
// The breakdown is as follows:
//
// - KydyBase: This contract defines the most fundamental core functionalities, including data storage and management.
//
// - KydyAccessControl: This contract manages the roles, addresses and constraints for CEO, CFO and COO.
//
// - KydyOwnership: This contract provides the methods required for basic non-fungible token transactions.
//
// - KydySynthesis: This contract contains how new baby Kydy is created via a process called the Synthesis.
//
// - KydyAuction: This contract manages auction creation and bidding.
//
// - KydyMinting: This contract defines how we create new Generation 0 Kydys. There is a limit of 8,888 Gen 0 Kydys.
// Upgraded version of the core contract.
// Should be used when the core contract is broken and an upgrade is required.
address public newContractAddress;
/// @notice Creates the main Kydy smart contract instance.
constructor() public {
// Starts with the contract is paused.
paused = true;
// The creator of the contract is the initial CEO
ceoAddress = msg.sender;
// Starts with the Kydy ID 0 which is invalid one.
// So we don't have generation-0 parent issues.
_createKydy(0, 0, 0, uint256(-1), address(0));
}
/**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/
function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
/**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/
function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
/**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/
function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
/**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/
function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
/// @dev CFO can withdraw the balance available from the contract.
function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
/// @dev Sets new tokenURI API for token metadata.
function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
// An address of Kydy Travel Plugin.
KydyTravelInterface public travelCore;
/**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/
function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
} | /**
* @title The Dyverse : A decentralized universe of Kydys, the unique 3D characters and avatars on the Blockchain.
* @author VREX Lab Co., Ltd
* @dev This is the main KydyCore contract. It keeps track of the kydys over the blockchain, and manages
* general operation of the contracts, metadata and important addresses, including defining who can withdraw
* the balance from the contract.
*/ | NatSpecMultiLine | withdrawBalance | function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
| /// @dev CFO can withdraw the balance available from the contract. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
4536,
4951
]
} | 56,956 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyCore | contract KydyCore is KydyMinting {
// This is the main Kydy contract. To keep the code upgradable and secure, we broke up the code in two different ways.
// First, we separated auction and gene combination functions into several sibling contracts. This allows us to securely
// fix bugs and upgrade contracts, if necessary. Please note that while we try to make most code open source,
// some code regarding gene combination is not open-source to make it more intriguing for users.
// However, as always, advanced users will be able to figure out how it works.
//
// We also break the core function into a few files, having one contract for each of the major functionalities of the Dyverse.
// The breakdown is as follows:
//
// - KydyBase: This contract defines the most fundamental core functionalities, including data storage and management.
//
// - KydyAccessControl: This contract manages the roles, addresses and constraints for CEO, CFO and COO.
//
// - KydyOwnership: This contract provides the methods required for basic non-fungible token transactions.
//
// - KydySynthesis: This contract contains how new baby Kydy is created via a process called the Synthesis.
//
// - KydyAuction: This contract manages auction creation and bidding.
//
// - KydyMinting: This contract defines how we create new Generation 0 Kydys. There is a limit of 8,888 Gen 0 Kydys.
// Upgraded version of the core contract.
// Should be used when the core contract is broken and an upgrade is required.
address public newContractAddress;
/// @notice Creates the main Kydy smart contract instance.
constructor() public {
// Starts with the contract is paused.
paused = true;
// The creator of the contract is the initial CEO
ceoAddress = msg.sender;
// Starts with the Kydy ID 0 which is invalid one.
// So we don't have generation-0 parent issues.
_createKydy(0, 0, 0, uint256(-1), address(0));
}
/**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/
function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
/**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/
function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
/**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/
function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
/**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/
function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
/// @dev CFO can withdraw the balance available from the contract.
function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
/// @dev Sets new tokenURI API for token metadata.
function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
// An address of Kydy Travel Plugin.
KydyTravelInterface public travelCore;
/**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/
function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
} | /**
* @title The Dyverse : A decentralized universe of Kydys, the unique 3D characters and avatars on the Blockchain.
* @author VREX Lab Co., Ltd
* @dev This is the main KydyCore contract. It keeps track of the kydys over the blockchain, and manages
* general operation of the contracts, metadata and important addresses, including defining who can withdraw
* the balance from the contract.
*/ | NatSpecMultiLine | setNewTokenURI | function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
| /// @dev Sets new tokenURI API for token metadata. | NatSpecSingleLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
5010,
5126
]
} | 56,957 |
|
KydyCore | contracts/lib/Strings.sol | 0xd90f5ebc01914bbd357b754956aafb199f4d1624 | Solidity | KydyCore | contract KydyCore is KydyMinting {
// This is the main Kydy contract. To keep the code upgradable and secure, we broke up the code in two different ways.
// First, we separated auction and gene combination functions into several sibling contracts. This allows us to securely
// fix bugs and upgrade contracts, if necessary. Please note that while we try to make most code open source,
// some code regarding gene combination is not open-source to make it more intriguing for users.
// However, as always, advanced users will be able to figure out how it works.
//
// We also break the core function into a few files, having one contract for each of the major functionalities of the Dyverse.
// The breakdown is as follows:
//
// - KydyBase: This contract defines the most fundamental core functionalities, including data storage and management.
//
// - KydyAccessControl: This contract manages the roles, addresses and constraints for CEO, CFO and COO.
//
// - KydyOwnership: This contract provides the methods required for basic non-fungible token transactions.
//
// - KydySynthesis: This contract contains how new baby Kydy is created via a process called the Synthesis.
//
// - KydyAuction: This contract manages auction creation and bidding.
//
// - KydyMinting: This contract defines how we create new Generation 0 Kydys. There is a limit of 8,888 Gen 0 Kydys.
// Upgraded version of the core contract.
// Should be used when the core contract is broken and an upgrade is required.
address public newContractAddress;
/// @notice Creates the main Kydy smart contract instance.
constructor() public {
// Starts with the contract is paused.
paused = true;
// The creator of the contract is the initial CEO
ceoAddress = msg.sender;
// Starts with the Kydy ID 0 which is invalid one.
// So we don't have generation-0 parent issues.
_createKydy(0, 0, 0, uint256(-1), address(0));
}
/**
* @dev Used to mark the smart contract as upgraded when an upgrade happens.
* @param _v2Address Upgraded version of the core contract.
*/
function setNewAddress(address _v2Address) external onlyCEO whenPaused {
// We'll announce if the upgrade is needed.
newContractAddress = _v2Address;
emit ContractUpgrade(_v2Address);
}
/**
* @dev Rejects all Ether being sent from unregistered addresses, so that users don't accidentally end us Ether.
*/
function() external payable {
require(
msg.sender == address(saleAuction) ||
msg.sender == address(synthesizingAuction)
);
}
/**
* @notice Returns all info about a given Kydy.
* @param _id ID of the Kydy you are enquiring about.
*/
function getKydy(uint256 _id)
external
view
returns (
bool isCreating,
bool isReady,
uint256 rechargeIndex,
uint256 nextActionAt,
uint256 synthesizingWithId,
uint256 createdTime,
uint256 yinId,
uint256 yangId,
uint256 generation,
uint256 genes
) {
Kydy storage kyd = kydys[_id];
// If this is setted to 0 then it's not at creating mode.
isCreating = (kyd.synthesizingWithId != 0);
isReady = (kyd.rechargeEndBlock <= block.number);
rechargeIndex = uint256(kyd.rechargeIndex);
nextActionAt = uint256(kyd.rechargeEndBlock);
synthesizingWithId = uint256(kyd.synthesizingWithId);
createdTime = uint256(kyd.createdTime);
yinId = uint256(kyd.yinId);
yangId = uint256(kyd.yangId);
generation = uint256(kyd.generation);
genes = kyd.genes;
}
/**
* @dev Overrides unpause() to make sure that all external contract addresses are set before unpause.
* @notice This should be public rather than external.
*/
function unpause() public onlyCEO whenPaused {
require(saleAuction != address(0));
require(synthesizingAuction != address(0));
require(geneSynthesis != address(0));
require(newContractAddress == address(0));
// Now the contract actually unpauses.
super.unpause();
}
/// @dev CFO can withdraw the balance available from the contract.
function withdrawBalance() external onlyCFO {
uint256 balance = address(this).balance;
// Subtracts all creation fees needed to be given to the bringKydyHome() callers,
// and plus 1 of margin.
uint256 subtractFees = (creatingKydys + 1) * autoCreationFee;
if (balance > subtractFees) {
cfoAddress.transfer(balance - subtractFees);
}
}
/// @dev Sets new tokenURI API for token metadata.
function setNewTokenURI(string _newTokenURI) external onlyCLevel {
tokenURIBase = _newTokenURI;
}
// An address of Kydy Travel Plugin.
KydyTravelInterface public travelCore;
/**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/
function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
} | /**
* @title The Dyverse : A decentralized universe of Kydys, the unique 3D characters and avatars on the Blockchain.
* @author VREX Lab Co., Ltd
* @dev This is the main KydyCore contract. It keeps track of the kydys over the blockchain, and manages
* general operation of the contracts, metadata and important addresses, including defining who can withdraw
* the balance from the contract.
*/ | NatSpecMultiLine | setTravelCore | function setTravelCore(address _newTravelCore) external onlyCEO whenPaused {
travelCore = KydyTravelInterface(_newTravelCore);
}
| /**
* @dev Adds the Kydy Travel Plugin contract to the Kydy Core contract.
* @notice We have a plan to add some fun features to the Dyverse.
* Your Kydy will travel all over our world while you carry on with your life.
* During their travel, they will earn some valuable coins which will then be given to you.
* Please stay tuned!
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://984728e95ce5f0c01a687d1e7a73daa4abbc56d2875bd49459d0d51c1a244805 | {
"func_code_index": [
5596,
5743
]
} | 56,958 |
|
DHOOKSTEAD | DHOOKSTEAD.sol | 0x4f9c68bc906f3c9dd059e4bcc55c0b5528d7407b | Solidity | DHOOKSTEAD | contract DHOOKSTEAD is ERC20Detailed {
using SafeMath for uint256;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply = 10000000000 * 1e18;
uint256 public basePercent = 320;
constructor() public ERC20Detailed("Hookstead Capital Shares", "BCSX", 18) {
_mint(msg.sender, _totalSupply);
}
/// @return Total number of tokens in circulation
function totalSupply() public view returns(uint256) {
return _totalSupply;
}
function balanceOf(address owner) public view returns(uint256) {
return _balances[owner];
}
function allowance(address owner, address spender) public view returns(uint256) {
return _allowances[owner][spender];
}
function findBurnAmount(uint256 value) public view returns(uint256) {
if (value == 1) {
return 0;
}
uint256 roundValue = value.ceil(basePercent);
//Gas optimized
uint256 burnAmount = roundValue.mul(100).div(32000);
return burnAmount;
}
function transfer(address to, uint256 value) public returns(bool) {
require(to != address(0));
uint256 tokensToBurn = findBurnAmount(value);
uint256 tokensToTransfer = value.sub(tokensToBurn);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(tokensToTransfer);
_totalSupply = _totalSupply.sub(tokensToBurn);
emit Transfer(msg.sender, to, tokensToTransfer);
emit Transfer(msg.sender, address(0), tokensToBurn);
return true;
}
function approve(address spender, uint256 value) public returns(bool) {
require(spender != address(0));
_allowances[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) public returns(bool) {
require(value <= _allowances[from][msg.sender]);
require(to != address(0));
_balances[from] = _balances[from].sub(value);
uint256 tokensToBurn = findBurnAmount(value);
uint256 tokensToTransfer = value.sub(tokensToBurn);
_balances[to] = _balances[to].add(tokensToTransfer);
_totalSupply = _totalSupply.sub(tokensToBurn);
_allowances[from][msg.sender] = _allowances[from][msg.sender].sub(value);
emit Transfer(from, to, tokensToTransfer);
emit Transfer(from, address(0), tokensToBurn);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public returns(bool) {
require(spender != address(0));
_allowances[msg.sender][spender] = (_allowances[msg.sender][spender].add(addedValue));
emit Approval(msg.sender, spender, _allowances[msg.sender][spender]);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns(bool) {
require(spender != address(0));
_allowances[msg.sender][spender] = (_allowances[msg.sender][spender].sub(subtractedValue));
emit Approval(msg.sender, spender, _allowances[msg.sender][spender]);
return true;
}
function _mint(address account, uint256 amount) internal {
require(amount != 0);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function burn(uint256 amount) external {
_burn(msg.sender, amount);
}
function _burn(address account, uint256 amount) internal {
require(amount != 0);
_totalSupply = _totalSupply.sub(amount);
_balances[account] = _balances[account].sub(amount);
emit Transfer(account, address(0), amount);
}
function burnFrom(address account, uint256 amount) external {
require(amount <= _allowances[account][msg.sender]);
_allowances[account][msg.sender] = _allowances[account][msg.sender].sub(amount);
_burn(account, amount);
}
} | totalSupply | function totalSupply() public view returns(uint256) {
return _totalSupply;
}
| /// @return Total number of tokens in circulation | NatSpecSingleLine | v0.5.17+commit.d19bba13 | None | bzzr://6672ebe7cf7e5d89fff9e0ee3956256948f79aafa2372e548f210923bc33bc97 | {
"func_code_index": [
493,
588
]
} | 56,959 |
||
PluralMoon | PluralMoon.sol | 0xc2870a99f278c8885deba9d50388daf737f03669 | 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.12+commit.27d51765 | None | ipfs://fe3ab263a58412d5e5c0b7e4e8f233a36e230fdaed5105efb348857a4b7015f1 | {
"func_code_index": [
94,
154
]
} | 56,960 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.