Address Contract Partially Verified
Address
0x8B5bf267f91C71f1e2f43659bF4E88aFAdC3D795
Balance
0 ETH
Nonce
1
Code Size
6413 bytes
Creator
0x606b08c0...634f at tx 0xb842e911...cb5f97
Indexed Transactions
0
Contract Bytecode
6413 bytes
0x6080604052600436106101095760003560e01c80639377530f11610095578063c3756e6911610064578063c3756e6914610338578063d547741f14610358578063d54bdada14610378578063df8de3e71461038f578063fa89401a146103af57600080fd5b80639377530f1461025b5780639d76ea5814610271578063a217fddf146102a9578063b81b8630146102be57600080fd5b80632f2ff15d116100dc5780632f2ff15d146101b957806336568abe146101d957806357f1935f146101f95780638c97fd411461021957806391d148541461023b57600080fd5b806301ffc9a71461010e5780630661c04014610143578063115425e414610165578063248a9ca314610189575b600080fd5b34801561011a57600080fd5b5061012e6101293660046114d4565b6103c2565b60405190151581526020015b60405180910390f35b34801561014f57600080fd5b5061016361015e366004611513565b6103f9565b005b34801561017157600080fd5b5061017b60025481565b60405190815260200161013a565b34801561019557600080fd5b5061017b6101a436600461154c565b60009081526020819052604090206001015490565b3480156101c557600080fd5b506101636101d4366004611565565b6106c7565b3480156101e557600080fd5b506101636101f4366004611565565b6106f1565b34801561020557600080fd5b50610163610214366004611513565b61076f565b34801561022557600080fd5b5061022e61092a565b60405161013a919061158a565b34801561024757600080fd5b5061012e610256366004611565565b61098c565b34801561026757600080fd5b5061017b60035481565b34801561027d57600080fd5b50600154610291906001600160a01b031681565b6040516001600160a01b03909116815260200161013a565b3480156102b557600080fd5b5061017b600081565b3480156102ca57600080fd5b506103256102d93660046115d7565b6001600160a01b03166000908152600460208190526040909120805460038201549282015460018301546002840154600590940154929591939092909160ff8083169261010090041690565b60405161013a979695949392919061160a565b34801561034457600080fd5b50610163610353366004611673565b6109b5565b34801561036457600080fd5b50610163610373366004611565565b610d67565b34801561038457600080fd5b5061017b6201518081565b34801561039b57600080fd5b506101636103aa3660046115d7565b610d8c565b6101636103bd3660046115d7565b6110e6565b60006001600160e01b03198216637965db0b60e01b14806103f357506301ffc9a760e01b6001600160e01b03198316145b92915050565b61040460003361098c565b6104675760405162461bcd60e51b815260206004820152602960248201527f4d75737420686176652061646d696e20726f6c6520746f2063616e63656c2061604482015268363637b1b0ba34b7b760b91b60648201526084015b60405180910390fd5b6001600160a01b0382166000908152600460205260409020805461048f9062015180906116df565b4210806104a557506005810154610100900460ff165b6104f15760405162461bcd60e51b815260206004820152601d60248201527f416c6c6f636174696f6e2063616e6e6f742062652063616e63656c6564000000604482015260640161045e565b600581015460ff16600281111561050a5761050a6115f4565b6001146105525760405162461bcd60e51b81526020600482015260166024820152752a3432b9329034b99037379030b63637b1b0ba34b7b760511b604482015260640161045e565b6002810154156105b95760405162461bcd60e51b815260206004820152602c60248201527f43616e6e6f742063616e63656c20616c6c6f636174696f6e207769746820636c60448201526b61696d656420746f6b656e7360a01b606482015260840161045e565b6005810180546002919060ff191660018302179055508060010154600260008282546105e591906116f2565b9091555050600180549082015460405163a9059cbb60e01b81526001600160a01b038581166004830152602482019290925291169063a9059cbb906044016020604051808303816000875af1158015610642573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106669190611705565b6106825760405162461bcd60e51b815260040161045e90611722565b816001600160a01b0316836001600160a01b03167f93bd5b21f327255d5c94866a6213a85fa53456a31c94c85ef95d3466a96bb77660405160405180910390a3505050565b6000828152602081905260409020600101546106e2816111d7565b6106ec83836111e4565b505050565b6001600160a01b03811633146107615760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161045e565b61076b8282611268565b5050565b61077a60003361098c565b6107c65760405162461bcd60e51b815260206004820152601e60248201527f4d75737420686176652061646d696e20726f6c6520746f20726566756e640000604482015260640161045e565b6001546001600160a01b03908116908216036108245760405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f7420726566756e64206e617469766520746f6b656e000000000000604482015260640161045e565b6040516370a0823160e01b815230600482015281906000906001600160a01b038316906370a0823190602401602060405180830381865afa15801561086d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108919190611752565b60405163a9059cbb60e01b81526001600160a01b038681166004830152602482018390529192509083169063a9059cbb906044016020604051808303816000875af11580156108e4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109089190611705565b6109245760405162461bcd60e51b815260040161045e90611722565b50505050565b6060600580548060200260200160405190810160405280929190818152602001828054801561098257602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610964575b5050505050905090565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6109c060003361098c565b610a0c5760405162461bcd60e51b815260206004820181905260248201527f4d75737420686176652061646d696e20726f6c6520746f20616c6c6f63617465604482015260640161045e565b6001600160a01b038516600003610a655760405162461bcd60e51b815260206004820152601f60248201527f526563697069656e7420616464726573732063616e6e6f742062652030783000604482015260640161045e565b83600010610ac55760405162461bcd60e51b815260206004820152602760248201527f416c6c6f636174656420616d6f756e74206d75737420626520677265617465726044820152660207468616e20360cc1b606482015260840161045e565b610ad262278d0083611781565b15610b1f5760405162461bcd60e51b815260206004820152601a60248201527f76657374696e675f2025204d4f4e5448206d7573742062652030000000000000604482015260640161045e565b6001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610b67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8b9190611752565b84600254610b9991906116df565b1115610bdc5760405162461bcd60e51b8152602060048201526012602482015271496e73756666696369656e742066756e647360701b604482015260640161045e565b6001600160a01b0385166000908152600460205260409020600581015460ff166002811115610c0d57610c0d6115f4565b600103610c5c5760405162461bcd60e51b815260206004820181905260248201527f526563697069656e7420616c72656164792068617320616c6c6f636174696f6e604482015260640161045e565b600581015460ff166002811115610c7557610c756115f4565b600003610cc857600580546001810182556000919091527f036b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db00180546001600160a01b0319166001600160a01b0388161790555b4281556003810184905560048101839055600180820186905560058201805461ffff19166101008515150217909117905560028054869190600090610d0e9084906116df565b909155505060408051868152602081018690529081018490526001600160a01b038716907fc2c07af19f0b022c178a7241f9432ed8cf9c78d174adbf2dc8629411021bfadc9060600160405180910390a2505050505050565b600082815260208190526040902060010154610d82816111d7565b6106ec8383611268565b6001600160a01b0381166000908152600460205260409020600581015460ff166002811115610dbd57610dbd6115f4565b600114610e1d5760405162461bcd60e51b815260206004820152602860248201527f5468657265206973206e6f20616c6c6f636174696f6e20666f722074686520726044820152671958da5c1a595b9d60c21b606482015260840161045e565b8060010154816002015410610e865760405162461bcd60e51b815260206004820152602960248201527f416c6c6f636174696f6e73206861766520616c7265616479206265656e207472604482015268185b9cd9995c9c995960ba1b606482015260840161045e565b60038101548154600091610e99916116df565b421115610f2c57600482015460038301548354610eb691906116df565b610ec091906116df565b421115610ecf57506064610f2c565b600062278d008360040154610ee49190611795565b90508062278d0084600301548560000154610eff91906116df565b610f0990426116f2565b610f139190611795565b610f1e9060646117a9565b610f289190611795565b9150505b60018201546064821015610f59576064828460010154610f4c91906117a9565b610f569190611795565b90505b82600201548111610fc35760405162461bcd60e51b815260206004820152602e60248201527f546f6b656e7320666f72207468697320706572696f642061726520616c72656160448201526d191e481d1c985b9cd9995c9c995960921b606482015260840161045e565b6000836002015482610fd591906116f2565b60015460405163a9059cbb60e01b81526001600160a01b0388811660048301526024820184905292935091169063a9059cbb906044016020604051808303816000875af115801561102a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061104e9190611705565b61106a5760405162461bcd60e51b815260040161045e90611722565b806003600082825461107c91906116df565b92505081905550806002600082825461109591906116f2565b9091555050600284018290556040518181526001600160a01b038616907fe42df0d9493dfd0d7f69902c895b94c190a53e8c27876a86f45e7c997d9d8f7c9060200160405180910390a25050505050565b6110f160003361098c565b61113d5760405162461bcd60e51b815260206004820152601e60248201527f4d75737420686176652061646d696e20726f6c6520746f20726566756e640000604482015260640161045e565b6000816001600160a01b03164760405160006040518083038185875af1925050503d806000811461118a576040519150601f19603f3d011682016040523d82523d6000602084013e61118f565b606091505b505090508061076b5760405162461bcd60e51b81526020600482015260146024820152732330b4b632b2103a379039b2b7321022ba3432b960611b604482015260640161045e565b6111e181336112cd565b50565b6111ee828261098c565b61076b576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556112243390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b611272828261098c565b1561076b576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6112d7828261098c565b61076b576112ef816001600160a01b03166014611331565b6112fa836020611331565b60405160200161130b9291906117ec565b60408051601f198184030181529082905262461bcd60e51b825261045e91600401611861565b606060006113408360026117a9565b61134b9060026116df565b67ffffffffffffffff81111561136357611363611894565b6040519080825280601f01601f19166020018201604052801561138d576020820181803683370190505b509050600360fc1b816000815181106113a8576113a86118aa565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106113d7576113d76118aa565b60200101906001600160f81b031916908160001a90535060006113fb8460026117a9565b6114069060016116df565b90505b600181111561147e576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061143a5761143a6118aa565b1a60f81b828281518110611450576114506118aa565b60200101906001600160f81b031916908160001a90535060049490941c93611477816118c0565b9050611409565b5083156114cd5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161045e565b9392505050565b6000602082840312156114e657600080fd5b81356001600160e01b0319811681146114cd57600080fd5b6001600160a01b03811681146111e157600080fd5b6000806040838503121561152657600080fd5b8235611531816114fe565b91506020830135611541816114fe565b809150509250929050565b60006020828403121561155e57600080fd5b5035919050565b6000806040838503121561157857600080fd5b823591506020830135611541816114fe565b6020808252825182820181905260009190848201906040850190845b818110156115cb5783516001600160a01b0316835292840192918401916001016115a6565b50909695505050505050565b6000602082840312156115e957600080fd5b81356114cd816114fe565b634e487b7160e01b600052602160045260246000fd5b600060e0820190508882528760208301528660408301528560608301528460808301526003841061164b57634e487b7160e01b600052602160045260246000fd5b8360a083015282151560c083015298975050505050505050565b80151581146111e157600080fd5b600080600080600060a0868803121561168b57600080fd5b8535611696816114fe565b945060208601359350604086013592506060860135915060808601356116bb81611665565b809150509295509295909350565b634e487b7160e01b600052601160045260246000fd5b808201808211156103f3576103f36116c9565b818103818111156103f3576103f36116c9565b60006020828403121561171757600080fd5b81516114cd81611665565b60208082526016908201527543616e6e6f74207472616e7366657220746f6b656e7360501b604082015260600190565b60006020828403121561176457600080fd5b5051919050565b634e487b7160e01b600052601260045260246000fd5b6000826117905761179061176b565b500690565b6000826117a4576117a461176b565b500490565b60008160001904831182151516156117c3576117c36116c9565b500290565b60005b838110156117e35781810151838201526020016117cb565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e74200000000000000000008152600083516118248160178501602088016117c8565b7001034b99036b4b9b9b4b733903937b6329607d1b60179184019182015283516118558160288401602088016117c8565b01602801949350505050565b60208152600082518060208401526118808160408501602087016117c8565b601f01601f19169190910160400192915050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b6000816118cf576118cf6116c9565b50600019019056fea264697066735822122065a9efc87f1c643685fb423a04139e799ee981ab765a57433773e5ac957920de64736f6c63430008100033
Verified Source Code Partial Match
Compiler: v0.8.16+commit.07a7930e
EVM: london
Optimization: Yes (200 runs)
Strings.sol 75 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}
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;
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
IAccessControl.sol 88 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @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.
*
* _Available since v3.1._
*/
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, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
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 `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
AccessControl.sol 247 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../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:
*
* ```
* 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}:
*
* ```
* 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.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
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 override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @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 override 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 override 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 override 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 `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @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 Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
CustomAllocations.sol 177 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
/// Openzeppelin imports
import '@openzeppelin/contracts/access/AccessControl.sol';
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
contract CustomAllocations is AccessControl {
/// Constant private member variables
uint256 private constant MONTH = 30 days;
/// Constant public member variables
uint256 public constant CANCELATION_PERIOD = 1 days;
/// Public variables
address public tokenAddress;
uint256 public allocatedAmount = 0;
uint256 public grandTotalClaimed = 0;
// Private variables
mapping(address => Allocation) private _allocations;
address[] private _allocatedAddresses;
/// Allocation State
enum AllocationState {
NotAllocated,
Allocated,
Canceled
}
/// Allocation with vesting information
struct Allocation {
uint256 allocationTime; // Locking calculated from this time
uint256 amount; // Total tokens allocated
uint256 amountClaimed; // Total tokens claimed
uint256 lockupPeriod; // Lockup period
uint256 vesting; // Vesting
AllocationState state; // Allocation state
bool cancelation; // Cancelation
}
/// Events
event NewAllocation(address indexed recipient, uint256 amount, uint256 lockupPeriod, uint256 vesting);
event TokenClaimed(address indexed recipient, uint256 amountClaimed);
event CancelAllocation(address indexed allocatedAddress, address indexed recipient);
/// Constructor
constructor(address tokenAddress_) {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
tokenAddress = tokenAddress_;
}
/// Sets allocation for the given recipient with corresponding amount.
function setAllocation(address recipient_,
uint256 amount_,
uint256 lockupPeriod_,
uint256 vesting_,
bool cancelation_) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'Must have admin role to allocate');
require(address(0x0) != recipient_, 'Recipient address cannot be 0x0');
require(0 < amount_, 'Allocated amount must be greater than 0');
require(0 == vesting_ % MONTH, 'vesting_ % MONTH must be 0');
require(allocatedAmount + amount_ <= IERC20(tokenAddress).balanceOf(address(this)), 'Insufficient funds');
Allocation storage a = _allocations[recipient_];
require(AllocationState.Allocated != a.state, 'Recipient already has allocation');
if (AllocationState.NotAllocated == a.state) {
_allocatedAddresses.push(recipient_);
}
a.allocationTime = block.timestamp;
a.lockupPeriod = lockupPeriod_;
a.vesting = vesting_;
a.amount = amount_;
a.state = AllocationState.Allocated;
a.cancelation = cancelation_;
allocatedAmount += amount_;
emit NewAllocation(recipient_, amount_, lockupPeriod_, vesting_);
}
/// Cancels allocation for the given recipient
function cancelAllocation(address allocatedAddress_, address recipient_) public {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'Must have admin role to cancel allocation');
Allocation storage a = _allocations[allocatedAddress_];
require(block.timestamp < a.allocationTime + CANCELATION_PERIOD || a.cancelation, 'Allocation cannot be canceled');
require(AllocationState.Allocated == a.state, 'There is no allocation');
require(0 == a.amountClaimed, 'Cannot cancel allocation with claimed tokens');
a.state = AllocationState.Canceled;
allocatedAmount -= a.amount;
require(IERC20(tokenAddress).transfer(recipient_, a.amount), 'Cannot transfer tokens');
emit CancelAllocation(allocatedAddress_, recipient_);
}
/// Transfers a recipient's available allocation to their address
function claimTokens(address recipient_) public {
Allocation storage a = _allocations[recipient_];
require(AllocationState.Allocated == a.state, 'There is no allocation for the recipient');
require(a.amountClaimed < a.amount, 'Allocations have already been transferred');
uint256 newPercentage = 0;
if (block.timestamp > a.allocationTime + a.lockupPeriod) {
if (block.timestamp > a.allocationTime + a.lockupPeriod + a.vesting) {
newPercentage = 100;
} else {
uint256 n = a.vesting / MONTH; // a.vesting % MONTH == 0
newPercentage = (((block.timestamp - (a.allocationTime + a.lockupPeriod)) / MONTH) * 100) / n;
}
}
uint256 newAmountClaimed = a.amount;
if (newPercentage < 100) {
newAmountClaimed = a.amount * newPercentage / 100;
}
require(newAmountClaimed > a.amountClaimed, 'Tokens for this period are already transferred');
uint256 tokensToTransfer = newAmountClaimed - a.amountClaimed;
require(IERC20(tokenAddress).transfer(recipient_, tokensToTransfer), 'Cannot transfer tokens');
grandTotalClaimed += tokensToTransfer;
allocatedAmount -= tokensToTransfer;
a.amountClaimed = newAmountClaimed;
emit TokenClaimed(recipient_, tokensToTransfer);
}
/// Allows transfer of accidentally sent ERC20 tokens
function refundTokens(address recipientAddress_, address erc20Address_) external {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'Must have admin role to refund');
require(erc20Address_ != tokenAddress, 'Cannot refund native token');
IERC20 erc20 = IERC20(erc20Address_);
uint256 balance = erc20.balanceOf(address(this));
require(erc20.transfer(recipientAddress_, balance), 'Cannot transfer tokens');
}
/// Allows transfer of accidentally sent Ethers
function refund(address payable recipientAddress_) external payable {
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'Must have admin role to refund');
(bool success, ) = recipientAddress_.call{value: address(this).balance}('');
require(success, "Failed to send Ether");
}
/// Gets array of allocated addresses array
function allocatedAddresses() view external returns(address[] memory) {
return _allocatedAddresses;
}
/// Gets allocation properties for the given address
function allocation(address address_)
view
external
returns(uint256 allocationTime,
uint256 lockupPeriod,
uint256 vesting,
uint256 amount,
uint256 amountClaimed,
AllocationState state,
bool cancelation) {
allocationTime = _allocations[address_].allocationTime;
lockupPeriod = _allocations[address_].lockupPeriod;
vesting = _allocations[address_].vesting;
amount = _allocations[address_].amount;
amountClaimed = _allocations[address_].amountClaimed;
state = _allocations[address_].state;
cancelation = _allocations[address_].cancelation;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
ERC165.sol 29 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 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);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
Read Contract
CANCELATION_PERIOD 0xd54bdada → uint256
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
allocatedAddresses 0x8c97fd41 → address[]
allocatedAmount 0x115425e4 → uint256
allocation 0xb81b8630 → uint256, uint256, uint256, uint256, uint256, uint8, bool
getRoleAdmin 0x248a9ca3 → bytes32
grandTotalClaimed 0x9377530f → uint256
hasRole 0x91d14854 → bool
supportsInterface 0x01ffc9a7 → bool
tokenAddress 0x9d76ea58 → address
Write Contract 8 functions
These functions modify contract state and require a wallet transaction to execute.
cancelAllocation 0x0661c040
address allocatedAddress_
address recipient_
claimTokens 0xdf8de3e7
address recipient_
grantRole 0x2f2ff15d
bytes32 role
address account
refund 0xfa89401a
address recipientAddress_
refundTokens 0x57f1935f
address recipientAddress_
address erc20Address_
renounceRole 0x36568abe
bytes32 role
address account
revokeRole 0xd547741f
bytes32 role
address account
setAllocation 0xc3756e69
address recipient_
uint256 amount_
uint256 lockupPeriod_
uint256 vesting_
bool cancelation_
Recent Transactions
No transactions found for this address