Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00Multichain Info
N/A
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers.
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | ||||
---|---|---|---|---|---|---|---|
11983451 | 11 mins ago | 0 ETH | |||||
11983086 | 17 mins ago | 0 ETH | |||||
11982478 | 27 mins ago | 0 ETH | |||||
11982317 | 30 mins ago | 0 ETH | |||||
11982087 | 34 mins ago | 0 ETH | |||||
11982011 | 35 mins ago | 0 ETH | |||||
11981952 | 36 mins ago | 0 ETH | |||||
11981879 | 37 mins ago | 0 ETH | |||||
11981352 | 46 mins ago | 0 ETH | |||||
11981337 | 46 mins ago | 0 ETH | |||||
11980927 | 53 mins ago | 0 ETH | |||||
11980858 | 54 mins ago | 0 ETH | |||||
11980620 | 58 mins ago | 0 ETH | |||||
11980420 | 1 hr ago | 0 ETH | |||||
11980399 | 1 hr ago | 0 ETH | |||||
11980333 | 1 hr ago | 0 ETH | |||||
11979948 | 1 hr ago | 0 ETH | |||||
11979691 | 1 hr ago | 0 ETH | |||||
11979576 | 1 hr ago | 0 ETH | |||||
11979395 | 1 hr ago | 0 ETH | |||||
11979381 | 1 hr ago | 0 ETH | |||||
11978821 | 1 hr ago | 0 ETH | |||||
11978684 | 1 hr ago | 0 ETH | |||||
11977450 | 1 hr ago | 0 ETH | |||||
11977247 | 1 hr ago | 0 ETH |
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Source Code Verified (Exact Match)
Contract Name:
PullTokenWrapperWithTransfer
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 100 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.17; import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { DistributionCreator } from "../../DistributionCreator.sol"; import { UUPSHelper } from "../../utils/UUPSHelper.sol"; import { IAccessControlManager } from "../../interfaces/IAccessControlManager.sol"; import { Errors } from "../../utils/Errors.sol"; /// @title PullTokenWrapperWithTransfer /// @notice Wrapper for a reward token on Merkl so campaigns do not have to be prefunded contract PullTokenWrapperWithTransfer is UUPSHelper, ERC20Upgradeable { using SafeERC20 for IERC20; // ================================= VARIABLES ================================= /// @notice `AccessControlManager` contract handling access control IAccessControlManager public accessControlManager; // Could be put as immutable in a non upgradeable contract address public token; address public holder; address public feeRecipient; address public distributor; address public distributionCreator; // ================================= MODIFIERS ================================= /// @notice Checks whether the `msg.sender` has the governor role or the guardian role modifier onlyHolderOrGovernor() { if (msg.sender != holder && !accessControlManager.isGovernor(msg.sender)) revert Errors.NotAllowed(); _; } // ================================= FUNCTIONS ================================= function initialize( address _token, address _distributionCreator, address _holder, string memory _name, string memory _symbol ) public initializer { __ERC20_init(string.concat(_name), string.concat(_symbol)); __UUPSUpgradeable_init(); if (_holder == address(0)) revert Errors.ZeroAddress(); IERC20(_token).balanceOf(_holder); distributor = DistributionCreator(_distributionCreator).distributor(); accessControlManager = DistributionCreator(_distributionCreator).accessControlManager(); token = _token; distributionCreator = _distributionCreator; holder = _holder; _setFeeRecipient(); } function _beforeTokenTransfer(address from, address to, uint256 amount) internal override { // During claim transactions, tokens are transferred to the `to` address if (from == distributor || to == feeRecipient) IERC20(token).safeTransfer(to, amount); } function _afterTokenTransfer(address, address to, uint256 amount) internal override { // No leftover tokens can be kept except on the holder address if (to != address(distributor) && to != holder && to != address(0)) _burn(to, amount); } function setHolder(address _newHolder) external onlyHolderOrGovernor { holder = _newHolder; } function mint(uint256 amount) external onlyHolderOrGovernor { _mint(holder, amount); } function recover(address _token, address _to, uint256 amount) external onlyHolderOrGovernor { IERC20(_token).safeTransfer(_to, amount); } function setFeeRecipient() external { _setFeeRecipient(); } function _setFeeRecipient() internal { address _feeRecipient = DistributionCreator(distributionCreator).feeRecipient(); feeRecipient = _feeRecipient; } /// @inheritdoc UUPSHelper function _authorizeUpgrade(address) internal view override onlyGovernorUpgrader(accessControlManager) {} }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.8.0; struct DistributionParameters { // ID of the reward (populated once created). This can be left as a null bytes32 when creating distributions // on Merkl. bytes32 rewardId; // Address of the UniswapV3 pool that needs to be incentivized address uniV3Pool; // Address of the reward token for the incentives address rewardToken; // Amount of `rewardToken` to distribute across all the epochs // Amount distributed per epoch is `amount/numEpoch` uint256 amount; // List of all position wrappers to consider or not for this contract. Some wrappers like Gamma or Arrakis // are automatically detected and so there is no need to specify them here. Check out the docs to find out // which need to be specified and which are not automatically detected. address[] positionWrappers; // Type (blacklist==3, whitelist==0, ...) encoded as a `uint32` for each wrapper in the list above. Mapping between // wrapper types and their corresponding `uint32` value can be found in Angle Docs uint32[] wrapperTypes; // In the incentivization formula, how much of the fees should go to holders of token0 // in base 10**4 uint32 propToken0; // Proportion for holding token1 (in base 10**4) uint32 propToken1; // Proportion for providing a useful liquidity (in base 10**4) that generates fees uint32 propFees; // Timestamp at which the incentivization should start. This is in the same units as `block.timestamp`. uint32 epochStart; // Amount of epochs for which incentivization should last. Epochs are expressed in hours here, so for a // campaign of 1 week `numEpoch` should for instance be 168. uint32 numEpoch; // Whether out of range liquidity should still be incentivized or not // This should be equal to 1 if out of range liquidity should still be incentivized // and 0 otherwise. uint32 isOutOfRangeIncentivized; // How much more addresses with a maximum boost can get with respect to addresses // which do not have a boost (in base 4). In the case of Curve where addresses get 2.5x more // this would be 25000. uint32 boostedReward; // Address of the token which dictates who gets boosted rewards or not. This is optional // and if the zero address is given no boost will be taken into account. In the case of Curve, this address // would for instance be the veBoostProxy address, or in other cases the veToken address. address boostingAddress; // Additional data passed when distributing rewards. This parameter may be used in case // the reward distribution script needs to look into other parameters beyond the ones above. // In most cases, when creating a campaign on Merkl, you can leave this as an empty bytes. bytes additionalData; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol) pragma solidity ^0.8.0; /** * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified * proxy whose upgrades are fully controlled by the current implementation. */ interface IERC1822ProxiableUpgradeable { /** * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation * address. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. */ function proxiableUUID() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol) pragma solidity ^0.8.0; /** * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC. * * _Available since v4.8.3._ */ interface IERC1967Upgradeable { /** * @dev Emitted when the implementation is upgraded. */ event Upgraded(address indexed implementation); /** * @dev Emitted when the admin account has changed. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Emitted when the beacon is changed. */ event BeaconUpgraded(address indexed beacon); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // 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(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. 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 for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the 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. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // 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 preconditions 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 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // ? `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // ? `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol) pragma solidity ^0.8.0; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../ERC1967/ERC1967UpgradeUpgradeable.sol"; import "./Initializable.sol"; /** * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy. * * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing * `UUPSUpgradeable` with a custom implementation of upgrades. * * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism. * * _Available since v4.1._ */ abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable { function __UUPSUpgradeable_init() internal onlyInitializing { } function __UUPSUpgradeable_init_unchained() internal onlyInitializing { } /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment address private immutable __self = address(this); /** * @dev Check that the execution is being performed through a delegatecall call and that the execution context is * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to * fail. */ modifier onlyProxy() { require(address(this) != __self, "Function must be called through delegatecall"); require(_getImplementation() == __self, "Function must be called through active proxy"); _; } /** * @dev Check that the execution is not being performed through a delegate call. This allows a function to be * callable on the implementing contract but not through proxies. */ modifier notDelegated() { require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall"); _; } /** * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the * implementation. It is used to validate the implementation's compatibility when performing an upgrade. * * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier. */ function proxiableUUID() external view virtual override notDelegated returns (bytes32) { return _IMPLEMENTATION_SLOT; } /** * @dev Upgrade the implementation of the proxy to `newImplementation`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeTo(address newImplementation) public virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, new bytes(0), false); } /** * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call * encoded in `data`. * * Calls {_authorizeUpgrade}. * * Emits an {Upgraded} event. * * @custom:oz-upgrades-unsafe-allow-reachable delegatecall */ function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy { _authorizeUpgrade(newImplementation); _upgradeToAndCallUUPS(newImplementation, data, true); } /** * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by * {upgradeTo} and {upgradeToAndCall}. * * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}. * * ```solidity * function _authorizeUpgrade(address) internal override onlyOwner {} * ``` */ function _authorizeUpgrade(address newImplementation) internal virtual; /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; import "../Strings.sol"; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ? {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) { // 32 is the length in bytes of hash, // enforced by the type signature above /// @solidity memory-safe-assembly assembly { mstore(0x00, "\x19Ethereum Signed Message:\n32") mstore(0x1c, hash) message := keccak256(0x00, 0x3c) } } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, "\x19\x01") mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) data := keccak256(ptr, 0x42) } } /** * @dev Returns an Ethereum Signed Data with intended validator, created from a * `validator` and `data` according to the version 0 of EIP-191. * * See {recover}. */ function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x00", validator, data)); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.8.0; struct CampaignParameters { // POPULATED ONCE CREATED // ID of the campaign. This can be left as a null bytes32 when creating campaigns // on Merkl. bytes32 campaignId; // CHOSEN BY CAMPAIGN CREATOR // Address of the campaign creator, if marked as address(0), it will be overriden with the // address of the `msg.sender` creating the campaign address creator; // Address of the token used as a reward address rewardToken; // Amount of `rewardToken` to distribute across all the epochs // Amount distributed per epoch is `amount/numEpoch` uint256 amount; // Type of campaign uint32 campaignType; // Timestamp at which the campaign should start uint32 startTimestamp; // Duration of the campaign in seconds. Has to be a multiple of EPOCH = 3600 uint32 duration; // Extra data to pass to specify the campaign bytes campaignData; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20Upgradeable.sol"; import "./extensions/IERC20MetadataUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the default value returned by this function, unless * it's overridden. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, 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}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, 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}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer(address from, address to, uint256 amount) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by // decrementing then incrementing. _balances[to] += amount; } emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; unchecked { // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. _balances[account] += amount; } emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; // Overflow not possible: amount <= accountBalance <= totalSupply. _totalSupply -= amount; } emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; import "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such 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. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); require(downcasted == value, "SafeCast: value doesn't fit in 248 bits"); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); require(downcasted == value, "SafeCast: value doesn't fit in 240 bits"); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); require(downcasted == value, "SafeCast: value doesn't fit in 232 bits"); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); require(downcasted == value, "SafeCast: value doesn't fit in 224 bits"); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); require(downcasted == value, "SafeCast: value doesn't fit in 216 bits"); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); require(downcasted == value, "SafeCast: value doesn't fit in 208 bits"); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); require(downcasted == value, "SafeCast: value doesn't fit in 200 bits"); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); require(downcasted == value, "SafeCast: value doesn't fit in 192 bits"); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); require(downcasted == value, "SafeCast: value doesn't fit in 184 bits"); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); require(downcasted == value, "SafeCast: value doesn't fit in 176 bits"); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); require(downcasted == value, "SafeCast: value doesn't fit in 168 bits"); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); require(downcasted == value, "SafeCast: value doesn't fit in 160 bits"); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); require(downcasted == value, "SafeCast: value doesn't fit in 152 bits"); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); require(downcasted == value, "SafeCast: value doesn't fit in 144 bits"); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); require(downcasted == value, "SafeCast: value doesn't fit in 136 bits"); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); require(downcasted == value, "SafeCast: value doesn't fit in 128 bits"); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); require(downcasted == value, "SafeCast: value doesn't fit in 120 bits"); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); require(downcasted == value, "SafeCast: value doesn't fit in 112 bits"); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); require(downcasted == value, "SafeCast: value doesn't fit in 104 bits"); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); require(downcasted == value, "SafeCast: value doesn't fit in 96 bits"); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); require(downcasted == value, "SafeCast: value doesn't fit in 88 bits"); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); require(downcasted == value, "SafeCast: value doesn't fit in 80 bits"); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); require(downcasted == value, "SafeCast: value doesn't fit in 72 bits"); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); require(downcasted == value, "SafeCast: value doesn't fit in 64 bits"); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); require(downcasted == value, "SafeCast: value doesn't fit in 56 bits"); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); require(downcasted == value, "SafeCast: value doesn't fit in 48 bits"); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); require(downcasted == value, "SafeCast: value doesn't fit in 40 bits"); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); require(downcasted == value, "SafeCast: value doesn't fit in 32 bits"); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); require(downcasted == value, "SafeCast: value doesn't fit in 24 bits"); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); require(downcasted == value, "SafeCast: value doesn't fit in 16 bits"); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); require(downcasted == value, "SafeCast: value doesn't fit in 8 bits"); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @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 { /** * @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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.17; library Errors { error CampaignDoesNotExist(); error CampaignAlreadyExists(); error CampaignDurationBelowHour(); error CampaignRewardTokenNotWhitelisted(); error CampaignRewardTooLow(); error CampaignShouldStartInFuture(); error InvalidDispute(); error InvalidLengths(); error InvalidOverride(); error InvalidParam(); error InvalidParams(); error InvalidProof(); error InvalidUninitializedRoot(); error InvalidReturnMessage(); error InvalidReward(); error InvalidSignature(); error KeyAlreadyUsed(); error NoDispute(); error NoOverrideForCampaign(); error NotAllowed(); error NotEnoughPayment(); error NotGovernor(); error NotGovernorOrGuardian(); error NotSigned(); error NotTrusted(); error NotUpgradeable(); error NotWhitelisted(); error UnresolvedDispute(); error ZeroAddress(); error DisputeFundsTransferFailed(); error EthNotAccepted(); error ReentrantCall(); error WithdrawalFailed(); error InvalidClaim(); error RefererNotSet(); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized != type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.17; import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; import { UUPSHelper } from "./utils/UUPSHelper.sol"; import { IAccessControlManager } from "./interfaces/IAccessControlManager.sol"; import { Errors } from "./utils/Errors.sol"; import { CampaignParameters } from "./struct/CampaignParameters.sol"; import { DistributionParameters } from "./struct/DistributionParameters.sol"; import { RewardTokenAmounts } from "./struct/RewardTokenAmounts.sol"; import { Distributor } from "./Distributor.sol"; /// @title DistributionCreator /// @author Angle Labs, Inc. /// @notice Manages the distribution of rewards through the Merkl system /// @dev This contract is mostly a helper for APIs built on top of Merkl /// @dev This contract distinguishes two types of different rewards: /// - distributions: type of campaign for concentrated liquidity pools created before Feb 15 2024, /// now deprecated /// - campaigns: the more global name to describe any reward program on top of Merkl //solhint-disable contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable { using SafeERC20 for IERC20; /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// CONSTANTS / VARIABLES //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ uint32 public constant HOUR = 3600; /// @notice Base for fee computation uint256 public constant BASE_9 = 1e9; uint256 public immutable CHAIN_ID = block.chainid; /// @notice `AccessControlManager` contract handling access control IAccessControlManager public accessControlManager; /// @notice Contract distributing rewards to users address public distributor; /// @notice Address to which fees are forwarded address public feeRecipient; /// @notice Value (in base 10**9) of the fees taken when creating a campaign uint256 public defaultFees; /// @notice Message that needs to be acknowledged by users creating a campaign string public message; /// @notice Hash of the message that needs to be signed bytes32 public messageHash; /// @notice List of all rewards distributed in the contract on campaigns created before mid Feb 2024 /// for concentrated liquidity pools DistributionParameters[] public distributionList; /// @notice Maps an address to its fee rebate mapping(address => uint256) public feeRebate; /// @notice Maps a token to whether it is whitelisted or not. No fees are to be paid for incentives given /// on pools with whitelisted tokens mapping(address => uint256) public isWhitelistedToken; /// @notice Deprecated, kept for storage compatibility mapping(address => uint256) public _nonces; /// @notice Maps an address to the last valid hash signed mapping(address => bytes32) public userSignatures; /// @notice Maps a user to whether it is whitelisted for not signing mapping(address => uint256) public userSignatureWhitelist; /// @notice Maps a token to the minimum amount that must be sent per epoch for a distribution to be valid /// @dev If `rewardTokenMinAmounts[token] == 0`, then `token` cannot be used as a reward mapping(address => uint256) public rewardTokenMinAmounts; /// @notice List of all reward tokens that have at some point been accepted address[] public rewardTokens; /// @notice List of all rewards ever distributed or to be distributed in the contract /// @dev An attacker could try to populate this list. It shouldn't be an issue as only view functions /// iterate on it CampaignParameters[] public campaignList; /// @notice Maps a campaignId to the ID of the campaign in the campaign list + 1 mapping(bytes32 => uint256) internal _campaignLookup; /// @notice Maps a campaign type to the fees for this specific campaign mapping(uint32 => uint256) public campaignSpecificFees; /// @notice Maps a campaignId to a potential override written mapping(bytes32 => CampaignParameters) public campaignOverrides; /// @notice Maps a campaignId to the block numbers at which it's been updated mapping(bytes32 => uint256[]) public campaignOverridesTimestamp; /// @notice Maps one address to another one to reallocate rewards for a given campaign mapping(bytes32 => mapping(address => address)) public campaignReallocation; /// @notice List all reallocated address for a given campaign mapping(bytes32 => address[]) public campaignListReallocation; /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ event DistributorUpdated(address indexed _distributor); event FeeRebateUpdated(address indexed user, uint256 userFeeRebate); event FeeRecipientUpdated(address indexed _feeRecipient); event FeesSet(uint256 _fees); event CampaignOverride(bytes32 _campaignId, CampaignParameters campaign); event CampaignReallocation(bytes32 _campaignId, address[] indexed from, address indexed to); event CampaignSpecificFeesSet(uint32 campaignType, uint256 _fees); event MessageUpdated(bytes32 _messageHash); event NewCampaign(CampaignParameters campaign); event NewDistribution(DistributionParameters distribution, address indexed sender); event RewardTokenMinimumAmountUpdated(address indexed token, uint256 amount); event TokenWhitelistToggled(address indexed token, uint256 toggleStatus); event UserSigned(bytes32 messageHash, address indexed user); event UserSigningWhitelistToggled(address indexed user, uint256 toggleStatus); /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// MODIFIERS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Checks whether the `msg.sender` has the governor role or the guardian role modifier onlyGovernorOrGuardian() { if (!accessControlManager.isGovernorOrGuardian(msg.sender)) revert Errors.NotGovernorOrGuardian(); _; } /// @notice Checks whether the `msg.sender` has the governor role or the guardian role modifier onlyGovernor() { if (!accessControlManager.isGovernor(msg.sender)) revert Errors.NotGovernor(); _; } /// @notice Checks whether an address has signed the message or not modifier hasSigned() { if ( userSignatureWhitelist[msg.sender] == 0 && userSignatures[msg.sender] != messageHash && userSignatureWhitelist[tx.origin] == 0 && userSignatures[tx.origin] != messageHash ) revert Errors.NotSigned(); _; } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ function initialize( IAccessControlManager _accessControlManager, address _distributor, uint256 _fees ) external initializer { if (address(_accessControlManager) == address(0) || _distributor == address(0)) revert Errors.ZeroAddress(); if (_fees >= BASE_9) revert Errors.InvalidParam(); distributor = _distributor; accessControlManager = _accessControlManager; defaultFees = _fees; } constructor() initializer {} /// @inheritdoc UUPSHelper function _authorizeUpgrade(address) internal view override onlyGovernorUpgrader(accessControlManager) {} /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// USER FACING FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Creates a `campaign` to incentivize a given pool for a specific period of time /// @return The campaignId of the new campaign /// @dev If the campaign is badly specified, it will not be handled by the campaign script and rewards may be lost /// @dev Reward tokens sent as part of campaigns must have been whitelisted before and amounts /// sent should be bigger than a minimum amount specific to each token /// @dev This function reverts if the sender has not accepted the terms and conditions function createCampaign(CampaignParameters memory newCampaign) external nonReentrant hasSigned returns (bytes32) { return _createCampaign(newCampaign); } /// @notice Same as the function above but for multiple campaigns at once /// @return List of all the campaign amounts actually deposited for each `campaign` in the `campaigns` list function createCampaigns( CampaignParameters[] memory campaigns ) external nonReentrant hasSigned returns (bytes32[] memory) { uint256 campaignsLength = campaigns.length; bytes32[] memory campaignIds = new bytes32[](campaignsLength); for (uint256 i; i < campaignsLength; ) { campaignIds[i] = _createCampaign(campaigns[i]); unchecked { ++i; } } return campaignIds; } /// @notice Allows a user to accept the conditions without signing the message /// @dev Users may either call `acceptConditions` here or `sign` the message function acceptConditions() external { userSignatureWhitelist[msg.sender] = 1; } /// @notice Checks whether the `msg.sender`'s `signature` is compatible with the message /// to sign and stores the signature /// @dev If you signed the message once, and the message has not been modified, then you do not /// need to sign again function sign(bytes calldata signature) external { _sign(signature); } /// @notice Combines signing the message and creating a campaign function signAndCreateCampaign( CampaignParameters memory newCampaign, bytes calldata signature ) external returns (bytes32) { _sign(signature); return _createCampaign(newCampaign); } /// @notice Creates a `distribution` to incentivize a given pool for a specific period of time function createDistribution( DistributionParameters memory newDistribution ) external nonReentrant hasSigned returns (uint256 distributionAmount) { return _createDistribution(newDistribution); } /// @notice Same as the function above but for multiple distributions at once function createDistributions( DistributionParameters[] memory distributions ) external nonReentrant hasSigned returns (uint256[] memory) { uint256 distributionsLength = distributions.length; uint256[] memory distributionAmounts = new uint256[](distributionsLength); for (uint256 i; i < distributionsLength; ) { distributionAmounts[i] = _createDistribution(distributions[i]); unchecked { ++i; } } return distributionAmounts; } /// @notice Overrides a campaign with new parameters /// @dev Some overrides maybe incorrect, but their correctness cannot be checked onchain. It is up to the Merkl /// engine to check the validity of the override. If the override is invalid, then the first campaign details /// will still apply. /// @dev Some fields in the new campaign parameters will be disregarded anyway (like the amount) function overrideCampaign(bytes32 _campaignId, CampaignParameters memory newCampaign) external { CampaignParameters memory _campaign = campaign(_campaignId); if ( _campaign.creator != msg.sender || newCampaign.rewardToken != _campaign.rewardToken || newCampaign.amount != _campaign.amount || (newCampaign.startTimestamp != _campaign.startTimestamp && block.timestamp > _campaign.startTimestamp) || // Allow to update startTimestamp before campaign start // End timestamp should be in the future newCampaign.duration + _campaign.startTimestamp <= block.timestamp ) revert Errors.InvalidOverride(); // Take a new fee to not trick the system by creating a campaign with the smallest fee // and then overriding it with a campaign with a bigger fee _computeFees(newCampaign.campaignType, newCampaign.amount, newCampaign.rewardToken); newCampaign.campaignId = _campaignId; newCampaign.creator = msg.sender; campaignOverrides[_campaignId] = newCampaign; campaignOverridesTimestamp[_campaignId].push(block.timestamp); emit CampaignOverride(_campaignId, newCampaign); } /// @notice Reallocates rewards of a given campaign from one address to another /// @dev To prevent manipulations by campaign creators, this function can only be called by the /// initial campaign creator if the `from` address has never claimed any reward on the chain /// @dev Compute engine should also make sure when reallocating rewards that `from` claimed amount /// is still 0 - otherwise double allocation can happen /// @dev It is meant to be used for the case of addresses accruing rewards but unable to claim them function reallocateCampaignRewards(bytes32 _campaignId, address[] memory froms, address to) external { CampaignParameters memory _campaign = campaign(_campaignId); if (_campaign.creator != msg.sender || block.timestamp < _campaign.startTimestamp + _campaign.duration) revert Errors.InvalidOverride(); uint256 fromsLength = froms.length; address[] memory successfullFrom = new address[](fromsLength); uint256 count = 0; for (uint256 i; i < fromsLength; i++) { (uint208 amount, uint48 timestamp, ) = Distributor(distributor).claimed(froms[i], _campaign.rewardToken); if (amount == 0 && timestamp == 0) { successfullFrom[count] = froms[i]; campaignReallocation[_campaignId][froms[i]] = to; campaignListReallocation[_campaignId].push(froms[i]); count++; } } assembly { mstore(successfullFrom, count) } if (count == 0) revert Errors.InvalidOverride(); emit CampaignReallocation(_campaignId, successfullFrom, to); } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GETTERS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Returns the distribution at a given index converted into a campaign function distribution(uint256 index) external view returns (CampaignParameters memory) { return _convertDistribution(distributionList[index]); } /// @notice Returns the index of a campaign in the campaign list function campaignLookup(bytes32 _campaignId) public view returns (uint256) { uint256 index = _campaignLookup[_campaignId]; if (index == 0) revert Errors.CampaignDoesNotExist(); return index - 1; } /// @notice Returns the campaign parameters of a given campaignId /// @dev If a campaign has been overriden, this function still shows the original state of the campaign function campaign(bytes32 _campaignId) public view returns (CampaignParameters memory) { return campaignList[campaignLookup(_campaignId)]; } /// @notice Returns the campaign ID for a given campaign /// @dev The campaign ID is computed as the hash of the following parameters: /// - `campaign.chainId` /// - `campaign.creator` /// - `campaign.rewardToken` /// - `campaign.campaignType` /// - `campaign.startTimestamp` /// - `campaign.duration` /// - `campaign.campaignData` /// This prevents the creation by the same account of two campaigns with the same parameters /// which is not a huge issue function campaignId(CampaignParameters memory campaignData) public view returns (bytes32) { return bytes32( keccak256( abi.encodePacked( CHAIN_ID, campaignData.creator, campaignData.rewardToken, campaignData.campaignType, campaignData.startTimestamp, campaignData.duration, campaignData.campaignData ) ) ); } /// @notice Returns the list of all the reward tokens supported as well as their minimum amounts /// @dev Not to be queried on-chain and hence not optimized for gas consumption function getValidRewardTokens() external view returns (RewardTokenAmounts[] memory) { (RewardTokenAmounts[] memory validRewardTokens, ) = _getValidRewardTokens(0, type(uint32).max); return validRewardTokens; } /// @dev Not to be queried on-chain and hence not optimized for gas consumption function getValidRewardTokens( uint32 skip, uint32 first ) external view returns (RewardTokenAmounts[] memory, uint256) { return _getValidRewardTokens(skip, first); } /// @notice Gets all the campaigns which were live at some point between `start` and `end` timestamp /// @param skip Disregard distibutions with a global index lower than `skip` /// @param first Limit the length of the returned array to `first` /// @return searchCampaigns Eligible campaigns /// @return lastIndexCampaign Index of the last campaign assessed in the list of all campaigns /// @dev For pagniation purpose, in case of out of gas, you can call back the same function but with `skip` set to `lastIndexCampaign` /// @dev Not to be queried on-chain and hence not optimized for gas consumption function getCampaignsBetween( uint32 start, uint32 end, uint32 skip, uint32 first ) external view returns (CampaignParameters[] memory, uint256 lastIndexCampaign) { return _getCampaignsBetween(start, end, skip, first); } function getCampaignOverridesTimestamp(bytes32 _campaignId) external view returns (uint256[] memory) { return campaignOverridesTimestamp[_campaignId]; } function getCampaignListReallocation(bytes32 _campaignId) external view returns (address[] memory) { return campaignListReallocation[_campaignId]; } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GOVERNANCE FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Sets a new `distributor` to which rewards should be distributed function setNewDistributor(address _distributor) external onlyGovernor { if (_distributor == address(0)) revert Errors.InvalidParam(); distributor = _distributor; emit DistributorUpdated(_distributor); } /// @notice Sets the defaultFees on deposit function setFees(uint256 _defaultFees) external onlyGovernor { if (_defaultFees >= BASE_9) revert Errors.InvalidParam(); defaultFees = _defaultFees; emit FeesSet(_defaultFees); } /// @notice Recovers fees accrued on the contract for a list of `tokens` function recoverFees(IERC20[] calldata tokens, address to) external onlyGovernor { uint256 tokensLength = tokens.length; for (uint256 i; i < tokensLength; ) { tokens[i].safeTransfer(to, tokens[i].balanceOf(address(this))); unchecked { ++i; } } } /// @notice Sets a new address to receive fees function setFeeRecipient(address _feeRecipient) external onlyGovernor { feeRecipient = _feeRecipient; emit FeeRecipientUpdated(_feeRecipient); } /// @notice Sets the message that needs to be signed by users before posting rewards function setMessage(string memory _message) external onlyGovernor { message = _message; bytes32 _messageHash = ECDSA.toEthSignedMessageHash(bytes(_message)); messageHash = _messageHash; emit MessageUpdated(_messageHash); } /// @notice Sets the fees specific for a campaign /// @dev To waive the fees for a campaign, set its fees to 1 function setCampaignFees(uint32 campaignType, uint256 _fees) external onlyGovernorOrGuardian { if (_fees >= BASE_9) revert Errors.InvalidParam(); campaignSpecificFees[campaignType] = _fees; emit CampaignSpecificFeesSet(campaignType, _fees); } /// @notice Toggles the fee whitelist for `token` function toggleTokenWhitelist(address token) external onlyGovernorOrGuardian { uint256 toggleStatus = 1 - isWhitelistedToken[token]; isWhitelistedToken[token] = toggleStatus; emit TokenWhitelistToggled(token, toggleStatus); } /// @notice Sets fee rebates for a given user function setUserFeeRebate(address user, uint256 userFeeRebate) external onlyGovernorOrGuardian { feeRebate[user] = userFeeRebate; emit FeeRebateUpdated(user, userFeeRebate); } /// @notice Sets the minimum amounts per distribution epoch for different reward tokens function setRewardTokenMinAmounts( address[] calldata tokens, uint256[] calldata amounts ) external onlyGovernorOrGuardian { uint256 tokensLength = tokens.length; if (tokensLength != amounts.length) revert Errors.InvalidLengths(); for (uint256 i; i < tokensLength; ++i) { uint256 amount = amounts[i]; // Basic logic check to make sure there are no duplicates in the `rewardTokens` table. If a token is // removed then re-added, it will appear as a duplicate in the list if (amount != 0 && rewardTokenMinAmounts[tokens[i]] == 0) rewardTokens.push(tokens[i]); rewardTokenMinAmounts[tokens[i]] = amount; emit RewardTokenMinimumAmountUpdated(tokens[i], amount); } } /// @notice Toggles the whitelist status for `user` when it comes to signing messages before depositing rewards. function toggleSigningWhitelist(address user) external onlyGovernorOrGuardian { uint256 whitelistStatus = 1 - userSignatureWhitelist[user]; userSignatureWhitelist[user] = whitelistStatus; emit UserSigningWhitelistToggled(user, whitelistStatus); } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// INTERNAL //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Internal version of `createCampaign` function _createCampaign(CampaignParameters memory newCampaign) internal returns (bytes32) { uint256 rewardTokenMinAmount = rewardTokenMinAmounts[newCampaign.rewardToken]; // if the campaign doesn't last at least one hour if (newCampaign.duration < HOUR) revert Errors.CampaignDurationBelowHour(); // if the reward token is not whitelisted as an incentive token if (rewardTokenMinAmount == 0) revert Errors.CampaignRewardTokenNotWhitelisted(); // if the amount distributed is too small with respect to what is allowed if ((newCampaign.amount * HOUR) / newCampaign.duration < rewardTokenMinAmount) revert Errors.CampaignRewardTooLow(); if (newCampaign.creator == address(0)) newCampaign.creator = msg.sender; // Computing fees: these are waived for whitelisted addresses and if there is a whitelisted token in a pool uint256 campaignAmountMinusFees = _computeFees( newCampaign.campaignType, newCampaign.amount, newCampaign.rewardToken ); IERC20(newCampaign.rewardToken).safeTransferFrom(msg.sender, distributor, campaignAmountMinusFees); newCampaign.amount = campaignAmountMinusFees; newCampaign.campaignId = campaignId(newCampaign); if (_campaignLookup[newCampaign.campaignId] != 0) revert Errors.CampaignAlreadyExists(); _campaignLookup[newCampaign.campaignId] = campaignList.length + 1; campaignList.push(newCampaign); emit NewCampaign(newCampaign); return newCampaign.campaignId; } /// @notice Creates a distribution from a deprecated distribution type function _createDistribution(DistributionParameters memory newDistribution) internal returns (uint256) { _createCampaign(_convertDistribution(newDistribution)); // Not gas efficient but deprecated return campaignList[campaignList.length - 1].amount; } /// @notice Converts the deprecated distribution type into a campaign function _convertDistribution( DistributionParameters memory distributionToConvert ) internal view returns (CampaignParameters memory) { uint256 wrapperLength = distributionToConvert.wrapperTypes.length; address[] memory whitelist = new address[](wrapperLength); address[] memory blacklist = new address[](wrapperLength); uint256 whitelistLength; uint256 blacklistLength; for (uint256 k = 0; k < wrapperLength; k++) { if (distributionToConvert.wrapperTypes[k] == 0) { whitelist[whitelistLength] = (distributionToConvert.positionWrappers[k]); whitelistLength += 1; } if (distributionToConvert.wrapperTypes[k] == 3) { blacklist[blacklistLength] = (distributionToConvert.positionWrappers[k]); blacklistLength += 1; } } assembly { mstore(whitelist, whitelistLength) mstore(blacklist, blacklistLength) } return CampaignParameters({ campaignId: distributionToConvert.rewardId, creator: msg.sender, rewardToken: distributionToConvert.rewardToken, amount: distributionToConvert.amount, campaignType: 2, startTimestamp: distributionToConvert.epochStart, duration: distributionToConvert.numEpoch * HOUR, campaignData: abi.encode( distributionToConvert.uniV3Pool, distributionToConvert.propFees, // eg. 6000 distributionToConvert.propToken0, // eg. 3000 distributionToConvert.propToken1, // eg. 1000 distributionToConvert.isOutOfRangeIncentivized, // eg. 0 distributionToConvert.boostingAddress, // eg. NULL_ADDRESS distributionToConvert.boostedReward, // eg. 0 whitelist, // eg. [] blacklist, // eg. [] "0x" ) }); } /// @notice Computes the fees to be taken on a campaign and transfers them to the fee recipient function _computeFees( uint32 campaignType, uint256 distributionAmount, address rewardToken ) internal returns (uint256 distributionAmountMinusFees) { uint256 baseFeesValue = campaignSpecificFees[campaignType]; if (baseFeesValue == 1) baseFeesValue = 0; else if (baseFeesValue == 0) baseFeesValue = defaultFees; uint256 _fees = (baseFeesValue * (BASE_9 - feeRebate[msg.sender])) / BASE_9; distributionAmountMinusFees = distributionAmount; if (_fees != 0) { distributionAmountMinusFees = (distributionAmount * (BASE_9 - _fees)) / BASE_9; address _feeRecipient = feeRecipient; _feeRecipient = _feeRecipient == address(0) ? address(this) : _feeRecipient; IERC20(rewardToken).safeTransferFrom( msg.sender, _feeRecipient, distributionAmount - distributionAmountMinusFees ); } } /// @notice Internal version of the `sign` function function _sign(bytes calldata signature) internal { bytes32 _messageHash = messageHash; if (!SignatureChecker.isValidSignatureNow(msg.sender, _messageHash, signature)) revert Errors.InvalidSignature(); userSignatures[msg.sender] = _messageHash; emit UserSigned(_messageHash, msg.sender); } /// @notice Rounds an `epoch` timestamp to the start of the corresponding period function _getRoundedEpoch(uint32 epoch) internal pure returns (uint32) { return (epoch / HOUR) * HOUR; } /// @notice Internal version of `getCampaignsBetween` function _getCampaignsBetween( uint32 start, uint32 end, uint32 skip, uint32 first ) internal view returns (CampaignParameters[] memory, uint256) { uint256 length; uint256 campaignListLength = campaignList.length; uint256 returnSize = first > campaignListLength ? campaignListLength : first; CampaignParameters[] memory activeRewards = new CampaignParameters[](returnSize); uint32 i = skip; while (i < campaignListLength) { CampaignParameters memory campaignToProcess = campaignList[i]; if ( campaignToProcess.startTimestamp + campaignToProcess.duration > start && campaignToProcess.startTimestamp < end ) { activeRewards[length] = campaignToProcess; length += 1; } unchecked { ++i; } if (length == returnSize) break; } assembly { mstore(activeRewards, length) } return (activeRewards, i); } /// @notice Builds the list of valid reward tokens function _getValidRewardTokens( uint32 skip, uint32 first ) internal view returns (RewardTokenAmounts[] memory, uint256) { uint256 length; uint256 rewardTokenListLength = rewardTokens.length; uint256 returnSize = first > rewardTokenListLength ? rewardTokenListLength : first; RewardTokenAmounts[] memory validRewardTokens = new RewardTokenAmounts[](returnSize); uint32 i = skip; while (i < rewardTokenListLength) { address token = rewardTokens[i]; uint256 minAmount = rewardTokenMinAmounts[token]; if (minAmount > 0) { validRewardTokens[length] = RewardTokenAmounts(token, minAmount); length += 1; } unchecked { ++i; } if (length == returnSize) break; } assembly { mstore(validRewardTokens, length) } return (validRewardTokens, i); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[31] private __gap; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.17; /// @title IAccessControlManager /// @author Angle Labs, Inc. /// @notice Interface for the `AccessControlManager` contracts of Merkl contracts interface IAccessControlManager { /// @notice Checks whether an address is governor /// @param admin Address to check /// @return Whether the address has the `GOVERNOR_ROLE` or not function isGovernor(address admin) external view returns (bool); /// @notice Checks whether an address is a governor or a guardian of a module /// @param admin Address to check /// @return Whether the address has the `GUARDIAN_ROLE` or not /// @dev Governance should make sure when adding a governor to also give this governor the guardian /// role by calling the `addGovernor` function function isGovernorOrGuardian(address admin) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [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://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.0/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 functionCallWithValue(target, data, 0, "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"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or 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 { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/SignatureChecker.sol) pragma solidity ^0.8.0; import "./ECDSA.sol"; import "../../interfaces/IERC1271.sol"; /** * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like * Argent and Gnosis Safe. * * _Available since v4.1._ */ library SignatureChecker { /** * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`. * * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus * change through time. It could return true at block N and false at block N+1 (or the opposite). */ function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) { (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature); return (error == ECDSA.RecoverError.NoError && recovered == signer) || isValidERC1271SignatureNow(signer, hash, signature); } /** * @dev Checks if a signature is valid for a given signer and data hash. The signature is validated * against the signer smart contract using ERC1271. * * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus * change through time. It could return true at block N and false at block N+1 (or the opposite). */ function isValidERC1271SignatureNow( address signer, bytes32 hash, bytes memory signature ) internal view returns (bool) { (bool success, bytes memory result) = signer.staticcall( abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature) ); return (success && result.length >= 32 && abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ```solidity * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._ * _Available since v4.9 for `string`, `bytes`._ */ library StorageSlotUpgradeable { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct StringSlot { string value; } struct BytesSlot { bytes value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` with member `value` located at `slot`. */ function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot(string storage store) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev Returns an `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol) pragma solidity ^0.8.0; /** * @dev This is the interface that {BeaconProxy} expects of its beacon. */ interface IBeaconUpgradeable { /** * @dev Must return an address that can be used as a delegate call target. * * {BeaconProxy} will check that this address is a contract. */ function implementation() external view returns (address); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.17; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { UUPSHelper } from "./utils/UUPSHelper.sol"; import { IAccessControlManager } from "./interfaces/IAccessControlManager.sol"; import { Errors } from "./utils/Errors.sol"; struct MerkleTree { // Root of a Merkle tree which leaves are `(address user, address token, uint amount)` // representing an amount of tokens accumulated by `user`. // The Merkle tree is assumed to have only increasing amounts: that is to say if a user can claim 1, // then after the amount associated in the Merkle tree for this token should be x > 1 bytes32 merkleRoot; // Ipfs hash of the tree data bytes32 ipfsHash; } struct Claim { uint208 amount; uint48 timestamp; bytes32 merkleRoot; } interface IClaimRecipient { /// @notice Hook to call within contracts receiving token rewards on behalf of users function onClaim(address user, address token, uint256 amount, bytes memory data) external returns (bytes32); } /// @title Distributor /// @notice Allows to claim rewards distributed to them through Merkl /// @author Angle Labs. Inc contract Distributor is UUPSHelper { using SafeERC20 for IERC20; /// @notice Default epoch duration uint32 internal constant _EPOCH_DURATION = 3600; /// @notice Success message received when calling a `ClaimRecipient` contract bytes32 public constant CALLBACK_SUCCESS = keccak256("IClaimRecipient.onClaim"); /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// VARIABLES //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Tree of claimable tokens through this contract MerkleTree public tree; /// @notice Tree that was in place in the contract before the last `tree` update MerkleTree public lastTree; /// @notice Token to deposit to freeze the roots update IERC20 public disputeToken; /// @notice `AccessControlManager` contract handling access control IAccessControlManager public accessControlManager; /// @notice Address which created the last dispute /// @dev Used to store if there is an ongoing dispute address public disputer; /// @notice When the current tree becomes valid uint48 public endOfDisputePeriod; /// @notice Time after which a change in a tree becomes effective, in EPOCH_DURATION uint48 public disputePeriod; /// @notice Amount to deposit to freeze the roots update uint256 public disputeAmount; /// @notice Mapping user -> token -> amount to track claimed amounts mapping(address => mapping(address => Claim)) public claimed; /// @notice Trusted EOAs to update the Merkle root mapping(address => uint256) public canUpdateMerkleRoot; /// @notice Deprecated mapping mapping(address => uint256) public onlyOperatorCanClaim; /// @notice User -> Operator -> authorisation to claim on behalf of the user mapping(address => mapping(address => uint256)) public operators; /// @notice Whether the contract has been made non upgradeable or not uint128 public upgradeabilityDeactivated; /// @notice Reentrancy status uint96 private _status; /// @notice Epoch duration for dispute periods (in seconds) uint32 internal _epochDuration; /// @notice user -> token -> recipient address for when user claims `token` /// @dev If the mapping is empty, by default rewards will accrue on the user address mapping(address => mapping(address => address)) public claimRecipient; uint256[36] private __gap; /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ event Claimed(address indexed user, address indexed token, uint256 amount); event ClaimRecipientUpdated(address indexed user, address indexed token, address indexed recipient); event DisputeAmountUpdated(uint256 _disputeAmount); event Disputed(string reason); event DisputePeriodUpdated(uint48 _disputePeriod); event DisputeResolved(bool valid); event DisputeTokenUpdated(address indexed _disputeToken); event EpochDurationUpdated(uint32 newEpochDuration); event OperatorClaimingToggled(address indexed user, bool isEnabled); event OperatorToggled(address indexed user, address indexed operator, bool isWhitelisted); event Recovered(address indexed token, address indexed to, uint256 amount); event Revoked(); // With this event an indexer could maintain a table (timestamp, merkleRootUpdate) event TreeUpdated(bytes32 merkleRoot, bytes32 ipfsHash, uint48 endOfDisputePeriod); event TrustedToggled(address indexed eoa, bool trust); event UpgradeabilityRevoked(); /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// MODIFIERS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Checks whether the `msg.sender` has the governor role modifier onlyGovernor() { if (!accessControlManager.isGovernor(msg.sender)) revert Errors.NotGovernor(); _; } /// @notice Checks whether the `msg.sender` is the `user` address or is a trusted address modifier onlyTrustedOrUser(address user) { if ( user != msg.sender && canUpdateMerkleRoot[msg.sender] != 1 && !accessControlManager.isGovernorOrGuardian(msg.sender) ) revert Errors.NotTrusted(); _; } /// @notice Checks whether the contract is upgradeable or whether the caller is allowed to upgrade the contract modifier onlyUpgradeableInstance() { if (upgradeabilityDeactivated == 1) revert Errors.NotUpgradeable(); else if (!accessControlManager.isGovernor(msg.sender)) revert Errors.NotGovernor(); _; } /// @notice Checks whether a call is reentrant or not modifier nonReentrant() { if (_status == 2) revert Errors.ReentrantCall(); // Any calls to nonReentrant after this point will fail _status = 2; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = 1; } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ constructor() initializer {} function initialize(IAccessControlManager _accessControlManager) external initializer { if (address(_accessControlManager) == address(0)) revert Errors.ZeroAddress(); accessControlManager = _accessControlManager; } /// @inheritdoc UUPSHelper function _authorizeUpgrade(address) internal view override onlyUpgradeableInstance {} /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// MAIN FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Claims rewards for a given set of users /// @dev Unless another address has been approved for claiming, only an address can claim for itself /// @param users Addresses for which claiming is taking place /// @param tokens ERC20 token claimed /// @param amounts Amount of tokens that will be sent to the corresponding users /// @param proofs Array of hashes bridging from a leaf `(hash of user | token | amount)` to the Merkle root function claim( address[] calldata users, address[] calldata tokens, uint256[] calldata amounts, bytes32[][] calldata proofs ) external { address[] memory recipients = new address[](users.length); bytes[] memory datas = new bytes[](users.length); _claim(users, tokens, amounts, proofs, recipients, datas); } /// @notice Same as the function above except that for each token claimed, the caller may set different /// recipients for rewards and pass arbitrary data to the reward recipient on claim /// @dev Only a `msg.sender` calling for itself can set a different recipient for the token rewards /// within the context of a call to claim /// @dev Non-zero recipient addresses given by the `msg.sender` can override any previously set reward address function claimWithRecipient( address[] calldata users, address[] calldata tokens, uint256[] calldata amounts, bytes32[][] calldata proofs, address[] calldata recipients, bytes[] memory datas ) external { _claim(users, tokens, amounts, proofs, recipients, datas); } /// @notice Returns the Merkle root that is currently live for the contract function getMerkleRoot() public view returns (bytes32) { if (block.timestamp >= endOfDisputePeriod && disputer == address(0)) return tree.merkleRoot; else return lastTree.merkleRoot; } function getEpochDuration() public view returns (uint32 epochDuration) { epochDuration = _epochDuration; if (epochDuration == 0) epochDuration = _EPOCH_DURATION; } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// USER ADMIN FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Toggles whitelisting for a given user and a given operator /// @dev When an operator is whitelisted for a user, the operator can claim rewards on behalf of the user function toggleOperator(address user, address operator) external onlyTrustedOrUser(user) { uint256 oldValue = operators[user][operator]; operators[user][operator] = 1 - oldValue; emit OperatorToggled(user, operator, oldValue == 0); } /// @notice Sets a recipient for a user claiming rewards for a token /// @dev This is an optional functionality and if the `recipient` is set to the zero address, then /// the user will still accrue all rewards to its address /// @dev Users may still specify a different recipient when they claim token rewards with the /// `claimWithRecipient` function function setClaimRecipient(address recipient, address token) external { claimRecipient[msg.sender][token] = recipient; emit ClaimRecipientUpdated(msg.sender, recipient, token); } /// @notice Freezes the Merkle tree update until the dispute is resolved /// @dev Requires a deposit of `disputeToken` that'll be slashed if the dispute is not accepted /// @dev It is only possible to create a dispute within `disputePeriod` after each tree update function disputeTree(string memory reason) external { if (disputer != address(0)) revert Errors.UnresolvedDispute(); if (block.timestamp >= endOfDisputePeriod) revert Errors.InvalidDispute(); IERC20(disputeToken).safeTransferFrom(msg.sender, address(this), disputeAmount); disputer = msg.sender; emit Disputed(reason); } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// GOVERNANCE FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Updates the Merkle tree function updateTree(MerkleTree calldata _tree) external { if ( disputer != address(0) || // A trusted address cannot update a tree right after a precedent tree update otherwise it can de facto // validate a tree which has not passed the dispute period ((canUpdateMerkleRoot[msg.sender] != 1 || block.timestamp < endOfDisputePeriod) && !accessControlManager.isGovernor(msg.sender)) ) revert Errors.NotTrusted(); MerkleTree memory _lastTree = tree; tree = _tree; lastTree = _lastTree; uint48 _endOfPeriod = _endOfDisputePeriod(uint48(block.timestamp)); endOfDisputePeriod = _endOfPeriod; emit TreeUpdated(_tree.merkleRoot, _tree.ipfsHash, _endOfPeriod); } /// @notice Adds or removes addresses which are trusted to update the Merkle root function toggleTrusted(address trustAddress) external onlyGovernor { uint256 trustedStatus = 1 - canUpdateMerkleRoot[trustAddress]; canUpdateMerkleRoot[trustAddress] = trustedStatus; emit TrustedToggled(trustAddress, trustedStatus == 1); } /// @notice Prevents future contract upgrades function revokeUpgradeability() external onlyGovernor { upgradeabilityDeactivated = 1; emit UpgradeabilityRevoked(); } /// @notice Updates the epoch duration period function setEpochDuration(uint32 epochDuration) external onlyGovernor { _epochDuration = epochDuration; emit EpochDurationUpdated(epochDuration); } /// @notice Resolve the ongoing dispute, if any /// @param valid Whether the dispute was valid function resolveDispute(bool valid) external onlyGovernor { if (disputer == address(0)) revert Errors.NoDispute(); if (valid) { IERC20(disputeToken).safeTransfer(disputer, disputeAmount); // If a dispute is valid, the contract falls back to the last tree that was updated _revokeTree(); } else { IERC20(disputeToken).safeTransfer(msg.sender, disputeAmount); endOfDisputePeriod = _endOfDisputePeriod(uint48(block.timestamp)); } disputer = address(0); emit DisputeResolved(valid); } /// @notice Allows the governor of this contract to fallback to the last version of the tree /// immediately function revokeTree() external onlyGovernor { if (disputer != address(0)) revert Errors.UnresolvedDispute(); _revokeTree(); } /// @notice Recovers any ERC20 token left on the contract function recoverERC20(address tokenAddress, address to, uint256 amountToRecover) external onlyGovernor { IERC20(tokenAddress).safeTransfer(to, amountToRecover); emit Recovered(tokenAddress, to, amountToRecover); } /// @notice Sets the dispute period after which a tree update becomes effective function setDisputePeriod(uint48 _disputePeriod) external onlyGovernor { disputePeriod = uint48(_disputePeriod); emit DisputePeriodUpdated(_disputePeriod); } /// @notice Sets the token used as a caution during disputes function setDisputeToken(IERC20 _disputeToken) external onlyGovernor { if (disputer != address(0)) revert Errors.UnresolvedDispute(); disputeToken = _disputeToken; emit DisputeTokenUpdated(address(_disputeToken)); } /// @notice Sets the amount of `disputeToken` used as a caution during disputes function setDisputeAmount(uint256 _disputeAmount) external onlyGovernor { if (disputer != address(0)) revert Errors.UnresolvedDispute(); disputeAmount = _disputeAmount; emit DisputeAmountUpdated(_disputeAmount); } /*////////////////////////////////////////////////////////////////////////////////////////////////////////////////// INTERNAL HELPERS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /// @notice Internal version of `claimWithRecipient` function _claim( address[] calldata users, address[] calldata tokens, uint256[] calldata amounts, bytes32[][] calldata proofs, address[] memory recipients, bytes[] memory datas ) internal nonReentrant { uint256 usersLength = users.length; if ( usersLength == 0 || usersLength != tokens.length || usersLength != amounts.length || usersLength != proofs.length || usersLength != recipients.length || usersLength != datas.length ) revert Errors.InvalidLengths(); for (uint256 i; i < usersLength; ) { address user = users[i]; address token = tokens[i]; uint256 amount = amounts[i]; bytes memory data = datas[i]; // Only approved operator can claim for `user` if (msg.sender != user && tx.origin != user && operators[user][msg.sender] == 0) revert Errors.NotWhitelisted(); // Verifying proof bytes32 leaf = keccak256(abi.encode(user, token, amount)); if (!_verifyProof(leaf, proofs[i])) revert Errors.InvalidProof(); // Closing reentrancy gate here uint256 toSend = amount - claimed[user][token].amount; claimed[user][token] = Claim(SafeCast.toUint208(amount), uint48(block.timestamp), getMerkleRoot()); emit Claimed(user, token, toSend); address recipient = recipients[i]; // Only `msg.sender` can set a different recipient for itself within the context of a call to claim // The recipient set in the context of the call to `claim` can override the default recipient set by the user if (msg.sender != user || recipient == address(0)) { address userSetRecipient = claimRecipient[user][token]; if (userSetRecipient == address(0)) recipient = user; else recipient = userSetRecipient; } if (toSend != 0) { IERC20(token).safeTransfer(recipient, toSend); if (data.length != 0) { try IClaimRecipient(recipient).onClaim(user, token, amount, data) returns ( bytes32 callbackSuccess ) { if (callbackSuccess != CALLBACK_SUCCESS) revert Errors.InvalidReturnMessage(); } catch {} } } unchecked { ++i; } } } /// @notice Fallback to the last version of the tree function _revokeTree() internal { MerkleTree memory _tree = lastTree; endOfDisputePeriod = 0; tree = _tree; uint32 epochDuration = getEpochDuration(); emit Revoked(); emit TreeUpdated( _tree.merkleRoot, _tree.ipfsHash, (uint48(block.timestamp) / epochDuration) * (epochDuration) // Last hour ); } /// @notice Returns the end of the dispute period /// @dev treeUpdate is rounded up to next hour and then `disputePeriod` hours are added function _endOfDisputePeriod(uint48 treeUpdate) internal view returns (uint48) { uint32 epochDuration = getEpochDuration(); return ((treeUpdate - 1) / epochDuration + 1 + disputePeriod) * (epochDuration); } /// @notice Checks the validity of a proof /// @param leaf Hashed leaf data, the starting point of the proof /// @param proof Array of hashes forming a hash chain from leaf to root /// @return true If proof is correct, else false function _verifyProof(bytes32 leaf, bytes32[] memory proof) internal view returns (bool) { bytes32 currentHash = leaf; uint256 proofLength = proof.length; for (uint256 i; i < proofLength; ) { if (currentHash < proof[i]) { currentHash = keccak256(abi.encode(currentHash, proof[i])); } else { currentHash = keccak256(abi.encode(proof[i], currentHash)); } unchecked { ++i; } } bytes32 root = getMerkleRoot(); if (root == bytes32(0)) revert Errors.InvalidUninitializedRoot(); return currentHash == root; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @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 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, 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 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } /** * @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 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @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 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit 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 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"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 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.isContract(address(token)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.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 ReentrancyGuardUpgradeable is Initializable { // 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; function __ReentrancyGuard_init() internal onlyInitializing { __ReentrancyGuard_init_unchained(); } function __ReentrancyGuard_init_unchained() internal onlyInitializing { _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() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == _ENTERED; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.8.0; struct RewardTokenAmounts { address token; uint256 minimumAmountPerEpoch; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol) pragma solidity ^0.8.2; import "../beacon/IBeaconUpgradeable.sol"; import "../../interfaces/IERC1967Upgradeable.sol"; import "../../interfaces/draft-IERC1822Upgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/StorageSlotUpgradeable.sol"; import "../utils/Initializable.sol"; /** * @dev This abstract contract provides getters and event emitting update functions for * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * * _Available since v4.1._ */ abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable { function __ERC1967Upgrade_init() internal onlyInitializing { } function __ERC1967Upgrade_init_unchained() internal onlyInitializing { } // This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1 bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143; /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /** * @dev Returns the current implementation address. */ function _getImplementation() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value; } /** * @dev Stores a new address in the EIP1967 implementation slot. */ function _setImplementation(address newImplementation) private { require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract"); StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; } /** * @dev Perform implementation upgrade * * Emits an {Upgraded} event. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Perform implementation upgrade with additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal { _upgradeTo(newImplementation); if (data.length > 0 || forceCall) { AddressUpgradeable.functionDelegateCall(newImplementation, data); } } /** * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call. * * Emits an {Upgraded} event. */ function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal { // Upgrades from old implementations will perform a rollback test. This test requires the new // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing // this special case will break upgrade paths from old UUPS implementation to new ones. if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) { _setImplementation(newImplementation); } else { try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) { require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID"); } catch { revert("ERC1967Upgrade: new implementation is not UUPS"); } _upgradeToAndCall(newImplementation, data, forceCall); } } /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is * validated in the constructor. */ bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103; /** * @dev Returns the current admin. */ function _getAdmin() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value; } /** * @dev Stores a new address in the EIP1967 admin slot. */ function _setAdmin(address newAdmin) private { require(newAdmin != address(0), "ERC1967: new admin is the zero address"); StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin; } /** * @dev Changes the admin of the proxy. * * Emits an {AdminChanged} event. */ function _changeAdmin(address newAdmin) internal { emit AdminChanged(_getAdmin(), newAdmin); _setAdmin(newAdmin); } /** * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy. * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor. */ bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50; /** * @dev Returns the current beacon. */ function _getBeacon() internal view returns (address) { return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value; } /** * @dev Stores a new beacon in the EIP1967 beacon slot. */ function _setBeacon(address newBeacon) private { require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract"); require( AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()), "ERC1967: beacon implementation is not a contract" ); StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon; } /** * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that). * * Emits a {BeaconUpgraded} event. */ function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal { _setBeacon(newBeacon); emit BeaconUpgraded(newBeacon); if (data.length > 0 || forceCall) { AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data); } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC1271 standard signature validation method for * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271]. * * _Available since v4.1._ */ interface IERC1271 { /** * @dev Should return whether the signature provided is valid for the provided data * @param hash Hash of the data to be signed * @param signature Signature byte array associated with _data */ function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.17; import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol"; import { IAccessControlManager } from "../interfaces/IAccessControlManager.sol"; import { Errors } from "./Errors.sol"; /// @title UUPSHelper /// @notice Helper contract for UUPSUpgradeable contracts where the upgradeability is controlled by a specific address /// @author Angle Labs., Inc /// @dev The 0 address check in the modifier allows the use of these modifiers during initialization abstract contract UUPSHelper is UUPSUpgradeable { modifier onlyGuardianUpgrader(IAccessControlManager _accessControlManager) { if (address(_accessControlManager) != address(0) && !_accessControlManager.isGovernorOrGuardian(msg.sender)) revert Errors.NotGovernorOrGuardian(); _; } modifier onlyGovernorUpgrader(IAccessControlManager _accessControlManager) { if (address(_accessControlManager) != address(0) && !_accessControlManager.isGovernor(msg.sender)) revert Errors.NotGovernor(); _; } constructor() initializer {} /// @inheritdoc UUPSUpgradeable function _authorizeUpgrade(address newImplementation) internal virtual override {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [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://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.0/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 functionCallWithValue(target, data, 0, "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"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or 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 { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage); } } }
{ "evmVersion": "cancun", "libraries": {}, "metadata": { "appendCBOR": true, "bytecodeHash": "ipfs", "useLiteralContent": false }, "optimizer": { "enabled": true, "runs": 100 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "remappings": [ "@openzeppelin/=node_modules/@openzeppelin/", "forge-std/=node_modules/forge-std/src/", "oz/=node_modules/@openzeppelin/contracts/", "@utils/=node_modules/utils/src/", "lz/=node_modules/utils/lib/solidity-examples/contracts/", "stringutils/=node_modules/utils/lib/solidity-stringutils/src/", "utils/=node_modules/utils/" ], "viaIR": false }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"NotAllowed","type":"error"},{"inputs":[],"name":"NotGovernor","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"accessControlManager","outputs":[{"internalType":"contract IAccessControlManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"distributionCreator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"distributor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"holder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_distributionCreator","type":"address"},{"internalType":"address","name":"_holder","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"recover","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"setFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newHolder","type":"address"}],"name":"setHolder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"}]
Contract Creation Code
60a060405230608052348015610013575f80fd5b505f54610100900460ff161580801561003257505f54600160ff909116105b8061004b5750303b15801561004b57505f5460ff166001145b6100b25760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b5f805460ff1916600117905580156100d3575f805461ff0019166101001790555b8015610118575f805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b5060805161212561014d5f395f818161060801528181610651015281816106f90152818161073901526107b401526121255ff3fe608060405260043610610152575f3560e01c806370a08231116100be578063ae99c0ac11610078578063ae99c0ac14610391578063b4a0bdf3146103b0578063bfe10928146103cf578063d979f5aa146103ee578063dd62ed3e1461040d578063e534155d1461042c578063fc0c546a1461044b575f80fd5b806370a08231146102cd57806383b435891461030157806395d89b4114610320578063a0712d6814610334578063a457c2d714610353578063a9059cbb14610372575f80fd5b8063313ce5671161010f578063313ce567146102215780633659cfe61461023c578063395093511461025b578063469048401461027a5780634f1ef286146102a657806352d1902d146102b9575f80fd5b806306fdde0314610156578063095ea7b31461018057806313cf69dd146101af57806318160ddd146101c55780631ec82cb8146101e357806323b872dd14610202575b5f80fd5b348015610161575f80fd5b5061016a61046a565b6040516101779190611b0b565b60405180910390f35b34801561018b575f80fd5b5061019f61019a366004611b54565b6104fa565b6040519015158152602001610177565b3480156101ba575f80fd5b506101c3610513565b005b3480156101d0575f80fd5b506099545b604051908152602001610177565b3480156101ee575f80fd5b506101c36101fd366004611b7e565b61051d565b34801561020d575f80fd5b5061019f61021c366004611b7e565b6105db565b34801561022c575f80fd5b5060405160128152602001610177565b348015610247575f80fd5b506101c3610256366004611bbc565b6105fe565b348015610266575f80fd5b5061019f610275366004611b54565b6106ce565b348015610285575f80fd5b5060cc54610299906001600160a01b031681565b6040516101779190611bd7565b6101c36102b4366004611c72565b6106ef565b3480156102c4575f80fd5b506101d56107a8565b3480156102d8575f80fd5b506101d56102e7366004611bbc565b6001600160a01b03165f9081526097602052604090205490565b34801561030c575f80fd5b506101c361031b366004611cf0565b610854565b34801561032b575f80fd5b5061016a610b73565b34801561033f575f80fd5b506101c361034e366004611d86565b610b82565b34801561035e575f80fd5b5061019f61036d366004611b54565b610c3d565b34801561037d575f80fd5b5061019f61038c366004611b54565b610cb7565b34801561039c575f80fd5b5060ce54610299906001600160a01b031681565b3480156103bb575f80fd5b5060c954610299906001600160a01b031681565b3480156103da575f80fd5b5060cd54610299906001600160a01b031681565b3480156103f9575f80fd5b506101c3610408366004611bbc565b610cc4565b348015610418575f80fd5b506101d5610427366004611d9d565b610d8b565b348015610437575f80fd5b5060cb54610299906001600160a01b031681565b348015610456575f80fd5b5060ca54610299906001600160a01b031681565b6060609a805461047990611dd4565b80601f01602080910402602001604051908101604052809291908181526020018280546104a590611dd4565b80156104f05780601f106104c7576101008083540402835291602001916104f0565b820191905f5260205f20905b8154815290600101906020018083116104d357829003601f168201915b5050505050905090565b5f33610507818585610db5565b60019150505b92915050565b61051b610ed8565b565b60cb546001600160a01b031633148015906105a4575060c954604051631c86b03760e31b81526001600160a01b039091169063e43581b890610563903390600401611bd7565b602060405180830381865afa15801561057e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a29190611e0c565b155b156105c257604051631eb49d6d60e11b815260040160405180910390fd5b6105d66001600160a01b0384168383610f66565b505050565b5f336105e8858285610fb8565b6105f3858585611030565b506001949350505050565b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016300361064f5760405162461bcd60e51b815260040161064690611e2b565b60405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166106816111d7565b6001600160a01b0316146106a75760405162461bcd60e51b815260040161064690611e77565b6106b0816111f2565b604080515f808252602082019092526106cb91839190611293565b50565b5f336105078185856106e08383610d8b565b6106ea9190611ec3565b610db5565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036107375760405162461bcd60e51b815260040161064690611e2b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166107696111d7565b6001600160a01b03161461078f5760405162461bcd60e51b815260040161064690611e77565b610798826111f2565b6107a482826001611293565b5050565b5f306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146108425760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608401610646565b505f8051602061208983398151915290565b5f54610100900460ff161580801561087257505f54600160ff909116105b8061088b5750303b15801561088b57505f5460ff166001145b6108ee5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610646565b5f805460ff19166001179055801561090f575f805461ff0019166101001790555b610957836040516020016109239190611ef9565b604051602081830303815290604052836040516020016109439190611ef9565b6040516020818303038152906040526113fd565b61095f61142d565b6001600160a01b0384166109865760405163d92e233d60e01b815260040160405180910390fd5b6040516370a0823160e01b81526001600160a01b038716906370a08231906109b2908790600401611bd7565b602060405180830381865afa1580156109cd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109f19190611f04565b50846001600160a01b031663bfe109286040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a529190611f1b565b60cd5f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550846001600160a01b031663b4a0bdf36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ab3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ad79190611f1b565b60c980546001600160a01b03199081166001600160a01b039384161790915560ca8054821689841617905560ce8054821688841617905560cb8054909116918616919091179055610b26610ed8565b8015610b6b575f805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6060609b805461047990611dd4565b60cb546001600160a01b03163314801590610c09575060c954604051631c86b03760e31b81526001600160a01b039091169063e43581b890610bc8903390600401611bd7565b602060405180830381865afa158015610be3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c079190611e0c565b155b15610c2757604051631eb49d6d60e11b815260040160405180910390fd5b60cb546106cb906001600160a01b031682611453565b5f3381610c4a8286610d8b565b905083811015610caa5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610646565b6105f38286868403610db5565b5f33610507818585611030565b60cb546001600160a01b03163314801590610d4b575060c954604051631c86b03760e31b81526001600160a01b039091169063e43581b890610d0a903390600401611bd7565b602060405180830381865afa158015610d25573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d499190611e0c565b155b15610d6957604051631eb49d6d60e11b815260040160405180910390fd5b60cb80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b039182165f90815260986020908152604080832093909416825291909152205490565b6001600160a01b038316610e175760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610646565b6001600160a01b038216610e785760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610646565b6001600160a01b038381165f8181526098602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60ce546040805163011a412160e61b815290515f926001600160a01b03169163469048409160048083019260209291908290030181865afa158015610f1f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f439190611f1b565b60cc80546001600160a01b0319166001600160a01b039290921691909117905550565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526105d6908490611511565b5f610fc38484610d8b565b90505f19811461102a578181101561101d5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610646565b61102a8484848403610db5565b50505050565b6001600160a01b0383166110945760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610646565b6001600160a01b0382166110f65760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610646565b6111018383836115e4565b6001600160a01b0383165f90815260976020526040902054818110156111785760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610646565b6001600160a01b038085165f8181526097602052604080822086860390559286168082529083902080548601905591515f805160206120d0833981519152906111c49086815260200190565b60405180910390a361102a848484611629565b5f80516020612089833981519152546001600160a01b031690565b60c9546001600160a01b031680158015906112755750604051631c86b03760e31b81526001600160a01b0382169063e43581b890611234903390600401611bd7565b602060405180830381865afa15801561124f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112739190611e0c565b155b156107a457604051633b8d9d7560e21b815260040160405180910390fd5b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156112c6576105d683611678565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611320575060408051601f3d908101601f1916820190925261131d91810190611f04565b60015b6113835760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610646565b5f8051602061208983398151915281146113f15760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610646565b506105d6838383611713565b5f54610100900460ff166114235760405162461bcd60e51b815260040161064690611f36565b6107a48282611737565b5f54610100900460ff1661051b5760405162461bcd60e51b815260040161064690611f36565b6001600160a01b0382166114a95760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610646565b6114b45f83836115e4565b8060995f8282546114c59190611ec3565b90915550506001600160a01b0382165f818152609760209081526040808320805486019055518481525f805160206120d0833981519152910160405180910390a36107a45f8383611629565b5f611565826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166117769092919063ffffffff16565b905080515f14806115855750808060200190518101906115859190611e0c565b6105d65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610646565b60cd546001600160a01b038481169116148061160d575060cc546001600160a01b038381169116145b156105d65760ca546105d6906001600160a01b03168383610f66565b60cd546001600160a01b03838116911614801590611655575060cb546001600160a01b03838116911614155b801561166957506001600160a01b03821615155b156105d6576105d6828261178c565b6001600160a01b0381163b6116e55760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610646565b5f8051602061208983398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61171c836118bc565b5f825111806117285750805b156105d65761102a83836118fb565b5f54610100900460ff1661175d5760405162461bcd60e51b815260040161064690611f36565b609a6117698382611fcc565b50609b6105d68282611fcc565b606061178484845f85611927565b949350505050565b6001600160a01b0382166117ec5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610646565b6117f7825f836115e4565b6001600160a01b0382165f908152609760205260409020548181101561186a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610646565b6001600160a01b0383165f8181526097602090815260408083208686039055609980548790039055518581529192915f805160206120d0833981519152910160405180910390a36105d6835f84611629565b6118c581611678565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a250565b606061192083836040518060600160405280602781526020016120a9602791396119fe565b9392505050565b6060824710156119885760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610646565b5f80866001600160a01b031685876040516119a39190611ef9565b5f6040518083038185875af1925050503d805f81146119dd576040519150601f19603f3d011682016040523d82523d5f602084013e6119e2565b606091505b50915091506119f387838387611a72565b979650505050505050565b60605f80856001600160a01b031685604051611a1a9190611ef9565b5f60405180830381855af49150503d805f8114611a52576040519150601f19603f3d011682016040523d82523d5f602084013e611a57565b606091505b5091509150611a6886838387611a72565b9695505050505050565b60608315611ae05782515f03611ad9576001600160a01b0385163b611ad95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610646565b5081611784565b6117848383815115611af55781518083602001fd5b8060405162461bcd60e51b815260040161064691905b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b6001600160a01b03811681146106cb575f80fd5b5f8060408385031215611b65575f80fd5b8235611b7081611b40565b946020939093013593505050565b5f805f60608486031215611b90575f80fd5b8335611b9b81611b40565b92506020840135611bab81611b40565b929592945050506040919091013590565b5f60208284031215611bcc575f80fd5b813561192081611b40565b6001600160a01b0391909116815260200190565b634e487b7160e01b5f52604160045260245ffd5b5f67ffffffffffffffff80841115611c1957611c19611beb565b604051601f8501601f19908116603f01168101908282118183101715611c4157611c41611beb565b81604052809350858152868686011115611c59575f80fd5b858560208301375f602087830101525050509392505050565b5f8060408385031215611c83575f80fd5b8235611c8e81611b40565b9150602083013567ffffffffffffffff811115611ca9575f80fd5b8301601f81018513611cb9575f80fd5b611cc885823560208401611bff565b9150509250929050565b5f82601f830112611ce1575f80fd5b61192083833560208501611bff565b5f805f805f60a08688031215611d04575f80fd5b8535611d0f81611b40565b94506020860135611d1f81611b40565b93506040860135611d2f81611b40565b9250606086013567ffffffffffffffff80821115611d4b575f80fd5b611d5789838a01611cd2565b93506080880135915080821115611d6c575f80fd5b50611d7988828901611cd2565b9150509295509295909350565b5f60208284031215611d96575f80fd5b5035919050565b5f8060408385031215611dae575f80fd5b8235611db981611b40565b91506020830135611dc981611b40565b809150509250929050565b600181811c90821680611de857607f821691505b602082108103611e0657634e487b7160e01b5f52602260045260245ffd5b50919050565b5f60208284031215611e1c575f80fd5b81518015158114611920575f80fd5b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8082018082111561050d57634e487b7160e01b5f52601160045260245ffd5b5f81518060208401855e5f93019283525090919050565b5f6119208284611ee2565b5f60208284031215611f14575f80fd5b5051919050565b5f60208284031215611f2b575f80fd5b815161192081611b40565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b601f8211156105d657805f5260205f20601f840160051c81016020851015611fa65750805b601f840160051c820191505b81811015611fc5575f8155600101611fb2565b5050505050565b815167ffffffffffffffff811115611fe657611fe6611beb565b611ffa81611ff48454611dd4565b84611f81565b602080601f83116001811461202d575f84156120165750858301515b5f19600386901b1c1916600185901b178555610b6b565b5f85815260208120601f198616915b8281101561205b5788860151825594840194600190910190840161203c565b508582101561207857878501515f19600388901b60f8161c191681555b5050505050600190811b0190555056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa26469706673582212207958b9802a88227484b59d2f640ca0ca22211ffb4a9f7d0ff450de7f26bf847e64736f6c63430008190033
Deployed Bytecode
0x608060405260043610610152575f3560e01c806370a08231116100be578063ae99c0ac11610078578063ae99c0ac14610391578063b4a0bdf3146103b0578063bfe10928146103cf578063d979f5aa146103ee578063dd62ed3e1461040d578063e534155d1461042c578063fc0c546a1461044b575f80fd5b806370a08231146102cd57806383b435891461030157806395d89b4114610320578063a0712d6814610334578063a457c2d714610353578063a9059cbb14610372575f80fd5b8063313ce5671161010f578063313ce567146102215780633659cfe61461023c578063395093511461025b578063469048401461027a5780634f1ef286146102a657806352d1902d146102b9575f80fd5b806306fdde0314610156578063095ea7b31461018057806313cf69dd146101af57806318160ddd146101c55780631ec82cb8146101e357806323b872dd14610202575b5f80fd5b348015610161575f80fd5b5061016a61046a565b6040516101779190611b0b565b60405180910390f35b34801561018b575f80fd5b5061019f61019a366004611b54565b6104fa565b6040519015158152602001610177565b3480156101ba575f80fd5b506101c3610513565b005b3480156101d0575f80fd5b506099545b604051908152602001610177565b3480156101ee575f80fd5b506101c36101fd366004611b7e565b61051d565b34801561020d575f80fd5b5061019f61021c366004611b7e565b6105db565b34801561022c575f80fd5b5060405160128152602001610177565b348015610247575f80fd5b506101c3610256366004611bbc565b6105fe565b348015610266575f80fd5b5061019f610275366004611b54565b6106ce565b348015610285575f80fd5b5060cc54610299906001600160a01b031681565b6040516101779190611bd7565b6101c36102b4366004611c72565b6106ef565b3480156102c4575f80fd5b506101d56107a8565b3480156102d8575f80fd5b506101d56102e7366004611bbc565b6001600160a01b03165f9081526097602052604090205490565b34801561030c575f80fd5b506101c361031b366004611cf0565b610854565b34801561032b575f80fd5b5061016a610b73565b34801561033f575f80fd5b506101c361034e366004611d86565b610b82565b34801561035e575f80fd5b5061019f61036d366004611b54565b610c3d565b34801561037d575f80fd5b5061019f61038c366004611b54565b610cb7565b34801561039c575f80fd5b5060ce54610299906001600160a01b031681565b3480156103bb575f80fd5b5060c954610299906001600160a01b031681565b3480156103da575f80fd5b5060cd54610299906001600160a01b031681565b3480156103f9575f80fd5b506101c3610408366004611bbc565b610cc4565b348015610418575f80fd5b506101d5610427366004611d9d565b610d8b565b348015610437575f80fd5b5060cb54610299906001600160a01b031681565b348015610456575f80fd5b5060ca54610299906001600160a01b031681565b6060609a805461047990611dd4565b80601f01602080910402602001604051908101604052809291908181526020018280546104a590611dd4565b80156104f05780601f106104c7576101008083540402835291602001916104f0565b820191905f5260205f20905b8154815290600101906020018083116104d357829003601f168201915b5050505050905090565b5f33610507818585610db5565b60019150505b92915050565b61051b610ed8565b565b60cb546001600160a01b031633148015906105a4575060c954604051631c86b03760e31b81526001600160a01b039091169063e43581b890610563903390600401611bd7565b602060405180830381865afa15801561057e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a29190611e0c565b155b156105c257604051631eb49d6d60e11b815260040160405180910390fd5b6105d66001600160a01b0384168383610f66565b505050565b5f336105e8858285610fb8565b6105f3858585611030565b506001949350505050565b6001600160a01b037f000000000000000000000000f0d2dbe40d56616470a756d8457697b604bdc91a16300361064f5760405162461bcd60e51b815260040161064690611e2b565b60405180910390fd5b7f000000000000000000000000f0d2dbe40d56616470a756d8457697b604bdc91a6001600160a01b03166106816111d7565b6001600160a01b0316146106a75760405162461bcd60e51b815260040161064690611e77565b6106b0816111f2565b604080515f808252602082019092526106cb91839190611293565b50565b5f336105078185856106e08383610d8b565b6106ea9190611ec3565b610db5565b6001600160a01b037f000000000000000000000000f0d2dbe40d56616470a756d8457697b604bdc91a1630036107375760405162461bcd60e51b815260040161064690611e2b565b7f000000000000000000000000f0d2dbe40d56616470a756d8457697b604bdc91a6001600160a01b03166107696111d7565b6001600160a01b03161461078f5760405162461bcd60e51b815260040161064690611e77565b610798826111f2565b6107a482826001611293565b5050565b5f306001600160a01b037f000000000000000000000000f0d2dbe40d56616470a756d8457697b604bdc91a16146108425760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c6044820152771b1959081d1a1c9bdd59da0819195b1959d85d1958d85b1b60421b6064820152608401610646565b505f8051602061208983398151915290565b5f54610100900460ff161580801561087257505f54600160ff909116105b8061088b5750303b15801561088b57505f5460ff166001145b6108ee5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610646565b5f805460ff19166001179055801561090f575f805461ff0019166101001790555b610957836040516020016109239190611ef9565b604051602081830303815290604052836040516020016109439190611ef9565b6040516020818303038152906040526113fd565b61095f61142d565b6001600160a01b0384166109865760405163d92e233d60e01b815260040160405180910390fd5b6040516370a0823160e01b81526001600160a01b038716906370a08231906109b2908790600401611bd7565b602060405180830381865afa1580156109cd573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109f19190611f04565b50846001600160a01b031663bfe109286040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a2e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a529190611f1b565b60cd5f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550846001600160a01b031663b4a0bdf36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ab3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ad79190611f1b565b60c980546001600160a01b03199081166001600160a01b039384161790915560ca8054821689841617905560ce8054821688841617905560cb8054909116918616919091179055610b26610ed8565b8015610b6b575f805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050505050565b6060609b805461047990611dd4565b60cb546001600160a01b03163314801590610c09575060c954604051631c86b03760e31b81526001600160a01b039091169063e43581b890610bc8903390600401611bd7565b602060405180830381865afa158015610be3573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c079190611e0c565b155b15610c2757604051631eb49d6d60e11b815260040160405180910390fd5b60cb546106cb906001600160a01b031682611453565b5f3381610c4a8286610d8b565b905083811015610caa5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610646565b6105f38286868403610db5565b5f33610507818585611030565b60cb546001600160a01b03163314801590610d4b575060c954604051631c86b03760e31b81526001600160a01b039091169063e43581b890610d0a903390600401611bd7565b602060405180830381865afa158015610d25573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d499190611e0c565b155b15610d6957604051631eb49d6d60e11b815260040160405180910390fd5b60cb80546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b039182165f90815260986020908152604080832093909416825291909152205490565b6001600160a01b038316610e175760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610646565b6001600160a01b038216610e785760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610646565b6001600160a01b038381165f8181526098602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60ce546040805163011a412160e61b815290515f926001600160a01b03169163469048409160048083019260209291908290030181865afa158015610f1f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f439190611f1b565b60cc80546001600160a01b0319166001600160a01b039290921691909117905550565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526105d6908490611511565b5f610fc38484610d8b565b90505f19811461102a578181101561101d5760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610646565b61102a8484848403610db5565b50505050565b6001600160a01b0383166110945760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610646565b6001600160a01b0382166110f65760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610646565b6111018383836115e4565b6001600160a01b0383165f90815260976020526040902054818110156111785760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610646565b6001600160a01b038085165f8181526097602052604080822086860390559286168082529083902080548601905591515f805160206120d0833981519152906111c49086815260200190565b60405180910390a361102a848484611629565b5f80516020612089833981519152546001600160a01b031690565b60c9546001600160a01b031680158015906112755750604051631c86b03760e31b81526001600160a01b0382169063e43581b890611234903390600401611bd7565b602060405180830381865afa15801561124f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112739190611e0c565b155b156107a457604051633b8d9d7560e21b815260040160405180910390fd5b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff16156112c6576105d683611678565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611320575060408051601f3d908101601f1916820190925261131d91810190611f04565b60015b6113835760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b6064820152608401610646565b5f8051602061208983398151915281146113f15760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b6064820152608401610646565b506105d6838383611713565b5f54610100900460ff166114235760405162461bcd60e51b815260040161064690611f36565b6107a48282611737565b5f54610100900460ff1661051b5760405162461bcd60e51b815260040161064690611f36565b6001600160a01b0382166114a95760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610646565b6114b45f83836115e4565b8060995f8282546114c59190611ec3565b90915550506001600160a01b0382165f818152609760209081526040808320805486019055518481525f805160206120d0833981519152910160405180910390a36107a45f8383611629565b5f611565826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166117769092919063ffffffff16565b905080515f14806115855750808060200190518101906115859190611e0c565b6105d65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610646565b60cd546001600160a01b038481169116148061160d575060cc546001600160a01b038381169116145b156105d65760ca546105d6906001600160a01b03168383610f66565b60cd546001600160a01b03838116911614801590611655575060cb546001600160a01b03838116911614155b801561166957506001600160a01b03821615155b156105d6576105d6828261178c565b6001600160a01b0381163b6116e55760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608401610646565b5f8051602061208983398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b61171c836118bc565b5f825111806117285750805b156105d65761102a83836118fb565b5f54610100900460ff1661175d5760405162461bcd60e51b815260040161064690611f36565b609a6117698382611fcc565b50609b6105d68282611fcc565b606061178484845f85611927565b949350505050565b6001600160a01b0382166117ec5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610646565b6117f7825f836115e4565b6001600160a01b0382165f908152609760205260409020548181101561186a5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610646565b6001600160a01b0383165f8181526097602090815260408083208686039055609980548790039055518581529192915f805160206120d0833981519152910160405180910390a36105d6835f84611629565b6118c581611678565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a250565b606061192083836040518060600160405280602781526020016120a9602791396119fe565b9392505050565b6060824710156119885760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610646565b5f80866001600160a01b031685876040516119a39190611ef9565b5f6040518083038185875af1925050503d805f81146119dd576040519150601f19603f3d011682016040523d82523d5f602084013e6119e2565b606091505b50915091506119f387838387611a72565b979650505050505050565b60605f80856001600160a01b031685604051611a1a9190611ef9565b5f60405180830381855af49150503d805f8114611a52576040519150601f19603f3d011682016040523d82523d5f602084013e611a57565b606091505b5091509150611a6886838387611a72565b9695505050505050565b60608315611ae05782515f03611ad9576001600160a01b0385163b611ad95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610646565b5081611784565b6117848383815115611af55781518083602001fd5b8060405162461bcd60e51b815260040161064691905b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b6001600160a01b03811681146106cb575f80fd5b5f8060408385031215611b65575f80fd5b8235611b7081611b40565b946020939093013593505050565b5f805f60608486031215611b90575f80fd5b8335611b9b81611b40565b92506020840135611bab81611b40565b929592945050506040919091013590565b5f60208284031215611bcc575f80fd5b813561192081611b40565b6001600160a01b0391909116815260200190565b634e487b7160e01b5f52604160045260245ffd5b5f67ffffffffffffffff80841115611c1957611c19611beb565b604051601f8501601f19908116603f01168101908282118183101715611c4157611c41611beb565b81604052809350858152868686011115611c59575f80fd5b858560208301375f602087830101525050509392505050565b5f8060408385031215611c83575f80fd5b8235611c8e81611b40565b9150602083013567ffffffffffffffff811115611ca9575f80fd5b8301601f81018513611cb9575f80fd5b611cc885823560208401611bff565b9150509250929050565b5f82601f830112611ce1575f80fd5b61192083833560208501611bff565b5f805f805f60a08688031215611d04575f80fd5b8535611d0f81611b40565b94506020860135611d1f81611b40565b93506040860135611d2f81611b40565b9250606086013567ffffffffffffffff80821115611d4b575f80fd5b611d5789838a01611cd2565b93506080880135915080821115611d6c575f80fd5b50611d7988828901611cd2565b9150509295509295909350565b5f60208284031215611d96575f80fd5b5035919050565b5f8060408385031215611dae575f80fd5b8235611db981611b40565b91506020830135611dc981611b40565b809150509250929050565b600181811c90821680611de857607f821691505b602082108103611e0657634e487b7160e01b5f52602260045260245ffd5b50919050565b5f60208284031215611e1c575f80fd5b81518015158114611920575f80fd5b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b8082018082111561050d57634e487b7160e01b5f52601160045260245ffd5b5f81518060208401855e5f93019283525090919050565b5f6119208284611ee2565b5f60208284031215611f14575f80fd5b5051919050565b5f60208284031215611f2b575f80fd5b815161192081611b40565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b601f8211156105d657805f5260205f20601f840160051c81016020851015611fa65750805b601f840160051c820191505b81811015611fc5575f8155600101611fb2565b5050505050565b815167ffffffffffffffff811115611fe657611fe6611beb565b611ffa81611ff48454611dd4565b84611f81565b602080601f83116001811461202d575f84156120165750858301515b5f19600386901b1c1916600185901b178555610b6b565b5f85815260208120601f198616915b8281101561205b5788860151825594840194600190910190840161203c565b508582101561207857878501515f19600388901b60f8161c191681555b5050505050600190811b0190555056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa26469706673582212207958b9802a88227484b59d2f640ca0ca22211ffb4a9f7d0ff450de7f26bf847e64736f6c63430008190033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.