Feature Tip: Add private address tag to any address under My Name Tag !
More Info
Private Name Tags
ContractCreator
Latest 17 from a total of 17 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Exit One For Cre... | 21610261 | 6 days ago | IN | 0 ETH | 0.00285538 | ||||
Exit One For Cre... | 21518687 | 18 days ago | IN | 0 ETH | 0.00538528 | ||||
Exit One For Cre... | 21291762 | 50 days ago | IN | 0 ETH | 0.00535836 | ||||
Exit One For Cre... | 21228809 | 59 days ago | IN | 0 ETH | 0.00717771 | ||||
Exit One For Cre... | 21158365 | 69 days ago | IN | 0 ETH | 0.01578304 | ||||
Exit One For Cre... | 20718851 | 130 days ago | IN | 0 ETH | 0.00257416 | ||||
Exit One For Cre... | 20637623 | 141 days ago | IN | 0 ETH | 0.00079924 | ||||
Exit One For Cre... | 20562508 | 152 days ago | IN | 0 ETH | 0.00304574 | ||||
Exit One For Cre... | 20562496 | 152 days ago | IN | 0 ETH | 0.00353728 | ||||
Exit One For Cre... | 20556544 | 153 days ago | IN | 0 ETH | 0.00241819 | ||||
Exit One For Cre... | 20518603 | 158 days ago | IN | 0 ETH | 0.00136442 | ||||
Exit One For Cre... | 20509920 | 159 days ago | IN | 0 ETH | 0.00139824 | ||||
Exit One For Cre... | 20498415 | 161 days ago | IN | 0 ETH | 0.00105219 | ||||
Exit All For Cre... | 20494691 | 161 days ago | IN | 0 ETH | 0.0072452 | ||||
Exit One For Cre... | 20470975 | 165 days ago | IN | 0 ETH | 0.00590338 | ||||
Exit One For Cre... | 20466678 | 165 days ago | IN | 0 ETH | 0.00219823 | ||||
Exit One For Cre... | 20460967 | 166 days ago | IN | 0 ETH | 0.03702701 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x30C33A3f...403ADa94E The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
FraxFarmQuitCreditor_UniV3_1
Compiler Version
v0.8.26+commit.8a97fa7a
Contract Source Code (Solidity)
/** *Submitted for verification at Etherscan.io on 2024-07-30 */ // SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; // node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol // OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol) /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard_0 { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being 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. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @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 work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20_0 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev 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 `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount ) external returns (bool); } // node_modules/@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit_0 { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // node_modules/@openzeppelin/contracts/utils/Address.sol // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) /** * @dev Collection of functions related to the address type */ library Address_0 { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 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 /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } } // src/contracts/Miscellany/FraxFarmQuitCreditor/ICrossDomainMessenger.sol interface ICrossDomainMessenger_0 { function MESSAGE_VERSION() external view returns (uint16); function MIN_GAS_CALLDATA_OVERHEAD() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR() external view returns (uint64); function OTHER_MESSENGER() external view returns (address); function RELAY_CALL_OVERHEAD() external view returns (uint64); function RELAY_CONSTANT_OVERHEAD() external view returns (uint64); function RELAY_GAS_CHECK_BUFFER() external view returns (uint64); function RELAY_RESERVED_GAS() external view returns (uint64); function baseGas(bytes memory _message, uint32 _minGasLimit) external pure returns (uint64); function failedMessages(bytes32) external view returns (bool); function initialize() external; function l1CrossDomainMessenger() external view returns (address); function messageNonce() external view returns (uint256); function paused() external view returns (bool); function relayMessage( uint256 _nonce, address _sender, address _target, uint256 _value, uint256 _minGasLimit, bytes memory _message ) external; function sendMessage(address _target, bytes memory _message, uint32 _minGasLimit) external; function successfulMessages(bytes32) external view returns (bool); function version() external view returns (string memory); function xDomainMessageSender() external view returns (address); } // src/contracts/Miscellany/FraxFarmQuitCreditor/IExponentialPriceOracle.sol interface IExponentialPriceOracle_0 { function getPrices() external view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh); function priceEnd() external view returns (uint256); function pricePerShare() external view returns (uint256 _price); function priceStart() external view returns (uint256); function timeEnd() external view returns (uint256); function timeStart() external view returns (uint256); } // src/contracts/Miscellany/FraxFarmQuitCreditor/IL1CrossDomainMessenger.sol interface IL1CrossDomainMessenger_0 { function MESSAGE_VERSION() external view returns (uint16); function MIN_GAS_CALLDATA_OVERHEAD() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR() external view returns (uint64); function OTHER_MESSENGER() external view returns (address); function PORTAL() external view returns (address); function RELAY_CALL_OVERHEAD() external view returns (uint64); function RELAY_CONSTANT_OVERHEAD() external view returns (uint64); function RELAY_GAS_CHECK_BUFFER() external view returns (uint64); function RELAY_RESERVED_GAS() external view returns (uint64); function baseGas(bytes memory _message, uint32 _minGasLimit) external pure returns (uint64); function failedMessages(bytes32) external view returns (bool); function initialize(address _superchainConfig) external; function messageNonce() external view returns (uint256); function paused() external view returns (bool); function portal() external view returns (address); function relayMessage( uint256 _nonce, address _sender, address _target, uint256 _value, uint256 _minGasLimit, bytes memory _message ) external; function sendMessage(address _target, bytes memory _message, uint32 _minGasLimit) external payable; function successfulMessages(bytes32) external view returns (bool); function superchainConfig() external view returns (address); function version() external view returns (string memory); function xDomainMessageSender() external view returns (address); } // src/contracts/Miscellany/FraxFarmQuitCreditor/Imports.sol // Sources flattened with hardhat v2.19.4 https://hardhat.org // File @openzeppelin/contracts/token/ERC20/extensions/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol) /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit_1 { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // File @openzeppelin/contracts/token/ERC20/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol) /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20_1 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) 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 a `value` amount of tokens 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 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol) /** * @dev Collection of functions related to the address type */ library Address_1 { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error AddressInsufficientBalance(address account); /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedInnerCall(); /** * @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { if (address(this).balance < amount) { revert AddressInsufficientBalance(address(this)); } (bool success, ) = recipient.call{ value: amount }(""); if (!success) { revert FailedInnerCall(); } } /** * @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 or custom error, it is bubbled * up by this function (like regular Solidity function calls). However, if * the call reverted with no returned reason, this function reverts with a * {FailedInnerCall} error. * * 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. */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0); } /** * @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`. */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { if (address(this).balance < value) { revert AddressInsufficientBalance(address(this)); } (bool success, bytes memory returndata) = target.call{ value: value }(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an * unsuccessful call. */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata ) internal view returns (bytes memory) { if (!success) { _revert(returndata); } else { // only check if target is a contract if the call was successful and the return data is empty // otherwise we already know that it was a contract if (returndata.length == 0 && target.code.length == 0) { revert AddressEmptyCode(target); } return returndata; } } /** * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the * revert reason or with a default {FailedInnerCall} error. */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (!success) { _revert(returndata); } else { return returndata; } } /** * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}. */ function _revert(bytes memory returndata) private pure { // 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 /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert FailedInnerCall(); } } } // File @openzeppelin/contracts/token/ERC20/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.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_0 { using Address_1 for address; /** * @dev An operation with an ERC20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20_1 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20_1 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20_1 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20_1 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove(IERC20_1 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @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_1 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); if (returndata.length != 0 && !abi.decode(returndata, (bool))) { revert SafeERC20FailedOperation(address(token)); } } /** * @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). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20_1 token, bytes memory data) private returns (bool) { // 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 cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0; } } // File @openzeppelin/contracts/utils/introspection/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol) /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File @openzeppelin/contracts/token/ERC721/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol) /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or * {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon * a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom(address from, address to, uint256 tokenId) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 tokenId) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the address zero. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); } // File @openzeppelin/contracts/token/ERC721/extensions/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol) /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // File @openzeppelin/contracts/token/ERC721/extensions/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Metadata.sol) /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File contracts/Common/Context.sol // Original license: SPDX_License_Identifier: MIT /* * @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 GSN 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 payable) { return payable(msg.sender); } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } } // File contracts/Math/SafeMath.sol // Original license: SPDX_License_Identifier: MIT /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File contracts/ERC20/ERC20.sol // Original license: SPDX_License_Identifier: MIT /** * @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 {ERC20Mintable}. * * 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 guidelines: functions revert instead * of 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_1 { using SafeMath for uint256; mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor(string memory __name, string memory __symbol) public { _name = __name; _symbol = __symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view 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 {_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() public view returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view 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.approve(address spender, uint256 amount) */ 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); _approve( sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance") ); 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].add(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) { _approve( _msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero") ); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is 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); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(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 * * - `to` 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 = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. */ function burn(uint256 amount) public virtual { _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for `accounts`'s tokens of at least * `amount`. */ function burnFrom(address account, uint256 amount) public virtual { uint256 decreasedAllowance = allowance(account, _msgSender()).sub( amount, "ERC20: burn amount exceeds allowance" ); _approve(account, _msgSender(), decreasedAllowance); _burn(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); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is 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 Destroys `amount` tokens from `account`.`amount` is then deducted * from the caller's allowance. * * See {_burn} and {_approve}. */ function _burnFrom(address account, uint256 amount) internal virtual { _burn(account, amount); _approve( account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance") ); } /** * @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 to 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:using-hooks.adoc[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {} } // File contracts/Math/HomoraMath.sol // Original license: SPDX_License_Identifier: MIT library HomoraMath { using SafeMath for uint256; function divCeil(uint256 lhs, uint256 rhs) internal pure returns (uint256) { return lhs.add(rhs).sub(1) / rhs; } function fmul(uint256 lhs, uint256 rhs) internal pure returns (uint256) { return lhs.mul(rhs) / (2 ** 112); } function fdiv(uint256 lhs, uint256 rhs) internal pure returns (uint256) { return lhs.mul(2 ** 112) / rhs; } // implementation from https://github.com/Uniswap/uniswap-lib/commit/99f3f28770640ba1bb1ff460ac7c5292fb8291a0 // original implementation: https://github.com/abdk-consulting/abdk-libraries-solidity/blob/master/ABDKMath64x64.sol#L687 function sqrt(uint256 x) internal pure returns (uint256) { if (x == 0) return 0; uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return (r < r1 ? r : r1); } } // File contracts/Oracle/AggregatorV3Interface.sol // Original license: SPDX_License_Identifier: MIT interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); // getRoundData and latestRoundData should both raise "No data present" // if they do not have data to report, instead of returning unset values // which could be misinterpreted as actual reported values. function getRoundData( uint80 _roundId ) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); } // File contracts/Oracle/IPricePerShareOptions.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later interface IPricePerShareOptions { // Compound-style [Comp, Cream, Rari, Scream] // Multiplied by 1e18 function exchangeRateStored() external view returns (uint256); // Curve-style [Curve, Convex, NOT StakeDAO] // In 1e18 function get_virtual_price() external view returns (uint256); // SaddleD4Pool (SwapFlashLoan) function getVirtualPrice() external view returns (uint256); // StakeDAO function getPricePerFullShare() external view returns (uint256); // Yearn Vault function pricePerShare() external view returns (uint256); } // File contracts/Staking/Owned.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later // https://docs.synthetix.io/contracts/Owned contract Owned { address public owner; address public nominatedOwner; constructor(address _owner) public { require(_owner != address(0), "Owner address cannot be 0"); owner = _owner; emit OwnerChanged(address(0), _owner); } function nominateNewOwner(address _owner) external onlyOwner { nominatedOwner = _owner; emit OwnerNominated(_owner); } function acceptOwnership() external { require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership"); emit OwnerChanged(owner, nominatedOwner); owner = nominatedOwner; nominatedOwner = address(0); } modifier onlyOwner() { require(msg.sender == owner, "Only the contract owner may perform this action"); _; } event OwnerNominated(address newOwner); event OwnerChanged(address oldOwner, address newOwner); } // File contracts/Oracle/ComboOracle.sol // Original license: SPDX_License_Identifier: MIT // ==================================================================== // | ______ _______ | // | / _____________ __ __ / ____(_____ ____ _____ ________ | // | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ | // | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ | // | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ | // | | // ==================================================================== // =========================== ComboOracle ============================ // ==================================================================== // Aggregates prices for various tokens // Also has improvements from https://github.com/AlphaFinanceLab/alpha-homora-v2-contract/blob/master/contracts/oracle/ChainlinkAdapterOracle.sol // Frax Finance: https://github.com/FraxFinance // Primary Author(s) // Travis Moore: https://github.com/FortisFortuna // Reviewer(s) / Contributor(s) // Jason Huan: https://github.com/jasonhuan // Sam Kazemian: https://github.com/samkazemian contract ComboOracle is Owned { /* ========== STATE VARIABLES ========== */ address timelock_address; address address_to_consult; AggregatorV3Interface private priceFeedETHUSD; ERC20 private WETH; string public native_token_symbol; uint256 public PRECISE_PRICE_PRECISION = 1e18; uint256 public PRICE_PRECISION = 1e6; uint256 public PRICE_MISSING_MULTIPLIER = 1e12; address[] public all_token_addresses; mapping(address => TokenInfo) public token_info; // token address => info mapping(address => bool) public has_info; // token address => has info // Price mappings uint256 public maxDelayTime = 90_000; // 25 hrs. Mapping for max delay time /* ========== STRUCTS ========== */ struct TokenInfoConstructorArgs { address token_address; address agg_addr_for_underlying; uint256 agg_other_side; // 0: USD, 1: ETH address underlying_tkn_address; // Will be address(0) for simple tokens. Otherwise, the aUSDC, yvUSDC address, etc address pps_override_address; bytes4 pps_call_selector; // eg bytes4(keccak256("pricePerShare()")); uint256 pps_decimals; } struct TokenInfo { address token_address; string symbol; address agg_addr_for_underlying; uint256 agg_other_side; // 0: USD, 1: ETH uint256 agg_decimals; address underlying_tkn_address; // Will be address(0) for simple tokens. Otherwise, the aUSDC, yvUSDC address, etc address pps_override_address; bytes4 pps_call_selector; // eg bytes4(keccak256("pricePerShare()")); uint256 pps_decimals; int256 ctkn_undrly_missing_decs; } /* ========== CONSTRUCTOR ========== */ constructor( address _owner_address, address _eth_usd_chainlink_address, address _weth_address, string memory _native_token_symbol, string memory _weth_token_symbol ) Owned(_owner_address) { // Instantiate the instances priceFeedETHUSD = AggregatorV3Interface(_eth_usd_chainlink_address); WETH = ERC20(_weth_address); // Handle native ETH all_token_addresses.push(address(0)); native_token_symbol = _native_token_symbol; token_info[address(0)] = TokenInfo( address(0), _native_token_symbol, address(_eth_usd_chainlink_address), 0, 8, address(0), address(0), bytes4(0), 0, 0 ); has_info[address(0)] = true; // Handle WETH/USD all_token_addresses.push(_weth_address); token_info[_weth_address] = TokenInfo( _weth_address, _weth_token_symbol, address(_eth_usd_chainlink_address), 0, 8, address(0), address(0), bytes4(0), 0, 0 ); has_info[_weth_address] = true; } /* ========== MODIFIERS ========== */ modifier onlyByOwnGov() { require( msg.sender == owner || msg.sender == timelock_address, "You are not an owner or the governance timelock" ); _; } /* ========== VIEWS ========== */ function allTokenAddresses() public view returns (address[] memory) { return all_token_addresses; } function allTokenInfos() public view returns (TokenInfo[] memory) { TokenInfo[] memory return_data = new TokenInfo[](all_token_addresses.length); for (uint256 i = 0; i < all_token_addresses.length; i++) { return_data[i] = token_info[all_token_addresses[i]]; } return return_data; } // E6 function getETHPrice() public view returns (uint256) { (uint80 roundID, int256 price, , uint256 updatedAt, uint80 answeredInRound) = priceFeedETHUSD.latestRoundData(); require( price >= 0 && (updatedAt >= block.timestamp - maxDelayTime) && answeredInRound >= roundID, "Invalid chainlink price" ); return (uint256(price) * (PRICE_PRECISION)) / (1e8); // ETH/USD is 8 decimals on Chainlink } // E18 function getETHPricePrecise() public view returns (uint256) { (uint80 roundID, int256 price, , uint256 updatedAt, uint80 answeredInRound) = priceFeedETHUSD.latestRoundData(); require( price >= 0 && (updatedAt >= block.timestamp - maxDelayTime) && answeredInRound >= roundID, "Invalid chainlink price" ); return (uint256(price) * (PRECISE_PRICE_PRECISION)) / (1e8); // ETH/USD is 8 decimals on Chainlink } function getTokenPrice( address token_address ) public view returns (uint256 precise_price, uint256 short_price, uint256 eth_price) { // Get the token info TokenInfo memory thisTokenInfo = token_info[token_address]; // Get the price for the underlying token (uint80 roundID, int256 price, , uint256 updatedAt, uint80 answeredInRound) = AggregatorV3Interface( thisTokenInfo.agg_addr_for_underlying ).latestRoundData(); require( price >= 0 && (updatedAt >= block.timestamp - maxDelayTime) && answeredInRound >= roundID, "Invalid chainlink price" ); uint256 agg_price = uint256(price); // Convert to USD, if not already if (thisTokenInfo.agg_other_side == 1) agg_price = (agg_price * getETHPricePrecise()) / PRECISE_PRICE_PRECISION; // cToken balance * pps = amt of underlying in native decimals uint256 price_per_share = 1; if (thisTokenInfo.underlying_tkn_address != address(0)) { address pps_address_to_use = thisTokenInfo.token_address; if (thisTokenInfo.pps_override_address != address(0)) { pps_address_to_use = thisTokenInfo.pps_override_address; } (bool success, bytes memory data) = (pps_address_to_use).staticcall( abi.encodeWithSelector(thisTokenInfo.pps_call_selector) ); require(success, "Oracle Failed"); price_per_share = abi.decode(data, (uint256)); } // E18 uint256 pps_multiplier = (uint256(10) ** (thisTokenInfo.pps_decimals)); // Handle difference in decimals() if (thisTokenInfo.ctkn_undrly_missing_decs < 0) { uint256 ctkn_undr_miss_dec_mult = (10 ** uint256(-1 * thisTokenInfo.ctkn_undrly_missing_decs)); precise_price = (agg_price * PRECISE_PRICE_PRECISION * price_per_share) / (ctkn_undr_miss_dec_mult * pps_multiplier * (uint256(10) ** (thisTokenInfo.agg_decimals))); } else { uint256 ctkn_undr_miss_dec_mult = (10 ** uint256(thisTokenInfo.ctkn_undrly_missing_decs)); precise_price = (agg_price * PRECISE_PRICE_PRECISION * price_per_share * ctkn_undr_miss_dec_mult) / (pps_multiplier * (uint256(10) ** (thisTokenInfo.agg_decimals))); } // E6 short_price = precise_price / PRICE_MISSING_MULTIPLIER; // ETH Price eth_price = (precise_price * PRECISE_PRICE_PRECISION) / getETHPricePrecise(); } // Return token price in ETH, multiplied by 2**112 function getETHPx112(address token_address) external view returns (uint256) { if (token_address == address(WETH) || token_address == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) { return uint256(2 ** 112); } require(maxDelayTime != 0, "Max delay time not set"); // Get the ETH Price PRECISE_PRICE_PRECISION (, , uint256 eth_price) = getTokenPrice(token_address); // Get the decimals uint256 decimals = uint256(ERC20(token_address).decimals()); // Scale to 2*112 // Also divide by the token decimals (needed for the math. Nothing to do with missing decimals or anything) return (eth_price * (2 ** 112)) / (10 ** decimals); } /* ========== RESTRICTED GOVERNANCE FUNCTIONS ========== */ function setTimelock(address _timelock_address) external onlyByOwnGov { timelock_address = _timelock_address; } function setMaxDelayTime(uint256 _maxDelayTime) external onlyByOwnGov { maxDelayTime = _maxDelayTime; } function batchSetOracleInfoDirect(TokenInfoConstructorArgs[] memory _initial_token_infos) external onlyByOwnGov { // Batch set token info for (uint256 i = 0; i < _initial_token_infos.length; i++) { TokenInfoConstructorArgs memory this_token_info = _initial_token_infos[i]; _setTokenInfo( this_token_info.token_address, this_token_info.agg_addr_for_underlying, this_token_info.agg_other_side, this_token_info.underlying_tkn_address, this_token_info.pps_override_address, this_token_info.pps_call_selector, this_token_info.pps_decimals ); } } // Sets oracle info for a token // Chainlink Addresses // https://docs.chain.link/docs/ethereum-addresses/ // exchangeRateStored: 0x182df0f5 // getPricePerFullShare: 0x77c7b8fc // get_virtual_price: 0xbb7b8b80 // getVirtualPrice: 0xe25aa5fa // pricePerShare: 0x99530b06 // lp_price: 0x54f0f7d5 // Function signature encoder // web3_data.eth.abi.encodeFunctionSignature({ // name: 'getVirtualPrice', // type: 'function', // inputs: [] // }) // web3_data.eth.abi.encodeFunctionSignature({ // name: 'myMethod', // type: 'function', // inputs: [{ // type: 'uint256', // name: 'myNumber' // }] // }) // To burn something, for example, type this on app.frax.finance's JS console // https://web3js.readthedocs.io/en/v1.2.11/web3-eth-abi.html#encodefunctioncall // web3_data.eth.abi.encodeFunctionCall({ // name: 'burn', // type: 'function', // inputs: [{ // type: 'uint256', // name: 'myNumber' // }] // }, ['100940878321208298244715']); function _setTokenInfo( address token_address, address agg_addr_for_underlying, uint256 agg_other_side, // 0: USD, 1: ETH address underlying_tkn_address, address pps_override_address, bytes4 pps_call_selector, uint256 pps_decimals ) internal { // require(token_address != address(0), "Cannot add zero address"); // See if there are any missing decimals between a cToken and the underlying int256 ctkn_undrly_missing_decs = 0; if (underlying_tkn_address != address(0)) { uint256 cToken_decs = ERC20(token_address).decimals(); uint256 underlying_decs = ERC20(underlying_tkn_address).decimals(); ctkn_undrly_missing_decs = int256(cToken_decs) - int256(underlying_decs); } // Add the token address to the array if it doesn't already exist bool token_exists = false; for (uint256 i = 0; i < all_token_addresses.length; i++) { if (all_token_addresses[i] == token_address) { token_exists = true; break; } } if (!token_exists) all_token_addresses.push(token_address); uint256 agg_decs = uint256(AggregatorV3Interface(agg_addr_for_underlying).decimals()); string memory name_to_use; if (token_address == address(0)) { name_to_use = native_token_symbol; } else { name_to_use = ERC20(token_address).name(); } // Add the token to the mapping token_info[token_address] = TokenInfo( token_address, ERC20(token_address).name(), agg_addr_for_underlying, agg_other_side, agg_decs, underlying_tkn_address, pps_override_address, pps_call_selector, pps_decimals, ctkn_undrly_missing_decs ); has_info[token_address] = true; } function setTokenInfo( address token_address, address agg_addr_for_underlying, uint256 agg_other_side, address underlying_tkn_address, address pps_override_address, bytes4 pps_call_selector, uint256 pps_decimals ) public onlyByOwnGov { _setTokenInfo( token_address, agg_addr_for_underlying, agg_other_side, underlying_tkn_address, pps_override_address, pps_call_selector, pps_decimals ); } } // File @uniswap/v3-core/contracts/interfaces/callback/[email protected] // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Callback for IUniswapV3PoolActions#swap /// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface interface IUniswapV3SwapCallback { /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. /// @dev In the implementation you must pay the pool tokens owed for the swap. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external; } // File contracts/Uniswap_V3/ISwapRouter.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later // Original pragma directive: pragma abicoder v2 /// @title Router token swapping functionality /// @notice Functions for swapping tokens via Uniswap V3 interface ISwapRouter is IUniswapV3SwapCallback { struct ExactInputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; uint160 sqrtPriceLimitX96; } /// @notice Swaps `amountIn` of one token for as much as possible of another token /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata /// @return amountOut The amount of the received token function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut); struct ExactInputParams { bytes path; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; } /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut); struct ExactOutputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; uint160 sqrtPriceLimitX96; } /// @notice Swaps as little as possible of one token for `amountOut` of another token /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata /// @return amountIn The amount of the input token function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); struct ExactOutputParams { bytes path; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; } /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata /// @return amountIn The amount of the input token function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn); } // File contracts/Uniswap_V3/IUniswapV3Factory.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title The interface for the Uniswap V3 Factory /// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees interface IUniswapV3Factory { /// @notice Emitted when the owner of the factory is changed /// @param oldOwner The owner before the owner was changed /// @param newOwner The owner after the owner was changed event OwnerChanged(address indexed oldOwner, address indexed newOwner); /// @notice Emitted when a pool is created /// @param token0 The first token of the pool by address sort order /// @param token1 The second token of the pool by address sort order /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @param tickSpacing The minimum number of ticks between initialized ticks /// @param pool The address of the created pool event PoolCreated( address indexed token0, address indexed token1, uint24 indexed fee, int24 tickSpacing, address pool ); /// @notice Emitted when a new fee amount is enabled for pool creation via the factory /// @param fee The enabled fee, denominated in hundredths of a bip /// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing); /// @notice Returns the current owner of the factory /// @dev Can be changed by the current owner via setOwner /// @return The address of the factory owner function owner() external view returns (address); /// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled /// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context /// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee /// @return The tick spacing function feeAmountTickSpacing(uint24 fee) external view returns (int24); /// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order /// @param tokenA The contract address of either token0 or token1 /// @param tokenB The contract address of the other token /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @return pool The pool address function getPool(address tokenA, address tokenB, uint24 fee) external view returns (address pool); /// @notice Creates a pool for the given two tokens and fee /// @param tokenA One of the two tokens in the desired pool /// @param tokenB The other of the two tokens in the desired pool /// @param fee The desired fee for the pool /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved /// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments /// are invalid. /// @return pool The address of the newly created pool function createPool(address tokenA, address tokenB, uint24 fee) external returns (address pool); /// @notice Updates the owner of the factory /// @dev Must be called by the current owner /// @param _owner The new owner of the factory function setOwner(address _owner) external; /// @notice Enables a fee amount with the given tickSpacing /// @dev Fee amounts may never be removed once enabled /// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6) /// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount function enableFeeAmount(uint24 fee, int24 tickSpacing) external; } // File contracts/Uniswap_V3/pool/IUniswapV3PoolActions.sol // Original license: SPDX_License_Identifier: MIT /// @title Permissionless pool actions /// @notice Contains pool methods that can be called by anyone interface IUniswapV3PoolActions { /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn(int24 tickLower, int24 tickUpper, uint128 amount) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash(address recipient, uint256 amount0, uint256 amount1, bytes calldata data) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; } // File contracts/Uniswap_V3/pool/IUniswapV3PoolDerivedState.sol // Original license: SPDX_License_Identifier: MIT /// @title Pool state that is not stored /// @notice Contains view functions to provide information about the pool that is computed rather than stored on the /// blockchain. The functions here may have variable gas costs. interface IUniswapV3PoolDerivedState { /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe( uint32[] calldata secondsAgos ) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside( int24 tickLower, int24 tickUpper ) external view returns (int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside); } // File contracts/Uniswap_V3/pool/IUniswapV3PoolEvents.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Events emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolEvents { /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); } // File contracts/Uniswap_V3/pool/IUniswapV3PoolImmutables.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Pool state that never changes /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values interface IUniswapV3PoolImmutables { /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); } // File contracts/Uniswap_V3/pool/IUniswapV3PoolOwnerActions.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the factory owner interface IUniswapV3PoolOwnerActions { /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); } // File contracts/Uniswap_V3/pool/IUniswapV3PoolState.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Pool state that can change /// @notice These methods compose the pool's state, and can change with any frequency including multiple times /// per transaction interface IUniswapV3PoolState { /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// observationIndex The index of the last oracle observation that was written, /// observationCardinality The current maximum number of observations stored in the pool, /// observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 token0, uint128 token1); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper, /// liquidityNet how much liquidity changes when the pool price crosses the tick, /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// secondsOutside the seconds spent on the other side of the tick from the current tick, /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks( int24 tick ) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return _liquidity The amount of liquidity in the position, /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions( bytes32 key ) external view returns ( uint128 _liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// Returns initialized whether the observation has been initialized and the values are safe to use function observations( uint256 index ) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); } // File contracts/Uniswap_V3/IUniswapV3Pool.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title The interface for a Uniswap V3 Pool /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IUniswapV3Pool is IUniswapV3PoolImmutables, IUniswapV3PoolState, IUniswapV3PoolDerivedState, IUniswapV3PoolActions, IUniswapV3PoolOwnerActions, IUniswapV3PoolEvents { } // File contracts/Uniswap_V3/libraries/FixedPoint96.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title FixedPoint96 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) /// @dev Used in SqrtPriceMath.sol library FixedPoint96 { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 0x1000000000000000000000000; } // File contracts/Uniswap_V3/libraries/FullMath.sol // Original license: SPDX_License_Identifier: MIT /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = (type(uint256).max - denominator + 1) & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the precoditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } } // File contracts/Uniswap_V3/libraries/LiquidityAmounts.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Liquidity amount functions /// @notice Provides functions for computing liquidity amounts from token amounts and prices library LiquidityAmounts { /// @notice Downcasts uint256 to uint128 /// @param x The uint258 to be downcasted /// @return y The passed value, downcasted to uint128 function toUint128(uint256 x) private pure returns (uint128 y) { require((y = uint128(x)) == x); } /// @notice Computes the amount of liquidity received for a given amount of token0 and price range /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount0 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount0( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount1 The amount1 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount1( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96)); } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount of token0 being sent in /// @param amount1 The amount of token1 being sent in /// @return liquidity The maximum amount of liquidity received function getLiquidityForAmounts( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0); } else if (sqrtRatioX96 < sqrtRatioBX96) { uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1); } } /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 function getAmount0ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 ) / sqrtRatioAX96; } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount1 The amount of token1 function getAmount1ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function getAmountsForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } } // File contracts/Uniswap_V3/libraries/TickMath.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMath { /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887_272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4_295_128_739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1_461_446_703_485_210_103_287_273_052_203_988_822_378_723_970_342; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); require(int256(absTick) <= int256(MAX_TICK), "T"); uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128; if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { // second inequality must be < because the price can never reach the price at the max tick require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, "R"); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; uint256 msb = 0; assembly { let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(5, gt(r, 0xFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(4, gt(r, 0xFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(3, gt(r, 0xFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(2, gt(r, 0xF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(1, gt(r, 0x3)) msb := or(msb, f) r := shr(f, r) } assembly { let f := gt(r, 0x1) msb := or(msb, f) } if (msb >= 128) r = ratio >> (msb - 127); else r = ratio << (127 - msb); int256 log_2 = (int256(msb) - 128) << 64; assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(63, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(62, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(61, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(60, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(59, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(58, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(57, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(56, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(55, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(54, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(53, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(52, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(51, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(50, f)) } int256 log_sqrt10001 = log_2 * 255_738_958_999_603_826_347_141; // 128.128 number int24 tickLow = int24((log_sqrt10001 - 3_402_992_956_809_132_418_596_140_100_660_247_210) >> 128); int24 tickHi = int24((log_sqrt10001 + 291_339_464_771_989_622_907_027_621_153_398_088_495) >> 128); tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } } // File contracts/Uniswap_V3/periphery/interfaces/IERC721Permit.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title ERC721 with permit /// @notice Extension to ERC721 that includes a permit function for signature based approvals interface IERC721Permit is IERC721 { /// @notice The permit typehash used in the permit signature /// @return The typehash for the permit function PERMIT_TYPEHASH() external pure returns (bytes32); /// @notice The domain separator used in the permit signature /// @return The domain seperator used in encoding of permit signature function DOMAIN_SEPARATOR() external view returns (bytes32); /// @notice Approve of a specific token ID for spending by spender via signature /// @param spender The account that is being approved /// @param tokenId The ID of the token that is being approved for spending /// @param deadline The deadline timestamp by which the call must be mined for the approve to work /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable; } // File contracts/Uniswap_V3/periphery/interfaces/IPeripheryImmutableState.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Immutable state /// @notice Functions that return immutable state of the router interface IPeripheryImmutableState { /// @return Returns the address of the Uniswap V3 factory function factory() external view returns (address); /// @return Returns the address of WETH9 function WETH9() external view returns (address); } // File contracts/Uniswap_V3/periphery/interfaces/IPeripheryPayments.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Periphery Payments /// @notice Functions to ease deposits and withdrawals of ETH interface IPeripheryPayments { /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH. /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. /// @param amountMinimum The minimum amount of WETH9 to unwrap /// @param recipient The address receiving ETH function unwrapWETH9(uint256 amountMinimum, address recipient) external payable; /// @notice Refunds any ETH balance held by this contract to the `msg.sender` /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps /// that use ether for the input amount function refundETH() external payable; /// @notice Transfers the full amount of a token held by this contract to recipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users /// @param token The contract address of the token which will be transferred to `recipient` /// @param amountMinimum The minimum amount of token required for a transfer /// @param recipient The destination address of the token function sweepToken(address token, uint256 amountMinimum, address recipient) external payable; } // File contracts/Uniswap_V3/periphery/interfaces/IPoolInitializer.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later // Original pragma directive: pragma abicoder v2 /// @title Creates and initializes V3 Pools /// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that /// require the pool to exist. interface IPoolInitializer { /// @notice Creates a new pool if it does not exist, then initializes if not initialized /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool /// @param token0 The contract address of token0 of the pool /// @param token1 The contract address of token1 of the pool /// @param fee The fee amount of the v3 pool for the specified token pair /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary function createAndInitializePoolIfNecessary( address token0, address token1, uint24 fee, uint160 sqrtPriceX96 ) external payable returns (address pool); } // File contracts/Uniswap_V3/periphery/libraries/PoolAddress.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee library PoolAddress { bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; /// @notice The identifying key of the pool struct PoolKey { address token0; address token1; uint24 fee; } /// @notice Returns PoolKey: the ordered tokens with the matched fee levels /// @param tokenA The first token of a pool, unsorted /// @param tokenB The second token of a pool, unsorted /// @param fee The fee level of the pool /// @return Poolkey The pool details with ordered token0 and token1 assignments function getPoolKey(address tokenA, address tokenB, uint24 fee) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({ token0: tokenA, token1: tokenB, fee: fee }); } /// @notice Deterministically computes the pool address given the factory and PoolKey /// @param factory The Uniswap V3 factory contract address /// @param key The PoolKey /// @return pool The contract address of the V3 pool function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { require(key.token0 < key.token1); pool = address( uint160( uint256( keccak256( abi.encodePacked( hex"ff", factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ) ); } } // File contracts/Uniswap_V3/periphery/interfaces/INonfungiblePositionManager.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later // Original pragma directive: pragma abicoder v2 /// @title Non-fungible token for positions /// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred /// and authorized. interface INonfungiblePositionManager is IPoolInitializer, IPeripheryPayments, IPeripheryImmutableState, IERC721Metadata, IERC721Enumerable, IERC721Permit { /// @notice Emitted when liquidity is increased for a position NFT /// @dev Also emitted when a token is minted /// @param tokenId The ID of the token for which liquidity was increased /// @param liquidity The amount by which liquidity for the NFT position was increased /// @param amount0 The amount of token0 that was paid for the increase in liquidity /// @param amount1 The amount of token1 that was paid for the increase in liquidity event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when liquidity is decreased for a position NFT /// @param tokenId The ID of the token for which liquidity was decreased /// @param liquidity The amount by which liquidity for the NFT position was decreased /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when tokens are collected for a position NFT /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior /// @param tokenId The ID of the token for which underlying tokens were collected /// @param recipient The address of the account that received the collected tokens /// @param amount0 The amount of token0 owed to the position that was collected /// @param amount1 The amount of token1 owed to the position that was collected event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1); /// @notice Returns the position information associated with a given token ID. /// @dev Throws if the token ID is not valid. /// @param tokenId The ID of the token that represents the position /// @return nonce The nonce for permits /// @return operator The address that is approved for spending /// @return token0 The address of the token0 for a specific pool /// @return token1 The address of the token1 for a specific pool /// @return fee The fee associated with the pool /// @return tickLower The lower end of the tick range for the position /// @return tickUpper The higher end of the tick range for the position /// @return liquidity The liquidity of the position /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation function positions( uint256 tokenId ) external view returns ( uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); struct MintParams { address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; } /// @notice Creates a new position wrapped in a NFT /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized /// a method does not exist, i.e. the pool is assumed to be initialized. /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata /// @return tokenId The ID of the token that represents the minted position /// @return liquidity The amount of liquidity for this position /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function mint( MintParams calldata params ) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); struct IncreaseLiquidityParams { uint256 tokenId; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` /// @param params tokenId The ID of the token for which liquidity is being increased, /// amount0Desired The desired amount of token0 to be spent, /// amount1Desired The desired amount of token1 to be spent, /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check, /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check, /// deadline The time by which the transaction must be included to effect the change /// @return liquidity The new liquidity amount as a result of the increase /// @return amount0 The amount of token0 to acheive resulting liquidity /// @return amount1 The amount of token1 to acheive resulting liquidity function increaseLiquidity( IncreaseLiquidityParams calldata params ) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1); struct DecreaseLiquidityParams { uint256 tokenId; uint128 liquidity; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Decreases the amount of liquidity in a position and accounts it to the position /// @param params tokenId The ID of the token for which liquidity is being decreased, /// amount The amount by which liquidity will be decreased, /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity, /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity, /// deadline The time by which the transaction must be included to effect the change /// @return amount0 The amount of token0 accounted to the position's tokens owed /// @return amount1 The amount of token1 accounted to the position's tokens owed function decreaseLiquidity( DecreaseLiquidityParams calldata params ) external payable returns (uint256 amount0, uint256 amount1); struct CollectParams { uint256 tokenId; address recipient; uint128 amount0Max; uint128 amount1Max; } /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient /// @param params tokenId The ID of the NFT for which tokens are being collected, /// recipient The account that should receive the tokens, /// amount0Max The maximum amount of token0 to collect, /// amount1Max The maximum amount of token1 to collect /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1); /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens /// must be collected first. /// @param tokenId The ID of the token that is being burned function burn(uint256 tokenId) external payable; } // File contracts/Uniswap/Interfaces/IUniswapV2Pair.sol // Original license: SPDX_License_Identifier: MIT interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint256); function balanceOf(address owner) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 value) external returns (bool); function transfer(address to, uint256 value) external returns (bool); function transferFrom(address from, address to, uint256 value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint256); function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; event Mint(address indexed sender, uint256 amount0, uint256 amount1); event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to); event Swap( address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint256); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint256); function price1CumulativeLast() external view returns (uint256); function kLast() external view returns (uint256); function mint(address to) external returns (uint256 liquidity); function burn(address to) external returns (uint256 amount0, uint256 amount1); function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; } // File contracts/Uniswap/Interfaces/IUniswapV2Router01.sol // Original license: SPDX_License_Identifier: MIT interface IUniswapV2Router01 { function factory() external returns (address); function WETH() external returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB, uint256 liquidity); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } // File contracts/Uniswap/Interfaces/IUniswapV2Router02.sol // Original license: SPDX_License_Identifier: MIT interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; } // File contracts/Oracle/ComboOracle_UniV2_UniV3.sol // Original license: SPDX_License_Identifier: MIT // ==================================================================== // | ______ _______ | // | / _____________ __ __ / ____(_____ ____ _____ ________ | // | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ | // | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ | // | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ | // | | // ==================================================================== // ===================== ComboOracle_UniV2_UniV3 ====================== // ==================================================================== // Aggregates prices for SLP, UniV2, and UniV3 style LP tokens // Frax Finance: https://github.com/FraxFinance // Primary Author(s) // Travis Moore: https://github.com/FortisFortuna // Reviewer(s) / Contributor(s) // Jason Huan: https://github.com/jasonhuan // Sam Kazemian: https://github.com/samkazemian // ComboOracle // UniV2 / SLP // UniV3 contract ComboOracle_UniV2_UniV3 is Owned { using SafeMath for uint256; using HomoraMath for uint256; /* ========== STATE VARIABLES ========== */ // Core addresses address timelock_address; address public frax_address; address public fxs_address; // Oracle info ComboOracle public combo_oracle; // UniV2 / SLP IUniswapV2Router02 public router; // UniV3 IUniswapV3Factory public univ3_factory; INonfungiblePositionManager public univ3_positions; ISwapRouter public univ3_router; // Precision uint256 public PRECISE_PRICE_PRECISION = 1e18; uint256 public PRICE_PRECISION = 1e6; uint256 public PRICE_MISSING_MULTIPLIER = 1e12; /* ========== STRUCTS ========== */ // ------------ UniV2 ------------ struct UniV2LPBasicInfo { address lp_address; string token_name; string token_symbol; address token0; address token1; uint256 token0_decimals; uint256 token1_decimals; uint256 token0_reserves; uint256 token1_reserves; uint256 lp_total_supply; } struct UniV2PriceInfo { uint256 precise_price; uint256 short_price; string token_symbol; string token_name; string token0_symbol; string token1_symbol; } // ------------ UniV3 ------------ struct UniV3NFTBasicInfo { address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint128 liquidity; uint256 token0_decimals; uint256 token1_decimals; uint256 lowest_decimals; } struct UniV3NFTValueInfo { uint256 token0_value; uint256 token1_value; uint256 total_value; string token0_symbol; string token1_symbol; uint256 liquidity_price; } /* ========== CONSTRUCTOR ========== */ constructor(address _owner_address, address[] memory _starting_addresses) Owned(_owner_address) { // Core addresses frax_address = _starting_addresses[0]; fxs_address = _starting_addresses[1]; // Oracle info combo_oracle = ComboOracle(_starting_addresses[2]); // UniV2 / SLP router = IUniswapV2Router02(_starting_addresses[3]); // UniV3 univ3_factory = IUniswapV3Factory(_starting_addresses[4]); univ3_positions = INonfungiblePositionManager(_starting_addresses[5]); univ3_router = ISwapRouter(_starting_addresses[6]); } /* ========== MODIFIERS ========== */ modifier onlyByOwnGov() { require( msg.sender == owner || msg.sender == timelock_address, "You are not an owner or the governance timelock" ); _; } /* ========== VIEWS ========== */ // UniV2 / SLP Info function uniV2LPBasicInfo(address pair_address) public view returns (UniV2LPBasicInfo memory) { // Instantiate the pair IUniswapV2Pair the_pair = IUniswapV2Pair(pair_address); // Get the reserves (uint256 reserve0, uint256 reserve1, ) = (the_pair.getReserves()); // Get the token1 address address token0 = the_pair.token0(); address token1 = the_pair.token1(); // Return return UniV2LPBasicInfo( pair_address, // [0] the_pair.name(), // [1] the_pair.symbol(), // [2] token0, // [3] token1, // [4] ERC20(token0).decimals(), // [5] ERC20(token1).decimals(), // [6] reserve0, // [7] reserve1, // [8] the_pair.totalSupply() // [9] ); } // UniV2 / SLP LP Token Price // Alpha Homora Fair LP Pricing Method (flash loan resistant) // https://cmichel.io/pricing-lp-tokens/ // https://blog.alphafinance.io/fair-lp-token-pricing/ // https://github.com/AlphaFinanceLab/alpha-homora-v2-contract/blob/master/contracts/oracle/UniswapV2Oracle.sol function uniV2LPPriceInfo(address lp_token_address) public view returns (UniV2PriceInfo memory) { // Get info about the LP token UniV2LPBasicInfo memory lp_basic_info = uniV2LPBasicInfo(lp_token_address); // Get the price of ETH in USD uint256 eth_price = combo_oracle.getETHPricePrecise(); // Alpha Homora method uint256 precise_price; { uint256 sqrtK = HomoraMath.sqrt(lp_basic_info.token0_reserves * lp_basic_info.token1_reserves).fdiv( lp_basic_info.lp_total_supply ); // in 2**112 uint256 px0 = combo_oracle.getETHPx112(lp_basic_info.token0); // in 2**112 uint256 px1 = combo_oracle.getETHPx112(lp_basic_info.token1); // in 2**112 // fair token0 amt: sqrtK * sqrt(px1/px0) // fair token1 amt: sqrtK * sqrt(px0/px1) // fair lp price = 2 * sqrt(px0 * px1) // split into 2 sqrts multiplication to prevent uint overflow (note the 2**112) // In ETH per unit of LP, multiplied by 2**112. uint256 precise_price_eth112 = (((sqrtK * 2 * HomoraMath.sqrt(px0)) / (2 ** 56)) * HomoraMath.sqrt(px1)) / (2 ** 56); // In USD // Split into 2 parts to avoid overflows uint256 precise_price56 = precise_price_eth112 / (2 ** 56); precise_price = (precise_price56 * eth_price) / (2 ** 56); } return UniV2PriceInfo( precise_price, // [0] precise_price / PRICE_MISSING_MULTIPLIER, // [1] lp_basic_info.token_symbol, // [2] lp_basic_info.token_name, // [3] ERC20(lp_basic_info.token0).symbol(), // [4] ERC20(lp_basic_info.token1).symbol() // [5] ); } // UniV2 / SLP LP Token Price // Reserves method function uniV2LPPriceInfoViaReserves(address lp_token_address) public view returns (UniV2PriceInfo memory) { // Get info about the LP token UniV2LPBasicInfo memory lp_basic_info = uniV2LPBasicInfo(lp_token_address); // Get the price of one of the tokens. Try token0 first. // After that, multiply the price by the reserves, then scale to E18 // Then multiply by 2 since both sides are equal dollar value // Then divide the the total number of LP tokens uint256 precise_price; if (combo_oracle.has_info(lp_basic_info.token0)) { (uint256 token_precise_price, , ) = combo_oracle.getTokenPrice(lp_basic_info.token0); // Multiply by 2 because each token is half of the TVL precise_price = (2 * token_precise_price * lp_basic_info.token0_reserves) / lp_basic_info.lp_total_supply; // Scale to E18 precise_price *= (10 ** (uint256(18) - lp_basic_info.token0_decimals)); } else { (uint256 token_precise_price, , ) = combo_oracle.getTokenPrice(lp_basic_info.token1); // Multiply by 2 because each token is half of the TVL precise_price = (2 * token_precise_price * lp_basic_info.token1_reserves) / lp_basic_info.lp_total_supply; // Scale to E18 precise_price *= (10 ** (uint256(18) - lp_basic_info.token1_decimals)); } return UniV2PriceInfo( precise_price, // [0] precise_price / PRICE_MISSING_MULTIPLIER, // [1] lp_basic_info.token_symbol, // [2] lp_basic_info.token_name, // [3] ERC20(lp_basic_info.token0).symbol(), // [4] ERC20(lp_basic_info.token1).symbol() // [5] ); } function getUniV3NFTBasicInfo(uint256 token_id) public view returns (UniV3NFTBasicInfo memory) { // Get the position information ( , , // [0] // [1] address token0, // [2] address token1, // [3] uint24 fee, // [4] int24 tickLower, // [5] int24 tickUpper, // [6] uint128 liquidity, // [7] // [8] // [9] // [10] // [11] , , , ) = univ3_positions.positions(token_id); // Get decimals uint256 tkn0_dec = ERC20(token0).decimals(); uint256 tkn1_dec = ERC20(token1).decimals(); return UniV3NFTBasicInfo( token0, // [0] token1, // [1] fee, // [2] tickLower, // [3] tickUpper, // [4] liquidity, // [5] tkn0_dec, // [6] tkn1_dec, // [7] (tkn0_dec < tkn1_dec) ? tkn0_dec : tkn1_dec // [8] ); } // Get stats about a particular UniV3 NFT function getUniV3NFTValueInfo(uint256 token_id) public view returns (UniV3NFTValueInfo memory) { UniV3NFTBasicInfo memory lp_basic_info = getUniV3NFTBasicInfo(token_id); // Get pool price info uint160 sqrtPriceX96; { address pool_address = univ3_factory.getPool(lp_basic_info.token0, lp_basic_info.token1, lp_basic_info.fee); IUniswapV3Pool the_pool = IUniswapV3Pool(pool_address); (sqrtPriceX96, , , , , , ) = the_pool.slot0(); } // Tick math uint256 token0_val_usd = 0; uint256 token1_val_usd = 0; { // Get the amount of each underlying token in each NFT uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(lp_basic_info.tickLower); uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(lp_basic_info.tickUpper); // Get amount of each token for 0.1% liquidity movement in each direction (1 per mille) uint256 liq_pricing_divisor = (10 ** lp_basic_info.lowest_decimals); (uint256 token0_1pm_amt, uint256 token1_1pm_amt) = LiquidityAmounts.getAmountsForLiquidity( sqrtPriceX96, sqrtRatioAX96, sqrtRatioBX96, uint128(lp_basic_info.liquidity / liq_pricing_divisor) ); // Get missing decimals uint256 token0_miss_dec_mult = 10 ** (uint256(18) - lp_basic_info.token0_decimals); uint256 token1_miss_dec_mult = 10 ** (uint256(18) - lp_basic_info.token1_decimals); // Get token prices // Will revert if ComboOracle doesn't have a price for both token0 and token1 (uint256 token0_precise_price, , ) = combo_oracle.getTokenPrice(lp_basic_info.token0); (uint256 token1_precise_price, , ) = combo_oracle.getTokenPrice(lp_basic_info.token1); // Get the value of each portion // Multiply by liq_pricing_divisor as well token0_val_usd = (token0_1pm_amt * liq_pricing_divisor * token0_precise_price * token0_miss_dec_mult) / PRECISE_PRICE_PRECISION; token1_val_usd = (token1_1pm_amt * liq_pricing_divisor * token1_precise_price * token1_miss_dec_mult) / PRECISE_PRICE_PRECISION; } // Return the total value of the UniV3 NFT uint256 nft_ttl_val = (token0_val_usd + token1_val_usd); // Return return UniV3NFTValueInfo( token0_val_usd, token1_val_usd, nft_ttl_val, ERC20(lp_basic_info.token0).symbol(), ERC20(lp_basic_info.token1).symbol(), (uint256(lp_basic_info.liquidity) * PRECISE_PRICE_PRECISION) / nft_ttl_val ); } /* ========== RESTRICTED GOVERNANCE FUNCTIONS ========== */ function setTimelock(address _timelock_address) external onlyByOwnGov { timelock_address = _timelock_address; } function setComboOracle(address _combo_oracle) external onlyByOwnGov { combo_oracle = ComboOracle(_combo_oracle); } function setUniV2Addrs(address _router) external onlyByOwnGov { // UniV2 / SLP router = IUniswapV2Router02(_router); } function setUniV3Addrs(address _factory, address _positions_nft_manager, address _router) external onlyByOwnGov { // UniV3 univ3_factory = IUniswapV3Factory(_factory); univ3_positions = INonfungiblePositionManager(_positions_nft_manager); univ3_router = ISwapRouter(_router); } } // File contracts/Staking/IFraxFarm.sol // Original license: SPDX_License_Identifier: MIT interface IFraxswap { function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function token0() external view returns (address); function token1() external view returns (address); } /// @notice Minimalistic IFraxFarmUniV3 interface IFraxFarmUniV3TokenPositions { function uni_token0() external view returns (address); function uni_token1() external view returns (address); } interface IFraxswapERC20 { function decimals() external view returns (uint8); } interface IFraxFarm { function owner() external view returns (address); function stakingToken() external view returns (address); function fraxPerLPToken() external view returns (uint256); function calcCurCombinedWeight( address account ) external view returns (uint256 old_combined_weight, uint256 new_vefxs_multiplier, uint256 new_combined_weight); function periodFinish() external view returns (uint256); function getAllRewardTokens() external view returns (address[] memory); function earned(address account) external view returns (uint256[] memory new_earned); function totalLiquidityLocked() external view returns (uint256); function lockedLiquidityOf(address account) external view returns (uint256); function totalCombinedWeight() external view returns (uint256); function combinedWeightOf(address account) external view returns (uint256); function lockMultiplier(uint256 secs) external view returns (uint256); function rewardRates(uint256 token_idx) external view returns (uint256 rwd_rate); function userStakedFrax(address account) external view returns (uint256); function proxyStakedFrax(address proxy_address) external view returns (uint256); function maxLPForMaxBoost(address account) external view returns (uint256); function minVeFXSForMaxBoost(address account) external view returns (uint256); function minVeFXSForMaxBoostProxy(address proxy_address) external view returns (uint256); function veFXSMultiplier(address account) external view returns (uint256 vefxs_multiplier); function toggleValidVeFXSProxy(address proxy_address) external; function proxyToggleStaker(address staker_address) external; function stakerSetVeFXSProxy(address proxy_address) external; function getReward(address destination_address) external returns (uint256[] memory); function getReward(address destination_address, bool also_claim_extra) external returns (uint256[] memory); function vefxs_max_multiplier() external view returns (uint256); function vefxs_boost_scale_factor() external view returns (uint256); function vefxs_per_frax_for_max_boost() external view returns (uint256); function getProxyFor(address addr) external view returns (address); function sync() external; function nominateNewOwner(address _owner) external; function acceptOwnership() external; function updateRewardAndBalance(address acct, bool sync) external; function setRewardVars( address reward_token_address, uint256 _new_rate, address _gauge_controller_address, address _rewards_distributor_address ) external; function calcCurrLockMultiplier( address account, uint256 stake_idx ) external view returns (uint256 midpoint_lock_multiplier); function staker_designated_proxies(address staker_address) external view returns (address); function sync_gauge_weights(bool andForce) external; } interface IFraxFarmTransfers { function setAllowance(address spender, uint256 lockId, uint256 amount) external; function removeAllowance(address spender, uint256 lockId) external; function setApprovalForAll(address spender, bool approved) external; function isApproved(address staker, uint256 lockId, uint256 amount) external view returns (bool); function transferLockedFrom( address sender_address, address receiver_address, uint256 sender_lock_index, uint256 transfer_amount, bool use_receiver_lock_index, uint256 receiver_lock_index ) external returns (uint256); function transferLocked( address receiver_address, uint256 sender_lock_index, uint256 transfer_amount, bool use_receiver_lock_index, uint256 receiver_lock_index ) external returns (uint256); function beforeLockTransfer( address operator, address from, uint256 lockId, bytes calldata data ) external returns (bytes4); function onLockReceived( address operator, address from, uint256 lockId, bytes memory data ) external returns (bytes4); } interface IFraxFarmERC20 is IFraxFarm, IFraxFarmTransfers { struct LockedStake { uint256 start_timestamp; uint256 liquidity; uint256 ending_timestamp; uint256 lock_multiplier; // 6 decimals of precision. 1x = 1000000 } /// TODO this references the public getter for `lockedStakes` in the contract function lockedStakes(address account, uint256 stake_idx) external view returns (LockedStake memory); function lockedStakesOf(address account) external view returns (LockedStake[] memory); function lockedStakesOfLength(address account) external view returns (uint256); function lockAdditional(uint256 lockId, uint256 addl_liq) external; function lockLonger(uint256 lockId, uint256 _newUnlockTimestamp) external; function stakeLocked(uint256 liquidity, uint256 secs) external returns (uint256); function withdrawLocked(uint256 lockId, address destination_address) external returns (uint256); } interface IFraxFarmUniV3 is IFraxFarm, IFraxFarmUniV3TokenPositions { struct LockedNFT { uint256 token_id; // for Uniswap V3 LPs uint256 liquidity; uint256 start_timestamp; uint256 ending_timestamp; uint256 lock_multiplier; // 6 decimals of precision. 1x = 1000000 int24 tick_lower; int24 tick_upper; } function acceptOwnership() external; function addMigrator(address migrator_address) external; function bypassEmissionFactor() external view returns (bool); function calcCurCombinedWeight( address account ) external view returns (uint256 old_combined_weight, uint256 new_vefxs_multiplier, uint256 new_combined_weight); function combinedWeightOf(address account) external view returns (uint256); function emissionFactor() external view returns (uint256 emission_factor); function getReward() external returns (uint256); function getRewardForDuration() external view returns (uint256); function greylistAddress(address _address) external; function ideal_tick() external view returns (int24); function initializeDefault() external; function lockMultiplier(uint256 secs) external view returns (uint256); function lock_max_multiplier() external view returns (uint256); function lock_time_for_max_multiplier() external view returns (uint256); function lock_time_min() external view returns (uint256); function lockedLiquidityOf(address account) external view returns (uint256); function lockedNFTsOf(address account) external view returns (LockedNFT[] memory); function migrationsOn() external view returns (bool); function migrator_stakeLocked_for( address staker_address, uint256 token_id, uint256 secs, uint256 start_timestamp ) external; function migrator_withdraw_locked(address staker_address, uint256 token_id) external; function minVeFXSForMaxBoost(address account) external view returns (uint256); function nominateNewOwner(address _owner) external; function nominatedOwner() external view returns (address); function onERC721Received(address, address, uint256, bytes memory) external pure returns (bytes4); function owner() external view returns (address); function recoverERC20(address tokenAddress, uint256 tokenAmount) external; function recoverERC721(address tokenAddress, uint256 token_id) external; function removeMigrator(address migrator_address) external; function rewardRate0() external view returns (uint256 rwd_rate); function reward_rate_manual() external view returns (uint256); function rewardsCollectionPaused() external view returns (bool); function rewardsDuration() external view returns (uint256); function setGaugeController(address _gauge_controller_address) external; function setLockedNFTTimeForMinAndMaxMultiplier( uint256 _lock_time_for_max_multiplier, uint256 _lock_time_min ) external; function setManualRewardRate(uint256 _reward_rate_manual, bool sync_too) external; function setMultipliers( uint256 _lock_max_multiplier, uint256 _vefxs_max_multiplier, uint256 _vefxs_per_frax_for_max_boost ) external; function setPauses(bool _stakingPaused, bool _withdrawalsPaused, bool _rewardsCollectionPaused) external; function setTWAP(uint32 _new_twap_duration) external; function setTimelock(address _new_timelock) external; function stakeLocked(uint256 token_id, uint256 secs) external; function stakerAllowMigrator(address migrator_address) external; function stakerDisallowMigrator(address migrator_address) external; function stakesUnlocked() external view returns (bool); function stakingPaused() external view returns (bool); function sync() external; function sync_gauge_weight(bool force_update) external; function timelock_address() external view returns (address); function toggleEmissionFactorBypass() external; function toggleMigrations() external; function totalCombinedWeight() external view returns (uint256); function totalLiquidityLocked() external view returns (uint256); function twap_duration() external view returns (uint32); function uni_required_fee() external view returns (uint24); function uni_tick_lower() external view returns (int24); function uni_tick_upper() external view returns (int24); function uni_token0() external view returns (address); function uni_token1() external view returns (address); function unlockStakes() external; function userStakedFrax(address account) external view returns (uint256); function veFXSMultiplier(address account) external view returns (uint256); function vefxs_max_multiplier() external view returns (uint256); function vefxs_per_frax_for_max_boost() external view returns (uint256); function withdrawLocked(uint256 token_id) external; function withdrawalsPaused() external view returns (bool); } // File contracts/Staking/IL1CrossDomainMessenger.sol // Original license: SPDX_License_Identifier: MIT interface IL1CrossDomainMessenger_1 { function MESSAGE_VERSION() external view returns (uint16); function MIN_GAS_CALLDATA_OVERHEAD() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR() external view returns (uint64); function OTHER_MESSENGER() external view returns (address); function PORTAL() external view returns (address); function RELAY_CALL_OVERHEAD() external view returns (uint64); function RELAY_CONSTANT_OVERHEAD() external view returns (uint64); function RELAY_GAS_CHECK_BUFFER() external view returns (uint64); function RELAY_RESERVED_GAS() external view returns (uint64); function baseGas(bytes memory _message, uint32 _minGasLimit) external pure returns (uint64); function failedMessages(bytes32) external view returns (bool); function initialize(address _superchainConfig) external; function messageNonce() external view returns (uint256); function paused() external view returns (bool); function portal() external view returns (address); function relayMessage( uint256 _nonce, address _sender, address _target, uint256 _value, uint256 _minGasLimit, bytes memory _message ) external; function sendMessage(address _target, bytes memory _message, uint32 _minGasLimit) external payable; function successfulMessages(bytes32) external view returns (bool); function superchainConfig() external view returns (address); function version() external view returns (string memory); function xDomainMessageSender() external view returns (address); } // File contracts/Staking/ICrossDomainMessenger.sol // Original license: SPDX_License_Identifier: MIT interface ICrossDomainMessenger_1 { function MESSAGE_VERSION() external view returns (uint16); function MIN_GAS_CALLDATA_OVERHEAD() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_DENOMINATOR() external view returns (uint64); function MIN_GAS_DYNAMIC_OVERHEAD_NUMERATOR() external view returns (uint64); function OTHER_MESSENGER() external view returns (address); function RELAY_CALL_OVERHEAD() external view returns (uint64); function RELAY_CONSTANT_OVERHEAD() external view returns (uint64); function RELAY_GAS_CHECK_BUFFER() external view returns (uint64); function RELAY_RESERVED_GAS() external view returns (uint64); function baseGas(bytes memory _message, uint32 _minGasLimit) external pure returns (uint64); function failedMessages(bytes32) external view returns (bool); function initialize() external; function l1CrossDomainMessenger() external view returns (address); function messageNonce() external view returns (uint256); function paused() external view returns (bool); function relayMessage( uint256 _nonce, address _sender, address _target, uint256 _value, uint256 _minGasLimit, bytes memory _message ) external; function sendMessage(address _target, bytes memory _message, uint32 _minGasLimit) external; function successfulMessages(bytes32) external view returns (bool); function version() external view returns (string memory); function xDomainMessageSender() external view returns (address); } // File contracts/Staking/IExponentialPriceOracle.sol // Original license: SPDX_License_Identifier: MIT interface IExponentialPriceOracle_1 { function getPrices() external view returns (bool _isBadData, uint256 _priceLow, uint256 _priceHigh); function priceEnd() external view returns (uint256); function pricePerShare() external view returns (uint256 _price); function priceStart() external view returns (uint256); function timeEnd() external view returns (uint256); function timeStart() external view returns (uint256); } // File contracts/Staking/OwnedV2.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later // https://docs.synthetix.io/contracts/Owned contract OwnedV2_0 { error OwnerCannotBeZero(); error InvalidOwnershipAcceptance(); error OnlyOwner(); address public owner; address public nominatedOwner; constructor(address _owner) { // require(_owner != address(0), "Owner address cannot be 0"); if (_owner == address(0)) revert OwnerCannotBeZero(); owner = _owner; emit OwnerChanged(address(0), _owner); } function nominateNewOwner(address _owner) external onlyOwner { nominatedOwner = _owner; emit OwnerNominated(_owner); } function acceptOwnership() external { // require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership"); if (msg.sender != nominatedOwner) revert InvalidOwnershipAcceptance(); emit OwnerChanged(owner, nominatedOwner); owner = nominatedOwner; nominatedOwner = address(0); } modifier onlyOwner() { // require(msg.sender == owner, "Only the contract owner may perform this action"); if (msg.sender != owner) revert OnlyOwner(); _; } event OwnerNominated(address newOwner); event OwnerChanged(address oldOwner, address newOwner); } // File contracts/Utils/ReentrancyGuard.sol // Original license: SPDX_License_Identifier: MIT /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard_1 { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being 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. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() internal { _status = _NOT_ENTERED; } /** * @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 make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } } // File contracts/Staking/L1QuitCreditorReceiverConverter.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later // ==================================================================== // | ______ _______ | // | / _____________ __ __ / ____(_____ ____ _____ ________ | // | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ | // | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ | // | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ | // | | // ==================================================================== // ================= L1QuitCreditorReceiverConverter ================== // ==================================================================== // Accepts an L1 message from a FraxFarmQuitCreditor_XXX and converts the provided USD value to another token // Frax Finance: https://github.com/FraxFinance // Primary Author(s) // Travis Moore: https://github.com/FortisFortuna // Reviewer(s) / Contributor(s) // Dennis: https://github.com/denett /// @notice Accepts an L1 message from a FraxFarmQuitCreditor_XXX and converts the provided USD value to another token contract L1QuitCreditorReceiverConverter_0 is ReentrancyGuard_1, OwnedV2_0 { // STATE VARIABLES // =================================================== /// @notice Fraxtal CrossDomainMessenger ICrossDomainMessenger_1 public messenger = ICrossDomainMessenger_1(0x4200000000000000000000000000000000000007); /// @notice Fraxtal CrossDomainMessenger address public quitCreditorAddress; /// @notice Token that the L1 USD credit is being exchanged for IERC20_1 public conversionToken; /// @notice How much conversion token to give for each 1e18 USD that was messaged over IExponentialPriceOracle_1 public conversionOracle; /// @notice Used for testing mapping(address pinger => Ping lastPing) public lastPingReceived; // STRUCTS // =================================================== /// @notice Ping used for testing purposes /// @param sourceTs Timestamp the ping was triggered on Ethereum /// @param fraxtalTs Timestamp the ping was received on this contract struct Ping { uint256 sourceTs; uint256 fraxtalTs; } // CONSTRUCTOR // =================================================== /// @notice Constructor /// @param _owner The owner of the contract /// @param _quitCreditor Address of the L1 FraxFarmQuitCreditor_XXX /// @param _conversionToken Token being converted to /// @param _conversionOracle Oracle for the price of the conversion token constructor( address _owner, address _quitCreditor, address _conversionToken, address _conversionOracle ) OwnedV2_0(_owner) { quitCreditorAddress = _quitCreditor; conversionToken = IERC20_1(_conversionToken); conversionOracle = IExponentialPriceOracle_1(_conversionOracle); } // PUBLIC FUNCTIONS // =================================================== /// @notice Used to test connectivity. Receives a dummy message from Ethereum function receivePing(uint256 _sourceTs) external nonReentrant { // Make sure that the caller on L1 was the FraxFarmQuitCreditor_XXX if (messenger.xDomainMessageSender() != quitCreditorAddress) revert BadXDomainMessageSender(); // Mark when the last ping was received lastPingReceived[messenger.xDomainMessageSender()] = Ping(_sourceTs, block.timestamp); } /// @notice Processes the L1-originating message from the FraxFarmQuitCreditor_XXX /// @param _originalStaker Address of the original farmer who held the position /// @param _recipient Recipient for the newly converted tokens /// @param _usdCredit The USD value that should be converted into the conversion token function processMessage( address _originalStaker, address _recipient, uint256 _usdCredit ) external nonReentrant returns (uint256 _convTknOut) { // Make sure that the caller on L1 was the FraxFarmQuitCreditor_XXX if (messenger.xDomainMessageSender() != quitCreditorAddress) revert BadXDomainMessageSender(); // Do the conversion _convTknOut = (_usdCredit * 1e18) / conversionOracle.pricePerShare(); // Send out the tokens SafeERC20_0.safeTransfer(conversionToken, _recipient, _convTknOut); emit MessageProcessed(_originalStaker, _recipient, _usdCredit, _convTknOut); } // RESTRICTED FUNCTIONS // =================================================== /// @notice Allows the owner to recover any ERC20 /// @param tokenAddress The address of the token to recover /// @param tokenAmount The amount of the token to recover function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner { SafeERC20_0.safeTransfer(IERC20_1(tokenAddress), msg.sender, tokenAmount); } /// @notice Set the IExponentialPriceOracle that has the conversion rate for the conversion token /// @param _newConversionOracle The new address for the IExponentialPriceOracle function setConversionOracle(address _newConversionOracle) external onlyOwner { conversionOracle = IExponentialPriceOracle_1(_newConversionOracle); } /// @notice Set the address for the L1 FraxFarmQuitCreditor_XXX /// @param _newQuitCreditorAddress The new address for the L1 FraxFarmQuitCreditor_XXX function setQuitCreditorAddress(address _newQuitCreditorAddress) external onlyOwner { quitCreditorAddress = _newQuitCreditorAddress; } // ERRORS // =================================================== /// @notice Only the FraxFarmQuitCreditor_XXX should be the messenger.xDomainMessageSender() error BadXDomainMessageSender(); // EVENTS // =================================================== /// @notice When the ping from L1 was received /// @param sender The msg.sender that triggered the ping on the FraxFarmQuitCreditor_XXX /// @param sourceTs Ethereum time the ping was received /// @param fraxtalTs Fraxtal time the ping was received event Pinged(address indexed sender, uint256 sourceTs, uint256 fraxtalTs); /// @notice When the crediting message from the L1 FraxFarmQuitCreditor_XXX was processed /// @param originalStaker Address of the original farmer who held the position /// @param recipient Recipient for the newly converted tokens /// @param usdCredit Amount of USD credit processed /// @param convTknOut Conversion token output amount to the recipient event MessageProcessed( address indexed originalStaker, address indexed recipient, uint256 usdCredit, uint256 convTknOut ); /// @notice When ERC20 tokens were recovered /// @param token Token address /// @param amount Amount of tokens collected event RecoveredERC20(address token, uint256 amount); } // File contracts/Staking/FraxFarmQuitCreditor_UniV3.sol // Original license: SPDX_License_Identifier: GPL-2.0-or-later // ==================================================================== // | ______ _______ | // | / _____________ __ __ / ____(_____ ____ _____ ________ | // | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ | // | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ | // | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ | // | | // ==================================================================== // =============== FraxFarmQuitCreditor_UniV3 =============== // ==================================================================== // Exits a Frax UniV3 farm and credits a USD value to a special contract on Fraxtal, which can be converted // there into another token, such as an FXB // Frax Finance: https://github.com/FraxFinance // Primary Author(s) // Travis Moore: https://github.com/FortisFortuna // Reviewer(s) / Contributor(s) // Dennis: https://github.com/denett /// @notice Exits a Frax UniV3 farm and credits a USD value to a special contract on Fraxtal, which can be converted there into another token, such as an FXB /// @dev Make sure to enable this contract as a migrator first on the target farm contract FraxFarmQuitCreditor_UniV3_0 is ReentrancyGuard_1, OwnedV2_0 { // STATE VARIABLES // =================================================== /// @notice The farm holding the UniV3 NFT IFraxFarmUniV3 public farm = IFraxFarmUniV3(0x3EF26504dbc8Dd7B7aa3E97Bc9f3813a9FC0B4B0); /// @notice FXS reward tokens IERC20_1 public fxsToken = IERC20_1(0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0); /// @notice Used for pricing UniV3 NFTs ComboOracle_UniV2_UniV3 public comboOracle = ComboOracle_UniV2_UniV3(0x1cBE07F3b3bf3BDe44d363cecAecfe9a98EC2dff); /// @notice On Fraxtal. Accepts a cross-chain message and converts the USD value to another specified token address public fxtlL1QuitCdRecCvtrAddr; /// @notice L1CrossDomainMessenger for sending messages to Fraxtal IL1CrossDomainMessenger_1 public l1CrossDomainMessenger = IL1CrossDomainMessenger_1(0x126bcc31Bc076B3d515f60FBC81FddE0B0d542Ed); /// @notice Minimum gas limit for the L1CrossDomainMessenger sendMessage uint32 public minGasLimit = 500_000; // CONSTRUCTOR // =================================================== /// @param _owner The owner of the contract /// @param _fxtlL1QuitCdRecCvtrAddr On Fraxtal. Accepts a cross-chain message and converts the USD value to another specified token constructor(address _owner, address _fxtlL1QuitCdRecCvtrAddr) OwnedV2_0(_owner) { fxtlL1QuitCdRecCvtrAddr = _fxtlL1QuitCdRecCvtrAddr; } // PUBLIC FUNCTIONS // =================================================== /// @notice Used to test connectivity. Sends a dummy message to Fraxtal function ping() external payable nonReentrant { // Send the message to Fraxtal via the L1CrossDomainMessenger l1CrossDomainMessenger.sendMessage{ value: msg.value }( fxtlL1QuitCdRecCvtrAddr, abi.encodeCall(L1QuitCreditorReceiverConverter_0.receivePing, (block.timestamp)), minGasLimit ); } /// @notice Exits all NFTs and sends a message to Fraxtal indicating how much FXB the user is entitled to /// @param _recipientOnFraxtal Recipient address on Fraxtal /// @return _totalLiquidity Sum total of all of the NFTs' liquidities /// @return _usdCredit The calculated USD value of the NFTs. Info will be "sent" to Fraxtal for conversion into a specified token there. function exitAllForCredit( address _recipientOnFraxtal ) external payable nonReentrant returns (uint256 _totalLiquidity, uint256 _usdCredit) { // Get all locked NFTs of the user IFraxFarmUniV3.LockedNFT[] memory lockedNFTs = farm.lockedNFTsOf(msg.sender); // Loop through the NFTs and withdraw them here for (uint256 i; i < lockedNFTs.length; i++) { uint256 _liquidity = lockedNFTs[i].liquidity; if (_liquidity > 0) { // Do the withdrawal farm.migrator_withdraw_locked(msg.sender, lockedNFTs[i].token_id); // Add the liquidity _totalLiquidity += _liquidity; // See what the USD value of the NFT is worth ComboOracle_UniV2_UniV3.UniV3NFTValueInfo memory _nftInfo = comboOracle.getUniV3NFTValueInfo( lockedNFTs[i].token_id ); // Add the USD value _usdCredit += _nftInfo.total_value; } } require(_totalLiquidity > 0, "Nothing to unlock"); // All reward tokens collected during the migration are sent to the user. SafeERC20_0.safeTransfer(fxsToken, msg.sender, fxsToken.balanceOf(address(this))); // Send the message to Fraxtal via the L1CrossDomainMessenger l1CrossDomainMessenger.sendMessage{ value: msg.value }( fxtlL1QuitCdRecCvtrAddr, abi.encodeCall( L1QuitCreditorReceiverConverter_0.processMessage, (msg.sender, _recipientOnFraxtal, _usdCredit) ), minGasLimit ); } // RESTRICTED FUNCTIONS // =================================================== /// @notice to indicate that this contract is ERC721 compatible function onERC721Received(address, address, uint256, bytes memory) public pure returns (bytes4) { return this.onERC721Received.selector; } /// @notice Allows the owner to recover any ERC20 /// @param tokenAddress The address of the token to recover /// @param tokenAmount The amount of the token to recover function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner { SafeERC20_0.safeTransfer(IERC20_1(tokenAddress), msg.sender, tokenAmount); } /// @notice Allows the owner to recover any ERC721 /// @param tokenAddress The address of the token to recover /// @param token_id The NFT id to recover function recoverERC721(address tokenAddress, uint256 token_id) external onlyOwner { // Only the owner address can ever receive the recovery withdrawal // INonfungiblePositionManager inherits IERC721 so the latter does not need to be imported INonfungiblePositionManager(tokenAddress).safeTransferFrom(address(this), owner, token_id); emit RecoveredERC721(tokenAddress, token_id); } /// @notice Set the address for the L1QuitCreditorReceiverConverter located on Fraxtal /// @param _newFxtlL1QuitCdRecCvtrAddr The new address for the L1QuitCreditorReceiverConverter function setFxtlL1QuitCdRecCvtrAddr(address _newFxtlL1QuitCdRecCvtrAddr) external onlyOwner { fxtlL1QuitCdRecCvtrAddr = _newFxtlL1QuitCdRecCvtrAddr; } /// @notice Set the min gas limit for the L1CrossDomainMessenger /// @param _minGasLimit Minimum gas limit function setXChainMinGasLimit(uint32 _minGasLimit) external onlyOwner { minGasLimit = _minGasLimit; } /* ========== EVENTS ========== */ event RecoveredERC20(address token, uint256 amount); event RecoveredERC721(address token, uint256 token_id); } // src/contracts/Miscellany/OwnedV2.sol // https://docs.synthetix.io/contracts/Owned contract OwnedV2_1 { error OwnerCannotBeZero(); error InvalidOwnershipAcceptance(); error OnlyOwner(); address public owner; address public nominatedOwner; constructor(address _owner) { // require(_owner != address(0), "Owner address cannot be 0"); if (_owner == address(0)) revert OwnerCannotBeZero(); owner = _owner; emit OwnerChanged(address(0), _owner); } function nominateNewOwner(address _owner) external onlyOwner { nominatedOwner = _owner; emit OwnerNominated(_owner); } function acceptOwnership() external { // require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership"); if (msg.sender != nominatedOwner) revert InvalidOwnershipAcceptance(); emit OwnerChanged(owner, nominatedOwner); owner = nominatedOwner; nominatedOwner = address(0); } modifier onlyOwner() { // require(msg.sender == owner, "Only the contract owner may perform this action"); if (msg.sender != owner) revert OnlyOwner(); _; } event OwnerNominated(address newOwner); event OwnerChanged(address oldOwner, address newOwner); } // node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20_0 { /** * @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); } // node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.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_1 { using Address_0 for address; function safeTransfer( IERC20_0 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20_0 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_0 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_0 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_0 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)); } } function safePermit( IERC20Permit_0 token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20_0 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"); } } } // src/contracts/Miscellany/FraxFarmQuitCreditor/L1QuitCreditorReceiverConverter.sol // ==================================================================== // | ______ _______ | // | / _____________ __ __ / ____(_____ ____ _____ ________ | // | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ | // | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ | // | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ | // | | // ==================================================================== // ================= L1QuitCreditorReceiverConverter ================== // ==================================================================== // Accepts an L1 message from an Ethereum Mainnet FraxFarmQuitCreditor_XXX and converts the provided USD value to another token // Frax Finance: https://github.com/FraxFinance // Primary Author(s) // Travis Moore: https://github.com/FortisFortuna // Reviewer(s) / Contributor(s) // Dennis: https://github.com/denett /// @notice Accepts an L1 message from an Ethereum Mainnet FraxFarmQuitCreditor_XXX and converts the provided USD value to another token contract L1QuitCreditorReceiverConverter_1 is ReentrancyGuard_0, OwnedV2_1 { // STATE VARIABLES // =================================================== /// @notice Fraxtal CrossDomainMessenger ICrossDomainMessenger_0 public messenger = ICrossDomainMessenger_0(0x4200000000000000000000000000000000000007); /// @notice Address of the L1 FraxFarmQuitCreditor_XXX address public quitCreditorAddress; /// @notice Token that the L1 USD credit is being exchanged for IERC20_0 public conversionToken; /// @notice Manually set conversion price (USDe18 per 1e18 conversion token) uint256 public conversionPrice; /// @notice Used for testing mapping(address pinger => Ping lastPing) public lastPingReceived; // STRUCTS // =================================================== /// @notice Ping used for testing purposes /// @param sourceTs Timestamp the ping was triggered on Ethereum /// @param fraxtalTs Timestamp the ping was received on this contract struct Ping { uint256 sourceTs; uint256 fraxtalTs; } // MODIFIERS // =================================================== modifier correctSender() { // Make sure the direct msg.sender is the messenger if (msg.sender != address(messenger)) revert BadSender(); // Make sure that the caller on L1 was the FraxFarmQuitCreditor_XXX if (messenger.xDomainMessageSender() != quitCreditorAddress) revert BadXDomainMessageSender(); _; } // CONSTRUCTOR // =================================================== /// @notice Constructor /// @param _owner The owner of the contract /// @param _quitCreditor Address of the L1 FraxFarmQuitCreditor_XXX /// @param _conversionToken Token being converted to /// @param _conversionPrice Price of the conversion token, in E18 USD constructor( address _owner, address _quitCreditor, address _conversionToken, uint256 _conversionPrice ) OwnedV2_1(_owner) { quitCreditorAddress = _quitCreditor; conversionToken = IERC20_0(_conversionToken); conversionPrice = _conversionPrice; } // PUBLIC FUNCTIONS // =================================================== /// @notice Used to test connectivity. Receives a dummy message from Ethereum /// @param _pinger Original pinger on Ethereum /// @param _sourceTs Time the ping was sent on Ethereum function receivePing(address _pinger, uint256 _sourceTs) external nonReentrant correctSender { // Mark when the last ping was received lastPingReceived[_pinger] = Ping(_sourceTs, block.timestamp); emit PingReceived(_pinger, _sourceTs, block.timestamp); } /// @notice Processes the L1-originating message from the FraxFarmQuitCreditor_XXX /// @param _originalStaker Address of the original farmer who held the position /// @param _recipient Recipient for the newly converted tokens /// @param _usdCredit The USD value that should be converted into the conversion token function processMessage( address _originalStaker, address _recipient, uint256 _usdCredit ) external nonReentrant correctSender returns (uint256 _convTknOut) { // Do the conversion _convTknOut = (_usdCredit * 1e18) / conversionPrice; // Send out the tokens SafeERC20_1.safeTransfer(conversionToken, _recipient, _convTknOut); emit MessageProcessed(_originalStaker, _recipient, _usdCredit, _convTknOut); } // RESTRICTED FUNCTIONS // =================================================== /// @notice Allows the owner to recover any ERC20 /// @param tokenAddress The address of the token to recover /// @param tokenAmount The amount of the token to recover function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner { SafeERC20_1.safeTransfer(IERC20_0(tokenAddress), msg.sender, tokenAmount); } /// @notice Set the price of the conversion token, in E18 USD /// @param _newConversionPrice The new conversion price function setConversionPrice(uint256 _newConversionPrice) external onlyOwner { conversionPrice = _newConversionPrice; } /// @notice Set the address for the L1 FraxFarmQuitCreditor_XXX /// @param _newQuitCreditorAddress The new address for the L1 FraxFarmQuitCreditor_XXX function setQuitCreditorAddress(address _newQuitCreditorAddress) external onlyOwner { quitCreditorAddress = _newQuitCreditorAddress; } // ERRORS // =================================================== /// @notice Only the CrossDomainMessenger should be the sender error BadSender(); /// @notice Only the FraxFarmQuitCreditor_XXX should be the messenger.xDomainMessageSender() error BadXDomainMessageSender(); // EVENTS // =================================================== /// @notice When the ping from L1 was received /// @param sender The msg.sender that triggered the ping on the FraxFarmQuitCreditor_XXX /// @param sourceTs Ethereum time the ping was received /// @param fraxtalTs Fraxtal time the ping was received event PingReceived(address indexed sender, uint256 sourceTs, uint256 fraxtalTs); /// @notice When the crediting message from the L1 FraxFarmQuitCreditor_XXX was processed /// @param originalStaker Address of the original farmer who held the position /// @param recipient Recipient for the newly converted tokens /// @param usdCredit Amount of USD credit processed /// @param convTknOut Conversion token output amount to the recipient event MessageProcessed( address indexed originalStaker, address indexed recipient, uint256 usdCredit, uint256 convTknOut ); /// @notice When ERC20 tokens were recovered /// @param token Token address /// @param amount Amount of tokens collected event RecoveredERC20(address token, uint256 amount); } // src/contracts/Miscellany/FraxFarmQuitCreditor/FraxFarmQuitCreditor_UniV3.sol // ==================================================================== // | ______ _______ | // | / _____________ __ __ / ____(_____ ____ _____ ________ | // | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ | // | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ | // | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ | // | | // ==================================================================== // ==================== FraxFarmQuitCreditor_UniV3 ==================== // ==================================================================== // Exits a Frax UniV3 farm and credits a USD value to a special contract on Fraxtal (L1QuitCreditorReceiverConverter), // which can be converted there into another token, such as an FXB // Frax Finance: https://github.com/FraxFinance // Primary Author(s) // Travis Moore: https://github.com/FortisFortuna // Reviewer(s) / Contributor(s) // Dennis: https://github.com/denett // Carter Carlson: https://github.com/pegahcarter // Thomas Clement: https://github.com/tom2o17 /// @notice Exits a Frax UniV3 farm and credits a USD value to a special contract on Fraxtal, which can be converted there into another token, such as an FXB /// @dev Make sure to enable this contract as a migrator first on the target farm contract FraxFarmQuitCreditor_UniV3_1 is ReentrancyGuard_0, OwnedV2_1 { // STATE VARIABLES // =================================================== /// @notice The farm holding the UniV3 NFT IFraxFarmUniV3 public farm; /// @notice The NFT INonfungiblePositionManager public nft = INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88); /// @notice token0 for the NFT IERC20Metadata public token0; /// @notice token1 for the NFT IERC20Metadata public token1; /// @notice token0 and token1 missing decimals away from 18. So FRAX would have 0, while USDC would have 12 uint256[2] public missingDecimals; /// @notice FXS reward tokens IERC20Metadata public fxsToken = IERC20Metadata(0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0); /// @notice On Fraxtal. Accepts a cross-chain message and converts the USD value to another specified token address public fxtlL1QuitCdRecCvtrAddr; /// @notice L1CrossDomainMessenger for sending messages to Fraxtal IL1CrossDomainMessenger_0 public l1CrossDomainMessenger = IL1CrossDomainMessenger_0(0x126bcc31Bc076B3d515f60FBC81FddE0B0d542Ed); /// @notice Minimum gas limit for the L1CrossDomainMessenger sendMessage uint32 public minGasLimit = 500_000; // CONSTRUCTOR // =================================================== /// @param _owner The owner of the contract /// @param _fxtlL1QuitCdRecCvtrAddr On Fraxtal. Accepts a cross-chain message and converts the USD value to another specified token /// @param _farm The address of the UniV3 farm. constructor(address _owner, address _fxtlL1QuitCdRecCvtrAddr, address _farm) OwnedV2_1(_owner) { fxtlL1QuitCdRecCvtrAddr = _fxtlL1QuitCdRecCvtrAddr; farm = IFraxFarmUniV3(_farm); token0 = IERC20Metadata(IFraxFarmUniV3(_farm).uni_token0()); token1 = IERC20Metadata(IFraxFarmUniV3(_farm).uni_token1()); // Check missing decimals missingDecimals[0] = 18 - token0.decimals(); missingDecimals[1] = 18 - token1.decimals(); } // INTERNAL // =================================================== /// @notice Internal logic for withdrawing and unwinding the NFT /// @param _tknId ID of the NFT /// @param _liquidity Liquidity of the NFT /// @return _tokensOutOne token0 fees, token1 fees, token0 principal, token1 principal respectively. Fees goes to the original farmer, principals to this QuitCreditor contract for later collection function _withdrawLogic(uint256 _tknId, uint256 _liquidity) internal returns (uint256[4] memory _tokensOutOne) { // Do the withdrawal farm.migrator_withdraw_locked(msg.sender, _tknId); // Prepare to collect token0 and token1 fees and send to the original staker INonfungiblePositionManager.CollectParams memory _collectParams = INonfungiblePositionManager.CollectParams( _tknId, msg.sender, type(uint128).max, type(uint128).max ); // Do the collection { // Collect fees (uint256 _fees0Out, uint256 fees1Out) = nft.collect(_collectParams); // Note the collected fees _tokensOutOne[0] += _fees0Out; _tokensOutOne[1] += fees1Out; } // Remove the principal { // Prepare to remove the principal INonfungiblePositionManager.DecreaseLiquidityParams memory _decLiqParams = INonfungiblePositionManager .DecreaseLiquidityParams( _tknId, uint128(_liquidity), 0, // If frontrun, it will be all $1 tokens anyways 0, // If frontrun, it will be all $1 tokens anyways block.timestamp + 604_800 ); // Decrease the liquidity (DOES NOT ACTUALLY TRANSFER OUT TOKEN0 AND TOKEN1 YET) (uint256 _principal0Out, uint256 _principal1Out) = nft.decreaseLiquidity(_decLiqParams); // Prepare to collect the principal _collectParams = INonfungiblePositionManager.CollectParams( _tknId, address(this), type(uint128).max, type(uint128).max ); // Do the collection nft.collect(_collectParams); // Note the collected principals. Will be kept in this contract for later recovery _tokensOutOne[2] += _principal0Out; _tokensOutOne[3] += _principal1Out; } // Burn the NFT nft.burn(_tknId); } /// @notice Exits NFTs and sends a message to Fraxtal indicating how much FXB the user is entitled to /// @param _recipientOnFraxtal Recipient address on Fraxtal /// @param _onlyExitOne If you are only exiting one NFT. Needed in case _nftId is legitimately 0 /// @param _nftId The single NFT Id to exit /// @return _totalLiquidity Sum total of all of the NFTs' liquidities /// @return _tokensOut FXS rewards, token0 fees, token1 fees, token0 principal, token1 principal respectively. Fees goes to the original farmer, principals to this QuitCreditor contract for later collection /// @return _usdCredit The calculated USD value of the NFTs. Info will be "sent" to Fraxtal for conversion into a specified token there. /// @return _encodedMessage Encoded message to send to the Fraxtal L1QuitCreditorReceiverConverter function _exitForCredit( address _recipientOnFraxtal, bool _onlyExitOne, uint256 _nftId ) internal nonReentrant returns ( uint256 _totalLiquidity, uint256[5] memory _tokensOut, uint256 _usdCredit, bytes memory _encodedMessage ) { // Check the recipient if (_recipientOnFraxtal == address(0)) revert InvalidRecipient(); // Get all locked NFTs of the sender IFraxFarmUniV3.LockedNFT[] memory lockedNFTs = farm.lockedNFTsOf(msg.sender); // Note FXS balance before uint256 _fxsBefore = fxsToken.balanceOf(address(this)); // Loop through the NFTs and withdraw them here for (uint256 i; i < lockedNFTs.length; ) { // Get token info uint256 _tknId = lockedNFTs[i].token_id; uint256 _liquidity = lockedNFTs[i].liquidity; // Proceed if there is liquidity if (_liquidity > 0) { if (_onlyExitOne && !(_tknId == _nftId)) { // Do nothing } else { // Withdraw one NFT uint256[4] memory _tokensOutOne = _withdrawLogic(_tknId, _liquidity); // Accounting _tokensOut[1] += _tokensOutOne[0]; _tokensOut[2] += _tokensOutOne[1]; _tokensOut[3] += _tokensOutOne[2]; _tokensOut[4] += _tokensOutOne[3]; // Tally the total liquidity _totalLiquidity += _liquidity; // Break if _onlyExitOne is true if (_onlyExitOne) break; } } unchecked { ++i; } } // Make sure there is something to actually unlock if (_totalLiquidity == 0) revert NothingToUnlock(); // Note the FXS balance change _tokensOut[0] = fxsToken.balanceOf(address(this)) - _fxsBefore; // Send the FXS rewards to the original staker SafeERC20_1.safeTransfer(fxsToken, msg.sender, _tokensOut[0]); // Assume token0 and token1 are both worth $1 per 1x10^(decimals) _usdCredit = (_tokensOut[3] * (10 ** missingDecimals[0])) + (_tokensOut[4] * (10 ** missingDecimals[1])); // Create the encoded message _encodedMessage = abi.encodeCall( L1QuitCreditorReceiverConverter_1.processMessage, (msg.sender, _recipientOnFraxtal, _usdCredit) ); // Send the message to Fraxtal via the L1CrossDomainMessenger l1CrossDomainMessenger.sendMessage(fxtlL1QuitCdRecCvtrAddr, _encodedMessage, minGasLimit); emit MessageSent(msg.sender, _recipientOnFraxtal, _usdCredit, _tokensOut); } // PUBLIC FUNCTIONS // =================================================== /// @notice Exits all NFTs and sends a message to Fraxtal indicating how much FXB the user is entitled to /// @param _recipientOnFraxtal Recipient address on Fraxtal /// @return _totalLiquidity Sum total of all of the NFTs' liquidities /// @return _tokensOut FXS rewards, token0 fees, token1 fees, token0 principal, token1 principal respectively. Fees goes to the original farmer, principals to this QuitCreditor contract for later collection /// @return _usdCredit The calculated USD value of the NFTs. Info will be "sent" to Fraxtal for conversion into a specified token there. /// @return _encodedMessage Encoded message to send to the Fraxtal L1QuitCreditorReceiverConverter function exitAllForCredit( address _recipientOnFraxtal ) external returns ( uint256 _totalLiquidity, uint256[5] memory _tokensOut, uint256 _usdCredit, bytes memory _encodedMessage ) { return _exitForCredit(_recipientOnFraxtal, false, 0); } /// @notice Exits a single NFT and sends a message to Fraxtal indicating how much FXB the user is entitled to /// @param _recipientOnFraxtal Recipient address on Fraxtal /// @param _nftId The NFT ID to exit /// @return _totalLiquidity Sum total of all of the NFTs' liquidities /// @return _tokensOut FXS rewards, token0 fees, token1 fees, token0 principal, token1 principal respectively. Fees goes to the original farmer, principals to this QuitCreditor contract for later collection /// @return _usdCredit The calculated USD value of the NFTs. Info will be "sent" to Fraxtal for conversion into a specified token there. /// @return _encodedMessage Encoded message to send to the Fraxtal L1QuitCreditorReceiverConverter function exitOneForCredit( address _recipientOnFraxtal, uint256 _nftId ) external returns ( uint256 _totalLiquidity, uint256[5] memory _tokensOut, uint256 _usdCredit, bytes memory _encodedMessage ) { return _exitForCredit(_recipientOnFraxtal, true, _nftId); } /// @notice to indicate that this contract is ERC721 compatible function onERC721Received(address, address, uint256, bytes memory) public pure returns (bytes4) { return this.onERC721Received.selector; } /// @notice Used to test connectivity. Sends a dummy message to Fraxtal function ping() external nonReentrant { // Send the message to Fraxtal via the L1CrossDomainMessenger l1CrossDomainMessenger.sendMessage( fxtlL1QuitCdRecCvtrAddr, abi.encodeCall(L1QuitCreditorReceiverConverter_1.receivePing, (msg.sender, block.timestamp)), minGasLimit ); emit PingSent(msg.sender, block.timestamp); } // RESTRICTED FUNCTIONS // =================================================== /// @notice Collect all token0 and token1 in the contract function collectAllTkn0AndTkn1() external onlyOwner returns (uint256[2] memory _tknsOut) { // Note balances _tknsOut[0] = token0.balanceOf(address(this)); _tknsOut[1] = token1.balanceOf(address(this)); // Send the tokens SafeERC20_1.safeTransfer(token0, msg.sender, _tknsOut[0]); SafeERC20_1.safeTransfer(token1, msg.sender, _tknsOut[1]); } /// @notice Allows the owner to recover any ERC20 /// @param tokenAddress The address of the token to recover /// @param tokenAmount The amount of the token to recover function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner { SafeERC20_1.safeTransfer(IERC20Metadata(tokenAddress), msg.sender, tokenAmount); } /// @notice Allows the owner to recover any ERC721 /// @param tokenAddress The address of the token to recover /// @param token_id The NFT id to recover function recoverERC721(address tokenAddress, uint256 token_id) external onlyOwner { // Only the owner address can ever receive the recovery withdrawal // INonfungiblePositionManager inherits IERC721 so the latter does not need to be imported INonfungiblePositionManager(tokenAddress).safeTransferFrom(address(this), owner, token_id); emit RecoveredERC721(tokenAddress, token_id); } /// @notice Set the address for the L1QuitCreditorReceiverConverter located on Fraxtal /// @param _newFxtlL1QuitCdRecCvtrAddr The new address for the L1QuitCreditorReceiverConverter function setFxtlL1QuitCdRecCvtrAddr(address _newFxtlL1QuitCdRecCvtrAddr) external onlyOwner { fxtlL1QuitCdRecCvtrAddr = _newFxtlL1QuitCdRecCvtrAddr; } /// @notice Set the min gas limit for the L1CrossDomainMessenger /// @param _minGasLimit Minimum gas limit function setXChainMinGasLimit(uint32 _minGasLimit) external onlyOwner { minGasLimit = _minGasLimit; } // ERRORS // =================================================== /// @notice When the Fraxtal recipient is invalid error InvalidRecipient(); /// @notice When there are no NFTs to unlock error NothingToUnlock(); // EVENTS // =================================================== /// @notice When the ping to L2 was sent /// @param sender The msg.sender that triggered the ping /// @param ts Time the ping was sent event PingSent(address indexed sender, uint256 ts); /// @notice When the crediting message to L2 was sent /// @param originalStaker Address of the original farmer who held the position /// @param recipient Recipient for the newly converted tokens /// @param usdCredit Amount of USD credit processed /// @param tokensOut FXS rewards, token0 fees, token1 fees, token0 principal, token1 principal respectively. Fees goes to the original farmer, principals to this QuitCreditor contract for later collection event MessageSent( address indexed originalStaker, address indexed recipient, uint256 usdCredit, uint256[5] tokensOut ); /// @notice When ERC20 tokens were recovered /// @param token Token address /// @param amount Amount of tokens collected event RecoveredERC20(address token, uint256 amount); /// @notice When ERC721 tokens were recovered /// @param tokenAddress NFT address /// @param tokenId ID of the recovered NFT event RecoveredERC721(address tokenAddress, uint256 tokenId); }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_fxtlL1QuitCdRecCvtrAddr","type":"address"},{"internalType":"address","name":"_farm","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidOwnershipAcceptance","type":"error"},{"inputs":[],"name":"InvalidRecipient","type":"error"},{"inputs":[],"name":"NothingToUnlock","type":"error"},{"inputs":[],"name":"OnlyOwner","type":"error"},{"inputs":[],"name":"OwnerCannotBeZero","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"originalStaker","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdCredit","type":"uint256"},{"indexed":false,"internalType":"uint256[5]","name":"tokensOut","type":"uint256[5]"}],"name":"MessageSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"ts","type":"uint256"}],"name":"PingSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RecoveredERC20","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"RecoveredERC721","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collectAllTkn0AndTkn1","outputs":[{"internalType":"uint256[2]","name":"_tknsOut","type":"uint256[2]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipientOnFraxtal","type":"address"}],"name":"exitAllForCredit","outputs":[{"internalType":"uint256","name":"_totalLiquidity","type":"uint256"},{"internalType":"uint256[5]","name":"_tokensOut","type":"uint256[5]"},{"internalType":"uint256","name":"_usdCredit","type":"uint256"},{"internalType":"bytes","name":"_encodedMessage","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipientOnFraxtal","type":"address"},{"internalType":"uint256","name":"_nftId","type":"uint256"}],"name":"exitOneForCredit","outputs":[{"internalType":"uint256","name":"_totalLiquidity","type":"uint256"},{"internalType":"uint256[5]","name":"_tokensOut","type":"uint256[5]"},{"internalType":"uint256","name":"_usdCredit","type":"uint256"},{"internalType":"bytes","name":"_encodedMessage","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"farm","outputs":[{"internalType":"contract IFraxFarmUniV3","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fxsToken","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fxtlL1QuitCdRecCvtrAddr","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"l1CrossDomainMessenger","outputs":[{"internalType":"contract IL1CrossDomainMessenger_0","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minGasLimit","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"missingDecimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nft","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ping","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"recoverERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"token_id","type":"uint256"}],"name":"recoverERC721","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newFxtlL1QuitCdRecCvtrAddr","type":"address"}],"name":"setFxtlL1QuitCdRecCvtrAddr","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_minGasLimit","type":"uint32"}],"name":"setXChainMinGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"contract IERC20Metadata","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
Deployed Bytecode
0x608060405234801561000f575f80fd5b5060043610610179575f3560e01c80635aeb4d77116100d25780638da5cb5b11610088578063ba770a7b11610063578063ba770a7b146103f4578063c1dba86414610409578063d21220a714610429575f80fd5b80638da5cb5b146103a1578063a7119869146103c1578063b16e8502146103e1575f80fd5b806379ba5097116100b857806379ba509714610373578063819d4cc61461037b5780638980f11f1461038e575f80fd5b80635aeb4d771461032e5780635c36b1861461036b575f80fd5b80631627540c1161013257806347ccca021161010d57806347ccca02146102db57806348c9d974146102fb57806353a47bb71461030e575f80fd5b80631627540c146102855780632e11b3b51461029857806336e9332d146102bb575f80fd5b80630dfe1681116101625780630dfe1681146101dc57806314d71c29146101fc578063150b7a021461021d575f80fd5b80630173c2561461017d57806309dacc0414610192575b5f80fd5b61019061018b366004611b62565b610449565b005b6009546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6005546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b61020f61020a366004611b85565b6104e9565b6040519081526020016101d3565b61025461022b366004611c69565b7f150b7a0200000000000000000000000000000000000000000000000000000000949350505050565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020016101d3565b610190610293366004611d45565b6104ff565b6102ab6102a6366004611d5e565b6105c9565b6040516101d39493929190611dfa565b6003546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b6004546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b6102ab610309366004611d45565b6105f1565b6002546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b600b546103569074010000000000000000000000000000000000000000900463ffffffff1681565b60405163ffffffff90911681526020016101d3565b610190610617565b6101906107fe565b610190610389366004611d5e565b6108f3565b61019061039c366004611d5e565b610a25565b6001546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b600b546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b6101906103ef366004611d45565b610a85565b6103fc610b1d565b6040516101d39190611e31565b600a546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b6006546101b29073ffffffffffffffffffffffffffffffffffffffff1681565b60015473ffffffffffffffffffffffffffffffffffffffff16331461049a576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600b805463ffffffff90921674010000000000000000000000000000000000000000027fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff909216919091179055565b600781600281106104f8575f80fd5b0154905081565b60015473ffffffffffffffffffffffffffffffffffffffff163314610550576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff83169081179091556040519081527f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce229060200160405180910390a150565b5f6105d2611b08565b5f60606105e186600187610cf1565b9299919850965090945092505050565b5f6105fa611b08565b5f6060610608855f80610cf1565b93509350935093509193509193565b60025f5403610687576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064015b60405180910390fd5b60025f55600b54600a5460405133602482015242604482015273ffffffffffffffffffffffffffffffffffffffff92831692633dbb202b921690606401604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fab219c4a00000000000000000000000000000000000000000000000000000000179052600b5490517fffffffff0000000000000000000000000000000000000000000000000000000060e086901b16815261079693929163ffffffff740100000000000000000000000000000000000000009091041690600401611e61565b5f604051808303815f87803b1580156107ad575f80fd5b505af11580156107bf573d5f803e3d5ffd5b50506040514281523392507fd5fd11568fef84379772ca0ede26f57178e76ab3f922db124b3ef166646a1b58915060200160405180910390a260015f55565b60025473ffffffffffffffffffffffffffffffffffffffff16331461084f576040517fd74b334e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001546002546040805173ffffffffffffffffffffffffffffffffffffffff93841681529290911660208301527fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c910160405180910390a160028054600180547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff841617909155169055565b60015473ffffffffffffffffffffffffffffffffffffffff163314610944576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001546040517f42842e0e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff918216602482015260448101839052908316906342842e0e906064015f604051808303815f87803b1580156109bb575f80fd5b505af11580156109cd573d5f803e3d5ffd5b50506040805173ffffffffffffffffffffffffffffffffffffffff86168152602081018590527f57519b6a0997d7d44511836bcee0a36871aa79d445816f6c464abb0cd9d3f3e8935001905060405180910390a15050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610a76576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a81823383611308565b5050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610ad6576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600a80547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b610b25611b26565b60015473ffffffffffffffffffffffffffffffffffffffff163314610b76576040517f5fc483c500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6005546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff909116906370a0823190602401602060405180830381865afa158015610be2573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c069190611ea5565b81526006546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff909116906370a0823190602401602060405180830381865afa158015610c74573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c989190611ea5565b6020820152600554610cc89073ffffffffffffffffffffffffffffffffffffffff1633835f5b6020020151611308565b600654610cee9073ffffffffffffffffffffffffffffffffffffffff1633836001610cbe565b90565b5f610cfa611b08565b5f606060025f5403610d68576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161067e565b60025f5573ffffffffffffffffffffffffffffffffffffffff8716610db9576040517f9c8d2cd200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003546040517f92ad41590000000000000000000000000000000000000000000000000000000081523360048201525f9173ffffffffffffffffffffffffffffffffffffffff16906392ad4159906024015f60405180830381865afa158015610e24573d5f803e3d5ffd5b505050506040513d5f823e601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201604052610e699190810190611efa565b6009546040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529192505f9173ffffffffffffffffffffffffffffffffffffffff909116906370a0823190602401602060405180830381865afa158015610eda573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610efe9190611ea5565b90505f5b8251811015610ffc575f838281518110610f1e57610f1e611ebc565b60200260200101515f015190505f848381518110610f3e57610f3e611ebc565b60200260200101516020015190505f811115610ff2578a8015610f615750898214155b610ff2575f610f70838361139a565b805160208b0180519293509091610f8890839061202f565b905250602081015160408a018051610fa190839061202f565b905250604081015160608a018051610fba90839061202f565b905250606081015160808a018051610fd390839061202f565b905250610fe0828b61202f565b99508b15610ff057505050610ffc565b505b5050600101610f02565b50855f03611036576040517f764c157f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6009546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152829173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa1580156110a2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110c69190611ea5565b6110d09190612048565b85526009546110f79073ffffffffffffffffffffffffffffffffffffffff1633875f610cbe565b60085461110590600a61217c565b60808601516111149190612187565b60075461112290600a61217c565b60608701516111319190612187565b61113b919061202f565b60405133602482015273ffffffffffffffffffffffffffffffffffffffff8b16604482015260648101829052909450608401604080518083037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe00181529181526020820180517fa7a53248000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff909116179052600b54600a5491517f3dbb202b00000000000000000000000000000000000000000000000000000000815292955073ffffffffffffffffffffffffffffffffffffffff80821693633dbb202b936112639392169188917401000000000000000000000000000000000000000090910463ffffffff1690600401611e61565b5f604051808303815f87803b15801561127a575f80fd5b505af115801561128c573d5f803e3d5ffd5b505050508873ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167e57f6120ad0cb6034e01af747c86402cc944df3a98b4d09b426a6feb18b6e6d86886040516112ee92919061219e565b60405180910390a3505060015f8190555093509350935093565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052611395908490611800565b505050565b6113a2611b44565b6003546040517f575959bf0000000000000000000000000000000000000000000000000000000081523360048201526024810185905273ffffffffffffffffffffffffffffffffffffffff9091169063575959bf906044015f604051808303815f87803b158015611411575f80fd5b505af1158015611423573d5f803e3d5ffd5b50506040805160808101825286815233602082019081526fffffffffffffffffffffffffffffffff828401818152606084018281526004805496517ffc6f7865000000000000000000000000000000000000000000000000000000008152865191810191909152935173ffffffffffffffffffffffffffffffffffffffff90811660248601529151831660448501525190911660648301529194505f93508392919091169063fc6f78659060840160408051808303815f875af11580156114ec573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061151091906121b2565b855191935091508290859061152690839061202f565b905250808460016020020181815161153e919061202f565b905250506040805160a0810182528681526fffffffffffffffffffffffffffffffff861660208201525f91810182905260608101829052909150608081016115894262093a8061202f565b905260048054604080517f0c49ccbe00000000000000000000000000000000000000000000000000000000815284519381019390935260208401516fffffffffffffffffffffffffffffffff166024840152830151604483015260608301516064830152608083015160848301529192505f91829173ffffffffffffffffffffffffffffffffffffffff90911690630c49ccbe9060a40160408051808303815f875af115801561163b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061165f91906121b2565b604080516080810182528a815230602082019081526fffffffffffffffffffffffffffffffff828401818152606084018281526004805496517ffc6f7865000000000000000000000000000000000000000000000000000000008152865191810191909152935173ffffffffffffffffffffffffffffffffffffffff9081166024860152915183166044850152519091166064830152919850939550919350169063fc6f78659060840160408051808303815f875af1158015611724573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061174891906121b2565b505060408501805183919061175e90839061202f565b9052508085600360200201818151611776919061202f565b90525050600480546040517f42966c6800000000000000000000000000000000000000000000000000000000815291820188905273ffffffffffffffffffffffffffffffffffffffff1692506342966c6891506024015f604051808303815f87803b1580156117e3575f80fd5b505af11580156117f5573d5f803e3d5ffd5b505050505092915050565b5f611861826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff1661190b9092919063ffffffff16565b805190915015611395578080602001905181019061187f91906121d4565b611395576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161067e565b606061191984845f85611923565b90505b9392505050565b6060824710156119b5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161067e565b73ffffffffffffffffffffffffffffffffffffffff85163b611a33576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161067e565b5f808673ffffffffffffffffffffffffffffffffffffffff168587604051611a5b91906121f3565b5f6040518083038185875af1925050503d805f8114611a95576040519150601f19603f3d011682016040523d82523d5f602084013e611a9a565b606091505b5091509150611aaa828286611ab5565b979650505050505050565b60608315611ac457508161191c565b825115611ad45782518084602001fd5b816040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067e9190612209565b6040518060a001604052806005906020820280368337509192915050565b60405180604001604052806002906020820280368337509192915050565b60405180608001604052806004906020820280368337509192915050565b5f60208284031215611b72575f80fd5b813563ffffffff8116811461191c575f80fd5b5f60208284031215611b95575f80fd5b5035919050565b803573ffffffffffffffffffffffffffffffffffffffff81168114611bbf575f80fd5b919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405160e0810167ffffffffffffffff81118282101715611c1457611c14611bc4565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715611c6157611c61611bc4565b604052919050565b5f805f8060808587031215611c7c575f80fd5b611c8585611b9c565b9350611c9360208601611b9c565b925060408501359150606085013567ffffffffffffffff811115611cb5575f80fd5b8501601f81018713611cc5575f80fd5b803567ffffffffffffffff811115611cdf57611cdf611bc4565b611d1060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601611c1a565b818152886020838501011115611d24575f80fd5b816020840160208301375f6020838301015280935050505092959194509250565b5f60208284031215611d55575f80fd5b61191c82611b9c565b5f8060408385031215611d6f575f80fd5b611d7883611b9c565b946020939093013593505050565b805f5b6005811015611da8578151845260209384019390910190600101611d89565b50505050565b5f81518084528060208401602086015e5f6020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b848152611e0a6020820185611d86565b8260c082015261010060e08201525f611e27610100830184611dae565b9695505050505050565b6040810181835f5b6002811015611e58578151835260209283019290910190600101611e39565b50505092915050565b73ffffffffffffffffffffffffffffffffffffffff84168152606060208201525f611e8f6060830185611dae565b905063ffffffff83166040830152949350505050565b5f60208284031215611eb5575f80fd5b5051919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b8051600281900b8114611bbf575f80fd5b5f60208284031215611f0a575f80fd5b815167ffffffffffffffff811115611f20575f80fd5b8201601f81018413611f30575f80fd5b805167ffffffffffffffff811115611f4a57611f4a611bc4565b611f5960208260051b01611c1a565b80828252602082019150602060e08402850101925086831115611f7a575f80fd5b6020840193505b82841015611e275760e08488031215611f98575f80fd5b611fa0611bf1565b8451815260208086015190820152604080860151908201526060808601519082015260808086015190820152611fd860a08601611ee9565b60a0820152611fe960c08601611ee9565b60c0820152825260e09390930192602090910190611f81565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b8082018082111561204257612042612002565b92915050565b8181038181111561204257612042612002565b6001815b60018411156120965780850481111561207a5761207a612002565b600184161561208857908102905b60019390931c92800261205f565b935093915050565b5f826120ac57506001612042565b816120b857505f612042565b81600181146120ce57600281146120d8576120f4565b6001915050612042565b60ff8411156120e9576120e9612002565b50506001821b612042565b5060208310610133831016604e8410600b8410161715612117575081810a612042565b6121427fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff848461205b565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0482111561217457612174612002565b029392505050565b5f61191c838361209e565b808202811582820484141761204257612042612002565b82815260c0810161191c6020830184611d86565b5f80604083850312156121c3575f80fd5b505080516020909101519092909150565b5f602082840312156121e4575f80fd5b8151801515811461191c575f80fd5b5f82518060208501845e5f920191825250919050565b602081525f61191c6020830184611dae56fea264697066735822122039dfd85842f5d82911842218eeb126fa8eb0ebd3f083c5521443fe47547ac8eb64736f6c634300081a0033
Deployed Bytecode Sourcemap
228569:15262:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;242129:115;;;;;;:::i;:::-;;:::i;:::-;;229297:91;;;;;;;;;;;;494:42:1;482:55;;;464:74;;452:2;437:18;229297:91:0;;;;;;;;228997:28;;;;;;;;;229220:33;;;;;;:::i;:::-;;:::i;:::-;;;926:25:1;;;914:2;899:18;229220:33:0;780:177:1;239470:152:0;;;;;;:::i;:::-;239584:30;239470:152;;;;;;;;;;3215:66:1;3203:79;;;3185:98;;3173:2;3158:18;239470:152:0;3041:248:1;213517:141:0;;;;;;:::i;:::-;;:::i;239013:380::-;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;:::i;228780:26::-;;;;;;;;;228840:112;;;;;;;;;237899:351;;;;;;:::i;:::-;;:::i;213227:29::-;;;;;;;;;229852:35;;;;;;;;;;;;;;;5879:10:1;5867:23;;;5849:42;;5837:2;5822:18;229852:35:0;5705:192:1;239707:399:0;;;:::i;213666:354::-;;;:::i;241218:422::-;;;;;;:::i;:::-;;:::i;240860:182::-;;;;;;:::i;:::-;;:::i;213200:20::-;;;;;;;;;229629:136;;;;;;;;;241840:164;;;;;;:::i;:::-;;:::i;240268:401::-;;;:::i;:::-;;;;;;;:::i;229510:38::-;;;;;;;;;229070:28;;;;;;;;;242129:115;214171:5;;;;214157:10;:19;214153:43;;214185:11;;;;;;;;;;;;;;214153:43;242210:11:::1;:26:::0;;::::1;::::0;;::::1;::::0;::::1;::::0;;;::::1;::::0;;;::::1;::::0;;242129:115::o;229220:33::-;;;;;;;;;;;;;;;-1:-1:-1;229220:33:0;:::o;213517:141::-;214171:5;;;;214157:10;:19;214153:43;;214185:11;;;;;;;;;;;;;;214153:43;213589:14:::1;:23:::0;;;::::1;;::::0;::::1;::::0;;::::1;::::0;;;213628:22:::1;::::0;464:74:1;;;213628:22:0::1;::::0;452:2:1;437:18;213628:22:0::1;;;;;;;213517:141:::0;:::o;239013:380::-;239159:23;239197:28;;:::i;:::-;239240:18;239273:28;239336:49;239351:19;239372:4;239378:6;239336:14;:49::i;:::-;239329:56;;;;-1:-1:-1;239329:56:0;-1:-1:-1;239329:56:0;;-1:-1:-1;239013:380:0;-1:-1:-1;;;239013:380:0:o;237899:351::-;238020:23;238058:28;;:::i;:::-;238101:18;238134:28;238197:45;238212:19;238233:5;238240:1;238197:14;:45::i;:::-;238190:52;;;;;;;;237899:351;;;;;:::o;239707:399::-;1868:1;2466:7;;:19;2458:63;;;;;;;6844:2:1;2458:63:0;;;6826:21:1;6883:2;6863:18;;;6856:30;6922:33;6902:18;;;6895:61;6973:18;;2458:63:0;;;;;;;;;1868:1;2599:7;:18;239827:22:::1;::::0;239876:23:::1;::::0;239914:92:::1;::::0;239977:10:::1;239914:92;::::0;::::1;7176:74:1::0;239989:15:0::1;7266:18:1::0;;;7259:34;239827:22:0::1;::::0;;::::1;::::0;:34:::1;::::0;239876:23:::1;::::0;7149:18:1;;239914:92:0::1;::::0;;;;;::::1;::::0;;;;;;::::1;::::0;::::1;::::0;;::::1;;::::0;::::1;::::0;;240021:11:::1;::::0;239827:216;;;239914:92:::1;239827:216:::0;;;;;;::::1;::::0;;239914:92;240021:11:::1;::::0;;;::::1;;::::0;239827:216:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;240061:37:0::1;::::0;240082:15:::1;926:25:1::0;;240070:10:0::1;::::0;-1:-1:-1;240061:37:0::1;::::0;-1:-1:-1;914:2:1;899:18;240061:37:0::1;;;;;;;1824:1:::0;2778:7;:22;239707:399::o;213666:354::-;213839:14;;;;213825:10;:28;213821:69;;213862:28;;;;;;;;;;;;;;213821:69;213919:5;;213926:14;;213906:35;;;213919:5;;;;7906:74:1;;213926:14:0;;;;8011:2:1;7996:18;;7989:83;213906:35:0;;7879:18:1;213906:35:0;;;;;;;213960:14;;;;213952:22;;;;;;213960:14;;;213952:22;;;;213985:27;;;213666:354::o;241218:422::-;214171:5;;;;214157:10;:19;214153:43;;214185:11;;;;;;;;;;;;;;214153:43;241561:5:::1;::::0;241487:90:::1;::::0;;;;241554:4:::1;241487:90;::::0;::::1;8285:74:1::0;241487:58:0::1;241561:5:::0;;::::1;8375:18:1::0;;;8368:83;8467:18;;;8460:34;;;241487:58:0;;::::1;::::0;::::1;::::0;8258:18:1;;241487:90:0::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;241593:39:0::1;::::0;;7206:42:1;7194:55;;7176:74;;7281:2;7266:18;;7259:34;;;241593:39:0::1;::::0;-1:-1:-1;7149:18:1;;-1:-1:-1;241593:39:0::1;;;;;;;241218:422:::0;;:::o;240860:182::-;214171:5;;;;214157:10;:19;214153:43;;214185:11;;;;;;;;;;;;;;214153:43;240955:79:::1;240995:12;241010:10;241022:11;240955:24;:79::i;:::-;240860:182:::0;;:::o;241840:164::-;214171:5;;;;214157:10;:19;214153:43;;214185:11;;;;;;;;;;;;;;214153:43;241943:23:::1;:53:::0;;;::::1;;::::0;;;::::1;::::0;;;::::1;::::0;;241840:164::o;240268:401::-;240329:26;;:::i;:::-;214171:5;;;;214157:10;:19;214153:43;;214185:11;;;;;;;;;;;;;;214153:43;240408:6:::1;::::0;:31:::1;::::0;;;;240433:4:::1;240408:31;::::0;::::1;464:74:1::0;240408:6:0::1;::::0;;::::1;::::0;:16:::1;::::0;437:18:1;;240408:31:0::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;240394:45:::0;;240464:6:::1;::::0;:31:::1;::::0;;;;240489:4:::1;240464:31;::::0;::::1;464:74:1::0;240464:6:0::1;::::0;;::::1;::::0;:16:::1;::::0;437:18:1;;240464:31:0::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;240450:11;::::0;::::1;:45:::0;240561:6:::1;::::0;240536:57:::1;::::0;240561:6:::1;;240569:10;240450:8:::0;240561:6:::1;240581:11;;;;;240536:24;:57::i;:::-;240629:6;::::0;240604:57:::1;::::0;240629:6:::1;;240637:10;240649:8:::0;240629:6;240649:11:::1;::::0;240604:57:::1;240268:401:::0;:::o;234185:2910::-;234379:23;234417:28;;:::i;:::-;234460:18;234493:28;1868:1;2466:7;;:19;2458:63;;;;;;;6844:2:1;2458:63:0;;;6826:21:1;6883:2;6863:18;;;6856:30;6922:33;6902:18;;;6895:61;6973:18;;2458:63:0;6642:355:1;2458:63:0;1868:1;2599:7;:18;234585:33:::1;::::0;::::1;234581:64;;234627:18;;;;;;;;;;;;;;234581:64;234751:4;::::0;:29:::1;::::0;;;;234769:10:::1;234751:29;::::0;::::1;464:74:1::0;234704:44:0::1;::::0;234751:4:::1;;::::0;:17:::1;::::0;437:18:1;;234751:29:0::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;::::0;;::::1;::::0;::::1;::::0;::::1;;::::0;::::1;::::0;;;::::1;::::0;::::1;:::i;:::-;234850:8;::::0;:33:::1;::::0;;;;234877:4:::1;234850:33;::::0;::::1;464:74:1::0;234704:76:0;;-1:-1:-1;234829:18:0::1;::::0;234850:8:::1;::::0;;::::1;::::0;:18:::1;::::0;437::1;;234850:33:0::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;234829:54;;234958:9;234953:1098;234973:10;:17;234969:1;:21;234953:1098;;;235040:14;235057:10;235068:1;235057:13;;;;;;;;:::i;:::-;;;;;;;:22;;;235040:39;;235094:18;235115:10;235126:1;235115:13;;;;;;;;:::i;:::-;;;;;;;:23;;;235094:44;;235218:1;235205:10;:14;235201:775;;;235244:12;:35;;;;;235272:6;235262;:16;235260:19;235244:35;235240:721;;235406:31;235440:34;235455:6;235463:10;235440:14;:34::i;:::-;235551:16:::0;;::::1;235534:13:::0;::::1;:33:::0;;235406:68;;-1:-1:-1;235551:16:0;;235534:33:::1;::::0;235551:16;;235534:33:::1;:::i;:::-;::::0;;-1:-1:-1;235607:16:0::1;::::0;::::1;::::0;235590:13;;::::1;:33:::0;;::::1;::::0;235607:16;;235590:33:::1;:::i;:::-;::::0;;-1:-1:-1;235663:16:0;;::::1;::::0;235646:13;;::::1;:33:::0;;::::1;::::0;235663:16;;235646:33:::1;:::i;:::-;::::0;;-1:-1:-1;235719:16:0;;::::1;::::0;235702:13;;::::1;:33:::0;;::::1;::::0;235719:16;;235702:33:::1;:::i;:::-;::::0;;-1:-1:-1;235810:29:0::1;235829:10:::0;235810:29;::::1;:::i;:::-;;;235922:12;235918:23;;;235936:5;;;;;235918:23;235342:619;235240:721;-1:-1:-1::0;;236021:3:0::1;;234953:1098;;;;236127:15;236146:1;236127:20:::0;236123:50:::1;;236156:17;;;;;;;;;;;;;;236123:50;236242:8;::::0;:33:::1;::::0;;;;236269:4:::1;236242:33;::::0;::::1;464:74:1::0;236278:10:0;;236242:8:::1;;::::0;:18:::1;::::0;437::1;;236242:33:0::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:46;;;;:::i;:::-;236226:62:::0;;236382:8:::1;::::0;236357:61:::1;::::0;236382:8:::1;;236392:10;236226::::0;236237:1:::1;236404:13;::::0;236357:61:::1;236590:18:::0;;236584:24:::1;::::0;:2:::1;:24;:::i;:::-;236567:13:::0;;::::1;::::0;:42:::1;::::0;;::::1;:::i;:::-;236543:15;:18:::0;236537:24:::1;::::0;:2:::1;:24;:::i;:::-;236520:13:::0;;::::1;::::0;:42:::1;::::0;;::::1;:::i;:::-;236519:91;;;;:::i;:::-;236680:148;::::0;236773:10:::1;236680:148;::::0;::::1;8285:74:1::0;8315:42;8395:55;;8375:18;;;8368:83;8467:18;;;8460:34;;;236506:104:0;;-1:-1:-1;8258:18:1;;236680:148:0::1;::::0;;;;::::1;::::0;;;;;;;::::1;::::0;::::1;::::0;;;::::1;::::0;;::::1;;::::0;;236912:22:::1;::::0;236947:23:::1;::::0;236912:89;;;;;236680:148;;-1:-1:-1;236912:22:0::1;::::0;;::::1;::::0;:34:::1;::::0;:89:::1;::::0;236947:23;::::1;::::0;236680:148;;236989:11;;;::::1;;;::::0;236912:89:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;237043:19;237019:68;;237031:10;237019:68;;;237064:10;237076;237019:68;;;;;;;:::i;:::-;;;;;;;;234538:2557;;1824:1:::0;2778:7;:22;;;;234185:2910;;;;;;;:::o;215734:213::-;215880:58;;;7206:42:1;7194:55;;215880:58:0;;;7176:74:1;7266:18;;;;7259:34;;;215880:58:0;;;;;;;;;;7149:18:1;;;;215880:58:0;;;;;;;;;;215903:23;215880:58;;;215853:86;;215873:5;;215853:19;:86::i;:::-;215734:213;;;:::o;231149:2172::-;231227:31;;:::i;:::-;231301:4;;:49;;;;;231331:10;231301:49;;;7176:74:1;7266:18;;;7259:34;;;231301:4:0;;;;;:29;;7149:18:1;;231301:49:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;231515:162:0;;;;;;;;;;;231592:10;231515:162;;;;;;231617:17;231515:162;;;;;;;;;;;;231804:3;;;:27;;;;;13593:13:1;;231804:27:0;;;13575:32:1;;;;13649:24;;231515:162:0;13645:73:1;;;13623:20;;;13616:103;13761:24;;13757:65;;13735:20;;;13728:95;13865:24;13861:65;;;13839:20;;;13832:95;231515:162:0;;-1:-1:-1;;;;;;231804:3:0;;;;;:11;;13547:19:1;;231804:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;231888:29;;231764:67;;-1:-1:-1;231764:67:0;-1:-1:-1;231764:67:0;;231888:13;;:29;;231764:67;;231888:29;:::i;:::-;;;-1:-1:-1;231952:8:0;231932:13;231946:1;231932:16;;;:28;;;;;;;:::i;:::-;;;-1:-1:-1;;232155:353:0;;;;;;;;;;;;;;;;;;232080:72;232155:353;;;;;;;;;;;;232080:72;;-1:-1:-1;232155:353:0;;;232464:25;:15;232482:7;232464:25;:::i;:::-;232155:353;;232670:3;;;:36;;;;;;14533:13:1;;232670:36:0;;;14515:32:1;;;;14607:4;14595:17;;14589:24;14615:34;14585:65;14563:20;;;14556:95;14695:17;;14689:24;14667:20;;;14660:54;14770:4;14758:17;;14752:24;14730:20;;;14723:54;14833:4;14821:17;;14815:24;14793:20;;;14786:54;232080:428:0;;-1:-1:-1;232620:22:0;;;;232670:3;;;;;:21;;14487:19:1;;232670:36:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;232789:185;;;;;;;;;;;232882:4;232789:185;;;;;;232906:17;232789:185;;;;;;;;;;;;233025:3;;;:27;;;;;13593:13:1;;233025:27:0;;;13575:32:1;;;;13649:24;;232789:185:0;13645:73:1;;;13623:20;;;13616:103;13761:24;;13757:65;;13735:20;;;13728:95;13865:24;13861:65;;;13839:20;;;13832:95;232789:185:0;;-1:-1:-1;232619:87:0;;-1:-1:-1;232619:87:0;;-1:-1:-1;233025:3:0;;:11;;13547:19:1;;233025:27:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1;;233165:16:0;;;:34;;233185:14;;233165:16;:34;;233185:14;;233165:34;:::i;:::-;;;-1:-1:-1;233234:14:0;233214:13;233228:1;233214:16;;;:34;;;;;;;:::i;:::-;;;-1:-1:-1;;233297:3:0;;;:16;;;;;;;;926:25:1;;;233297:3:0;;;-1:-1:-1;233297:8:0;;-1:-1:-1;899:18:1;;233297:16:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;231260:2061;231149:2172;;;;:::o;218813:718::-;219239:23;219265:69;219293:4;219265:69;;;;;;;;;;;;;;;;;219273:5;219265:27;;;;:69;;;;;:::i;:::-;219349:17;;219239:95;;-1:-1:-1;219349:21:0;219345:179;;219446:10;219435:30;;;;;;;;;;;;:::i;:::-;219427:85;;;;;;;15335:2:1;219427:85:0;;;15317:21:1;15374:2;15354:18;;;15347:30;15413:34;15393:18;;;15386:62;15484:12;15464:18;;;15457:40;15514:19;;219427:85:0;15133:406:1;11977:229:0;12114:12;12146:52;12168:6;12176:4;12182:1;12185:12;12146:21;:52::i;:::-;12139:59;;11977:229;;;;;;:::o;13097:510::-;13267:12;13325:5;13300:21;:30;;13292:81;;;;;;;15746:2:1;13292:81:0;;;15728:21:1;15785:2;15765:18;;;15758:30;15824:34;15804:18;;;15797:62;15895:8;15875:18;;;15868:36;15921:19;;13292:81:0;15544:402:1;13292:81:0;9527:19;;;;13384:60;;;;;;;16153:2:1;13384:60:0;;;16135:21:1;16192:2;16172:18;;;16165:30;16231:31;16211:18;;;16204:59;16280:18;;13384:60:0;15951:353:1;13384:60:0;13458:12;13472:23;13499:6;:11;;13518:5;13525:4;13499:31;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;13457:73;;;;13548:51;13565:7;13574:10;13586:12;13548:16;:51::i;:::-;13541:58;13097:510;-1:-1:-1;;;;;;;13097:510:0:o;15783:762::-;15933:12;15962:7;15958:580;;;-1:-1:-1;15993:10:0;15986:17;;15958:580;16107:17;;:21;16103:424;;16355:10;16349:17;16416:15;16403:10;16399:2;16395:19;16388:44;16103:424;16498:12;16491:20;;;;;;;;;;;:::i;-1:-1:-1:-;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;14:276:1:-;72:6;125:2;113:9;104:7;100:23;96:32;93:52;;;141:1;138;131:12;93:52;180:9;167:23;230:10;223:5;219:22;212:5;209:33;199:61;;256:1;253;246:12;549:226;608:6;661:2;649:9;640:7;636:23;632:32;629:52;;;677:1;674;667:12;629:52;-1:-1:-1;722:23:1;;549:226;-1:-1:-1;549:226:1:o;962:196::-;1030:20;;1090:42;1079:54;;1069:65;;1059:93;;1148:1;1145;1138:12;1059:93;962:196;;;:::o;1163:184::-;1215:77;1212:1;1205:88;1312:4;1309:1;1302:15;1336:4;1333:1;1326:15;1352:253;1424:2;1418:9;1466:4;1454:17;;1501:18;1486:34;;1522:22;;;1483:62;1480:88;;;1548:18;;:::i;:::-;1584:2;1577:22;1352:253;:::o;1610:334::-;1681:2;1675:9;1737:2;1727:13;;1742:66;1723:86;1711:99;;1840:18;1825:34;;1861:22;;;1822:62;1819:88;;;1887:18;;:::i;:::-;1923:2;1916:22;1610:334;;-1:-1:-1;1610:334:1:o;1949:1087::-;2044:6;2052;2060;2068;2121:3;2109:9;2100:7;2096:23;2092:33;2089:53;;;2138:1;2135;2128:12;2089:53;2161:29;2180:9;2161:29;:::i;:::-;2151:39;;2209:38;2243:2;2232:9;2228:18;2209:38;:::i;:::-;2199:48;-1:-1:-1;2316:2:1;2301:18;;2288:32;;-1:-1:-1;2395:2:1;2380:18;;2367:32;2422:18;2411:30;;2408:50;;;2454:1;2451;2444:12;2408:50;2477:22;;2530:4;2522:13;;2518:27;-1:-1:-1;2508:55:1;;2559:1;2556;2549:12;2508:55;2599:2;2586:16;2625:18;2617:6;2614:30;2611:56;;;2647:18;;:::i;:::-;2689:116;2801:2;2732:66;2725:4;2717:6;2713:17;2709:90;2705:99;2689:116;:::i;:::-;2828:6;2821:5;2814:21;2876:7;2871:2;2862:6;2858:2;2854:15;2850:24;2847:37;2844:57;;;2897:1;2894;2887:12;2844:57;2952:6;2947:2;2943;2939:11;2934:2;2927:5;2923:14;2910:49;3004:1;2999:2;2990:6;2983:5;2979:18;2975:27;2968:38;3025:5;3015:15;;;;;1949:1087;;;;;;;:::o;3294:186::-;3353:6;3406:2;3394:9;3385:7;3381:23;3377:32;3374:52;;;3422:1;3419;3412:12;3374:52;3445:29;3464:9;3445:29;:::i;3485:300::-;3553:6;3561;3614:2;3602:9;3593:7;3589:23;3585:32;3582:52;;;3630:1;3627;3620:12;3582:52;3653:29;3672:9;3653:29;:::i;:::-;3643:39;3751:2;3736:18;;;;3723:32;;-1:-1:-1;;;3485:300:1:o;3790:303::-;3883:5;3906:1;3916:171;3930:4;3927:1;3924:11;3916:171;;;3989:13;;3977:26;;4032:4;4023:14;;;;4060:17;;;;3950:1;3943:9;3916:171;;;3920:3;;3790:303;;:::o;4098:347::-;4139:3;4177:5;4171:12;4204:6;4199:3;4192:19;4260:6;4253:4;4246:5;4242:16;4235:4;4230:3;4226:14;4220:47;4312:1;4305:4;4296:6;4291:3;4287:16;4283:27;4276:38;4434:4;4364:66;4359:2;4351:6;4347:15;4343:88;4338:3;4334:98;4330:109;4323:116;;;4098:347;;;;:::o;4450:498::-;4727:6;4716:9;4709:25;4743:52;4791:2;4780:9;4776:18;4768:6;4743:52;:::i;:::-;4832:6;4826:3;4815:9;4811:19;4804:35;4876:3;4870;4859:9;4855:19;4848:32;4690:4;4897:45;4937:3;4926:9;4922:19;4914:6;4897:45;:::i;:::-;4889:53;4450:498;-1:-1:-1;;;;;;4450:498:1:o;6166:471::-;6346:2;6331:18;;6335:9;6426:6;6304:4;6460:171;6474:4;6471:1;6468:11;6460:171;;;6533:13;;6521:26;;6576:4;6567:14;;;;6604:17;;;;6494:1;6487:9;6460:171;;;6464:3;;;6166:471;;;;:::o;7304:423::-;7517:42;7509:6;7505:55;7494:9;7487:74;7597:2;7592;7581:9;7577:18;7570:30;7468:4;7617:44;7657:2;7646:9;7642:18;7634:6;7617:44;:::i;:::-;7609:52;;7709:10;7701:6;7697:23;7692:2;7681:9;7677:18;7670:51;7304:423;;;;;;:::o;8505:230::-;8575:6;8628:2;8616:9;8607:7;8603:23;8599:32;8596:52;;;8644:1;8641;8634:12;8596:52;-1:-1:-1;8689:16:1;;8505:230;-1:-1:-1;8505:230:1:o;8740:184::-;8792:77;8789:1;8782:88;8889:4;8886:1;8879:15;8913:4;8910:1;8903:15;8929:164;9006:13;;9059:1;9048:20;;;9038:31;;9028:59;;9083:1;9080;9073:12;9098:1777;9220:6;9273:2;9261:9;9252:7;9248:23;9244:32;9241:52;;;9289:1;9286;9279:12;9241:52;9322:9;9316:16;9355:18;9347:6;9344:30;9341:50;;;9387:1;9384;9377:12;9341:50;9410:22;;9463:4;9455:13;;9451:27;-1:-1:-1;9441:55:1;;9492:1;9489;9482:12;9441:55;9525:2;9519:9;9551:18;9543:6;9540:30;9537:56;;;9573:18;;:::i;:::-;9613:40;9649:2;9640:6;9637:1;9633:14;9629:23;9613:40;:::i;:::-;9675:3;9699:6;9694:3;9687:19;9731:2;9726:3;9722:12;9715:19;;9789:2;9781:4;9773:6;9769:17;9765:2;9761:26;9757:35;9743:49;;9815:7;9807:6;9804:19;9801:39;;;9836:1;9833;9826:12;9801:39;9868:2;9864;9860:11;9849:22;;9880:965;9896:6;9891:3;9888:15;9880:965;;;9978:4;9972:3;9963:7;9959:17;9955:28;9952:48;;;9996:1;9993;9986:12;9952:48;10026:22;;:::i;:::-;10101:10;;10124:22;;10214:2;10205:12;;;10199:19;10238:14;;;10231:31;10330:2;10321:12;;;10315:19;10354:14;;;10347:31;10446:2;10437:12;;;10431:19;10470:14;;;10463:31;10562:3;10553:13;;;10547:20;10587:15;;;10580:32;10649:42;10686:3;10677:13;;10649:42;:::i;:::-;10643:3;10636:5;10632:15;10625:67;10729:42;10766:3;10761;10757:13;10729:42;:::i;:::-;10723:3;10712:15;;10705:67;10785:18;;9922:4;9913:14;;;;;10832:2;10823:12;;;;9880:965;;10880:184;10932:77;10929:1;10922:88;11029:4;11026:1;11019:15;11053:4;11050:1;11043:15;11069:125;11134:9;;;11155:10;;;11152:36;;;11168:18;;:::i;:::-;11069:125;;;;:::o;11199:128::-;11266:9;;;11287:11;;;11284:37;;;11301:18;;:::i;11332:375::-;11420:1;11438:5;11452:249;11473:1;11463:8;11460:15;11452:249;;;11523:4;11518:3;11514:14;11508:4;11505:24;11502:50;;;11532:18;;:::i;:::-;11582:1;11572:8;11568:16;11565:49;;;11596:16;;;;11565:49;11679:1;11675:16;;;;;11635:15;;11452:249;;;11332:375;;;;;;:::o;11712:1022::-;11761:5;11791:8;11781:80;;-1:-1:-1;11832:1:1;11846:5;;11781:80;11880:4;11870:76;;-1:-1:-1;11917:1:1;11931:5;;11870:76;11962:4;11980:1;11975:59;;;;12048:1;12043:174;;;;11955:262;;11975:59;12005:1;11996:10;;12019:5;;;12043:174;12080:3;12070:8;12067:17;12064:43;;;12087:18;;:::i;:::-;-1:-1:-1;;12143:1:1;12129:16;;12202:5;;11955:262;;12301:2;12291:8;12288:16;12282:3;12276:4;12273:13;12269:36;12263:2;12253:8;12250:16;12245:2;12239:4;12236:12;12232:35;12229:77;12226:203;;;-1:-1:-1;12338:19:1;;;12414:5;;12226:203;12461:102;12496:66;12486:8;12480:4;12461:102;:::i;:::-;12659:6;12591:66;12587:79;12578:7;12575:92;12572:118;;;12670:18;;:::i;:::-;12708:20;;11712:1022;-1:-1:-1;;;11712:1022:1:o;12739:131::-;12799:5;12828:36;12855:8;12849:4;12828:36;:::i;12875:168::-;12948:9;;;12979;;12996:15;;;12990:22;;12976:37;12966:71;;13017:18;;:::i;13048:313::-;13269:25;;;13256:3;13241:19;;13303:52;13351:2;13336:18;;13328:6;13303:52;:::i;13938:343::-;14017:6;14025;14078:2;14066:9;14057:7;14053:23;14049:32;14046:52;;;14094:1;14091;14084:12;14046:52;-1:-1:-1;;14139:16:1;;14245:2;14230:18;;;14224:25;14139:16;;14224:25;;-1:-1:-1;13938:343:1:o;14851:277::-;14918:6;14971:2;14959:9;14950:7;14946:23;14942:32;14939:52;;;14987:1;14984;14977:12;14939:52;15019:9;15013:16;15072:5;15065:13;15058:21;15051:5;15048:32;15038:60;;15094:1;15091;15084:12;16309:301;16438:3;16476:6;16470:13;16522:6;16515:4;16507:6;16503:17;16498:3;16492:37;16584:1;16548:16;;16573:13;;;-1:-1:-1;16548:16:1;16309:301;-1:-1:-1;16309:301:1:o;16615:219::-;16764:2;16753:9;16746:21;16727:4;16784:44;16824:2;16813:9;16809:18;16801:6;16784:44;:::i
Swarm Source
ipfs://39dfd85842f5d82911842218eeb126fa8eb0ebd3f083c5521443fe47547ac8eb
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.