Address Contract Verified
Address
0x0F8d011aEc647ECD601dE4e3CD7774BeB03b4507
Balance
0.228620 ETH
Nonce
1
Code Size
4354 bytes
Creator
0x44B772A5...5eDE at tx 0x8461f275...224ae8
Indexed Transactions
0
Contract Bytecode
4354 bytes
0x608080604052600436101561001c575b50361561001a575f80fd5b005b5f3560e01c90816301ffc9a714610cd15750806306575c8914610cb4578063157c5bb414610b7c5780632194f3a214610b56578063248a9ca314610b2a5780632f2ff15d14610aee5780632fde382614610a5157806336568abe14610a0a5780633c87ca36146108aa5780635157347a1461066c57806371af9bf51461060f57806375b238fc146105d55780637d6f0d5f1461051457806391d14854146104cb578063932b37e0146104a1578063a217fddf14610487578063b683454a146101a4578063cabb45491461016a578063d547741f1461012e5763fdea8e0b14610104575f61000f565b3461012a575f36600319011261012a5760206001600160a01b0360025416604051908152f35b5f80fd5b3461012a57604036600319011261012a5761001a60043561014d610dbf565b90805f525f602052610165600160405f200154610f1f565b610fbd565b3461012a575f36600319011261012a5760206040517f28d695c7dfc0dc20c36b38cc22e861d8a3c0da73ef3975e85a4bf12193642a5c8152f35b3461012a57604036600319011261012a5760043567ffffffffffffffff811161012a576101d5903690600401610d24565b9060243567ffffffffffffffff811161012a576101f6903690600401610d24565b90927f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005c6104755760017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d8015801561046b575b610459575f5b81811061027d575f7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f005d005b610288818386610e19565b35805f52600660205260405f2054421061045057335f52600560205260405f20815f5260205260405f20906102be838689610e61565b5f9291925b8181106102d95750505050506001905b01610251565b6102ec6102e7828487610e19565b610e3d565b906001600160a01b0382165f528560205260405f208054908115610445575f9055846001600160a01b03841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee036104305750804710610410575f80808084335af13d1561040b573d67ffffffffffffffff81116103f75760405190601f1967ffffffffffffffff601f83018216603f0182168401908111908411176103f757603f81601f8401160116820160405281525f60203d92013e5b156103e55760019285915b6001600160a01b036040519216825260208201527f4cf9aafe8782e9501b8091a02dd67093b00ac91e6ea03c5174b00fce63610d7760403392a35b016102c3565b60405163d6bda27560e01b8152600490fd5b634e487b7160e01b5f52604160045260245ffd5b610399565b60405163cf47918160e01b81524760048201526024810191909152604490fd5b9092836104406001953384611030565b6103a4565b5050600191506103df565b506001906102d3565b604051635cb045db60e01b8152600490fd5b508181141561024b565b604051633ee5aeb560e01b8152600490fd5b3461012a575f36600319011261012a5760206040515f8152f35b3461012a57602036600319011261012a576004355f526006602052602060405f2054604051908152f35b3461012a57604036600319011261012a576104e4610dbf565b6004355f525f6020526001600160a01b0360405f2091165f52602052602060ff60405f2054166040519015158152f35b3461012a57602036600319011261012a5761052d610dd5565b610535610ea6565b6003546001600160a01b03808316929190811683156105c3578381146105b157604080516001600160a01b03928316815293909116602084015273ffffffffffffffffffffffffffffffffffffffff19927fe22b566ac7db56412e2e041c88a7fd3151151ad6c6647e954f9bdc054bcb780e9190a11617600355005b604051631310759d60e11b8152600490fd5b60405163d92e233d60e01b8152600490fd5b3461012a575f36600319011261012a5760206040517fdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec428152f35b3461012a57606036600319011261012a57610628610dd5565b604435906001600160a01b039081831680930361012a57165f52600560205260405f206024355f5260205260405f20905f52602052602060405f2054604051908152f35b3461012a57604036600319011261012a5767ffffffffffffffff60043581811161012a5761069e903690600401610d24565b60249283359080821161012a573660238301121561012a57816004013590811161012a57848201906006928636918360061b01011161012a576001600160a01b0390816002541633036108985784156104595780850361088657600454805f526020976006895260405f2054804210156107e9575b505050600454945f5b81811061072557005b836107346102e783858c610e19565b169081156105c357815f5260058a5260405f20885f528a5260405f208a61075c83878a610e51565b0135908661076e6102e785898c610e51565b165f528b5261078260405f20918254610e0c565b9055875f52868a5260405f205461079a828689610e51565b92604051918252833587811680910361012a576060838e6001977faadf833049536ac3aa88b2c85dd33ab3f699f66f736255042a909402f576d448948f9783015201356040820152a30161071c565b6107f38142610deb565b9160015492831561087257839004936001850180951161085e578461081791610e0c565b938460045583810293818504149015171561084b57509061083791610e0c565b905f526006885260405f2055878080610713565b634e487b7160e01b5f9081526011600452fd5b50634e487b7160e01b5f9081526011600452fd5b50634e487b7160e01b5f9081526012600452fd5b60405163512509d360e11b8152600490fd5b6040516392ed0e8160e01b8152600490fd5b3461012a576108b836610d55565b92916108c79695919496610ea6565b81156109f8578381148015906109ee575b610886575f5b8281106108e757005b6108f56102e782858a610e19565b610900828487610e61565b909161090d84898b610e61565b8084929403610886576001600160a01b0383165f52600560205260405f208d5f5260205260405f20915f5b81811061094e57505050505050506001016108de565b807ff8fac52ac2d09488c8bd1a54a727e4d3fe3c827e9ee3174754fc48d0a08b979a6109806102e7600194868c610e19565b61098b83878b610e19565b35906001600160a01b0381165f528760205260405f206109ac838254610deb565b90556109c4826001600160a01b036003541683611030565b604080516001600160a01b038b81168252929092166020830152810191909152606090a101610938565b50818414156108d8565b604051630f59b9ff60e01b8152600490fd5b3461012a57604036600319011261012a57610a23610dbf565b336001600160a01b03821603610a3f5761001a90600435610fbd565b60405163334bd91960e11b8152600490fd5b3461012a57602036600319011261012a57610a6a610dd5565b610a72610ea6565b6002546001600160a01b03808316929190811683156105c3578381146105b157604080516001600160a01b03928316815293909116602084015273ffffffffffffffffffffffffffffffffffffffff19927f42e6b4d0f422db8acba71d0435d0dd4e46fadb4a2d99683b66eded85126fb2859190a11617600255005b3461012a57604036600319011261012a5761001a600435610b0d610dbf565b90805f525f602052610b25600160405f200154610f1f565b610f40565b3461012a57602036600319011261012a576004355f525f6020526020600160405f200154604051908152f35b3461012a575f36600319011261012a5760206001600160a01b0360035416604051908152f35b3461012a57610b8a36610d55565b9291610b999695919496610ea6565b81156109f857838114801590610caa575b610886575f5b828110610bb957005b610bc76102e782858a610e19565b610bd2828487610e61565b9091610bdf84898b610e61565b8084929403610886576001600160a01b0383165f52600560205260405f208d5f5260205260405f20915f5b818110610c205750505050505050600101610bb0565b807fd5607305373f2912fe1072f6a6796e29747201e0388e184e311884fec5fd04a8610c526102e7600194868c610e19565b610c5d83878b610e19565b35906001600160a01b0381165f528760205260405f20610c7e838254610e0c565b9055604080516001600160a01b038b81168252929092166020830152810191909152606090a101610c0a565b5081841415610baa565b3461012a575f36600319011261012a576020600454604051908152f35b3461012a57602036600319011261012a576004359063ffffffff60e01b821680920361012a57602091637965db0b60e01b8114908115610d13575b5015158152f35b6301ffc9a760e01b14905083610d0c565b9181601f8401121561012a5782359167ffffffffffffffff831161012a576020808501948460051b01011161012a57565b608060031982011261012a5767ffffffffffffffff9160043583811161012a5782610d8291600401610d24565b939093926024359260443583811161012a5782610da191600401610d24565b9390939260643591821161012a57610dbb91600401610d24565b9091565b602435906001600160a01b038216820361012a57565b600435906001600160a01b038216820361012a57565b91908203918211610df857565b634e487b7160e01b5f52601160045260245ffd5b91908201809211610df857565b9190811015610e295760051b0190565b634e487b7160e01b5f52603260045260245ffd5b356001600160a01b038116810361012a5790565b9190811015610e295760061b0190565b9190811015610e295760051b81013590601e198136030182121561012a57019081359167ffffffffffffffff831161012a576020018260051b3603811361012a579190565b335f9081527f5cbfc8ee58ca47855df7bcf648dd304ddb6b932f9b87878bdf6318d7ec7ee5b760205260409020547fdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec429060ff1615610f015750565b6044906040519063e2517d3f60e01b82523360048301526024820152fd5b805f525f60205260405f20335f5260205260ff60405f20541615610f015750565b90815f525f6020526001600160a01b0360405f20911690815f5260205260ff60405f205416155f14610fb757815f525f60205260405f20815f5260205260405f20600160ff1982541617905533917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d5f80a4600190565b50505f90565b90815f525f6020526001600160a01b0360405f20911690815f5260205260ff60405f2054165f14610fb757815f525f60205260405f20815f5260205260405f2060ff19815416905533917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b5f80a4600190565b9160405190602082019063a9059cbb60e01b82526001600160a01b038094166024840152604483015260448252608082019082821067ffffffffffffffff8311176103f7576020925f92604052519082865af1156110c1575f513d6110b857508082163b155b61109e575050565b604051635274afe760e01b81529116600482015260249150fd5b60011415611096565b6040513d5f823e3d90fdfea2646970667358221220d0bb36819da3e5de4f748c0be16ab593cced11d3d381f7577370d466e0394dfe64736f6c63430008190033
Verified Source Code Full Match
Compiler: v0.8.25+commit.b61c2a91
EVM: cancun
Optimization: Yes (800 runs)
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 199 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
ReentrancyGuardTransient.sol 61 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuardTransient.sol)
pragma solidity ^0.8.24;
import {TransientSlot} from "./TransientSlot.sol";
/**
* @dev Variant of {ReentrancyGuard} that uses transient storage.
*
* NOTE: This variant only works on networks where EIP-1153 is available.
*
* _Available since v5.1._
*/
abstract contract ReentrancyGuardTransient {
using TransientSlot for *;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
/**
* @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
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true);
}
function _nonReentrantAfter() private {
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false);
}
/**
* @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 REENTRANCY_GUARD_STORAGE.asBoolean().tload();
}
}
TransientSlot.sol 183 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/TransientSlot.sol)
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
pragma solidity ^0.8.24;
/**
* @dev Library for reading and writing value-types to specific transient storage slots.
*
* Transient slots are often used to store temporary values that are removed after the current transaction.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* * Example reading and writing values using transient storage:
* ```solidity
* contract Lock {
* using TransientSlot for *;
*
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier locked() {
* require(!_LOCK_SLOT.asBoolean().tload());
*
* _LOCK_SLOT.asBoolean().tstore(true);
* _;
* _LOCK_SLOT.asBoolean().tstore(false);
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library TransientSlot {
/**
* @dev UDVT that represent a slot holding a address.
*/
type AddressSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a AddressSlot.
*/
function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
return AddressSlot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a bool.
*/
type BooleanSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a BooleanSlot.
*/
function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
return BooleanSlot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a bytes32.
*/
type Bytes32Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Bytes32Slot.
*/
function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
return Bytes32Slot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a uint256.
*/
type Uint256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Uint256Slot.
*/
function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
return Uint256Slot.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a int256.
*/
type Int256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Int256Slot.
*/
function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
return Int256Slot.wrap(slot);
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(AddressSlot slot) internal view returns (address value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(AddressSlot slot, address value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(BooleanSlot slot) internal view returns (bool value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(BooleanSlot slot, bool value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Bytes32Slot slot, bytes32 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Uint256Slot slot) internal view returns (uint256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Uint256Slot slot, uint256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Int256Slot slot) internal view returns (int256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Int256Slot slot, int256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
}
Claims.sol 277 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { ReentrancyGuardTransient } from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
import { IClaims, ClaimInfo } from "./interfaces/IClaims.sol";
import { ETH, InvalidData, ArrayLengthMismatch, ZeroAddress, IdenticalValue, ZeroLengthArray } from "./utils/Common.sol";
/// @title Claims contract
/// @notice Implements the claiming of the leader's commissions
contract Claims is IClaims, AccessControl, ReentrancyGuardTransient {
using SafeERC20 for IERC20;
using Address for address payable;
/// @dev The constant value helps in calculating time
uint256 private ONE_WEEK_SECONDS = 604800;
/// NOTE: keccak256("COMMISSIONS_MANAGER")
bytes32 public constant COMMISSIONS_MANAGER = 0x28d695c7dfc0dc20c36b38cc22e861d8a3c0da73ef3975e85a4bf12193642a5c;
/// @dev keccak256("ADMIN")
bytes32 public constant ADMIN_ROLE = 0xdf8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec42;
/// @notice Returns the address of the presale contract
address public presale;
/// @notice The address of funds wallet
address public fundsWallet;
/// @notice The current week number
uint256 public currentWeek;
/// @notice Stores the claim amount of token in a week of the user
mapping(address leader => mapping(uint256 week => mapping(IERC20 token => uint256 commission)))
public pendingClaims;
/// @notice Stores the end time of the given week number
mapping(uint256 week => uint256 endTime) public endTimes;
/// @dev Emitted when claim amount is set for the addresses
event ClaimSet(address indexed to, uint256 indexed week, uint256 endTime, ClaimInfo claimInfo);
/// @dev Emitted when claim amount is claimed
event FundsClaimed(address indexed by, IERC20 token, uint256 indexed week, uint256 amount);
/// @dev Emitted when address of funds wallet is updated
event FundsWalletUpdated(address oldFundsWallet, address newFundsWallet);
/// @dev Emitted when token presale contract is updated
event PresaleUpdated(address prevAddress, address newAddress);
/// @dev Emitted when claim is revoked for the user
event ClaimRevoked(address leader, IERC20 token, uint256 amount);
/// @dev Emitted when claim is added for the user
event ClaimsUpdated(address leader, IERC20 token, uint256 amount);
/// @notice Thrown when caller is not presale contract
error OnlyPresale();
/// @dev Constructor
/// @param fundsWalletAddress The address of funds Wallet
/// @param weekNumber The new week number
constructor(address fundsWalletAddress, uint256 weekNumber) {
if (fundsWalletAddress == address(0)) {
revert ZeroAddress();
}
fundsWallet = fundsWalletAddress;
_setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
_setRoleAdmin(COMMISSIONS_MANAGER, ADMIN_ROLE);
_grantRole(ADMIN_ROLE, msg.sender);
currentWeek = weekNumber;
endTimes[weekNumber] = block.timestamp + ONE_WEEK_SECONDS;
}
/// @inheritdoc IClaims
function addClaimInfo(address[] calldata to, ClaimInfo[] calldata claims) external {
if (msg.sender != presale) {
revert OnlyPresale();
}
uint256 toLength = to.length;
if (toLength == 0) {
revert InvalidData();
}
if (toLength != claims.length) {
revert ArrayLengthMismatch();
}
uint256 prevEndTime = endTimes[currentWeek];
if (block.timestamp >= prevEndTime) {
uint256 weeksElapsed = ((block.timestamp - prevEndTime) / ONE_WEEK_SECONDS) + 1;
currentWeek += weeksElapsed;
endTimes[currentWeek] = prevEndTime + (weeksElapsed * ONE_WEEK_SECONDS);
}
uint256 week = currentWeek;
for (uint256 i; i < toLength; ++i) {
address leader = to[i];
if (leader == address(0)) {
revert ZeroAddress();
}
mapping(IERC20 => uint256) storage claimInfo = pendingClaims[leader][week];
claimInfo[claims[i].token] += claims[i].amount;
emit ClaimSet({ to: leader, week: week, endTime: endTimes[week], claimInfo: claims[i] });
}
}
/// @notice Revokes leader claim for the given token
/// @param leaders The addresses of the leaders
/// @param tokens Tokens of the leader whose claims will be revoked
/// @param amounts The revoke amount of each token of the leader
function revokeLeaderClaim(
address[] calldata leaders,
uint256 week,
IERC20[][] calldata tokens,
uint256[][] calldata amounts
) external onlyRole(ADMIN_ROLE) {
_updateOrRevokeClaim(leaders, tokens, amounts, week, true);
}
/// @notice Updates leader claim for the given token
/// @param leaders The addresses of the leaders
/// @param tokens Tokens of the leader whose claims will be revoked
/// @param amounts The revoke amount of each token of the leader
function updateClaims(
address[] calldata leaders,
uint256 week,
IERC20[][] calldata tokens,
uint256[][] calldata amounts
) external onlyRole(ADMIN_ROLE) {
_updateOrRevokeClaim(leaders, tokens, amounts, week, false);
}
/// @notice Updates presale contract address in claims
/// @param newPresale The address of the presale contract
function updatePresaleAddress(address newPresale) external onlyRole(ADMIN_ROLE) {
address oldPresaleAddress = presale;
if (newPresale == address(0)) {
revert ZeroAddress();
}
if (oldPresaleAddress == newPresale) {
revert IdenticalValue();
}
emit PresaleUpdated({ prevAddress: oldPresaleAddress, newAddress: newPresale });
presale = newPresale;
}
/// @notice Changes funds wallet to a new address
/// @param newFundsWallet The address of the new funds wallet
function changeFundsWallet(address newFundsWallet) external onlyRole(ADMIN_ROLE) {
address oldFundsWallet = fundsWallet;
if (newFundsWallet == address(0)) {
revert ZeroAddress();
}
if (oldFundsWallet == newFundsWallet) {
revert IdenticalValue();
}
emit FundsWalletUpdated({ oldFundsWallet: oldFundsWallet, newFundsWallet: newFundsWallet });
fundsWallet = newFundsWallet;
}
/// @notice Claims the amount in a given weeks
/// @param claimWeeks The array of weeks for which you want to claim
/// @param tokens Tokens used for buying in each week
function claimAll(uint256[] calldata claimWeeks, IERC20[][] calldata tokens) external nonReentrant {
uint256 weeksLength = claimWeeks.length;
if (weeksLength == 0 || weeksLength != tokens.length) {
revert InvalidData();
}
for (uint256 i; i < weeksLength; ++i) {
uint256 week = claimWeeks[i];
if (block.timestamp < endTimes[week]) {
continue;
}
mapping(IERC20 => uint256) storage claims = pendingClaims[msg.sender][week];
IERC20[] calldata token = tokens[i];
for (uint256 j; j < token.length; ++j) {
IERC20 currentToken = token[j];
uint256 amount = claims[currentToken];
if (amount == 0) {
continue;
}
delete claims[currentToken];
if (currentToken == ETH) {
payable(msg.sender).sendValue(amount);
} else {
currentToken.safeTransfer(msg.sender, amount);
}
emit FundsClaimed({ by: msg.sender, token: currentToken, week: week, amount: amount });
}
}
}
/// @dev Revokes or updates leader claims for the given token
/// @param leaders The addresses of the leaders
/// @param tokens Tokens of the leader whose claims will be revoked
/// @param amounts The revoke amount of each token of the leader
/// @param isRevoke Boolean for revoke or update claims
function _updateOrRevokeClaim(
address[] calldata leaders,
IERC20[][] calldata tokens,
uint256[][] calldata amounts,
uint256 week,
bool isRevoke
) private {
uint256 leadersLength = leaders.length;
if (leadersLength == 0) {
revert ZeroLengthArray();
}
if (tokens.length != amounts.length || amounts.length != leadersLength) {
revert ArrayLengthMismatch();
}
for (uint256 i; i < leadersLength; ++i) {
address leader = leaders[i];
IERC20[] calldata leaderTokens = tokens[i];
uint256[] calldata leaderAmounts = amounts[i];
if (leaderTokens.length != leaderAmounts.length) {
revert ArrayLengthMismatch();
}
mapping(IERC20 => uint256) storage claimInfo = pendingClaims[leader][week];
for (uint256 j; j < leaderTokens.length; ++j) {
IERC20 token = leaderTokens[j];
uint256 amount = leaderAmounts[j];
if (isRevoke) {
claimInfo[token] -= amount;
token.safeTransfer(fundsWallet, amount);
emit ClaimRevoked(leader, token, amount);
} else {
claimInfo[token] += amount;
emit ClaimsUpdated(leader, token, amount);
}
}
}
}
// This function is executed when a contract receives plain Ether (without data)
receive() external payable {}
}
IClaims.sol 17 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @member token The token address
/// @member amount The token amount
struct ClaimInfo {
IERC20 token;
uint256 amount;
}
interface IClaims {
/// @notice Sets claim token and amount in the given round
/// @param to The address of the leader
/// @param claims The claim token and amount of the leader
function addClaimInfo(address[] calldata to, ClaimInfo[] calldata claims) external;
}
Common.sol 38 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @member latestPrice The price of token from price feed
/// @member normalizationFactor The normalization factor to achieve return value of 18 decimals ,while calculating token purchases and always with different token decimals
struct TokenInfo {
uint256 latestPrice;
uint8 normalizationFactor;
}
/// @dev The constant value helps in calculating percentages
uint256 constant PPM = 1_000_000;
/// @dev The address of the Ethereum
IERC20 constant ETH = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
/// @notice Thrown when updating an address with zero address
error ZeroAddress();
/// @notice Thrown when updating with an array of no values
error ZeroLengthArray();
/// @notice Thrown when updating with the same value as previously stored
error IdenticalValue();
/// @notice Thrown when two array lengths does not match
error ArrayLengthMismatch();
/// @notice Thrown when sign is invalid
error InvalidSignature();
/// @notice Thrown when value to transfer is zero
error ZeroValue();
/// @notice Thrown when input array length is zero
error InvalidData();
Read Contract
ADMIN_ROLE 0x75b238fc → bytes32
COMMISSIONS_MANAGER 0xcabb4549 → bytes32
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
currentWeek 0x06575c89 → uint256
endTimes 0x932b37e0 → uint256
fundsWallet 0x2194f3a2 → address
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
pendingClaims 0x71af9bf5 → uint256
presale 0xfdea8e0b → address
supportsInterface 0x01ffc9a7 → bool
Write Contract 9 functions
These functions modify contract state and require a wallet transaction to execute.
addClaimInfo 0x04479e7a
address[] to
tuple[] claims
changeFundsWallet 0x7d6f0d5f
address newFundsWallet
claimAll 0xb683454a
uint256[] claimWeeks
address[][] tokens
grantRole 0x2f2ff15d
bytes32 role
address account
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeLeaderClaim 0x3c87ca36
address[] leaders
uint256 week
address[][] tokens
uint256[][] amounts
revokeRole 0xd547741f
bytes32 role
address account
updateClaims 0x157c5bb4
address[] leaders
uint256 week
address[][] tokens
uint256[][] amounts
updatePresaleAddress 0x2fde3826
address newPresale
Token Balances (2)
View Transfers →Recent Transactions
No transactions found for this address