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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | Ownable | contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
} | /**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/ | NatSpecMultiLine | _transferOwnership | function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1759,
1988
]
} | 55,561 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC165 | interface IERC165 {
/**
* @notice Query if a contract implements an interface
* @dev Interface identification is specified in ERC-165. This function
* uses less than 30,000 gas
* @param _interfaceId The interface identifier, as specified in ERC-165
*/
function supportsInterface(bytes4 _interfaceId)
external
view
returns (bool);
} | /**
* @title ERC165
* @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 _interfaceId)
external
view
returns (bool);
| /**
* @notice Query if a contract implements an interface
* @dev Interface identification is specified in ERC-165. This function
* uses less than 30,000 gas
* @param _interfaceId The interface identifier, as specified in ERC-165
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
282,
375
]
} | 55,562 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath#mul: OVERFLOW");
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath#div: DIVISION_BY_ZERO");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath#sub: UNDERFLOW");
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath#add: OVERFLOW");
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath#mod: DIVISION_BY_ZERO");
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath#mul: OVERFLOW");
return c;
}
| /**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
97,
506
]
} | 55,563 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath#mul: OVERFLOW");
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath#div: DIVISION_BY_ZERO");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath#sub: UNDERFLOW");
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath#add: OVERFLOW");
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath#mod: DIVISION_BY_ZERO");
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath#div: DIVISION_BY_ZERO");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
626,
936
]
} | 55,564 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath#mul: OVERFLOW");
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath#div: DIVISION_BY_ZERO");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath#sub: UNDERFLOW");
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath#add: OVERFLOW");
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath#mod: DIVISION_BY_ZERO");
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath#sub: UNDERFLOW");
uint256 c = a - b;
return c;
}
| /**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1059,
1219
]
} | 55,565 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath#mul: OVERFLOW");
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath#div: DIVISION_BY_ZERO");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath#sub: UNDERFLOW");
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath#add: OVERFLOW");
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath#mod: DIVISION_BY_ZERO");
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath#add: OVERFLOW");
return c;
}
| /**
* @dev Adds two unsigned integers, reverts on overflow.
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1292,
1452
]
} | 55,566 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two unsigned integers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath#mul: OVERFLOW");
return c;
}
/**
* @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath#div: DIVISION_BY_ZERO");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath#sub: UNDERFLOW");
uint256 c = a - b;
return c;
}
/**
* @dev Adds two unsigned integers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath#add: OVERFLOW");
return c;
}
/**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath#mod: DIVISION_BY_ZERO");
return a % b;
}
} | /**
* @title SafeMath
* @dev Unsigned math operations with safety checks that revert on error
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath#mod: DIVISION_BY_ZERO");
return a % b;
}
| /**
* @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1595,
1742
]
} | 55,567 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155TokenReceiver | interface IERC1155TokenReceiver {
/**
* @notice Handle the receipt of a single ERC1155 token type
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeTransferFrom` after the balance has been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value MUST result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeTransferFrom` function
* @param _from The address which previously owned the token
* @param _id The id of the token being transferred
* @param _amount The amount of tokens being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
*/
function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _amount, bytes calldata _data) external returns(bytes4);
/**
* @notice Handle the receipt of multiple ERC1155 token types
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeBatchTransferFrom` after the balances have been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value WILL result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeBatchTransferFrom` function
* @param _from The address which previously owned the token
* @param _ids An array containing ids of each token being transferred
* @param _amounts An array containing amounts of each token being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
*/
function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external returns(bytes4);
/**
* @notice Indicates whether a contract implements the `ERC1155TokenReceiver` functions and so can accept ERC1155 token types.
* @param interfaceID The ERC-165 interface ID that is queried for support.s
* @dev This function MUST return true if it implements the ERC1155TokenReceiver interface and ERC-165 interface.
* This function MUST NOT consume more than 5,000 gas.
* @return Wheter ERC-165 or ERC1155TokenReceiver interfaces are supported.
*/
function supportsInterface(bytes4 interfaceID) external view returns (bool);
} | /**
* @dev ERC-1155 interface for accepting safe transfers.
*/ | NatSpecMultiLine | onERC1155Received | function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _amount, bytes calldata _data) external returns(bytes4);
| /**
* @notice Handle the receipt of a single ERC1155 token type
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeTransferFrom` after the balance has been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value MUST result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeTransferFrom` function
* @param _from The address which previously owned the token
* @param _id The id of the token being transferred
* @param _amount The amount of tokens being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
946,
1086
]
} | 55,568 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155TokenReceiver | interface IERC1155TokenReceiver {
/**
* @notice Handle the receipt of a single ERC1155 token type
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeTransferFrom` after the balance has been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value MUST result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeTransferFrom` function
* @param _from The address which previously owned the token
* @param _id The id of the token being transferred
* @param _amount The amount of tokens being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
*/
function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _amount, bytes calldata _data) external returns(bytes4);
/**
* @notice Handle the receipt of multiple ERC1155 token types
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeBatchTransferFrom` after the balances have been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value WILL result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeBatchTransferFrom` function
* @param _from The address which previously owned the token
* @param _ids An array containing ids of each token being transferred
* @param _amounts An array containing amounts of each token being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
*/
function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external returns(bytes4);
/**
* @notice Indicates whether a contract implements the `ERC1155TokenReceiver` functions and so can accept ERC1155 token types.
* @param interfaceID The ERC-165 interface ID that is queried for support.s
* @dev This function MUST return true if it implements the ERC1155TokenReceiver interface and ERC-165 interface.
* This function MUST NOT consume more than 5,000 gas.
* @return Wheter ERC-165 or ERC1155TokenReceiver interfaces are supported.
*/
function supportsInterface(bytes4 interfaceID) external view returns (bool);
} | /**
* @dev ERC-1155 interface for accepting safe transfers.
*/ | NatSpecMultiLine | onERC1155BatchReceived | function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external returns(bytes4);
| /**
* @notice Handle the receipt of multiple ERC1155 token types
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeBatchTransferFrom` after the balances have been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value WILL result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeBatchTransferFrom` function
* @param _from The address which previously owned the token
* @param _ids An array containing ids of each token being transferred
* @param _amounts An array containing amounts of each token being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
2060,
2229
]
} | 55,569 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155TokenReceiver | interface IERC1155TokenReceiver {
/**
* @notice Handle the receipt of a single ERC1155 token type
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeTransferFrom` after the balance has been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value MUST result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeTransferFrom` function
* @param _from The address which previously owned the token
* @param _id The id of the token being transferred
* @param _amount The amount of tokens being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
*/
function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _amount, bytes calldata _data) external returns(bytes4);
/**
* @notice Handle the receipt of multiple ERC1155 token types
* @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeBatchTransferFrom` after the balances have been updated
* This function MAY throw to revert and reject the transfer
* Return of other amount than the magic value WILL result in the transaction being reverted
* Note: The token contract address is always the message sender
* @param _operator The address which called the `safeBatchTransferFrom` function
* @param _from The address which previously owned the token
* @param _ids An array containing ids of each token being transferred
* @param _amounts An array containing amounts of each token being transferred
* @param _data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
*/
function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external returns(bytes4);
/**
* @notice Indicates whether a contract implements the `ERC1155TokenReceiver` functions and so can accept ERC1155 token types.
* @param interfaceID The ERC-165 interface ID that is queried for support.s
* @dev This function MUST return true if it implements the ERC1155TokenReceiver interface and ERC-165 interface.
* This function MUST NOT consume more than 5,000 gas.
* @return Wheter ERC-165 or ERC1155TokenReceiver interfaces are supported.
*/
function supportsInterface(bytes4 interfaceID) external view returns (bool);
} | /**
* @dev ERC-1155 interface for accepting safe transfers.
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 interfaceID) external view returns (bool);
| /**
* @notice Indicates whether a contract implements the `ERC1155TokenReceiver` functions and so can accept ERC1155 token types.
* @param interfaceID The ERC-165 interface ID that is queried for support.s
* @dev This function MUST return true if it implements the ERC1155TokenReceiver interface and ERC-165 interface.
* This function MUST NOT consume more than 5,000 gas.
* @return Wheter ERC-165 or ERC1155TokenReceiver interfaces are supported.
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
2708,
2786
]
} | 55,570 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155 | interface IERC1155 {
// Events
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of a token ID with no initial balance, the contract SHOULD emit the TransferSingle event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
/**
* @dev MUST emit when an approval is updated
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
* @dev MUST emit when the URI is updated for a token ID
* URIs are defined in RFC 3986
* The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema"
*/
event URI(string _amount, uint256 indexed _id);
/**
* @notice Transfers amount of an _id from the _from address to the _to address specified
* @dev MUST emit TransferSingle event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if balance of sender for token `_id` is lower than the `_amount` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes calldata _data) external;
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @dev MUST emit TransferBatch event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if length of `_ids` is not the same as length of `_amounts`
* MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_amounts` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* Transfers and events MUST occur in the array order they were submitted (_ids[0] before _ids[1], etc)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external;
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @dev MUST emit the ApprovalForAll event on success
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);
} | safeTransferFrom | function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes calldata _data) external;
| /**
* @notice Transfers amount of an _id from the _from address to the _to address specified
* @dev MUST emit TransferSingle event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if balance of sender for token `_id` is lower than the `_amount` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
3103,
3220
]
} | 55,571 |
||||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155 | interface IERC1155 {
// Events
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of a token ID with no initial balance, the contract SHOULD emit the TransferSingle event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
/**
* @dev MUST emit when an approval is updated
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
* @dev MUST emit when the URI is updated for a token ID
* URIs are defined in RFC 3986
* The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema"
*/
event URI(string _amount, uint256 indexed _id);
/**
* @notice Transfers amount of an _id from the _from address to the _to address specified
* @dev MUST emit TransferSingle event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if balance of sender for token `_id` is lower than the `_amount` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes calldata _data) external;
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @dev MUST emit TransferBatch event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if length of `_ids` is not the same as length of `_amounts`
* MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_amounts` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* Transfers and events MUST occur in the array order they were submitted (_ids[0] before _ids[1], etc)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external;
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @dev MUST emit the ApprovalForAll event on success
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);
} | safeBatchTransferFrom | function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external;
| /**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @dev MUST emit TransferBatch event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if length of `_ids` is not the same as length of `_amounts`
* MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_amounts` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* Transfers and events MUST occur in the array order they were submitted (_ids[0] before _ids[1], etc)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
4397,
4543
]
} | 55,572 |
||||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155 | interface IERC1155 {
// Events
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of a token ID with no initial balance, the contract SHOULD emit the TransferSingle event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
/**
* @dev MUST emit when an approval is updated
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
* @dev MUST emit when the URI is updated for a token ID
* URIs are defined in RFC 3986
* The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema"
*/
event URI(string _amount, uint256 indexed _id);
/**
* @notice Transfers amount of an _id from the _from address to the _to address specified
* @dev MUST emit TransferSingle event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if balance of sender for token `_id` is lower than the `_amount` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes calldata _data) external;
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @dev MUST emit TransferBatch event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if length of `_ids` is not the same as length of `_amounts`
* MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_amounts` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* Transfers and events MUST occur in the array order they were submitted (_ids[0] before _ids[1], etc)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external;
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @dev MUST emit the ApprovalForAll event on success
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);
} | balanceOf | function balanceOf(address _owner, uint256 _id) external view returns (uint256);
| /**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
4768,
4850
]
} | 55,573 |
||||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155 | interface IERC1155 {
// Events
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of a token ID with no initial balance, the contract SHOULD emit the TransferSingle event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
/**
* @dev MUST emit when an approval is updated
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
* @dev MUST emit when the URI is updated for a token ID
* URIs are defined in RFC 3986
* The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema"
*/
event URI(string _amount, uint256 indexed _id);
/**
* @notice Transfers amount of an _id from the _from address to the _to address specified
* @dev MUST emit TransferSingle event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if balance of sender for token `_id` is lower than the `_amount` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes calldata _data) external;
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @dev MUST emit TransferBatch event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if length of `_ids` is not the same as length of `_amounts`
* MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_amounts` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* Transfers and events MUST occur in the array order they were submitted (_ids[0] before _ids[1], etc)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external;
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @dev MUST emit the ApprovalForAll event on success
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);
} | balanceOfBatch | function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
| /**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5128,
5248
]
} | 55,574 |
||||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155 | interface IERC1155 {
// Events
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of a token ID with no initial balance, the contract SHOULD emit the TransferSingle event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
/**
* @dev MUST emit when an approval is updated
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
* @dev MUST emit when the URI is updated for a token ID
* URIs are defined in RFC 3986
* The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema"
*/
event URI(string _amount, uint256 indexed _id);
/**
* @notice Transfers amount of an _id from the _from address to the _to address specified
* @dev MUST emit TransferSingle event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if balance of sender for token `_id` is lower than the `_amount` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes calldata _data) external;
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @dev MUST emit TransferBatch event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if length of `_ids` is not the same as length of `_amounts`
* MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_amounts` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* Transfers and events MUST occur in the array order they were submitted (_ids[0] before _ids[1], etc)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external;
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @dev MUST emit the ApprovalForAll event on success
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);
} | setApprovalForAll | function setApprovalForAll(address _operator, bool _approved) external;
| /**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @dev MUST emit the ApprovalForAll event on success
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5577,
5650
]
} | 55,575 |
||||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | IERC1155 | interface IERC1155 {
// Events
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of a token ID with no initial balance, the contract SHOULD emit the TransferSingle event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
/**
* @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred, including zero amount transfers as well as minting or burning
* Operator MUST be msg.sender
* When minting/creating tokens, the `_from` field MUST be set to `0x0`
* When burning/destroying tokens, the `_to` field MUST be set to `0x0`
* The total amount transferred from address 0x0 minus the total amount transferred to 0x0 may be used by clients and exchanges to be added to the "circulating supply" for a given token ID
* To broadcast the existence of multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event from `0x0` to `0x0`, with the token creator as `_operator`, and a `_amount` of 0
*/
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
/**
* @dev MUST emit when an approval is updated
*/
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
/**
* @dev MUST emit when the URI is updated for a token ID
* URIs are defined in RFC 3986
* The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema"
*/
event URI(string _amount, uint256 indexed _id);
/**
* @notice Transfers amount of an _id from the _from address to the _to address specified
* @dev MUST emit TransferSingle event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if balance of sender for token `_id` is lower than the `_amount` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155Received` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes calldata _data) external;
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @dev MUST emit TransferBatch event on success
* Caller must be approved to manage the _from account's tokens (see isApprovedForAll)
* MUST throw if `_to` is the zero address
* MUST throw if length of `_ids` is not the same as length of `_amounts`
* MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_amounts` sent
* MUST throw on any other error
* When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0). If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return amount is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* Transfers and events MUST occur in the array order they were submitted (_ids[0] before _ids[1], etc)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external;
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id) external view returns (uint256);
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] calldata _owners, uint256[] calldata _ids) external view returns (uint256[] memory);
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @dev MUST emit the ApprovalForAll event on success
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved) external;
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);
} | isApprovedForAll | function isApprovedForAll(address _owner, address _operator) external view returns (bool isOperator);
| /**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5909,
6012
]
} | 55,576 |
||||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | Address | library Address {
/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param account address of the account to check
* @return whether the target address is a contract
*/
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
assembly { codehash := extcodehash(account) }
return (codehash != 0x0 && codehash != accountHash);
}
} | /**
* Utility library of inline functions on addresses
*/ | NatSpecMultiLine | isContract | function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
assembly { codehash := extcodehash(account) }
return (codehash != 0x0 && codehash != accountHash);
}
| /**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param account address of the account to check
* @return whether the target address is a contract
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
361,
1024
]
} | 55,577 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | safeTransferFrom | function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
| /**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1445,
1983
]
} | 55,578 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | safeBatchTransferFrom | function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
| /**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
2364,
2868
]
} | 55,579 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | _safeTransferFrom | function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
| /**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
3256,
3625
]
} | 55,580 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | _callonERC1155Received | function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
| /**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
3731,
4154
]
} | 55,581 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | _safeBatchTransferFrom | function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
| /**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
4449,
5121
]
} | 55,582 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | _callonERC1155BatchReceived | function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
| /**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5232,
5702
]
} | 55,583 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | setApprovalForAll | function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
| /**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
6097,
6320
]
} | 55,584 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | isApprovedForAll | function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
| /**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
6569,
6722
]
} | 55,585 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
| /**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
7060,
7185
]
} | 55,586 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | balanceOfBatch | function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
| /**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
7463,
7951
]
} | 55,587 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155 | contract ERC1155 is IERC165 {
using SafeMath for uint256;
using Address for address;
/***********************************|
| Variables and Events |
|__________________________________*/
// onReceive function signatures
bytes4 constant internal ERC1155_RECEIVED_VALUE = 0xf23a6e61;
bytes4 constant internal ERC1155_BATCH_RECEIVED_VALUE = 0xbc197c81;
// Objects balances
mapping (address => mapping(uint256 => uint256)) internal balances;
// Operator Functions
mapping (address => mapping(address => bool)) internal operators;
// Events
event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _amount);
event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _amounts);
event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved);
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Public Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeTransferFrom: INVALID_OPERATOR");
require(_to != address(0),"ERC1155#safeTransferFrom: INVALID_RECIPIENT");
// require(_amount >= balances[_from][_id]) is not necessary since checked with safemath operations
_safeTransferFrom(_from, _to, _id, _amount);
_callonERC1155Received(_from, _to, _id, _amount, _data);
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
* @param _data Additional data with no specified format, sent in call to `_to`
*/
function safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
public
{
// Requirements
require((msg.sender == _from) || isApprovedForAll(_from, msg.sender), "ERC1155#safeBatchTransferFrom: INVALID_OPERATOR");
require(_to != address(0), "ERC1155#safeBatchTransferFrom: INVALID_RECIPIENT");
_safeBatchTransferFrom(_from, _to, _ids, _amounts);
_callonERC1155BatchReceived(_from, _to, _ids, _amounts, _data);
}
/***********************************|
| Internal Transfer Functions |
|__________________________________*/
/**
* @notice Transfers amount amount of an _id from the _from address to the _to address specified
* @param _from Source address
* @param _to Target address
* @param _id ID of the token type
* @param _amount Transfered amount
*/
function _safeTransferFrom(address _from, address _to, uint256 _id, uint256 _amount)
internal
{
// Update balances
balances[_from][_id] = balances[_from][_id].sub(_amount); // Subtract amount
balances[_to][_id] = balances[_to][_id].add(_amount); // Add amount
// Emit event
emit TransferSingle(msg.sender, _from, _to, _id, _amount);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155Received(...)
*/
function _callonERC1155Received(address _from, address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Check if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155Received(msg.sender, _from, _id, _amount, _data);
require(retval == ERC1155_RECEIVED_VALUE, "ERC1155#_callonERC1155Received: INVALID_ON_RECEIVE_MESSAGE");
}
}
/**
* @notice Send multiple types of Tokens from the _from address to the _to address (with safety call)
* @param _from Source addresses
* @param _to Target addresses
* @param _ids IDs of each token type
* @param _amounts Transfer amounts per token type
*/
function _safeBatchTransferFrom(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155#_safeBatchTransferFrom: INVALID_ARRAYS_LENGTH");
// Number of transfer to execute
uint256 nTransfer = _ids.length;
// Executing all transfers
for (uint256 i = 0; i < nTransfer; i++) {
// Update storage balance of previous bin
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit event
emit TransferBatch(msg.sender, _from, _to, _ids, _amounts);
}
/**
* @notice Verifies if receiver is contract and if so, calls (_to).onERC1155BatchReceived(...)
*/
function _callonERC1155BatchReceived(address _from, address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
// Pass data if recipient is contract
if (_to.isContract()) {
bytes4 retval = IERC1155TokenReceiver(_to).onERC1155BatchReceived(msg.sender, _from, _ids, _amounts, _data);
require(retval == ERC1155_BATCH_RECEIVED_VALUE, "ERC1155#_callonERC1155BatchReceived: INVALID_ON_RECEIVE_MESSAGE");
}
}
/***********************************|
| Operator Functions |
|__________________________________*/
/**
* @notice Enable or disable approval for a third party ("operator") to manage all of caller's tokens
* @param _operator Address to add to the set of authorized operators
* @param _approved True if the operator is approved, false to revoke approval
*/
function setApprovalForAll(address _operator, bool _approved)
external
{
// Update operator status
operators[msg.sender][_operator] = _approved;
emit ApprovalForAll(msg.sender, _operator, _approved);
}
/**
* @notice Queries the approval status of an operator for a given owner
* @param _owner The owner of the Tokens
* @param _operator Address of authorized operator
* @return True if the operator is approved, false if not
*/
function isApprovedForAll(address _owner, address _operator)
public view returns (bool isOperator)
{
return operators[_owner][_operator];
}
/***********************************|
| Balance Functions |
|__________________________________*/
/**
* @notice Get the balance of an account's Tokens
* @param _owner The address of the token holder
* @param _id ID of the Token
* @return The _owner's balance of the Token type requested
*/
function balanceOf(address _owner, uint256 _id)
public view returns (uint256)
{
return balances[_owner][_id];
}
/**
* @notice Get the balance of multiple account/token pairs
* @param _owners The addresses of the token holders
* @param _ids ID of the Tokens
* @return The _owner's balance of the Token types requested (i.e. balance for each (owner, id) pair)
*/
function balanceOfBatch(address[] memory _owners, uint256[] memory _ids)
public view returns (uint256[] memory)
{
require(_owners.length == _ids.length, "ERC1155#balanceOfBatch: INVALID_ARRAY_LENGTH");
// Variables
uint256[] memory batchBalances = new uint256[](_owners.length);
// Iterate over each owner and token ID
for (uint256 i = 0; i < _owners.length; i++) {
batchBalances[i] = balances[_owners[i]][_ids[i]];
}
return batchBalances;
}
/***********************************|
| ERC165 Functions |
|__________________________________*/
/**
* INTERFACE_SIGNATURE_ERC165 = bytes4(keccak256("supportsInterface(bytes4)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC165 = 0x01ffc9a7;
/**
* INTERFACE_SIGNATURE_ERC1155 =
* bytes4(keccak256("safeTransferFrom(address,address,uint256,uint256,bytes)")) ^
* bytes4(keccak256("safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)")) ^
* bytes4(keccak256("balanceOf(address,uint256)")) ^
* bytes4(keccak256("balanceOfBatch(address[],uint256[])")) ^
* bytes4(keccak256("setApprovalForAll(address,bool)")) ^
* bytes4(keccak256("isApprovedForAll(address,address)"));
*/
bytes4 constant private INTERFACE_SIGNATURE_ERC1155 = 0xd9b67a26;
/**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
} | /**
* @dev Implementation of Multi-Token Standard contract
*/ | NatSpecMultiLine | supportsInterface | function supportsInterface(bytes4 _interfaceID) external view returns (bool) {
if (_interfaceID == INTERFACE_SIGNATURE_ERC165 ||
_interfaceID == INTERFACE_SIGNATURE_ERC1155) {
return true;
}
return false;
}
| /**
* @notice Query if a contract implements an interface
* @param _interfaceID The interface identifier, as specified in ERC-165
* @return `true` if the contract implements `_interfaceID` and
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
8981,
9217
]
} | 55,588 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Metadata | contract ERC1155Metadata {
// URI's default URI prefix
string internal baseMetadataURI;
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Metadata Public Function s |
|__________________________________*/
/**
* @notice A distinct Uniform Resource Identifier (URI) for a given token.
* @dev URIs are defined in RFC 3986.
* URIs are assumed to be deterministically generated based on token ID
* Token IDs are assumed to be represented in their hex format in URIs
* @return URI string
*/
function uri(uint256 _id) public view returns (string memory) {
return string(abi.encodePacked(baseMetadataURI, _uint2str(_id), ".json"));
}
/***********************************|
| Metadata Internal Functions |
|__________________________________*/
/**
* @notice Will emit default URI log event for corresponding token _id
* @param _tokenIDs Array of IDs of tokens to log default URI
*/
function _logURIs(uint256[] memory _tokenIDs) internal {
string memory baseURL = baseMetadataURI;
string memory tokenURI;
for (uint256 i = 0; i < _tokenIDs.length; i++) {
tokenURI = string(abi.encodePacked(baseURL, _uint2str(_tokenIDs[i]), ".json"));
emit URI(tokenURI, _tokenIDs[i]);
}
}
/**
* @notice Will emit a specific URI log event for corresponding token
* @param _tokenIDs IDs of the token corresponding to the _uris logged
* @param _URIs The URIs of the specified _tokenIDs
*/
function _logURIs(uint256[] memory _tokenIDs, string[] memory _URIs) internal {
require(_tokenIDs.length == _URIs.length, "ERC1155Metadata#_logURIs: INVALID_ARRAYS_LENGTH");
for (uint256 i = 0; i < _tokenIDs.length; i++) {
emit URI(_URIs[i], _tokenIDs[i]);
}
}
/**
* @notice Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function _setBaseMetadataURI(string memory _newBaseMetadataURI) internal {
baseMetadataURI = _newBaseMetadataURI;
}
/***********************************|
| Utility Internal Functions |
|__________________________________*/
/**
* @notice Convert uint256 to string
* @param _i Unsigned integer to convert to string
*/
function _uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 ii = _i;
uint256 len;
// Get number of bytes
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len - 1;
// Get each individual ASCII
while (ii != 0) {
bstr[k--] = byte(uint8(48 + ii % 10));
ii /= 10;
}
// Convert to string
return string(bstr);
}
} | /**
* @notice Contract that handles metadata related methods.
* @dev Methods assume a deterministic generation of URI based on token IDs.
* Methods also assume that URI uses hex representation of token IDs.
*/ | NatSpecMultiLine | uri | function uri(uint256 _id) public view returns (string memory) {
return string(abi.encodePacked(baseMetadataURI, _uint2str(_id), ".json"));
}
| /**
* @notice A distinct Uniform Resource Identifier (URI) for a given token.
* @dev URIs are defined in RFC 3986.
* URIs are assumed to be deterministically generated based on token ID
* Token IDs are assumed to be represented in their hex format in URIs
* @return URI string
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
573,
721
]
} | 55,589 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Metadata | contract ERC1155Metadata {
// URI's default URI prefix
string internal baseMetadataURI;
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Metadata Public Function s |
|__________________________________*/
/**
* @notice A distinct Uniform Resource Identifier (URI) for a given token.
* @dev URIs are defined in RFC 3986.
* URIs are assumed to be deterministically generated based on token ID
* Token IDs are assumed to be represented in their hex format in URIs
* @return URI string
*/
function uri(uint256 _id) public view returns (string memory) {
return string(abi.encodePacked(baseMetadataURI, _uint2str(_id), ".json"));
}
/***********************************|
| Metadata Internal Functions |
|__________________________________*/
/**
* @notice Will emit default URI log event for corresponding token _id
* @param _tokenIDs Array of IDs of tokens to log default URI
*/
function _logURIs(uint256[] memory _tokenIDs) internal {
string memory baseURL = baseMetadataURI;
string memory tokenURI;
for (uint256 i = 0; i < _tokenIDs.length; i++) {
tokenURI = string(abi.encodePacked(baseURL, _uint2str(_tokenIDs[i]), ".json"));
emit URI(tokenURI, _tokenIDs[i]);
}
}
/**
* @notice Will emit a specific URI log event for corresponding token
* @param _tokenIDs IDs of the token corresponding to the _uris logged
* @param _URIs The URIs of the specified _tokenIDs
*/
function _logURIs(uint256[] memory _tokenIDs, string[] memory _URIs) internal {
require(_tokenIDs.length == _URIs.length, "ERC1155Metadata#_logURIs: INVALID_ARRAYS_LENGTH");
for (uint256 i = 0; i < _tokenIDs.length; i++) {
emit URI(_URIs[i], _tokenIDs[i]);
}
}
/**
* @notice Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function _setBaseMetadataURI(string memory _newBaseMetadataURI) internal {
baseMetadataURI = _newBaseMetadataURI;
}
/***********************************|
| Utility Internal Functions |
|__________________________________*/
/**
* @notice Convert uint256 to string
* @param _i Unsigned integer to convert to string
*/
function _uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 ii = _i;
uint256 len;
// Get number of bytes
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len - 1;
// Get each individual ASCII
while (ii != 0) {
bstr[k--] = byte(uint8(48 + ii % 10));
ii /= 10;
}
// Convert to string
return string(bstr);
}
} | /**
* @notice Contract that handles metadata related methods.
* @dev Methods assume a deterministic generation of URI based on token IDs.
* Methods also assume that URI uses hex representation of token IDs.
*/ | NatSpecMultiLine | _logURIs | function _logURIs(uint256[] memory _tokenIDs) internal {
string memory baseURL = baseMetadataURI;
string memory tokenURI;
for (uint256 i = 0; i < _tokenIDs.length; i++) {
tokenURI = string(abi.encodePacked(baseURL, _uint2str(_tokenIDs[i]), ".json"));
emit URI(tokenURI, _tokenIDs[i]);
}
}
| /**
* @notice Will emit default URI log event for corresponding token _id
* @param _tokenIDs Array of IDs of tokens to log default URI
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
994,
1315
]
} | 55,590 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Metadata | contract ERC1155Metadata {
// URI's default URI prefix
string internal baseMetadataURI;
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Metadata Public Function s |
|__________________________________*/
/**
* @notice A distinct Uniform Resource Identifier (URI) for a given token.
* @dev URIs are defined in RFC 3986.
* URIs are assumed to be deterministically generated based on token ID
* Token IDs are assumed to be represented in their hex format in URIs
* @return URI string
*/
function uri(uint256 _id) public view returns (string memory) {
return string(abi.encodePacked(baseMetadataURI, _uint2str(_id), ".json"));
}
/***********************************|
| Metadata Internal Functions |
|__________________________________*/
/**
* @notice Will emit default URI log event for corresponding token _id
* @param _tokenIDs Array of IDs of tokens to log default URI
*/
function _logURIs(uint256[] memory _tokenIDs) internal {
string memory baseURL = baseMetadataURI;
string memory tokenURI;
for (uint256 i = 0; i < _tokenIDs.length; i++) {
tokenURI = string(abi.encodePacked(baseURL, _uint2str(_tokenIDs[i]), ".json"));
emit URI(tokenURI, _tokenIDs[i]);
}
}
/**
* @notice Will emit a specific URI log event for corresponding token
* @param _tokenIDs IDs of the token corresponding to the _uris logged
* @param _URIs The URIs of the specified _tokenIDs
*/
function _logURIs(uint256[] memory _tokenIDs, string[] memory _URIs) internal {
require(_tokenIDs.length == _URIs.length, "ERC1155Metadata#_logURIs: INVALID_ARRAYS_LENGTH");
for (uint256 i = 0; i < _tokenIDs.length; i++) {
emit URI(_URIs[i], _tokenIDs[i]);
}
}
/**
* @notice Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function _setBaseMetadataURI(string memory _newBaseMetadataURI) internal {
baseMetadataURI = _newBaseMetadataURI;
}
/***********************************|
| Utility Internal Functions |
|__________________________________*/
/**
* @notice Convert uint256 to string
* @param _i Unsigned integer to convert to string
*/
function _uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 ii = _i;
uint256 len;
// Get number of bytes
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len - 1;
// Get each individual ASCII
while (ii != 0) {
bstr[k--] = byte(uint8(48 + ii % 10));
ii /= 10;
}
// Convert to string
return string(bstr);
}
} | /**
* @notice Contract that handles metadata related methods.
* @dev Methods assume a deterministic generation of URI based on token IDs.
* Methods also assume that URI uses hex representation of token IDs.
*/ | NatSpecMultiLine | _logURIs | function _logURIs(uint256[] memory _tokenIDs, string[] memory _URIs) internal {
require(_tokenIDs.length == _URIs.length, "ERC1155Metadata#_logURIs: INVALID_ARRAYS_LENGTH");
for (uint256 i = 0; i < _tokenIDs.length; i++) {
emit URI(_URIs[i], _tokenIDs[i]);
}
}
| /**
* @notice Will emit a specific URI log event for corresponding token
* @param _tokenIDs IDs of the token corresponding to the _uris logged
* @param _URIs The URIs of the specified _tokenIDs
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1531,
1813
]
} | 55,591 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Metadata | contract ERC1155Metadata {
// URI's default URI prefix
string internal baseMetadataURI;
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Metadata Public Function s |
|__________________________________*/
/**
* @notice A distinct Uniform Resource Identifier (URI) for a given token.
* @dev URIs are defined in RFC 3986.
* URIs are assumed to be deterministically generated based on token ID
* Token IDs are assumed to be represented in their hex format in URIs
* @return URI string
*/
function uri(uint256 _id) public view returns (string memory) {
return string(abi.encodePacked(baseMetadataURI, _uint2str(_id), ".json"));
}
/***********************************|
| Metadata Internal Functions |
|__________________________________*/
/**
* @notice Will emit default URI log event for corresponding token _id
* @param _tokenIDs Array of IDs of tokens to log default URI
*/
function _logURIs(uint256[] memory _tokenIDs) internal {
string memory baseURL = baseMetadataURI;
string memory tokenURI;
for (uint256 i = 0; i < _tokenIDs.length; i++) {
tokenURI = string(abi.encodePacked(baseURL, _uint2str(_tokenIDs[i]), ".json"));
emit URI(tokenURI, _tokenIDs[i]);
}
}
/**
* @notice Will emit a specific URI log event for corresponding token
* @param _tokenIDs IDs of the token corresponding to the _uris logged
* @param _URIs The URIs of the specified _tokenIDs
*/
function _logURIs(uint256[] memory _tokenIDs, string[] memory _URIs) internal {
require(_tokenIDs.length == _URIs.length, "ERC1155Metadata#_logURIs: INVALID_ARRAYS_LENGTH");
for (uint256 i = 0; i < _tokenIDs.length; i++) {
emit URI(_URIs[i], _tokenIDs[i]);
}
}
/**
* @notice Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function _setBaseMetadataURI(string memory _newBaseMetadataURI) internal {
baseMetadataURI = _newBaseMetadataURI;
}
/***********************************|
| Utility Internal Functions |
|__________________________________*/
/**
* @notice Convert uint256 to string
* @param _i Unsigned integer to convert to string
*/
function _uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 ii = _i;
uint256 len;
// Get number of bytes
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len - 1;
// Get each individual ASCII
while (ii != 0) {
bstr[k--] = byte(uint8(48 + ii % 10));
ii /= 10;
}
// Convert to string
return string(bstr);
}
} | /**
* @notice Contract that handles metadata related methods.
* @dev Methods assume a deterministic generation of URI based on token IDs.
* Methods also assume that URI uses hex representation of token IDs.
*/ | NatSpecMultiLine | _setBaseMetadataURI | function _setBaseMetadataURI(string memory _newBaseMetadataURI) internal {
baseMetadataURI = _newBaseMetadataURI;
}
| /**
* @notice Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1940,
2063
]
} | 55,592 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Metadata | contract ERC1155Metadata {
// URI's default URI prefix
string internal baseMetadataURI;
event URI(string _uri, uint256 indexed _id);
/***********************************|
| Metadata Public Function s |
|__________________________________*/
/**
* @notice A distinct Uniform Resource Identifier (URI) for a given token.
* @dev URIs are defined in RFC 3986.
* URIs are assumed to be deterministically generated based on token ID
* Token IDs are assumed to be represented in their hex format in URIs
* @return URI string
*/
function uri(uint256 _id) public view returns (string memory) {
return string(abi.encodePacked(baseMetadataURI, _uint2str(_id), ".json"));
}
/***********************************|
| Metadata Internal Functions |
|__________________________________*/
/**
* @notice Will emit default URI log event for corresponding token _id
* @param _tokenIDs Array of IDs of tokens to log default URI
*/
function _logURIs(uint256[] memory _tokenIDs) internal {
string memory baseURL = baseMetadataURI;
string memory tokenURI;
for (uint256 i = 0; i < _tokenIDs.length; i++) {
tokenURI = string(abi.encodePacked(baseURL, _uint2str(_tokenIDs[i]), ".json"));
emit URI(tokenURI, _tokenIDs[i]);
}
}
/**
* @notice Will emit a specific URI log event for corresponding token
* @param _tokenIDs IDs of the token corresponding to the _uris logged
* @param _URIs The URIs of the specified _tokenIDs
*/
function _logURIs(uint256[] memory _tokenIDs, string[] memory _URIs) internal {
require(_tokenIDs.length == _URIs.length, "ERC1155Metadata#_logURIs: INVALID_ARRAYS_LENGTH");
for (uint256 i = 0; i < _tokenIDs.length; i++) {
emit URI(_URIs[i], _tokenIDs[i]);
}
}
/**
* @notice Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function _setBaseMetadataURI(string memory _newBaseMetadataURI) internal {
baseMetadataURI = _newBaseMetadataURI;
}
/***********************************|
| Utility Internal Functions |
|__________________________________*/
/**
* @notice Convert uint256 to string
* @param _i Unsigned integer to convert to string
*/
function _uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 ii = _i;
uint256 len;
// Get number of bytes
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len - 1;
// Get each individual ASCII
while (ii != 0) {
bstr[k--] = byte(uint8(48 + ii % 10));
ii /= 10;
}
// Convert to string
return string(bstr);
}
} | /**
* @notice Contract that handles metadata related methods.
* @dev Methods assume a deterministic generation of URI based on token IDs.
* Methods also assume that URI uses hex representation of token IDs.
*/ | NatSpecMultiLine | _uint2str | function _uint2str(uint256 _i) internal pure returns (string memory _uintAsString) {
if (_i == 0) {
return "0";
}
uint256 j = _i;
uint256 ii = _i;
uint256 len;
// Get number of bytes
while (j != 0) {
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint256 k = len - 1;
// Get each individual ASCII
while (ii != 0) {
bstr[k--] = byte(uint8(48 + ii % 10));
ii /= 10;
}
// Convert to string
return string(bstr);
}
| /**
* @notice Convert uint256 to string
* @param _i Unsigned integer to convert to string
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
2291,
2806
]
} | 55,593 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155MintBurn | contract ERC1155MintBurn is ERC1155 {
/****************************************|
| Minting Functions |
|_______________________________________*/
/**
* @notice Mint _amount of tokens of a given id
* @param _to The address to mint tokens to
* @param _id Token id to mint
* @param _amount The amount to be minted
* @param _data Data to pass if receiver is contract
*/
function _mint(address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Add _amount
balances[_to][_id] = balances[_to][_id].add(_amount);
// Emit event
emit TransferSingle(msg.sender, address(0x0), _to, _id, _amount);
// Calling onReceive method if recipient is contract
_callonERC1155Received(address(0x0), _to, _id, _amount, _data);
}
/**
* @notice Mint tokens for each ids in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _amounts Array of amount of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function _batchMint(address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchMint: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nMint = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nMint; i++) {
// Update storage balance
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, address(0x0), _to, _ids, _amounts);
// Calling onReceive method if recipient is contract
_callonERC1155BatchReceived(address(0x0), _to, _ids, _amounts, _data);
}
/****************************************|
| Burning Functions |
|_______________________________________*/
/**
* @notice Burn _amount of tokens of a given token id
* @param _from The address to burn tokens from
* @param _id Token id to burn
* @param _amount The amount to be burned
*/
function _burn(address _from, uint256 _id, uint256 _amount)
internal
{
//Substract _amount
balances[_from][_id] = balances[_from][_id].sub(_amount);
// Emit event
emit TransferSingle(msg.sender, _from, address(0x0), _id, _amount);
}
/**
* @notice Burn tokens of given token id for each (_ids[i], _amounts[i]) pair
* @param _from The address to burn tokens from
* @param _ids Array of token ids to burn
* @param _amounts Array of the amount to be burned
*/
function _batchBurn(address _from, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchBurn: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nBurn = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nBurn; i++) {
// Update storage balance
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, _from, address(0x0), _ids, _amounts);
}
} | /**
* @dev Multi-Fungible Tokens with minting and burning methods. These methods assume
* a parent contract to be executed as they are `internal` functions
*/ | NatSpecMultiLine | _mint | function _mint(address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Add _amount
balances[_to][_id] = balances[_to][_id].add(_amount);
// Emit event
emit TransferSingle(msg.sender, address(0x0), _to, _id, _amount);
// Calling onReceive method if recipient is contract
_callonERC1155Received(address(0x0), _to, _id, _amount, _data);
}
| /**
* @notice Mint _amount of tokens of a given id
* @param _to The address to mint tokens to
* @param _id Token id to mint
* @param _amount The amount to be minted
* @param _data Data to pass if receiver is contract
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
430,
822
]
} | 55,594 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155MintBurn | contract ERC1155MintBurn is ERC1155 {
/****************************************|
| Minting Functions |
|_______________________________________*/
/**
* @notice Mint _amount of tokens of a given id
* @param _to The address to mint tokens to
* @param _id Token id to mint
* @param _amount The amount to be minted
* @param _data Data to pass if receiver is contract
*/
function _mint(address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Add _amount
balances[_to][_id] = balances[_to][_id].add(_amount);
// Emit event
emit TransferSingle(msg.sender, address(0x0), _to, _id, _amount);
// Calling onReceive method if recipient is contract
_callonERC1155Received(address(0x0), _to, _id, _amount, _data);
}
/**
* @notice Mint tokens for each ids in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _amounts Array of amount of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function _batchMint(address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchMint: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nMint = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nMint; i++) {
// Update storage balance
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, address(0x0), _to, _ids, _amounts);
// Calling onReceive method if recipient is contract
_callonERC1155BatchReceived(address(0x0), _to, _ids, _amounts, _data);
}
/****************************************|
| Burning Functions |
|_______________________________________*/
/**
* @notice Burn _amount of tokens of a given token id
* @param _from The address to burn tokens from
* @param _id Token id to burn
* @param _amount The amount to be burned
*/
function _burn(address _from, uint256 _id, uint256 _amount)
internal
{
//Substract _amount
balances[_from][_id] = balances[_from][_id].sub(_amount);
// Emit event
emit TransferSingle(msg.sender, _from, address(0x0), _id, _amount);
}
/**
* @notice Burn tokens of given token id for each (_ids[i], _amounts[i]) pair
* @param _from The address to burn tokens from
* @param _ids Array of token ids to burn
* @param _amounts Array of the amount to be burned
*/
function _batchBurn(address _from, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchBurn: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nBurn = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nBurn; i++) {
// Update storage balance
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, _from, address(0x0), _ids, _amounts);
}
} | /**
* @dev Multi-Fungible Tokens with minting and burning methods. These methods assume
* a parent contract to be executed as they are `internal` functions
*/ | NatSpecMultiLine | _batchMint | function _batchMint(address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchMint: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nMint = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nMint; i++) {
// Update storage balance
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, address(0x0), _to, _ids, _amounts);
// Calling onReceive method if recipient is contract
_callonERC1155BatchReceived(address(0x0), _to, _ids, _amounts, _data);
}
| /**
* @notice Mint tokens for each ids in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _amounts Array of amount of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1098,
1805
]
} | 55,595 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155MintBurn | contract ERC1155MintBurn is ERC1155 {
/****************************************|
| Minting Functions |
|_______________________________________*/
/**
* @notice Mint _amount of tokens of a given id
* @param _to The address to mint tokens to
* @param _id Token id to mint
* @param _amount The amount to be minted
* @param _data Data to pass if receiver is contract
*/
function _mint(address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Add _amount
balances[_to][_id] = balances[_to][_id].add(_amount);
// Emit event
emit TransferSingle(msg.sender, address(0x0), _to, _id, _amount);
// Calling onReceive method if recipient is contract
_callonERC1155Received(address(0x0), _to, _id, _amount, _data);
}
/**
* @notice Mint tokens for each ids in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _amounts Array of amount of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function _batchMint(address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchMint: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nMint = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nMint; i++) {
// Update storage balance
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, address(0x0), _to, _ids, _amounts);
// Calling onReceive method if recipient is contract
_callonERC1155BatchReceived(address(0x0), _to, _ids, _amounts, _data);
}
/****************************************|
| Burning Functions |
|_______________________________________*/
/**
* @notice Burn _amount of tokens of a given token id
* @param _from The address to burn tokens from
* @param _id Token id to burn
* @param _amount The amount to be burned
*/
function _burn(address _from, uint256 _id, uint256 _amount)
internal
{
//Substract _amount
balances[_from][_id] = balances[_from][_id].sub(_amount);
// Emit event
emit TransferSingle(msg.sender, _from, address(0x0), _id, _amount);
}
/**
* @notice Burn tokens of given token id for each (_ids[i], _amounts[i]) pair
* @param _from The address to burn tokens from
* @param _ids Array of token ids to burn
* @param _amounts Array of the amount to be burned
*/
function _batchBurn(address _from, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchBurn: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nBurn = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nBurn; i++) {
// Update storage balance
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, _from, address(0x0), _ids, _amounts);
}
} | /**
* @dev Multi-Fungible Tokens with minting and burning methods. These methods assume
* a parent contract to be executed as they are `internal` functions
*/ | NatSpecMultiLine | _burn | function _burn(address _from, uint256 _id, uint256 _amount)
internal
{
//Substract _amount
balances[_from][_id] = balances[_from][_id].sub(_amount);
// Emit event
emit TransferSingle(msg.sender, _from, address(0x0), _id, _amount);
}
| /**
* @notice Burn _amount of tokens of a given token id
* @param _from The address to burn tokens from
* @param _id Token id to burn
* @param _amount The amount to be burned
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
2148,
2407
]
} | 55,596 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155MintBurn | contract ERC1155MintBurn is ERC1155 {
/****************************************|
| Minting Functions |
|_______________________________________*/
/**
* @notice Mint _amount of tokens of a given id
* @param _to The address to mint tokens to
* @param _id Token id to mint
* @param _amount The amount to be minted
* @param _data Data to pass if receiver is contract
*/
function _mint(address _to, uint256 _id, uint256 _amount, bytes memory _data)
internal
{
// Add _amount
balances[_to][_id] = balances[_to][_id].add(_amount);
// Emit event
emit TransferSingle(msg.sender, address(0x0), _to, _id, _amount);
// Calling onReceive method if recipient is contract
_callonERC1155Received(address(0x0), _to, _id, _amount, _data);
}
/**
* @notice Mint tokens for each ids in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _amounts Array of amount of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function _batchMint(address _to, uint256[] memory _ids, uint256[] memory _amounts, bytes memory _data)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchMint: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nMint = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nMint; i++) {
// Update storage balance
balances[_to][_ids[i]] = balances[_to][_ids[i]].add(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, address(0x0), _to, _ids, _amounts);
// Calling onReceive method if recipient is contract
_callonERC1155BatchReceived(address(0x0), _to, _ids, _amounts, _data);
}
/****************************************|
| Burning Functions |
|_______________________________________*/
/**
* @notice Burn _amount of tokens of a given token id
* @param _from The address to burn tokens from
* @param _id Token id to burn
* @param _amount The amount to be burned
*/
function _burn(address _from, uint256 _id, uint256 _amount)
internal
{
//Substract _amount
balances[_from][_id] = balances[_from][_id].sub(_amount);
// Emit event
emit TransferSingle(msg.sender, _from, address(0x0), _id, _amount);
}
/**
* @notice Burn tokens of given token id for each (_ids[i], _amounts[i]) pair
* @param _from The address to burn tokens from
* @param _ids Array of token ids to burn
* @param _amounts Array of the amount to be burned
*/
function _batchBurn(address _from, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchBurn: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nBurn = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nBurn; i++) {
// Update storage balance
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, _from, address(0x0), _ids, _amounts);
}
} | /**
* @dev Multi-Fungible Tokens with minting and burning methods. These methods assume
* a parent contract to be executed as they are `internal` functions
*/ | NatSpecMultiLine | _batchBurn | function _batchBurn(address _from, uint256[] memory _ids, uint256[] memory _amounts)
internal
{
require(_ids.length == _amounts.length, "ERC1155MintBurn#batchBurn: INVALID_ARRAYS_LENGTH");
// Number of mints to execute
uint256 nBurn = _ids.length;
// Executing all minting
for (uint256 i = 0; i < nBurn; i++) {
// Update storage balance
balances[_from][_ids[i]] = balances[_from][_ids[i]].sub(_amounts[i]);
}
// Emit batch mint event
emit TransferBatch(msg.sender, _from, address(0x0), _ids, _amounts);
}
| /**
* @notice Burn tokens of given token id for each (_ids[i], _amounts[i]) pair
* @param _from The address to burn tokens from
* @param _ids Array of token ids to burn
* @param _amounts Array of the amount to be burned
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
2659,
3221
]
} | 55,597 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | Strings | library Strings {
// via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol
function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory) {
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 (uint i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
for (uint i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
for (uint i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
for (uint i = 0; i < _be.length; i++) babcde[k++] = _be[i];
return string(babcde);
}
function strConcat(string memory _a, string memory _b, string memory _c, string memory _d) internal pure returns (string memory) {
return strConcat(_a, _b, _c, _d, "");
}
function strConcat(string memory _a, string memory _b, string memory _c) internal pure returns (string memory) {
return strConcat(_a, _b, _c, "", "");
}
function strConcat(string memory _a, string memory _b) internal pure returns (string memory) {
return strConcat(_a, _b, "", "", "");
}
function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
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(uint8(48 + _i % 10));
_i /= 10;
}
return string(bstr);
}
} | strConcat | function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory) {
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 (uint i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
for (uint i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
for (uint i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
for (uint 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.5.12+commit.7709ece9 | {
"func_code_index": [
100,
959
]
} | 55,598 |
||||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | totalSupply | function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
| /**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1410,
1518
]
} | 55,599 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | setBaseMetadataURI | function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
| /**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
1642,
1783
]
} | 55,600 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | create | function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
| /**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
2272,
2720
]
} | 55,601 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | mint | function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
| /**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
3012,
3237
]
} | 55,602 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | batchMint | function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
| /**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
3529,
3991
]
} | 55,603 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | setCreator | function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
| /**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
4163,
4435
]
} | 55,604 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | isApprovedForAll | function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
| /**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
4552,
4944
]
} | 55,605 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | _setCreator | function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
| /**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5108,
5217
]
} | 55,606 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | _exists | function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
| /**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5436,
5550
]
} | 55,607 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | _getNextTokenID | function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
| /**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5683,
5783
]
} | 55,608 |
||
AwwGamesCollectible | AwwGamesCollectible.sol | 0x5f5c08f823aeeddc8a4e53e4f144e7a8f50d3b37 | Solidity | ERC1155Tradable | contract ERC1155Tradable is ERC1155, ERC1155MintBurn, ERC1155Metadata, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenID = 0;
mapping (uint256 => address) public creators;
mapping (uint256 => uint256) public tokenSupply;
// Contract name
string public name;
// Contract symbol
string public symbol;
/**
* @dev Require msg.sender to be the creator of the token id
*/
modifier creatorOnly(uint256 _id) {
require(creators[_id] == msg.sender, "ERC1155Tradable#creatorOnly: ONLY_CREATOR_ALLOWED");
_;
}
/**
* @dev Require msg.sender to own more than 0 of the token id
*/
modifier ownersOnly(uint256 _id) {
require(balances[msg.sender][_id] > 0, "ERC1155Tradable#ownersOnly: ONLY_OWNERS_ALLOWED");
_;
}
constructor(
string memory _name,
string memory _symbol,
address _proxyRegistryAddress
) public {
name = _name;
symbol = _symbol;
proxyRegistryAddress = _proxyRegistryAddress;
}
function uri(
uint256 _id
) public view returns (string memory) {
require(_exists(_id), "ERC721Tradable#uri: NONEXISTENT_TOKEN");
return Strings.strConcat(
baseMetadataURI,
Strings.uint2str(_id)
);
}
/**
* @dev Returns the total quantity for a token ID
* @param _id uint256 ID of the token to query
* @return amount of token in existence
*/
function totalSupply(
uint256 _id
) public view returns (uint256) {
return tokenSupply[_id];
}
/**
* @dev Will update the base URL of token's URI
* @param _newBaseMetadataURI New base URL of token's URI
*/
function setBaseMetadataURI(
string memory _newBaseMetadataURI
) public onlyOwner {
_setBaseMetadataURI(_newBaseMetadataURI);
}
/**
* @dev Creates a new token type and assigns _initialSupply to an address
* NOTE: remove onlyOwner if you want third parties to create new tokens on your contract (which may change your IDs)
* @param _initialOwner address of the first owner of the token
* @param _initialSupply amount to supply the first owner
* @param _uri Optional URI for this token type
* @param _data Data to pass if receiver is contract
* @return The newly created token ID
*/
function create(
address _initialOwner,
uint256 _initialSupply,
string calldata _uri,
bytes calldata _data
) external onlyOwner returns (uint256) {
uint256 _id = _getNextTokenID();
_incrementTokenTypeId();
creators[_id] = msg.sender;
if (bytes(_uri).length > 0) {
emit URI(_uri, _id);
}
_mint(_initialOwner, _id, _initialSupply, _data);
tokenSupply[_id] = _initialSupply;
return _id;
}
/**
* @dev Mints some amount of tokens to an address
* @param _to Address of the future owner of the token
* @param _id Token ID to mint
* @param _quantity Amount of tokens to mint
* @param _data Data to pass if receiver is contract
*/
function mint(
address _to,
uint256 _id,
uint256 _quantity,
bytes memory _data
) public creatorOnly(_id) {
_mint(_to, _id, _quantity, _data);
tokenSupply[_id] = tokenSupply[_id].add(_quantity);
}
/**
* @dev Mint tokens for each id in _ids
* @param _to The address to mint tokens to
* @param _ids Array of ids to mint
* @param _quantities Array of amounts of tokens to mint per id
* @param _data Data to pass if receiver is contract
*/
function batchMint(
address _to,
uint256[] memory _ids,
uint256[] memory _quantities,
bytes memory _data
) public {
for (uint256 i = 0; i < _ids.length; i++) {
uint256 _id = _ids[i];
require(creators[_id] == msg.sender, "ERC1155Tradable#batchMint: ONLY_CREATOR_ALLOWED");
uint256 quantity = _quantities[i];
tokenSupply[_id] = tokenSupply[_id].add(quantity);
}
_batchMint(_to, _ids, _quantities, _data);
}
/**
* @dev Change the creator address for given tokens
* @param _to Address of the new creator
* @param _ids Array of Token IDs to change creator
*/
function setCreator(
address _to,
uint256[] memory _ids
) public {
require(_to != address(0), "ERC1155Tradable#setCreator: INVALID_ADDRESS.");
for (uint256 i = 0; i < _ids.length; i++) {
uint256 id = _ids[i];
_setCreator(_to, id);
}
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* @dev Change the creator address for given token
* @param _to Address of the new creator
* @param _id Token IDs to change creator of
*/
function _setCreator(address _to, uint256 _id) internal creatorOnly(_id)
{
creators[_id] = _to;
}
/**
* @dev Returns whether the specified token exists by checking to see if it has a creator
* @param _id uint256 ID of the token to query the existence of
* @return bool whether the token exists
*/
function _exists(
uint256 _id
) internal view returns (bool) {
return creators[_id] != address(0);
}
/**
* @dev calculates the next token ID based on value of _currentTokenID
* @return uint256 for the next token ID
*/
function _getNextTokenID() private view returns (uint256) {
return _currentTokenID.add(1);
}
/**
* @dev increments the value of _currentTokenID
*/
function _incrementTokenTypeId() private {
_currentTokenID++;
}
} | /**
* @title ERC1155Tradable
* ERC1155Tradable - ERC1155 contract that whitelists an operator address, has create and mint functionality, and supports useful standards from OpenZeppelin,
like _exists(), name(), symbol(), and totalSupply()
*/ | NatSpecMultiLine | _incrementTokenTypeId | function _incrementTokenTypeId() private {
_currentTokenID++;
}
| /**
* @dev increments the value of _currentTokenID
*/ | NatSpecMultiLine | v0.5.12+commit.7709ece9 | {
"func_code_index": [
5849,
5921
]
} | 55,609 |
||
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | tryAdd | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
| /**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
161,
344
]
} | 55,610 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | trySub | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
| /**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
492,
651
]
} | 55,611 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | tryMul | function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
| /**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
801,
1249
]
} | 55,612 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | tryDiv | function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
| /**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
1400,
1560
]
} | 55,613 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | tryMod | function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
| /**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
1721,
1881
]
} | 55,614 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
2123,
2307
]
} | 55,615 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
| /**
* @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.
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
2585,
2748
]
} | 55,616 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
3002,
3227
]
} | 55,617 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
| /**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
3700,
3858
]
} | 55,618 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting 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.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
4320,
4476
]
} | 55,619 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
4950,
5155
]
} | 55,620 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
| /**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
5824,
6028
]
} | 55,621 |
KollectToken | @openzeppelin/contracts/math/SafeMath.sol | 0x1cc30e2eac975416060ec6fe682041408420d414 | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b > a) return (false, 0);
return (true, a - b);
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a / b);
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
if (b == 0) return (false, 0);
return (true, a % b);
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) return 0;
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: division by zero");
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "SafeMath: modulo by zero");
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
return a - b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryDiv}.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mod | function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
return a % b;
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* 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.7.6+commit.7338295f | MIT | ipfs://da268c79f83338112ad06dfa7bdfcedfe47772fff8205f02cf2b4b914239be21 | {
"func_code_index": [
6686,
6890
]
} | 55,622 |
Expiry | contracts/external/traders/Expiry.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Expiry | contract Expiry is
Ownable,
OnlySolo,
ICallee,
IAutoTrader
{
using SafeMath for uint32;
using SafeMath for uint256;
using Types for Types.Par;
using Types for Types.Wei;
// ============ Constants ============
bytes32 constant FILE = "Expiry";
// ============ Events ============
event ExpirySet(
address owner,
uint256 number,
uint256 marketId,
uint32 time
);
event LogExpiryRampTimeSet(
uint256 expiryRampTime
);
// ============ Storage ============
// owner => number => market => time
mapping (address => mapping (uint256 => mapping (uint256 => uint32))) g_expiries;
// time over which the liquidation ratio goes from zero to maximum
uint256 public g_expiryRampTime;
// ============ Constructor ============
constructor (
address soloMargin,
uint256 expiryRampTime
)
public
OnlySolo(soloMargin)
{
g_expiryRampTime = expiryRampTime;
}
// ============ Admin Functions ============
function ownerSetExpiryRampTime(
uint256 newExpiryRampTime
)
external
onlyOwner
{
emit LogExpiryRampTimeSet(newExpiryRampTime);
g_expiryRampTime = newExpiryRampTime;
}
// ============ Only-Solo Functions ============
function callFunction(
address /* sender */,
Account.Info memory account,
bytes memory data
)
public
onlySolo(msg.sender)
{
(
uint256 marketId,
uint32 expiryTime
) = parseCallArgs(data);
// don't set expiry time for accounts with positive balance
if (expiryTime != 0 && !SOLO_MARGIN.getAccountPar(account, marketId).isNegative()) {
return;
}
setExpiry(account, marketId, expiryTime);
}
function getTradeCost(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Account.Info memory /* takerAccount */,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
bytes memory data
)
public
onlySolo(msg.sender)
returns (Types.AssetAmount memory)
{
// return zero if input amount is zero
if (inputWei.isZero()) {
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Par,
ref: Types.AssetReference.Delta,
value: 0
});
}
(
uint256 owedMarketId,
uint32 maxExpiry
) = parseTradeArgs(data);
uint32 expiry = getExpiry(makerAccount, owedMarketId);
// validate expiry
Require.that(
expiry != 0,
FILE,
"Expiry not set",
makerAccount.owner,
makerAccount.number,
owedMarketId
);
Require.that(
expiry <= Time.currentTime(),
FILE,
"Borrow not yet expired",
expiry
);
Require.that(
expiry <= maxExpiry,
FILE,
"Expiry past maxExpiry",
expiry
);
return getTradeCostInternal(
inputMarketId,
outputMarketId,
makerAccount,
oldInputPar,
newInputPar,
inputWei,
owedMarketId,
expiry
);
}
// ============ Getters ============
function getExpiry(
Account.Info memory account,
uint256 marketId
)
public
view
returns (uint32)
{
return g_expiries[account.owner][account.number][marketId];
}
function getSpreadAdjustedPrices(
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
public
view
returns (
Monetary.Price memory,
Monetary.Price memory
)
{
Decimal.D256 memory spread = SOLO_MARGIN.getLiquidationSpreadForPair(
heldMarketId,
owedMarketId
);
uint256 expiryAge = Time.currentTime().sub(expiry);
if (expiryAge < g_expiryRampTime) {
spread.value = Math.getPartial(spread.value, expiryAge, g_expiryRampTime);
}
Monetary.Price memory heldPrice = SOLO_MARGIN.getMarketPrice(heldMarketId);
Monetary.Price memory owedPrice = SOLO_MARGIN.getMarketPrice(owedMarketId);
owedPrice.value = owedPrice.value.add(Decimal.mul(owedPrice.value, spread));
return (heldPrice, owedPrice);
}
// ============ Private Functions ============
function getTradeCostInternal(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
uint256 owedMarketId,
uint32 expiry
)
private
returns (Types.AssetAmount memory)
{
Types.AssetAmount memory output;
Types.Wei memory maxOutputWei = SOLO_MARGIN.getAccountWei(makerAccount, outputMarketId);
if (inputWei.isPositive()) {
Require.that(
inputMarketId == owedMarketId,
FILE,
"inputMarket mismatch",
inputMarketId
);
Require.that(
!newInputPar.isPositive(),
FILE,
"Borrows cannot be overpaid",
newInputPar.value
);
assert(oldInputPar.isNegative());
Require.that(
maxOutputWei.isPositive(),
FILE,
"Collateral must be positive",
outputMarketId,
maxOutputWei.value
);
output = owedWeiToHeldWei(
inputWei,
outputMarketId,
inputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (newInputPar.isZero()) {
setExpiry(makerAccount, owedMarketId, 0);
}
} else {
Require.that(
outputMarketId == owedMarketId,
FILE,
"outputMarket mismatch",
outputMarketId
);
Require.that(
!newInputPar.isNegative(),
FILE,
"Collateral cannot be overused",
newInputPar.value
);
assert(oldInputPar.isPositive());
Require.that(
maxOutputWei.isNegative(),
FILE,
"Borrows must be negative",
outputMarketId,
maxOutputWei.value
);
output = heldWeiToOwedWei(
inputWei,
inputMarketId,
outputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (output.value == maxOutputWei.value) {
setExpiry(makerAccount, owedMarketId, 0);
}
}
Require.that(
output.value <= maxOutputWei.value,
FILE,
"outputMarket too small",
output.value,
maxOutputWei.value
);
assert(output.sign != maxOutputWei.sign);
return output;
}
function setExpiry(
Account.Info memory account,
uint256 marketId,
uint32 time
)
private
{
g_expiries[account.owner][account.number][marketId] = time;
emit ExpirySet(
account.owner,
account.number,
marketId,
time
);
}
function heldWeiToOwedWei(
Types.Wei memory heldWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 owedAmount = Math.getPartialRoundUp(
heldWei.value,
heldPrice.value,
owedPrice.value
);
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: owedAmount
});
}
function owedWeiToHeldWei(
Types.Wei memory owedWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 heldAmount = Math.getPartial(
owedWei.value,
owedPrice.value,
heldPrice.value
);
return Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: heldAmount
});
}
function parseCallArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Call data invalid length",
data.length
);
uint256 marketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
marketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
marketId,
Math.to32(rawExpiry)
);
}
function parseTradeArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Trade data invalid length",
data.length
);
uint256 owedMarketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
owedMarketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
owedMarketId,
Math.to32(rawExpiry)
);
}
} | /**
* @title Expiry
* @author dYdX
*
* Sets the negative balance for an account to expire at a certain time. This allows any other
* account to repay that negative balance after expiry using any positive balance in the same
* account. The arbitrage incentive is the same as liquidation in the base protocol.
*/ | NatSpecMultiLine | ownerSetExpiryRampTime | function ownerSetExpiryRampTime(
uint256 newExpiryRampTime
)
external
onlyOwner
{
emit LogExpiryRampTimeSet(newExpiryRampTime);
g_expiryRampTime = newExpiryRampTime;
}
| // ============ Admin Functions ============ | LineComment | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
1128,
1360
]
} | 55,623 |
Expiry | contracts/external/traders/Expiry.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Expiry | contract Expiry is
Ownable,
OnlySolo,
ICallee,
IAutoTrader
{
using SafeMath for uint32;
using SafeMath for uint256;
using Types for Types.Par;
using Types for Types.Wei;
// ============ Constants ============
bytes32 constant FILE = "Expiry";
// ============ Events ============
event ExpirySet(
address owner,
uint256 number,
uint256 marketId,
uint32 time
);
event LogExpiryRampTimeSet(
uint256 expiryRampTime
);
// ============ Storage ============
// owner => number => market => time
mapping (address => mapping (uint256 => mapping (uint256 => uint32))) g_expiries;
// time over which the liquidation ratio goes from zero to maximum
uint256 public g_expiryRampTime;
// ============ Constructor ============
constructor (
address soloMargin,
uint256 expiryRampTime
)
public
OnlySolo(soloMargin)
{
g_expiryRampTime = expiryRampTime;
}
// ============ Admin Functions ============
function ownerSetExpiryRampTime(
uint256 newExpiryRampTime
)
external
onlyOwner
{
emit LogExpiryRampTimeSet(newExpiryRampTime);
g_expiryRampTime = newExpiryRampTime;
}
// ============ Only-Solo Functions ============
function callFunction(
address /* sender */,
Account.Info memory account,
bytes memory data
)
public
onlySolo(msg.sender)
{
(
uint256 marketId,
uint32 expiryTime
) = parseCallArgs(data);
// don't set expiry time for accounts with positive balance
if (expiryTime != 0 && !SOLO_MARGIN.getAccountPar(account, marketId).isNegative()) {
return;
}
setExpiry(account, marketId, expiryTime);
}
function getTradeCost(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Account.Info memory /* takerAccount */,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
bytes memory data
)
public
onlySolo(msg.sender)
returns (Types.AssetAmount memory)
{
// return zero if input amount is zero
if (inputWei.isZero()) {
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Par,
ref: Types.AssetReference.Delta,
value: 0
});
}
(
uint256 owedMarketId,
uint32 maxExpiry
) = parseTradeArgs(data);
uint32 expiry = getExpiry(makerAccount, owedMarketId);
// validate expiry
Require.that(
expiry != 0,
FILE,
"Expiry not set",
makerAccount.owner,
makerAccount.number,
owedMarketId
);
Require.that(
expiry <= Time.currentTime(),
FILE,
"Borrow not yet expired",
expiry
);
Require.that(
expiry <= maxExpiry,
FILE,
"Expiry past maxExpiry",
expiry
);
return getTradeCostInternal(
inputMarketId,
outputMarketId,
makerAccount,
oldInputPar,
newInputPar,
inputWei,
owedMarketId,
expiry
);
}
// ============ Getters ============
function getExpiry(
Account.Info memory account,
uint256 marketId
)
public
view
returns (uint32)
{
return g_expiries[account.owner][account.number][marketId];
}
function getSpreadAdjustedPrices(
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
public
view
returns (
Monetary.Price memory,
Monetary.Price memory
)
{
Decimal.D256 memory spread = SOLO_MARGIN.getLiquidationSpreadForPair(
heldMarketId,
owedMarketId
);
uint256 expiryAge = Time.currentTime().sub(expiry);
if (expiryAge < g_expiryRampTime) {
spread.value = Math.getPartial(spread.value, expiryAge, g_expiryRampTime);
}
Monetary.Price memory heldPrice = SOLO_MARGIN.getMarketPrice(heldMarketId);
Monetary.Price memory owedPrice = SOLO_MARGIN.getMarketPrice(owedMarketId);
owedPrice.value = owedPrice.value.add(Decimal.mul(owedPrice.value, spread));
return (heldPrice, owedPrice);
}
// ============ Private Functions ============
function getTradeCostInternal(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
uint256 owedMarketId,
uint32 expiry
)
private
returns (Types.AssetAmount memory)
{
Types.AssetAmount memory output;
Types.Wei memory maxOutputWei = SOLO_MARGIN.getAccountWei(makerAccount, outputMarketId);
if (inputWei.isPositive()) {
Require.that(
inputMarketId == owedMarketId,
FILE,
"inputMarket mismatch",
inputMarketId
);
Require.that(
!newInputPar.isPositive(),
FILE,
"Borrows cannot be overpaid",
newInputPar.value
);
assert(oldInputPar.isNegative());
Require.that(
maxOutputWei.isPositive(),
FILE,
"Collateral must be positive",
outputMarketId,
maxOutputWei.value
);
output = owedWeiToHeldWei(
inputWei,
outputMarketId,
inputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (newInputPar.isZero()) {
setExpiry(makerAccount, owedMarketId, 0);
}
} else {
Require.that(
outputMarketId == owedMarketId,
FILE,
"outputMarket mismatch",
outputMarketId
);
Require.that(
!newInputPar.isNegative(),
FILE,
"Collateral cannot be overused",
newInputPar.value
);
assert(oldInputPar.isPositive());
Require.that(
maxOutputWei.isNegative(),
FILE,
"Borrows must be negative",
outputMarketId,
maxOutputWei.value
);
output = heldWeiToOwedWei(
inputWei,
inputMarketId,
outputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (output.value == maxOutputWei.value) {
setExpiry(makerAccount, owedMarketId, 0);
}
}
Require.that(
output.value <= maxOutputWei.value,
FILE,
"outputMarket too small",
output.value,
maxOutputWei.value
);
assert(output.sign != maxOutputWei.sign);
return output;
}
function setExpiry(
Account.Info memory account,
uint256 marketId,
uint32 time
)
private
{
g_expiries[account.owner][account.number][marketId] = time;
emit ExpirySet(
account.owner,
account.number,
marketId,
time
);
}
function heldWeiToOwedWei(
Types.Wei memory heldWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 owedAmount = Math.getPartialRoundUp(
heldWei.value,
heldPrice.value,
owedPrice.value
);
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: owedAmount
});
}
function owedWeiToHeldWei(
Types.Wei memory owedWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 heldAmount = Math.getPartial(
owedWei.value,
owedPrice.value,
heldPrice.value
);
return Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: heldAmount
});
}
function parseCallArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Call data invalid length",
data.length
);
uint256 marketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
marketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
marketId,
Math.to32(rawExpiry)
);
}
function parseTradeArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Trade data invalid length",
data.length
);
uint256 owedMarketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
owedMarketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
owedMarketId,
Math.to32(rawExpiry)
);
}
} | /**
* @title Expiry
* @author dYdX
*
* Sets the negative balance for an account to expire at a certain time. This allows any other
* account to repay that negative balance after expiry using any positive balance in the same
* account. The arbitrage incentive is the same as liquidation in the base protocol.
*/ | NatSpecMultiLine | callFunction | function callFunction(
address /* sender */,
Account.Info memory account,
bytes memory data
)
public
onlySolo(msg.sender)
{
(
uint256 marketId,
uint32 expiryTime
) = parseCallArgs(data);
// don't set expiry time for accounts with positive balance
if (expiryTime != 0 && !SOLO_MARGIN.getAccountPar(account, marketId).isNegative()) {
return;
}
setExpiry(account, marketId, expiryTime);
}
| // ============ Only-Solo Functions ============ | LineComment | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
1419,
1966
]
} | 55,624 |
Expiry | contracts/external/traders/Expiry.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Expiry | contract Expiry is
Ownable,
OnlySolo,
ICallee,
IAutoTrader
{
using SafeMath for uint32;
using SafeMath for uint256;
using Types for Types.Par;
using Types for Types.Wei;
// ============ Constants ============
bytes32 constant FILE = "Expiry";
// ============ Events ============
event ExpirySet(
address owner,
uint256 number,
uint256 marketId,
uint32 time
);
event LogExpiryRampTimeSet(
uint256 expiryRampTime
);
// ============ Storage ============
// owner => number => market => time
mapping (address => mapping (uint256 => mapping (uint256 => uint32))) g_expiries;
// time over which the liquidation ratio goes from zero to maximum
uint256 public g_expiryRampTime;
// ============ Constructor ============
constructor (
address soloMargin,
uint256 expiryRampTime
)
public
OnlySolo(soloMargin)
{
g_expiryRampTime = expiryRampTime;
}
// ============ Admin Functions ============
function ownerSetExpiryRampTime(
uint256 newExpiryRampTime
)
external
onlyOwner
{
emit LogExpiryRampTimeSet(newExpiryRampTime);
g_expiryRampTime = newExpiryRampTime;
}
// ============ Only-Solo Functions ============
function callFunction(
address /* sender */,
Account.Info memory account,
bytes memory data
)
public
onlySolo(msg.sender)
{
(
uint256 marketId,
uint32 expiryTime
) = parseCallArgs(data);
// don't set expiry time for accounts with positive balance
if (expiryTime != 0 && !SOLO_MARGIN.getAccountPar(account, marketId).isNegative()) {
return;
}
setExpiry(account, marketId, expiryTime);
}
function getTradeCost(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Account.Info memory /* takerAccount */,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
bytes memory data
)
public
onlySolo(msg.sender)
returns (Types.AssetAmount memory)
{
// return zero if input amount is zero
if (inputWei.isZero()) {
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Par,
ref: Types.AssetReference.Delta,
value: 0
});
}
(
uint256 owedMarketId,
uint32 maxExpiry
) = parseTradeArgs(data);
uint32 expiry = getExpiry(makerAccount, owedMarketId);
// validate expiry
Require.that(
expiry != 0,
FILE,
"Expiry not set",
makerAccount.owner,
makerAccount.number,
owedMarketId
);
Require.that(
expiry <= Time.currentTime(),
FILE,
"Borrow not yet expired",
expiry
);
Require.that(
expiry <= maxExpiry,
FILE,
"Expiry past maxExpiry",
expiry
);
return getTradeCostInternal(
inputMarketId,
outputMarketId,
makerAccount,
oldInputPar,
newInputPar,
inputWei,
owedMarketId,
expiry
);
}
// ============ Getters ============
function getExpiry(
Account.Info memory account,
uint256 marketId
)
public
view
returns (uint32)
{
return g_expiries[account.owner][account.number][marketId];
}
function getSpreadAdjustedPrices(
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
public
view
returns (
Monetary.Price memory,
Monetary.Price memory
)
{
Decimal.D256 memory spread = SOLO_MARGIN.getLiquidationSpreadForPair(
heldMarketId,
owedMarketId
);
uint256 expiryAge = Time.currentTime().sub(expiry);
if (expiryAge < g_expiryRampTime) {
spread.value = Math.getPartial(spread.value, expiryAge, g_expiryRampTime);
}
Monetary.Price memory heldPrice = SOLO_MARGIN.getMarketPrice(heldMarketId);
Monetary.Price memory owedPrice = SOLO_MARGIN.getMarketPrice(owedMarketId);
owedPrice.value = owedPrice.value.add(Decimal.mul(owedPrice.value, spread));
return (heldPrice, owedPrice);
}
// ============ Private Functions ============
function getTradeCostInternal(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
uint256 owedMarketId,
uint32 expiry
)
private
returns (Types.AssetAmount memory)
{
Types.AssetAmount memory output;
Types.Wei memory maxOutputWei = SOLO_MARGIN.getAccountWei(makerAccount, outputMarketId);
if (inputWei.isPositive()) {
Require.that(
inputMarketId == owedMarketId,
FILE,
"inputMarket mismatch",
inputMarketId
);
Require.that(
!newInputPar.isPositive(),
FILE,
"Borrows cannot be overpaid",
newInputPar.value
);
assert(oldInputPar.isNegative());
Require.that(
maxOutputWei.isPositive(),
FILE,
"Collateral must be positive",
outputMarketId,
maxOutputWei.value
);
output = owedWeiToHeldWei(
inputWei,
outputMarketId,
inputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (newInputPar.isZero()) {
setExpiry(makerAccount, owedMarketId, 0);
}
} else {
Require.that(
outputMarketId == owedMarketId,
FILE,
"outputMarket mismatch",
outputMarketId
);
Require.that(
!newInputPar.isNegative(),
FILE,
"Collateral cannot be overused",
newInputPar.value
);
assert(oldInputPar.isPositive());
Require.that(
maxOutputWei.isNegative(),
FILE,
"Borrows must be negative",
outputMarketId,
maxOutputWei.value
);
output = heldWeiToOwedWei(
inputWei,
inputMarketId,
outputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (output.value == maxOutputWei.value) {
setExpiry(makerAccount, owedMarketId, 0);
}
}
Require.that(
output.value <= maxOutputWei.value,
FILE,
"outputMarket too small",
output.value,
maxOutputWei.value
);
assert(output.sign != maxOutputWei.sign);
return output;
}
function setExpiry(
Account.Info memory account,
uint256 marketId,
uint32 time
)
private
{
g_expiries[account.owner][account.number][marketId] = time;
emit ExpirySet(
account.owner,
account.number,
marketId,
time
);
}
function heldWeiToOwedWei(
Types.Wei memory heldWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 owedAmount = Math.getPartialRoundUp(
heldWei.value,
heldPrice.value,
owedPrice.value
);
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: owedAmount
});
}
function owedWeiToHeldWei(
Types.Wei memory owedWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 heldAmount = Math.getPartial(
owedWei.value,
owedPrice.value,
heldPrice.value
);
return Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: heldAmount
});
}
function parseCallArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Call data invalid length",
data.length
);
uint256 marketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
marketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
marketId,
Math.to32(rawExpiry)
);
}
function parseTradeArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Trade data invalid length",
data.length
);
uint256 owedMarketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
owedMarketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
owedMarketId,
Math.to32(rawExpiry)
);
}
} | /**
* @title Expiry
* @author dYdX
*
* Sets the negative balance for an account to expire at a certain time. This allows any other
* account to repay that negative balance after expiry using any positive balance in the same
* account. The arbitrage incentive is the same as liquidation in the base protocol.
*/ | NatSpecMultiLine | getExpiry | function getExpiry(
Account.Info memory account,
uint256 marketId
)
public
view
returns (uint32)
{
return g_expiries[account.owner][account.number][marketId];
}
| // ============ Getters ============ | LineComment | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
3740,
3974
]
} | 55,625 |
Expiry | contracts/external/traders/Expiry.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Expiry | contract Expiry is
Ownable,
OnlySolo,
ICallee,
IAutoTrader
{
using SafeMath for uint32;
using SafeMath for uint256;
using Types for Types.Par;
using Types for Types.Wei;
// ============ Constants ============
bytes32 constant FILE = "Expiry";
// ============ Events ============
event ExpirySet(
address owner,
uint256 number,
uint256 marketId,
uint32 time
);
event LogExpiryRampTimeSet(
uint256 expiryRampTime
);
// ============ Storage ============
// owner => number => market => time
mapping (address => mapping (uint256 => mapping (uint256 => uint32))) g_expiries;
// time over which the liquidation ratio goes from zero to maximum
uint256 public g_expiryRampTime;
// ============ Constructor ============
constructor (
address soloMargin,
uint256 expiryRampTime
)
public
OnlySolo(soloMargin)
{
g_expiryRampTime = expiryRampTime;
}
// ============ Admin Functions ============
function ownerSetExpiryRampTime(
uint256 newExpiryRampTime
)
external
onlyOwner
{
emit LogExpiryRampTimeSet(newExpiryRampTime);
g_expiryRampTime = newExpiryRampTime;
}
// ============ Only-Solo Functions ============
function callFunction(
address /* sender */,
Account.Info memory account,
bytes memory data
)
public
onlySolo(msg.sender)
{
(
uint256 marketId,
uint32 expiryTime
) = parseCallArgs(data);
// don't set expiry time for accounts with positive balance
if (expiryTime != 0 && !SOLO_MARGIN.getAccountPar(account, marketId).isNegative()) {
return;
}
setExpiry(account, marketId, expiryTime);
}
function getTradeCost(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Account.Info memory /* takerAccount */,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
bytes memory data
)
public
onlySolo(msg.sender)
returns (Types.AssetAmount memory)
{
// return zero if input amount is zero
if (inputWei.isZero()) {
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Par,
ref: Types.AssetReference.Delta,
value: 0
});
}
(
uint256 owedMarketId,
uint32 maxExpiry
) = parseTradeArgs(data);
uint32 expiry = getExpiry(makerAccount, owedMarketId);
// validate expiry
Require.that(
expiry != 0,
FILE,
"Expiry not set",
makerAccount.owner,
makerAccount.number,
owedMarketId
);
Require.that(
expiry <= Time.currentTime(),
FILE,
"Borrow not yet expired",
expiry
);
Require.that(
expiry <= maxExpiry,
FILE,
"Expiry past maxExpiry",
expiry
);
return getTradeCostInternal(
inputMarketId,
outputMarketId,
makerAccount,
oldInputPar,
newInputPar,
inputWei,
owedMarketId,
expiry
);
}
// ============ Getters ============
function getExpiry(
Account.Info memory account,
uint256 marketId
)
public
view
returns (uint32)
{
return g_expiries[account.owner][account.number][marketId];
}
function getSpreadAdjustedPrices(
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
public
view
returns (
Monetary.Price memory,
Monetary.Price memory
)
{
Decimal.D256 memory spread = SOLO_MARGIN.getLiquidationSpreadForPair(
heldMarketId,
owedMarketId
);
uint256 expiryAge = Time.currentTime().sub(expiry);
if (expiryAge < g_expiryRampTime) {
spread.value = Math.getPartial(spread.value, expiryAge, g_expiryRampTime);
}
Monetary.Price memory heldPrice = SOLO_MARGIN.getMarketPrice(heldMarketId);
Monetary.Price memory owedPrice = SOLO_MARGIN.getMarketPrice(owedMarketId);
owedPrice.value = owedPrice.value.add(Decimal.mul(owedPrice.value, spread));
return (heldPrice, owedPrice);
}
// ============ Private Functions ============
function getTradeCostInternal(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
uint256 owedMarketId,
uint32 expiry
)
private
returns (Types.AssetAmount memory)
{
Types.AssetAmount memory output;
Types.Wei memory maxOutputWei = SOLO_MARGIN.getAccountWei(makerAccount, outputMarketId);
if (inputWei.isPositive()) {
Require.that(
inputMarketId == owedMarketId,
FILE,
"inputMarket mismatch",
inputMarketId
);
Require.that(
!newInputPar.isPositive(),
FILE,
"Borrows cannot be overpaid",
newInputPar.value
);
assert(oldInputPar.isNegative());
Require.that(
maxOutputWei.isPositive(),
FILE,
"Collateral must be positive",
outputMarketId,
maxOutputWei.value
);
output = owedWeiToHeldWei(
inputWei,
outputMarketId,
inputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (newInputPar.isZero()) {
setExpiry(makerAccount, owedMarketId, 0);
}
} else {
Require.that(
outputMarketId == owedMarketId,
FILE,
"outputMarket mismatch",
outputMarketId
);
Require.that(
!newInputPar.isNegative(),
FILE,
"Collateral cannot be overused",
newInputPar.value
);
assert(oldInputPar.isPositive());
Require.that(
maxOutputWei.isNegative(),
FILE,
"Borrows must be negative",
outputMarketId,
maxOutputWei.value
);
output = heldWeiToOwedWei(
inputWei,
inputMarketId,
outputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (output.value == maxOutputWei.value) {
setExpiry(makerAccount, owedMarketId, 0);
}
}
Require.that(
output.value <= maxOutputWei.value,
FILE,
"outputMarket too small",
output.value,
maxOutputWei.value
);
assert(output.sign != maxOutputWei.sign);
return output;
}
function setExpiry(
Account.Info memory account,
uint256 marketId,
uint32 time
)
private
{
g_expiries[account.owner][account.number][marketId] = time;
emit ExpirySet(
account.owner,
account.number,
marketId,
time
);
}
function heldWeiToOwedWei(
Types.Wei memory heldWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 owedAmount = Math.getPartialRoundUp(
heldWei.value,
heldPrice.value,
owedPrice.value
);
return Types.AssetAmount({
sign: true,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: owedAmount
});
}
function owedWeiToHeldWei(
Types.Wei memory owedWei,
uint256 heldMarketId,
uint256 owedMarketId,
uint32 expiry
)
private
view
returns (Types.AssetAmount memory)
{
(
Monetary.Price memory heldPrice,
Monetary.Price memory owedPrice
) = getSpreadAdjustedPrices(
heldMarketId,
owedMarketId,
expiry
);
uint256 heldAmount = Math.getPartial(
owedWei.value,
owedPrice.value,
heldPrice.value
);
return Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: heldAmount
});
}
function parseCallArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Call data invalid length",
data.length
);
uint256 marketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
marketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
marketId,
Math.to32(rawExpiry)
);
}
function parseTradeArgs(
bytes memory data
)
private
pure
returns (
uint256,
uint32
)
{
Require.that(
data.length == 64,
FILE,
"Trade data invalid length",
data.length
);
uint256 owedMarketId;
uint256 rawExpiry;
/* solium-disable-next-line security/no-inline-assembly */
assembly {
owedMarketId := mload(add(data, 32))
rawExpiry := mload(add(data, 64))
}
return (
owedMarketId,
Math.to32(rawExpiry)
);
}
} | /**
* @title Expiry
* @author dYdX
*
* Sets the negative balance for an account to expire at a certain time. This allows any other
* account to repay that negative balance after expiry using any positive balance in the same
* account. The arbitrage incentive is the same as liquidation in the base protocol.
*/ | NatSpecMultiLine | getTradeCostInternal | function getTradeCostInternal(
uint256 inputMarketId,
uint256 outputMarketId,
Account.Info memory makerAccount,
Types.Par memory oldInputPar,
Types.Par memory newInputPar,
Types.Wei memory inputWei,
uint256 owedMarketId,
uint32 expiry
)
private
returns (Types.AssetAmount memory)
{
Types.AssetAmount memory output;
Types.Wei memory maxOutputWei = SOLO_MARGIN.getAccountWei(makerAccount, outputMarketId);
if (inputWei.isPositive()) {
Require.that(
inputMarketId == owedMarketId,
FILE,
"inputMarket mismatch",
inputMarketId
);
Require.that(
!newInputPar.isPositive(),
FILE,
"Borrows cannot be overpaid",
newInputPar.value
);
assert(oldInputPar.isNegative());
Require.that(
maxOutputWei.isPositive(),
FILE,
"Collateral must be positive",
outputMarketId,
maxOutputWei.value
);
output = owedWeiToHeldWei(
inputWei,
outputMarketId,
inputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (newInputPar.isZero()) {
setExpiry(makerAccount, owedMarketId, 0);
}
} else {
Require.that(
outputMarketId == owedMarketId,
FILE,
"outputMarket mismatch",
outputMarketId
);
Require.that(
!newInputPar.isNegative(),
FILE,
"Collateral cannot be overused",
newInputPar.value
);
assert(oldInputPar.isPositive());
Require.that(
maxOutputWei.isNegative(),
FILE,
"Borrows must be negative",
outputMarketId,
maxOutputWei.value
);
output = heldWeiToOwedWei(
inputWei,
inputMarketId,
outputMarketId,
expiry
);
// clear expiry if borrow is fully repaid
if (output.value == maxOutputWei.value) {
setExpiry(makerAccount, owedMarketId, 0);
}
}
Require.that(
output.value <= maxOutputWei.value,
FILE,
"outputMarket too small",
output.value,
maxOutputWei.value
);
assert(output.sign != maxOutputWei.sign);
return output;
}
| // ============ Private Functions ============ | LineComment | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
4962,
7853
]
} | 55,626 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | 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.
*/
constructor () internal {
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) onlyOwner public {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) onlyOwner public {
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.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
642,
823
]
} | 55,627 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | Solidity | StandardToken | contract StandardToken is ERC20Basic, Ownable {
uint256 public totalSupply;
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public override returns (bool trans1) {
require(_to != address(0));
//require(canTransfer(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
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.
*/
function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}
mapping (address => mapping (address => uint256)) 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 override returns (bool trans) {
require(_to != address(0));
// require(canTransfer(msg.sender));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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 override returns (bool hello) {
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.
*/
function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public override returns (bool trans1) {
require(_to != address(0));
//require(canTransfer(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
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.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
324,
737
]
} | 55,628 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | Solidity | StandardToken | contract StandardToken is ERC20Basic, Ownable {
uint256 public totalSupply;
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public override returns (bool trans1) {
require(_to != address(0));
//require(canTransfer(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
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.
*/
function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}
mapping (address => mapping (address => uint256)) 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 override returns (bool trans) {
require(_to != address(0));
// require(canTransfer(msg.sender));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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 override returns (bool hello) {
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.
*/
function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
870,
991
]
} | 55,629 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | Solidity | StandardToken | contract StandardToken is ERC20Basic, Ownable {
uint256 public totalSupply;
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public override returns (bool trans1) {
require(_to != address(0));
//require(canTransfer(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
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.
*/
function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}
mapping (address => mapping (address => uint256)) 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 override returns (bool trans) {
require(_to != address(0));
// require(canTransfer(msg.sender));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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 override returns (bool hello) {
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.
*/
function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public override returns (bool trans) {
require(_to != address(0));
// require(canTransfer(msg.sender));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
1339,
1949
]
} | 55,630 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | Solidity | StandardToken | contract StandardToken is ERC20Basic, Ownable {
uint256 public totalSupply;
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public override returns (bool trans1) {
require(_to != address(0));
//require(canTransfer(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
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.
*/
function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}
mapping (address => mapping (address => uint256)) 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 override returns (bool trans) {
require(_to != address(0));
// require(canTransfer(msg.sender));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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 override returns (bool hello) {
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.
*/
function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public override returns (bool hello) {
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.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
2581,
2791
]
} | 55,631 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | Solidity | StandardToken | contract StandardToken is ERC20Basic, Ownable {
uint256 public totalSupply;
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public override returns (bool trans1) {
require(_to != address(0));
//require(canTransfer(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
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.
*/
function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}
mapping (address => mapping (address => uint256)) 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 override returns (bool trans) {
require(_to != address(0));
// require(canTransfer(msg.sender));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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 override returns (bool hello) {
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.
*/
function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
3031,
3182
]
} | 55,632 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | Solidity | StandardToken | contract StandardToken is ERC20Basic, Ownable {
uint256 public totalSupply;
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public override returns (bool trans1) {
require(_to != address(0));
//require(canTransfer(msg.sender));
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
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.
*/
function balanceOf(address _owner) public view override returns (uint256 balance) {
return balances[_owner];
}
mapping (address => mapping (address => uint256)) 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 override returns (bool trans) {
require(_to != address(0));
// require(canTransfer(msg.sender));
uint256 _allowance = allowed[_from][msg.sender];
// Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
// require (_value <= _allowance);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = _allowance.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 override returns (bool hello) {
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.
*/
function allowance(address _owner, address _spender) public view override returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
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;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
3427,
3705
]
} | 55,633 |
AFA | AFA.sol | 0x90b664b2bf9c818ded2b6daa8a430b7985936522 | Solidity | BurnableToken | contract BurnableToken is StandardToken {
event Burn(address indexed burner, uint256 value);
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint256 _value) public {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value);
emit Transfer(burner, address(0), _value);
}
} | /**
* @title Burnable Token
* @dev Token that can be irreversibly burned (destroyed).
*/ | NatSpecMultiLine | burn | function burn(uint256 _value) public {
require(_value > 0);
require(_value <= balances[msg.sender]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure
address burner = msg.sender;
balances[burner] = balances[burner].sub(_value);
totalSupply = totalSupply.sub(_value);
emit Burn(burner, _value);
emit Transfer(burner, address(0), _value);
}
| /**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | None | ipfs://6187e122b35825c082e41c0019528ac3720114fadf34023a185f790250ce554d | {
"func_code_index": [
225,
770
]
} | 55,634 |
Expiry | contracts/protocol/lib/Storage.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Storage | library Storage {
using Cache for Cache.MarketCache;
using Storage for Storage.State;
using Math for uint256;
using Types for Types.Par;
using Types for Types.Wei;
using SafeMath for uint256;
// ============ Constants ============
bytes32 constant FILE = "Storage";
// ============ Structs ============
// All information necessary for tracking a market
struct Market {
// Contract address of the associated ERC20 token
address token;
// Total aggregated supply and borrow amount of the entire market
Types.TotalPar totalPar;
// Interest index of the market
Interest.Index index;
// Contract address of the price oracle for this market
IPriceOracle priceOracle;
// Contract address of the interest setter for this market
IInterestSetter interestSetter;
// Multiplier on the marginRatio for this market
Decimal.D256 marginPremium;
// Multiplier on the liquidationSpread for this market
Decimal.D256 spreadPremium;
// Whether additional borrows are allowed for this market
bool isClosing;
}
// The global risk parameters that govern the health and security of the system
struct RiskParams {
// Required ratio of over-collateralization
Decimal.D256 marginRatio;
// Percentage penalty incurred by liquidated accounts
Decimal.D256 liquidationSpread;
// Percentage of the borrower's interest fee that gets passed to the suppliers
Decimal.D256 earningsRate;
// The minimum absolute borrow value of an account
// There must be sufficient incentivize to liquidate undercollateralized accounts
Monetary.Value minBorrowedValue;
}
// The maximum RiskParam values that can be set
struct RiskLimits {
uint64 marginRatioMax;
uint64 liquidationSpreadMax;
uint64 earningsRateMax;
uint64 marginPremiumMax;
uint64 spreadPremiumMax;
uint128 minBorrowedValueMax;
}
// The entire storage state of Solo
struct State {
// number of markets
uint256 numMarkets;
// marketId => Market
mapping (uint256 => Market) markets;
// owner => account number => Account
mapping (address => mapping (uint256 => Account.Storage)) accounts;
// Addresses that can control other users accounts
mapping (address => mapping (address => bool)) operators;
// Addresses that can control all users accounts
mapping (address => bool) globalOperators;
// mutable risk parameters of the system
RiskParams riskParams;
// immutable risk limits of the system
RiskLimits riskLimits;
}
// ============ Functions ============
function getToken(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (address)
{
return state.markets[marketId].token;
}
function getTotalPar(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.TotalPar memory)
{
return state.markets[marketId].totalPar;
}
function getIndex(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Interest.Index memory)
{
return state.markets[marketId].index;
}
function getNumExcessTokens(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Interest.Index memory index = state.getIndex(marketId);
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
address token = state.getToken(marketId);
Types.Wei memory balanceWei = Types.Wei({
sign: true,
value: Token.balanceOf(token, address(this))
});
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
// borrowWei is negative, so subtracting it makes the value more positive
return balanceWei.sub(borrowWei).sub(supplyWei);
}
function getStatus(
Storage.State storage state,
Account.Info memory account
)
internal
view
returns (Account.Status)
{
return state.accounts[account.owner][account.number].status;
}
function getPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Par memory)
{
return state.accounts[account.owner][account.number].balances[marketId];
}
function getWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Types.Par memory par = state.getPar(account, marketId);
if (par.isZero()) {
return Types.zeroWei();
}
Interest.Index memory index = state.getIndex(marketId);
return Interest.parToWei(par, index);
}
function getLiquidationSpreadForPair(
Storage.State storage state,
uint256 heldMarketId,
uint256 owedMarketId
)
internal
view
returns (Decimal.D256 memory)
{
uint256 result = state.riskParams.liquidationSpread.value;
result = Decimal.mul(result, Decimal.onePlus(state.markets[heldMarketId].spreadPremium));
result = Decimal.mul(result, Decimal.onePlus(state.markets[owedMarketId].spreadPremium));
return Decimal.D256({
value: result
});
}
function fetchNewIndex(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Index memory)
{
Interest.Rate memory rate = state.fetchInterestRate(marketId, index);
return Interest.calculateNewIndex(
index,
rate,
state.getTotalPar(marketId),
state.riskParams.earningsRate
);
}
function fetchInterestRate(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Rate memory)
{
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
Interest.Rate memory rate = state.markets[marketId].interestSetter.getInterestRate(
state.getToken(marketId),
borrowWei.value,
supplyWei.value
);
return rate;
}
function fetchPrice(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Monetary.Price memory)
{
IPriceOracle oracle = IPriceOracle(state.markets[marketId].priceOracle);
Monetary.Price memory price = oracle.getPrice(state.getToken(marketId));
Require.that(
price.value != 0,
FILE,
"Price cannot be zero",
marketId
);
return price;
}
function getAccountValues(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool adjustForLiquidity
)
internal
view
returns (Monetary.Value memory, Monetary.Value memory)
{
Monetary.Value memory supplyValue;
Monetary.Value memory borrowValue;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Wei memory userWei = state.getWei(account, m);
if (userWei.isZero()) {
continue;
}
uint256 assetValue = userWei.value.mul(cache.getPrice(m).value);
Decimal.D256 memory adjust = Decimal.one();
if (adjustForLiquidity) {
adjust = Decimal.onePlus(state.markets[m].marginPremium);
}
if (userWei.sign) {
supplyValue.value = supplyValue.value.add(Decimal.div(assetValue, adjust));
} else {
borrowValue.value = borrowValue.value.add(Decimal.mul(assetValue, adjust));
}
}
return (supplyValue, borrowValue);
}
function isCollateralized(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool requireMinBorrow
)
internal
view
returns (bool)
{
// get account values (adjusted for liquidity)
(
Monetary.Value memory supplyValue,
Monetary.Value memory borrowValue
) = state.getAccountValues(account, cache, /* adjustForLiquidity = */ true);
if (borrowValue.value == 0) {
return true;
}
if (requireMinBorrow) {
Require.that(
borrowValue.value >= state.riskParams.minBorrowedValue.value,
FILE,
"Borrow value too low",
account.owner,
account.number,
borrowValue.value
);
}
uint256 requiredMargin = Decimal.mul(borrowValue.value, state.riskParams.marginRatio);
return supplyValue.value >= borrowValue.value.add(requiredMargin);
}
function isGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
returns (bool)
{
return state.globalOperators[operator];
}
function isLocalOperator(
Storage.State storage state,
address owner,
address operator
)
internal
view
returns (bool)
{
return state.operators[owner][operator];
}
function requireIsGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
{
bool isValidOperator = state.isGlobalOperator(operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned global operator",
operator
);
}
function requireIsOperator(
Storage.State storage state,
Account.Info memory account,
address operator
)
internal
view
{
bool isValidOperator =
operator == account.owner
|| state.isGlobalOperator(operator)
|| state.isLocalOperator(account.owner, operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned operator",
operator
);
}
/**
* Determine and set an account's balance based on the intended balance change. Return the
* equivalent amount in wei
*/
function getNewParAndDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (amount.value == 0 && amount.ref == Types.AssetReference.Delta) {
return (oldPar, Types.zeroWei());
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = Interest.parToWei(oldPar, index);
Types.Par memory newPar;
Types.Wei memory deltaWei;
if (amount.denomination == Types.AssetDenomination.Wei) {
deltaWei = Types.Wei({
sign: amount.sign,
value: amount.value
});
if (amount.ref == Types.AssetReference.Target) {
deltaWei = deltaWei.sub(oldWei);
}
newPar = Interest.weiToPar(oldWei.add(deltaWei), index);
} else { // AssetDenomination.Par
newPar = Types.Par({
sign: amount.sign,
value: amount.value.to128()
});
if (amount.ref == Types.AssetReference.Delta) {
newPar = oldPar.add(newPar);
}
deltaWei = Interest.parToWei(newPar, index).sub(oldWei);
}
return (newPar, deltaWei);
}
function getNewParAndDeltaWeiForLiquidation(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
Require.that(
!oldPar.isPositive(),
FILE,
"Owed balance cannot be positive",
account.owner,
account.number,
marketId
);
(
Types.Par memory newPar,
Types.Wei memory deltaWei
) = state.getNewParAndDeltaWei(
account,
marketId,
amount
);
// if attempting to over-repay the owed asset, bound it by the maximum
if (newPar.isPositive()) {
newPar = Types.zeroPar();
deltaWei = state.getWei(account, marketId).negative();
}
Require.that(
!deltaWei.isNegative() && oldPar.value >= newPar.value,
FILE,
"Owed balance cannot increase",
account.owner,
account.number,
marketId
);
// if not paying back enough wei to repay any par, then bound wei to zero
if (oldPar.equals(newPar)) {
deltaWei = Types.zeroWei();
}
return (newPar, deltaWei);
}
function isVaporizable(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache
)
internal
view
returns (bool)
{
bool hasNegative = false;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Par memory par = state.getPar(account, m);
if (par.isZero()) {
continue;
} else if (par.sign) {
return false;
} else {
hasNegative = true;
}
}
return hasNegative;
}
// =============== Setter Functions ===============
function updateIndex(
Storage.State storage state,
uint256 marketId
)
internal
returns (Interest.Index memory)
{
Interest.Index memory index = state.getIndex(marketId);
if (index.lastUpdate == Time.currentTime()) {
return index;
}
return state.markets[marketId].index = state.fetchNewIndex(marketId, index);
}
function setStatus(
Storage.State storage state,
Account.Info memory account,
Account.Status status
)
internal
{
state.accounts[account.owner][account.number].status = status;
}
function setPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Par memory newPar
)
internal
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (Types.equals(oldPar, newPar)) {
return;
}
// updateTotalPar
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
// roll-back oldPar
if (oldPar.sign) {
totalPar.supply = uint256(totalPar.supply).sub(oldPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).sub(oldPar.value).to128();
}
// roll-forward newPar
if (newPar.sign) {
totalPar.supply = uint256(totalPar.supply).add(newPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).add(newPar.value).to128();
}
state.markets[marketId].totalPar = totalPar;
state.accounts[account.owner][account.number].balances[marketId] = newPar;
}
/**
* Determine and set an account's balance based on a change in wei
*/
function setParFromDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Wei memory deltaWei
)
internal
{
if (deltaWei.isZero()) {
return;
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = state.getWei(account, marketId);
Types.Wei memory newWei = oldWei.add(deltaWei);
Types.Par memory newPar = Interest.weiToPar(newWei, index);
state.setPar(
account,
marketId,
newPar
);
}
} | /**
* @title Storage
* @author dYdX
*
* Functions for reading, writing, and verifying state in Solo
*/ | NatSpecMultiLine | getToken | function getToken(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (address)
{
return state.markets[marketId].token;
}
| // ============ Functions ============ | LineComment | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
2935,
3149
]
} | 55,635 |
Expiry | contracts/protocol/lib/Storage.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Storage | library Storage {
using Cache for Cache.MarketCache;
using Storage for Storage.State;
using Math for uint256;
using Types for Types.Par;
using Types for Types.Wei;
using SafeMath for uint256;
// ============ Constants ============
bytes32 constant FILE = "Storage";
// ============ Structs ============
// All information necessary for tracking a market
struct Market {
// Contract address of the associated ERC20 token
address token;
// Total aggregated supply and borrow amount of the entire market
Types.TotalPar totalPar;
// Interest index of the market
Interest.Index index;
// Contract address of the price oracle for this market
IPriceOracle priceOracle;
// Contract address of the interest setter for this market
IInterestSetter interestSetter;
// Multiplier on the marginRatio for this market
Decimal.D256 marginPremium;
// Multiplier on the liquidationSpread for this market
Decimal.D256 spreadPremium;
// Whether additional borrows are allowed for this market
bool isClosing;
}
// The global risk parameters that govern the health and security of the system
struct RiskParams {
// Required ratio of over-collateralization
Decimal.D256 marginRatio;
// Percentage penalty incurred by liquidated accounts
Decimal.D256 liquidationSpread;
// Percentage of the borrower's interest fee that gets passed to the suppliers
Decimal.D256 earningsRate;
// The minimum absolute borrow value of an account
// There must be sufficient incentivize to liquidate undercollateralized accounts
Monetary.Value minBorrowedValue;
}
// The maximum RiskParam values that can be set
struct RiskLimits {
uint64 marginRatioMax;
uint64 liquidationSpreadMax;
uint64 earningsRateMax;
uint64 marginPremiumMax;
uint64 spreadPremiumMax;
uint128 minBorrowedValueMax;
}
// The entire storage state of Solo
struct State {
// number of markets
uint256 numMarkets;
// marketId => Market
mapping (uint256 => Market) markets;
// owner => account number => Account
mapping (address => mapping (uint256 => Account.Storage)) accounts;
// Addresses that can control other users accounts
mapping (address => mapping (address => bool)) operators;
// Addresses that can control all users accounts
mapping (address => bool) globalOperators;
// mutable risk parameters of the system
RiskParams riskParams;
// immutable risk limits of the system
RiskLimits riskLimits;
}
// ============ Functions ============
function getToken(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (address)
{
return state.markets[marketId].token;
}
function getTotalPar(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.TotalPar memory)
{
return state.markets[marketId].totalPar;
}
function getIndex(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Interest.Index memory)
{
return state.markets[marketId].index;
}
function getNumExcessTokens(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Interest.Index memory index = state.getIndex(marketId);
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
address token = state.getToken(marketId);
Types.Wei memory balanceWei = Types.Wei({
sign: true,
value: Token.balanceOf(token, address(this))
});
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
// borrowWei is negative, so subtracting it makes the value more positive
return balanceWei.sub(borrowWei).sub(supplyWei);
}
function getStatus(
Storage.State storage state,
Account.Info memory account
)
internal
view
returns (Account.Status)
{
return state.accounts[account.owner][account.number].status;
}
function getPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Par memory)
{
return state.accounts[account.owner][account.number].balances[marketId];
}
function getWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Types.Par memory par = state.getPar(account, marketId);
if (par.isZero()) {
return Types.zeroWei();
}
Interest.Index memory index = state.getIndex(marketId);
return Interest.parToWei(par, index);
}
function getLiquidationSpreadForPair(
Storage.State storage state,
uint256 heldMarketId,
uint256 owedMarketId
)
internal
view
returns (Decimal.D256 memory)
{
uint256 result = state.riskParams.liquidationSpread.value;
result = Decimal.mul(result, Decimal.onePlus(state.markets[heldMarketId].spreadPremium));
result = Decimal.mul(result, Decimal.onePlus(state.markets[owedMarketId].spreadPremium));
return Decimal.D256({
value: result
});
}
function fetchNewIndex(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Index memory)
{
Interest.Rate memory rate = state.fetchInterestRate(marketId, index);
return Interest.calculateNewIndex(
index,
rate,
state.getTotalPar(marketId),
state.riskParams.earningsRate
);
}
function fetchInterestRate(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Rate memory)
{
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
Interest.Rate memory rate = state.markets[marketId].interestSetter.getInterestRate(
state.getToken(marketId),
borrowWei.value,
supplyWei.value
);
return rate;
}
function fetchPrice(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Monetary.Price memory)
{
IPriceOracle oracle = IPriceOracle(state.markets[marketId].priceOracle);
Monetary.Price memory price = oracle.getPrice(state.getToken(marketId));
Require.that(
price.value != 0,
FILE,
"Price cannot be zero",
marketId
);
return price;
}
function getAccountValues(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool adjustForLiquidity
)
internal
view
returns (Monetary.Value memory, Monetary.Value memory)
{
Monetary.Value memory supplyValue;
Monetary.Value memory borrowValue;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Wei memory userWei = state.getWei(account, m);
if (userWei.isZero()) {
continue;
}
uint256 assetValue = userWei.value.mul(cache.getPrice(m).value);
Decimal.D256 memory adjust = Decimal.one();
if (adjustForLiquidity) {
adjust = Decimal.onePlus(state.markets[m].marginPremium);
}
if (userWei.sign) {
supplyValue.value = supplyValue.value.add(Decimal.div(assetValue, adjust));
} else {
borrowValue.value = borrowValue.value.add(Decimal.mul(assetValue, adjust));
}
}
return (supplyValue, borrowValue);
}
function isCollateralized(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool requireMinBorrow
)
internal
view
returns (bool)
{
// get account values (adjusted for liquidity)
(
Monetary.Value memory supplyValue,
Monetary.Value memory borrowValue
) = state.getAccountValues(account, cache, /* adjustForLiquidity = */ true);
if (borrowValue.value == 0) {
return true;
}
if (requireMinBorrow) {
Require.that(
borrowValue.value >= state.riskParams.minBorrowedValue.value,
FILE,
"Borrow value too low",
account.owner,
account.number,
borrowValue.value
);
}
uint256 requiredMargin = Decimal.mul(borrowValue.value, state.riskParams.marginRatio);
return supplyValue.value >= borrowValue.value.add(requiredMargin);
}
function isGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
returns (bool)
{
return state.globalOperators[operator];
}
function isLocalOperator(
Storage.State storage state,
address owner,
address operator
)
internal
view
returns (bool)
{
return state.operators[owner][operator];
}
function requireIsGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
{
bool isValidOperator = state.isGlobalOperator(operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned global operator",
operator
);
}
function requireIsOperator(
Storage.State storage state,
Account.Info memory account,
address operator
)
internal
view
{
bool isValidOperator =
operator == account.owner
|| state.isGlobalOperator(operator)
|| state.isLocalOperator(account.owner, operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned operator",
operator
);
}
/**
* Determine and set an account's balance based on the intended balance change. Return the
* equivalent amount in wei
*/
function getNewParAndDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (amount.value == 0 && amount.ref == Types.AssetReference.Delta) {
return (oldPar, Types.zeroWei());
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = Interest.parToWei(oldPar, index);
Types.Par memory newPar;
Types.Wei memory deltaWei;
if (amount.denomination == Types.AssetDenomination.Wei) {
deltaWei = Types.Wei({
sign: amount.sign,
value: amount.value
});
if (amount.ref == Types.AssetReference.Target) {
deltaWei = deltaWei.sub(oldWei);
}
newPar = Interest.weiToPar(oldWei.add(deltaWei), index);
} else { // AssetDenomination.Par
newPar = Types.Par({
sign: amount.sign,
value: amount.value.to128()
});
if (amount.ref == Types.AssetReference.Delta) {
newPar = oldPar.add(newPar);
}
deltaWei = Interest.parToWei(newPar, index).sub(oldWei);
}
return (newPar, deltaWei);
}
function getNewParAndDeltaWeiForLiquidation(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
Require.that(
!oldPar.isPositive(),
FILE,
"Owed balance cannot be positive",
account.owner,
account.number,
marketId
);
(
Types.Par memory newPar,
Types.Wei memory deltaWei
) = state.getNewParAndDeltaWei(
account,
marketId,
amount
);
// if attempting to over-repay the owed asset, bound it by the maximum
if (newPar.isPositive()) {
newPar = Types.zeroPar();
deltaWei = state.getWei(account, marketId).negative();
}
Require.that(
!deltaWei.isNegative() && oldPar.value >= newPar.value,
FILE,
"Owed balance cannot increase",
account.owner,
account.number,
marketId
);
// if not paying back enough wei to repay any par, then bound wei to zero
if (oldPar.equals(newPar)) {
deltaWei = Types.zeroWei();
}
return (newPar, deltaWei);
}
function isVaporizable(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache
)
internal
view
returns (bool)
{
bool hasNegative = false;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Par memory par = state.getPar(account, m);
if (par.isZero()) {
continue;
} else if (par.sign) {
return false;
} else {
hasNegative = true;
}
}
return hasNegative;
}
// =============== Setter Functions ===============
function updateIndex(
Storage.State storage state,
uint256 marketId
)
internal
returns (Interest.Index memory)
{
Interest.Index memory index = state.getIndex(marketId);
if (index.lastUpdate == Time.currentTime()) {
return index;
}
return state.markets[marketId].index = state.fetchNewIndex(marketId, index);
}
function setStatus(
Storage.State storage state,
Account.Info memory account,
Account.Status status
)
internal
{
state.accounts[account.owner][account.number].status = status;
}
function setPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Par memory newPar
)
internal
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (Types.equals(oldPar, newPar)) {
return;
}
// updateTotalPar
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
// roll-back oldPar
if (oldPar.sign) {
totalPar.supply = uint256(totalPar.supply).sub(oldPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).sub(oldPar.value).to128();
}
// roll-forward newPar
if (newPar.sign) {
totalPar.supply = uint256(totalPar.supply).add(newPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).add(newPar.value).to128();
}
state.markets[marketId].totalPar = totalPar;
state.accounts[account.owner][account.number].balances[marketId] = newPar;
}
/**
* Determine and set an account's balance based on a change in wei
*/
function setParFromDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Wei memory deltaWei
)
internal
{
if (deltaWei.isZero()) {
return;
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = state.getWei(account, marketId);
Types.Wei memory newWei = oldWei.add(deltaWei);
Types.Par memory newPar = Interest.weiToPar(newWei, index);
state.setPar(
account,
marketId,
newPar
);
}
} | /**
* @title Storage
* @author dYdX
*
* Functions for reading, writing, and verifying state in Solo
*/ | NatSpecMultiLine | getNewParAndDeltaWei | function getNewParAndDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (amount.value == 0 && amount.ref == Types.AssetReference.Delta) {
return (oldPar, Types.zeroWei());
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = Interest.parToWei(oldPar, index);
Types.Par memory newPar;
Types.Wei memory deltaWei;
if (amount.denomination == Types.AssetDenomination.Wei) {
deltaWei = Types.Wei({
sign: amount.sign,
value: amount.value
});
if (amount.ref == Types.AssetReference.Target) {
deltaWei = deltaWei.sub(oldWei);
}
newPar = Interest.weiToPar(oldWei.add(deltaWei), index);
} else { // AssetDenomination.Par
newPar = Types.Par({
sign: amount.sign,
value: amount.value.to128()
});
if (amount.ref == Types.AssetReference.Delta) {
newPar = oldPar.add(newPar);
}
deltaWei = Interest.parToWei(newPar, index).sub(oldWei);
}
return (newPar, deltaWei);
}
| /**
* Determine and set an account's balance based on the intended balance change. Return the
* equivalent amount in wei
*/ | NatSpecMultiLine | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
11642,
13148
]
} | 55,636 |
Expiry | contracts/protocol/lib/Storage.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Storage | library Storage {
using Cache for Cache.MarketCache;
using Storage for Storage.State;
using Math for uint256;
using Types for Types.Par;
using Types for Types.Wei;
using SafeMath for uint256;
// ============ Constants ============
bytes32 constant FILE = "Storage";
// ============ Structs ============
// All information necessary for tracking a market
struct Market {
// Contract address of the associated ERC20 token
address token;
// Total aggregated supply and borrow amount of the entire market
Types.TotalPar totalPar;
// Interest index of the market
Interest.Index index;
// Contract address of the price oracle for this market
IPriceOracle priceOracle;
// Contract address of the interest setter for this market
IInterestSetter interestSetter;
// Multiplier on the marginRatio for this market
Decimal.D256 marginPremium;
// Multiplier on the liquidationSpread for this market
Decimal.D256 spreadPremium;
// Whether additional borrows are allowed for this market
bool isClosing;
}
// The global risk parameters that govern the health and security of the system
struct RiskParams {
// Required ratio of over-collateralization
Decimal.D256 marginRatio;
// Percentage penalty incurred by liquidated accounts
Decimal.D256 liquidationSpread;
// Percentage of the borrower's interest fee that gets passed to the suppliers
Decimal.D256 earningsRate;
// The minimum absolute borrow value of an account
// There must be sufficient incentivize to liquidate undercollateralized accounts
Monetary.Value minBorrowedValue;
}
// The maximum RiskParam values that can be set
struct RiskLimits {
uint64 marginRatioMax;
uint64 liquidationSpreadMax;
uint64 earningsRateMax;
uint64 marginPremiumMax;
uint64 spreadPremiumMax;
uint128 minBorrowedValueMax;
}
// The entire storage state of Solo
struct State {
// number of markets
uint256 numMarkets;
// marketId => Market
mapping (uint256 => Market) markets;
// owner => account number => Account
mapping (address => mapping (uint256 => Account.Storage)) accounts;
// Addresses that can control other users accounts
mapping (address => mapping (address => bool)) operators;
// Addresses that can control all users accounts
mapping (address => bool) globalOperators;
// mutable risk parameters of the system
RiskParams riskParams;
// immutable risk limits of the system
RiskLimits riskLimits;
}
// ============ Functions ============
function getToken(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (address)
{
return state.markets[marketId].token;
}
function getTotalPar(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.TotalPar memory)
{
return state.markets[marketId].totalPar;
}
function getIndex(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Interest.Index memory)
{
return state.markets[marketId].index;
}
function getNumExcessTokens(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Interest.Index memory index = state.getIndex(marketId);
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
address token = state.getToken(marketId);
Types.Wei memory balanceWei = Types.Wei({
sign: true,
value: Token.balanceOf(token, address(this))
});
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
// borrowWei is negative, so subtracting it makes the value more positive
return balanceWei.sub(borrowWei).sub(supplyWei);
}
function getStatus(
Storage.State storage state,
Account.Info memory account
)
internal
view
returns (Account.Status)
{
return state.accounts[account.owner][account.number].status;
}
function getPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Par memory)
{
return state.accounts[account.owner][account.number].balances[marketId];
}
function getWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Types.Par memory par = state.getPar(account, marketId);
if (par.isZero()) {
return Types.zeroWei();
}
Interest.Index memory index = state.getIndex(marketId);
return Interest.parToWei(par, index);
}
function getLiquidationSpreadForPair(
Storage.State storage state,
uint256 heldMarketId,
uint256 owedMarketId
)
internal
view
returns (Decimal.D256 memory)
{
uint256 result = state.riskParams.liquidationSpread.value;
result = Decimal.mul(result, Decimal.onePlus(state.markets[heldMarketId].spreadPremium));
result = Decimal.mul(result, Decimal.onePlus(state.markets[owedMarketId].spreadPremium));
return Decimal.D256({
value: result
});
}
function fetchNewIndex(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Index memory)
{
Interest.Rate memory rate = state.fetchInterestRate(marketId, index);
return Interest.calculateNewIndex(
index,
rate,
state.getTotalPar(marketId),
state.riskParams.earningsRate
);
}
function fetchInterestRate(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Rate memory)
{
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
Interest.Rate memory rate = state.markets[marketId].interestSetter.getInterestRate(
state.getToken(marketId),
borrowWei.value,
supplyWei.value
);
return rate;
}
function fetchPrice(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Monetary.Price memory)
{
IPriceOracle oracle = IPriceOracle(state.markets[marketId].priceOracle);
Monetary.Price memory price = oracle.getPrice(state.getToken(marketId));
Require.that(
price.value != 0,
FILE,
"Price cannot be zero",
marketId
);
return price;
}
function getAccountValues(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool adjustForLiquidity
)
internal
view
returns (Monetary.Value memory, Monetary.Value memory)
{
Monetary.Value memory supplyValue;
Monetary.Value memory borrowValue;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Wei memory userWei = state.getWei(account, m);
if (userWei.isZero()) {
continue;
}
uint256 assetValue = userWei.value.mul(cache.getPrice(m).value);
Decimal.D256 memory adjust = Decimal.one();
if (adjustForLiquidity) {
adjust = Decimal.onePlus(state.markets[m].marginPremium);
}
if (userWei.sign) {
supplyValue.value = supplyValue.value.add(Decimal.div(assetValue, adjust));
} else {
borrowValue.value = borrowValue.value.add(Decimal.mul(assetValue, adjust));
}
}
return (supplyValue, borrowValue);
}
function isCollateralized(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool requireMinBorrow
)
internal
view
returns (bool)
{
// get account values (adjusted for liquidity)
(
Monetary.Value memory supplyValue,
Monetary.Value memory borrowValue
) = state.getAccountValues(account, cache, /* adjustForLiquidity = */ true);
if (borrowValue.value == 0) {
return true;
}
if (requireMinBorrow) {
Require.that(
borrowValue.value >= state.riskParams.minBorrowedValue.value,
FILE,
"Borrow value too low",
account.owner,
account.number,
borrowValue.value
);
}
uint256 requiredMargin = Decimal.mul(borrowValue.value, state.riskParams.marginRatio);
return supplyValue.value >= borrowValue.value.add(requiredMargin);
}
function isGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
returns (bool)
{
return state.globalOperators[operator];
}
function isLocalOperator(
Storage.State storage state,
address owner,
address operator
)
internal
view
returns (bool)
{
return state.operators[owner][operator];
}
function requireIsGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
{
bool isValidOperator = state.isGlobalOperator(operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned global operator",
operator
);
}
function requireIsOperator(
Storage.State storage state,
Account.Info memory account,
address operator
)
internal
view
{
bool isValidOperator =
operator == account.owner
|| state.isGlobalOperator(operator)
|| state.isLocalOperator(account.owner, operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned operator",
operator
);
}
/**
* Determine and set an account's balance based on the intended balance change. Return the
* equivalent amount in wei
*/
function getNewParAndDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (amount.value == 0 && amount.ref == Types.AssetReference.Delta) {
return (oldPar, Types.zeroWei());
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = Interest.parToWei(oldPar, index);
Types.Par memory newPar;
Types.Wei memory deltaWei;
if (amount.denomination == Types.AssetDenomination.Wei) {
deltaWei = Types.Wei({
sign: amount.sign,
value: amount.value
});
if (amount.ref == Types.AssetReference.Target) {
deltaWei = deltaWei.sub(oldWei);
}
newPar = Interest.weiToPar(oldWei.add(deltaWei), index);
} else { // AssetDenomination.Par
newPar = Types.Par({
sign: amount.sign,
value: amount.value.to128()
});
if (amount.ref == Types.AssetReference.Delta) {
newPar = oldPar.add(newPar);
}
deltaWei = Interest.parToWei(newPar, index).sub(oldWei);
}
return (newPar, deltaWei);
}
function getNewParAndDeltaWeiForLiquidation(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
Require.that(
!oldPar.isPositive(),
FILE,
"Owed balance cannot be positive",
account.owner,
account.number,
marketId
);
(
Types.Par memory newPar,
Types.Wei memory deltaWei
) = state.getNewParAndDeltaWei(
account,
marketId,
amount
);
// if attempting to over-repay the owed asset, bound it by the maximum
if (newPar.isPositive()) {
newPar = Types.zeroPar();
deltaWei = state.getWei(account, marketId).negative();
}
Require.that(
!deltaWei.isNegative() && oldPar.value >= newPar.value,
FILE,
"Owed balance cannot increase",
account.owner,
account.number,
marketId
);
// if not paying back enough wei to repay any par, then bound wei to zero
if (oldPar.equals(newPar)) {
deltaWei = Types.zeroWei();
}
return (newPar, deltaWei);
}
function isVaporizable(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache
)
internal
view
returns (bool)
{
bool hasNegative = false;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Par memory par = state.getPar(account, m);
if (par.isZero()) {
continue;
} else if (par.sign) {
return false;
} else {
hasNegative = true;
}
}
return hasNegative;
}
// =============== Setter Functions ===============
function updateIndex(
Storage.State storage state,
uint256 marketId
)
internal
returns (Interest.Index memory)
{
Interest.Index memory index = state.getIndex(marketId);
if (index.lastUpdate == Time.currentTime()) {
return index;
}
return state.markets[marketId].index = state.fetchNewIndex(marketId, index);
}
function setStatus(
Storage.State storage state,
Account.Info memory account,
Account.Status status
)
internal
{
state.accounts[account.owner][account.number].status = status;
}
function setPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Par memory newPar
)
internal
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (Types.equals(oldPar, newPar)) {
return;
}
// updateTotalPar
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
// roll-back oldPar
if (oldPar.sign) {
totalPar.supply = uint256(totalPar.supply).sub(oldPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).sub(oldPar.value).to128();
}
// roll-forward newPar
if (newPar.sign) {
totalPar.supply = uint256(totalPar.supply).add(newPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).add(newPar.value).to128();
}
state.markets[marketId].totalPar = totalPar;
state.accounts[account.owner][account.number].balances[marketId] = newPar;
}
/**
* Determine and set an account's balance based on a change in wei
*/
function setParFromDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Wei memory deltaWei
)
internal
{
if (deltaWei.isZero()) {
return;
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = state.getWei(account, marketId);
Types.Wei memory newWei = oldWei.add(deltaWei);
Types.Par memory newPar = Interest.weiToPar(newWei, index);
state.setPar(
account,
marketId,
newPar
);
}
} | /**
* @title Storage
* @author dYdX
*
* Functions for reading, writing, and verifying state in Solo
*/ | NatSpecMultiLine | updateIndex | function updateIndex(
Storage.State storage state,
uint256 marketId
)
internal
returns (Interest.Index memory)
{
Interest.Index memory index = state.getIndex(marketId);
if (index.lastUpdate == Time.currentTime()) {
return index;
}
return state.markets[marketId].index = state.fetchNewIndex(marketId, index);
}
| // =============== Setter Functions =============== | LineComment | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
15454,
15868
]
} | 55,637 |
Expiry | contracts/protocol/lib/Storage.sol | 0x736aed44debed3c273af836409deaaf6722671b2 | Solidity | Storage | library Storage {
using Cache for Cache.MarketCache;
using Storage for Storage.State;
using Math for uint256;
using Types for Types.Par;
using Types for Types.Wei;
using SafeMath for uint256;
// ============ Constants ============
bytes32 constant FILE = "Storage";
// ============ Structs ============
// All information necessary for tracking a market
struct Market {
// Contract address of the associated ERC20 token
address token;
// Total aggregated supply and borrow amount of the entire market
Types.TotalPar totalPar;
// Interest index of the market
Interest.Index index;
// Contract address of the price oracle for this market
IPriceOracle priceOracle;
// Contract address of the interest setter for this market
IInterestSetter interestSetter;
// Multiplier on the marginRatio for this market
Decimal.D256 marginPremium;
// Multiplier on the liquidationSpread for this market
Decimal.D256 spreadPremium;
// Whether additional borrows are allowed for this market
bool isClosing;
}
// The global risk parameters that govern the health and security of the system
struct RiskParams {
// Required ratio of over-collateralization
Decimal.D256 marginRatio;
// Percentage penalty incurred by liquidated accounts
Decimal.D256 liquidationSpread;
// Percentage of the borrower's interest fee that gets passed to the suppliers
Decimal.D256 earningsRate;
// The minimum absolute borrow value of an account
// There must be sufficient incentivize to liquidate undercollateralized accounts
Monetary.Value minBorrowedValue;
}
// The maximum RiskParam values that can be set
struct RiskLimits {
uint64 marginRatioMax;
uint64 liquidationSpreadMax;
uint64 earningsRateMax;
uint64 marginPremiumMax;
uint64 spreadPremiumMax;
uint128 minBorrowedValueMax;
}
// The entire storage state of Solo
struct State {
// number of markets
uint256 numMarkets;
// marketId => Market
mapping (uint256 => Market) markets;
// owner => account number => Account
mapping (address => mapping (uint256 => Account.Storage)) accounts;
// Addresses that can control other users accounts
mapping (address => mapping (address => bool)) operators;
// Addresses that can control all users accounts
mapping (address => bool) globalOperators;
// mutable risk parameters of the system
RiskParams riskParams;
// immutable risk limits of the system
RiskLimits riskLimits;
}
// ============ Functions ============
function getToken(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (address)
{
return state.markets[marketId].token;
}
function getTotalPar(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.TotalPar memory)
{
return state.markets[marketId].totalPar;
}
function getIndex(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Interest.Index memory)
{
return state.markets[marketId].index;
}
function getNumExcessTokens(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Interest.Index memory index = state.getIndex(marketId);
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
address token = state.getToken(marketId);
Types.Wei memory balanceWei = Types.Wei({
sign: true,
value: Token.balanceOf(token, address(this))
});
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
// borrowWei is negative, so subtracting it makes the value more positive
return balanceWei.sub(borrowWei).sub(supplyWei);
}
function getStatus(
Storage.State storage state,
Account.Info memory account
)
internal
view
returns (Account.Status)
{
return state.accounts[account.owner][account.number].status;
}
function getPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Par memory)
{
return state.accounts[account.owner][account.number].balances[marketId];
}
function getWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId
)
internal
view
returns (Types.Wei memory)
{
Types.Par memory par = state.getPar(account, marketId);
if (par.isZero()) {
return Types.zeroWei();
}
Interest.Index memory index = state.getIndex(marketId);
return Interest.parToWei(par, index);
}
function getLiquidationSpreadForPair(
Storage.State storage state,
uint256 heldMarketId,
uint256 owedMarketId
)
internal
view
returns (Decimal.D256 memory)
{
uint256 result = state.riskParams.liquidationSpread.value;
result = Decimal.mul(result, Decimal.onePlus(state.markets[heldMarketId].spreadPremium));
result = Decimal.mul(result, Decimal.onePlus(state.markets[owedMarketId].spreadPremium));
return Decimal.D256({
value: result
});
}
function fetchNewIndex(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Index memory)
{
Interest.Rate memory rate = state.fetchInterestRate(marketId, index);
return Interest.calculateNewIndex(
index,
rate,
state.getTotalPar(marketId),
state.riskParams.earningsRate
);
}
function fetchInterestRate(
Storage.State storage state,
uint256 marketId,
Interest.Index memory index
)
internal
view
returns (Interest.Rate memory)
{
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
(
Types.Wei memory supplyWei,
Types.Wei memory borrowWei
) = Interest.totalParToWei(totalPar, index);
Interest.Rate memory rate = state.markets[marketId].interestSetter.getInterestRate(
state.getToken(marketId),
borrowWei.value,
supplyWei.value
);
return rate;
}
function fetchPrice(
Storage.State storage state,
uint256 marketId
)
internal
view
returns (Monetary.Price memory)
{
IPriceOracle oracle = IPriceOracle(state.markets[marketId].priceOracle);
Monetary.Price memory price = oracle.getPrice(state.getToken(marketId));
Require.that(
price.value != 0,
FILE,
"Price cannot be zero",
marketId
);
return price;
}
function getAccountValues(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool adjustForLiquidity
)
internal
view
returns (Monetary.Value memory, Monetary.Value memory)
{
Monetary.Value memory supplyValue;
Monetary.Value memory borrowValue;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Wei memory userWei = state.getWei(account, m);
if (userWei.isZero()) {
continue;
}
uint256 assetValue = userWei.value.mul(cache.getPrice(m).value);
Decimal.D256 memory adjust = Decimal.one();
if (adjustForLiquidity) {
adjust = Decimal.onePlus(state.markets[m].marginPremium);
}
if (userWei.sign) {
supplyValue.value = supplyValue.value.add(Decimal.div(assetValue, adjust));
} else {
borrowValue.value = borrowValue.value.add(Decimal.mul(assetValue, adjust));
}
}
return (supplyValue, borrowValue);
}
function isCollateralized(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache,
bool requireMinBorrow
)
internal
view
returns (bool)
{
// get account values (adjusted for liquidity)
(
Monetary.Value memory supplyValue,
Monetary.Value memory borrowValue
) = state.getAccountValues(account, cache, /* adjustForLiquidity = */ true);
if (borrowValue.value == 0) {
return true;
}
if (requireMinBorrow) {
Require.that(
borrowValue.value >= state.riskParams.minBorrowedValue.value,
FILE,
"Borrow value too low",
account.owner,
account.number,
borrowValue.value
);
}
uint256 requiredMargin = Decimal.mul(borrowValue.value, state.riskParams.marginRatio);
return supplyValue.value >= borrowValue.value.add(requiredMargin);
}
function isGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
returns (bool)
{
return state.globalOperators[operator];
}
function isLocalOperator(
Storage.State storage state,
address owner,
address operator
)
internal
view
returns (bool)
{
return state.operators[owner][operator];
}
function requireIsGlobalOperator(
Storage.State storage state,
address operator
)
internal
view
{
bool isValidOperator = state.isGlobalOperator(operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned global operator",
operator
);
}
function requireIsOperator(
Storage.State storage state,
Account.Info memory account,
address operator
)
internal
view
{
bool isValidOperator =
operator == account.owner
|| state.isGlobalOperator(operator)
|| state.isLocalOperator(account.owner, operator);
Require.that(
isValidOperator,
FILE,
"Unpermissioned operator",
operator
);
}
/**
* Determine and set an account's balance based on the intended balance change. Return the
* equivalent amount in wei
*/
function getNewParAndDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (amount.value == 0 && amount.ref == Types.AssetReference.Delta) {
return (oldPar, Types.zeroWei());
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = Interest.parToWei(oldPar, index);
Types.Par memory newPar;
Types.Wei memory deltaWei;
if (amount.denomination == Types.AssetDenomination.Wei) {
deltaWei = Types.Wei({
sign: amount.sign,
value: amount.value
});
if (amount.ref == Types.AssetReference.Target) {
deltaWei = deltaWei.sub(oldWei);
}
newPar = Interest.weiToPar(oldWei.add(deltaWei), index);
} else { // AssetDenomination.Par
newPar = Types.Par({
sign: amount.sign,
value: amount.value.to128()
});
if (amount.ref == Types.AssetReference.Delta) {
newPar = oldPar.add(newPar);
}
deltaWei = Interest.parToWei(newPar, index).sub(oldWei);
}
return (newPar, deltaWei);
}
function getNewParAndDeltaWeiForLiquidation(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.AssetAmount memory amount
)
internal
view
returns (Types.Par memory, Types.Wei memory)
{
Types.Par memory oldPar = state.getPar(account, marketId);
Require.that(
!oldPar.isPositive(),
FILE,
"Owed balance cannot be positive",
account.owner,
account.number,
marketId
);
(
Types.Par memory newPar,
Types.Wei memory deltaWei
) = state.getNewParAndDeltaWei(
account,
marketId,
amount
);
// if attempting to over-repay the owed asset, bound it by the maximum
if (newPar.isPositive()) {
newPar = Types.zeroPar();
deltaWei = state.getWei(account, marketId).negative();
}
Require.that(
!deltaWei.isNegative() && oldPar.value >= newPar.value,
FILE,
"Owed balance cannot increase",
account.owner,
account.number,
marketId
);
// if not paying back enough wei to repay any par, then bound wei to zero
if (oldPar.equals(newPar)) {
deltaWei = Types.zeroWei();
}
return (newPar, deltaWei);
}
function isVaporizable(
Storage.State storage state,
Account.Info memory account,
Cache.MarketCache memory cache
)
internal
view
returns (bool)
{
bool hasNegative = false;
uint256 numMarkets = cache.getNumMarkets();
for (uint256 m = 0; m < numMarkets; m++) {
if (!cache.hasMarket(m)) {
continue;
}
Types.Par memory par = state.getPar(account, m);
if (par.isZero()) {
continue;
} else if (par.sign) {
return false;
} else {
hasNegative = true;
}
}
return hasNegative;
}
// =============== Setter Functions ===============
function updateIndex(
Storage.State storage state,
uint256 marketId
)
internal
returns (Interest.Index memory)
{
Interest.Index memory index = state.getIndex(marketId);
if (index.lastUpdate == Time.currentTime()) {
return index;
}
return state.markets[marketId].index = state.fetchNewIndex(marketId, index);
}
function setStatus(
Storage.State storage state,
Account.Info memory account,
Account.Status status
)
internal
{
state.accounts[account.owner][account.number].status = status;
}
function setPar(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Par memory newPar
)
internal
{
Types.Par memory oldPar = state.getPar(account, marketId);
if (Types.equals(oldPar, newPar)) {
return;
}
// updateTotalPar
Types.TotalPar memory totalPar = state.getTotalPar(marketId);
// roll-back oldPar
if (oldPar.sign) {
totalPar.supply = uint256(totalPar.supply).sub(oldPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).sub(oldPar.value).to128();
}
// roll-forward newPar
if (newPar.sign) {
totalPar.supply = uint256(totalPar.supply).add(newPar.value).to128();
} else {
totalPar.borrow = uint256(totalPar.borrow).add(newPar.value).to128();
}
state.markets[marketId].totalPar = totalPar;
state.accounts[account.owner][account.number].balances[marketId] = newPar;
}
/**
* Determine and set an account's balance based on a change in wei
*/
function setParFromDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Wei memory deltaWei
)
internal
{
if (deltaWei.isZero()) {
return;
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = state.getWei(account, marketId);
Types.Wei memory newWei = oldWei.add(deltaWei);
Types.Par memory newPar = Interest.weiToPar(newWei, index);
state.setPar(
account,
marketId,
newPar
);
}
} | /**
* @title Storage
* @author dYdX
*
* Functions for reading, writing, and verifying state in Solo
*/ | NatSpecMultiLine | setParFromDeltaWei | function setParFromDeltaWei(
Storage.State storage state,
Account.Info memory account,
uint256 marketId,
Types.Wei memory deltaWei
)
internal
{
if (deltaWei.isZero()) {
return;
}
Interest.Index memory index = state.getIndex(marketId);
Types.Wei memory oldWei = state.getWei(account, marketId);
Types.Wei memory newWei = oldWei.add(deltaWei);
Types.Par memory newPar = Interest.weiToPar(newWei, index);
state.setPar(
account,
marketId,
newPar
);
}
| /**
* Determine and set an account's balance based on a change in wei
*/ | NatSpecMultiLine | v0.5.7+commit.6da8b019 | Apache-2.0 | bzzr://b2a5b9b6df14d9d88effa144582fcb11171e627a944a310c807c080088d7ceaa | {
"func_code_index": [
17303,
17938
]
} | 55,638 |
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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 c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
| /**
* @dev Multiplies two numbers, reverts on overflow.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
90,
486
]
} | 55,639 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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 c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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 c;
}
| /**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
598,
877
]
} | 55,640 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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 c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
| /**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
992,
1131
]
} | 55,641 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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 c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
| /**
* @dev Adds two numbers, reverts on overflow.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
1196,
1335
]
} | 55,642 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts 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 c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
| /**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/ | NatSpecMultiLine | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
1470,
1587
]
} | 55,643 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | totalSupply | function totalSupply() public view returns (uint) {
return supply;
}
| // Get the total supply of tokens | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
1101,
1188
]
} | 55,644 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | balanceOf | function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
| // Get the token balance for account `tokenOwner` | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
1247,
1373
]
} | 55,645 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | allowance | function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
| // Get the allowance of funds beteen a token holder and a spender | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
1448,
1601
]
} | 55,646 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | transfer | function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
| // Transfer the balance from owner's account to another account | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
1674,
2037
]
} | 55,647 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | approve | function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
| // Sets how much a sender is allowed to use of an owners funds | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
2112,
2323
]
} | 55,648 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | transferFrom | function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
| // Transfer from function, pulls from allowance | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
2383,
2808
]
} | 55,649 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | function () external payable {
revert();
}
| // Users Cannot acidentaly send ETH to the contract | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
2872,
2933
]
} | 55,650 |
||||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | mint | function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
| // Owner Can mint new tokens | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
2974,
3168
]
} | 55,651 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | burn | function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
| // Owner can burn existing tokens | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
3214,
3461
]
} | 55,652 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | setICOPrice | function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
| // Change ICO Price | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
3493,
3594
]
} | 55,653 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | getRemainingICOBalance | function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
| // See how many tokens are available to be purcahsed. | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
3660,
3781
]
} | 55,654 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | topUpICO | function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
| // Top up ICO balance | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
3815,
4127
]
} | 55,655 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | buyTokens | function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
| // Buy tokens | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
4159,
4690
]
} | 55,656 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | withdrawContractBalance | function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
| // Withdraw ETH | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
4718,
4838
]
} | 55,657 |
|||
TBDToken | TBDToken.sol | 0xf13cba0345c4c033fca220e457ddd811a8d68faa | Solidity | TBDToken | contract TBDToken is IERC20, Owned {
using SafeMath for uint256;
// Constructor - Sets the token Owner
constructor() public {
owner = 0x21553F98Ce782Da4AE52e868B2c0bAC5964DEe29;
contractAddress = address(this);
_balances[owner] = supply;
emit Transfer(address(0), owner, supply);
}
// Events
event Error(string err);
event Mint(uint mintAmount, address to);
event Burn(uint burnAmount, address from);
// Token Setup
string public constant name = "Tiffany Brown Designs Token";
string public constant symbol = "TBD";
uint256 public constant decimals = 18;
uint256 public supply = 1000000000 * 10 ** decimals; // 1 Billion Tokens
address private contractAddress;
uint256 public ICOPrice;
// Balances for each account
mapping(address => uint256) _balances;
// Owner of account approves the transfer of an amount to another account
mapping(address => mapping (address => uint256)) public _allowed;
// Get the total supply of tokens
function totalSupply() public view returns (uint) {
return supply;
}
// Get the token balance for account `tokenOwner`
function balanceOf(address tokenOwner) public view returns (uint balance) {
return _balances[tokenOwner];
}
// Get the allowance of funds beteen a token holder and a spender
function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
return _allowed[tokenOwner][spender];
}
// Transfer the balance from owner's account to another account
function transfer(address to, uint value) public returns (bool success) {
require(_balances[msg.sender] >= value);
require(to != contractAddress);
_balances[msg.sender] = _balances[msg.sender].sub(value);
_balances[to] = _balances[to].add(value);
emit Transfer(msg.sender, to, value);
return true;
}
// Sets how much a sender is allowed to use of an owners funds
function approve(address spender, uint value) public returns (bool success) {
_allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
// Transfer from function, pulls from allowance
function transferFrom(address from, address to, uint value) public returns (bool success) {
require(value <= balanceOf(from));
require(value <= allowance(from, to));
_balances[from] = _balances[from].sub(value);
_balances[to] = _balances[to].add(value);
_allowed[from][to] = _allowed[from][to].sub(value);
emit Transfer(from, to, value);
return true;
}
// Users Cannot acidentaly send ETH to the contract
function () external payable {
revert();
}
// Owner Can mint new tokens
function mint(uint256 amount, address to) public onlyOwner {
_balances[to] = _balances[to].add(amount);
supply = supply.add(amount);
emit Mint(amount, to);
}
// Owner can burn existing tokens
function burn(uint256 amount, address from) public onlyOwner {
require(_balances[from] >= amount);
_balances[from] = _balances[from].sub(amount);
supply = supply.sub(amount);
emit Burn(amount, from);
}
// Change ICO Price
function setICOPrice(uint256 _newPrice) public onlyOwner {
ICOPrice = _newPrice;
}
// See how many tokens are available to be purcahsed.
function getRemainingICOBalance() public view returns (uint256) {
return _balances[contractAddress];
}
// Top up ICO balance
function topUpICO(uint256 _amount) public onlyOwner {
require(_balances[owner] >= _amount);
_balances[owner] = _balances[owner].sub(_amount);
_balances[contractAddress] = _balances[contractAddress].add(_amount);
emit Transfer(msg.sender, contractAddress, _amount);
}
// Buy tokens
function buyTokens() public payable {
require(ICOPrice > 0);
require(msg.value >= ICOPrice);
uint256 affordAmount = msg.value / ICOPrice;
require(_balances[contractAddress] >= affordAmount * 10 ** decimals);
_balances[contractAddress] = _balances[contractAddress].sub(affordAmount * 10 ** decimals);
_balances[msg.sender] = _balances[msg.sender].add(affordAmount * 10 ** decimals);
emit Transfer(contractAddress, msg.sender, affordAmount * 10 ** decimals);
}
// Withdraw ETH
function withdrawContractBalance() public onlyOwner {
msg.sender.transfer(contractAddress.balance);
}
// Cancel and withdraw ICO tokens
function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
} | withdrawContractTokens | function withdrawContractTokens(uint256 _amount) public onlyOwner {
require(_balances[contractAddress] >= _amount);
_balances[contractAddress] = _balances[contractAddress].sub(_amount);
_balances[owner] = _balances[owner].add(_amount);
emit Transfer(contractAddress, owner, _amount);
}
| // Cancel and withdraw ICO tokens | LineComment | v0.5.2+commit.1df8f40c | bzzr://7a5ddd2e75d1865ce6ed7626d01617369edb55403cdceb75e934cd435ccf7592 | {
"func_code_index": [
4884,
5215
]
} | 55,658 |
|||
DecentrEx | DecentrEx.sol | 0x728974844947e09b77f01ba1ef115230ddc8a9a0 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
uint public decimals;
string public name;
} | totalSupply | function totalSupply() constant returns (uint256 supply) {}
| /// @return total amount of tokens | NatSpecSingleLine | v0.4.8+commit.60cc1668 | bzzr://68b8d75990c02744ad9b01451030f1a0ac004ffbf0f66ffe65bfdeb81512b5c9 | {
"func_code_index": [
56,
118
]
} | 55,659 |
|||
DecentrEx | DecentrEx.sol | 0x728974844947e09b77f01ba1ef115230ddc8a9a0 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
uint public decimals;
string public name;
} | balanceOf | function balanceOf(address _owner) constant returns (uint256 balance) {}
| /// @param _owner The address from which the balance will be retrieved
/// @return The balance | NatSpecSingleLine | v0.4.8+commit.60cc1668 | bzzr://68b8d75990c02744ad9b01451030f1a0ac004ffbf0f66ffe65bfdeb81512b5c9 | {
"func_code_index": [
222,
297
]
} | 55,660 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.