Skip to content
Verified contractPartialMIT

Usd4

Address0x1d8a582d0aa40b007d6e6d1af5d2d6aad877d28b
Balance

0 ETH

 

Transactions

40

 

Compiler

solc 0.8.35

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.35+commit.47b9dedd
Language
solidity
Optimization
Yes, 1 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,890,035
Creation transaction
0x91b6180a34…15bdd1e9c8
Proxy implementation
0xe2683060…e197b411Usd4

src/Usd4Token.sol

// SPDX-License-Identifier: MIT
//
//   .--.  .--.  .--.  .--.
//  ( $  )( $  )( $  )( $  )
//   '--'  '--'  '--'  '--'
//
//  USD4 · the deliverable dollar basket
//  https://www.usd4.org/ · https://x.com/USD4_
//
pragma solidity ^0.8.26;

/*──────────────────────────────────────────────────────────────
  ERC-1967 immutable proxy for $USD4.

  All ERC-20 state (totalSupply · balances · allowances) is stored
  here. Every call is delegated to the sealed logic contract whose
  address lives at the canonical ERC-1967 implementation slot.

  Design rules — enforced at construction, permanent thereafter:
    · No upgradeTo — implementation slot is written once and sealed.
    · ERC-1967 compliant — slot = keccak256("eip1967.proxy.implementation") - 1
    · Transparent — every unmatched selector forwarded as-is via delegatecall.
    · Atomic init — supply minted inside the constructor, unreplayable.
    · Input hardening — zero-address and EOA checks before any write.
──────────────────────────────────────────────────────────────*/
contract Usd4 {

    // ERC-1967 slot: bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)
    bytes32 internal constant _IMPLEMENTATION_SLOT =
        0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    // ── proxy-level constants ─────────────────────────────────────────────

    string  public constant PROTOCOL      = "USD4";
    string  public constant PROXY_VERSION = "1.0.0";
    bool    public constant UPGRADEABLE   = false;
    uint8   public constant LEG_COUNT     = 4;
    uint8   public constant TIER_COUNT    = 5;
    uint256 public constant TOTAL_SUPPLY  = 1_000_000_000 * 1e18;
    string  public constant website       = "https://usd4.org";
    string  public constant twitterX      = "https://x.com/USD4_";

    // ── events ────────────────────────────────────────────────────────────

    event Upgraded(address indexed implementation);
    event ProxyInitialized(address indexed initializer, address indexed deployer);

    // ── errors ────────────────────────────────────────────────────────────

    error ZeroImplementation();
    error ZeroInitializer();
    error ZeroDeployer();
    error NotAContract(address target);
    error InitializationFailed();

    // ── constructor ───────────────────────────────────────────────────────

    constructor(address _implementation, address _initializer, address _deployer) {

        // reject zero addresses up front
        if (_implementation == address(0)) revert ZeroImplementation();
        if (_initializer    == address(0)) revert ZeroInitializer();
        if (_deployer       == address(0)) revert ZeroDeployer();

        // reject EOAs — a code-less impl silently no-ops every delegatecall
        if (_implementation.code.length == 0) revert NotAContract(_implementation);
        if (_initializer.code.length    == 0) revert NotAContract(_initializer);

        // mint 1,000,000,000 USD4 to _deployer in proxy storage.
        // runs inside the constructor — unreplayable, cannot be front-run.
        (bool ok, bytes memory ret) = _initializer.delegatecall(
            abi.encodeWithSignature("initialize(address)", _deployer)
        );
        if (!ok) {
            if (ret.length > 0) { assembly { revert(add(ret, 0x20), mload(ret)) } }
            revert InitializationFailed();
        }
        emit ProxyInitialized(_initializer, _deployer);

        // seal — one write, no code path touches this slot again
        assembly { sstore(_IMPLEMENTATION_SLOT, _implementation) }
        emit Upgraded(_implementation);
    }

    // ── native proxy reads ────────────────────────────────────────────────

    // sealed logic address — the only selector resolved here without delegation
    function implementation() external view returns (address impl) {
        impl = _implementation_();
    }

    // protocol identity
    function protocolName()  external pure returns (string memory) { return PROTOCOL; }
    function proxyVersion()  external pure returns (string memory) { return PROXY_VERSION; }
    function isUpgradeable() external pure returns (bool)          { return UPGRADEABLE; }

    // basket shape — matches constants in the implementation
    function legCount()       external pure returns (uint8)   { return LEG_COUNT; }
    function tierCount()      external pure returns (uint8)   { return TIER_COUNT; }
    function expectedSupply() external pure returns (uint256) { return TOTAL_SUPPLY; }

    // ── internals ─────────────────────────────────────────────────────────

    function _implementation_() internal view returns (address impl) {
        assembly { impl := sload(_IMPLEMENTATION_SLOT) }
    }

    // forward any call to impl, return or revert with its exact payload
    function _delegate(address impl) internal {
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }

    // ── delegation entrypoints ────────────────────────────────────────────

    fallback() external payable { _delegate(_implementation_()); }
    receive()  external payable {}
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 1,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@uniswap/v4-core/=lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "permit2/=lib/permit2/",
    "forge-std/=lib/forge-std/src/",
    "solady/=lib/solady/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
    "ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/v4-core/node_modules/hardhat/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solmate/=lib/v4-core/lib/solmate/",
    "v4-core/=lib/v4-core/src/",
    "v4-periphery/=lib/v4-periphery/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.