Skip to content
Verified contractExactMIT

QusdCoin

Address0x4c4a7f689bd325bb413709e20021848b668b5ef9
Balance

0 ETH

 

Transactions

5

 

Compiler

solc 0.8.30

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,344,663
Creation transaction
0x897496a732…2dd714795c

QusdCoin.sol

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

/// @title QUSD — the coin. Fungible only. Bound to its face by the ByteID.
/// @author QUANTVESTRIX INC.
///
/// WHY THIS CONTRACT EXISTS SEPARATELY
/// -----------------------------------
/// The previous canonical QUSD answered ERC-165 with 0x80ac58cd, because the same address
/// carried both the coin and its $1 NFT face. Every Etherscan-family explorer reads
/// ERC-165 first, so all four chains filed QUSD as an NFT COLLECTION and suppressed every
/// fungible behaviour: holders 0, transfers 0, market N/A, no price. MetaMask, DexScreener,
/// CoinGecko and DefiLlama all inherit that call. Observed live 2026-09-14 on BscScan and
/// PolygonScan while the ERC-20 surface underneath was perfectly intact.
///
/// `supportsInterface` there is `external pure` with the constant hardcoded, and the
/// contract is not a proxy, so it cannot be corrected in place. Hence a split - NOT a
/// separation. The face is not being taken away; it is being moved to its own address so
/// that each contract answers exactly one question about itself.
///
/// HOW THEY STAY ONE THING - THE BYTEID DOES IT, NOT A REGISTRY
/// ------------------------------------------------------------
///     tokenId = uint256(keccak256(bytes(byteid)))
///
/// The coin and the face compute that same line from the same substrate-minted string, so
/// the same ByteID resolves to the SAME id on both contracts and on every chain. The link
/// is computable by anyone and stored by nobody. Nothing is registered, mirrored or synced,
/// so nothing can drift out of sync.
///
/// THIS CONTRACT NEVER JUDGES A BYTEID. IT PINS ONE.
/// -------------------------------------------------
/// A ByteID can only be made by the L0 substrate folding real content
/// (qvtx_substrate.byteid_pair_quaternary, via qvtx_byteid_roundtrip.mint). The chain
/// cannot run that fold, and must not pretend to. Checking a ByteID's *shape* on-chain
/// would be worse than no check: "QVTX-AAA-00000000-00000000-0000-A-0000" is perfectly
/// well-formed and no fold ever produced it, so a grammar check would bless fakes while
/// looking like validation.
///
/// The real gate is off-chain and already enforced at the mint (tools/mint_cascade.py):
/// the ByteID is folded FROM the mint instruction itself, and `recover(byteid)` must return
/// those exact bytes or the mint refuses to broadcast. A fabricated ByteID recovers nothing
/// - no strand was ever written to the L0 base for it - so it never reaches this contract.
///
/// What the chain enforces instead is scarcity, and that it does absolutely:
/// `AlreadyPinned` means one fold, one coin, one face, one redemption. Ever.
contract QusdCoin {
    error NotOwner();
    error NotMinter();
    error ZeroAddress();
    error Unbacked();
    error AlreadyPinned();
    error NoSuchMark();
    error Bal();
    error Allow();
    error NotFace();
    error FaceSet();

    // ───────────────────────────────────────────────────────────────── ERC-20
    string  public constant name     = "QVTX USD";
    string  public constant symbol   = "QUSD";
    uint8   public constant decimals = 18;
    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    address public constant reserve = 0xCDb91C04B6A730f52fd23887d002d9d6BEE4C066;

    string public constant MINT_SITE   = "https://qusd.qvtx.net/mint";
    string public constant REDEEM_SITE = "https://qusd.qvtx.net/redeem";
    string public constant VERIFIER    = "https://exchange.qvtx.net/qusd";

    address public owner;
    address public minter;

    /// @notice The ERC-721 face. Set once, then immutable in practice: a face that could be
    ///         repointed would let the coin disown the marks it already issued.
    address public face;

    uint256 public totalBackingCents;

    // ───────────────────────────────────────────── the marks (state lives HERE)
    /// @dev The face contract holds ERC-721 ownership and renders. The FACTS about a mark -
    ///      what it is backed by, what coin it carried, whether it was a redemption - live
    ///      here, with the supply they describe. One truth, read by the face, never copied
    ///      into it.
    struct Mark {
        string  byteid;
        uint256 cents;
        uint256 units;
        uint64  at;
        bool    isRedeem;
        bool    exists;
    }
    mapping(uint256 => Mark) private _mark;
    uint256 public marksIssued;

    /// @dev The cascade edge. A redemption is its OWN fold - the substrate folds the redeem
    ///      instruction, not the mint's - so it gets its own id, exactly as the deployed
    ///      contract does. This records which mint it cascaded from, so the chain carries
    ///      the lineage rather than leaving it only inside the folded content.
    mapping(uint256 => uint256) public cascadedFrom;
    mapping(uint256 => uint256) public cascadedTo;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed o, address indexed spender, uint256 value);
    event Minted(address indexed to, uint256 amount, string byteid, uint256 cents, uint256 tokenId);
    event Redeemed(address indexed from, uint256 amount, string byteid, uint256 tokenId);
    event Cascaded(uint256 indexed fromId, uint256 indexed toId, uint256 unitsBurned);
    event FaceBound(address indexed face);

    modifier onlyOwner()  { if (msg.sender != owner)  revert NotOwner();  _; }
    modifier onlyMinter() { if (msg.sender != minter) revert NotMinter(); _; }

    constructor(address _owner, address _minter) {
        if (_owner == address(0) || _minter == address(0)) revert ZeroAddress();
        owner = _owner;
        minter = _minter;
    }

    /// @notice Bind the face, once. Reverts ever after.
    function bindFace(address f) external onlyOwner {
        if (f == address(0)) revert ZeroAddress();
        if (face != address(0)) revert FaceSet();
        face = f;
        emit FaceBound(f);
    }

    // ───────────────────────────────────────────────────────── ERC-20 movement
    function transfer(address to, uint256 v) external returns (bool) {
        return _move(msg.sender, to, v);
    }

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

    function transferFrom(address f, address t, uint256 v) external returns (bool) {
        uint256 a = allowance[f][msg.sender];
        if (a < v) revert Allow();
        if (a != type(uint256).max) allowance[f][msg.sender] = a - v;
        return _move(f, t, v);
    }

    function _move(address f, address t, uint256 v) internal returns (bool) {
        if (t == address(0)) revert ZeroAddress();
        uint256 b = balanceOf[f];
        if (b < v) revert Bal();
        unchecked { balanceOf[f] = b - v; balanceOf[t] += v; }
        emit Transfer(f, t, v);
        return true;
    }

    // ─────────────────────────────────────────────────── the binding, in one line
    /// @notice The id a ByteID resolves to. `pure` and identical on the face contract and
    ///         on every chain, which is the whole binding: same fold, same id, everywhere.
    ///         Anyone can compute it without asking either contract anything.
    function tokenIdOf(string memory byteid) public pure returns (uint256) {
        return uint256(keccak256(bytes(byteid)));
    }

    function byteIdOf(uint256 id) external view returns (string memory) {
        if (!_mark[id].exists) revert NoSuchMark();
        return _mark[id].byteid;
    }

    function isPinned(string calldata byteid) external view returns (bool) {
        return _mark[tokenIdOf(byteid)].exists;
    }

    function markOf(uint256 id) external view returns (
        string memory byteid, uint256 cents, uint256 units,
        uint64 at, bool isRedeem, bool exists)
    {
        Mark storage m = _mark[id];
        return (m.byteid, m.cents, m.units, m.at, m.isRedeem, m.exists);
    }

    /// @dev Pin. Never validate - see the contract header. The face is told, and refuses
    ///      any issue that did not come from here, so a face can exist only because a coin
    ///      movement created it.
    function _pin(address to, string memory byteid, uint256 cents, uint256 units,
                  bool isRedeem)
        internal returns (uint256 id)
    {
        id = uint256(keccak256(bytes(byteid)));
        if (_mark[id].exists) revert AlreadyPinned();   // one identifier, one coin. Ever.
        _mark[id] = Mark(byteid, cents, units, uint64(block.timestamp), isRedeem, true);
        unchecked { marksIssued += 1; }
        IQusdFace(face).issue(to, id);
    }

    // ────────────────────────────────────────────────────────────── mint / redeem
    /// @notice Issue QUSD against recorded fiat and pin the ByteID that proves it.
    /// @dev Rail, settlement reference, source transaction and sponsor are folded into
    ///      `byteid` by the substrate and recovered from it. Only the backing figure is
    ///      kept here, so a chain reader needs no kernel to check cover.
    function mintWithByteId(address to, uint256 amount, string calldata byteid, uint256 cents)
        external onlyMinter returns (uint256 id)
    {
        if (to == address(0)) revert ZeroAddress();
        if (cents == 0) revert Unbacked();          // a dollar nobody pegged cannot exist
        unchecked {
            totalSupply += amount;
            balanceOf[to] += amount;
            totalBackingCents += cents;
        }
        emit Transfer(address(0), to, amount);
        id = _pin(to, byteid, cents, amount, false);
        emit Minted(to, amount, byteid, cents, id);
    }

    /// @notice Burn to redeem, pinning the redemption's OWN fold and cascading from the
    ///         mint it came out of.
    /// @param parentByteId the mint fold being cascaded. Pass "" for a redemption with no
    ///        single parent mint; the burn still stands, it simply records no edge rather
    ///        than inventing one.
    function redeemWithByteId(uint256 amount, string calldata byteid,
                              string calldata parentByteId)
        external returns (uint256 id)
    {
        uint256 b = balanceOf[msg.sender];
        if (b < amount) revert Bal();
        unchecked { balanceOf[msg.sender] = b - amount; totalSupply -= amount; }

        // The backing leaves WITH the coin. Burning supply without releasing the cents
        // behind it would leave totalBackingCents standing against a supply that no longer
        // exists - backing() would overstate the reserve from the first redemption onward,
        // and it would never come back into line. 1e18 units is one dollar is 100 cents,
        // so 1e16 units is one cent. Clamped, because a redemption must never be the thing
        // that underflows the book.
        uint256 released = amount / 1e16;
        if (released > totalBackingCents) released = totalBackingCents;
        unchecked { totalBackingCents -= released; }

        emit Transfer(msg.sender, address(0), amount);
        id = _pin(msg.sender, byteid, released, 0, true);

        // The cascade edge, recorded only when the parent is a mark this contract actually
        // issued. An edge to something that was never pinned would be a claim, not a fact.
        if (bytes(parentByteId).length != 0) {
            uint256 pid = uint256(keccak256(bytes(parentByteId)));
            if (!_mark[pid].exists) revert NoSuchMark();
            cascadedFrom[id] = pid;
            cascadedTo[pid]  = id;
            emit Cascaded(pid, id, amount);
        }
        emit Redeemed(msg.sender, amount, byteid, id);
    }

    // ────────────────────────────────────────────────────────────────── backing
    function backing() external view returns (
        uint256 supply, uint256 backingCents, uint256 coveredUnits, bool covered)
    {
        supply = totalSupply;
        backingCents = totalBackingCents;
        coveredUnits = totalBackingCents * 1e16;
        covered = coveredUnits >= supply;
    }

    function backingBps() external view returns (uint256) {
        if (totalSupply == 0) return 10000;
        return (totalBackingCents * 1e16 * 10000) / totalSupply;
    }

    // ───────────────────────────────────────────────────────────────── ERC-165
    /// @notice ERC-165 only. This contract does NOT answer 0x80ac58cd, and that omission is
    ///         the entire point of the split: answering it is what made every explorer file
    ///         QUSD as an NFT collection and refuse to price it. The face at `face()`
    ///         answers it instead.
    function supportsInterface(bytes4 i) external pure returns (bool) {
        return i == 0x01ffc9a7;
    }

    function setMinter(address m) external onlyOwner {
        if (m == address(0)) revert ZeroAddress();
        minter = m;
    }

    function transferOwnership(address to) external onlyOwner {
        if (to == address(0)) revert ZeroAddress();
        owner = to;
    }
}

interface IQusdFace {
    function issue(address to, uint256 id) external;
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.