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
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); }
/** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 723, 864 ] }
10,700
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
sub
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; }
/** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 1162, 1359 ] }
10,701
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
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-contracts/pull/522 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.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 1613, 2089 ] }
10,702
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
div
function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); }
/** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 2560, 2697 ] }
10,703
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
div
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; }
/** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 3188, 3471 ] }
10,704
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mod
function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 3931, 4066 ] }
10,705
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */
NatSpecMultiLine
mod
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 4546, 4717 ] }
10,706
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call.value(weiValue)(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
isContract
function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; }
/** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 606, 1033 ] }
10,707
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call.value(weiValue)(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
sendValue
function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); }
/** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 1963, 2362 ] }
10,708
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call.value(weiValue)(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCall
function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); }
/** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 3118, 3296 ] }
10,709
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call.value(weiValue)(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCall
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 3521, 3722 ] }
10,710
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call.value(weiValue)(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 4092, 4323 ] }
10,711
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call.value(weiValue)(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
/** * @dev Collection of functions related to the address type */
NatSpecMultiLine
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); }
/** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 4574, 4895 ] }
10,712
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeERC20
library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
/** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */
NatSpecMultiLine
safeApprove
function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); }
/** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 747, 1374 ] }
10,713
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
SafeERC20
library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
/** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */
NatSpecMultiLine
_callOptionalReturn
function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } }
/** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */
NatSpecMultiLine
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 2393, 3159 ] }
10,714
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
encode
function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); }
// encode a uint112 as a UQ112x112
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 450, 584 ] }
10,715
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
encode144
function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); }
// encodes a uint144 as a UQ144x112
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 628, 765 ] }
10,716
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
div
function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); }
// divide a UQ112x112 by a uint112, returning a UQ112x112
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 831, 1034 ] }
10,717
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
mul
function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); }
// multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 1127, 1385 ] }
10,718
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
fraction
function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); }
// returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator)
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 1536, 1787 ] }
10,719
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
decode
function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); }
// decode a UQ112x112 into a uint112 by truncating after the radix point
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 1868, 2000 ] }
10,720
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
decode144
function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); }
// decode a UQ144x112 into a uint144 by truncating after the radix point
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 2081, 2216 ] }
10,721
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
reciprocal
function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); }
// take the reciprocal of a UQ112x112
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 2262, 2474 ] }
10,722
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
FixedPoint
library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint _x; } uint8 private constant RESOLUTION = 112; uint private constant Q112 = uint(1) << RESOLUTION; uint private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, 'FixedPoint: DIV_BY_ZERO'); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint y) internal pure returns (uq144x112 memory) { uint z; require(y == 0 || (z = uint(self._x) * y) / y == uint(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, 'FixedPoint: ZERO_RECIPROCAL'); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } }
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
LineComment
sqrt
function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); }
// square root of a UQ112x112
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 2512, 2680 ] }
10,723
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
UniswapV2OracleLibrary
library UniswapV2OracleLibrary { using FixedPoint for *; // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] function currentBlockTimestamp() internal view returns (uint32) { return uint32(block.timestamp % 2 ** 32); } // produces the cumulative price using counterfactuals to save gas and avoid a call to sync. function currentCumulativePrices( address pair, bool isToken0 ) internal view returns (uint priceCumulative, uint32 blockTimestamp) { blockTimestamp = currentBlockTimestamp(); (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = UniswapPair(pair).getReserves(); if (isToken0) { priceCumulative = UniswapPair(pair).price0CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual priceCumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; } } else { priceCumulative = UniswapPair(pair).price1CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual priceCumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; } } } }
// library with helper methods for oracles that are concerned with computing average prices
LineComment
currentBlockTimestamp
function currentBlockTimestamp() internal view returns (uint32) { return uint32(block.timestamp % 2 ** 32); }
// helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1]
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 178, 306 ] }
10,724
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
UniswapV2OracleLibrary
library UniswapV2OracleLibrary { using FixedPoint for *; // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] function currentBlockTimestamp() internal view returns (uint32) { return uint32(block.timestamp % 2 ** 32); } // produces the cumulative price using counterfactuals to save gas and avoid a call to sync. function currentCumulativePrices( address pair, bool isToken0 ) internal view returns (uint priceCumulative, uint32 blockTimestamp) { blockTimestamp = currentBlockTimestamp(); (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = UniswapPair(pair).getReserves(); if (isToken0) { priceCumulative = UniswapPair(pair).price0CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual priceCumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; } } else { priceCumulative = UniswapPair(pair).price1CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual priceCumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; } } } }
// library with helper methods for oracles that are concerned with computing average prices
LineComment
currentCumulativePrices
function currentCumulativePrices( address pair, bool isToken0 ) internal view returns (uint priceCumulative, uint32 blockTimestamp) { blockTimestamp = currentBlockTimestamp(); (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = UniswapPair(pair).getReserves(); if (isToken0) { priceCumulative = UniswapPair(pair).price0CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual priceCumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; } } else { priceCumulative = UniswapPair(pair).price1CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual priceCumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; } } }
// produces the cumulative price using counterfactuals to save gas and avoid a call to sync.
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 407, 1878 ] }
10,725
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
TWAPBound
contract TWAPBound is YamSubGoverned { using SafeMath for uint256; uint256 public constant BASE = 10**18; /// @notice For a sale of a specific amount uint256 public sell_amount; /// @notice For a purchase of a specific amount uint256 public purchase_amount; /// @notice Token to be sold address public sell_token; /// @notice Token to be puchased address public purchase_token; /// @notice Current uniswap pair for purchase & sale tokens address public uniswap_pair1; /// @notice Second uniswap pair for if TWAP uses two markets to determine price (for liquidity purposes) address public uniswap_pair2; /// @notice Flag for if purchase token is toke 0 in uniswap pair 2 bool public purchaseTokenIs0; /// @notice Flag for if sale token is token 0 in uniswap pair bool public saleTokenIs0; /// @notice TWAP for first hop uint256 public priceAverageSell; /// @notice TWAP for second hop uint256 public priceAverageBuy; /// @notice last TWAP update time uint32 public blockTimestampLast; /// @notice last TWAP cumulative price; uint256 public priceCumulativeLastSell; /// @notice last TWAP cumulative price for two hop pairs; uint256 public priceCumulativeLastBuy; /// @notice Time between TWAP updates uint256 public period; /// @notice counts number of twaps uint256 public twap_counter; /// @notice Grace period after last twap update for a trade to occur uint256 public grace = 60 * 60; // 1 hour uint256 public constant MAX_BOUND = 10**17; /// @notice % bound away from TWAP price uint256 public twap_bounds; /// @notice denotes a trade as complete bool public complete; bool public isSale; function setup_twap_bound ( address sell_token_, address purchase_token_, uint256 amount_, bool is_sale, uint256 twap_period, uint256 twap_bounds_, address uniswap1, address uniswap2, // if two hop uint256 grace_ // length after twap update that it can occur ) public onlyGovOrSubGov { require(twap_bounds_ <= MAX_BOUND, "slippage too high"); sell_token = sell_token_; purchase_token = purchase_token_; period = twap_period; twap_bounds = twap_bounds_; isSale = is_sale; if (is_sale) { sell_amount = amount_; purchase_amount = 0; } else { purchase_amount = amount_; sell_amount = 0; } complete = false; grace = grace_; reset_twap(uniswap1, uniswap2, sell_token, purchase_token); } function reset_twap( address uniswap1, address uniswap2, address sell_token_, address purchase_token_ ) internal { uniswap_pair1 = uniswap1; uniswap_pair2 = uniswap2; blockTimestampLast = 0; priceCumulativeLastSell = 0; priceCumulativeLastBuy = 0; priceAverageBuy = 0; if (UniswapPair(uniswap1).token0() == sell_token_) { saleTokenIs0 = true; } else { saleTokenIs0 = false; } if (uniswap2 != address(0)) { if (UniswapPair(uniswap2).token0() == purchase_token_) { purchaseTokenIs0 = true; } else { purchaseTokenIs0 = false; } } update_twap(); twap_counter = 0; } function quote( uint256 purchaseAmount, uint256 saleAmount ) public view returns (uint256) { uint256 decs = uint256(ExpandedERC20(sell_token).decimals()); uint256 one = 10**decs; return purchaseAmount.mul(one).div(saleAmount); } function bounds() public view returns (uint256) { uint256 uniswap_quote = consult(); uint256 minimum = uniswap_quote.mul(BASE.sub(twap_bounds)).div(BASE); return minimum; } function bounds_max() public view returns (uint256) { uint256 uniswap_quote = consult(); uint256 maximum = uniswap_quote.mul(BASE.add(twap_bounds)).div(BASE); return maximum; } function withinBounds ( uint256 purchaseAmount, uint256 saleAmount ) internal view returns (bool) { uint256 quoted = quote(purchaseAmount, saleAmount); uint256 minimum = bounds(); uint256 maximum = bounds_max(); return quoted > minimum && quoted < maximum; } function withinBoundsWithQuote ( uint256 quoted ) internal view returns (bool) { uint256 minimum = bounds(); uint256 maximum = bounds_max(); return quoted > minimum && quoted < maximum; } // callable by anyone function update_twap() public { (uint256 sell_token_priceCumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(uniswap_pair1, saleTokenIs0); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired // ensure that at least one full period has passed since the last update require(timeElapsed >= period, 'OTC: PERIOD_NOT_ELAPSED'); // overflow is desired priceAverageSell = uint256(uint224((sell_token_priceCumulative - priceCumulativeLastSell) / timeElapsed)); priceCumulativeLastSell = sell_token_priceCumulative; if (uniswap_pair2 != address(0)) { // two hop (uint256 buy_token_priceCumulative, ) = UniswapV2OracleLibrary.currentCumulativePrices(uniswap_pair2, !purchaseTokenIs0); priceAverageBuy = uint256(uint224((buy_token_priceCumulative - priceCumulativeLastBuy) / timeElapsed)); priceCumulativeLastBuy = buy_token_priceCumulative; } twap_counter = twap_counter.add(1); blockTimestampLast = blockTimestamp; } function consult() public view returns (uint256) { if (uniswap_pair2 != address(0)) { // two hop uint256 purchasePrice; uint256 salePrice; uint256 one; if (saleTokenIs0) { uint8 decs = ExpandedERC20(sell_token).decimals(); require(decs <= 18, "too many decimals"); one = 10**uint256(decs); } else { uint8 decs = ExpandedERC20(sell_token).decimals(); require(decs <= 18, "too many decimals"); one = 10**uint256(decs); } if (priceAverageSell > uint192(-1)) { // eat loss of precision // effectively: (x / 2**112) * 1e18 purchasePrice = (priceAverageSell >> 112) * one; } else { // cant overflow // effectively: (x * 1e18 / 2**112) purchasePrice = (priceAverageSell * one) >> 112; } if (purchaseTokenIs0) { uint8 decs = ExpandedERC20(UniswapPair(uniswap_pair2).token1()).decimals(); require(decs <= 18, "too many decimals"); one = 10**uint256(decs); } else { uint8 decs = ExpandedERC20(UniswapPair(uniswap_pair2).token0()).decimals(); require(decs <= 18, "too many decimals"); one = 10**uint256(decs); } if (priceAverageBuy > uint192(-1)) { salePrice = (priceAverageBuy >> 112) * one; } else { salePrice = (priceAverageBuy * one) >> 112; } return purchasePrice.mul(salePrice).div(one); } else { uint256 one; if (saleTokenIs0) { uint8 decs = ExpandedERC20(sell_token).decimals(); require(decs <= 18, "too many decimals"); one = 10**uint256(decs); } else { uint8 decs = ExpandedERC20(sell_token).decimals(); require(decs <= 18, "too many decimals"); one = 10**uint256(decs); } // single hop uint256 purchasePrice; if (priceAverageSell > uint192(-1)) { // eat loss of precision // effectively: (x / 2**112) * 1e18 purchasePrice = (priceAverageSell >> 112) * one; } else { // cant overflow // effectively: (x * 1e18 / 2**112) purchasePrice = (priceAverageSell * one) >> 112; } return purchasePrice; } } function recencyCheck() internal returns (bool) { return (block.timestamp - blockTimestampLast < grace) && (twap_counter > 0); } }
update_twap
function update_twap() public { (uint256 sell_token_priceCumulative, uint32 blockTimestamp) = UniswapV2OracleLibrary.currentCumulativePrices(uniswap_pair1, saleTokenIs0); uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired // ensure that at least one full period has passed since the last update require(timeElapsed >= period, 'OTC: PERIOD_NOT_ELAPSED'); // overflow is desired priceAverageSell = uint256(uint224((sell_token_priceCumulative - priceCumulativeLastSell) / timeElapsed)); priceCumulativeLastSell = sell_token_priceCumulative; if (uniswap_pair2 != address(0)) { // two hop (uint256 buy_token_priceCumulative, ) = UniswapV2OracleLibrary.currentCumulativePrices(uniswap_pair2, !purchaseTokenIs0); priceAverageBuy = uint256(uint224((buy_token_priceCumulative - priceCumulativeLastBuy) / timeElapsed)); priceCumulativeLastBuy = buy_token_priceCumulative; } twap_counter = twap_counter.add(1); blockTimestampLast = blockTimestamp; }
// callable by anyone
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 5117, 6304 ] }
10,726
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
IndexStaking
contract IndexStaking is ReserveUniHelper { constructor(address pendingGov_, address reserves_) public { gov = msg.sender; pendingGov = pendingGov_; reserves = reserves_; IERC20(lp).approve(address(staking), uint256(-1)); } IndexStaker public staking = IndexStaker(0x8f06FBA4684B5E0988F215a47775Bb611Af0F986); address public lp = address(0x4d5ef58aAc27d99935E5b6B4A6778ff292059991); function currentStake() public view returns (uint256) { return staking.balanceOf(address(this)); } // callable by anyone assuming twap bounds checks function stake() public { _getLPToken(); uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } // callable by anyone assuming twap bounds checks function getUnderlying() public { _getUnderlyingToken(true); } // ========= STAKING ======== function _stakeCurrentLPBalance() public onlyGovOrSubGov { uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } function _approveStakingFromReserves( bool isToken0Limited, uint256 amount ) public onlyGovOrSubGov { if (isToken0Limited) { setup_twap_bound( UniswapPair(lp).token0(), // The limiting asset UniswapPair(lp).token1(), amount, // amount of token0 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } else { setup_twap_bound( UniswapPair(lp).token1(), // The limiting asset UniswapPair(lp).token0(), amount, // amount of token1 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } } // ============================ // ========= EXITING ========== function _exitStaking() public onlyGovOrSubGov { staking.exit(); } function _exitAndApproveGetUnderlying() public onlyGovOrSubGov { staking.exit(); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } function _exitStakingEmergency() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); } function _exitStakingEmergencyAndApproveGetUnderlying() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } // ============================ function _getTokenFromHere(address token) public onlyGovOrSubGov { IERC20 t = IERC20(token); t.transfer(reserves, t.balanceOf(address(this))); } }
stake
function stake() public { _getLPToken(); uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); }
// callable by anyone assuming twap bounds checks
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 655, 825 ] }
10,727
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
IndexStaking
contract IndexStaking is ReserveUniHelper { constructor(address pendingGov_, address reserves_) public { gov = msg.sender; pendingGov = pendingGov_; reserves = reserves_; IERC20(lp).approve(address(staking), uint256(-1)); } IndexStaker public staking = IndexStaker(0x8f06FBA4684B5E0988F215a47775Bb611Af0F986); address public lp = address(0x4d5ef58aAc27d99935E5b6B4A6778ff292059991); function currentStake() public view returns (uint256) { return staking.balanceOf(address(this)); } // callable by anyone assuming twap bounds checks function stake() public { _getLPToken(); uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } // callable by anyone assuming twap bounds checks function getUnderlying() public { _getUnderlyingToken(true); } // ========= STAKING ======== function _stakeCurrentLPBalance() public onlyGovOrSubGov { uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } function _approveStakingFromReserves( bool isToken0Limited, uint256 amount ) public onlyGovOrSubGov { if (isToken0Limited) { setup_twap_bound( UniswapPair(lp).token0(), // The limiting asset UniswapPair(lp).token1(), amount, // amount of token0 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } else { setup_twap_bound( UniswapPair(lp).token1(), // The limiting asset UniswapPair(lp).token0(), amount, // amount of token1 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } } // ============================ // ========= EXITING ========== function _exitStaking() public onlyGovOrSubGov { staking.exit(); } function _exitAndApproveGetUnderlying() public onlyGovOrSubGov { staking.exit(); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } function _exitStakingEmergency() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); } function _exitStakingEmergencyAndApproveGetUnderlying() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } // ============================ function _getTokenFromHere(address token) public onlyGovOrSubGov { IERC20 t = IERC20(token); t.transfer(reserves, t.balanceOf(address(this))); } }
getUnderlying
function getUnderlying() public { _getUnderlyingToken(true); }
// callable by anyone assuming twap bounds checks
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 883, 978 ] }
10,728
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
IndexStaking
contract IndexStaking is ReserveUniHelper { constructor(address pendingGov_, address reserves_) public { gov = msg.sender; pendingGov = pendingGov_; reserves = reserves_; IERC20(lp).approve(address(staking), uint256(-1)); } IndexStaker public staking = IndexStaker(0x8f06FBA4684B5E0988F215a47775Bb611Af0F986); address public lp = address(0x4d5ef58aAc27d99935E5b6B4A6778ff292059991); function currentStake() public view returns (uint256) { return staking.balanceOf(address(this)); } // callable by anyone assuming twap bounds checks function stake() public { _getLPToken(); uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } // callable by anyone assuming twap bounds checks function getUnderlying() public { _getUnderlyingToken(true); } // ========= STAKING ======== function _stakeCurrentLPBalance() public onlyGovOrSubGov { uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } function _approveStakingFromReserves( bool isToken0Limited, uint256 amount ) public onlyGovOrSubGov { if (isToken0Limited) { setup_twap_bound( UniswapPair(lp).token0(), // The limiting asset UniswapPair(lp).token1(), amount, // amount of token0 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } else { setup_twap_bound( UniswapPair(lp).token1(), // The limiting asset UniswapPair(lp).token0(), amount, // amount of token1 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } } // ============================ // ========= EXITING ========== function _exitStaking() public onlyGovOrSubGov { staking.exit(); } function _exitAndApproveGetUnderlying() public onlyGovOrSubGov { staking.exit(); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } function _exitStakingEmergency() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); } function _exitStakingEmergencyAndApproveGetUnderlying() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } // ============================ function _getTokenFromHere(address token) public onlyGovOrSubGov { IERC20 t = IERC20(token); t.transfer(reserves, t.balanceOf(address(this))); } }
_stakeCurrentLPBalance
function _stakeCurrentLPBalance() public onlyGovOrSubGov { uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); }
// ========= STAKING ========
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 1016, 1204 ] }
10,729
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
IndexStaking
contract IndexStaking is ReserveUniHelper { constructor(address pendingGov_, address reserves_) public { gov = msg.sender; pendingGov = pendingGov_; reserves = reserves_; IERC20(lp).approve(address(staking), uint256(-1)); } IndexStaker public staking = IndexStaker(0x8f06FBA4684B5E0988F215a47775Bb611Af0F986); address public lp = address(0x4d5ef58aAc27d99935E5b6B4A6778ff292059991); function currentStake() public view returns (uint256) { return staking.balanceOf(address(this)); } // callable by anyone assuming twap bounds checks function stake() public { _getLPToken(); uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } // callable by anyone assuming twap bounds checks function getUnderlying() public { _getUnderlyingToken(true); } // ========= STAKING ======== function _stakeCurrentLPBalance() public onlyGovOrSubGov { uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } function _approveStakingFromReserves( bool isToken0Limited, uint256 amount ) public onlyGovOrSubGov { if (isToken0Limited) { setup_twap_bound( UniswapPair(lp).token0(), // The limiting asset UniswapPair(lp).token1(), amount, // amount of token0 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } else { setup_twap_bound( UniswapPair(lp).token1(), // The limiting asset UniswapPair(lp).token0(), amount, // amount of token1 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } } // ============================ // ========= EXITING ========== function _exitStaking() public onlyGovOrSubGov { staking.exit(); } function _exitAndApproveGetUnderlying() public onlyGovOrSubGov { staking.exit(); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } function _exitStakingEmergency() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); } function _exitStakingEmergencyAndApproveGetUnderlying() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } // ============================ function _getTokenFromHere(address token) public onlyGovOrSubGov { IERC20 t = IERC20(token); t.transfer(reserves, t.balanceOf(address(this))); } }
_exitStaking
function _exitStaking() public onlyGovOrSubGov { staking.exit(); }
// ============================ // ========= EXITING ==========
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 2342, 2450 ] }
10,730
IndexStaking
IndexStaking.sol
0xa940e0541f8b8a40551b28d4c7e37bd85de426ff
Solidity
IndexStaking
contract IndexStaking is ReserveUniHelper { constructor(address pendingGov_, address reserves_) public { gov = msg.sender; pendingGov = pendingGov_; reserves = reserves_; IERC20(lp).approve(address(staking), uint256(-1)); } IndexStaker public staking = IndexStaker(0x8f06FBA4684B5E0988F215a47775Bb611Af0F986); address public lp = address(0x4d5ef58aAc27d99935E5b6B4A6778ff292059991); function currentStake() public view returns (uint256) { return staking.balanceOf(address(this)); } // callable by anyone assuming twap bounds checks function stake() public { _getLPToken(); uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } // callable by anyone assuming twap bounds checks function getUnderlying() public { _getUnderlyingToken(true); } // ========= STAKING ======== function _stakeCurrentLPBalance() public onlyGovOrSubGov { uint256 amount = IERC20(lp).balanceOf(address(this)); staking.stake(amount); } function _approveStakingFromReserves( bool isToken0Limited, uint256 amount ) public onlyGovOrSubGov { if (isToken0Limited) { setup_twap_bound( UniswapPair(lp).token0(), // The limiting asset UniswapPair(lp).token1(), amount, // amount of token0 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } else { setup_twap_bound( UniswapPair(lp).token1(), // The limiting asset UniswapPair(lp).token0(), amount, // amount of token1 true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } } // ============================ // ========= EXITING ========== function _exitStaking() public onlyGovOrSubGov { staking.exit(); } function _exitAndApproveGetUnderlying() public onlyGovOrSubGov { staking.exit(); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } function _exitStakingEmergency() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); } function _exitStakingEmergencyAndApproveGetUnderlying() public onlyGovOrSubGov { staking.withdraw(staking.balanceOf(address(this))); setup_twap_bound( UniswapPair(lp).token0(), // doesnt really matter UniswapPair(lp).token1(), // doesnt really matter staking.balanceOf(address(this)), // amount of LP tokens true, // is sale 60 * 60, // 1 hour 5 * 10**15, // .5% lp, address(0), // if two hop 60 * 60 // length after twap update that it can occur ); } // ============================ function _getTokenFromHere(address token) public onlyGovOrSubGov { IERC20 t = IERC20(token); t.transfer(reserves, t.balanceOf(address(this))); } }
_getTokenFromHere
function _getTokenFromHere(address token) public onlyGovOrSubGov { IERC20 t = IERC20(token); t.transfer(reserves, t.balanceOf(address(this))); }
// ============================
LineComment
v0.5.15+commit.6a57276f
MIT
bzzr://03fe324518d3cb1e7f9c96e627895b760bd3b4a3bdae8305c4509e3a81daac8c
{ "func_code_index": [ 3858, 4053 ] }
10,731
SubdomainRegistrar
contracts/RegistrarInterface.sol
0xecd494c1c127ee50f4fc569c5643a81f0030e0e8
Solidity
RegistrarInterface
contract RegistrarInterface { event OwnerChanged(bytes32 indexed label, address indexed oldOwner, address indexed newOwner); event DomainConfigured(bytes32 indexed label); event DomainUnlisted(bytes32 indexed label); event NewRegistration(bytes32 indexed label, string subdomain, address indexed owner); event RentPaid(bytes32 indexed label, string subdomain, uint amount, uint expirationDate); // InterfaceID of these four methods is 0xc1b15f5a function query(bytes32 label, string calldata subdomain) external view returns (string memory domain); function register(bytes32 label, string calldata subdomain, address owner, address resolver) external payable; function rentDue(bytes32 label, string calldata subdomain) external view returns (uint timestamp); function payRent(bytes32 label, string calldata subdomain) external payable; }
query
function query(bytes32 label, string calldata subdomain) external view returns (string memory domain);
// InterfaceID of these four methods is 0xc1b15f5a
LineComment
v0.5.16+commit.9c3226ce
MIT
bzzr://cd3d85f775de700ef786cd63c459acbc005036a05e728cb8569507b7b8b59cae
{ "func_code_index": [ 479, 586 ] }
10,732
OctusNetworkGoldenToken
zeppelin-solidity/contracts/token/StandardToken.sol
0x3b3c6809e03244a5bbc3e76e13fb3923d7da9b62
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; event Burn(address indexed burner, uint256 value); function burn(uint256 _value) public { require(_value > 0); require(_value <= balances[msg.sender]); address burner = msg.sender; balances[burner] = balances[burner].sub(_value); totalSupply = totalSupply.sub(_value); emit Burn(burner, _value); } /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
transferFrom
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; }
/** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */
NatSpecMultiLine
v0.4.25+commit.59dbf8f1
bzzr://bcf3502a6f5ba3c6c427c5b7b3596defdd618535c0d0064abaee483836a3e54b
{ "func_code_index": [ 744, 1201 ] }
10,733
OctusNetworkGoldenToken
zeppelin-solidity/contracts/token/StandardToken.sol
0x3b3c6809e03244a5bbc3e76e13fb3923d7da9b62
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; event Burn(address indexed burner, uint256 value); function burn(uint256 _value) public { require(_value > 0); require(_value <= balances[msg.sender]); address burner = msg.sender; balances[burner] = balances[burner].sub(_value); totalSupply = totalSupply.sub(_value); emit Burn(burner, _value); } /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
approve
function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; }
/** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */
NatSpecMultiLine
v0.4.25+commit.59dbf8f1
bzzr://bcf3502a6f5ba3c6c427c5b7b3596defdd618535c0d0064abaee483836a3e54b
{ "func_code_index": [ 1833, 2028 ] }
10,734
OctusNetworkGoldenToken
zeppelin-solidity/contracts/token/StandardToken.sol
0x3b3c6809e03244a5bbc3e76e13fb3923d7da9b62
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; event Burn(address indexed burner, uint256 value); function burn(uint256 _value) public { require(_value > 0); require(_value <= balances[msg.sender]); address burner = msg.sender; balances[burner] = balances[burner].sub(_value); totalSupply = totalSupply.sub(_value); emit Burn(burner, _value); } /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
allowance
function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; }
/** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */
NatSpecMultiLine
v0.4.25+commit.59dbf8f1
bzzr://bcf3502a6f5ba3c6c427c5b7b3596defdd618535c0d0064abaee483836a3e54b
{ "func_code_index": [ 2352, 2483 ] }
10,735
OctusNetworkGoldenToken
zeppelin-solidity/contracts/token/StandardToken.sol
0x3b3c6809e03244a5bbc3e76e13fb3923d7da9b62
Solidity
StandardToken
contract StandardToken is ERC20, BasicToken { mapping (address => mapping (address => uint256)) internal allowed; event Burn(address indexed burner, uint256 value); function burn(uint256 _value) public { require(_value > 0); require(_value <= balances[msg.sender]); address burner = msg.sender; balances[burner] = balances[burner].sub(_value); totalSupply = totalSupply.sub(_value); emit Burn(burner, _value); } /** * @dev Transfer tokens from one address to another * @param _from address The address which you want to send tokens from * @param _to address The address which you want to transfer to * @param _value uint256 the amount of tokens to be transferred */ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[_from]); require(_value <= allowed[_from][msg.sender]); balances[_from] = balances[_from].sub(_value); balances[_to] = balances[_to].add(_value); allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); emit Transfer(_from, _to, _value); return true; } /** * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. * * Beware that changing an allowance with this method brings the risk that someone may use both the old * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * @param _spender The address which will spend the funds. * @param _value The amount of tokens to be spent. */ function approve(address _spender, uint256 _value) public returns (bool) { allowed[msg.sender][_spender] = _value; emit Approval(msg.sender, _spender, _value); return true; } /** * @dev Function to check the amount of tokens that an owner allowed to a spender. * @param _owner address The address which owns the funds. * @param _spender address The address which will spend the funds. * @return A uint256 specifying the amount of tokens still available for the spender. */ function allowance(address _owner, address _spender) public view returns (uint256) { return allowed[_owner][_spender]; } /** * approve should be called when allowed[_spender] == 0. To increment * allowed value is better to use this function to avoid 2 calls (and wait until * the first transaction is mined) * From MonolithDAO Token.sol */ function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { uint oldValue = allowed[msg.sender][_spender]; if (_subtractedValue > oldValue) { allowed[msg.sender][_spender] = 0; } else { allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); } emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); return true; } }
/** * @title Standard ERC20 token * * @dev Implementation of the basic standard token. * @dev https://github.com/ethereum/EIPs/issues/20 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol */
NatSpecMultiLine
increaseApproval
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); 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.4.25+commit.59dbf8f1
bzzr://bcf3502a6f5ba3c6c427c5b7b3596defdd618535c0d0064abaee483836a3e54b
{ "func_code_index": [ 2728, 2997 ] }
10,736
PendleYieldContractDeployerBaseV2
contracts/core/abstractV2/PendleYieldTokenHolderBaseV2.sol
0x3714e5d5a32fdc16e3e6fee6788afc3ac9eb5762
Solidity
PendleYieldTokenHolderBaseV2
contract PendleYieldTokenHolderBaseV2 is IPendleYieldTokenHolderV2, WithdrawableV2 { using SafeERC20 for IERC20; using Math for uint256; using SafeMath for uint256; address public immutable override yieldToken; address public immutable override forge; address public override rewardToken; // no immutable to save bytecode size uint256 public override expiry; // no immutable to save bytecode size modifier onlyForge() { require(msg.sender == address(forge), "ONLY_FORGE"); _; } constructor( address _governanceManager, address _forge, address _yieldToken, uint256 _expiry ) PermissionsV2(_governanceManager) { address _rewardToken = address(IPendleForge(_forge).rewardToken()); address rewardManager = address(IPendleForge(_forge).rewardManager()); yieldToken = _yieldToken; forge = _forge; rewardToken = _rewardToken; expiry = _expiry; IERC20(_rewardToken).safeApprove(rewardManager, type(uint256).max); } /** @dev function has been depreciated but must still be left here to conform with the interface */ function setUpEmergencyMode(address) external pure override { revert("FUNCTION_DEPRECIATED"); } // Only forge can call this function // this will allow a spender to spend the whole balance of the specified tokens // the spender should ideally be a contract with logic for users to withdraw out their funds. function setUpEmergencyModeV2(address spender, bool) external virtual override onlyForge { // by default we store all the tokens inside this contract, so just approve IERC20(yieldToken).safeApprove(spender, type(uint256).max); IERC20(rewardToken).safeApprove(spender, type(uint256).max); } /// @dev by default the token doesn't have any rewards function redeemRewards() external virtual override {} /// @dev by default we will keep all tokens in this contract, so no further actions necessary function afterReceiveTokens(uint256 amount) external virtual override {} function pushYieldTokens( address to, uint256 amount, uint256 minNYieldAfterPush ) external virtual override onlyForge { uint256 yieldTokenBal = IERC20(yieldToken).balanceOf(address(this)); require(yieldTokenBal.sub(amount) >= minNYieldAfterPush, "INVARIANCE_ERROR"); IERC20(yieldToken).safeTransfer(to, amount); } // The governance address will be able to withdraw any tokens except for // the yieldToken and the rewardToken function _allowedToWithdraw(address _token) internal view virtual override returns (bool allowed) { allowed = _token != yieldToken && _token != rewardToken; } }
setUpEmergencyMode
function setUpEmergencyMode(address) external pure override { revert("FUNCTION_DEPRECIATED"); }
/** @dev function has been depreciated but must still be left here to conform with the interface */
NatSpecMultiLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 1177, 1288 ] }
10,737
PendleYieldContractDeployerBaseV2
contracts/core/abstractV2/PendleYieldTokenHolderBaseV2.sol
0x3714e5d5a32fdc16e3e6fee6788afc3ac9eb5762
Solidity
PendleYieldTokenHolderBaseV2
contract PendleYieldTokenHolderBaseV2 is IPendleYieldTokenHolderV2, WithdrawableV2 { using SafeERC20 for IERC20; using Math for uint256; using SafeMath for uint256; address public immutable override yieldToken; address public immutable override forge; address public override rewardToken; // no immutable to save bytecode size uint256 public override expiry; // no immutable to save bytecode size modifier onlyForge() { require(msg.sender == address(forge), "ONLY_FORGE"); _; } constructor( address _governanceManager, address _forge, address _yieldToken, uint256 _expiry ) PermissionsV2(_governanceManager) { address _rewardToken = address(IPendleForge(_forge).rewardToken()); address rewardManager = address(IPendleForge(_forge).rewardManager()); yieldToken = _yieldToken; forge = _forge; rewardToken = _rewardToken; expiry = _expiry; IERC20(_rewardToken).safeApprove(rewardManager, type(uint256).max); } /** @dev function has been depreciated but must still be left here to conform with the interface */ function setUpEmergencyMode(address) external pure override { revert("FUNCTION_DEPRECIATED"); } // Only forge can call this function // this will allow a spender to spend the whole balance of the specified tokens // the spender should ideally be a contract with logic for users to withdraw out their funds. function setUpEmergencyModeV2(address spender, bool) external virtual override onlyForge { // by default we store all the tokens inside this contract, so just approve IERC20(yieldToken).safeApprove(spender, type(uint256).max); IERC20(rewardToken).safeApprove(spender, type(uint256).max); } /// @dev by default the token doesn't have any rewards function redeemRewards() external virtual override {} /// @dev by default we will keep all tokens in this contract, so no further actions necessary function afterReceiveTokens(uint256 amount) external virtual override {} function pushYieldTokens( address to, uint256 amount, uint256 minNYieldAfterPush ) external virtual override onlyForge { uint256 yieldTokenBal = IERC20(yieldToken).balanceOf(address(this)); require(yieldTokenBal.sub(amount) >= minNYieldAfterPush, "INVARIANCE_ERROR"); IERC20(yieldToken).safeTransfer(to, amount); } // The governance address will be able to withdraw any tokens except for // the yieldToken and the rewardToken function _allowedToWithdraw(address _token) internal view virtual override returns (bool allowed) { allowed = _token != yieldToken && _token != rewardToken; } }
setUpEmergencyModeV2
function setUpEmergencyModeV2(address spender, bool) external virtual override onlyForge { // by default we store all the tokens inside this contract, so just approve IERC20(yieldToken).safeApprove(spender, type(uint256).max); IERC20(rewardToken).safeApprove(spender, type(uint256).max); }
// Only forge can call this function // this will allow a spender to spend the whole balance of the specified tokens // the spender should ideally be a contract with logic for users to withdraw out their funds.
LineComment
v0.7.6+commit.7338295f
{ "func_code_index": [ 1513, 1834 ] }
10,738
PendleYieldContractDeployerBaseV2
contracts/core/abstractV2/PendleYieldTokenHolderBaseV2.sol
0x3714e5d5a32fdc16e3e6fee6788afc3ac9eb5762
Solidity
PendleYieldTokenHolderBaseV2
contract PendleYieldTokenHolderBaseV2 is IPendleYieldTokenHolderV2, WithdrawableV2 { using SafeERC20 for IERC20; using Math for uint256; using SafeMath for uint256; address public immutable override yieldToken; address public immutable override forge; address public override rewardToken; // no immutable to save bytecode size uint256 public override expiry; // no immutable to save bytecode size modifier onlyForge() { require(msg.sender == address(forge), "ONLY_FORGE"); _; } constructor( address _governanceManager, address _forge, address _yieldToken, uint256 _expiry ) PermissionsV2(_governanceManager) { address _rewardToken = address(IPendleForge(_forge).rewardToken()); address rewardManager = address(IPendleForge(_forge).rewardManager()); yieldToken = _yieldToken; forge = _forge; rewardToken = _rewardToken; expiry = _expiry; IERC20(_rewardToken).safeApprove(rewardManager, type(uint256).max); } /** @dev function has been depreciated but must still be left here to conform with the interface */ function setUpEmergencyMode(address) external pure override { revert("FUNCTION_DEPRECIATED"); } // Only forge can call this function // this will allow a spender to spend the whole balance of the specified tokens // the spender should ideally be a contract with logic for users to withdraw out their funds. function setUpEmergencyModeV2(address spender, bool) external virtual override onlyForge { // by default we store all the tokens inside this contract, so just approve IERC20(yieldToken).safeApprove(spender, type(uint256).max); IERC20(rewardToken).safeApprove(spender, type(uint256).max); } /// @dev by default the token doesn't have any rewards function redeemRewards() external virtual override {} /// @dev by default we will keep all tokens in this contract, so no further actions necessary function afterReceiveTokens(uint256 amount) external virtual override {} function pushYieldTokens( address to, uint256 amount, uint256 minNYieldAfterPush ) external virtual override onlyForge { uint256 yieldTokenBal = IERC20(yieldToken).balanceOf(address(this)); require(yieldTokenBal.sub(amount) >= minNYieldAfterPush, "INVARIANCE_ERROR"); IERC20(yieldToken).safeTransfer(to, amount); } // The governance address will be able to withdraw any tokens except for // the yieldToken and the rewardToken function _allowedToWithdraw(address _token) internal view virtual override returns (bool allowed) { allowed = _token != yieldToken && _token != rewardToken; } }
redeemRewards
function redeemRewards() external virtual override {}
/// @dev by default the token doesn't have any rewards
NatSpecSingleLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 1895, 1952 ] }
10,739
PendleYieldContractDeployerBaseV2
contracts/core/abstractV2/PendleYieldTokenHolderBaseV2.sol
0x3714e5d5a32fdc16e3e6fee6788afc3ac9eb5762
Solidity
PendleYieldTokenHolderBaseV2
contract PendleYieldTokenHolderBaseV2 is IPendleYieldTokenHolderV2, WithdrawableV2 { using SafeERC20 for IERC20; using Math for uint256; using SafeMath for uint256; address public immutable override yieldToken; address public immutable override forge; address public override rewardToken; // no immutable to save bytecode size uint256 public override expiry; // no immutable to save bytecode size modifier onlyForge() { require(msg.sender == address(forge), "ONLY_FORGE"); _; } constructor( address _governanceManager, address _forge, address _yieldToken, uint256 _expiry ) PermissionsV2(_governanceManager) { address _rewardToken = address(IPendleForge(_forge).rewardToken()); address rewardManager = address(IPendleForge(_forge).rewardManager()); yieldToken = _yieldToken; forge = _forge; rewardToken = _rewardToken; expiry = _expiry; IERC20(_rewardToken).safeApprove(rewardManager, type(uint256).max); } /** @dev function has been depreciated but must still be left here to conform with the interface */ function setUpEmergencyMode(address) external pure override { revert("FUNCTION_DEPRECIATED"); } // Only forge can call this function // this will allow a spender to spend the whole balance of the specified tokens // the spender should ideally be a contract with logic for users to withdraw out their funds. function setUpEmergencyModeV2(address spender, bool) external virtual override onlyForge { // by default we store all the tokens inside this contract, so just approve IERC20(yieldToken).safeApprove(spender, type(uint256).max); IERC20(rewardToken).safeApprove(spender, type(uint256).max); } /// @dev by default the token doesn't have any rewards function redeemRewards() external virtual override {} /// @dev by default we will keep all tokens in this contract, so no further actions necessary function afterReceiveTokens(uint256 amount) external virtual override {} function pushYieldTokens( address to, uint256 amount, uint256 minNYieldAfterPush ) external virtual override onlyForge { uint256 yieldTokenBal = IERC20(yieldToken).balanceOf(address(this)); require(yieldTokenBal.sub(amount) >= minNYieldAfterPush, "INVARIANCE_ERROR"); IERC20(yieldToken).safeTransfer(to, amount); } // The governance address will be able to withdraw any tokens except for // the yieldToken and the rewardToken function _allowedToWithdraw(address _token) internal view virtual override returns (bool allowed) { allowed = _token != yieldToken && _token != rewardToken; } }
afterReceiveTokens
function afterReceiveTokens(uint256 amount) external virtual override {}
/// @dev by default we will keep all tokens in this contract, so no further actions necessary
NatSpecSingleLine
v0.7.6+commit.7338295f
{ "func_code_index": [ 2052, 2128 ] }
10,740
PendleYieldContractDeployerBaseV2
contracts/core/abstractV2/PendleYieldTokenHolderBaseV2.sol
0x3714e5d5a32fdc16e3e6fee6788afc3ac9eb5762
Solidity
PendleYieldTokenHolderBaseV2
contract PendleYieldTokenHolderBaseV2 is IPendleYieldTokenHolderV2, WithdrawableV2 { using SafeERC20 for IERC20; using Math for uint256; using SafeMath for uint256; address public immutable override yieldToken; address public immutable override forge; address public override rewardToken; // no immutable to save bytecode size uint256 public override expiry; // no immutable to save bytecode size modifier onlyForge() { require(msg.sender == address(forge), "ONLY_FORGE"); _; } constructor( address _governanceManager, address _forge, address _yieldToken, uint256 _expiry ) PermissionsV2(_governanceManager) { address _rewardToken = address(IPendleForge(_forge).rewardToken()); address rewardManager = address(IPendleForge(_forge).rewardManager()); yieldToken = _yieldToken; forge = _forge; rewardToken = _rewardToken; expiry = _expiry; IERC20(_rewardToken).safeApprove(rewardManager, type(uint256).max); } /** @dev function has been depreciated but must still be left here to conform with the interface */ function setUpEmergencyMode(address) external pure override { revert("FUNCTION_DEPRECIATED"); } // Only forge can call this function // this will allow a spender to spend the whole balance of the specified tokens // the spender should ideally be a contract with logic for users to withdraw out their funds. function setUpEmergencyModeV2(address spender, bool) external virtual override onlyForge { // by default we store all the tokens inside this contract, so just approve IERC20(yieldToken).safeApprove(spender, type(uint256).max); IERC20(rewardToken).safeApprove(spender, type(uint256).max); } /// @dev by default the token doesn't have any rewards function redeemRewards() external virtual override {} /// @dev by default we will keep all tokens in this contract, so no further actions necessary function afterReceiveTokens(uint256 amount) external virtual override {} function pushYieldTokens( address to, uint256 amount, uint256 minNYieldAfterPush ) external virtual override onlyForge { uint256 yieldTokenBal = IERC20(yieldToken).balanceOf(address(this)); require(yieldTokenBal.sub(amount) >= minNYieldAfterPush, "INVARIANCE_ERROR"); IERC20(yieldToken).safeTransfer(to, amount); } // The governance address will be able to withdraw any tokens except for // the yieldToken and the rewardToken function _allowedToWithdraw(address _token) internal view virtual override returns (bool allowed) { allowed = _token != yieldToken && _token != rewardToken; } }
_allowedToWithdraw
function _allowedToWithdraw(address _token) internal view virtual override returns (bool allowed) { allowed = _token != yieldToken && _token != rewardToken; }
// The governance address will be able to withdraw any tokens except for // the yieldToken and the rewardToken
LineComment
v0.7.6+commit.7338295f
{ "func_code_index": [ 2625, 2843 ] }
10,741
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
swapExactETHForTokens
function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); }
/*********************** + Swap wrappers + ***********************/
NatSpecMultiLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 1003, 1681 ] }
10,742
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
pairFor
function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); }
// calculates the CREATE2 address for a pair without making any external calls
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 5087, 5458 ] }
10,743
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
getReserves
function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); }
// fetches and sorts the reserves for a pair
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 5834, 6183 ] }
10,744
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
quote
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; }
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 6287, 6583 ] }
10,745
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
getAmountOut
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; }
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 6696, 7162 ] }
10,746
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
getAmountIn
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; }
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 7274, 7699 ] }
10,747
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
getAmountsOut
function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } }
// performs chained getAmountOut calculations on any number of pairs
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 7772, 8213 ] }
10,748
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
getAmountsIn
function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } }
// performs chained getAmountIn calculations on any number of pairs
LineComment
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 8285, 8747 ] }
10,749
MistXRouter
contracts/MistXRouter.sol
0xef7973b8fcd97bd948c9a46c3ead0beb704e0f02
Solidity
MistXRouter
contract MistXRouter is Managable { /*********************** + Global Settings + ***********************/ using SafeERC20 for IERC20; // Managers are permissioned for critical functionality mapping (address => bool) public managers; address public tipjar; address public immutable WETH; address public immutable factory; bytes32 public immutable initHash; receive() external payable {} fallback() external payable {} constructor( address _WETH, address _factory, bytes32 _initHash, address _owner, address _tipjar ) Managable(_owner) { WETH = _WETH; factory = _factory; initHash = _initHash; managers[_owner] = true; tipjar = _tipjar; } /*********************** + Structures + ***********************/ struct Swap { uint256 amount0; uint256 amount1; address[] path; address to; uint256 deadline; } /*********************** + Swap wrappers + ***********************/ function swapExactETHForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'MistXRouter: INVALID_PATH'); uint amountIn = msg.value - _bribe; IWETH(WETH).deposit{value: amountIn}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amountIn)); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapETHForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); require(_swap.path[0] == WETH, 'UniswapV2Router: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount1, _swap.path); require(amounts[0] <= msg.value - _bribe, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT'); IWETH(WETH).deposit{value: amounts[0]}(); assert(IWETH(WETH).transfer(pairFor(_swap.path[0], _swap.path[1]), amounts[0])); _swapPath(amounts, _swap.path, _swap.to); // refund dust eth, if any if (msg.value - _bribe > amounts[0]) { (bool success, ) = msg.sender.call{value: msg.value - _bribe - amounts[0]}(new bytes(0)); require(success, 'safeTransferETH: ETH transfer failed'); } } function swapExactTokensForTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); uint balanceBefore = IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to); _swapSupportingFeeOnTransferTokens(_swap.path, _swap.to); require( IERC20(_swap.path[_swap.path.length - 1]).balanceOf(_swap.to) - balanceBefore >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT' ); } function swapTokensForExactTokens( Swap calldata _swap, uint256 _bribe ) external payable { deposit(_bribe); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, _swap.to); } function swapTokensForExactETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); uint[] memory amounts = getAmountsIn(_swap.amount0, _swap.path); require(amounts[0] <= _swap.amount1, 'MistXRouter: EXCESSIVE_INPUT_AMOUNT'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), amounts[0] ); _swapPath(amounts, _swap.path, address(this)); IWETH(WETH).withdraw(amounts[amounts.length - 1]); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amounts[amounts.length - 1] - _bribe); } function swapExactTokensForETH( Swap calldata _swap, uint256 _bribe ) external payable { require(_swap.path[_swap.path.length - 1] == WETH, 'MistXRouter: INVALID_PATH'); TransferHelper.safeTransferFrom( _swap.path[0], msg.sender, pairFor(_swap.path[0], _swap.path[1]), _swap.amount0 ); _swapSupportingFeeOnTransferTokens(_swap.path, address(this)); uint amountOut = IERC20(WETH).balanceOf(address(this)); require(amountOut >= _swap.amount1, 'MistXRouter: INSUFFICIENT_OUTPUT_AMOUNT'); IWETH(WETH).withdraw(amountOut); deposit(_bribe); // ETH after bribe must be swept to _to TransferHelper.safeTransferETH(_swap.to, amountOut - _bribe); } /*********************** + Library + ***********************/ // calculates the CREATE2 address for a pair without making any external calls function pairFor(address tokenA, address tokenB) internal view returns (address pair) { (address token0, address token1) = sortTokens(tokenA, tokenB); uint hashed = uint(keccak256(abi.encodePacked( hex'ff', factory, keccak256(abi.encodePacked(token0, token1)), initHash // init code hash ))); pair = address(uint160(hashed)); } function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { require(tokenA != tokenB, 'MistXLibrary: IDENTICAL_ADDRESSES'); (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), 'MistXLibrary: ZERO_ADDRESS'); } // fetches and sorts the reserves for a pair function getReserves(address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) { (address token0,) = sortTokens(tokenA, tokenB); (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(tokenA, tokenB)).getReserves(); (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0); } // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) { require(amountA > 0, 'MistXLibrary: INSUFFICIENT_AMOUNT'); require(reserveA > 0 && reserveB > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); amountB = amountA * (reserveB) / reserveA; } // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) { require(amountIn > 0, 'MistXLibrary: INSUFFICIENT_INPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint amountInWithFee = amountIn * 997; uint numerator = amountInWithFee * reserveOut; uint denominator = reserveIn * 1000 + amountInWithFee; amountOut = numerator / denominator; } // given an output amount of an asset and pair reserves, returns a required input amount of the other asset function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) { require(amountOut > 0, 'MistXLibrary: INSUFFICIENT_OUTPUT_AMOUNT'); require(reserveIn > 0 && reserveOut > 0, 'MistXLibrary: INSUFFICIENT_LIQUIDITY'); uint numerator = reserveIn * amountOut * 1000; uint denominator = (reserveOut - amountOut) * 997; amountIn = (numerator / denominator) + 1; } // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[0] = amountIn; for (uint i; i < path.length - 1; i++) { (uint reserveIn, uint reserveOut) = getReserves(path[i], path[i + 1]); amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut); } } // performs chained getAmountIn calculations on any number of pairs function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'MistXLibrary: INVALID_PATH'); amounts = new uint[](path.length); amounts[amounts.length - 1] = amountOut; for (uint i = path.length - 1; i > 0; i--) { (uint reserveIn, uint reserveOut) = getReserves(path[i - 1], path[i]); amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut); } } /*********************** + Support functions + ***********************/ function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); } function _swapSupportingFeeOnTransferTokens( address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); IUniswapV2Pair pair = IUniswapV2Pair(pairFor(input, output)); uint amountInput; uint amountOutput; { (uint reserve0, uint reserve1,) = pair.getReserves(); (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0); amountInput = IERC20(input).balanceOf(address(pair)) - reserveInput; amountOutput = getAmountOut(amountInput, reserveInput, reserveOutput); } (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; pair.swap(amount0Out, amount1Out, to, new bytes(0)); } } function _swapPath( uint[] memory amounts, address[] memory path, address _to ) internal virtual { for (uint i; i < path.length - 1; i++) { (address input, address output) = (path[i], path[i + 1]); (address token0,) = sortTokens(input, output); uint amountOut = amounts[i + 1]; (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0)); address to = i < path.length - 2 ? pairFor(output, path[i + 2]) : _to; IUniswapV2Pair(pairFor(input, output)).swap( amount0Out, amount1Out, to, new bytes(0) ); } } /*********************** + Administration + ***********************/ modifier onlyManager() { require(managers[msg.sender] == true, "Only managers can call this"); _; } function addManager( address _manager ) external onlyOwner { managers[_manager] = true; } function removeManager( address _manager ) external onlyOwner { managers[_manager] = false; } function changeTipjar( address _tipjar ) external onlyOwner { tipjar = _tipjar; } function rescueStuckETH( uint256 _amount, address _to ) external onlyManager { payable(_to).transfer(_amount); } function rescueStuckToken( address _tokenContract, uint256 _value, address _to ) external onlyManager { IERC20(_tokenContract).safeTransfer(_to, _value); } }
/// @author Nathan Worsley (https://github.com/CodeForcer) /// @title MistX Router with generic Uniswap-style support /// @notice If you came here just to copy my stuff, you NGMI - learn to code!
NatSpecSingleLine
deposit
function deposit(uint256 value) public payable { (bool sent, bytes memory data) = tipjar.call{value: value}(new bytes(0)); require(sent, "Failed to send Ether"); }
/*********************** + Support functions + ***********************/
NatSpecMultiLine
v0.8.4+commit.c7e474f2
{ "func_code_index": [ 8831, 9006 ] }
10,750
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
Ownable
contract Ownable { address public owner; event OwnershipRenounced(address indexed previousOwner); event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } /** * @dev Allows the current owner to relinquish control of the contract. */ function renounceOwnership() public onlyOwner { emit OwnershipRenounced(owner); owner = address(0); } }
transferOwnership
function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; }
/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 710, 891 ] }
10,751
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
Ownable
contract Ownable { address public owner; event OwnershipRenounced(address indexed previousOwner); event OwnershipTransferred( address indexed previousOwner, address indexed newOwner ); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor() public { owner = msg.sender; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(msg.sender == owner); _; } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { require(newOwner != address(0)); emit OwnershipTransferred(owner, newOwner); owner = newOwner; } /** * @dev Allows the current owner to relinquish control of the contract. */ function renounceOwnership() public onlyOwner { emit OwnershipRenounced(owner); owner = address(0); } }
renounceOwnership
function renounceOwnership() public onlyOwner { emit OwnershipRenounced(owner); owner = address(0); }
/** * @dev Allows the current owner to relinquish control of the contract. */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 983, 1100 ] }
10,752
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
TokenRecipient
contract TokenRecipient { event ReceivedEther(address indexed sender, uint amount); event ReceivedTokens(address indexed from, uint256 value, address indexed token, bytes extraData); /** * @dev Receive tokens and generate a log event * @param from Address from which to transfer tokens * @param value Amount of tokens to transfer * @param token Address of token * @param extraData Additional data to log */ function receiveApproval(address from, uint256 value, address token, bytes extraData) public { ERC20 t = ERC20(token); require(t.transferFrom(from, this, value)); emit ReceivedTokens(from, value, token, extraData); } /** * @dev Receive Ether and generate a log event */ function () payable public { emit ReceivedEther(msg.sender, msg.value); } }
receiveApproval
function receiveApproval(address from, uint256 value, address token, bytes extraData) public { ERC20 t = ERC20(token); require(t.transferFrom(from, this, value)); emit ReceivedTokens(from, value, token, extraData); }
/** * @dev Receive tokens and generate a log event * @param from Address from which to transfer tokens * @param value Amount of tokens to transfer * @param token Address of token * @param extraData Additional data to log */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 461, 714 ] }
10,753
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
TokenRecipient
contract TokenRecipient { event ReceivedEther(address indexed sender, uint amount); event ReceivedTokens(address indexed from, uint256 value, address indexed token, bytes extraData); /** * @dev Receive tokens and generate a log event * @param from Address from which to transfer tokens * @param value Amount of tokens to transfer * @param token Address of token * @param extraData Additional data to log */ function receiveApproval(address from, uint256 value, address token, bytes extraData) public { ERC20 t = ERC20(token); require(t.transferFrom(from, this, value)); emit ReceivedTokens(from, value, token, extraData); } /** * @dev Receive Ether and generate a log event */ function () payable public { emit ReceivedEther(msg.sender, msg.value); } }
function () payable public { emit ReceivedEther(msg.sender, msg.value); }
/** * @dev Receive Ether and generate a log event */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 787, 879 ] }
10,754
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
ProxyRegistry
contract ProxyRegistry is Ownable { /* DelegateProxy implementation contract. Must be initialized. */ address public delegateProxyImplementation; /* Authenticated proxies by user. */ mapping(address => OwnableDelegateProxy) public proxies; /* Contracts pending access. */ mapping(address => uint) public pending; /* Contracts allowed to call those proxies. */ mapping(address => bool) public contracts; /* Delay period for adding an authenticated contract. This mitigates a particular class of potential attack on the Wyvern DAO (which owns this registry) - if at any point the value of assets held by proxy contracts exceeded the value of half the WYV supply (votes in the DAO), a malicious but rational attacker could buy half the Wyvern and grant themselves access to all the proxy contracts. A delay period renders this attack nonthreatening - given two weeks, if that happened, users would have plenty of time to notice and transfer their assets. */ uint public DELAY_PERIOD = 2 weeks; /** * Start the process to enable access for specified contract. Subject to delay period. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function startGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] == 0); pending[addr] = now; } /** * End the process to nable access for specified contract after delay period has passed. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function endGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] != 0 && ((pending[addr] + DELAY_PERIOD) < now)); pending[addr] = 0; contracts[addr] = true; } /** * Revoke access for specified contract. Can be done instantly. * * @dev ProxyRegistry owner only * @param addr Address of which to revoke permissions */ function revokeAuthentication (address addr) public onlyOwner { contracts[addr] = false; } /** * Register a proxy contract with this registry * * @dev Must be called by the user which the proxy is for, creates a new AuthenticatedProxy * @return New AuthenticatedProxy contract */ function registerProxy() public returns (OwnableDelegateProxy proxy) { require(proxies[msg.sender] == address(0)); proxy = new OwnableDelegateProxy(msg.sender, delegateProxyImplementation, abi.encodeWithSignature("initialize(address,address)", msg.sender, address(this))); proxies[msg.sender] = proxy; return proxy; } }
startGrantAuthentication
function startGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] == 0); pending[addr] = now; }
/** * Start the process to enable access for specified contract. Subject to delay period. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 1297, 1487 ] }
10,755
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
ProxyRegistry
contract ProxyRegistry is Ownable { /* DelegateProxy implementation contract. Must be initialized. */ address public delegateProxyImplementation; /* Authenticated proxies by user. */ mapping(address => OwnableDelegateProxy) public proxies; /* Contracts pending access. */ mapping(address => uint) public pending; /* Contracts allowed to call those proxies. */ mapping(address => bool) public contracts; /* Delay period for adding an authenticated contract. This mitigates a particular class of potential attack on the Wyvern DAO (which owns this registry) - if at any point the value of assets held by proxy contracts exceeded the value of half the WYV supply (votes in the DAO), a malicious but rational attacker could buy half the Wyvern and grant themselves access to all the proxy contracts. A delay period renders this attack nonthreatening - given two weeks, if that happened, users would have plenty of time to notice and transfer their assets. */ uint public DELAY_PERIOD = 2 weeks; /** * Start the process to enable access for specified contract. Subject to delay period. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function startGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] == 0); pending[addr] = now; } /** * End the process to nable access for specified contract after delay period has passed. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function endGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] != 0 && ((pending[addr] + DELAY_PERIOD) < now)); pending[addr] = 0; contracts[addr] = true; } /** * Revoke access for specified contract. Can be done instantly. * * @dev ProxyRegistry owner only * @param addr Address of which to revoke permissions */ function revokeAuthentication (address addr) public onlyOwner { contracts[addr] = false; } /** * Register a proxy contract with this registry * * @dev Must be called by the user which the proxy is for, creates a new AuthenticatedProxy * @return New AuthenticatedProxy contract */ function registerProxy() public returns (OwnableDelegateProxy proxy) { require(proxies[msg.sender] == address(0)); proxy = new OwnableDelegateProxy(msg.sender, delegateProxyImplementation, abi.encodeWithSignature("initialize(address,address)", msg.sender, address(this))); proxies[msg.sender] = proxy; return proxy; } }
endGrantAuthentication
function endGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] != 0 && ((pending[addr] + DELAY_PERIOD) < now)); pending[addr] = 0; contracts[addr] = true; }
/** * End the process to nable access for specified contract after delay period has passed. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 1706, 1967 ] }
10,756
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
ProxyRegistry
contract ProxyRegistry is Ownable { /* DelegateProxy implementation contract. Must be initialized. */ address public delegateProxyImplementation; /* Authenticated proxies by user. */ mapping(address => OwnableDelegateProxy) public proxies; /* Contracts pending access. */ mapping(address => uint) public pending; /* Contracts allowed to call those proxies. */ mapping(address => bool) public contracts; /* Delay period for adding an authenticated contract. This mitigates a particular class of potential attack on the Wyvern DAO (which owns this registry) - if at any point the value of assets held by proxy contracts exceeded the value of half the WYV supply (votes in the DAO), a malicious but rational attacker could buy half the Wyvern and grant themselves access to all the proxy contracts. A delay period renders this attack nonthreatening - given two weeks, if that happened, users would have plenty of time to notice and transfer their assets. */ uint public DELAY_PERIOD = 2 weeks; /** * Start the process to enable access for specified contract. Subject to delay period. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function startGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] == 0); pending[addr] = now; } /** * End the process to nable access for specified contract after delay period has passed. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function endGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] != 0 && ((pending[addr] + DELAY_PERIOD) < now)); pending[addr] = 0; contracts[addr] = true; } /** * Revoke access for specified contract. Can be done instantly. * * @dev ProxyRegistry owner only * @param addr Address of which to revoke permissions */ function revokeAuthentication (address addr) public onlyOwner { contracts[addr] = false; } /** * Register a proxy contract with this registry * * @dev Must be called by the user which the proxy is for, creates a new AuthenticatedProxy * @return New AuthenticatedProxy contract */ function registerProxy() public returns (OwnableDelegateProxy proxy) { require(proxies[msg.sender] == address(0)); proxy = new OwnableDelegateProxy(msg.sender, delegateProxyImplementation, abi.encodeWithSignature("initialize(address,address)", msg.sender, address(this))); proxies[msg.sender] = proxy; return proxy; } }
revokeAuthentication
function revokeAuthentication (address addr) public onlyOwner { contracts[addr] = false; }
/** * Revoke access for specified contract. Can be done instantly. * * @dev ProxyRegistry owner only * @param addr Address of which to revoke permissions */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 2166, 2298 ] }
10,757
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
ProxyRegistry
contract ProxyRegistry is Ownable { /* DelegateProxy implementation contract. Must be initialized. */ address public delegateProxyImplementation; /* Authenticated proxies by user. */ mapping(address => OwnableDelegateProxy) public proxies; /* Contracts pending access. */ mapping(address => uint) public pending; /* Contracts allowed to call those proxies. */ mapping(address => bool) public contracts; /* Delay period for adding an authenticated contract. This mitigates a particular class of potential attack on the Wyvern DAO (which owns this registry) - if at any point the value of assets held by proxy contracts exceeded the value of half the WYV supply (votes in the DAO), a malicious but rational attacker could buy half the Wyvern and grant themselves access to all the proxy contracts. A delay period renders this attack nonthreatening - given two weeks, if that happened, users would have plenty of time to notice and transfer their assets. */ uint public DELAY_PERIOD = 2 weeks; /** * Start the process to enable access for specified contract. Subject to delay period. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function startGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] == 0); pending[addr] = now; } /** * End the process to nable access for specified contract after delay period has passed. * * @dev ProxyRegistry owner only * @param addr Address to which to grant permissions */ function endGrantAuthentication (address addr) public onlyOwner { require(!contracts[addr] && pending[addr] != 0 && ((pending[addr] + DELAY_PERIOD) < now)); pending[addr] = 0; contracts[addr] = true; } /** * Revoke access for specified contract. Can be done instantly. * * @dev ProxyRegistry owner only * @param addr Address of which to revoke permissions */ function revokeAuthentication (address addr) public onlyOwner { contracts[addr] = false; } /** * Register a proxy contract with this registry * * @dev Must be called by the user which the proxy is for, creates a new AuthenticatedProxy * @return New AuthenticatedProxy contract */ function registerProxy() public returns (OwnableDelegateProxy proxy) { require(proxies[msg.sender] == address(0)); proxy = new OwnableDelegateProxy(msg.sender, delegateProxyImplementation, abi.encodeWithSignature("initialize(address,address)", msg.sender, address(this))); proxies[msg.sender] = proxy; return proxy; } }
registerProxy
function registerProxy() public returns (OwnableDelegateProxy proxy) { require(proxies[msg.sender] == address(0)); proxy = new OwnableDelegateProxy(msg.sender, delegateProxyImplementation, abi.encodeWithSignature("initialize(address,address)", msg.sender, address(this))); proxies[msg.sender] = proxy; return proxy; }
/** * Register a proxy contract with this registry * * @dev Must be called by the user which the proxy is for, creates a new AuthenticatedProxy * @return New AuthenticatedProxy contract */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 2525, 2911 ] }
10,758
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
WyvernProxyRegistry
contract WyvernProxyRegistry is ProxyRegistry { string public constant name = "Project Wyvern Proxy Registry"; /* Whether the initial auth address has been set. */ bool public initialAddressSet = false; constructor () public { delegateProxyImplementation = new AuthenticatedProxy(); } /** * Grant authentication to the initial Exchange protocol contract * * @dev No delay, can only be called once - after that the standard registry process with a delay must be used * @param authAddress Address of the contract to grant authentication */ function grantInitialAuthentication (address authAddress) onlyOwner public { require(!initialAddressSet); initialAddressSet = true; contracts[authAddress] = true; } }
grantInitialAuthentication
function grantInitialAuthentication (address authAddress) onlyOwner public { require(!initialAddressSet); initialAddressSet = true; contracts[authAddress] = true; }
/** * Grant authentication to the initial Exchange protocol contract * * @dev No delay, can only be called once - after that the standard registry process with a delay must be used * @param authAddress Address of the contract to grant authentication */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 631, 855 ] }
10,759
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityStorage
contract OwnedUpgradeabilityStorage { // Current implementation address internal _implementation; // Owner of the contract address private _upgradeabilityOwner; /** * @dev Tells the address of the owner * @return the address of the owner */ function upgradeabilityOwner() public view returns (address) { return _upgradeabilityOwner; } /** * @dev Sets the address of the owner */ function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal { _upgradeabilityOwner = newUpgradeabilityOwner; } /** * @dev Tells the address of the current implementation * @return address of the current implementation */ function implementation() public view returns (address) { return _implementation; } /** * @dev Tells the proxy type (EIP 897) * @return Proxy type, 2 for forwarding proxy */ function proxyType() public pure returns (uint256 proxyTypeId) { return 2; } }
upgradeabilityOwner
function upgradeabilityOwner() public view returns (address) { return _upgradeabilityOwner; }
/** * @dev Tells the address of the owner * @return the address of the owner */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 275, 379 ] }
10,760
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityStorage
contract OwnedUpgradeabilityStorage { // Current implementation address internal _implementation; // Owner of the contract address private _upgradeabilityOwner; /** * @dev Tells the address of the owner * @return the address of the owner */ function upgradeabilityOwner() public view returns (address) { return _upgradeabilityOwner; } /** * @dev Sets the address of the owner */ function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal { _upgradeabilityOwner = newUpgradeabilityOwner; } /** * @dev Tells the address of the current implementation * @return address of the current implementation */ function implementation() public view returns (address) { return _implementation; } /** * @dev Tells the proxy type (EIP 897) * @return Proxy type, 2 for forwarding proxy */ function proxyType() public pure returns (uint256 proxyTypeId) { return 2; } }
setUpgradeabilityOwner
function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal { _upgradeabilityOwner = newUpgradeabilityOwner; }
/** * @dev Sets the address of the owner */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 437, 571 ] }
10,761
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityStorage
contract OwnedUpgradeabilityStorage { // Current implementation address internal _implementation; // Owner of the contract address private _upgradeabilityOwner; /** * @dev Tells the address of the owner * @return the address of the owner */ function upgradeabilityOwner() public view returns (address) { return _upgradeabilityOwner; } /** * @dev Sets the address of the owner */ function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal { _upgradeabilityOwner = newUpgradeabilityOwner; } /** * @dev Tells the address of the current implementation * @return address of the current implementation */ function implementation() public view returns (address) { return _implementation; } /** * @dev Tells the proxy type (EIP 897) * @return Proxy type, 2 for forwarding proxy */ function proxyType() public pure returns (uint256 proxyTypeId) { return 2; } }
implementation
function implementation() public view returns (address) { return _implementation; }
/** * @dev Tells the address of the current implementation * @return address of the current implementation */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 696, 790 ] }
10,762
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityStorage
contract OwnedUpgradeabilityStorage { // Current implementation address internal _implementation; // Owner of the contract address private _upgradeabilityOwner; /** * @dev Tells the address of the owner * @return the address of the owner */ function upgradeabilityOwner() public view returns (address) { return _upgradeabilityOwner; } /** * @dev Sets the address of the owner */ function setUpgradeabilityOwner(address newUpgradeabilityOwner) internal { _upgradeabilityOwner = newUpgradeabilityOwner; } /** * @dev Tells the address of the current implementation * @return address of the current implementation */ function implementation() public view returns (address) { return _implementation; } /** * @dev Tells the proxy type (EIP 897) * @return Proxy type, 2 for forwarding proxy */ function proxyType() public pure returns (uint256 proxyTypeId) { return 2; } }
proxyType
function proxyType() public pure returns (uint256 proxyTypeId) { return 2; }
/** * @dev Tells the proxy type (EIP 897) * @return Proxy type, 2 for forwarding proxy */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 895, 982 ] }
10,763
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
AuthenticatedProxy
contract AuthenticatedProxy is TokenRecipient, OwnedUpgradeabilityStorage { /* Whether initialized. */ bool initialized = false; /* Address which owns this proxy. */ address public user; /* Associated registry with contract authentication information. */ ProxyRegistry public registry; /* Whether access has been revoked. */ bool public revoked; /* Delegate call could be used to atomically transfer multiple assets owned by the proxy contract with one order. */ enum HowToCall { Call, DelegateCall } /* Event fired when the proxy access is revoked or unrevoked. */ event Revoked(bool revoked); /** * Initialize an AuthenticatedProxy * * @param addrUser Address of user on whose behalf this proxy will act * @param addrRegistry Address of ProxyRegistry contract which will manage this proxy */ function initialize (address addrUser, ProxyRegistry addrRegistry) public { require(!initialized); initialized = true; user = addrUser; registry = addrRegistry; } /** * Set the revoked flag (allows a user to revoke ProxyRegistry access) * * @dev Can be called by the user only * @param revoke Whether or not to revoke access */ function setRevoke(bool revoke) public { require(msg.sender == user); revoked = revoke; emit Revoked(revoke); } /** * Execute a message call from the proxy contract * * @dev Can be called by the user, or by a contract authorized by the registry as long as the user has not revoked access * @param dest Address to which the call will be sent * @param howToCall Which kind of call to make * @param calldata Calldata to send * @return Result of the call (success or failure) */ function proxy(address dest, HowToCall howToCall, bytes calldata) public returns (bool result) { require(msg.sender == user || (!revoked && registry.contracts(msg.sender))); if (howToCall == HowToCall.Call) { result = dest.call(calldata); } else if (howToCall == HowToCall.DelegateCall) { result = dest.delegatecall(calldata); } return result; } /** * Execute a message call and assert success * * @dev Same functionality as `proxy`, just asserts the return value * @param dest Address to which the call will be sent * @param howToCall What kind of call to make * @param calldata Calldata to send */ function proxyAssert(address dest, HowToCall howToCall, bytes calldata) public { require(proxy(dest, howToCall, calldata)); } }
initialize
function initialize (address addrUser, ProxyRegistry addrRegistry) public { require(!initialized); initialized = true; user = addrUser; registry = addrRegistry; }
/** * Initialize an AuthenticatedProxy * * @param addrUser Address of user on whose behalf this proxy will act * @param addrRegistry Address of ProxyRegistry contract which will manage this proxy */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 904, 1126 ] }
10,764
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
AuthenticatedProxy
contract AuthenticatedProxy is TokenRecipient, OwnedUpgradeabilityStorage { /* Whether initialized. */ bool initialized = false; /* Address which owns this proxy. */ address public user; /* Associated registry with contract authentication information. */ ProxyRegistry public registry; /* Whether access has been revoked. */ bool public revoked; /* Delegate call could be used to atomically transfer multiple assets owned by the proxy contract with one order. */ enum HowToCall { Call, DelegateCall } /* Event fired when the proxy access is revoked or unrevoked. */ event Revoked(bool revoked); /** * Initialize an AuthenticatedProxy * * @param addrUser Address of user on whose behalf this proxy will act * @param addrRegistry Address of ProxyRegistry contract which will manage this proxy */ function initialize (address addrUser, ProxyRegistry addrRegistry) public { require(!initialized); initialized = true; user = addrUser; registry = addrRegistry; } /** * Set the revoked flag (allows a user to revoke ProxyRegistry access) * * @dev Can be called by the user only * @param revoke Whether or not to revoke access */ function setRevoke(bool revoke) public { require(msg.sender == user); revoked = revoke; emit Revoked(revoke); } /** * Execute a message call from the proxy contract * * @dev Can be called by the user, or by a contract authorized by the registry as long as the user has not revoked access * @param dest Address to which the call will be sent * @param howToCall Which kind of call to make * @param calldata Calldata to send * @return Result of the call (success or failure) */ function proxy(address dest, HowToCall howToCall, bytes calldata) public returns (bool result) { require(msg.sender == user || (!revoked && registry.contracts(msg.sender))); if (howToCall == HowToCall.Call) { result = dest.call(calldata); } else if (howToCall == HowToCall.DelegateCall) { result = dest.delegatecall(calldata); } return result; } /** * Execute a message call and assert success * * @dev Same functionality as `proxy`, just asserts the return value * @param dest Address to which the call will be sent * @param howToCall What kind of call to make * @param calldata Calldata to send */ function proxyAssert(address dest, HowToCall howToCall, bytes calldata) public { require(proxy(dest, howToCall, calldata)); } }
setRevoke
function setRevoke(bool revoke) public { require(msg.sender == user); revoked = revoke; emit Revoked(revoke); }
/** * Set the revoked flag (allows a user to revoke ProxyRegistry access) * * @dev Can be called by the user only * @param revoke Whether or not to revoke access */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 1329, 1491 ] }
10,765
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
AuthenticatedProxy
contract AuthenticatedProxy is TokenRecipient, OwnedUpgradeabilityStorage { /* Whether initialized. */ bool initialized = false; /* Address which owns this proxy. */ address public user; /* Associated registry with contract authentication information. */ ProxyRegistry public registry; /* Whether access has been revoked. */ bool public revoked; /* Delegate call could be used to atomically transfer multiple assets owned by the proxy contract with one order. */ enum HowToCall { Call, DelegateCall } /* Event fired when the proxy access is revoked or unrevoked. */ event Revoked(bool revoked); /** * Initialize an AuthenticatedProxy * * @param addrUser Address of user on whose behalf this proxy will act * @param addrRegistry Address of ProxyRegistry contract which will manage this proxy */ function initialize (address addrUser, ProxyRegistry addrRegistry) public { require(!initialized); initialized = true; user = addrUser; registry = addrRegistry; } /** * Set the revoked flag (allows a user to revoke ProxyRegistry access) * * @dev Can be called by the user only * @param revoke Whether or not to revoke access */ function setRevoke(bool revoke) public { require(msg.sender == user); revoked = revoke; emit Revoked(revoke); } /** * Execute a message call from the proxy contract * * @dev Can be called by the user, or by a contract authorized by the registry as long as the user has not revoked access * @param dest Address to which the call will be sent * @param howToCall Which kind of call to make * @param calldata Calldata to send * @return Result of the call (success or failure) */ function proxy(address dest, HowToCall howToCall, bytes calldata) public returns (bool result) { require(msg.sender == user || (!revoked && registry.contracts(msg.sender))); if (howToCall == HowToCall.Call) { result = dest.call(calldata); } else if (howToCall == HowToCall.DelegateCall) { result = dest.delegatecall(calldata); } return result; } /** * Execute a message call and assert success * * @dev Same functionality as `proxy`, just asserts the return value * @param dest Address to which the call will be sent * @param howToCall What kind of call to make * @param calldata Calldata to send */ function proxyAssert(address dest, HowToCall howToCall, bytes calldata) public { require(proxy(dest, howToCall, calldata)); } }
proxy
function proxy(address dest, HowToCall howToCall, bytes calldata) public returns (bool result) { require(msg.sender == user || (!revoked && registry.contracts(msg.sender))); if (howToCall == HowToCall.Call) { result = dest.call(calldata); } else if (howToCall == HowToCall.DelegateCall) { result = dest.delegatecall(calldata); } return result; }
/** * Execute a message call from the proxy contract * * @dev Can be called by the user, or by a contract authorized by the registry as long as the user has not revoked access * @param dest Address to which the call will be sent * @param howToCall Which kind of call to make * @param calldata Calldata to send * @return Result of the call (success or failure) */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 1910, 2359 ] }
10,766
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
AuthenticatedProxy
contract AuthenticatedProxy is TokenRecipient, OwnedUpgradeabilityStorage { /* Whether initialized. */ bool initialized = false; /* Address which owns this proxy. */ address public user; /* Associated registry with contract authentication information. */ ProxyRegistry public registry; /* Whether access has been revoked. */ bool public revoked; /* Delegate call could be used to atomically transfer multiple assets owned by the proxy contract with one order. */ enum HowToCall { Call, DelegateCall } /* Event fired when the proxy access is revoked or unrevoked. */ event Revoked(bool revoked); /** * Initialize an AuthenticatedProxy * * @param addrUser Address of user on whose behalf this proxy will act * @param addrRegistry Address of ProxyRegistry contract which will manage this proxy */ function initialize (address addrUser, ProxyRegistry addrRegistry) public { require(!initialized); initialized = true; user = addrUser; registry = addrRegistry; } /** * Set the revoked flag (allows a user to revoke ProxyRegistry access) * * @dev Can be called by the user only * @param revoke Whether or not to revoke access */ function setRevoke(bool revoke) public { require(msg.sender == user); revoked = revoke; emit Revoked(revoke); } /** * Execute a message call from the proxy contract * * @dev Can be called by the user, or by a contract authorized by the registry as long as the user has not revoked access * @param dest Address to which the call will be sent * @param howToCall Which kind of call to make * @param calldata Calldata to send * @return Result of the call (success or failure) */ function proxy(address dest, HowToCall howToCall, bytes calldata) public returns (bool result) { require(msg.sender == user || (!revoked && registry.contracts(msg.sender))); if (howToCall == HowToCall.Call) { result = dest.call(calldata); } else if (howToCall == HowToCall.DelegateCall) { result = dest.delegatecall(calldata); } return result; } /** * Execute a message call and assert success * * @dev Same functionality as `proxy`, just asserts the return value * @param dest Address to which the call will be sent * @param howToCall What kind of call to make * @param calldata Calldata to send */ function proxyAssert(address dest, HowToCall howToCall, bytes calldata) public { require(proxy(dest, howToCall, calldata)); } }
proxyAssert
function proxyAssert(address dest, HowToCall howToCall, bytes calldata) public { require(proxy(dest, howToCall, calldata)); }
/** * Execute a message call and assert success * * @dev Same functionality as `proxy`, just asserts the return value * @param dest Address to which the call will be sent * @param howToCall What kind of call to make * @param calldata Calldata to send */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 2664, 2822 ] }
10,767
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
Proxy
contract Proxy { /** * @dev Tells the address of the implementation where every call will be delegated. * @return address of the implementation to which it will be delegated */ function implementation() public view returns (address); /** * @dev Tells the type of proxy (EIP 897) * @return Type of proxy, 2 for upgradeable proxy */ function proxyType() public pure returns (uint256 proxyTypeId); /** * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */ function () payable public { address _impl = implementation(); require(_impl != address(0)); assembly { let ptr := mload(0x40) calldatacopy(ptr, 0, calldatasize) let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) let size := returndatasize returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } } }
implementation
function implementation() public view returns (address);
/** * @dev Tells the address of the implementation where every call will be delegated. * @return address of the implementation to which it will be delegated */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 192, 251 ] }
10,768
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
Proxy
contract Proxy { /** * @dev Tells the address of the implementation where every call will be delegated. * @return address of the implementation to which it will be delegated */ function implementation() public view returns (address); /** * @dev Tells the type of proxy (EIP 897) * @return Type of proxy, 2 for upgradeable proxy */ function proxyType() public pure returns (uint256 proxyTypeId); /** * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */ function () payable public { address _impl = implementation(); require(_impl != address(0)); assembly { let ptr := mload(0x40) calldatacopy(ptr, 0, calldatasize) let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) let size := returndatasize returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } } }
proxyType
function proxyType() public pure returns (uint256 proxyTypeId);
/** * @dev Tells the type of proxy (EIP 897) * @return Type of proxy, 2 for upgradeable proxy */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 363, 429 ] }
10,769
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
Proxy
contract Proxy { /** * @dev Tells the address of the implementation where every call will be delegated. * @return address of the implementation to which it will be delegated */ function implementation() public view returns (address); /** * @dev Tells the type of proxy (EIP 897) * @return Type of proxy, 2 for upgradeable proxy */ function proxyType() public pure returns (uint256 proxyTypeId); /** * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */ function () payable public { address _impl = implementation(); require(_impl != address(0)); assembly { let ptr := mload(0x40) calldatacopy(ptr, 0, calldatasize) let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) let size := returndatasize returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } } }
function () payable public { address _impl = implementation(); require(_impl != address(0)); assembly { let ptr := mload(0x40) calldatacopy(ptr, 0, calldatasize) let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) let size := returndatasize returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } }
/** * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 609, 1053 ] }
10,770
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityProxy
contract OwnedUpgradeabilityProxy is Proxy, OwnedUpgradeabilityStorage { /** * @dev Event to show ownership has been transferred * @param previousOwner representing the address of the previous owner * @param newOwner representing the address of the new owner */ event ProxyOwnershipTransferred(address previousOwner, address newOwner); /** * @dev This event will be emitted every time the implementation gets upgraded * @param implementation representing the address of the upgraded implementation */ event Upgraded(address indexed implementation); /** * @dev Upgrades the implementation address * @param implementation representing the address of the new implementation to be set */ function _upgradeTo(address implementation) internal { require(_implementation != implementation); _implementation = implementation; emit Upgraded(implementation); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyProxyOwner() { require(msg.sender == proxyOwner()); _; } /** * @dev Tells the address of the proxy owner * @return the address of the proxy owner */ function proxyOwner() public view returns (address) { return upgradeabilityOwner(); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0)); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy. * @param implementation representing the address of the new implementation to be set. */ function upgradeTo(address implementation) public onlyProxyOwner { _upgradeTo(implementation); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy * and delegatecall the new implementation for initialization. * @param implementation representing the address of the new implementation to be set. * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function * signature of the implementation to be called with the needed payload */ function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { upgradeTo(implementation); require(address(this).delegatecall(data)); } }
_upgradeTo
function _upgradeTo(address implementation) internal { require(_implementation != implementation); _implementation = implementation; emit Upgraded(implementation); }
/** * @dev Upgrades the implementation address * @param implementation representing the address of the new implementation to be set */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 734, 920 ] }
10,771
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityProxy
contract OwnedUpgradeabilityProxy is Proxy, OwnedUpgradeabilityStorage { /** * @dev Event to show ownership has been transferred * @param previousOwner representing the address of the previous owner * @param newOwner representing the address of the new owner */ event ProxyOwnershipTransferred(address previousOwner, address newOwner); /** * @dev This event will be emitted every time the implementation gets upgraded * @param implementation representing the address of the upgraded implementation */ event Upgraded(address indexed implementation); /** * @dev Upgrades the implementation address * @param implementation representing the address of the new implementation to be set */ function _upgradeTo(address implementation) internal { require(_implementation != implementation); _implementation = implementation; emit Upgraded(implementation); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyProxyOwner() { require(msg.sender == proxyOwner()); _; } /** * @dev Tells the address of the proxy owner * @return the address of the proxy owner */ function proxyOwner() public view returns (address) { return upgradeabilityOwner(); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0)); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy. * @param implementation representing the address of the new implementation to be set. */ function upgradeTo(address implementation) public onlyProxyOwner { _upgradeTo(implementation); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy * and delegatecall the new implementation for initialization. * @param implementation representing the address of the new implementation to be set. * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function * signature of the implementation to be called with the needed payload */ function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { upgradeTo(implementation); require(address(this).delegatecall(data)); } }
proxyOwner
function proxyOwner() public view returns (address) { return upgradeabilityOwner(); }
/** * @dev Tells the address of the proxy owner * @return the address of the proxy owner */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 1195, 1291 ] }
10,772
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityProxy
contract OwnedUpgradeabilityProxy is Proxy, OwnedUpgradeabilityStorage { /** * @dev Event to show ownership has been transferred * @param previousOwner representing the address of the previous owner * @param newOwner representing the address of the new owner */ event ProxyOwnershipTransferred(address previousOwner, address newOwner); /** * @dev This event will be emitted every time the implementation gets upgraded * @param implementation representing the address of the upgraded implementation */ event Upgraded(address indexed implementation); /** * @dev Upgrades the implementation address * @param implementation representing the address of the new implementation to be set */ function _upgradeTo(address implementation) internal { require(_implementation != implementation); _implementation = implementation; emit Upgraded(implementation); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyProxyOwner() { require(msg.sender == proxyOwner()); _; } /** * @dev Tells the address of the proxy owner * @return the address of the proxy owner */ function proxyOwner() public view returns (address) { return upgradeabilityOwner(); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0)); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy. * @param implementation representing the address of the new implementation to be set. */ function upgradeTo(address implementation) public onlyProxyOwner { _upgradeTo(implementation); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy * and delegatecall the new implementation for initialization. * @param implementation representing the address of the new implementation to be set. * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function * signature of the implementation to be called with the needed payload */ function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { upgradeTo(implementation); require(address(this).delegatecall(data)); } }
transferProxyOwnership
function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0)); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); }
/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 1455, 1674 ] }
10,773
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityProxy
contract OwnedUpgradeabilityProxy is Proxy, OwnedUpgradeabilityStorage { /** * @dev Event to show ownership has been transferred * @param previousOwner representing the address of the previous owner * @param newOwner representing the address of the new owner */ event ProxyOwnershipTransferred(address previousOwner, address newOwner); /** * @dev This event will be emitted every time the implementation gets upgraded * @param implementation representing the address of the upgraded implementation */ event Upgraded(address indexed implementation); /** * @dev Upgrades the implementation address * @param implementation representing the address of the new implementation to be set */ function _upgradeTo(address implementation) internal { require(_implementation != implementation); _implementation = implementation; emit Upgraded(implementation); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyProxyOwner() { require(msg.sender == proxyOwner()); _; } /** * @dev Tells the address of the proxy owner * @return the address of the proxy owner */ function proxyOwner() public view returns (address) { return upgradeabilityOwner(); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0)); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy. * @param implementation representing the address of the new implementation to be set. */ function upgradeTo(address implementation) public onlyProxyOwner { _upgradeTo(implementation); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy * and delegatecall the new implementation for initialization. * @param implementation representing the address of the new implementation to be set. * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function * signature of the implementation to be called with the needed payload */ function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { upgradeTo(implementation); require(address(this).delegatecall(data)); } }
upgradeTo
function upgradeTo(address implementation) public onlyProxyOwner { _upgradeTo(implementation); }
/** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy. * @param implementation representing the address of the new implementation to be set. */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 1876, 1983 ] }
10,774
WyvernProxyRegistry
WyvernProxyRegistry.sol
0x7fac518583390d8546c69bad5f73a44904be75a1
Solidity
OwnedUpgradeabilityProxy
contract OwnedUpgradeabilityProxy is Proxy, OwnedUpgradeabilityStorage { /** * @dev Event to show ownership has been transferred * @param previousOwner representing the address of the previous owner * @param newOwner representing the address of the new owner */ event ProxyOwnershipTransferred(address previousOwner, address newOwner); /** * @dev This event will be emitted every time the implementation gets upgraded * @param implementation representing the address of the upgraded implementation */ event Upgraded(address indexed implementation); /** * @dev Upgrades the implementation address * @param implementation representing the address of the new implementation to be set */ function _upgradeTo(address implementation) internal { require(_implementation != implementation); _implementation = implementation; emit Upgraded(implementation); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyProxyOwner() { require(msg.sender == proxyOwner()); _; } /** * @dev Tells the address of the proxy owner * @return the address of the proxy owner */ function proxyOwner() public view returns (address) { return upgradeabilityOwner(); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferProxyOwnership(address newOwner) public onlyProxyOwner { require(newOwner != address(0)); emit ProxyOwnershipTransferred(proxyOwner(), newOwner); setUpgradeabilityOwner(newOwner); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy. * @param implementation representing the address of the new implementation to be set. */ function upgradeTo(address implementation) public onlyProxyOwner { _upgradeTo(implementation); } /** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy * and delegatecall the new implementation for initialization. * @param implementation representing the address of the new implementation to be set. * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function * signature of the implementation to be called with the needed payload */ function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { upgradeTo(implementation); require(address(this).delegatecall(data)); } }
upgradeToAndCall
function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { upgradeTo(implementation); require(address(this).delegatecall(data)); }
/** * @dev Allows the upgradeability owner to upgrade the current implementation of the proxy * and delegatecall the new implementation for initialization. * @param implementation representing the address of the new implementation to be set. * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function * signature of the implementation to be called with the needed payload */
NatSpecMultiLine
v0.4.23+commit.124ca40d
bzzr://66f913efcdd02e2c74a318790fea4a3cf17890793a525c07242fc2adc74ac9e3
{ "func_code_index": [ 2442, 2623 ] }
10,775
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
totalSupply
function totalSupply() external view returns (uint256);
/** * @dev Returns the amount of tokens in existence. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 94, 154 ] }
10,776
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
balanceOf
function balanceOf(address account) external view returns (uint256);
/** * @dev Returns the amount of tokens owned by `account`. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 237, 310 ] }
10,777
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 534, 616 ] }
10,778
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
allowance
function allowance(address owner, address spender) external view returns (uint256);
/** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 895, 983 ] }
10,779
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
approve
function approve(address spender, uint256 amount) external returns (bool);
/** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 1647, 1726 ] }
10,780
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
IERC20
interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
transferFrom
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 2039, 2141 ] }
10,781
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
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.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 259, 445 ] }
10,782
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
sub
function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); }
/** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 723, 864 ] }
10,783
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
sub
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; }
/** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 1162, 1359 ] }
10,784
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
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-contracts/pull/522 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.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 1613, 2089 ] }
10,785
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
div
function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); }
/** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 2560, 2697 ] }
10,786
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
div
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; }
/** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 3188, 3471 ] }
10,787
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
mod
function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 3931, 4066 ] }
10,788
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
SafeMath
library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
mod
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; }
/** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 4546, 4717 ] }
10,789
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
isContract
function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); }
/** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 606, 1230 ] }
10,790
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
sendValue
function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); }
/** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 2160, 2562 ] }
10,791
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCall
function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); }
/** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 3318, 3498 ] }
10,792
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCall
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 3723, 3924 ] }
10,793
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); }
/** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 4294, 4525 ] }
10,794
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
Solidity
Address
library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
functionCallWithValue
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); }
/** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 4776, 5097 ] }
10,795
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
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(_owner == _msgSender(), "Ownable: caller is not the 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 virtual 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 virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
owner
function owner() public view returns (address) { return _owner; }
/** * @dev Returns the address of the current owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 497, 581 ] }
10,796
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
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(_owner == _msgSender(), "Ownable: caller is not the 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 virtual 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 virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
renounceOwnership
function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); }
/** * @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. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 1139, 1292 ] }
10,797
BabyFrankenstein
BabyFrankenstein.sol
0x980d7e8c8800a74c0dcecd393bc296d1cc719406
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(_owner == _msgSender(), "Ownable: caller is not the 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 virtual 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 virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
transferOwnership
function transferOwnership(address newOwner) public virtual onlyOwner { 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`). * Can only be called by the current owner. */
NatSpecMultiLine
v0.6.12+commit.27d51765
None
ipfs://99a972ead6b0180b9af88de2719a3be97ff5242f008fa1e59393ff4fc8fc8ba1
{ "func_code_index": [ 1442, 1691 ] }
10,798
EternalStorageProxy
Proxy.sol
0x83e9918ddee45a661a31a63474f864d77b156724
Solidity
EternalStorageProxy
contract EternalStorageProxy is EternalStorage { /** * @param contractLogic - the address of the first implementation of this contract's logic */ constructor(address contractLogic) public { // save the code address addressStorage[keccak256('proxy.implementation')] = contractLogic; } /** * This function runs every time a function is invoked on this contract, it is the "fallback function" */ function() external payable { //get the address of the contract holding the logic implementation address contractLogic = addressStorage[keccak256('proxy.implementation')]; assembly { //copy the data embedded in the function call that triggered the fallback calldatacopy(0x0, 0x0, calldatasize) //delegate this call to the linked contract let success := delegatecall(sub(gas, 10000), contractLogic, 0x0, calldatasize, 0, 0) let retSz := returndatasize //get the returned data returndatacopy(0, 0, retSz) switch success case 0 { revert(0, retSz) } default { return(0, retSz) } } } }
/** * @title EternalStorage * @dev This is a proxy pattern that holds all the necessary state variables to carry out the storage of any contract. */
NatSpecMultiLine
function() external payable { //get the address of the contract holding the logic implementation address contractLogic = addressStorage[keccak256('proxy.implementation')]; assembly { //copy the data embedded in the function call that triggered the fallback calldatacopy(0x0, 0x0, calldatasize) //delegate this call to the linked contract let success := delegatecall(sub(gas, 10000), contractLogic, 0x0, calldatasize, 0, 0) let retSz := returndatasize //get the returned data returndatacopy(0, 0, retSz) switch success case 0 { revert(0, retSz) } default { return(0, retSz) } } }
/** * This function runs every time a function is invoked on this contract, it is the "fallback function" */
NatSpecMultiLine
v0.5.17+commit.d19bba13
None
bzzr://7a7847732b508c4552f2c302f7d7a82333fe137a7c14be1fb55cc889555d568b
{ "func_code_index": [ 456, 1260 ] }
10,799