Address Contract Verified
Address
0x997523eF97E0b0a5625Ed2C197e61250acF4e5F1
Balance
0 ETH
Nonce
1
Code Size
5166 bytes
Creator
0x4ad5d7bf...F31F at tx 0xbc04f874...40d502
Indexed Transactions
0
Contract Bytecode
5166 bytes
0x608060405234801561001057600080fd5b506004361061010a5760003560e01c80638da5cb5b116100a2578063db20563511610071578063db2056351461023e578063de6acf0714610251578063e30c397814610264578063e8da302c14610277578063f2fde38b1461028a57600080fd5b80638da5cb5b146101c3578063ae9a6808146101e8578063bc6cc41714610208578063d05166501461021b57600080fd5b80635920be59116100de5780635920be591461017257806370ae92d214610185578063715018a6146101b357806379ba5097146101bb57600080fd5b806233f1831461010f57806312d18ed6146101245780635343481614610137578063562beba81461014a575b600080fd5b61012261011d36600461105d565b61029d565b005b6101226101323660046110c4565b61039c565b61012261014536600461113c565b61063b565b61015d61015836600461117e565b6106e1565b60405190151581526020015b60405180910390f35b6101226101803660046111a8565b610729565b6101a561019336600461105d565b60066020526000908152604090205481565b604051908152602001610169565b61012261080f565b610122610845565b6000546001600160a01b03165b6040516001600160a01b039091168152602001610169565b6101a56101f636600461105d565b60046020526000908152604090205481565b61012261021636600461117e565b6108ce565b61015d61022936600461105d565b60076020526000908152604090205460ff1681565b6003546101d0906001600160a01b031681565b61012261025f36600461105d565b610a2e565b6001546101d0906001600160a01b031681565b610122610285366004611214565b610ad1565b61012261029836600461105d565b610be9565b6003546001600160a01b031633148015906102c357506000546001600160a01b03163314155b156102e15760405163015783e960e51b815260040160405180910390fd5b6001600160a01b0381166103085760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03811660009081526007602052604090205460ff161561034257604051632944b29f60e11b815260040160405180910390fd5b6001600160a01b0381166000818152600760209081526040808320805460ff1916600117905560069091528082205490519092917f6fc2e87560262acdf5646a9dc9ebc5f3759a13652694b46f365f6300151cae0f91a350565b6002805414156103f35760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064015b60405180910390fd5b600280556001600160a01b038416158061041457506001600160a01b038616155b156104325760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0386166000908152600460205260409020546104685760405163bc68df3f60e01b815260040160405180910390fd5b6001600160a01b03861660009081526007602052604090205460ff16156104a25760405163d5e5fc0560e01b815260040160405180910390fd5b6104ac86866106e1565b156104ca57604051630c8d9eab60e31b815260040160405180910390fd5b60408051602081018790526bffffffffffffffffffffffff19606087901b16918101919091526054810184905260009060740160405160208183030381529060405280519060200120905061056983838080602002602001604051908101604052809392919081815260200183836020028082843760009201829052506001600160a01b038d168152600460205260409020549250859150610cbb9050565b610586576040516309bde33960e01b815260040160405180910390fd5b6001600160a01b03871660008181526006602090815260408083205460058352818420908452825280832060088b901c845290915290208054600160ff8a161b1790556105d4908686610cd3565b6001600160a01b038781166000818152600660209081526040918290205482518b815291820189905293891692917f7844b7eab4ee04c913dcbd13470fe9a8a84a32d92b9622279e492da597fa658a910160405180910390a4505060016002555050505050565b6003546001600160a01b0316331480159061066157506000546001600160a01b03163314155b1561067f5760405163015783e960e51b815260040160405180910390fd5b808061069e5760405163521299a960e01b815260040160405180910390fd5b60005b818110156106db576106d38484838181106106be576106be611267565b905060200201602081019061011d919061105d565b6001016106a1565b50505050565b6001600160a01b038216600090815260066020908152604080832054600583528184209084528252808320600885901c8452909152902054600160ff83161b16151592915050565b6003546001600160a01b0316331480159061074f57506000546001600160a01b03163314155b1561076d5760405163015783e960e51b815260040160405180910390fd5b828061078c5760405163521299a960e01b815260040160405180910390fd5b8082146107ac5760405163c155fe2160e01b815260040160405180910390fd5b60005b81811015610807576107ff8686838181106107cc576107cc611267565b90506020020160208101906107e1919061105d565b8585848181106107f3576107f3611267565b905060200201356108ce565b6001016107af565b505050505050565b6000546001600160a01b031633146108395760405162461bcd60e51b81526004016103ea9061127d565b6108436000610d2a565b565b6001546001600160a01b03163314610870576040516305e05b4b60e31b815260040160405180910390fd5b6001546001600160a01b031661088581610d2a565b600180546001600160a01b03191690556040516000906001600160a01b038316907fb3d55174552271a4f1aaf36b72f50381e892171636b3fb5447fe00e995e7a37b908390a350565b6003546001600160a01b031633148015906108f457506000546001600160a01b03163314155b156109125760405163015783e960e51b815260040160405180910390fd5b6001600160a01b0382166109395760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b03821660009081526007602052604090205460ff1661097257604051638208cbe560e01b815260040160405180910390fd5b80610990576040516385ac2b9960e01b815260040160405180910390fd5b6001600160a01b0382166000908152600760209081526040808320805460ff19169055600690915281208054600192906109cb9084906112c8565b90915550506001600160a01b038216600081815260046020908152604080832085905560068252918290205491518481529192917fb1a0d85f7eede3dffd8899fd01f07018ef51ed64acfc3c5ea6f6feacc49367ba910160405180910390a35050565b6000546001600160a01b03163314610a585760405162461bcd60e51b81526004016103ea9061127d565b6001600160a01b038116610a7f5760405163d92e233d60e01b815260040160405180910390fd5b600380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907fb90308ba350dbc6bbbd7119f9ab447b4a8cf558e61f5584a52ed4b86cae3641890600090a35050565b6001600160a01b038316610af85760405163d92e233d60e01b815260040160405180910390fd5b8080610b175760405163b68370bb60e01b815260040160405180910390fd5b60005b81811015610be257610bda848483818110610b3757610b37611267565b9050602002810190610b4991906112e0565b610b5790602081019061105d565b858584818110610b6957610b69611267565b9050602002810190610b7b91906112e0565b6020013587878786818110610b9257610b92611267565b9050602002810190610ba491906112e0565b60400135888887818110610bba57610bba611267565b9050602002810190610bcc91906112e0565b610132906060810190611300565b600101610b1a565b5050505050565b6000546001600160a01b03163314610c135760405162461bcd60e51b81526004016103ea9061127d565b6001600160a01b038116610c3a5760405163d92e233d60e01b815260040160405180910390fd5b6000546001600160a01b0382811691161415610c695760405163d5e889bf60e01b815260040160405180910390fd5b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907fb3d55174552271a4f1aaf36b72f50381e892171636b3fb5447fe00e995e7a37b90600090a35050565b600082610cc88584610d7a565b1490505b9392505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610d25908490610dee565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600081815b8451811015610de6576000858281518110610d9c57610d9c611267565b60200260200101519050808311610dc25760008381526020829052604090209250610dd3565b600081815260208490526040902092505b5080610dde8161134a565b915050610d7f565b509392505050565b6000610e43826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610ec09092919063ffffffff16565b805190915015610d255780806020019051810190610e619190611365565b610d255760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016103ea565b6060610ecf8484600085610ed7565b949350505050565b606082471015610f385760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016103ea565b6001600160a01b0385163b610f8f5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103ea565b600080866001600160a01b03168587604051610fab91906113b3565b60006040518083038185875af1925050503d8060008114610fe8576040519150601f19603f3d011682016040523d82523d6000602084013e610fed565b606091505b5091509150610ffd828286611008565b979650505050505050565b60608315611017575081610ccc565b8251156110275782518084602001fd5b8160405162461bcd60e51b81526004016103ea91906113c5565b80356001600160a01b038116811461105857600080fd5b919050565b60006020828403121561106f57600080fd5b610ccc82611041565b60008083601f84011261108a57600080fd5b50813567ffffffffffffffff8111156110a257600080fd5b6020830191508360208260051b85010111156110bd57600080fd5b9250929050565b60008060008060008060a087890312156110dd57600080fd5b6110e687611041565b9550602087013594506110fb60408801611041565b935060608701359250608087013567ffffffffffffffff81111561111e57600080fd5b61112a89828a01611078565b979a9699509497509295939492505050565b6000806020838503121561114f57600080fd5b823567ffffffffffffffff81111561116657600080fd5b61117285828601611078565b90969095509350505050565b6000806040838503121561119157600080fd5b61119a83611041565b946020939093013593505050565b600080600080604085870312156111be57600080fd5b843567ffffffffffffffff808211156111d657600080fd5b6111e288838901611078565b909650945060208701359150808211156111fb57600080fd5b5061120887828801611078565b95989497509550505050565b60008060006040848603121561122957600080fd5b61123284611041565b9250602084013567ffffffffffffffff81111561124e57600080fd5b61125a86828701611078565b9497909650939450505050565b634e487b7160e01b600052603260045260246000fd5b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b600052601160045260246000fd5b600082198211156112db576112db6112b2565b500190565b60008235607e198336030181126112f657600080fd5b9190910192915050565b6000808335601e1984360301811261131757600080fd5b83018035915067ffffffffffffffff82111561133257600080fd5b6020019150600581901b36038213156110bd57600080fd5b600060001982141561135e5761135e6112b2565b5060010190565b60006020828403121561137757600080fd5b81518015158114610ccc57600080fd5b60005b838110156113a257818101518382015260200161138a565b838111156106db5750506000910152565b600082516112f6818460208701611387565b60208152600082518060208401526113e4816040850160208701611387565b601f01601f1916919091016040019291505056fea2646970667358221220e1cba48953efce86c9832d3a2fe4547fb07006881404d7eeaf3e19f7e58ed2f664736f6c634300080a0033
Verified Source Code Full Match
Compiler: v0.8.10+commit.fc410830
EVM: london
Optimization: Yes (200 runs)
Owner.sol 38 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "../oz/utils/Ownable.sol";
/** @title Extend OZ Ownable contract */
/// @author Paladin
contract Owner is Ownable {
address public pendingOwner;
event NewPendingOwner(address indexed previousPendingOwner, address indexed newPendingOwner);
error CannotBeOwner();
error CallerNotPendingOwner();
error ZeroAddress();
function transferOwnership(address newOwner) public override virtual onlyOwner {
if(newOwner == address(0)) revert ZeroAddress();
if(newOwner == owner()) revert CannotBeOwner();
address oldPendingOwner = pendingOwner;
pendingOwner = newOwner;
emit NewPendingOwner(oldPendingOwner, newOwner);
}
function acceptOwnership() public virtual {
if(msg.sender != pendingOwner) revert CallerNotPendingOwner();
address newOwner = pendingOwner;
_transferOwnership(pendingOwner);
pendingOwner = address(0);
emit NewPendingOwner(newOwner, address(0));
}
}
Errors.sol 74 lines
pragma solidity 0.8.10;
//SPDX-License-Identifier: MIT
library Errors {
// Common Errors
error ZeroAddress();
error NullAmount();
error CallerNotAllowed();
error IncorrectRewardToken();
error SameAddress();
error InequalArraySizes();
error EmptyArray();
error EmptyParameters();
error AlreadyInitialized();
error InvalidParameter();
error CannotRecoverToken();
error ForbiddenCall();
error Killed();
error AlreadyKilled();
error NotKilled();
error KillDelayExpired();
error KillDelayNotExpired();
// Merkle Errors
error MerkleRootNotUpdated();
error AlreadyClaimed();
error InvalidProof();
error EmptyMerkleRoot();
error IncorrectRewardAmount();
error MerkleRootFrozen();
error NotFrozen();
error AlreadyFrozen();
// Quest Errors
error CallerNotQuestBoard();
error IncorrectQuestID();
error IncorrectPeriod();
error TokenNotWhitelisted();
error QuestAlreadyListed();
error QuestNotListed();
error PeriodAlreadyUpdated();
error PeriodNotClosed();
error PeriodStillActive();
error PeriodNotListed();
error EmptyQuest();
error EmptyPeriod();
error ExpiredQuest();
error NoDistributorSet();
error DisitributorFail();
error InvalidGauge();
error InvalidQuestID();
error InvalidPeriod();
error ObjectiveTooLow();
error RewardPerVoteTooLow();
error IncorrectDuration();
error IncorrectAddDuration();
error IncorrectTotalRewardAmount();
error IncorrectAddedRewardAmount();
error IncorrectFeeAmount();
error CalletNotQuestCreator();
error LowerRewardPerVote();
error LowerObjective();
error AlreadyBlacklisted();
//Math
error NumberExceed48Bits();
}
Address.sol 222 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
Ownable.sol 76 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "./Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
MerkleProof.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/cryptography/MerkleProof.sol)
pragma solidity ^0.8.0;
/**
* @dev These functions deal with verification of Merkle Trees proofs.
*
* The proofs can be generated using the JavaScript library
* https://github.com/miguelmota/merkletreejs[merkletreejs].
* Note: the hashing algorithm should be keccak256 and pair sorting should be enabled.
*
* See `test/utils/cryptography/MerkleProof.test.js` for some examples.
*/
library MerkleProof {
/**
* @dev Returns true if a `leaf` can be proved to be a part of a Merkle tree
* defined by `root`. For this, a `proof` must be provided, containing
* sibling hashes on the branch from the leaf to the root of the tree. Each
* pair of leaves and each pair of pre-images are assumed to be sorted.
*/
function verify(
bytes32[] memory proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool) {
return processProof(proof, leaf) == root;
}
/**
* @dev Returns the rebuilt hash obtained by traversing a Merklee tree up
* from `leaf` using `proof`. A `proof` is valid if and only if the rebuilt
* hash matches the root of the tree. When processing the proof, the pairs
* of leafs & pre-images are assumed to be sorted.
*
* _Available since v4.4._
*/
function processProof(bytes32[] memory proof, bytes32 leaf) internal pure returns (bytes32) {
bytes32 computedHash = leaf;
for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];
if (computedHash <= proofElement) {
// Hash(current computed hash + current element of the proof)
computedHash = _efficientHash(computedHash, proofElement);
} else {
// Hash(current element of the proof + current computed hash)
computedHash = _efficientHash(proofElement, computedHash);
}
}
return computedHash;
}
function _efficientHash(bytes32 a, bytes32 b) private pure returns (bytes32 value) {
assembly {
mstore(0x00, a)
mstore(0x20, b)
value := keccak256(0x00, 0x40)
}
}
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../interfaces/IERC20.sol";
import "../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
ReentrancyGuard.sol 63 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
ExtraRewardsMultiMerkle.sol 253 lines
//██████╗ █████╗ ██╗ █████╗ ██████╗ ██╗███╗ ██╗
//██╔══██╗██╔══██╗██║ ██╔══██╗██╔══██╗██║████╗ ██║
//██████╔╝███████║██║ ███████║██║ ██║██║██╔██╗ ██║
//██╔═══╝ ██╔══██║██║ ██╔══██║██║ ██║██║██║╚██╗██║
//██║ ██║ ██║███████╗██║ ██║██████╔╝██║██║ ╚████║
//╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═╝╚═╝ ╚═══╝
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import "../oz/interfaces/IERC20.sol";
import "../oz/libraries/SafeERC20.sol";
import "../oz/utils/MerkleProof.sol";
import "../utils/Owner.sol";
import "../oz/utils/ReentrancyGuard.sol";
import "../utils/Errors.sol";
/** @title Extra Rewards Multi Merkle */
/// @author Paladin
/*
Contract holds ERC20 rewards
Handles multiple Roots & allows to freeze and update Roots
*/
contract ExtraRewardsMultiMerkle is Owner, ReentrancyGuard {
using SafeERC20 for IERC20;
// Storage
/** @notice Address allowed to freeze the Roots & update them */
address public rootManager;
/** @notice Merkle Root for each token */
mapping(address => bytes32) public merkleRoots;
/** @notice BitMap of claims for each token, updated with the nonce */
// token => nonce => claimedBitMap
// This is a packed array of booleans.
mapping(address => mapping(uint256 => mapping(uint256 => uint256))) private claimedBitMap;
/** @notice Current update nonce for the token */
mapping(address => uint256) public nonce;
/** @notice Frozen token (to block claim before updating the Merkle Root) */
mapping(address => bool) public frozen;
//Struct ClaimParams
struct ClaimParams {
address token;
uint256 index;
uint256 amount;
bytes32[] merkleProof;
}
// Events
/** @notice Event emitted when an user Claims */
event Claimed(
address indexed rewardToken,
uint256 index,
address indexed account,
uint256 amount,
uint256 indexed nonce
);
/** @notice Event emitted when a Merkle Root is updated */
event UpdateRoot(
address indexed rewardToken,
bytes32 merkleRoot,
uint256 indexed nonce
);
/** @notice Event emitted when a token is frozen */
event FrozenRoot(
address indexed rewardToken,
uint256 indexed nonce
);
/** @notice Event emitted when the Root Manager is updated */
event UpdateRootManager(
address indexed oldManager,
address indexed newManager
);
// Modifier
modifier onlyAllowed(){
if(msg.sender != rootManager && msg.sender != owner()) revert Errors.CallerNotAllowed();
_;
}
constructor(address _rootManager) {
rootManager = _rootManager;
}
/**
* @notice Checks if the rewards were claimed for an index
* @dev Checks if the rewards were claimed for an index for the current update
* @param token addredd of the token to claim
* @param index Index of the claim
* @return bool : true if already claimed
*/
function isClaimed(address token, uint256 index) public view returns (bool) {
uint256 claimedWordIndex = index >> 8;
uint256 claimedBitIndex = index & 0xff;
uint256 updateNonce = nonce[token];
uint256 claimedWord = claimedBitMap[token][updateNonce][claimedWordIndex];
uint256 mask = (1 << claimedBitIndex);
return claimedWord & mask != 0;
}
/**
* @dev Sets the rewards as claimed for the index on the given period
* @param token addredd of the token to claim
* @param index Index of the claim
*/
function _setClaimed(address token, uint256 index) private {
uint256 claimedWordIndex = index >> 8;
uint256 claimedBitIndex = index & 0xff;
uint256 updateNonce = nonce[token];
claimedBitMap[token][updateNonce][claimedWordIndex] |= (1 << claimedBitIndex);
}
/**
* @notice Claims rewards for a given token for the user
* @dev Claims the reward for an user for the current update of the Merkle Root for the given token
* @param token Address of the token to claim
* @param index Index in the Merkle Tree
* @param account Address of the user claiming the rewards
* @param amount Amount of rewards to claim
* @param merkleProof Proof to claim the rewards
*/
function claim(address token, uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) public nonReentrant {
if(account == address(0) || token == address(0)) revert Errors.ZeroAddress();
if(merkleRoots[token] == 0) revert Errors.MerkleRootNotUpdated();
if(frozen[token]) revert Errors.MerkleRootFrozen();
if(isClaimed(token, index)) revert Errors.AlreadyClaimed();
// Check that the given parameters match the given Proof
bytes32 node = keccak256(abi.encodePacked(index, account, amount));
if(!MerkleProof.verify(merkleProof, merkleRoots[token], node)) revert Errors.InvalidProof();
// Set the rewards as claimed for that period
// And transfer the rewards to the user
_setClaimed(token, index);
IERC20(token).safeTransfer(account, amount);
emit Claimed(token, index, account, amount, nonce[token]);
}
/**
* @notice Claims multiple rewards for a given list
* @dev Calls the claim() method for each entry in the claims array
* @param account Address of the user claiming the rewards
* @param claims List of ClaimParams struct data to claim
*/
function multiClaim(address account, ClaimParams[] calldata claims) external {
if(account == address(0)) revert Errors.ZeroAddress();
uint256 length = claims.length;
if(length == 0) revert Errors.EmptyParameters();
for(uint256 i; i < length;){
claim(claims[i].token, claims[i].index, account, claims[i].amount, claims[i].merkleProof);
unchecked{ ++i; }
}
}
/**
* @notice Freezes the given token
* @dev Freezes the given token, blocking claims for this token
* @param token Address of the token to freeze
*/
function freezeRoot(address token) public onlyAllowed {
if(token == address(0)) revert Errors.ZeroAddress();
if(frozen[token]) revert Errors.AlreadyFrozen();
frozen[token] = true;
emit FrozenRoot(token, nonce[token]);
}
/**
* @notice Freezes a list of tokens
* @dev Calls the freezeRoot() method for each entry in the tokens array
* @param tokens List of tokens to freeze
*/
function multiFreezeRoot(address[] calldata tokens) external onlyAllowed {
uint256 length = tokens.length;
if(length == 0) revert Errors.EmptyArray();
for(uint256 i; i < length;){
freezeRoot(tokens[i]);
unchecked{ ++i; }
}
}
/**
* @notice Udpates the Merkle Root for a given token
* @dev Updates the Merkle Root for a frozen token
* @param token Address of the token
* @param root Merkle Root
*/
function updateRoot(address token, bytes32 root) public onlyAllowed {
if(token == address(0)) revert Errors.ZeroAddress();
if(!frozen[token]) revert Errors.NotFrozen();
if(root == 0) revert Errors.EmptyMerkleRoot();
frozen[token] = false;
nonce[token] += 1;
merkleRoots[token] = root;
emit UpdateRoot(token, root, nonce[token]);
}
/**
* @notice Updates the Merkle Roots for a list of tokens
* @dev Calls the updateRoot() method for each entry in the tokens array
* @param tokens List of tokens to update
* @param roots Merkle Root for each given token
*/
function multiUpdateRoot(address[] calldata tokens, bytes32[] calldata roots) external onlyAllowed {
uint256 length = tokens.length;
if(length == 0) revert Errors.EmptyArray();
if(length != roots.length) revert Errors.InequalArraySizes();
for(uint256 i; i < length;){
updateRoot(tokens[i], roots[i]);
unchecked{ ++i; }
}
}
/**
* @notice Udpates the Root Manager
* @dev Udpates the Root Manager
* @param newManager Address of the new Root Manager
*/
function updateRootManager(address newManager) external onlyOwner {
if(newManager == address(0)) revert Errors.ZeroAddress();
address oldManager = rootManager;
rootManager = newManager;
emit UpdateRootManager(oldManager, newManager);
}
}
Read Contract
frozen 0xd0516650 → bool
isClaimed 0x562beba8 → bool
merkleRoots 0xae9a6808 → bytes32
nonce 0x70ae92d2 → uint256
owner 0x8da5cb5b → address
pendingOwner 0xe30c3978 → address
rootManager 0xdb205635 → address
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
acceptOwnership 0x79ba5097
No parameters
claim 0x12d18ed6
address token
uint256 index
address account
uint256 amount
bytes32[] merkleProof
freezeRoot 0x0033f183
address token
multiClaim 0x3702656f
address account
tuple[] claims
multiFreezeRoot 0x53434816
address[] tokens
multiUpdateRoot 0x5920be59
address[] tokens
bytes32[] roots
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
updateRoot 0xbc6cc417
address token
bytes32 root
updateRootManager 0xde6acf07
address newManager
Token Balances (2)
View Transfers →Recent Transactions
No transactions found for this address