Contract Overview
Balance:
0 MATIC
My Name Tag:
Not Available
[ Download CSV Export ]
Latest 25 internal transaction
[ Download CSV Export ]
Contract Name:
LongShortPairCreator
Compiler Version
v0.8.9+commit.e5eed63a
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { _approve(sender, _msgSender(), currentAllowance - amount); } return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(_msgSender(), spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); _afterTokenTransfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ 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); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @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. */ library SafeERC20 { 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' 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) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _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 require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ 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 on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; 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"); (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"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { 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 assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a / b + (a % b == 0 ? 0 : 1); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * 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) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SignedSafeMath` is no longer needed starting with Solidity 0.8. The compiler * now has built in overflow checking. */ library SignedSafeMath { /** * @dev Returns the multiplication of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(int256 a, int256 b) internal pure returns (int256) { return a * b; } /** * @dev Returns the integer division of two signed integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(int256 a, int256 b) internal pure returns (int256) { return a / b; } /** * @dev Returns the subtraction of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(int256 a, int256 b) internal pure returns (int256) { return a - b; } /** * @dev Returns the addition of two signed integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(int256 a, int256 b) internal pure returns (int256) { return a + b; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Library for encoding and decoding ancillary data for DVM price requests. * @notice We assume that on-chain ancillary data can be formatted directly from bytes to utf8 encoding via * web3.utils.hexToUtf8, and that clients will parse the utf8-encoded ancillary data as a comma-delimitted key-value * dictionary. Therefore, this library provides internal methods that aid appending to ancillary data from Solidity * smart contracts. More details on UMA's ancillary data guidelines below: * https://docs.google.com/document/d/1zhKKjgY1BupBGPPrY_WOJvui0B6DMcd-xDR8-9-SPDw/edit */ library AncillaryData { // This converts the bottom half of a bytes32 input to hex in a highly gas-optimized way. // Source: the brilliant implementation at https://gitter.im/ethereum/solidity?at=5840d23416207f7b0ed08c9b. function toUtf8Bytes32Bottom(bytes32 bytesIn) private pure returns (bytes32) { unchecked { uint256 x = uint256(bytesIn); // Nibble interleave x = x & 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; x = (x | (x * 2**64)) & 0x0000000000000000ffffffffffffffff0000000000000000ffffffffffffffff; x = (x | (x * 2**32)) & 0x00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff; x = (x | (x * 2**16)) & 0x0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff0000ffff; x = (x | (x * 2**8)) & 0x00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff00ff; x = (x | (x * 2**4)) & 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f; // Hex encode uint256 h = (x & 0x0808080808080808080808080808080808080808080808080808080808080808) / 8; uint256 i = (x & 0x0404040404040404040404040404040404040404040404040404040404040404) / 4; uint256 j = (x & 0x0202020202020202020202020202020202020202020202020202020202020202) / 2; x = x + (h & (i | j)) * 0x27 + 0x3030303030303030303030303030303030303030303030303030303030303030; // Return the result. return bytes32(x); } } /** * @notice Returns utf8-encoded bytes32 string that can be read via web3.utils.hexToUtf8. * @dev Will return bytes32 in all lower case hex characters and without the leading 0x. * This has minor changes from the toUtf8BytesAddress to control for the size of the input. * @param bytesIn bytes32 to encode. * @return utf8 encoded bytes32. */ function toUtf8Bytes(bytes32 bytesIn) internal pure returns (bytes memory) { return abi.encodePacked(toUtf8Bytes32Bottom(bytesIn >> 128), toUtf8Bytes32Bottom(bytesIn)); } /** * @notice Returns utf8-encoded address that can be read via web3.utils.hexToUtf8. * Source: https://ethereum.stackexchange.com/questions/8346/convert-address-to-string/8447#8447 * @dev Will return address in all lower case characters and without the leading 0x. * @param x address to encode. * @return utf8 encoded address bytes. */ function toUtf8BytesAddress(address x) internal pure returns (bytes memory) { return abi.encodePacked(toUtf8Bytes32Bottom(bytes32(bytes20(x)) >> 128), bytes8(toUtf8Bytes32Bottom(bytes20(x)))); } /** * @notice Converts a uint into a base-10, UTF-8 representation stored in a `string` type. * @dev This method is based off of this code: https://stackoverflow.com/a/65707309. */ function toUtf8BytesUint(uint256 x) internal pure returns (bytes memory) { if (x == 0) { return "0"; } uint256 j = x; uint256 len; while (j != 0) { len++; j /= 10; } bytes memory bstr = new bytes(len); uint256 k = len; while (x != 0) { k = k - 1; uint8 temp = (48 + uint8(x - (x / 10) * 10)); bytes1 b1 = bytes1(temp); bstr[k] = b1; x /= 10; } return bstr; } function appendKeyValueBytes32( bytes memory currentAncillaryData, bytes memory key, bytes32 value ) internal pure returns (bytes memory) { bytes memory prefix = constructPrefix(currentAncillaryData, key); return abi.encodePacked(currentAncillaryData, prefix, toUtf8Bytes(value)); } /** * @notice Adds "key:value" to `currentAncillaryData` where `value` is an address that first needs to be converted * to utf8 bytes. For example, if `utf8(currentAncillaryData)="k1:v1"`, then this function will return * `utf8(k1:v1,key:value)`, and if `currentAncillaryData` is blank, then this will return `utf8(key:value)`. * @param currentAncillaryData This bytes data should ideally be able to be utf8-decoded, but its OK if not. * @param key Again, this bytes data should ideally be able to be utf8-decoded, but its OK if not. * @param value An address to set as the value in the key:value pair to append to `currentAncillaryData`. * @return Newly appended ancillary data. */ function appendKeyValueAddress( bytes memory currentAncillaryData, bytes memory key, address value ) internal pure returns (bytes memory) { bytes memory prefix = constructPrefix(currentAncillaryData, key); return abi.encodePacked(currentAncillaryData, prefix, toUtf8BytesAddress(value)); } /** * @notice Adds "key:value" to `currentAncillaryData` where `value` is a uint that first needs to be converted * to utf8 bytes. For example, if `utf8(currentAncillaryData)="k1:v1"`, then this function will return * `utf8(k1:v1,key:value)`, and if `currentAncillaryData` is blank, then this will return `utf8(key:value)`. * @param currentAncillaryData This bytes data should ideally be able to be utf8-decoded, but its OK if not. * @param key Again, this bytes data should ideally be able to be utf8-decoded, but its OK if not. * @param value A uint to set as the value in the key:value pair to append to `currentAncillaryData`. * @return Newly appended ancillary data. */ function appendKeyValueUint( bytes memory currentAncillaryData, bytes memory key, uint256 value ) internal pure returns (bytes memory) { bytes memory prefix = constructPrefix(currentAncillaryData, key); return abi.encodePacked(currentAncillaryData, prefix, toUtf8BytesUint(value)); } /** * @notice Helper method that returns the left hand side of a "key:value" pair plus the colon ":" and a leading * comma "," if the `currentAncillaryData` is not empty. The return value is intended to be prepended as a prefix to * some utf8 value that is ultimately added to a comma-delimited, key-value dictionary. */ function constructPrefix(bytes memory currentAncillaryData, bytes memory key) internal pure returns (bytes memory) { if (currentAncillaryData.length > 0) { return abi.encodePacked(",", key, ":"); } else { return abi.encodePacked(key, ":"); } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "./MultiRole.sol"; import "../interfaces/ExpandedIERC20.sol"; /** * @title An ERC20 with permissioned burning and minting. The contract deployer will initially * be the owner who is capable of adding new roles. */ contract ExpandedERC20 is ExpandedIERC20, ERC20, MultiRole { enum Roles { // Can set the minter and burner. Owner, // Addresses that can mint new tokens. Minter, // Addresses that can burn tokens that address owns. Burner } uint8 _decimals; /** * @notice Constructs the ExpandedERC20. * @param _tokenName The name which describes the new token. * @param _tokenSymbol The ticker abbreviation of the name. Ideally < 5 chars. * @param _tokenDecimals The number of decimals to define token precision. */ constructor( string memory _tokenName, string memory _tokenSymbol, uint8 _tokenDecimals ) ERC20(_tokenName, _tokenSymbol) { _decimals = _tokenDecimals; _createExclusiveRole(uint256(Roles.Owner), uint256(Roles.Owner), msg.sender); _createSharedRole(uint256(Roles.Minter), uint256(Roles.Owner), new address[](0)); _createSharedRole(uint256(Roles.Burner), uint256(Roles.Owner), new address[](0)); } function decimals() public view virtual override(ERC20) returns (uint8) { return _decimals; } /** * @dev Mints `value` tokens to `recipient`, returning true on success. * @param recipient address to mint to. * @param value amount of tokens to mint. * @return True if the mint succeeded, or False. */ function mint(address recipient, uint256 value) external override onlyRoleHolder(uint256(Roles.Minter)) returns (bool) { _mint(recipient, value); return true; } /** * @dev Burns `value` tokens owned by `msg.sender`. * @param value amount of tokens to burn. */ function burn(uint256 value) external override onlyRoleHolder(uint256(Roles.Burner)) { _burn(msg.sender, value); } /** * @dev Burns `value` tokens owned by `recipient`. * @param recipient address to burn tokens from. * @param value amount of tokens to burn. * @return True if the burn succeeded, or False. */ function burnFrom(address recipient, uint256 value) external override onlyRoleHolder(uint256(Roles.Burner)) returns (bool) { _burn(recipient, value); return true; } /** * @notice Add Minter role to account. * @dev The caller must have the Owner role. * @param account The address to which the Minter role is added. */ function addMinter(address account) external virtual override { addMember(uint256(Roles.Minter), account); } /** * @notice Add Burner role to account. * @dev The caller must have the Owner role. * @param account The address to which the Burner role is added. */ function addBurner(address account) external virtual override { addMember(uint256(Roles.Burner), account); } /** * @notice Reset Owner role to account. * @dev The caller must have the Owner role. * @param account The new holder of the Owner role. */ function resetOwner(address account) external virtual override { resetMember(uint256(Roles.Owner), account); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/math/SignedSafeMath.sol"; /** * @title Library for fixed point arithmetic on uints */ library FixedPoint { using SafeMath for uint256; using SignedSafeMath for int256; // Supports 18 decimals. E.g., 1e18 represents "1", 5e17 represents "0.5". // For unsigned values: // This can represent a value up to (2^256 - 1)/10^18 = ~10^59. 10^59 will be stored internally as uint256 10^77. uint256 private constant FP_SCALING_FACTOR = 10**18; // --------------------------------------- UNSIGNED ----------------------------------------------------------------------------- struct Unsigned { uint256 rawValue; } /** * @notice Constructs an `Unsigned` from an unscaled uint, e.g., `b=5` gets stored internally as `5*(10**18)`. * @param a uint to convert into a FixedPoint. * @return the converted FixedPoint. */ function fromUnscaledUint(uint256 a) internal pure returns (Unsigned memory) { return Unsigned(a.mul(FP_SCALING_FACTOR)); } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if equal, or False. */ function isEqual(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue == fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if equal, or False. */ function isEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue == b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a > b`, or False. */ function isGreaterThan(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue > b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a > b`, or False. */ function isGreaterThan(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue > fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a > b`, or False. */ function isGreaterThan(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue > b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue >= b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue >= fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue >= b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a < b`, or False. */ function isLessThan(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue < b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a < b`, or False. */ function isLessThan(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue < fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a < b`, or False. */ function isLessThan(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue < b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Unsigned memory a, Unsigned memory b) internal pure returns (bool) { return a.rawValue <= b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint. * @param b a uint256. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Unsigned memory a, uint256 b) internal pure returns (bool) { return a.rawValue <= fromUnscaledUint(b).rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a uint256. * @param b a FixedPoint. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(uint256 a, Unsigned memory b) internal pure returns (bool) { return fromUnscaledUint(a).rawValue <= b.rawValue; } /** * @notice The minimum of `a` and `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return the minimum of `a` and `b`. */ function min(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return a.rawValue < b.rawValue ? a : b; } /** * @notice The maximum of `a` and `b`. * @param a a FixedPoint. * @param b a FixedPoint. * @return the maximum of `a` and `b`. */ function max(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return a.rawValue > b.rawValue ? a : b; } /** * @notice Adds two `Unsigned`s, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the sum of `a` and `b`. */ function add(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.add(b.rawValue)); } /** * @notice Adds an `Unsigned` to an unscaled uint, reverting on overflow. * @param a a FixedPoint. * @param b a uint256. * @return the sum of `a` and `b`. */ function add(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return add(a, fromUnscaledUint(b)); } /** * @notice Subtracts two `Unsigned`s, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the difference of `a` and `b`. */ function sub(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.sub(b.rawValue)); } /** * @notice Subtracts an unscaled uint256 from an `Unsigned`, reverting on overflow. * @param a a FixedPoint. * @param b a uint256. * @return the difference of `a` and `b`. */ function sub(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return sub(a, fromUnscaledUint(b)); } /** * @notice Subtracts an `Unsigned` from an unscaled uint256, reverting on overflow. * @param a a uint256. * @param b a FixedPoint. * @return the difference of `a` and `b`. */ function sub(uint256 a, Unsigned memory b) internal pure returns (Unsigned memory) { return sub(fromUnscaledUint(a), b); } /** * @notice Multiplies two `Unsigned`s, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint. * @param b a FixedPoint. * @return the product of `a` and `b`. */ function mul(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { // There are two caveats with this computation: // 1. Max output for the represented number is ~10^41, otherwise an intermediate value overflows. 10^41 is // stored internally as a uint256 ~10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 1.4 * 2e-18 = 2.8e-18, which // would round to 3, but this computation produces the result 2. // No need to use SafeMath because FP_SCALING_FACTOR != 0. return Unsigned(a.rawValue.mul(b.rawValue) / FP_SCALING_FACTOR); } /** * @notice Multiplies an `Unsigned` and an unscaled uint256, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint. * @param b a uint256. * @return the product of `a` and `b`. */ function mul(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.mul(b)); } /** * @notice Multiplies two `Unsigned`s and "ceil's" the product, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the product of `a` and `b`. */ function mulCeil(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { uint256 mulRaw = a.rawValue.mul(b.rawValue); uint256 mulFloor = mulRaw / FP_SCALING_FACTOR; uint256 mod = mulRaw.mod(FP_SCALING_FACTOR); if (mod != 0) { return Unsigned(mulFloor.add(1)); } else { return Unsigned(mulFloor); } } /** * @notice Multiplies an `Unsigned` and an unscaled uint256 and "ceil's" the product, reverting on overflow. * @param a a FixedPoint. * @param b a FixedPoint. * @return the product of `a` and `b`. */ function mulCeil(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { // Since b is an uint, there is no risk of truncation and we can just mul it normally return Unsigned(a.rawValue.mul(b)); } /** * @notice Divides one `Unsigned` by an `Unsigned`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { // There are two caveats with this computation: // 1. Max value for the number dividend `a` represents is ~10^41, otherwise an intermediate value overflows. // 10^41 is stored internally as a uint256 10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 2 / 3 = 0.6 repeating, which // would round to 0.666666666666666667, but this computation produces the result 0.666666666666666666. return Unsigned(a.rawValue.mul(FP_SCALING_FACTOR).div(b.rawValue)); } /** * @notice Divides one `Unsigned` by an unscaled uint256, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b a uint256 denominator. * @return the quotient of `a` divided by `b`. */ function div(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { return Unsigned(a.rawValue.div(b)); } /** * @notice Divides one unscaled uint256 by an `Unsigned`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a uint256 numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(uint256 a, Unsigned memory b) internal pure returns (Unsigned memory) { return div(fromUnscaledUint(a), b); } /** * @notice Divides one `Unsigned` by an `Unsigned` and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function divCeil(Unsigned memory a, Unsigned memory b) internal pure returns (Unsigned memory) { uint256 aScaled = a.rawValue.mul(FP_SCALING_FACTOR); uint256 divFloor = aScaled.div(b.rawValue); uint256 mod = aScaled.mod(b.rawValue); if (mod != 0) { return Unsigned(divFloor.add(1)); } else { return Unsigned(divFloor); } } /** * @notice Divides one `Unsigned` by an unscaled uint256 and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b a uint256 denominator. * @return the quotient of `a` divided by `b`. */ function divCeil(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory) { // Because it is possible that a quotient gets truncated, we can't just call "Unsigned(a.rawValue.div(b))" // similarly to mulCeil with a uint256 as the second parameter. Therefore we need to convert b into an Unsigned. // This creates the possibility of overflow if b is very large. return divCeil(a, fromUnscaledUint(b)); } /** * @notice Raises an `Unsigned` to the power of an unscaled uint256, reverting on overflow. E.g., `b=2` squares `a`. * @dev This will "floor" the result. * @param a a FixedPoint numerator. * @param b a uint256 denominator. * @return output is `a` to the power of `b`. */ function pow(Unsigned memory a, uint256 b) internal pure returns (Unsigned memory output) { output = fromUnscaledUint(1); for (uint256 i = 0; i < b; i = i.add(1)) { output = mul(output, a); } } // ------------------------------------------------- SIGNED ------------------------------------------------------------- // Supports 18 decimals. E.g., 1e18 represents "1", 5e17 represents "0.5". // For signed values: // This can represent a value up (or down) to +-(2^255 - 1)/10^18 = ~10^58. 10^58 will be stored internally as int256 10^76. int256 private constant SFP_SCALING_FACTOR = 10**18; struct Signed { int256 rawValue; } function fromSigned(Signed memory a) internal pure returns (Unsigned memory) { require(a.rawValue >= 0, "Negative value provided"); return Unsigned(uint256(a.rawValue)); } function fromUnsigned(Unsigned memory a) internal pure returns (Signed memory) { require(a.rawValue <= uint256(type(int256).max), "Unsigned too large"); return Signed(int256(a.rawValue)); } /** * @notice Constructs a `Signed` from an unscaled int, e.g., `b=5` gets stored internally as `5*(10**18)`. * @param a int to convert into a FixedPoint.Signed. * @return the converted FixedPoint.Signed. */ function fromUnscaledInt(int256 a) internal pure returns (Signed memory) { return Signed(a.mul(SFP_SCALING_FACTOR)); } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint.Signed. * @param b a int256. * @return True if equal, or False. */ function isEqual(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue == fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is equal to `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if equal, or False. */ function isEqual(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue == b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a > b`, or False. */ function isGreaterThan(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue > b.rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a > b`, or False. */ function isGreaterThan(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue > fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is greater than `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a > b`, or False. */ function isGreaterThan(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue > b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue >= b.rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue >= fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is greater than or equal to `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a >= b`, or False. */ function isGreaterThanOrEqual(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue >= b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a < b`, or False. */ function isLessThan(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue < b.rawValue; } /** * @notice Whether `a` is less than `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a < b`, or False. */ function isLessThan(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue < fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is less than `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a < b`, or False. */ function isLessThan(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue < b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Signed memory a, Signed memory b) internal pure returns (bool) { return a.rawValue <= b.rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a a FixedPoint.Signed. * @param b an int256. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(Signed memory a, int256 b) internal pure returns (bool) { return a.rawValue <= fromUnscaledInt(b).rawValue; } /** * @notice Whether `a` is less than or equal to `b`. * @param a an int256. * @param b a FixedPoint.Signed. * @return True if `a <= b`, or False. */ function isLessThanOrEqual(int256 a, Signed memory b) internal pure returns (bool) { return fromUnscaledInt(a).rawValue <= b.rawValue; } /** * @notice The minimum of `a` and `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the minimum of `a` and `b`. */ function min(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return a.rawValue < b.rawValue ? a : b; } /** * @notice The maximum of `a` and `b`. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the maximum of `a` and `b`. */ function max(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return a.rawValue > b.rawValue ? a : b; } /** * @notice Adds two `Signed`s, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the sum of `a` and `b`. */ function add(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return Signed(a.rawValue.add(b.rawValue)); } /** * @notice Adds an `Signed` to an unscaled int, reverting on overflow. * @param a a FixedPoint.Signed. * @param b an int256. * @return the sum of `a` and `b`. */ function add(Signed memory a, int256 b) internal pure returns (Signed memory) { return add(a, fromUnscaledInt(b)); } /** * @notice Subtracts two `Signed`s, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the difference of `a` and `b`. */ function sub(Signed memory a, Signed memory b) internal pure returns (Signed memory) { return Signed(a.rawValue.sub(b.rawValue)); } /** * @notice Subtracts an unscaled int256 from an `Signed`, reverting on overflow. * @param a a FixedPoint.Signed. * @param b an int256. * @return the difference of `a` and `b`. */ function sub(Signed memory a, int256 b) internal pure returns (Signed memory) { return sub(a, fromUnscaledInt(b)); } /** * @notice Subtracts an `Signed` from an unscaled int256, reverting on overflow. * @param a an int256. * @param b a FixedPoint.Signed. * @return the difference of `a` and `b`. */ function sub(int256 a, Signed memory b) internal pure returns (Signed memory) { return sub(fromUnscaledInt(a), b); } /** * @notice Multiplies two `Signed`s, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the product of `a` and `b`. */ function mul(Signed memory a, Signed memory b) internal pure returns (Signed memory) { // There are two caveats with this computation: // 1. Max output for the represented number is ~10^41, otherwise an intermediate value overflows. 10^41 is // stored internally as an int256 ~10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 1.4 * 2e-18 = 2.8e-18, which // would round to 3, but this computation produces the result 2. // No need to use SafeMath because SFP_SCALING_FACTOR != 0. return Signed(a.rawValue.mul(b.rawValue) / SFP_SCALING_FACTOR); } /** * @notice Multiplies an `Signed` and an unscaled int256, reverting on overflow. * @dev This will "floor" the product. * @param a a FixedPoint.Signed. * @param b an int256. * @return the product of `a` and `b`. */ function mul(Signed memory a, int256 b) internal pure returns (Signed memory) { return Signed(a.rawValue.mul(b)); } /** * @notice Multiplies two `Signed`s and "ceil's" the product, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the product of `a` and `b`. */ function mulAwayFromZero(Signed memory a, Signed memory b) internal pure returns (Signed memory) { int256 mulRaw = a.rawValue.mul(b.rawValue); int256 mulTowardsZero = mulRaw / SFP_SCALING_FACTOR; // Manual mod because SignedSafeMath doesn't support it. int256 mod = mulRaw % SFP_SCALING_FACTOR; if (mod != 0) { bool isResultPositive = isLessThan(a, 0) == isLessThan(b, 0); int256 valueToAdd = isResultPositive ? int256(1) : int256(-1); return Signed(mulTowardsZero.add(valueToAdd)); } else { return Signed(mulTowardsZero); } } /** * @notice Multiplies an `Signed` and an unscaled int256 and "ceil's" the product, reverting on overflow. * @param a a FixedPoint.Signed. * @param b a FixedPoint.Signed. * @return the product of `a` and `b`. */ function mulAwayFromZero(Signed memory a, int256 b) internal pure returns (Signed memory) { // Since b is an int, there is no risk of truncation and we can just mul it normally return Signed(a.rawValue.mul(b)); } /** * @notice Divides one `Signed` by an `Signed`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(Signed memory a, Signed memory b) internal pure returns (Signed memory) { // There are two caveats with this computation: // 1. Max value for the number dividend `a` represents is ~10^41, otherwise an intermediate value overflows. // 10^41 is stored internally as an int256 10^59. // 2. Results that can't be represented exactly are truncated not rounded. E.g., 2 / 3 = 0.6 repeating, which // would round to 0.666666666666666667, but this computation produces the result 0.666666666666666666. return Signed(a.rawValue.mul(SFP_SCALING_FACTOR).div(b.rawValue)); } /** * @notice Divides one `Signed` by an unscaled int256, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a a FixedPoint numerator. * @param b an int256 denominator. * @return the quotient of `a` divided by `b`. */ function div(Signed memory a, int256 b) internal pure returns (Signed memory) { return Signed(a.rawValue.div(b)); } /** * @notice Divides one unscaled int256 by an `Signed`, reverting on overflow or division by 0. * @dev This will "floor" the quotient. * @param a an int256 numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function div(int256 a, Signed memory b) internal pure returns (Signed memory) { return div(fromUnscaledInt(a), b); } /** * @notice Divides one `Signed` by an `Signed` and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b a FixedPoint denominator. * @return the quotient of `a` divided by `b`. */ function divAwayFromZero(Signed memory a, Signed memory b) internal pure returns (Signed memory) { int256 aScaled = a.rawValue.mul(SFP_SCALING_FACTOR); int256 divTowardsZero = aScaled.div(b.rawValue); // Manual mod because SignedSafeMath doesn't support it. int256 mod = aScaled % b.rawValue; if (mod != 0) { bool isResultPositive = isLessThan(a, 0) == isLessThan(b, 0); int256 valueToAdd = isResultPositive ? int256(1) : int256(-1); return Signed(divTowardsZero.add(valueToAdd)); } else { return Signed(divTowardsZero); } } /** * @notice Divides one `Signed` by an unscaled int256 and "ceil's" the quotient, reverting on overflow or division by 0. * @param a a FixedPoint numerator. * @param b an int256 denominator. * @return the quotient of `a` divided by `b`. */ function divAwayFromZero(Signed memory a, int256 b) internal pure returns (Signed memory) { // Because it is possible that a quotient gets truncated, we can't just call "Signed(a.rawValue.div(b))" // similarly to mulCeil with an int256 as the second parameter. Therefore we need to convert b into an Signed. // This creates the possibility of overflow if b is very large. return divAwayFromZero(a, fromUnscaledInt(b)); } /** * @notice Raises an `Signed` to the power of an unscaled uint256, reverting on overflow. E.g., `b=2` squares `a`. * @dev This will "floor" the result. * @param a a FixedPoint.Signed. * @param b a uint256 (negative exponents are not allowed). * @return output is `a` to the power of `b`. */ function pow(Signed memory a, uint256 b) internal pure returns (Signed memory output) { output = fromUnscaledInt(1); for (uint256 i = 0; i < b; i = i.add(1)) { output = mul(output, a); } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title A contract that provides modifiers to prevent reentrancy to state-changing and view-only methods. This contract * is inspired by https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/ReentrancyGuard.sol * and https://github.com/balancer-labs/balancer-core/blob/master/contracts/BPool.sol. */ contract Lockable { bool private _notEntered; constructor() { // Storing an initial non-zero value makes deployment a bit more expensive, but in exchange the refund on every // call to nonReentrant will be lower in amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to increase the likelihood of the full // refund coming into effect. _notEntered = true; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` function is not supported. It is possible to * prevent this from happening by making the `nonReentrant` function external, and making it call a `private` * function that does the actual state modification. */ modifier nonReentrant() { _preEntranceCheck(); _preEntranceSet(); _; _postEntranceReset(); } /** * @dev Designed to prevent a view-only method from being re-entered during a call to a `nonReentrant()` state-changing method. */ modifier nonReentrantView() { _preEntranceCheck(); _; } // Internal methods are used to avoid copying the require statement's bytecode to every `nonReentrant()` method. // On entry into a function, `_preEntranceCheck()` should always be called to check if the function is being // re-entered. Then, if the function modifies state, it should call `_postEntranceSet()`, perform its logic, and // then call `_postEntranceReset()`. // View-only methods can simply call `_preEntranceCheck()` to make sure that it is not being re-entered. function _preEntranceCheck() internal view { // On the first call to nonReentrant, _notEntered will be true require(_notEntered, "ReentrancyGuard: reentrant call"); } function _preEntranceSet() internal { // Any calls to nonReentrant after this point will fail _notEntered = false; } function _postEntranceReset() internal { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _notEntered = true; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; library Exclusive { struct RoleMembership { address member; } function isMember(RoleMembership storage roleMembership, address memberToCheck) internal view returns (bool) { return roleMembership.member == memberToCheck; } function resetMember(RoleMembership storage roleMembership, address newMember) internal { require(newMember != address(0x0), "Cannot set an exclusive role to 0x0"); roleMembership.member = newMember; } function getMember(RoleMembership storage roleMembership) internal view returns (address) { return roleMembership.member; } function init(RoleMembership storage roleMembership, address initialMember) internal { resetMember(roleMembership, initialMember); } } library Shared { struct RoleMembership { mapping(address => bool) members; } function isMember(RoleMembership storage roleMembership, address memberToCheck) internal view returns (bool) { return roleMembership.members[memberToCheck]; } function addMember(RoleMembership storage roleMembership, address memberToAdd) internal { require(memberToAdd != address(0x0), "Cannot add 0x0 to a shared role"); roleMembership.members[memberToAdd] = true; } function removeMember(RoleMembership storage roleMembership, address memberToRemove) internal { roleMembership.members[memberToRemove] = false; } function init(RoleMembership storage roleMembership, address[] memory initialMembers) internal { for (uint256 i = 0; i < initialMembers.length; i++) { addMember(roleMembership, initialMembers[i]); } } } /** * @title Base class to manage permissions for the derived class. */ abstract contract MultiRole { using Exclusive for Exclusive.RoleMembership; using Shared for Shared.RoleMembership; enum RoleType { Invalid, Exclusive, Shared } struct Role { uint256 managingRole; RoleType roleType; Exclusive.RoleMembership exclusiveRoleMembership; Shared.RoleMembership sharedRoleMembership; } mapping(uint256 => Role) private roles; event ResetExclusiveMember(uint256 indexed roleId, address indexed newMember, address indexed manager); event AddedSharedMember(uint256 indexed roleId, address indexed newMember, address indexed manager); event RemovedSharedMember(uint256 indexed roleId, address indexed oldMember, address indexed manager); /** * @notice Reverts unless the caller is a member of the specified roleId. */ modifier onlyRoleHolder(uint256 roleId) { require(holdsRole(roleId, msg.sender), "Sender does not hold required role"); _; } /** * @notice Reverts unless the caller is a member of the manager role for the specified roleId. */ modifier onlyRoleManager(uint256 roleId) { require(holdsRole(roles[roleId].managingRole, msg.sender), "Can only be called by a role manager"); _; } /** * @notice Reverts unless the roleId represents an initialized, exclusive roleId. */ modifier onlyExclusive(uint256 roleId) { require(roles[roleId].roleType == RoleType.Exclusive, "Must be called on an initialized Exclusive role"); _; } /** * @notice Reverts unless the roleId represents an initialized, shared roleId. */ modifier onlyShared(uint256 roleId) { require(roles[roleId].roleType == RoleType.Shared, "Must be called on an initialized Shared role"); _; } /** * @notice Whether `memberToCheck` is a member of roleId. * @dev Reverts if roleId does not correspond to an initialized role. * @param roleId the Role to check. * @param memberToCheck the address to check. * @return True if `memberToCheck` is a member of `roleId`. */ function holdsRole(uint256 roleId, address memberToCheck) public view returns (bool) { Role storage role = roles[roleId]; if (role.roleType == RoleType.Exclusive) { return role.exclusiveRoleMembership.isMember(memberToCheck); } else if (role.roleType == RoleType.Shared) { return role.sharedRoleMembership.isMember(memberToCheck); } revert("Invalid roleId"); } /** * @notice Changes the exclusive role holder of `roleId` to `newMember`. * @dev Reverts if the caller is not a member of the managing role for `roleId` or if `roleId` is not an * initialized, ExclusiveRole. * @param roleId the ExclusiveRole membership to modify. * @param newMember the new ExclusiveRole member. */ function resetMember(uint256 roleId, address newMember) public onlyExclusive(roleId) onlyRoleManager(roleId) { roles[roleId].exclusiveRoleMembership.resetMember(newMember); emit ResetExclusiveMember(roleId, newMember, msg.sender); } /** * @notice Gets the current holder of the exclusive role, `roleId`. * @dev Reverts if `roleId` does not represent an initialized, exclusive role. * @param roleId the ExclusiveRole membership to check. * @return the address of the current ExclusiveRole member. */ function getMember(uint256 roleId) public view onlyExclusive(roleId) returns (address) { return roles[roleId].exclusiveRoleMembership.getMember(); } /** * @notice Adds `newMember` to the shared role, `roleId`. * @dev Reverts if `roleId` does not represent an initialized, SharedRole or if the caller is not a member of the * managing role for `roleId`. * @param roleId the SharedRole membership to modify. * @param newMember the new SharedRole member. */ function addMember(uint256 roleId, address newMember) public onlyShared(roleId) onlyRoleManager(roleId) { roles[roleId].sharedRoleMembership.addMember(newMember); emit AddedSharedMember(roleId, newMember, msg.sender); } /** * @notice Removes `memberToRemove` from the shared role, `roleId`. * @dev Reverts if `roleId` does not represent an initialized, SharedRole or if the caller is not a member of the * managing role for `roleId`. * @param roleId the SharedRole membership to modify. * @param memberToRemove the current SharedRole member to remove. */ function removeMember(uint256 roleId, address memberToRemove) public onlyShared(roleId) onlyRoleManager(roleId) { roles[roleId].sharedRoleMembership.removeMember(memberToRemove); emit RemovedSharedMember(roleId, memberToRemove, msg.sender); } /** * @notice Removes caller from the role, `roleId`. * @dev Reverts if the caller is not a member of the role for `roleId` or if `roleId` is not an * initialized, SharedRole. * @param roleId the SharedRole membership to modify. */ function renounceMembership(uint256 roleId) public onlyShared(roleId) onlyRoleHolder(roleId) { roles[roleId].sharedRoleMembership.removeMember(msg.sender); emit RemovedSharedMember(roleId, msg.sender, msg.sender); } /** * @notice Reverts if `roleId` is not initialized. */ modifier onlyValidRole(uint256 roleId) { require(roles[roleId].roleType != RoleType.Invalid, "Attempted to use an invalid roleId"); _; } /** * @notice Reverts if `roleId` is initialized. */ modifier onlyInvalidRole(uint256 roleId) { require(roles[roleId].roleType == RoleType.Invalid, "Cannot use a pre-existing role"); _; } /** * @notice Internal method to initialize a shared role, `roleId`, which will be managed by `managingRoleId`. * `initialMembers` will be immediately added to the role. * @dev Should be called by derived contracts, usually at construction time. Will revert if the role is already * initialized. */ function _createSharedRole( uint256 roleId, uint256 managingRoleId, address[] memory initialMembers ) internal onlyInvalidRole(roleId) { Role storage role = roles[roleId]; role.roleType = RoleType.Shared; role.managingRole = managingRoleId; role.sharedRoleMembership.init(initialMembers); require( roles[managingRoleId].roleType != RoleType.Invalid, "Attempted to use an invalid role to manage a shared role" ); } /** * @notice Internal method to initialize an exclusive role, `roleId`, which will be managed by `managingRoleId`. * `initialMember` will be immediately added to the role. * @dev Should be called by derived contracts, usually at construction time. Will revert if the role is already * initialized. */ function _createExclusiveRole( uint256 roleId, uint256 managingRoleId, address initialMember ) internal onlyInvalidRole(roleId) { Role storage role = roles[roleId]; role.roleType = RoleType.Exclusive; role.managingRole = managingRoleId; role.exclusiveRoleMembership.init(initialMember); require( roles[managingRoleId].roleType != RoleType.Invalid, "Attempted to use an invalid role to manage an exclusive role" ); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "./Timer.sol"; /** * @title Base class that provides time overrides, but only if being run in test mode. */ abstract contract Testable { // If the contract is being run in production, then `timerAddress` will be the 0x0 address. // Note: this variable should be set on construction and never modified. address public timerAddress; /** * @notice Constructs the Testable contract. Called by child contracts. * @param _timerAddress Contract that stores the current time in a testing environment. * Must be set to 0x0 for production environments that use live time. */ constructor(address _timerAddress) { timerAddress = _timerAddress; } /** * @notice Reverts if not running in test mode. */ modifier onlyIfTest { require(timerAddress != address(0x0)); _; } /** * @notice Sets the current time. * @dev Will revert if not running in test mode. * @param time timestamp to set current Testable time to. */ function setCurrentTime(uint256 time) external onlyIfTest { Timer(timerAddress).setCurrentTime(time); } /** * @notice Gets the current time. Will return the last time set in `setCurrentTime` if running in test mode. * Otherwise, it will return the block timestamp. * @return uint for the current Testable timestamp. */ function getCurrentTime() public view virtual returns (uint256) { if (timerAddress != address(0x0)) { return Timer(timerAddress).getCurrentTime(); } else { return block.timestamp; // solhint-disable-line not-rely-on-time } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Universal store of current contract time for testing environments. */ contract Timer { uint256 private currentTime; constructor() { currentTime = block.timestamp; // solhint-disable-line not-rely-on-time } /** * @notice Sets the current time. * @dev Will revert if not running in test mode. * @param time timestamp to set `currentTime` to. */ function setCurrentTime(uint256 time) external { currentTime = time; } /** * @notice Gets the currentTime variable set in the Timer. * @return uint256 for the current Testable timestamp. */ function getCurrentTime() public view returns (uint256) { return currentTime; } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; interface AddressWhitelistInterface { function addToWhitelist(address newElement) external; function removeFromWhitelist(address newElement) external; function isOnWhitelist(address newElement) external view returns (bool); function getWhitelist() external view returns (address[] memory); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title ERC20 interface that includes burn and mint methods. */ abstract contract ExpandedIERC20 is IERC20 { /** * @notice Burns a specific amount of the caller's tokens. * @dev Only burns the caller's tokens, so it is safe to leave this method permissionless. */ function burn(uint256 value) external virtual; /** * @dev Burns `value` tokens owned by `recipient`. * @param recipient address to burn tokens from. * @param value amount of tokens to burn. */ function burnFrom(address recipient, uint256 value) external virtual returns (bool); /** * @notice Mints tokens and adds them to the balance of the `to` address. * @dev This method should be permissioned to only allow designated parties to mint tokens. */ function mint(address to, uint256 value) external virtual returns (bool); function addMinter(address account) external virtual; function addBurner(address account) external virtual; function resetOwner(address account) external virtual; }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title ERC20 interface that includes the decimals read only method. */ interface IERC20Standard is IERC20 { /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should be displayed to a user as `5,05` * (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. This is the value * {ERC20} uses, unless {_setupDecimals} is called. * * NOTE: This information is only used for _display_ purposes: it in no way affects any of the arithmetic * of the contract, including {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "../../common/implementation/ExpandedERC20.sol"; import "../../common/implementation/Lockable.sol"; /** * @title Burnable and mintable ERC20. * @dev The contract deployer will initially be the only minter, burner and owner capable of adding new roles. */ contract SyntheticToken is ExpandedERC20, Lockable { /** * @notice Constructs the SyntheticToken. * @param tokenName The name which describes the new token. * @param tokenSymbol The ticker abbreviation of the name. Ideally < 5 chars. * @param tokenDecimals The number of decimals to define token precision. */ constructor( string memory tokenName, string memory tokenSymbol, uint8 tokenDecimals ) ExpandedERC20(tokenName, tokenSymbol, tokenDecimals) nonReentrant() {} /** * @notice Add Minter role to account. * @dev The caller must have the Owner role. * @param account The address to which the Minter role is added. */ function addMinter(address account) external override nonReentrant() { addMember(uint256(Roles.Minter), account); } /** * @notice Remove Minter role from account. * @dev The caller must have the Owner role. * @param account The address from which the Minter role is removed. */ function removeMinter(address account) external nonReentrant() { removeMember(uint256(Roles.Minter), account); } /** * @notice Add Burner role to account. * @dev The caller must have the Owner role. * @param account The address to which the Burner role is added. */ function addBurner(address account) external override nonReentrant() { addMember(uint256(Roles.Burner), account); } /** * @notice Removes Burner role from account. * @dev The caller must have the Owner role. * @param account The address from which the Burner role is removed. */ function removeBurner(address account) external nonReentrant() { removeMember(uint256(Roles.Burner), account); } /** * @notice Reset Owner role to account. * @dev The caller must have the Owner role. * @param account The new holder of the Owner role. */ function resetOwner(address account) external override nonReentrant() { resetMember(uint256(Roles.Owner), account); } /** * @notice Checks if a given account holds the Minter role. * @param account The address which is checked for the Minter role. * @return bool True if the provided account is a Minter. */ function isMinter(address account) public view nonReentrantView() returns (bool) { return holdsRole(uint256(Roles.Minter), account); } /** * @notice Checks if a given account holds the Burner role. * @param account The address which is checked for the Burner role. * @return bool True if the provided account is a Burner. */ function isBurner(address account) public view nonReentrantView() returns (bool) { return holdsRole(uint256(Roles.Burner), account); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "./SyntheticToken.sol"; import "../../common/interfaces/ExpandedIERC20.sol"; import "../../common/implementation/Lockable.sol"; /** * @title Factory for creating new mintable and burnable tokens. */ contract TokenFactory is Lockable { /** * @notice Create a new token and return it to the caller. * @dev The caller will become the only minter and burner and the new owner capable of assigning the roles. * @param tokenName used to describe the new token. * @param tokenSymbol short ticker abbreviation of the name. Ideally < 5 chars. * @param tokenDecimals used to define the precision used in the token's numerical representation. * @return newToken an instance of the newly created token interface. */ function createToken( string calldata tokenName, string calldata tokenSymbol, uint8 tokenDecimals ) external nonReentrant() returns (ExpandedIERC20 newToken) { SyntheticToken mintableToken = new SyntheticToken(tokenName, tokenSymbol, tokenDecimals); mintableToken.resetOwner(msg.sender); newToken = ExpandedIERC20(address(mintableToken)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "../../../../common/implementation/FixedPoint.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; interface ExpiringContractInterface { function expirationTimestamp() external view returns (uint256); } abstract contract LongShortPairFinancialProductLibrary { function percentageLongCollateralAtExpiry(int256 expiryPrice) public view virtual returns (uint256); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../common/financial-product-libraries/long-short-pair-libraries/LongShortPairFinancialProductLibrary.sol"; import "../../common/implementation/AncillaryData.sol"; import "../../common/implementation/Testable.sol"; import "../../common/implementation/Lockable.sol"; import "../../common/implementation/FixedPoint.sol"; import "../../common/interfaces/ExpandedIERC20.sol"; import "../../oracle/interfaces/OracleInterface.sol"; import "../../common/interfaces/AddressWhitelistInterface.sol"; import "../../oracle/interfaces/FinderInterface.sol"; import "../../oracle/interfaces/OptimisticOracleInterface.sol"; import "../../oracle/interfaces/IdentifierWhitelistInterface.sol"; import "../../oracle/implementation/Constants.sol"; /** * @title Long Short Pair. * @notice Uses a combination of long and short tokens to tokenize the bounded price exposure to a given identifier. */ contract LongShortPair is Testable, Lockable { using FixedPoint for FixedPoint.Unsigned; using SafeERC20 for IERC20; /************************************* * LONG SHORT PAIR DATA STRUCTURES * *************************************/ // Define the contract's constructor parameters as a struct to enable more variables to be specified. struct ConstructorParams { string pairName; // Name of the long short pair contract. uint64 expirationTimestamp; // Unix timestamp of when the contract will expire. uint256 collateralPerPair; // How many units of collateral are required to mint one pair of synthetic tokens. bytes32 priceIdentifier; // Price identifier, registered in the DVM for the long short pair. bool enableEarlyExpiration; // Enables the LSP contract to be settled early. ExpandedIERC20 longToken; // Token used as long in the LSP. Mint and burn rights needed by this contract. ExpandedIERC20 shortToken; // Token used as short in the LSP. Mint and burn rights needed by this contract. IERC20 collateralToken; // Collateral token used to back LSP synthetics. LongShortPairFinancialProductLibrary financialProductLibrary; // Contract providing settlement payout logic. bytes customAncillaryData; // Custom ancillary data to be passed along with the price request to the OO. uint256 proposerReward; // Optimistic oracle reward amount, pulled from the caller of the expire function. uint256 optimisticOracleLivenessTime; // OO liveness time for price requests. uint256 optimisticOracleProposerBond; // OO proposer bond for price requests. FinderInterface finder; // DVM finder to find other UMA ecosystem contracts. address timerAddress; // Timer used to synchronize contract time in testing. Set to 0x000... in production. } bool public receivedSettlementPrice; bool public enableEarlyExpiration; // If set, the LSP contract can request to be settled early by calling the OO. uint64 public expirationTimestamp; uint64 public earlyExpirationTimestamp; // Set in the case the contract is expired early. string public pairName; uint256 public collateralPerPair; // Amount of collateral a pair of tokens is always redeemable for. // Number between 0 and 1e18 to allocate collateral between long & short tokens at redemption. 0 entitles each short // to collateralPerPair and each long to 0. 1e18 makes each long worth collateralPerPair and short 0. uint256 public expiryPercentLong; bytes32 public priceIdentifier; // Price returned from the Optimistic oracle at settlement time. int256 public expiryPrice; // External contract interfaces. IERC20 public collateralToken; ExpandedIERC20 public longToken; ExpandedIERC20 public shortToken; FinderInterface public finder; LongShortPairFinancialProductLibrary public financialProductLibrary; // Optimistic oracle customization parameters. bytes public customAncillaryData; uint256 public proposerReward; uint256 public optimisticOracleLivenessTime; uint256 public optimisticOracleProposerBond; /**************************************** * EVENTS * ****************************************/ event TokensCreated(address indexed sponsor, uint256 indexed collateralUsed, uint256 indexed tokensMinted); event TokensRedeemed(address indexed sponsor, uint256 indexed collateralReturned, uint256 indexed tokensRedeemed); event ContractExpired(address indexed caller); event EarlyExpirationRequested(address indexed caller, uint64 earlyExpirationTimeStamp); event PositionSettled(address indexed sponsor, uint256 collateralReturned, uint256 longTokens, uint256 shortTokens); /**************************************** * MODIFIERS * ****************************************/ modifier preExpiration() { require(getCurrentTime() < expirationTimestamp, "Only callable pre-expiry"); _; } modifier postExpiration() { require(getCurrentTime() >= expirationTimestamp, "Only callable post-expiry"); _; } modifier notEarlyExpired() { require(!isContractEarlyExpired(), "Contract already early expired"); _; } /** * @notice Construct the LongShortPair * @param params Constructor params used to initialize the LSP. Key-valued object with the following structure: * - `pairName`: Name of the long short pair contract. * - `expirationTimestamp`: Unix timestamp of when the contract will expire. * - `collateralPerPair`: How many units of collateral are required to mint one pair of synthetic tokens. * - `priceIdentifier`: Price identifier, registered in the DVM for the long short pair. * - `longToken`: Token used as long in the LSP. Mint and burn rights needed by this contract. * - `shortToken`: Token used as short in the LSP. Mint and burn rights needed by this contract. * - `collateralToken`: Collateral token used to back LSP synthetics. * - `financialProductLibrary`: Contract providing settlement payout logic. * - `customAncillaryData`: Custom ancillary data to be passed along with the price request to the OO. * - `proposerReward`: Preloaded reward to incentivize settlement price proposals. * - `optimisticOracleLivenessTime`: OO liveness time for price requests. * - `optimisticOracleProposerBond`: OO proposer bond for price requests. * - `finder`: DVM finder to find other UMA ecosystem contracts. * - `timerAddress`: Timer used to synchronize contract time in testing. Set to 0x000... in production. */ constructor(ConstructorParams memory params) Testable(params.timerAddress) { finder = params.finder; require(bytes(params.pairName).length > 0, "Pair name cant be empty"); require(params.expirationTimestamp > getCurrentTime(), "Expiration timestamp in past"); require(params.collateralPerPair > 0, "Collateral per pair cannot be 0"); require(_getIdentifierWhitelist().isIdentifierSupported(params.priceIdentifier), "Identifier not registered"); require(address(_getOptimisticOracle()) != address(0), "Invalid finder"); require(address(params.financialProductLibrary) != address(0), "Invalid FinancialProductLibrary"); require(_getCollateralWhitelist().isOnWhitelist(address(params.collateralToken)), "Collateral not whitelisted"); require(params.optimisticOracleLivenessTime > 0, "OO liveness cannot be 0"); require(params.optimisticOracleLivenessTime < 5200 weeks, "OO liveness too large"); pairName = params.pairName; expirationTimestamp = params.expirationTimestamp; collateralPerPair = params.collateralPerPair; priceIdentifier = params.priceIdentifier; enableEarlyExpiration = params.enableEarlyExpiration; longToken = params.longToken; shortToken = params.shortToken; collateralToken = params.collateralToken; financialProductLibrary = params.financialProductLibrary; OptimisticOracleInterface optimisticOracle = _getOptimisticOracle(); // Ancillary data + additional stamped information should be less than ancillary data limit. Consider early // expiration ancillary data, if enableEarlyExpiration is set. customAncillaryData = params.customAncillaryData; require( optimisticOracle .stampAncillaryData( (enableEarlyExpiration ? getEarlyExpirationAncillaryData() : customAncillaryData), address(this) ) .length <= optimisticOracle.ancillaryBytesLimit(), "Ancillary Data too long" ); proposerReward = params.proposerReward; optimisticOracleLivenessTime = params.optimisticOracleLivenessTime; optimisticOracleProposerBond = params.optimisticOracleProposerBond; } /**************************************** * POSITION FUNCTIONS * ****************************************/ /** * @notice Creates a pair of long and short tokens equal in number to tokensToCreate. Pulls the required collateral * amount into this contract, defined by the collateralPerPair value. * @dev The caller must approve this contract to transfer `tokensToCreate * collateralPerPair` amount of collateral. * @param tokensToCreate number of long and short synthetic tokens to create. * @return collateralUsed total collateral used to mint the synthetics. */ function create(uint256 tokensToCreate) public preExpiration() nonReentrant() returns (uint256 collateralUsed) { // Note the use of mulCeil to prevent small collateralPerPair causing rounding of collateralUsed to 0 enabling // callers to mint dust LSP tokens without paying any collateral. collateralUsed = FixedPoint.Unsigned(tokensToCreate).mulCeil(FixedPoint.Unsigned(collateralPerPair)).rawValue; collateralToken.safeTransferFrom(msg.sender, address(this), collateralUsed); require(longToken.mint(msg.sender, tokensToCreate)); require(shortToken.mint(msg.sender, tokensToCreate)); emit TokensCreated(msg.sender, collateralUsed, tokensToCreate); } /** * @notice Redeems a pair of long and short tokens equal in number to tokensToRedeem. Returns the commensurate * amount of collateral to the caller for the pair of tokens, defined by the collateralPerPair value. * @dev This contract must have the `Burner` role for the `longToken` and `shortToken` in order to call `burnFrom`. * @dev The caller does not need to approve this contract to transfer any amount of `tokensToRedeem` since long * and short tokens are burned, rather than transferred, from the caller. * @dev This method can be called either pre or post expiration. * @param tokensToRedeem number of long and short synthetic tokens to redeem. * @return collateralReturned total collateral returned in exchange for the pair of synthetics. */ function redeem(uint256 tokensToRedeem) public nonReentrant() returns (uint256 collateralReturned) { require(longToken.burnFrom(msg.sender, tokensToRedeem)); require(shortToken.burnFrom(msg.sender, tokensToRedeem)); collateralReturned = FixedPoint.Unsigned(tokensToRedeem).mul(FixedPoint.Unsigned(collateralPerPair)).rawValue; collateralToken.safeTransfer(msg.sender, collateralReturned); emit TokensRedeemed(msg.sender, collateralReturned, tokensToRedeem); } /** * @notice Settle long and/or short tokens in for collateral at a rate informed by the contract settlement. * @dev Uses financialProductLibrary to compute the redemption rate between long and short tokens. * @dev This contract must have the `Burner` role for the `longToken` and `shortToken` in order to call `burnFrom`. * @dev The caller does not need to approve this contract to transfer any amount of `tokensToRedeem` since long * and short tokens are burned, rather than transferred, from the caller. * @dev This function can be called before or after expiration to facilitate early expiration. If a price has * not yet been resolved for either normal or early expiration yet then it will revert. * @param longTokensToRedeem number of long tokens to settle. * @param shortTokensToRedeem number of short tokens to settle. * @return collateralReturned total collateral returned in exchange for the pair of synthetics. */ function settle(uint256 longTokensToRedeem, uint256 shortTokensToRedeem) public nonReentrant() returns (uint256 collateralReturned) { // Either early expiration is enabled and it's before the expiration time or it's after the expiration time. require( (enableEarlyExpiration && getCurrentTime() < expirationTimestamp) || getCurrentTime() >= expirationTimestamp, "Cannot settle" ); // Get the settlement price and store it. Also sets expiryPercentLong to inform settlement. Reverts if either: // a) the price request has not resolved (either a normal expiration call or early expiration call) or b) If the // the contract was attempted to be settled early but the price returned is the ignore oracle price. // Note that we use the bool receivedSettlementPrice over checking for price != 0 as 0 is a valid price. if (!receivedSettlementPrice) getExpirationPrice(); require(longToken.burnFrom(msg.sender, longTokensToRedeem)); require(shortToken.burnFrom(msg.sender, shortTokensToRedeem)); // expiryPercentLong is a number between 0 and 1e18. 0 means all collateral goes to short tokens and 1e18 means // all collateral goes to the long token. Total collateral returned is the sum of payouts. uint256 longCollateralRedeemed = FixedPoint .Unsigned(longTokensToRedeem) .mul(FixedPoint.Unsigned(collateralPerPair)) .mul(FixedPoint.Unsigned(expiryPercentLong)) .rawValue; uint256 shortCollateralRedeemed = FixedPoint .Unsigned(shortTokensToRedeem) .mul(FixedPoint.Unsigned(collateralPerPair)) .mul(FixedPoint.fromUnscaledUint(1).sub(FixedPoint.Unsigned(expiryPercentLong))) .rawValue; collateralReturned = longCollateralRedeemed + shortCollateralRedeemed; collateralToken.safeTransfer(msg.sender, collateralReturned); emit PositionSettled(msg.sender, collateralReturned, longTokensToRedeem, shortTokensToRedeem); } /**************************************** * GLOBAL STATE FUNCTIONS * ****************************************/ /** * @notice Enables the LSP to request early expiration. This initiates a price request to the optimistic oracle at * the provided timestamp with a modified version of the ancillary data that includes the key "earlyExpiration:1" * which signals to the OO that this is an early expiration request, rather than standard settlement. * @dev The caller must approve this contract to transfer `proposerReward` amount of collateral. * @dev Will revert if: a) the contract is already early expired, b) it is after the expiration timestamp, c) * early expiration is disabled for this contract, d) the proposed expiration timestamp is in the future. * e) an early expiration attempt has already been made (in pending state). * @param _earlyExpirationTimestamp timestamp at which the early expiration is proposed. */ function requestEarlyExpiration(uint64 _earlyExpirationTimestamp) public nonReentrant() notEarlyExpired() preExpiration() { require(enableEarlyExpiration, "Early expiration disabled"); require(_earlyExpirationTimestamp <= getCurrentTime(), "Only propose expire in the past"); require(_earlyExpirationTimestamp > 0, "Early expiration can't be 0"); earlyExpirationTimestamp = _earlyExpirationTimestamp; _requestOraclePrice(earlyExpirationTimestamp, getEarlyExpirationAncillaryData()); emit EarlyExpirationRequested(msg.sender, _earlyExpirationTimestamp); } /** * @notice Expire the LSP contract. Makes a request to the optimistic oracle to inform the settlement price. * @dev The caller must approve this contract to transfer `proposerReward` amount of collateral. * @dev Will revert if: a) the contract is already early expired, b) it is before the expiration timestamp or c) * an expire call has already been made. */ function expire() public nonReentrant() notEarlyExpired() postExpiration() { _requestOraclePrice(expirationTimestamp, customAncillaryData); emit ContractExpired(msg.sender); } /*********************************** * GLOBAL VIEW FUNCTIONS * ***********************************/ /** * @notice Returns the number of long and short tokens a sponsor wallet holds. * @param sponsor address of the sponsor to query. * @return longTokens the number of long tokens held by the sponsor. * @return shortTokens the number of short tokens held by the sponsor. */ function getPositionTokens(address sponsor) public view nonReentrantView() returns (uint256 longTokens, uint256 shortTokens) { return (longToken.balanceOf(sponsor), shortToken.balanceOf(sponsor)); } /** * @notice Generates a modified ancillary data that indicates the contract is being expired early. */ function getEarlyExpirationAncillaryData() public view returns (bytes memory) { return AncillaryData.appendKeyValueUint(customAncillaryData, "earlyExpiration", 1); } /** * @notice Defines a special number that, if returned during an attempted early expiration, will cause the contract * to do nothing and not expire. This enables the OO (and DVM voters in the case of a dispute) to choose to keep * the contract running, thereby denying the early settlement request. */ function ignoreEarlyExpirationPrice() public pure returns (int256) { return type(int256).min; } /** * @notice If the earlyExpirationTimestamp is != 0 then a previous early expiration OO request might still be in the * pending state. Check if the OO contains the ignore early price. If it does not contain this then the contract * was early expired correctly. Note that _getOraclePrice call will revert if the price request is still pending, * thereby reverting all upstream calls pre-settlement of the early expiration price request. */ function isContractEarlyExpired() public returns (bool) { return (earlyExpirationTimestamp != 0 && _getOraclePrice(earlyExpirationTimestamp, getEarlyExpirationAncillaryData()) != ignoreEarlyExpirationPrice()); } /**************************************** * INTERNAL FUNCTIONS * ****************************************/ // Return the oracle price for a given request timestamp and ancillary data combo. function _getOraclePrice(uint64 requestTimestamp, bytes memory requestAncillaryData) internal returns (int256) { return _getOptimisticOracle().settleAndGetPrice(priceIdentifier, requestTimestamp, requestAncillaryData); } // Request a price in the optimistic oracle for a given request timestamp and ancillary data combo. Set the bonds // accordingly to the deployer's parameters. Will revert if re-requesting for a previously requested combo. function _requestOraclePrice(uint64 requestTimestamp, bytes memory requestAncillaryData) internal { OptimisticOracleInterface optimisticOracle = _getOptimisticOracle(); // If the proposer reward was set then pull it from the caller of the function. if (proposerReward > 0) { collateralToken.safeTransferFrom(msg.sender, address(this), proposerReward); collateralToken.safeApprove(address(optimisticOracle), proposerReward); } optimisticOracle.requestPrice( priceIdentifier, uint256(requestTimestamp), requestAncillaryData, collateralToken, proposerReward ); // Set the Optimistic oracle liveness for the price request. optimisticOracle.setCustomLiveness( priceIdentifier, uint256(requestTimestamp), requestAncillaryData, optimisticOracleLivenessTime ); // Set the Optimistic oracle proposer bond for the price request. optimisticOracle.setBond( priceIdentifier, uint256(requestTimestamp), requestAncillaryData, optimisticOracleProposerBond ); } // Fetch the optimistic oracle expiration price. If the oracle has the price for the provided expiration timestamp // and customData combo then return this. Else, try fetch the price on the early expiration ancillary data. If // there is no price for either, revert. If the early expiration price is the ignore price will also revert. function getExpirationPrice() internal { if (_getOptimisticOracle().hasPrice(address(this), priceIdentifier, expirationTimestamp, customAncillaryData)) expiryPrice = _getOraclePrice(expirationTimestamp, customAncillaryData); else { expiryPrice = _getOraclePrice(earlyExpirationTimestamp, getEarlyExpirationAncillaryData()); require(expiryPrice != ignoreEarlyExpirationPrice(), "Oracle prevents early expiration"); } // Finally, compute the value of expiryPercentLong based on the expiryPrice. Cap the return value at 1e18 as // this should, by definition, between 0 and 1e18. expiryPercentLong = Math.min( financialProductLibrary.percentageLongCollateralAtExpiry(expiryPrice), FixedPoint.fromUnscaledUint(1).rawValue ); receivedSettlementPrice = true; } function _getIdentifierWhitelist() internal view returns (IdentifierWhitelistInterface) { return IdentifierWhitelistInterface(finder.getImplementationAddress(OracleInterfaces.IdentifierWhitelist)); } function _getCollateralWhitelist() internal view returns (AddressWhitelistInterface) { return AddressWhitelistInterface(finder.getImplementationAddress(OracleInterfaces.CollateralWhitelist)); } function _getOptimisticOracle() internal view returns (OptimisticOracleInterface) { return OptimisticOracleInterface(finder.getImplementationAddress(OracleInterfaces.OptimisticOracle)); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "../../common/interfaces/ExpandedIERC20.sol"; import "../../common/interfaces/IERC20Standard.sol"; import "../../oracle/interfaces/FinderInterface.sol"; import "../../common/implementation/Testable.sol"; import "../../common/implementation/Lockable.sol"; import "../common/TokenFactory.sol"; import "./LongShortPair.sol"; import "../common/financial-product-libraries/long-short-pair-libraries/LongShortPairFinancialProductLibrary.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; /** * @title Long Short Pair Contract Creator. * @notice Factory contract to create new instances of long short pair contracts. * Responsible for constraining the parameters used to construct a new LSP. These constraints can evolve over time and * are initially constrained to conservative values in this first iteration. */ contract LongShortPairCreator is Testable, Lockable { using FixedPoint for FixedPoint.Unsigned; using SafeERC20 for IERC20Standard; struct CreatorParams { string pairName; uint64 expirationTimestamp; uint256 collateralPerPair; bytes32 priceIdentifier; bool enableEarlyExpiration; string longSynthName; string longSynthSymbol; string shortSynthName; string shortSynthSymbol; IERC20Standard collateralToken; LongShortPairFinancialProductLibrary financialProductLibrary; bytes customAncillaryData; uint256 proposerReward; uint256 optimisticOracleLivenessTime; uint256 optimisticOracleProposerBond; } // Address of TokenFactory used to create a new synthetic token. TokenFactory public tokenFactory; FinderInterface public finder; event CreatedLongShortPair( address indexed longShortPair, address indexed deployerAddress, address longToken, address shortToken ); /** * @notice Constructs the LongShortPairCreator contract. * @param _finder UMA protocol Finder used to discover other protocol contracts. * @param _tokenFactory ERC20 token factory used to deploy synthetic token instances. * @param _timer Contract that stores the current time in a testing environment. */ constructor( FinderInterface _finder, TokenFactory _tokenFactory, address _timer ) Testable(_timer) nonReentrant() { tokenFactory = _tokenFactory; finder = _finder; } /** * @notice Creates a longShortPair contract and associated long and short tokens. * @param params Constructor params used to initialize the LSP. Key-valued object with the following structure: * - `pairName`: Name of the long short pair contract. * - `expirationTimestamp`: Unix timestamp of when the contract will expire. * - `collateralPerPair`: How many units of collateral are required to mint one pair of synthetic tokens. * - `priceIdentifier`: Registered in the DVM for the synthetic. * - `enableEarlyExpiration`: Enables the LSP contract to be settled early. * - `longSynthName`: Name of the long synthetic tokens to be created. * - `longSynthSymbol`: Symbol of the long synthetic tokens to be created. * - `shortSynthName`: Name of the short synthetic tokens to be created. * - `shortSynthSymbol`: Symbol of the short synthetic tokens to be created. * - `collateralToken`: ERC20 token used as collateral in the LSP. * - `financialProductLibrary`: Contract providing settlement payout logic. * - `customAncillaryData`: Custom ancillary data to be passed along with the price request. If not needed, this * should be left as a 0-length bytes array. * - `proposerReward`: Optimistic oracle reward amount, pulled from the caller of the expire function. * - `optimisticOracleLivenessTime`: Optimistic oracle liveness time for price requests. * - `optimisticOracleProposerBond`: Optimistic oracle proposer bond for price requests. * @return lspAddress the deployed address of the new long short pair contract. * @notice Created LSP is not registered within the registry as the LSP uses the Optimistic Oracle for settlement. * @notice The LSP constructor does a number of validations on input params. These are not repeated here. */ function createLongShortPair(CreatorParams memory params) public nonReentrant() returns (address) { // Create a new synthetic token using the params. require(bytes(params.longSynthName).length != 0, "Missing long synthetic name"); require(bytes(params.shortSynthName).length != 0, "Missing short synthetic name"); require(bytes(params.longSynthSymbol).length != 0, "Missing long synthetic symbol"); require(bytes(params.shortSynthSymbol).length != 0, "Missing short synthetic symbol"); // If the collateral token does not have a `decimals()` method, then a default precision of 18 will be // applied to the newly created synthetic token. uint8 collateralDecimals = _getSyntheticDecimals(params.collateralToken); ExpandedIERC20 longToken = tokenFactory.createToken(params.longSynthName, params.longSynthSymbol, collateralDecimals); ExpandedIERC20 shortToken = tokenFactory.createToken(params.shortSynthName, params.shortSynthSymbol, collateralDecimals); // Deploy the LSP contract. LongShortPair lsp = new LongShortPair(_convertParams(params, longToken, shortToken)); address lspAddress = address(lsp); // Give permissions to new lsp contract and then hand over ownership. longToken.addMinter(lspAddress); longToken.addBurner(lspAddress); longToken.resetOwner(lspAddress); shortToken.addMinter(lspAddress); shortToken.addBurner(lspAddress); shortToken.resetOwner(lspAddress); emit CreatedLongShortPair(lspAddress, msg.sender, address(longToken), address(shortToken)); return lspAddress; } // Converts createLongShortPair creator params to LongShortPair constructor params. function _convertParams( CreatorParams memory creatorParams, ExpandedIERC20 longToken, ExpandedIERC20 shortToken ) private view returns (LongShortPair.ConstructorParams memory constructorParams) { // Input from function call. constructorParams.pairName = creatorParams.pairName; constructorParams.expirationTimestamp = creatorParams.expirationTimestamp; constructorParams.collateralPerPair = creatorParams.collateralPerPair; constructorParams.priceIdentifier = creatorParams.priceIdentifier; constructorParams.enableEarlyExpiration = creatorParams.enableEarlyExpiration; constructorParams.collateralToken = creatorParams.collateralToken; constructorParams.financialProductLibrary = creatorParams.financialProductLibrary; constructorParams.customAncillaryData = creatorParams.customAncillaryData; constructorParams.proposerReward = creatorParams.proposerReward; constructorParams.optimisticOracleLivenessTime = creatorParams.optimisticOracleLivenessTime; constructorParams.optimisticOracleProposerBond = creatorParams.optimisticOracleProposerBond; // Constructed long & short synthetic tokens. constructorParams.longToken = longToken; constructorParams.shortToken = shortToken; // Finder and timer. Should be the same as that used in this factory contract. constructorParams.finder = finder; constructorParams.timerAddress = timerAddress; } // IERC20Standard.decimals() will revert if the collateral contract has not implemented the decimals() method, // which is possible since the method is only an OPTIONAL method in the ERC20 standard: // https://eips.ethereum.org/EIPS/eip-20#methods. function _getSyntheticDecimals(IERC20Standard _collateralToken) private view returns (uint8 decimals) { try _collateralToken.decimals() returns (uint8 _decimals) { return _decimals; } catch { return 18; } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Stores common interface names used throughout the DVM by registration in the Finder. */ library OracleInterfaces { bytes32 public constant Oracle = "Oracle"; bytes32 public constant IdentifierWhitelist = "IdentifierWhitelist"; bytes32 public constant Store = "Store"; bytes32 public constant FinancialContractsAdmin = "FinancialContractsAdmin"; bytes32 public constant Registry = "Registry"; bytes32 public constant CollateralWhitelist = "CollateralWhitelist"; bytes32 public constant OptimisticOracle = "OptimisticOracle"; bytes32 public constant Bridge = "Bridge"; bytes32 public constant GenericHandler = "GenericHandler"; bytes32 public constant SkinnyOptimisticOracle = "SkinnyOptimisticOracle"; bytes32 public constant ChildMessenger = "ChildMessenger"; } /** * @title Commonly re-used values for contracts associated with the OptimisticOracle. */ library OptimisticOracleConstraints { // Any price request submitted to the OptimisticOracle must contain ancillary data no larger than this value. // This value must be <= the Voting contract's `ancillaryBytesLimit` constant value otherwise it is possible // that a price can be requested to the OptimisticOracle successfully, but cannot be resolved by the DVM which // refuses to accept a price request made with ancillary data length over a certain size. uint256 public constant ancillaryBytesLimit = 8192; }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Provides addresses of the live contracts implementing certain interfaces. * @dev Examples are the Oracle or Store interfaces. */ interface FinderInterface { /** * @notice Updates the address of the contract that implements `interfaceName`. * @param interfaceName bytes32 encoding of the interface name that is either changed or registered. * @param implementationAddress address of the deployed contract that implements the interface. */ function changeImplementationAddress(bytes32 interfaceName, address implementationAddress) external; /** * @notice Gets the address of the contract that implements the given `interfaceName`. * @param interfaceName queried interface. * @return implementationAddress address of the deployed contract that implements the interface. */ function getImplementationAddress(bytes32 interfaceName) external view returns (address); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Interface for whitelists of supported identifiers that the oracle can provide prices for. */ interface IdentifierWhitelistInterface { /** * @notice Adds the provided identifier as a supported identifier. * @dev Price requests using this identifier will succeed after this call. * @param identifier bytes32 encoding of the string identifier. Eg: BTC/USD. */ function addSupportedIdentifier(bytes32 identifier) external; /** * @notice Removes the identifier from the whitelist. * @dev Price requests using this identifier will no longer succeed after this call. * @param identifier bytes32 encoding of the string identifier. Eg: BTC/USD. */ function removeSupportedIdentifier(bytes32 identifier) external; /** * @notice Checks whether an identifier is on the whitelist. * @param identifier bytes32 encoding of the string identifier. Eg: BTC/USD. * @return bool if the identifier is supported (or not). */ function isIdentifierSupported(bytes32 identifier) external view returns (bool); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @title Financial contract facing Oracle interface. * @dev Interface used by financial contracts to interact with the Oracle. Voters will use a different interface. */ abstract contract OptimisticOracleInterface { // Struct representing the state of a price request. enum State { Invalid, // Never requested. Requested, // Requested, no other actions taken. Proposed, // Proposed, but not expired or disputed yet. Expired, // Proposed, not disputed, past liveness. Disputed, // Disputed, but no DVM price returned yet. Resolved, // Disputed and DVM price is available. Settled // Final price has been set in the contract (can get here from Expired or Resolved). } // Struct representing a price request. struct Request { address proposer; // Address of the proposer. address disputer; // Address of the disputer. IERC20 currency; // ERC20 token used to pay rewards and fees. bool settled; // True if the request is settled. bool refundOnDispute; // True if the requester should be refunded their reward on dispute. int256 proposedPrice; // Price that the proposer submitted. int256 resolvedPrice; // Price resolved once the request is settled. uint256 expirationTime; // Time at which the request auto-settles without a dispute. uint256 reward; // Amount of the currency to pay to the proposer on settlement. uint256 finalFee; // Final fee to pay to the Store upon request to the DVM. uint256 bond; // Bond that the proposer and disputer must pay on top of the final fee. uint256 customLiveness; // Custom liveness value set by the requester. } // This value must be <= the Voting contract's `ancillaryBytesLimit` value otherwise it is possible // that a price can be requested to this contract successfully, but cannot be disputed because the DVM refuses // to accept a price request made with ancillary data length over a certain size. uint256 public constant ancillaryBytesLimit = 8192; /** * @notice Requests a new price. * @param identifier price identifier being requested. * @param timestamp timestamp of the price being requested. * @param ancillaryData ancillary data representing additional args being passed with the price request. * @param currency ERC20 token used for payment of rewards and fees. Must be approved for use with the DVM. * @param reward reward offered to a successful proposer. Will be pulled from the caller. Note: this can be 0, * which could make sense if the contract requests and proposes the value in the same call or * provides its own reward system. * @return totalBond default bond (final fee) + final fee that the proposer and disputer will be required to pay. * This can be changed with a subsequent call to setBond(). */ function requestPrice( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, IERC20 currency, uint256 reward ) external virtual returns (uint256 totalBond); /** * @notice Set the proposal bond associated with a price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param bond custom bond amount to set. * @return totalBond new bond + final fee that the proposer and disputer will be required to pay. This can be * changed again with a subsequent call to setBond(). */ function setBond( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, uint256 bond ) external virtual returns (uint256 totalBond); /** * @notice Sets the request to refund the reward if the proposal is disputed. This can help to "hedge" the caller * in the event of a dispute-caused delay. Note: in the event of a dispute, the winner still receives the other's * bond, so there is still profit to be made even if the reward is refunded. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. */ function setRefundOnDispute( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual; /** * @notice Sets a custom liveness value for the request. Liveness is the amount of time a proposal must wait before * being auto-resolved. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param customLiveness new custom liveness. */ function setCustomLiveness( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, uint256 customLiveness ) external virtual; /** * @notice Proposes a price value on another address' behalf. Note: this address will receive any rewards that come * from this proposal. However, any bonds are pulled from the caller. * @param proposer address to set as the proposer. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param proposedPrice price being proposed. * @return totalBond the amount that's pulled from the caller's wallet as a bond. The bond will be returned to * the proposer once settled if the proposal is correct. */ function proposePriceFor( address proposer, address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, int256 proposedPrice ) public virtual returns (uint256 totalBond); /** * @notice Proposes a price value for an existing price request. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @param proposedPrice price being proposed. * @return totalBond the amount that's pulled from the proposer's wallet as a bond. The bond will be returned to * the proposer once settled if the proposal is correct. */ function proposePrice( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData, int256 proposedPrice ) external virtual returns (uint256 totalBond); /** * @notice Disputes a price request with an active proposal on another address' behalf. Note: this address will * receive any rewards that come from this dispute. However, any bonds are pulled from the caller. * @param disputer address to set as the disputer. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return totalBond the amount that's pulled from the caller's wallet as a bond. The bond will be returned to * the disputer once settled if the dispute was value (the proposal was incorrect). */ function disputePriceFor( address disputer, address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public virtual returns (uint256 totalBond); /** * @notice Disputes a price value for an existing price request with an active proposal. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return totalBond the amount that's pulled from the disputer's wallet as a bond. The bond will be returned to * the disputer once settled if the dispute was valid (the proposal was incorrect). */ function disputePrice( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual returns (uint256 totalBond); /** * @notice Retrieves a price that was previously requested by a caller. Reverts if the request is not settled * or settleable. Note: this method is not view so that this call may actually settle the price request if it * hasn't been settled. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return resolved price. */ function settleAndGetPrice( bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual returns (int256); /** * @notice Attempts to settle an outstanding price request. Will revert if it isn't settleable. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return payout the amount that the "winner" (proposer or disputer) receives on settlement. This amount includes * the returned bonds as well as additional rewards. */ function settle( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) external virtual returns (uint256 payout); /** * @notice Gets the current data structure containing all information about a price request. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return the Request data structure. */ function getRequest( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public view virtual returns (Request memory); /** * @notice Returns the state of a price request. * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return the State enum value. */ function getState( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public view virtual returns (State); /** * @notice Checks if a given request has resolved or been settled (i.e the optimistic oracle has a price). * @param requester sender of the initial price request. * @param identifier price identifier to identify the existing request. * @param timestamp timestamp to identify the existing request. * @param ancillaryData ancillary data of the price being requested. * @return true if price has resolved or settled, false otherwise. */ function hasPrice( address requester, bytes32 identifier, uint256 timestamp, bytes memory ancillaryData ) public view virtual returns (bool); function stampAncillaryData(bytes memory ancillaryData, address requester) public view virtual returns (bytes memory); }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity ^0.8.0; /** * @title Financial contract facing Oracle interface. * @dev Interface used by financial contracts to interact with the Oracle. Voters will use a different interface. */ abstract contract OracleInterface { /** * @notice Enqueues a request (if a request isn't already present) for the given `identifier`, `time` pair. * @dev Time must be in the past and the identifier must be supported. * @param identifier uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested. * @param time unix timestamp for the price request. */ function requestPrice(bytes32 identifier, uint256 time) public virtual; /** * @notice Whether the price for `identifier` and `time` is available. * @dev Time must be in the past and the identifier must be supported. * @param identifier uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested. * @param time unix timestamp for the price request. * @return bool if the DVM has resolved to a price for the given identifier and timestamp. */ function hasPrice(bytes32 identifier, uint256 time) public view virtual returns (bool); /** * @notice Gets the price for `identifier` and `time` if it has already been requested and resolved. * @dev If the price is not available, the method reverts. * @param identifier uniquely identifies the price requested. eg BTC/USD (encoded as bytes32) could be requested. * @param time unix timestamp for the price request. * @return int256 representing the resolved price for the given identifier and timestamp. */ function getPrice(bytes32 identifier, uint256 time) public view virtual returns (int256); }
{ "evmVersion": "london", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 1000000 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } } }
[{"inputs":[{"internalType":"contract FinderInterface","name":"_finder","type":"address"},{"internalType":"contract TokenFactory","name":"_tokenFactory","type":"address"},{"internalType":"address","name":"_timer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"longShortPair","type":"address"},{"indexed":true,"internalType":"address","name":"deployerAddress","type":"address"},{"indexed":false,"internalType":"address","name":"longToken","type":"address"},{"indexed":false,"internalType":"address","name":"shortToken","type":"address"}],"name":"CreatedLongShortPair","type":"event"},{"inputs":[{"components":[{"internalType":"string","name":"pairName","type":"string"},{"internalType":"uint64","name":"expirationTimestamp","type":"uint64"},{"internalType":"uint256","name":"collateralPerPair","type":"uint256"},{"internalType":"bytes32","name":"priceIdentifier","type":"bytes32"},{"internalType":"bool","name":"enableEarlyExpiration","type":"bool"},{"internalType":"string","name":"longSynthName","type":"string"},{"internalType":"string","name":"longSynthSymbol","type":"string"},{"internalType":"string","name":"shortSynthName","type":"string"},{"internalType":"string","name":"shortSynthSymbol","type":"string"},{"internalType":"contract IERC20Standard","name":"collateralToken","type":"address"},{"internalType":"contract LongShortPairFinancialProductLibrary","name":"financialProductLibrary","type":"address"},{"internalType":"bytes","name":"customAncillaryData","type":"bytes"},{"internalType":"uint256","name":"proposerReward","type":"uint256"},{"internalType":"uint256","name":"optimisticOracleLivenessTime","type":"uint256"},{"internalType":"uint256","name":"optimisticOracleProposerBond","type":"uint256"}],"internalType":"struct LongShortPairCreator.CreatorParams","name":"params","type":"tuple"}],"name":"createLongShortPair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"finder","outputs":[{"internalType":"contract FinderInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"time","type":"uint256"}],"name":"setCurrentTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"timerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenFactory","outputs":[{"internalType":"contract TokenFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b50604051620056e3380380620056e383398101604081905262000034916200013d565b600080546001600160a81b0319166001600160a01b03831617600160a01b1790556200005f620000c4565b620000726000805460ff60a01b19169055565b600180546001600160a01b038085166001600160a01b0319928316179092556002805492861692909116919091179055620000bb6000805460ff60a01b1916600160a01b179055565b50505062000191565b600054600160a01b900460ff16620001225760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640160405180910390fd5b565b6001600160a01b03811681146200013a57600080fd5b50565b6000806000606084860312156200015357600080fd5b8351620001608162000124565b6020850151909350620001738162000124565b6040850151909250620001868162000124565b809150509250925092565b61554280620001a16000396000f3fe60806040523480156200001157600080fd5b50600436106200007b5760003560e01c806329cb924d116200005657806329cb924d14620000fb578063b9a3c84c1462000114578063e77772fe146200013557600080fd5b8063124b4e3514620000805780631c39c38d14620000c157806322f8e56614620000e2575b600080fd5b620000976200009136600462000e4b565b62000156565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b600054620000979073ffffffffffffffffffffffffffffffffffffffff1681565b620000f9620000f33660046200100f565b62000a24565b005b6200010562000ad0565b604051908152602001620000b8565b600254620000979073ffffffffffffffffffffffffffffffffffffffff1681565b600154620000979073ffffffffffffffffffffffffffffffffffffffff1681565b60006200016262000b9c565b62000190600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff169055565b60a08201515162000202576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f4d697373696e67206c6f6e672073796e746865746963206e616d65000000000060448201526064015b60405180910390fd5b60e08201515162000270576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f4d697373696e672073686f72742073796e746865746963206e616d65000000006044820152606401620001f9565b60c082015151620002de576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4d697373696e67206c6f6e672073796e7468657469632073796d626f6c0000006044820152606401620001f9565b610100820151516200034d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f4d697373696e672073686f72742073796e7468657469632073796d626f6c00006044820152606401620001f9565b60006200035f83610120015162000c24565b60015460a085015160c08601516040517fe8a0aed300000000000000000000000000000000000000000000000000000000815293945060009373ffffffffffffffffffffffffffffffffffffffff9093169263e8a0aed392620003c9929091879060040162001097565b602060405180830381600087803b158015620003e457600080fd5b505af1158015620003f9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200041f9190620010d4565b60015460e08601516101008701516040517fe8a0aed300000000000000000000000000000000000000000000000000000000815293945060009373ffffffffffffffffffffffffffffffffffffffff9093169263e8a0aed3926200048a929091889060040162001097565b602060405180830381600087803b158015620004a557600080fd5b505af1158015620004ba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620004e09190620010d4565b905060006200062f868484604080516101e08101825260608082526000602083018190529282018390528082018390526080820183905260a0820183905260c0820183905260e0820183905261010082018390526101208201526101408101829052610160810182905261018081018290526101a081018290526101c08101919091528351815260208085015167ffffffffffffffff169082015260408085015190820152606080850151908201526080808501511515908201526101208085015173ffffffffffffffffffffffffffffffffffffffff90811660e0840152610140808701518216610100850152610160808801519385019390935261018080880151918501919091526101a080880151938501939093526101c0968701519084015293841660a083015291831660c08201526002548316918101919091526000549091169181019190915290565b6040516200063d9062000cd1565b620006499190620010fb565b604051809103906000f08015801562000666573d6000803e3d6000fd5b506040517f983b2d5600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8083166004830152919250829185169063983b2d5690602401600060405180830381600087803b158015620006d657600080fd5b505af1158015620006eb573d6000803e3d6000fd5b50506040517ff44637ba00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301528716925063f44637ba9150602401600060405180830381600087803b1580156200075957600080fd5b505af11580156200076e573d6000803e3d6000fd5b50506040517f73cc802a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152871692506373cc802a9150602401600060405180830381600087803b158015620007dc57600080fd5b505af1158015620007f1573d6000803e3d6000fd5b50506040517f983b2d5600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301528616925063983b2d569150602401600060405180830381600087803b1580156200085f57600080fd5b505af115801562000874573d6000803e3d6000fd5b50506040517ff44637ba00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301528616925063f44637ba9150602401600060405180830381600087803b158015620008e257600080fd5b505af1158015620008f7573d6000803e3d6000fd5b50506040517f73cc802a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152861692506373cc802a9150602401600060405180830381600087803b1580156200096557600080fd5b505af11580156200097a573d6000803e3d6000fd5b50506040805173ffffffffffffffffffffffffffffffffffffffff88811682528781166020830152339450851692507fd007d1b8d04c15a0cadef913ed5a5c4b381d3dcd2927c2de9a6dcc1ddab2d2f8910160405180910390a394505050505062000a1f600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055565b919050565b60005473ffffffffffffffffffffffffffffffffffffffff1662000a4757600080fd5b6000546040517f22f8e5660000000000000000000000000000000000000000000000000000000081526004810183905273ffffffffffffffffffffffffffffffffffffffff909116906322f8e56690602401600060405180830381600087803b15801562000ab457600080fd5b505af115801562000ac9573d6000803e3d6000fd5b5050505050565b6000805473ffffffffffffffffffffffffffffffffffffffff161562000b975760008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166329cb924d6040518163ffffffff1660e01b815260040160206040518083038186803b15801562000b5757600080fd5b505afa15801562000b6c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000b929190620012b6565b905090565b504290565b60005474010000000000000000000000000000000000000000900460ff1662000c22576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401620001f9565b565b60008173ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801562000c6d57600080fd5b505afa92505050801562000cbe575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820190925262000cbb91810190620012d0565b60015b62000ccb57506012919050565b92915050565b61421780620012f683390190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040516101e0810167ffffffffffffffff8111828210171562000d355762000d3562000cdf565b60405290565b600082601f83011262000d4d57600080fd5b813567ffffffffffffffff8082111562000d6b5762000d6b62000cdf565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f0116810190828211818310171562000db45762000db462000cdf565b8160405283815286602085880101111562000dce57600080fd5b836020870160208301376000602085830101528094505050505092915050565b803567ffffffffffffffff8116811462000a1f57600080fd5b8035801515811462000a1f57600080fd5b73ffffffffffffffffffffffffffffffffffffffff8116811462000e3b57600080fd5b50565b803562000a1f8162000e18565b60006020828403121562000e5e57600080fd5b813567ffffffffffffffff8082111562000e7757600080fd5b908301906101e0828603121562000e8d57600080fd5b62000e9762000d0e565b82358281111562000ea757600080fd5b62000eb58782860162000d3b565b82525062000ec66020840162000dee565b6020820152604083013560408201526060830135606082015262000eed6080840162000e07565b608082015260a08301358281111562000f0557600080fd5b62000f138782860162000d3b565b60a08301525060c08301358281111562000f2c57600080fd5b62000f3a8782860162000d3b565b60c08301525060e08301358281111562000f5357600080fd5b62000f618782860162000d3b565b60e083015250610100808401358381111562000f7c57600080fd5b62000f8a8882870162000d3b565b82840152505061012062000fa081850162000e3e565b9082015261014062000fb484820162000e3e565b90820152610160838101358381111562000fcd57600080fd5b62000fdb8882870162000d3b565b918301919091525061018083810135908201526101a080840135908201526101c09283013592810192909252509392505050565b6000602082840312156200102257600080fd5b5035919050565b6000815180845260005b81811015620010515760208185018101518683018201520162001033565b8181111562001064576000602083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b606081526000620010ac606083018662001029565b8281036020840152620010c0818662001029565b91505060ff83166040830152949350505050565b600060208284031215620010e757600080fd5b8151620010f48162000e18565b9392505050565b60208152600082516101e08060208501526200111c61020085018362001029565b915060208501516200113a604086018267ffffffffffffffff169052565b50604085015160608501526060850151608085015260808501516200116360a086018215159052565b5060a085015173ffffffffffffffffffffffffffffffffffffffff811660c08601525060c085015173ffffffffffffffffffffffffffffffffffffffff811660e08601525060e0850151610100620011d28187018373ffffffffffffffffffffffffffffffffffffffff169052565b8601519050610120620011fc8682018373ffffffffffffffffffffffffffffffffffffffff169052565b808701519150506101407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe086850301818701526200123b848362001029565b9087015161016087810191909152870151610180808801919091528701516101a08088019190915287015190935090506101c0620012908187018373ffffffffffffffffffffffffffffffffffffffff169052565b9095015173ffffffffffffffffffffffffffffffffffffffff1693019290925250919050565b600060208284031215620012c957600080fd5b5051919050565b600060208284031215620012e357600080fd5b815160ff81168114620010f457600080fdfe60806040523480156200001157600080fd5b506040516200421738038062004217833981016040819052620000349162000e55565b6101c0810151600080546001600160a81b0319166001600160a01b0392831617600160a01b1790556101a0820151600a8054919092166001600160a01b031991909116179055805151620000cf5760405162461bcd60e51b815260206004820152601760248201527f50616972206e616d652063616e7420626520656d70747900000000000000000060448201526064015b60405180910390fd5b620000d9620007c6565b81602001516001600160401b031611620001365760405162461bcd60e51b815260206004820152601c60248201527f45787069726174696f6e2074696d657374616d7020696e2070617374000000006044820152606401620000c6565b60008160400151116200018c5760405162461bcd60e51b815260206004820152601f60248201527f436f6c6c61746572616c2070657220706169722063616e6e6f742062652030006044820152606401620000c6565b620001966200086b565b6001600160a01b03166390978d1b82606001516040518263ffffffff1660e01b8152600401620001c891815260200190565b60206040518083038186803b158015620001e157600080fd5b505afa158015620001f6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200021c919062000fcb565b6200026a5760405162461bcd60e51b815260206004820152601960248201527f4964656e746966696572206e6f742072656769737465726564000000000000006044820152606401620000c6565b6000620002766200090c565b6001600160a01b03161415620002c05760405162461bcd60e51b815260206004820152600e60248201526d24b73b30b634b2103334b73232b960911b6044820152606401620000c6565b6101008101516001600160a01b03166200031d5760405162461bcd60e51b815260206004820152601f60248201527f496e76616c69642046696e616e6369616c50726f647563744c696272617279006044820152606401620000c6565b6200032762000951565b60e0820151604051631d1d5b3960e11b81526001600160a01b039182166004820152911690633a3ab6729060240160206040518083038186803b1580156200036e57600080fd5b505afa15801562000383573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003a9919062000fcb565b620003f75760405162461bcd60e51b815260206004820152601a60248201527f436f6c6c61746572616c206e6f742077686974656c69737465640000000000006044820152606401620000c6565b6000816101600151116200044e5760405162461bcd60e51b815260206004820152601760248201527f4f4f206c6976656e6573732063616e6e6f7420626520300000000000000000006044820152606401620000c6565b63bb74480081610160015110620004a85760405162461bcd60e51b815260206004820152601560248201527f4f4f206c6976656e65737320746f6f206c6172676500000000000000000000006044820152606401620000c6565b80518051620004c09160029160209091019062000c55565b506020810151600080546040840151600355606084015160055560808401511515600160b01b0260ff60b01b196001600160401b03909416600160b81b0293909316600160b01b600160f81b03199091161791909117815560a0820151600880546001600160a01b039283166001600160a01b03199182161790915560c08401516009805491841691831691909117905560e084015160078054918416918316919091179055610100840151600b8054919093169116179055620005836200090c565b6101208301518051919250620005a091600c916020019062000c55565b50806001600160a01b031663c371dda76040518163ffffffff1660e01b815260040160206040518083038186803b158015620005db57600080fd5b505afa158015620005f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000616919062000ff0565b6000546001600160a01b0383169063af5d2f3990600160b01b900460ff16620006d257600c805462000648906200100a565b80601f016020809104026020016040519081016040528092919081815260200182805462000676906200100a565b8015620006c75780601f106200069b57610100808354040283529160200191620006c7565b820191906000526020600020905b815481529060010190602001808311620006a957829003601f168201915b5050505050620006dc565b620006dc620009a3565b306040518363ffffffff1660e01b8152600401620006fc92919062001047565b60006040518083038186803b1580156200071557600080fd5b505afa1580156200072a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526200075491908101906200108d565b511115620007a55760405162461bcd60e51b815260206004820152601760248201527f416e63696c6c617279204461746120746f6f206c6f6e670000000000000000006044820152606401620000c6565b50610140810151600d55610160810151600e556101800151600f5562001264565b600080546001600160a01b031615620008665760008054906101000a90046001600160a01b03166001600160a01b03166329cb924d6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200082657600080fd5b505afa1580156200083b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000861919062000ff0565b905090565b504290565b600a546040516302abf57960e61b81527f4964656e74696669657257686974656c6973740000000000000000000000000060048201526000916001600160a01b03169063aafd5e40906024015b60206040518083038186803b158015620008d157600080fd5b505afa158015620008e6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620008619190620010cd565b600a546040516302abf57960e61b81526f4f7074696d69737469634f7261636c6560801b60048201526000916001600160a01b03169063aafd5e4090602401620008b8565b600a546040516302abf57960e61b81527f436f6c6c61746572616c57686974656c6973740000000000000000000000000060048201526000916001600160a01b03169063aafd5e4090602401620008b8565b606062000861600c8054620009b8906200100a565b80601f0160208091040260200160405190810160405280929190818152602001828054620009e6906200100a565b801562000a375780601f1062000a0b5761010080835404028352916020019162000a37565b820191906000526020600020905b81548152906001019060200180831162000a1957829003601f168201915b50505050506040518060400160405280600f81526020016e32b0b9363ca2bc3834b930ba34b7b760891b815250600162000a7760201b620018911760201c565b6060600062000a87858562000ac3565b9050848162000a968562000b11565b60405160200162000aaa93929190620010ed565b6040516020818303038152906040529150509392505050565b81516060901562000af8578160405160200162000ae1919062001136565b604051602081830303815290604052905062000b0b565b8160405160200162000ae191906200116c565b92915050565b60608162000b365750506040805180820190915260018152600360fc1b602082015290565b8160005b811562000b66578062000b4d81620011a9565b915062000b5e9050600a83620011c7565b915062000b3a565b6000816001600160401b0381111562000b835762000b8362000cfb565b6040519080825280601f01601f19166020018201604052801562000bae576020820181803683370190505b509050815b851562000c4c5762000bc7600182620011ea565b9050600062000bd8600a88620011c7565b62000be590600a62001204565b62000bf19088620011ea565b62000bfe90603062001226565b905060008160f81b90508084848151811062000c1e5762000c1e6200124e565b60200101906001600160f81b031916908160001a90535062000c42600a89620011c7565b9750505062000bb3565b50949350505050565b82805462000c63906200100a565b90600052602060002090601f01602090048101928262000c87576000855562000cd2565b82601f1062000ca257805160ff191683800117855562000cd2565b8280016001018555821562000cd2579182015b8281111562000cd257825182559160200191906001019062000cb5565b5062000ce092915062000ce4565b5090565b5b8082111562000ce0576000815560010162000ce5565b634e487b7160e01b600052604160045260246000fd5b6040516101e081016001600160401b038111828210171562000d375762000d3762000cfb565b60405290565b60005b8381101562000d5a57818101518382015260200162000d40565b8381111562000d6a576000848401525b50505050565b600082601f83011262000d8257600080fd5b81516001600160401b038082111562000d9f5762000d9f62000cfb565b604051601f8301601f19908116603f0116810190828211818310171562000dca5762000dca62000cfb565b8160405283815286602085880101111562000de457600080fd5b62000df784602083016020890162000d3d565b9695505050505050565b80516001600160401b038116811462000e1957600080fd5b919050565b8051801515811462000e1957600080fd5b6001600160a01b038116811462000e4557600080fd5b50565b805162000e198162000e2f565b60006020828403121562000e6857600080fd5b81516001600160401b038082111562000e8057600080fd5b908301906101e0828603121562000e9657600080fd5b62000ea062000d11565b82518281111562000eb057600080fd5b62000ebe8782860162000d70565b82525062000ecf6020840162000e01565b6020820152604083015160408201526060830151606082015262000ef66080840162000e1e565b608082015262000f0960a0840162000e48565b60a082015262000f1c60c0840162000e48565b60c082015262000f2f60e0840162000e48565b60e082015261010062000f4481850162000e48565b90820152610120838101518381111562000f5d57600080fd5b62000f6b8882870162000d70565b91830191909152506101408381015190820152610160808401519082015261018080840151908201526101a0915062000fa682840162000e48565b828201526101c0915062000fbc82840162000e48565b91810191909152949350505050565b60006020828403121562000fde57600080fd5b62000fe98262000e1e565b9392505050565b6000602082840312156200100357600080fd5b5051919050565b600181811c908216806200101f57607f821691505b602082108114156200104157634e487b7160e01b600052602260045260246000fd5b50919050565b60408152600083518060408401526200106881606085016020880162000d3d565b6001600160a01b0393909316602083015250601f91909101601f191601606001919050565b600060208284031215620010a057600080fd5b81516001600160401b03811115620010b757600080fd5b620010c58482850162000d70565b949350505050565b600060208284031215620010e057600080fd5b815162000fe98162000e2f565b600084516200110181846020890162000d3d565b8451908301906200111781836020890162000d3d565b84519101906200112c81836020880162000d3d565b0195945050505050565b600b60fa1b8152600082516200115481600185016020870162000d3d565b601d60f91b6001939091019283015250600201919050565b600082516200118081846020870162000d3d565b601d60f91b920191825250600101919050565b634e487b7160e01b600052601160045260246000fd5b6000600019821415620011c057620011c062001193565b5060010190565b600082620011e557634e487b7160e01b600052601260045260246000fd5b500490565b600082821015620011ff57620011ff62001193565b500390565b600081600019048311821515161562001221576200122162001193565b500290565b600060ff821660ff84168060ff0382111562001246576200124662001193565b019392505050565b634e487b7160e01b600052603260045260246000fd5b612fa380620012746000396000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c80639752366111610104578063b9a3c84c116100a2578063db006a7511610071578063db006a7514610476578063e3065da714610489578063e964ae02146104a9578063edfa9a9b146104b257600080fd5b8063b9a3c84c14610432578063c1e7d9b714610452578063cd4670f21461045a578063d564fddd1461046d57600080fd5b80639f43ddd2116100de5780639f43ddd2146103ba578063a9ae29df146103e9578063b2016bd4146103f2578063b66333cd1461041257600080fd5b806397523661146103715780639a9c29f61461037a5780639da49b1a1461038d57600080fd5b806374d3aa7e1161017c57806383f892861161014b57806383f892861461031a57806385c984741461032257806390392ae31461032b5780639375f0e91461035157600080fd5b806374d3aa7e146102d1578063780900dc146102f757806379599f961461030a5780638150fd3d1461031257600080fd5b806340794c3b116101b857806340794c3b146102545780634eef4a73146102695780634fe4ecbf1461029157806358aee8151461029a57600080fd5b80631c39c38d146101df57806322f8e5661461022957806329cb924d1461023e575b600080fd5b6000546101ff9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b61023c610237366004612919565b6104bb565b005b610246610564565b604051908152602001610220565b61025c61062b565b60405161022091906129a8565b61027c6102773660046129dd565b6106b9565b60408051928352602083019190915201610220565b610246600e5481565b6000546102c190760100000000000000000000000000000000000000000000900460ff1681565b6040519015158152602001610220565b7f8000000000000000000000000000000000000000000000000000000000000000610246565b610246610305366004612919565b610813565b61023c610b11565b61025c610d68565b61025c610d75565b610246600f5481565b6000546102c1907501000000000000000000000000000000000000000000900460ff1681565b600b546101ff9073ffffffffffffffffffffffffffffffffffffffff1681565b61024660055481565b6102466103883660046129fa565b610e42565b6001546103a19067ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610220565b6000546103a19077010000000000000000000000000000000000000000000000900467ffffffffffffffff1681565b61024660045481565b6007546101ff9073ffffffffffffffffffffffffffffffffffffffff1681565b6008546101ff9073ffffffffffffffffffffffffffffffffffffffff1681565b600a546101ff9073ffffffffffffffffffffffffffffffffffffffff1681565b6102c1611257565b61023c610468366004612a1c565b6112b6565b610246600d5481565b610246610484366004612919565b611634565b6009546101ff9073ffffffffffffffffffffffffffffffffffffffff1681565b61024660035481565b61024660065481565b60005473ffffffffffffffffffffffffffffffffffffffff166104dd57600080fd5b6000546040517f22f8e5660000000000000000000000000000000000000000000000000000000081526004810183905273ffffffffffffffffffffffffffffffffffffffff909116906322f8e56690602401600060405180830381600087803b15801561054957600080fd5b505af115801561055d573d6000803e3d6000fd5b5050505050565b6000805473ffffffffffffffffffffffffffffffffffffffff16156106265760008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166329cb924d6040518163ffffffff1660e01b815260040160206040518083038186803b1580156105e957600080fd5b505afa1580156105fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106219190612a46565b905090565b504290565b6002805461063890612a5f565b80601f016020809104026020016040519081016040528092919081815260200182805461066490612a5f565b80156106b15780601f10610686576101008083540402835291602001916106b1565b820191906000526020600020905b81548152906001019060200180831161069457829003601f168201915b505050505081565b6000806106c46118d8565b6008546040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8581166004830152909116906370a082319060240160206040518083038186803b15801561072f57600080fd5b505afa158015610743573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107679190612a46565b6009546040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152909116906370a082319060240160206040518083038186803b1580156107d257600080fd5b505afa1580156107e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061080a9190612a46565b91509150915091565b6000805477010000000000000000000000000000000000000000000000900467ffffffffffffffff16610844610564565b106108b0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f6e6c792063616c6c61626c65207072652d657870697279000000000000000060448201526064015b60405180910390fd5b6108b86118d8565b6108e5600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff169055565b60408051602080820183526003548252825190810190925283825261090a919061195c565b516007549091506109339073ffffffffffffffffffffffffffffffffffffffff163330846119ea565b6008546040517f40c10f190000000000000000000000000000000000000000000000000000000081523360048201526024810184905273ffffffffffffffffffffffffffffffffffffffff909116906340c10f1990604401602060405180830381600087803b1580156109a557600080fd5b505af11580156109b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109dd9190612ab3565b6109e657600080fd5b6009546040517f40c10f190000000000000000000000000000000000000000000000000000000081523360048201526024810184905273ffffffffffffffffffffffffffffffffffffffff909116906340c10f1990604401602060405180830381600087803b158015610a5857600080fd5b505af1158015610a6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a909190612ab3565b610a9957600080fd5b6040518290829033907f2b42f4b25222a5d447ca19dfca2afd1b8d32adfed550f7b87bf9569f6da70c0090600090a4610b0c600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055565b919050565b610b196118d8565b610b46600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff169055565b610b4e611257565b15610bb5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f436f6e747261637420616c7265616479206561726c792065787069726564000060448201526064016108a7565b60005477010000000000000000000000000000000000000000000000900467ffffffffffffffff16610be5610564565b1015610c4d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4f6e6c792063616c6c61626c6520706f73742d6578706972790000000000000060448201526064016108a7565b610cf7600060179054906101000a900467ffffffffffffffff16600c8054610c7490612a5f565b80601f0160208091040260200160405190810160405280929190818152602001828054610ca090612a5f565b8015610ced5780601f10610cc257610100808354040283529160200191610ced565b820191906000526020600020905b815481529060010190602001808311610cd057829003601f168201915b5050505050611acc565b60405133907f18600820405d6cf356e3556301762ca32395e72d8c81494fa344835c9da3633d90600090a2610d66600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055565b565b600c805461063890612a5f565b6060610621600c8054610d8790612a5f565b80601f0160208091040260200160405190810160405280929190818152602001828054610db390612a5f565b8015610e005780601f10610dd557610100808354040283529160200191610e00565b820191906000526020600020905b815481529060010190602001808311610de357829003601f168201915b50505050506040518060400160405280600f81526020017f6561726c7945787069726174696f6e00000000000000000000000000000000008152506001611891565b6000610e4c6118d8565b610e79600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff169055565b600054760100000000000000000000000000000000000000000000900460ff168015610ed2575060005477010000000000000000000000000000000000000000000000900467ffffffffffffffff16610ed0610564565b105b80610f0b575060005477010000000000000000000000000000000000000000000000900467ffffffffffffffff16610f08610564565b10155b610f71576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f43616e6e6f7420736574746c650000000000000000000000000000000000000060448201526064016108a7565b6000547501000000000000000000000000000000000000000000900460ff16610f9c57610f9c611d46565b6008546040517f79cc67900000000000000000000000000000000000000000000000000000000081523360048201526024810185905273ffffffffffffffffffffffffffffffffffffffff909116906379cc679090604401602060405180830381600087803b15801561100e57600080fd5b505af1158015611022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110469190612ab3565b61104f57600080fd5b6009546040517f79cc67900000000000000000000000000000000000000000000000000000000081523360048201526024810184905273ffffffffffffffffffffffffffffffffffffffff909116906379cc679090604401602060405180830381600087803b1580156110c157600080fd5b505af11580156110d5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110f99190612ab3565b61110257600080fd5b604080516020808201835260045482528251808201845260035481528351918201909352858152600092611140929161113a91612051565b90612051565b600001519050600061119461116f60405180602001604052806004548152506111696001612097565b906120cc565b60408051602080820183526003548252825190810190925287825261113a9190612051565b5190506111a18183612b04565b6007549093506111c89073ffffffffffffffffffffffffffffffffffffffff1633856120f6565b604080518481526020810187905290810185905233907fe8fdc264e5a5640d893f125384c4e2c5afe2d9a04aef1129e643caaa72771cff9060600160405180910390a25050611251600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055565b92915050565b60015460009067ffffffffffffffff161580159061062157507f80000000000000000000000000000000000000000000000000000000000000006001546112af9067ffffffffffffffff166112aa610d75565b612151565b1415905090565b6112be6118d8565b6112eb600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff169055565b6112f3611257565b1561135a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f436f6e747261637420616c7265616479206561726c792065787069726564000060448201526064016108a7565b60005477010000000000000000000000000000000000000000000000900467ffffffffffffffff1661138a610564565b106113f1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4f6e6c792063616c6c61626c65207072652d657870697279000000000000000060448201526064016108a7565b600054760100000000000000000000000000000000000000000000900460ff16611477576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f4561726c792065787069726174696f6e2064697361626c65640000000000000060448201526064016108a7565b61147f610564565b8167ffffffffffffffff1611156114f2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f4f6e6c792070726f706f73652065787069726520696e2074686520706173740060448201526064016108a7565b60008167ffffffffffffffff1611611566576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601b60248201527f4561726c792065787069726174696f6e2063616e27742062652030000000000060448201526064016108a7565b600180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff83169081179091556115ae906115a9610d75565b611acc565b60405167ffffffffffffffff8216815233907fe8f97c669cce9e6c955d0f1401760518c4d53fa550bcd00b4c21d16b7d9165259060200160405180910390a2611631600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055565b50565b600061163e6118d8565b61166b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff169055565b6008546040517f79cc67900000000000000000000000000000000000000000000000000000000081523360048201526024810184905273ffffffffffffffffffffffffffffffffffffffff909116906379cc679090604401602060405180830381600087803b1580156116dd57600080fd5b505af11580156116f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117159190612ab3565b61171e57600080fd5b6009546040517f79cc67900000000000000000000000000000000000000000000000000000000081523360048201526024810184905273ffffffffffffffffffffffffffffffffffffffff909116906379cc679090604401602060405180830381600087803b15801561179057600080fd5b505af11580156117a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117c89190612ab3565b6117d157600080fd5b6040805160208082018352600354825282519081019092528382526117f69190612051565b5160075490915061181e9073ffffffffffffffffffffffffffffffffffffffff1633836120f6565b6040518290829033907fd171fb179b26c49e23fe46eddd44d3048a1ad277b62144ac0725fbcf1dbf6d5290600090a4610b0c600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055565b6060600061189f85856121eb565b905084816118ac8561222d565b6040516020016118be93929190612b1c565b6040516020818303038152906040529150505b9392505050565b60005474010000000000000000000000000000000000000000900460ff16610d66576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016108a7565b60408051602081019091526000808252825184516119799161238a565b9050600061198f670de0b6b3a764000083612b8e565b905060006119a583670de0b6b3a7640000612396565b905080156119d1576040805160208101909152806119c48460016123a2565b8152509350505050611251565b6040518060200160405280838152509350505050611251565b60405173ffffffffffffffffffffffffffffffffffffffff80851660248301528316604482015260648101829052611ac69085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091526123ae565b50505050565b6000611ad66124ba565b600d5490915015611b3757600d54600754611b0d9173ffffffffffffffffffffffffffffffffffffffff90911690339030906119ea565b600d54600754611b379173ffffffffffffffffffffffffffffffffffffffff90911690839061257c565b600554600754600d546040517f11df92f100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff808616946311df92f194611ba594919367ffffffffffffffff8b16938a9392169190600401612ba2565b602060405180830381600087803b158015611bbf57600080fd5b505af1158015611bd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bf79190612a46565b50600554600e546040517f473c45fe00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84169263473c45fe92611c5c9267ffffffffffffffff8916918891600401612beb565b600060405180830381600087803b158015611c7657600080fd5b505af1158015611c8a573d6000803e3d6000fd5b5050600554600f546040517fad5a755a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8616945063ad5a755a9350611cf4929167ffffffffffffffff891691889190600401612beb565b602060405180830381600087803b158015611d0e57600080fd5b505af1158015611d22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ac69190612a46565b611d4e6124ba565b73ffffffffffffffffffffffffffffffffffffffff1663bc58ccaa30600554600060179054906101000a900467ffffffffffffffff16600c6040518563ffffffff1660e01b8152600401611da59493929190612c1b565b60206040518083038186803b158015611dbd57600080fd5b505afa158015611dd1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611df59190612ab3565b15611eac57611ea4600060179054906101000a900467ffffffffffffffff16600c8054611e2190612a5f565b80601f0160208091040260200160405190810160405280929190818152602001828054611e4d90612a5f565b8015611e9a5780601f10611e6f57610100808354040283529160200191611e9a565b820191906000526020600020905b815481529060010190602001808311611e7d57829003601f168201915b5050505050612151565b600655611f54565b600154611ec59067ffffffffffffffff166112aa610d75565b6006557f80000000000000000000000000000000000000000000000000000000000000006006541415611f54576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f7261636c652070726576656e7473206561726c792065787069726174696f6e60448201526064016108a7565b600b546006546040517f2da52361000000000000000000000000000000000000000000000000000000008152600481019190915261200c9173ffffffffffffffffffffffffffffffffffffffff1690632da523619060240160206040518083038186803b158015611fc457600080fd5b505afa158015611fd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ffc9190612a46565b6120066001612097565b5161270d565b600455600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff167501000000000000000000000000000000000000000000179055565b6040805160208101909152600081526040805160208101909152825184518291670de0b6b3a7640000916120849161238a565b61208e9190612b8e565b90529392505050565b6040805160208101909152600081526040805160208101909152806120c484670de0b6b3a764000061238a565b905292915050565b604080516020810190915260008152604080516020810190915282518451829161208e9190612723565b60405173ffffffffffffffffffffffffffffffffffffffff831660248201526044810182905261214c9084907fa9059cbb0000000000000000000000000000000000000000000000000000000090606401611a44565b505050565b600061215b6124ba565b73ffffffffffffffffffffffffffffffffffffffff166353b5923960055485856040518463ffffffff1660e01b815260040161219993929190612d31565b602060405180830381600087803b1580156121b357600080fd5b505af11580156121c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d19190612a46565b81516060901561221c57816040516020016122069190612d63565b6040516020818303038152906040529050611251565b816040516020016122069190612dcf565b60608161226d57505060408051808201909152600181527f3000000000000000000000000000000000000000000000000000000000000000602082015290565b8160005b8115612297578061228181612e10565b91506122909050600a83612b8e565b9150612271565b60008167ffffffffffffffff8111156122b2576122b2612e49565b6040519080825280601f01601f1916602001820160405280156122dc576020820181803683370190505b509050815b8515612381576122f2600182612e78565b90506000612301600a88612b8e565b61230c90600a612e8f565b6123169088612e78565b612321906030612ecc565b905060008160f81b90508084848151811061233e5761233e612ef1565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350612378600a89612b8e565b975050506122e1565b50949350505050565b60006118d18284612e8f565b60006118d18284612f20565b60006118d18284612b04565b6000612410826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661272f9092919063ffffffff16565b80519091501561214c578080602001905181019061242e9190612ab3565b61214c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f7420737563636565640000000000000000000000000000000000000000000060648201526084016108a7565b600a546040517faafd5e400000000000000000000000000000000000000000000000000000000081527f4f7074696d69737469634f7261636c6500000000000000000000000000000000600482015260009173ffffffffffffffffffffffffffffffffffffffff169063aafd5e409060240160206040518083038186803b15801561254457600080fd5b505afa158015612558573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106219190612f34565b80158061262b57506040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff838116602483015284169063dd62ed3e9060440160206040518083038186803b1580156125f157600080fd5b505afa158015612605573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126299190612a46565b155b6126b7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527f20746f206e6f6e2d7a65726f20616c6c6f77616e63650000000000000000000060648201526084016108a7565b60405173ffffffffffffffffffffffffffffffffffffffff831660248201526044810182905261214c9084907f095ea7b30000000000000000000000000000000000000000000000000000000090606401611a44565b600081831061271c57816118d1565b5090919050565b60006118d18284612e78565b606061273e8484600085612746565b949350505050565b6060824710156127d8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c000000000000000000000000000000000000000000000000000060648201526084016108a7565b843b612840576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016108a7565b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516128699190612f51565b60006040518083038185875af1925050503d80600081146128a6576040519150601f19603f3d011682016040523d82523d6000602084013e6128ab565b606091505b50915091506128bb8282866128c6565b979650505050505050565b606083156128d55750816118d1565b8251156128e55782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108a791906129a8565b60006020828403121561292b57600080fd5b5035919050565b60005b8381101561294d578181015183820152602001612935565b83811115611ac65750506000910152565b60008151808452612976816020860160208601612932565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6020815260006118d1602083018461295e565b73ffffffffffffffffffffffffffffffffffffffff8116811461163157600080fd5b6000602082840312156129ef57600080fd5b81356118d1816129bb565b60008060408385031215612a0d57600080fd5b50508035926020909101359150565b600060208284031215612a2e57600080fd5b813567ffffffffffffffff811681146118d157600080fd5b600060208284031215612a5857600080fd5b5051919050565b600181811c90821680612a7357607f821691505b60208210811415612aad577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b600060208284031215612ac557600080fd5b815180151581146118d157600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008219821115612b1757612b17612ad5565b500190565b60008451612b2e818460208901612932565b845190830190612b42818360208901612932565b8451910190612b55818360208801612932565b0195945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600082612b9d57612b9d612b5f565b500490565b85815284602082015260a060408201526000612bc160a083018661295e565b73ffffffffffffffffffffffffffffffffffffffff94909416606083015250608001529392505050565b848152836020820152608060408201526000612c0a608083018561295e565b905082606083015295945050505050565b73ffffffffffffffffffffffffffffffffffffffff8516815260006020858184015267ffffffffffffffff85166040840152608060608401526000845481600182811c915080831680612c6f57607f831692505b858310811415612ca6577f4e487b710000000000000000000000000000000000000000000000000000000085526022600452602485fd5b6080880183905260a08801818015612cc55760018114612cf457612d1f565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00861682528782019650612d1f565b60008b81526020902060005b86811015612d1957815484820152908501908901612d00565b83019750505b50949c9b505050505050505050505050565b83815267ffffffffffffffff83166020820152606060408201526000612d5a606083018461295e565b95945050505050565b7f2c00000000000000000000000000000000000000000000000000000000000000815260008251612d9b816001850160208701612932565b7f3a000000000000000000000000000000000000000000000000000000000000006001939091019283015250600201919050565b60008251612de1818460208701612932565b7f3a00000000000000000000000000000000000000000000000000000000000000920191825250600101919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415612e4257612e42612ad5565b5060010190565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082821015612e8a57612e8a612ad5565b500390565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615612ec757612ec7612ad5565b500290565b600060ff821660ff84168060ff03821115612ee957612ee9612ad5565b019392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082612f2f57612f2f612b5f565b500690565b600060208284031215612f4657600080fd5b81516118d1816129bb565b60008251612f63818460208701612932565b919091019291505056fea2646970667358221220ca4930d46e9ad54cee892386717332f475d43965f1584d0abc83f7795ac3774564736f6c63430008090033a2646970667358221220a654684638cd380d51de90785ecd1c0924a9824b0243d938265c4bb8397aac6864736f6c63430008090033000000000000000000000000b22033ff04ad01fbe8d78ef4622a20626834271b00000000000000000000000056f2c8353049270d3553773e680b0d6c632544b60000000000000000000000000000000000000000000000000000000000000000
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000b22033ff04ad01fbe8d78ef4622a20626834271b00000000000000000000000056f2c8353049270d3553773e680b0d6c632544b60000000000000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : _finder (address): 0xb22033ff04ad01fbe8d78ef4622a20626834271b
Arg [1] : _tokenFactory (address): 0x56f2c8353049270d3553773e680b0d6c632544b6
Arg [2] : _timer (address): 0x0000000000000000000000000000000000000000
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000b22033ff04ad01fbe8d78ef4622a20626834271b
Arg [1] : 00000000000000000000000056f2c8353049270d3553773e680b0d6c632544b6
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000000
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|