// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple ERC20 + EIP-2612 implementation.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol)
/// Note:
/// The ERC20 standard allows minting and transferring to and from the zero address,
/// minting and transferring zero tokens, as well as self-approvals.
/// For performance, this implementation WILL NOT revert for such actions.
/// Please add any checks with overrides if desired.
abstract contract ERC20 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The total supply has overflowed.
error TotalSupplyOverflow();
/// @dev The allowance has overflowed.
error AllowanceOverflow();
/// @dev The allowance has underflowed.
error AllowanceUnderflow();
/// @dev Insufficient balance.
error InsufficientBalance();
/// @dev Insufficient allowance.
error InsufficientAllowance();
/// @dev The permit is invalid.
error InvalidPermit();
/// @dev The permit has expired.
error PermitExpired();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Emitted when `amount` tokens is transferred from `from` to `to`.
event Transfer(address indexed from, address indexed to, uint256 amount);
/// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`.
event Approval(
address indexed owner,
address indexed spender,
uint256 amount
);
/// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`.
uint256 private constant _TRANSFER_EVENT_SIGNATURE =
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;
/// @dev `keccak256(bytes("Approval(address,address,uint256)"))`.
uint256 private constant _APPROVAL_EVENT_SIGNATURE =
0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The storage slot for the total supply.
uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c;
/// @dev The balance slot of `owner` is given by:
/// ```
/// mstore(0x0c, _BALANCE_SLOT_SEED)
/// mstore(0x00, owner)
/// let balanceSlot := keccak256(0x0c, 0x20)
/// ```
uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2;
/// @dev The allowance slot of (`owner`, `spender`) is given by:
/// ```
/// mstore(0x20, spender)
/// mstore(0x0c, _ALLOWANCE_SLOT_SEED)
/// mstore(0x00, owner)
/// let allowanceSlot := keccak256(0x0c, 0x34)
/// ```
uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20;
/// @dev The nonce slot of `owner` is given by:
/// ```
/// mstore(0x0c, _NONCES_SLOT_SEED)
/// mstore(0x00, owner)
/// let nonceSlot := keccak256(0x0c, 0x20)
/// ```
uint256 private constant _NONCES_SLOT_SEED = 0x38377508;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 METADATA */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the name of the token.
function name() public view virtual returns (string memory);
/// @dev Returns the symbol of the token.
function symbol() public view virtual returns (string memory);
/// @dev Returns the decimals places of the token.
function decimals() public view virtual returns (uint8) {
return 18;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the amount of tokens in existence.
function totalSupply() public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := sload(_TOTAL_SUPPLY_SLOT)
}
}
/// @dev Returns the amount of tokens owned by `owner`.
function balanceOf(
address owner
) public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x20))
}
}
/// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`.
function allowance(
address owner,
address spender
) public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x34))
}
}
/// @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
///
/// Emits a {Approval} event.
function approve(
address spender,
uint256 amount
) public virtual returns (bool) {
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and store the amount.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x34), amount)
// Emit the {Approval} event.
mstore(0x00, amount)
log3(
0x00,
0x20,
_APPROVAL_EVENT_SIGNATURE,
caller(),
shr(96, mload(0x2c))
)
}
return true;
}
/// @dev Atomically increases the allowance granted to `spender` by the caller.
///
/// Emits a {Approval} event.
function increaseAllowance(
address spender,
uint256 difference
) public virtual returns (bool) {
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and load its value.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, caller())
let allowanceSlot := keccak256(0x0c, 0x34)
let allowanceBefore := sload(allowanceSlot)
// Add to the allowance.
let allowanceAfter := add(allowanceBefore, difference)
// Revert upon overflow.
if lt(allowanceAfter, allowanceBefore) {
mstore(0x00, 0xf9067066) // `AllowanceOverflow()`.
revert(0x1c, 0x04)
}
// Store the updated allowance.
sstore(allowanceSlot, allowanceAfter)
// Emit the {Approval} event.
mstore(0x00, allowanceAfter)
log3(
0x00,
0x20,
_APPROVAL_EVENT_SIGNATURE,
caller(),
shr(96, mload(0x2c))
)
}
return true;
}
/// @dev Atomically decreases the allowance granted to `spender` by the caller.
///
/// Emits a {Approval} event.
function decreaseAllowance(
address spender,
uint256 difference
) public virtual returns (bool) {
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and load its value.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, caller())
let allowanceSlot := keccak256(0x0c, 0x34)
let allowanceBefore := sload(allowanceSlot)
// Revert if will underflow.
if lt(allowanceBefore, difference) {
mstore(0x00, 0x8301ab38) // `AllowanceUnderflow()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
let allowanceAfter := sub(allowanceBefore, difference)
sstore(allowanceSlot, allowanceAfter)
// Emit the {Approval} event.
mstore(0x00, allowanceAfter)
log3(
0x00,
0x20,
_APPROVAL_EVENT_SIGNATURE,
caller(),
shr(96, mload(0x2c))
)
}
return true;
}
/// @dev Transfer `amount` tokens from the caller to `to`.
///
/// Requirements:
/// - `from` must at least have `amount`.
///
/// Emits a {Transfer} event.
function transfer(
address to,
uint256 amount
) public virtual returns (bool) {
_beforeTokenTransfer(msg.sender, to, amount);
/// @solidity memory-safe-assembly
assembly {
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, caller())
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(
0x20,
0x20,
_TRANSFER_EVENT_SIGNATURE,
caller(),
shr(96, mload(0x0c))
)
}
_afterTokenTransfer(msg.sender, to, amount);
return true;
}
/// @dev Transfers `amount` tokens from `from` to `to`.
///
/// Note: does not update the allowance if it is the maximum uint256 value.
///
/// Requirements:
/// - `from` must at least have `amount`.
/// - The caller must have at least `amount` of allowance to transfer the tokens of `from`.
///
/// Emits a {Transfer} event.
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
_beforeTokenTransfer(from, to, amount);
/// @solidity memory-safe-assembly
assembly {
let from_ := shl(96, from)
// Compute the allowance slot and load its value.
mstore(0x20, caller())
mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED))
let allowanceSlot := keccak256(0x0c, 0x34)
let allowance_ := sload(allowanceSlot)
// If the allowance is not the maximum uint256 value.
if iszero(eq(allowance_, not(0))) {
// Revert if the amount to be transferred exceeds the allowance.
if gt(amount, allowance_) {
mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
sstore(allowanceSlot, sub(allowance_, amount))
}
// Compute the balance slot and load its value.
mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(
0x20,
0x20,
_TRANSFER_EVENT_SIGNATURE,
shr(96, from_),
shr(96, mload(0x0c))
)
}
_afterTokenTransfer(from, to, amount);
return true;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EIP-2612 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the current nonce for `owner`.
/// This value is used to compute the signature for EIP-2612 permit.
function nonces(
address owner
) public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
// Compute the nonce slot and load its value.
mstore(0x0c, _NONCES_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x20))
}
}
/// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`,
/// authorized by a signed approval by `owner`.
///
/// Emits a {Approval} event.
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
bytes32 domainSeparator = DOMAIN_SEPARATOR();
/// @solidity memory-safe-assembly
assembly {
// Grab the free memory pointer.
let m := mload(0x40)
// Revert if the block timestamp greater than `deadline`.
if gt(timestamp(), deadline) {
mstore(0x00, 0x1a15a3cc) // `PermitExpired()`.
revert(0x1c, 0x04)
}
// Clean the upper 96 bits.
owner := shr(96, shl(96, owner))
spender := shr(96, shl(96, spender))
// Compute the nonce slot and load its value.
mstore(0x0c, _NONCES_SLOT_SEED)
mstore(0x00, owner)
let nonceSlot := keccak256(0x0c, 0x20)
let nonceValue := sload(nonceSlot)
// Increment and store the updated nonce.
sstore(nonceSlot, add(nonceValue, 1))
// Prepare the inner hash.
// `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`.
// forgefmt: disable-next-item
mstore(
m,
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9
)
mstore(add(m, 0x20), owner)
mstore(add(m, 0x40), spender)
mstore(add(m, 0x60), value)
mstore(add(m, 0x80), nonceValue)
mstore(add(m, 0xa0), deadline)
// Prepare the outer hash.
mstore(0, 0x1901)
mstore(0x20, domainSeparator)
mstore(0x40, keccak256(m, 0xc0))
// Prepare the ecrecover calldata.
mstore(0, keccak256(0x1e, 0x42))
mstore(0x20, and(0xff, v))
mstore(0x40, r)
mstore(0x60, s)
pop(staticcall(gas(), 1, 0, 0x80, 0x20, 0x20))
// If the ecrecover fails, the returndatasize will be 0x00,
// `owner` will be be checked if it equals the hash at 0x00,
// which evaluates to false (i.e. 0), and we will revert.
// If the ecrecover succeeds, the returndatasize will be 0x20,
// `owner` will be compared against the returned address at 0x20.
if iszero(eq(mload(returndatasize()), owner)) {
mstore(0x00, 0xddafbaef) // `InvalidPermit()`.
revert(0x1c, 0x04)
}
// Compute the allowance slot and store the value.
// The `owner` is already at slot 0x20.
mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender))
sstore(keccak256(0x2c, 0x34), value)
// Emit the {Approval} event.
log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender)
mstore(0x40, m) // Restore the free memory pointer.
mstore(0x60, 0) // Restore the zero pointer.
}
}
/// @dev Returns the EIP-2612 domains separator.
function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(0x40) // Grab the free memory pointer.
}
// We simply calculate it on-the-fly to allow for cases where the `name` may change.
bytes32 nameHash = keccak256(bytes(name()));
/// @solidity memory-safe-assembly
assembly {
let m := result
// `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
// forgefmt: disable-next-item
mstore(
m,
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f
)
mstore(add(m, 0x20), nameHash)
// `keccak256("1")`.
// forgefmt: disable-next-item
mstore(
add(m, 0x40),
0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6
)
mstore(add(m, 0x60), chainid())
mstore(add(m, 0x80), address())
result := keccak256(m, 0xa0)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL MINT FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Mints `amount` tokens to `to`, increasing the total supply.
///
/// Emits a {Transfer} event.
function _mint(address to, uint256 amount) internal virtual {
_beforeTokenTransfer(address(0), to, amount);
/// @solidity memory-safe-assembly
assembly {
let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT)
let totalSupplyAfter := add(totalSupplyBefore, amount)
// Revert if the total supply overflows.
if lt(totalSupplyAfter, totalSupplyBefore) {
mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`.
revert(0x1c, 0x04)
}
// Store the updated total supply.
sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter)
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c)))
}
_afterTokenTransfer(address(0), to, amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL BURN FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Burns `amount` tokens from `from`, reducing the total supply.
///
/// Emits a {Transfer} event.
function _burn(address from, uint256 amount) internal virtual {
_beforeTokenTransfer(from, address(0), amount);
/// @solidity memory-safe-assembly
assembly {
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, from)
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Subtract and store the updated total supply.
sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount))
// Emit the {Transfer} event.
mstore(0x00, amount)
log3(
0x00,
0x20,
_TRANSFER_EVENT_SIGNATURE,
shr(96, shl(96, from)),
0
)
}
_afterTokenTransfer(from, address(0), amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL TRANSFER FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Moves `amount` of tokens from `from` to `to`.
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
_beforeTokenTransfer(from, to, amount);
/// @solidity memory-safe-assembly
assembly {
let from_ := shl(96, from)
// Compute the balance slot and load its value.
mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(
0x20,
0x20,
_TRANSFER_EVENT_SIGNATURE,
shr(96, from_),
shr(96, mload(0x0c))
)
}
_afterTokenTransfer(from, to, amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL ALLOWANCE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Updates the allowance of `owner` for `spender` based on spent `amount`.
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and load its value.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, owner)
let allowanceSlot := keccak256(0x0c, 0x34)
let allowance_ := sload(allowanceSlot)
// If the allowance is not the maximum uint256 value.
if iszero(eq(allowance_, not(0))) {
// Revert if the amount to be transferred exceeds the allowance.
if gt(amount, allowance_) {
mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
sstore(allowanceSlot, sub(allowance_, amount))
}
}
}
/// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`.
///
/// Emits a {Approval} event.
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
/// @solidity memory-safe-assembly
assembly {
let owner_ := shl(96, owner)
// Compute the allowance slot and store the amount.
mstore(0x20, spender)
mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED))
sstore(keccak256(0x0c, 0x34), amount)
// Emit the {Approval} event.
mstore(0x00, amount)
log3(
0x00,
0x20,
_APPROVAL_EVENT_SIGNATURE,
shr(96, owner_),
shr(96, mload(0x2c))
)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HOOKS TO OVERRIDE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Hook that is called before any transfer of tokens.
/// This includes minting and burning.
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/// @dev Hook that is called after any transfer of tokens.
/// This includes minting and burning.
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OwnershipTransferred(address indexed user, address indexed newOwner);
/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
//////////////////////////////////////////////////////////////*/
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner) {
owner = _owner;
emit OwnershipTransferred(address(0), _owner);
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function transferOwnership(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
pragma solidity ^0.8.13;
// SPDX-License-Identifier: ZYZZ LICENSED (UNLICENSED)
// *((///(*
// /,,*,#(/
// (,,,*#*,
// (,,,/(*,
// (/,,,,,,,
// #&%(%&&,,,,,,,,
// ((##%*##*,,,,,*
// ****#%,(&(,,,,,
// ,,,,,**,,,,,,,, *#
// .,,,,,.,,,,///*,,,******
// %*.....,,,,,,,,,,
// %%%%#**,,,,,.
// /%%%%%#//,,*
// %%%%%##//,**
// *&&&&&%#(/*(*
// &&&&&&##(/***
// @&&&&%#(//***
// @&&&%##(//*///
// &&&&%##(/(//**/ # /&
// &&&&&%%####(**** (%%&&&&&&@@&%
// %%%%%%%##((****** /#,(%%(%&&&&%
// #%%%%#((//**,,,* ,,,,*(#&&%&@&,
// ###((((((/*,,,, **///*(&&@@@&%
// /#((((##(//*,,, /%/,,*((%&@@@&&
// (%&%(((#%%#*,*, &&& ,* , ***,,*/#%#%@@@@&&#
// (#%&&&&&&&%#%&( @@%(*****,***/(**/* *,,,,, ,/%%%%&@@@@@&#
// *(#%&&&&%&&&&&&&% /*(*,*(%%%%#/,..,**,,* (##%&&@@@@@&%
// (##%%&&&&&&&&%#%% ,,%&&&#**/(#%%#/*.,,,** #%%&&&@@@@&&&.
// ((##%%&%%%%%%%%### /(#*#%#/(/#(#%(##*,,,,,* /%%&&@@@@@@&%&/
// ,((##########%%%##(( /,#&&#/#&&&&&&%%#/*,.,,,, ,#%&&&&&&&%%%#%
// ,############%%%##(( (&#%&&#%&&@@@&%%%(**..,..,* /(##%%%&%#######
// (##%%%%########%%(/* #%##%%%&&&%&&&&%%(*,....,,,* **/(#%##%&#(####
// (###############(** #(((//(((###%%%###/*,...,,,* ///(####(((%####/
// */(########(###(**(%& ./..,,,,,,,,,*/////*,,*...,.,* (((//##((((((####
// */(((######((((/#%%&&@% *,,,.,,,,,,,.....,,.......,,,* (///////(%##(((((
// *,**//((#####//(&&&&%&&&& ,,,,,.....,,,..,,,,,.....,*, #(///////((##(/**
// *,,,**/(####%#%&@&&&&&&&% ((,,,/#%#(//**,,,,,....,,,* %%%%%%#(((//((###(/*,,,*
// ,,**/((#%##%%&@@@&&%%%## (%%%%##(/(((((##(/*,.,,,,,* %%%#%%&%####(##%%###/*,,,,*/
// ,,/(##((###%&&@@@&&&%%#(((##%%&%%%%##((##(/**,..... .#%###%#%&%(#%#%(/((/,,,,,,,,
// */((##(#&#%%&&&&&&&&&%%###%&&&&%%%%#&%#(//*,,...* %%#%%##((/(#%#%#(//(**,...,,,*
// /(&&&&&##%%&&&&&&&&&&&%%%&&&%###%&%(((//*/*** ##%#%%#(#((#((//(##((/(//*,,.,..,,,*
// &%&@@@%#(##%%&&&&&&&@&@&&&%%&%#%%&%#(((//(((%(%####&##((/(///*(((//#(//(**,...,,,,,
// %%&@&%%#(###%%&&&&&&&&&&&&%%#%%&&&&&&&&&&&&&##%#%%%#%((/*(####/(((//((/*,,,..,,,,,
// (##&&&&&%(####%%%&&&&&%%%#####%&&&&&&&&&&&&&&&&%%%%%#((/,.##(*****//***,.....,,,*
// ###%%%&%%###%%%%%#%%&&&%%%%##&&%%%&&&&&&&&&&%%%%%#/***....,,,,,..,..,........,
// (#%%%%%%####%%%%##%%%%%%%#%&&&&&&&&%&&&%%%%%%##((/*,.....,////,,,........,
// (#%%%%&%%#####%%%%%%%%%%%%&&&&&&&&&&%%%%%####(((/**,.,..,#/,.........,
// ##%&&&%%##(/(##%%%%&&&&%%%&%&&&&&%%%%#%#####((//*,..,**#%#/*.....,
// /#%&&&%%%#///##%%%%%&&&%%%%%%&&%%%#####(((((((//*,,,*/(###/*,,,
// /###%#%%%%%#####%%%%%%%%#%%%%%%%#####((/////(///*,,,(#((//**/
// *(#%%#(#%%%###########((####%%%#####(((***//((/*,,,(#(///*,*
// (/(#%%##%%%##((###%#/*(((#####%#####((((((((////((#(//*,,*
// /((/(((((##%%&%((//((%&%%(%%#########(((##(((((((///*,,,,
// */(##(#%&%###%&&&&&@@&@@@&(((##%%%%##(#((*,*///*****,,,
// (,//((##%%%#%%%%&&&&&&@&&&&&&%#((////***((((//*****,
// ((#%#(##(##((##%%#(/(##%%########((((##(/*******,,*
// //((((//(#%%%%%##((#(##%###(((//(((((/*,,.....,,,
// .///(((//########((####%%%%%##((//****/////*,..,,
// .//*/////((////((((#((((((####((((//////**,,,..*
// *//*,,,//**///***///**,****///(//****,********
// .,,**,,,***(##(((/((((####(/****,,,((/*******
// ,,***,,,**//((((((((((((((((/***///*****////
// ,*****,,,,,,*///((///*/*///*/*********////((
// *****,,,,,,.,***/****///*,,,,*****///((((###
// ******,,,**/(((##((((((((((//////((((/(((###(
// ****///*,,/*/(((((*((#(((/////*//////(((((((/
// ,****//*,,,***/(((((/(///******///////(((//**
// *******,,*,,**//////*,,,***//(((/((/*********
// ./,,,*///*,,***********/*//*///////////*///*/(,
// ,/((((**////*,******////////*/////(///*/((//////
// ,,(#((((((/*/((/***********/*///(((/////##(((////%/,
// ,...,/#%&&%##/**/(/*/////////*////////*(##%#((##((&/**
// ....,,,,///(%&&&(**((//*//*/////////*,/##%%%#(((&&(**.,,
// ......,****/**//**/((//************.,(##((//*///*,**,,,,,
// ,.......*////*/,/***/**//***,*////*////*///******,******,,
// ,..........,//**///*,.**,//.****/////*///////(/*//////....,
// ... ...........*/*,*//*,///**/*/////////**,.**,**..,*,.. .,,
// .(*..... ............,///*.,./****,. ....,,*/, . ...,.
// ,*,.... . ... ... ............... .......
// *,*/,... ..... ..... . .
// /((/*.,/**/* ., ..... . ....
// /(/////*. . .......
// */////****,. ... .....
import "./Owned.sol";
import "./ERC20.sol";
contract SickCunt is ERC20, Owned {
/*/////////////////////////////////////////////////
ERRORS + EVENTS
/////////////////////////////////////////////////*/
event TaxPaused(bool paused);
event TaxTimeSet(uint256 startTime, uint256 endTime);
/*/////////////////////////////////////////////////
STATE
/////////////////////////////////////////////////*/
/// @notice tax percent (x 100). MK677 doesn't pay for itself
uint256 public constant taxPct = 500;
/// @notice Gotta tip the plug brah
address public MK677_PLUG;
/// @notice whitelist for tax avoiding senders
mapping(address => bool) noTaxWhitelisted;
/// @notice start time of tax period
uint256 public startTime;
/// @notice end time of tax period
uint256 public endTime;
/// @notice Flag to pause tax during tax period
bool public taxActive;
constructor(
uint256 _totalSuply,
address _owner,
address _tax_receiver
) Owned(_owner) {
/// only time _mint is called
_mint(_owner, _totalSuply);
taxActive = true;
owner = _owner;
MK677_PLUG = _tax_receiver;
/// initial tax period is 1 hour post deployment
_setTaxTime(block.timestamp, block.timestamp + 1 hours);
/// initial tax free sender whitelist
noTaxWhitelisted[_owner] = true;
noTaxWhitelisted[_tax_receiver] = true;
}
/*//////////////////////////////////////////////////////////////
ERC20 OVERRIDES
//////////////////////////////////////////////////////////////*/
/// @notice Name of the token.
function name() public pure override returns (string memory) {
return "Sick Cunt Money";
}
/// @notice Symbol of the token.
function symbol() public pure override returns (string memory) {
return "SIKCNT";
}
/**
* @notice Custom implementation of transfer function accounting for tax
* @dev THIS SPECIFIC IMPLEMENTATION IS MORE GAS WITH SOLADY THAN SOLMATE BUT WE MUST USE SOLADY
* IF YOU ARENT USING CUSTOM LOGIC, WHY ARENT YOU USING SOLADY?
* @param to Address to credit tokens
* @param amount Amount of tokens to transfer
*/
function transfer(
address to,
uint256 amount
) public override returns (bool) {
uint256 taxAmount = calculateTax(amount, to);
_transfer(msg.sender, to, amount - taxAmount);
if (taxAmount > 0) {
_transfer(msg.sender, MK677_PLUG, taxAmount);
}
return true;
}
/**
* @notice Cusotm implementation of transferFrom function accounting for tax
* @dev THIS SPECIFIC IMPLEMENTATION IS MORE GAS WITH SOLADY THAN SOLMATE BUT WE MUST USE SOLADY
* IF YOU ARENT USING CUSTOM LOGIC, WHY ARENT YOU USING SOLADY?
* @param from Account sending tokens
* @param to Account receiving tokens
* @param amount Amount of tokens to transfer
*/
function transferFrom(
address from,
address to,
uint256 amount
) public override returns (bool) {
uint256 _allowance = allowance(from, msg.sender);
if (amount > _allowance) revert InsufficientAllowance();
uint256 taxAmount = calculateTax(amount, to);
_transfer(from, to, amount - taxAmount);
if (taxAmount > 0) {
_transfer(from, MK677_PLUG, taxAmount);
}
return true;
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function pauseTax(bool paused) external onlyOwner {
taxActive = !paused;
emit TaxPaused(paused);
}
function setTaxTime(
uint256 _startTime,
uint256 _endTime
) external onlyOwner {
_setTaxTime(_startTime, _endTime);
}
function toggleNoTaxWhitelist(
address account,
bool taxFree
) external onlyOwner {
noTaxWhitelisted[account] = taxFree;
}
function changeTaxReceiver(address newReceiver) external onlyOwner {
MK677_PLUG = newReceiver;
}
/*//////////////////////////////////////////////////////////////
INTERNAL LOGIC
//////////////////////////////////////////////////////////////*/
function _setTaxTime(uint256 _startTime, uint256 _endTime) internal {
if (block.timestamp > _endTime) revert("bad time range");
if (_startTime > _endTime) revert("bad time range");
startTime = _startTime;
endTime = _endTime;
emit TaxTimeSet(_startTime, _endTime);
}
function inTimeRange() internal view returns (bool) {
return block.timestamp >= startTime && block.timestamp <= endTime;
}
function calculateTax(
uint256 amount,
address to
) internal view returns (uint256 taxAmount) {
if (
taxActive &&
inTimeRange() &&
!noTaxWhitelisted[msg.sender] &&
!noTaxWhitelisted[to]
) {
taxAmount = (amount * taxPct) / 10000;
}
}
}
{
"compilationTarget": {
"SickCunt.sol": "SickCunt"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"uint256","name":"_totalSuply","type":"uint256"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_tax_receiver","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AllowanceOverflow","type":"error"},{"inputs":[],"name":"AllowanceUnderflow","type":"error"},{"inputs":[],"name":"InsufficientAllowance","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidPermit","type":"error"},{"inputs":[],"name":"PermitExpired","type":"error"},{"inputs":[],"name":"TotalSupplyOverflow","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"paused","type":"bool"}],"name":"TaxPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"startTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"}],"name":"TaxTimeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"result","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MK677_PLUG","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newReceiver","type":"address"}],"name":"changeTaxReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"difference","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"endTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"difference","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"paused","type":"bool"}],"name":"pauseTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_startTime","type":"uint256"},{"internalType":"uint256","name":"_endTime","type":"uint256"}],"name":"setTaxTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"taxActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"taxPct","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"taxFree","type":"bool"}],"name":"toggleNoTaxWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]