Skip to content
Verified contractPartialMIT

UmaskToken

Address0xd48e222e91f339bdb41e21fbeba2b7d046566082
Balance

0.00033 ETH

 

Transactions

366

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,039,690
Creation transaction
0xda18c7ffeb…01a021ac73

contracts/UmaskToken.sol

// SPDX-License-Identifier: MIT
//
// uMASK
// X:       https://x.com/unimaskart
// Website: https://unimask.art
//
pragma solidity ^0.8.26;

import {ERC20} from "solady/tokens/ERC20.sol";
import {Ownable} from "solady/auth/Ownable.sol";
import {ReentrancyGuard} from "solady/utils/ReentrancyGuard.sol";
import {Tiers} from "./Tiers.sol";

interface IUmaskHook {
    function getRitualPriceX18() external view returns (uint256 price);
    function getMaskMcapWei(uint256 totalSupplyTokens) external view returns (uint256 mcapWei);
    function swapEntropy() external view returns (bytes32);
    function swapPartnerForEth(uint256 partnerIn, uint256 minEthOut) external returns (uint256 ethOut);
}

interface IUmaskRenderer {
    function tokenURI(uint256 tokenId, uint8 tier, bytes32 traits, string calldata mythicName)
        external view returns (string memory);
}

contract UmaskToken is ERC20, Ownable, ReentrancyGuard {
    using Tiers for uint8;

    string private constant _NAME = "uMASK";
    string private constant _SYMBOL = "uMASK";
    uint256 private constant _SUPPLY = Tiers.TOTAL_SUPPLY * 1e18;
    uint256 private constant _UNIT = 1e18;

    uint256 public constant RITUAL_RESERVE = 1_000;
    uint256 public constant RITUAL_WINDOW = 30 days;
    uint256 public constant RITUAL_MIN_MCAP_WEI = 150 ether;
    uint256 public constant DUMP_INTERVAL = 30 minutes;

    uint256 private constant ACC_SCALE = 1e36;
    uint96 public constant ROYALTY_BPS = 200;

    uint256 public constant REVEAL_MIN_DELAY = 4;
    uint256 public constant REVEAL_MAX_DELAY = 257;

    address public hook;
    address public teamWallet;
    address public lpWallet;
    address public renderer;
    address public immutable partnerToken;

    address public constant POOL_MANAGER       = 0x000000000004444c5dc75cB358380D2e3dE08A90;
    address public constant POSITION_MANAGER   = 0xbD216513d74C8cf14cf4747E6AaA6420FF64ee9e;
    address public constant UNIVERSAL_ROUTER   = 0x66a9893cC07D91D95644AEDD05D03f95e1dBA8Af;

    bool public hookLocked;
    bool public teamWalletLocked;
    bool public rendererLocked;
    bool public limitsRemoved;

    mapping(address => bool) public isAllowedOperator;
    bool public allowlistEnforced;

    uint256 public maxWallet;
    uint256 public maxTx;

    uint256 public immutable ritualDeadline;
    uint256 public ritualReserveLeft = RITUAL_RESERVE;
    uint256 public pendingPartnerSwap;
    uint256 public nextDumpTime;

    uint256 public accRewardPerWeight;
    uint256 public totalRarityWeight;
    uint256 public undistributedRewards;

    struct SealedSlot {
        address originalMinter;
        uint64 mintBlock;
        bool revealed;
    }
    struct Slot {
        address owner;
        uint8 tier;
        bool pinned;
        bytes32 traits;
    }

    uint256 public nextSlotId = 1;
    mapping(uint256 => SealedSlot) public sealedSlots;
    mapping(uint256 => Slot) public slots;
    mapping(uint256 => string) public mythicName;

    mapping(address => uint256[]) public ownerSlots;
    mapping(uint256 => uint256) public slotPositionInOwnerList;

    mapping(address => uint256) public userWeight;
    mapping(address => int256) public rewardDebt;
    mapping(address => uint256) public rewardCredit;
    mapping(address => bool) public excludedFromRewards;
    mapping(address => bool) public notMintable;

    mapping(uint256 => address) public slotApprovals;
    mapping(address => mapping(address => bool)) public operatorApprovals;

    event Reveal(uint256 indexed slotId, uint8 tier, bytes32 traits);
    event Pin(uint256 indexed slotId, bool pinned);
    event TransferUmask(address indexed from, address indexed to, uint256 indexed slotId);
    event ClaimRewards(address indexed user, uint256 amount);
    event DepositRewards(uint256 amount);
    event RitualConverted(address indexed user, uint256 partnerIn, uint256 maskCount, uint256 reserveLeft);
    event PartnerDumped(uint256 partnerSold, uint256 ethReceived);
    event LimitsRemoved();
    event HookLocked();
    event RendererSet(address indexed renderer);
    event AllowedOperator(address indexed op, bool allowed);
    event AllowlistEnforced(bool enforced);

    error NotHook();
    error AlreadyLocked();
    error NotMintable_(address account);
    error MaxWalletExceeded();
    error MaxTxExceeded();
    error PinnedSlotInPath();
    error NotSlotOwner();
    error TooEarly();
    error RevealExpired();
    error SlippageExceeded();
    error RitualClosed();
    error RitualDepleted();
    error MythicCannotMove();
    error OperatorNotAllowed();
    error ZeroAddress();
    error NotRenderer();
    error DumpRateLimited();
    error DumpOverPending();
    error RitualMcapTooLow();

    constructor(address _partnerToken, address _teamWallet, address _lpWallet) {
        if (_partnerToken == address(0) || _teamWallet == address(0) || _lpWallet == address(0))
            revert ZeroAddress();

        partnerToken = _partnerToken;
        teamWallet = _teamWallet;
        lpWallet = _lpWallet;

        maxWallet = _SUPPLY / 100;
        maxTx     = _SUPPLY / 100;

        excludedFromRewards[address(this)] = true;
        excludedFromRewards[_lpWallet] = true;
        excludedFromRewards[address(0)] = true;

        notMintable[msg.sender] = true;
        notMintable[address(this)] = true;
        notMintable[_lpWallet] = true;
        notMintable[address(0)] = true;

        _initializeOwner(msg.sender);
        _mint(_lpWallet, _SUPPLY);

        ritualDeadline = block.timestamp + RITUAL_WINDOW;
    }

    function name() public pure override returns (string memory) { return _NAME; }
    function symbol() public pure override returns (string memory) { return _SYMBOL; }

    function setHook(address _hook) external onlyOwner {
        require(!hookLocked, "locked");
        hook = _hook;
        excludedFromRewards[_hook] = true;
        notMintable[_hook] = true;
    }
    function lockHook() external onlyOwner { if (hookLocked) revert AlreadyLocked(); hookLocked = true; emit HookLocked(); }
    function setTeamWallet(address w) external onlyOwner { require(!teamWalletLocked, "locked"); teamWallet = w; }
    function lockTeamWallet() external onlyOwner { if (teamWalletLocked) revert AlreadyLocked(); teamWalletLocked = true; }

    function setRenderer(address r) external onlyOwner { require(!rendererLocked, "locked"); renderer = r; emit RendererSet(r); }
    function lockRenderer() external onlyOwner { if (rendererLocked) revert AlreadyLocked(); rendererLocked = true; }

    function removeLimits() external onlyOwner {
        if (limitsRemoved) revert AlreadyLocked();
        maxWallet = type(uint256).max;
        maxTx = type(uint256).max;
        limitsRemoved = true;
        emit LimitsRemoved();
    }

    function setAllowedOperator(address op, bool ok) external onlyOwner {
        isAllowedOperator[op] = ok;
        emit AllowedOperator(op, ok);
    }
    function setAllowlistEnforced(bool on) external onlyOwner {
        allowlistEnforced = on;
        emit AllowlistEnforced(on);
    }

    function setNotMintable(address a, bool flag) external onlyOwner {
        if (flag) notMintable[a] = true;
    }

    function seedMythicName(uint256 tokenId, string calldata humanName) external onlyOwner {
        require(Tiers.isMythicId(tokenId), "not mythic");
        require(bytes(mythicName[tokenId]).length == 0, "already seeded");
        mythicName[tokenId] = humanName;
    }

    function _beforeTokenTransfer(address from, address to, uint256 amount) internal override {
        if (limitsRemoved
            || from == owner() || to == owner()
            || from == hook    || to == hook
            || from == POOL_MANAGER || to == POOL_MANAGER
            || from == POSITION_MANAGER || to == POSITION_MANAGER
            || from == UNIVERSAL_ROUTER || to == UNIVERSAL_ROUTER) return;
        if (amount > maxTx) revert MaxTxExceeded();
        if (to != lpWallet && balanceOf(to) + amount > maxWallet) revert MaxWalletExceeded();
    }

    function _afterTokenTransfer(address from, address to, uint256 amount) internal override {
        _settleRewards(from);
        _settleRewards(to);
        _reconcileSlots(from, to);
        _updateRewardDebt(from);
        _updateRewardDebt(to);
    }

    function _reconcileSlots(address from, address to) internal {
        if (from == address(0) && to == address(0)) return;

        if (from != address(0)) {
            uint256 fromTarget = balanceOf(from) / _UNIT;
            uint256 fromCurrent = ownerSlots[from].length;
            if (fromCurrent > fromTarget) {
                uint256 diff = fromCurrent - fromTarget;
                if (notMintable[to] || to == address(this)) {
                    _burnSlotsLIFO(from, diff);
                } else {
                    _moveSlotsLIFO(from, to, diff);
                }
            }
        }

        // Mint-on-receive deferred to user-callable claimSlots() — keeps transfers cheap
        // (slot mints are ~70k gas each; would make atomic-bundle launches infeasible).
    }

    function claimSlots(uint256 maxToClaim) external {
        uint256 target = balanceOf(msg.sender) / _UNIT;
        uint256 current = ownerSlots[msg.sender].length;
        if (current >= target) return;
        if (notMintable[msg.sender]) return;
        uint256 deficit = target - current;
        uint256 toMint = deficit < maxToClaim ? deficit : maxToClaim;
        for (uint256 i; i < toMint; ++i) _mintSealedSlot(msg.sender);
    }

    function _mintSealedSlot(address to) internal {
        uint256 slotId = nextSlotId++;
        require(slotId <= Tiers.PROCEDURAL_CAP, "procedural cap");
        sealedSlots[slotId] = SealedSlot({originalMinter: to, mintBlock: uint64(block.number), revealed: false});
        slots[slotId].owner = to;
        _addToOwnerList(to, slotId);
    }

    function _burnSlotsLIFO(address from, uint256 count) internal {
        uint256[] storage list = ownerSlots[from];
        uint256 burned;
        uint256 i = list.length;
        while (burned < count && i > 0) {
            i--;
            uint256 slotId = list[i];
            if (slots[slotId].pinned) revert PinnedSlotInPath();
            if (Tiers.isMythicId(slotId)) revert MythicCannotMove();
            _removeFromOwnerList(from, slotId);
            if (slots[slotId].tier != 0) {
                _adjustWeight(from, -int256(Tiers.weightOf(slots[slotId].tier)));
            }
            delete slots[slotId];
            delete sealedSlots[slotId];
            delete slotApprovals[slotId];
            burned++;
        }
        require(burned == count, "insufficient unpinned");
    }

    function _moveSlotsLIFO(address from, address to, uint256 count) internal {
        uint256[] storage list = ownerSlots[from];
        uint256 moved;
        uint256 i = list.length;
        while (moved < count && i > 0) {
            i--;
            uint256 slotId = list[i];
            if (slots[slotId].pinned) revert PinnedSlotInPath();
            if (Tiers.isMythicId(slotId)) revert MythicCannotMove();
            _moveSpecificSlot(from, to, slotId);
            moved++;
        }
        require(moved == count, "insufficient unpinned");
    }

    function _moveSpecificSlot(address from, address to, uint256 slotId) internal {
        _removeFromOwnerList(from, slotId);
        _addToOwnerList(to, slotId);
        slots[slotId].owner = to;
        delete slotApprovals[slotId];

        if (slots[slotId].tier != 0) {
            uint256 w = Tiers.weightOf(slots[slotId].tier);
            _adjustWeight(from, -int256(w));
            _adjustWeight(to, int256(w));
        }
    }

    function _addToOwnerList(address o, uint256 slotId) internal {
        slotPositionInOwnerList[slotId] = ownerSlots[o].length;
        ownerSlots[o].push(slotId);
    }
    function _removeFromOwnerList(address o, uint256 slotId) internal {
        uint256 pos = slotPositionInOwnerList[slotId];
        uint256 last = ownerSlots[o].length - 1;
        if (pos != last) {
            uint256 lastSlot = ownerSlots[o][last];
            ownerSlots[o][pos] = lastSlot;
            slotPositionInOwnerList[lastSlot] = pos;
        }
        ownerSlots[o].pop();
        delete slotPositionInOwnerList[slotId];
    }

    function reveal(uint256[] calldata ids) external {
        for (uint256 i; i < ids.length; ++i) _reveal(ids[i]);
    }

    function _reveal(uint256 slotId) internal {
        SealedSlot storage s = sealedSlots[slotId];
        if (s.revealed) return;
        if (s.originalMinter == address(0)) revert NotSlotOwner();
        uint256 age = block.number - s.mintBlock;
        if (age < REVEAL_MIN_DELAY) revert TooEarly();
        if (age > REVEAL_MAX_DELAY) revert RevealExpired();

        bytes32 hookEntropy = hook == address(0) ? bytes32(0) : IUmaskHook(hook).swapEntropy();

        bytes32 entropy = keccak256(abi.encode(
            blockhash(s.mintBlock + 1),
            blockhash(s.mintBlock + 2),
            blockhash(s.mintBlock + 3),
            slotId,
            s.originalMinter,
            block.chainid,
            hookEntropy
        ));

        uint16 roll = uint16(uint256(entropy) % 10_000);
        uint8 tier = Tiers.rollToTier(roll);

        slots[slotId].tier = tier;
        slots[slotId].traits = entropy;
        s.revealed = true;

        if (tier >= Tiers.WRAITH) {
            slots[slotId].pinned = true;
            emit Pin(slotId, true);
        }

        address currentOwner = slots[slotId].owner;
        _settleRewards(currentOwner);
        _adjustWeight(currentOwner, int256(Tiers.weightOf(tier)));
        _updateRewardDebt(currentOwner);

        emit Reveal(slotId, tier, entropy);
    }

    function _adjustWeight(address user, int256 delta) internal {
        if (excludedFromRewards[user]) return;
        if (delta > 0) { userWeight[user] += uint256(delta); totalRarityWeight += uint256(delta); }
        else if (delta < 0) {
            uint256 d = uint256(-delta);
            userWeight[user] -= d; totalRarityWeight -= d;
        }
    }

    function _settleRewards(address user) internal {
        if (user == address(0) || excludedFromRewards[user]) return;
        uint256 pending = uint256(int256(userWeight[user] * accRewardPerWeight / ACC_SCALE) - rewardDebt[user]);
        if (pending > 0) rewardCredit[user] += pending;
    }

    function _updateRewardDebt(address user) internal {
        if (user == address(0) || excludedFromRewards[user]) return;
        rewardDebt[user] = int256(userWeight[user] * accRewardPerWeight / ACC_SCALE);
    }

    function pendingRewards(address user) external view returns (uint256) {
        if (excludedFromRewards[user]) return 0;
        uint256 acc = userWeight[user] * accRewardPerWeight / ACC_SCALE;
        return uint256(int256(acc) - rewardDebt[user]) + rewardCredit[user];
    }
    function claimable(address user) external view returns (uint256) {
        if (excludedFromRewards[user]) return 0;
        uint256 acc = userWeight[user] * accRewardPerWeight / ACC_SCALE;
        return uint256(int256(acc) - rewardDebt[user]) + rewardCredit[user];
    }

    function claim() external nonReentrant {
        _settleRewards(msg.sender);
        uint256 amount = rewardCredit[msg.sender];
        if (amount == 0) return;
        rewardCredit[msg.sender] = 0;
        _updateRewardDebt(msg.sender);
        (bool ok,) = msg.sender.call{value: amount}("");
        require(ok, "send fail");
        emit ClaimRewards(msg.sender, amount);
    }
    function claimRewards() external nonReentrant {
        _settleRewards(msg.sender);
        uint256 amount = rewardCredit[msg.sender];
        if (amount == 0) return;
        rewardCredit[msg.sender] = 0;
        _updateRewardDebt(msg.sender);
        (bool ok,) = msg.sender.call{value: amount}("");
        require(ok, "send fail");
        emit ClaimRewards(msg.sender, amount);
    }

    function depositRewards() external payable {
        if (msg.sender != hook && msg.sender != address(this)) revert NotHook();
        if (totalRarityWeight == 0) {
            undistributedRewards += msg.value;
        } else {
            uint256 toDistribute = msg.value + undistributedRewards;
            undistributedRewards = 0;
            accRewardPerWeight += toDistribute * ACC_SCALE / totalRarityWeight;
        }
        emit DepositRewards(msg.value);
    }

    function pinUmask(uint256 id) external {
        if (slots[id].owner != msg.sender) revert NotSlotOwner();
        if (!sealedSlots[id].revealed) _reveal(id);
        slots[id].pinned = true;
        emit Pin(id, true);
    }
    function unpinUmask(uint256 id) external {
        if (slots[id].owner != msg.sender) revert NotSlotOwner();
        if (Tiers.isMythicId(id)) revert MythicCannotMove();
        slots[id].pinned = false;
        emit Pin(id, false);
    }

    function transferUmask(uint256 id, address to) external {
        _transferUmask(msg.sender, to, id);
    }
    function transferUmaskFrom(address from, address to, uint256 id) external {
        require(slotApprovals[id] == msg.sender || operatorApprovals[from][msg.sender], "not approved");
        if (allowlistEnforced && !isAllowedOperator[msg.sender] && msg.sender != from)
            revert OperatorNotAllowed();
        _transferUmask(from, to, id);
    }

    function _transferUmask(address from, address to, uint256 id) internal {
        if (slots[id].owner != from) revert NotSlotOwner();
        if (notMintable[to]) revert NotMintable_(to);
        if (!sealedSlots[id].revealed) _reveal(id);

        _settleRewards(from);
        _settleRewards(to);

        _moveSpecificSlot(from, to, id);
        super._transfer(from, to, _UNIT);

        _updateRewardDebt(from);
        _updateRewardDebt(to);

        emit TransferUmask(from, to, id);
    }

    function approve(uint256 id, address op) external {
        if (slots[id].owner != msg.sender) revert NotSlotOwner();
        slotApprovals[id] = op;
    }
    function setOperator(address op, bool ok) external {
        operatorApprovals[msg.sender][op] = ok;
    }

    function quoteRitual(uint256 maskCount) public view returns (uint256 partnerCost) {
        require(maskCount > 0, "zero count");
        if (IUmaskHook(hook).getMaskMcapWei(Tiers.TOTAL_SUPPLY) < RITUAL_MIN_MCAP_WEI)
            revert RitualMcapTooLow();
        uint256 priceX18 = IUmaskHook(hook).getRitualPriceX18();
        uint256 raw = priceX18 * maskCount;
        partnerCost = (raw + 1e18 - 1) / 1e18;
        partnerCost = partnerCost * 1e18;
    }

    function isRitualOpen() external view returns (bool) {
        if (block.timestamp > ritualDeadline) return false;
        if (ritualReserveLeft == 0) return false;
        if (hook == address(0)) return false;
        return IUmaskHook(hook).getMaskMcapWei(Tiers.TOTAL_SUPPLY) >= RITUAL_MIN_MCAP_WEI;
    }

    function performRitual(uint256 maskCount, uint256 maxPartnerCost) external nonReentrant {
        if (block.timestamp > ritualDeadline) revert RitualClosed();
        if (maskCount == 0 || maskCount > ritualReserveLeft) revert RitualDepleted();
        if (IUmaskHook(hook).getMaskMcapWei(Tiers.TOTAL_SUPPLY) < RITUAL_MIN_MCAP_WEI)
            revert RitualMcapTooLow();

        uint256 cost = quoteRitual(maskCount);
        if (cost > maxPartnerCost) revert SlippageExceeded();

        require(ERC20(partnerToken).transferFrom(msg.sender, address(this), cost), "partner pull");

        super._transfer(lpWallet, msg.sender, maskCount * _UNIT);

        ritualReserveLeft -= maskCount;
        pendingPartnerSwap += cost;

        emit RitualConverted(msg.sender, cost, maskCount, ritualReserveLeft);
    }

    function dumpPartnerTick(uint256 maxSell, uint256 minEthOut) external nonReentrant {
        if (block.timestamp < nextDumpTime) revert DumpRateLimited();
        if (maxSell == 0 || maxSell > pendingPartnerSwap) revert DumpOverPending();

        pendingPartnerSwap -= maxSell;
        nextDumpTime = block.timestamp + DUMP_INTERVAL;

        require(ERC20(partnerToken).transfer(hook, maxSell), "partner xfer");
        uint256 ethOut = IUmaskHook(hook).swapPartnerForEth(maxSell, minEthOut);

        emit PartnerDumped(maxSell, ethOut);
    }

    function nameOf(uint256 tokenId) external view returns (string memory) {
        return mythicName[tokenId];
    }

    function tokenURI(uint256 tokenId) external view returns (string memory) {
        require(renderer != address(0), "renderer unset");
        Slot memory s = slots[tokenId];
        require(s.owner != address(0), "nonexistent");
        return IUmaskRenderer(renderer).tokenURI(tokenId, s.tier, s.traits, mythicName[tokenId]);
    }

    function royaltyInfo(uint256, uint256 salePrice)
        external view returns (address receiver, uint256 amount)
    {
        receiver = teamWallet;
        amount = (salePrice * ROYALTY_BPS) / 10_000;
    }

    function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
        return
            interfaceId == 0x01ffc9a7 ||
            interfaceId == 0x80ac58cd ||
            interfaceId == 0x5b5e139f ||
            interfaceId == 0x2a55205a;
    }

    receive() external payable {}
}

contracts/Tiers.sol

// SPDX-License-Identifier: MIT
//
// uMASK
// X:       https://x.com/unimaskart
// Website: https://unimask.art
//
pragma solidity ^0.8.26;

library Tiers {
    uint8 internal constant COMMON     = 1;
    uint8 internal constant CURSED     = 2;
    uint8 internal constant WRAITH     = 3;
    uint8 internal constant NIGHTMARE  = 4;
    uint8 internal constant LEGENDARY  = 5;
    uint8 internal constant MYTHIC     = 6;

    uint256 internal constant TOTAL_SUPPLY = 10_000;
    uint256 internal constant MYTHIC_FIRST_ID = 9991;
    uint256 internal constant MYTHIC_COUNT    = 10;
    uint256 internal constant PROCEDURAL_CAP  = TOTAL_SUPPLY - MYTHIC_COUNT;

    uint16 internal constant CUTOFF_COMMON     = 6465;
    uint16 internal constant CUTOFF_CURSED     = 8464;
    uint16 internal constant CUTOFF_WRAITH     = 9463;
    uint16 internal constant CUTOFF_NIGHTMARE  = 9944;
    uint16 internal constant CUTOFF_LEGENDARY  = 9990;

    function weightOf(uint8 tier) internal pure returns (uint256) {
        if (tier == COMMON)    return   1;
        if (tier == CURSED)    return   3;
        if (tier == WRAITH)    return   9;
        if (tier == NIGHTMARE) return  27;
        if (tier == LEGENDARY) return  65;
        if (tier == MYTHIC)    return 200;
        return 0;
    }

    function rollToTier(uint16 roll) internal pure returns (uint8) {
        if (roll < CUTOFF_COMMON)    return COMMON;
        if (roll < CUTOFF_CURSED)    return CURSED;
        if (roll < CUTOFF_WRAITH)    return WRAITH;
        if (roll < CUTOFF_NIGHTMARE) return NIGHTMARE;
        return LEGENDARY;
    }

    function isMythicId(uint256 tokenId) internal pure returns (bool) {
        return tokenId >= MYTHIC_FIRST_ID && tokenId <= TOTAL_SUPPLY;
    }

    function tierOfMythic(uint256 tokenId) internal pure returns (uint8) {
        return isMythicId(tokenId) ? MYTHIC : 0;
    }
}

lib/solady/src/auth/Ownable.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
///
/// @dev Note:
/// This implementation does NOT auto-initialize the owner to `msg.sender`.
/// You MUST call the `_initializeOwner` in the constructor / initializer.
///
/// While the ownable portion follows
/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
/// the nomenclature for the 2-step ownership handover may be unique to this codebase.
abstract contract Ownable {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The caller is not authorized to call the function.
    error Unauthorized();

    /// @dev The `newOwner` cannot be the zero address.
    error NewOwnerIsZeroAddress();

    /// @dev The `pendingOwner` does not have a valid handover request.
    error NoHandoverRequest();

    /// @dev Cannot double-initialize.
    error AlreadyInitialized();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The ownership is transferred from `oldOwner` to `newOwner`.
    /// This event is intentionally kept the same as OpenZeppelin's Ownable to be
    /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
    /// despite it not being as lightweight as a single argument event.
    event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

    /// @dev An ownership handover to `pendingOwner` has been requested.
    event OwnershipHandoverRequested(address indexed pendingOwner);

    /// @dev The ownership handover to `pendingOwner` has been canceled.
    event OwnershipHandoverCanceled(address indexed pendingOwner);

    /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
    uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
        0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;

    /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
        0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;

    /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
        0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          STORAGE                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The owner slot is given by:
    /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
    /// It is intentionally chosen to be a high value
    /// to avoid collision with lower slots.
    /// The choice of manual storage layout is to enable compatibility
    /// with both regular and upgradeable contracts.
    bytes32 internal constant _OWNER_SLOT =
        0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;

    /// The ownership handover slot of `newOwner` is given by:
    /// ```
    ///     mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
    ///     let handoverSlot := keccak256(0x00, 0x20)
    /// ```
    /// It stores the expiry timestamp of the two-step ownership handover.
    uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     INTERNAL FUNCTIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
    function _guardInitializeOwner() internal pure virtual returns (bool guard) {}

    /// @dev Initializes the owner directly without authorization guard.
    /// This function must be called upon initialization,
    /// regardless of whether the contract is upgradeable or not.
    /// This is to enable generalization to both regular and upgradeable contracts,
    /// and to save gas in case the initial owner is not the caller.
    /// For performance reasons, this function will not check if there
    /// is an existing owner.
    function _initializeOwner(address newOwner) internal virtual {
        if (_guardInitializeOwner()) {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                if sload(ownerSlot) {
                    mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
                    revert(0x1c, 0x04)
                }
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Store the new value.
                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
            }
        } else {
            /// @solidity memory-safe-assembly
            assembly {
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Store the new value.
                sstore(_OWNER_SLOT, newOwner)
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
            }
        }
    }

    /// @dev Sets the owner directly without authorization guard.
    function _setOwner(address newOwner) internal virtual {
        if (_guardInitializeOwner()) {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                // Store the new value.
                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
            }
        } else {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                // Store the new value.
                sstore(ownerSlot, newOwner)
            }
        }
    }

    /// @dev Throws if the sender is not the owner.
    function _checkOwner() internal view virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // If the caller is not the stored owner, revert.
            if iszero(eq(caller(), sload(_OWNER_SLOT))) {
                mstore(0x00, 0x82b42900) // `Unauthorized()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Returns how long a two-step ownership handover is valid for in seconds.
    /// Override to return a different value if needed.
    /// Made internal to conserve bytecode. Wrap it in a public function if needed.
    function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
        return 48 * 3600;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  PUBLIC UPDATE FUNCTIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Allows the owner to transfer the ownership to `newOwner`.
    function transferOwnership(address newOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(shl(96, newOwner)) {
                mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
                revert(0x1c, 0x04)
            }
        }
        _setOwner(newOwner);
    }

    /// @dev Allows the owner to renounce their ownership.
    function renounceOwnership() public payable virtual onlyOwner {
        _setOwner(address(0));
    }

    /// @dev Request a two-step ownership handover to the caller.
    /// The request will automatically expire in 48 hours (172800 seconds) by default.
    function requestOwnershipHandover() public payable virtual {
        unchecked {
            uint256 expires = block.timestamp + _ownershipHandoverValidFor();
            /// @solidity memory-safe-assembly
            assembly {
                // Compute and set the handover slot to `expires`.
                mstore(0x0c, _HANDOVER_SLOT_SEED)
                mstore(0x00, caller())
                sstore(keccak256(0x0c, 0x20), expires)
                // Emit the {OwnershipHandoverRequested} event.
                log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
            }
        }
    }

    /// @dev Cancels the two-step ownership handover to the caller, if any.
    function cancelOwnershipHandover() public payable virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, caller())
            sstore(keccak256(0x0c, 0x20), 0)
            // Emit the {OwnershipHandoverCanceled} event.
            log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
        }
    }

    /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
    /// Reverts if there is no existing ownership handover requested by `pendingOwner`.
    function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            let handoverSlot := keccak256(0x0c, 0x20)
            // If the handover does not exist, or has expired.
            if gt(timestamp(), sload(handoverSlot)) {
                mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
                revert(0x1c, 0x04)
            }
            // Set the handover slot to 0.
            sstore(handoverSlot, 0)
        }
        _setOwner(pendingOwner);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   PUBLIC READ FUNCTIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the owner of the contract.
    function owner() public view virtual returns (address result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := sload(_OWNER_SLOT)
        }
    }

    /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
    function ownershipHandoverExpiresAt(address pendingOwner)
        public
        view
        virtual
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the handover slot.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            // Load the handover slot.
            result := sload(keccak256(0x0c, 0x20))
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         MODIFIERS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Marks a function as only callable by the owner.
    modifier onlyOwner() virtual {
        _checkOwner();
        _;
    }
}

lib/solady/src/tokens/ERC20.sol

// 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)
///
/// @dev 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.
/// - The `permit` function uses the ecrecover precompile (0x1).
///
/// If you are overriding:
/// - NEVER violate the ERC20 invariant:
///   the total sum of all balances must be equal to `totalSupply()`.
/// - Check that the overridden function is actually used in the function you want to
///   change the behavior of. Much of the code has been manually inlined for performance.
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();

    /// @dev The allowance of Permit2 is fixed at infinity.
    error Permit2AllowanceIsFixedAtInfinity();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           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;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         CONSTANTS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`.
    uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901;

    /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
    bytes32 private constant _DOMAIN_TYPEHASH =
        0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;

    /// @dev `keccak256("1")`.
    /// If you need to use a different version, override `_versionHash`.
    bytes32 private constant _DEFAULT_VERSION_HASH =
        0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6;

    /// @dev `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`.
    bytes32 private constant _PERMIT_TYPEHASH =
        0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;

    /// @dev The canonical Permit2 address.
    /// For signature-based allowance granting for single transaction ERC20 `transferFrom`.
    /// Enabled by default. To disable, override `_givePermit2InfiniteAllowance()`.
    /// [Github](https://github.com/Uniswap/permit2)
    /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
    address internal constant _PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       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)
    {
        if (_givePermit2InfiniteAllowance()) {
            if (spender == _PERMIT2) return type(uint256).max;
        }
        /// @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) {
        if (_givePermit2InfiniteAllowance()) {
            /// @solidity memory-safe-assembly
            assembly {
                // If `spender == _PERMIT2 && amount != type(uint256).max`.
                if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) {
                    mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`.
                    revert(0x1c, 0x04)
                }
            }
        }
        /// @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 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);
        // Code duplication is for zero-cost abstraction if possible.
        if (_givePermit2InfiniteAllowance()) {
            /// @solidity memory-safe-assembly
            assembly {
                let from_ := shl(96, from)
                if iszero(eq(caller(), _PERMIT2)) {
                    // 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 not(allowance_) {
                        // 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)))
            }
        } else {
            /// @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 not(allowance_) {
                    // 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 For more performance, override to return the constant value
    /// of `keccak256(bytes(name()))` if `name()` will never change.
    function _constantNameHash() internal view virtual returns (bytes32 result) {}

    /// @dev If you need a different value, override this function.
    function _versionHash() internal view virtual returns (bytes32 result) {
        result = _DEFAULT_VERSION_HASH;
    }

    /// @dev For inheriting contracts to increment the nonce.
    function _incrementNonce(address owner) internal virtual {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x0c, _NONCES_SLOT_SEED)
            mstore(0x00, owner)
            let nonceSlot := keccak256(0x0c, 0x20)
            sstore(nonceSlot, add(1, sload(nonceSlot)))
        }
    }

    /// @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 {
        if (_givePermit2InfiniteAllowance()) {
            /// @solidity memory-safe-assembly
            assembly {
                // If `spender == _PERMIT2 && value != type(uint256).max`.
                if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(value)))) {
                    mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`.
                    revert(0x1c, 0x04)
                }
            }
        }
        bytes32 nameHash = _constantNameHash();
        //  We simply calculate it on-the-fly to allow for cases where the `name` may change.
        if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
        bytes32 versionHash = _versionHash();
        /// @solidity memory-safe-assembly
        assembly {
            // Revert if the block timestamp is greater than `deadline`.
            if gt(timestamp(), deadline) {
                mstore(0x00, 0x1a15a3cc) // `PermitExpired()`.
                revert(0x1c, 0x04)
            }
            let m := mload(0x40) // Grab the free memory pointer.
            // 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(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX)
            mstore(0x00, owner)
            let nonceSlot := keccak256(0x0c, 0x20)
            let nonceValue := sload(nonceSlot)
            // Prepare the domain separator.
            mstore(m, _DOMAIN_TYPEHASH)
            mstore(add(m, 0x20), nameHash)
            mstore(add(m, 0x40), versionHash)
            mstore(add(m, 0x60), chainid())
            mstore(add(m, 0x80), address())
            mstore(0x2e, keccak256(m, 0xa0))
            // Prepare the struct hash.
            mstore(m, _PERMIT_TYPEHASH)
            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)
            mstore(0x4e, keccak256(m, 0xc0))
            // Prepare the ecrecover calldata.
            mstore(0x00, keccak256(0x2c, 0x42))
            mstore(0x20, and(0xff, v))
            mstore(0x40, r)
            mstore(0x60, s)
            let t := staticcall(gas(), 1, 0x00, 0x80, 0x20, 0x20)
            // If the ecrecover fails, the returndatasize will be 0x00,
            // `owner` will 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)
            }
            // Increment and store the updated nonce.
            sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds.
            // 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-712 domain separator for the EIP-2612 permit.
    function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) {
        bytes32 nameHash = _constantNameHash();
        //  We simply calculate it on-the-fly to allow for cases where the `name` may change.
        if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
        bytes32 versionHash = _versionHash();
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Grab the free memory pointer.
            mstore(m, _DOMAIN_TYPEHASH)
            mstore(add(m, 0x20), nameHash)
            mstore(add(m, 0x40), versionHash)
            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 {
        if (_givePermit2InfiniteAllowance()) {
            if (spender == _PERMIT2) return; // Do nothing, as allowance is infinite.
        }
        /// @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 not(allowance_) {
                // 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 {
        if (_givePermit2InfiniteAllowance()) {
            /// @solidity memory-safe-assembly
            assembly {
                // If `spender == _PERMIT2 && amount != type(uint256).max`.
                if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) {
                    mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`.
                    revert(0x1c, 0x04)
                }
            }
        }
        /// @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 {}

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          PERMIT2                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns whether to fix the Permit2 contract's allowance at infinity.
    ///
    /// This value should be kept constant after contract initialization,
    /// or else the actual allowance values may not match with the {Approval} events.
    /// For best performance, return a compile-time constant for zero-cost abstraction.
    function _givePermit2InfiniteAllowance() internal view virtual returns (bool) {
        return true;
    }
}

lib/solady/src/utils/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Reentrancy guard mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Unauthorized reentrant call.
    error Reentrancy();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          STORAGE                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Equivalent to: `uint72(bytes9(keccak256("_REENTRANCY_GUARD_SLOT")))`.
    /// 9 bytes is large enough to avoid collisions with lower slots,
    /// but not too large to result in excessive bytecode bloat.
    uint256 private constant _REENTRANCY_GUARD_SLOT = 0x929eee149b4bd21268;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      REENTRANCY GUARD                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Guards a function from reentrancy.
    modifier nonReentrant() virtual {
        /// @solidity memory-safe-assembly
        assembly {
            if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                mstore(0x00, 0xab143c06) // `Reentrancy()`.
                revert(0x1c, 0x04)
            }
            sstore(_REENTRANCY_GUARD_SLOT, address())
        }
        _;
        /// @solidity memory-safe-assembly
        assembly {
            sstore(_REENTRANCY_GUARD_SLOT, codesize())
        }
    }

    /// @dev Guards a view function from read-only reentrancy.
    modifier nonReadReentrant() virtual {
        /// @solidity memory-safe-assembly
        assembly {
            if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                mstore(0x00, 0xab143c06) // `Reentrancy()`.
                revert(0x1c, 0x04)
            }
        }
        _;
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "solady/=lib/solady/src/",
    "@uniswap/v4-core/=lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "@openzeppelin/uniswap-hooks/=lib/uniswap-hooks/",
    "permit2/=lib/v4-periphery/lib/permit2/",
    "v4-router/=lib/v4-router/src/",
    "@v4/=lib/v4-core/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.