Verified contractPartialMIT
HookFunToken
Address0x831be8f3fd4d92af20dfcbfaa3f90011ebd15d37
- Balance
0 ETH
- Transactions
76
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 800 runs
- EVM version
- osaka
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,135,055
- Creation transaction
- 0xe0e32f5a2a…653d95e0df
src/HookFunToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
/// @notice Constructor-callback interface: the token takes no constructor arguments, so its init code
/// hash is constant and its CREATE2 address a pure function of the salt.
interface IHookFunTokenDeployer {
function tokenParameters()
external
view
returns (
string memory name,
string memory symbol,
string memory metadataURI,
uint256 supply,
address recipient,
address creator,
address host
);
}
/// @notice The hook, as a coin sees it.
interface ITransferHost {
function onTokenTransfer(address from, address to, uint256 amount) external;
}
/// @title HookFunToken
/// @notice Fixed-supply ERC20 with EIP-2612 permit. No mint, no burn, no owner, no transfer fee.
/// If its launch has rules that watch transfers (holding caps, the hot potato), every
/// transfer is reported to the hook after balances move, and the hook may revert it. The host
/// is fixed at deployment; zero for a launch with no such rule.
contract HookFunToken {
error PermitExpired();
error InvalidSigner();
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
uint8 public constant decimals = 18;
string public name;
string public symbol;
string public metadataURI;
uint256 public immutable totalSupply;
address public immutable launchpad;
address public immutable creator;
/// @notice The hook told of every transfer, or zero.
address public immutable host;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
mapping(address => uint256) public nonces;
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
bytes32 private immutable _hashedName;
bytes32 private constant _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
constructor() {
(
string memory n,
string memory s,
string memory uri,
uint256 supply,
address recipient,
address who,
address host_
) = IHookFunTokenDeployer(msg.sender).tokenParameters();
name = n;
symbol = s;
metadataURI = uri;
totalSupply = supply;
launchpad = msg.sender;
creator = who;
host = host_;
_hashedName = keccak256(bytes(n));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator(keccak256(bytes(n)));
balanceOf[recipient] = supply;
emit Transfer(address(0), recipient, supply);
}
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
allowance[from][msg.sender] = allowed - amount;
}
_transfer(from, to, amount);
return true;
}
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
{
if (block.timestamp > deadline) revert PermitExpired();
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline));
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash));
address recovered = ecrecover(digest, v, r, s);
if (recovered == address(0) || recovered != owner) revert InvalidSigner();
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view returns (bytes32) {
return block.chainid == _cachedChainId ? _cachedDomainSeparator : _buildDomainSeparator(_hashedName);
}
function _buildDomainSeparator(bytes32 hashedName) private view returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
hashedName,
keccak256("1"),
block.chainid,
address(this)
)
);
}
function _transfer(address from, address to, uint256 amount) private {
balanceOf[from] -= amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
if (host != address(0)) ITransferHost(host).onTokenTransfer(from, to, amount);
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 800,
"enabled": true
},
"evmVersion": "osaka",
"remappings": [
"forge-std/=lib/forge-std/src/",
"v4-core/=lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"@uniswap/v4-core/=lib/v4-core/",
"solmate/=lib/v4-core/lib/solmate/",
"openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"permit2/=lib/v4-periphery/lib/permit2/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
"ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.