Verified contractPartialMIT
CustomHook
Address0x3d76dcd9065f54c68fdb2a1dbc173d076336a124
- Balance
0 ETH
- Transactions
3
- Compiler
solc 0.8.24
- Same code
29 more contracts
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,130,016
- Creation transaction
- 0xfc033e0301…4c26f7371a
- Main copy (most transactions)
- 0x62641cb0…c3251d95
CustomHook.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @title Playground
/// @notice Learning contract that demonstrates common smart contract patterns:
/// ownership (one-step and two-step transfer), pausing, an internal points ledger
/// (mint / burn / transfer / airdrop / claim), a numeric counter, stored messages
/// and per-user native coin deposits.
/// @dev Points are an internal score only. They are intentionally NOT an ERC-20 token:
/// there is no balanceOf / Transfer, so wallets and explorers never show them as a token.
contract CustomHook {
// ------------------------------------------------------------------ ownership
address public owner;
address public pendingOwner;
bool public paused;
// ------------------------------------------------------------------ points ledger
mapping(address => uint256) public pointsOf;
mapping(address => uint256) public claimable;
uint256 public totalPoints;
uint256 public totalBurned;
uint256 public airdropRounds;
// ------------------------------------------------------------------ numbers and messages
uint256 public counter;
uint256 public lastNumber;
address public lastNumberBy;
mapping(address => uint256) public numberOf;
string public message;
// ------------------------------------------------------------------ native coin deposits
mapping(address => uint256) public depositOf;
uint256 public totalDeposits;
bool private locked;
// ------------------------------------------------------------------ events
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event Paused(address indexed by);
event Unpaused(address indexed by);
event PointsMinted(address indexed to, uint256 amount);
event PointsBurned(address indexed from, uint256 amount);
event PointsMoved(address indexed from, address indexed to, uint256 amount);
event Airdropped(uint256 indexed round, address indexed recipient, uint256 amount);
event ClaimableSet(address indexed account, uint256 amount);
event Claimed(address indexed account, uint256 amount);
event CounterChanged(uint256 oldValue, uint256 newValue, address indexed by);
event NumberStored(address indexed by, uint256 value);
event MessageChanged(address indexed by, string message);
event Deposited(address indexed account, uint256 amount);
event Withdrawn(address indexed account, uint256 amount);
// ------------------------------------------------------------------ errors
error NotOwner();
error NotPendingOwner();
error ZeroAddress();
error IsPaused();
error NotPaused();
error ZeroAmount();
error InsufficientPoints(uint256 available, uint256 required);
error LengthMismatch();
error EmptyList();
error NothingToClaim();
error CounterUnderflow();
error InsufficientDeposit(uint256 available, uint256 required);
error TransferFailed();
error Reentrancy();
// ------------------------------------------------------------------ modifiers
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
modifier whenNotPaused() {
if (paused) revert IsPaused();
_;
}
modifier nonReentrant() {
if (locked) revert Reentrancy();
locked = true;
_;
locked = false;
}
constructor() {
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
// ================================================================== ownership
/// @notice One-step transfer: ownership moves immediately.
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert ZeroAddress();
pendingOwner = address(0);
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
/// @notice Two-step transfer, step 1: nominate a new owner.
function startOwnershipTransfer(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert ZeroAddress();
pendingOwner = newOwner;
emit OwnershipTransferStarted(owner, newOwner);
}
/// @notice Two-step transfer, step 2: the nominee accepts.
function acceptOwnership() external {
if (msg.sender != pendingOwner) revert NotPendingOwner();
emit OwnershipTransferred(owner, msg.sender);
owner = msg.sender;
pendingOwner = address(0);
}
/// @notice Gives up ownership forever. Owner-only functions become unusable.
function renounceOwnership() external onlyOwner {
emit OwnershipTransferred(owner, address(0));
owner = address(0);
pendingOwner = address(0);
}
function pause() external onlyOwner {
if (paused) revert IsPaused();
paused = true;
emit Paused(msg.sender);
}
function unpause() external onlyOwner {
if (!paused) revert NotPaused();
paused = false;
emit Unpaused(msg.sender);
}
// ================================================================== points
function mint(address to, uint256 amount) external onlyOwner whenNotPaused {
if (to == address(0)) revert ZeroAddress();
if (amount == 0) revert ZeroAmount();
_credit(to, amount);
emit PointsMinted(to, amount);
}
/// @notice Burns the caller's own points.
function burn(uint256 amount) external whenNotPaused {
_burn(msg.sender, amount);
}
/// @notice Owner burns points from any account.
function burnFrom(address account, uint256 amount) external onlyOwner whenNotPaused {
_burn(account, amount);
}
function transferPoints(address to, uint256 amount) external whenNotPaused {
if (to == address(0)) revert ZeroAddress();
if (amount == 0) revert ZeroAmount();
uint256 balance = pointsOf[msg.sender];
if (balance < amount) revert InsufficientPoints(balance, amount);
unchecked {
pointsOf[msg.sender] = balance - amount;
}
pointsOf[to] += amount;
emit PointsMoved(msg.sender, to, amount);
}
/// @notice Mock airdrop: credits the same amount of points to every recipient.
function airdrop(address[] calldata recipients, uint256 amount) external onlyOwner whenNotPaused {
if (recipients.length == 0) revert EmptyList();
if (amount == 0) revert ZeroAmount();
uint256 round = ++airdropRounds;
for (uint256 i = 0; i < recipients.length; i++) {
if (recipients[i] == address(0)) revert ZeroAddress();
_credit(recipients[i], amount);
emit Airdropped(round, recipients[i], amount);
}
}
/// @notice Mock airdrop with a different amount per recipient.
function airdropCustom(address[] calldata recipients, uint256[] calldata amounts) external onlyOwner whenNotPaused {
if (recipients.length == 0) revert EmptyList();
if (recipients.length != amounts.length) revert LengthMismatch();
uint256 round = ++airdropRounds;
for (uint256 i = 0; i < recipients.length; i++) {
if (recipients[i] == address(0)) revert ZeroAddress();
_credit(recipients[i], amounts[i]);
emit Airdropped(round, recipients[i], amounts[i]);
}
}
/// @notice Pull-style airdrop, step 1: owner records how much each account may claim.
function setClaimable(address[] calldata accounts, uint256[] calldata amounts) external onlyOwner {
if (accounts.length != amounts.length) revert LengthMismatch();
for (uint256 i = 0; i < accounts.length; i++) {
claimable[accounts[i]] = amounts[i];
emit ClaimableSet(accounts[i], amounts[i]);
}
}
/// @notice Pull-style airdrop, step 2: the account claims its own allocation.
function claim() external whenNotPaused returns (uint256 amount) {
amount = claimable[msg.sender];
if (amount == 0) revert NothingToClaim();
claimable[msg.sender] = 0;
_credit(msg.sender, amount);
emit Claimed(msg.sender, amount);
}
// ================================================================== numbers and messages
function increment() external whenNotPaused returns (uint256) {
return _setCounter(counter + 1);
}
function decrement() external whenNotPaused returns (uint256) {
if (counter == 0) revert CounterUnderflow();
return _setCounter(counter - 1);
}
function addToCounter(uint256 value) external whenNotPaused returns (uint256) {
return _setCounter(counter + value);
}
function setCounter(uint256 value) external onlyOwner returns (uint256) {
return _setCounter(value);
}
function resetCounter() external onlyOwner returns (uint256) {
return _setCounter(0);
}
/// @notice Anyone can store a number; the contract remembers the last one and each sender's own.
function storeNumber(uint256 value) external whenNotPaused {
lastNumber = value;
lastNumberBy = msg.sender;
numberOf[msg.sender] = value;
emit NumberStored(msg.sender, value);
}
function setMessage(string calldata newMessage) external whenNotPaused {
message = newMessage;
emit MessageChanged(msg.sender, newMessage);
}
/// @notice Pure function: computes without reading or writing storage.
function calculate(uint256 a, uint256 b) external pure returns (uint256 sum, uint256 product, uint256 power) {
return (a + b, a * b, a ** (b > 10 ? 10 : b));
}
// ================================================================== native coin deposits
function deposit() external payable whenNotPaused {
_deposit(msg.sender, msg.value);
}
/// @notice Plain coin transfers to the contract address are recorded as deposits.
receive() external payable {
_deposit(msg.sender, msg.value);
}
/// @notice Withdraws the caller's own deposit. amount = 0 withdraws everything.
function withdraw(uint256 amount) external nonReentrant {
uint256 available = depositOf[msg.sender];
if (amount == 0) amount = available;
if (amount == 0 || amount > available) revert InsufficientDeposit(available, amount);
// Checks-effects-interactions: update state before sending coin.
depositOf[msg.sender] = available - amount;
totalDeposits -= amount;
(bool ok, ) = payable(msg.sender).call{value: amount}("");
if (!ok) revert TransferFailed();
emit Withdrawn(msg.sender, amount);
}
// ================================================================== views
function contractBalance() external view returns (uint256) {
return address(this).balance;
}
function summary()
external
view
returns (
address owner_,
address pendingOwner_,
bool paused_,
uint256 totalPoints_,
uint256 totalBurned_,
uint256 airdropRounds_,
uint256 counter_,
uint256 totalDeposits_
)
{
return (owner, pendingOwner, paused, totalPoints, totalBurned, airdropRounds, counter, totalDeposits);
}
function accountInfo(address account)
external
view
returns (uint256 points, uint256 claimableAmount, uint256 deposited, uint256 storedNumber)
{
return (pointsOf[account], claimable[account], depositOf[account], numberOf[account]);
}
// ================================================================== internal
function _credit(address to, uint256 amount) private {
pointsOf[to] += amount;
totalPoints += amount;
}
function _burn(address from, uint256 amount) private {
if (amount == 0) revert ZeroAmount();
uint256 balance = pointsOf[from];
if (balance < amount) revert InsufficientPoints(balance, amount);
unchecked {
pointsOf[from] = balance - amount;
totalPoints -= amount;
}
totalBurned += amount;
emit PointsBurned(from, amount);
}
function _setCounter(uint256 value) private returns (uint256) {
emit CounterChanged(counter, value, msg.sender);
counter = value;
return value;
}
function _deposit(address account, uint256 amount) private {
if (amount == 0) revert ZeroAmount();
depositOf[account] += amount;
totalDeposits += amount;
emit Deposited(account, amount);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.