Skip to content
Verified contractExactMIT

RatchetToken

Address0x77777777079ff6fbaf990adb374f5dca5a6474b9
Balance

0 ETH

 

Transactions

22

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 1,000,000 runs
EVM version
cancun
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,732,085
Creation transaction
0x589c35d617…1a0f45c8d2

contracts/RatchetToken.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

/*//////////////////////////////////////////////////////////////////////////
                                  RATCHET
                        floor = vault / supply
                       a ratchet only turns one way

                        https://x.com/Ratchet_fi
                          https://ratchet.markets
//////////////////////////////////////////////////////////////////////////*/

/// @title RatchetToken
/// @notice Minimal ERC-20 for the Ratchet system. 18 decimals. The entire
///         genesis supply is minted to the hook (which LPs it single-sided).
///         There is no mint path anywhere in this contract — total supply is
///         monotonically decreasing from genesis. Burns are the only supply
///         change and always emit Transfer(from, address(0), value).
contract RatchetToken {
    string public name;
    string public symbol;
    uint8 public constant decimals = 18;

    uint256 public immutable INITIAL_SUPPLY;
    address public immutable hook;

    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    error NotHook();
    error InsufficientBalance();
    error InsufficientAllowance();
    error TransferToZero();

    constructor(string memory name_, string memory symbol_, uint256 supply_, address hook_) {
        name = name_;
        symbol = symbol_;
        hook = hook_;
        INITIAL_SUPPLY = supply_;
        totalSupply = supply_;
        balanceOf[hook_] = supply_;
        emit Transfer(address(0), hook_, supply_);
    }

    function approve(address spender, uint256 value) external returns (bool) {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    function transfer(address to, uint256 value) external returns (bool) {
        _transfer(msg.sender, to, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value) external returns (bool) {
        uint256 allowed = allowance[from][msg.sender];
        if (allowed != type(uint256).max) {
            if (allowed < value) revert InsufficientAllowance();
            unchecked {
                allowance[from][msg.sender] = allowed - value;
            }
        }
        _transfer(from, to, value);
        return true;
    }

    /// @notice Burn your own tokens. Supply shrinks; the floor rises for everyone.
    function burn(uint256 value) external {
        _burn(msg.sender, value);
    }

    /// @notice Burn authority for the hook — used by redeem() and fee burns.
    function hookBurn(address from, uint256 value) external {
        if (msg.sender != hook) revert NotHook();
        _burn(from, value);
    }

    function _transfer(address from, address to, uint256 value) internal {
        // Transfers to the zero address must go through burn() so that
        // Transfer(_, 0x0, _) logs always mean real supply reduction.
        if (to == address(0)) revert TransferToZero();
        uint256 bal = balanceOf[from];
        if (bal < value) revert InsufficientBalance();
        unchecked {
            balanceOf[from] = bal - value;
        }
        balanceOf[to] += value;
        emit Transfer(from, to, value);
    }

    function _burn(address from, uint256 value) internal {
        uint256 bal = balanceOf[from];
        if (bal < value) revert InsufficientBalance();
        unchecked {
            balanceOf[from] = bal - value;
            totalSupply -= value;
        }
        emit Transfer(from, address(0), value);
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 1000000,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@uniswap/v4-core/=node_modules/@uniswap/v4-core/",
    "forge-std/=node_modules/forge-std/",
    "solmate/=node_modules/solmate/",
    "@openzeppelin/=node_modules/@openzeppelin/",
    "ds-test/=node_modules/ds-test/src/",
    "erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.