// SPDX-License-Identifier: MIT pragma solidity ^0.8.26; import {ERC721} from "./ERC721.sol"; import {ReceiptArt} from "./ReceiptArt.sol"; /// @title changeme contribution receipt /// @notice ERC-721 "changeme" / "CHANGE". Every contribution mints one transferable receipt that /// permanently records who contributed, the original wish and the round it joined. /// @dev Abstract base for the single deployed changeme contract. The only mint path is the /// internal `_mintReceipt`; the inheriting contract decides when (after taking payment). /// No owner, supply cap, royalties, pause, fees, burn or upgrade path. abstract contract ChangeReceipt is ERC721 { /// @notice Longest wish a receipt stores, matching the order encoder's per-wish limit. uint256 public constant MAX_WISH_BYTES = 140; struct Receipt { address contributor; // original minter, never changes on transfer uint64 round; // round (batch) the contribution joined uint32 mintedAt; // block timestamp at mint uint128 paid; // IMD (wei) paid with this contribution string wish; // original wish text, never changes } error EmptyWish(); error WishTooLong(uint256 length); error RoundTooLarge(uint256 round); error PaidTooLarge(uint256 paid); event ReceiptMinted( uint256 indexed tokenId, address indexed contributor, uint256 indexed round, uint256 paid, string wish ); uint256 private _minted; mapping(uint256 tokenId => Receipt) internal _receipts; function name() public pure override returns (string memory) { return "changeme"; } function symbol() public pure override returns (string memory) { return "CHANGE"; } /// @notice Receipts minted so far; token IDs are 1..totalSupply (nothing is ever burned). function totalSupply() public view returns (uint256) { return _minted; } /// @notice The keepsake: original contributor, round, mint time, amount paid and wish. function receiptOf(uint256 tokenId) public view returns (Receipt memory) { _requireOwned(tokenId); return _receipts[tokenId]; } function wishOf(uint256 tokenId) public view returns (string memory) { _requireOwned(tokenId); return _receipts[tokenId].wish; } function contributorOf(uint256 tokenId) public view returns (address) { _requireOwned(tokenId); return _receipts[tokenId].contributor; } function roundOf(uint256 tokenId) public view returns (uint256) { _requireOwned(tokenId); return _receipts[tokenId].round; } /// @notice On-chain JSON metadata with the full wish and light blue background. /// Attribution and payment details are available through receiptOf. function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { _requireOwned(tokenId); Receipt storage r = _receipts[tokenId]; return ReceiptArt.tokenURI(r.wish); } /// @dev Mints the next receipt to `contributor`. Does not call the receiver hook, so a /// contributor contract can neither block nor re-enter a contribution. The inheriting /// contract must validate the wish content itself (WishOrders); this only bounds its size. function _mintReceipt(address contributor, string memory wish, uint256 round, uint256 paid) internal returns (uint256 tokenId) { uint256 len = bytes(wish).length; if (len == 0) revert EmptyWish(); if (len > MAX_WISH_BYTES) revert WishTooLong(len); if (round > type(uint64).max) revert RoundTooLarge(round); if (paid > type(uint128).max) revert PaidTooLarge(paid); tokenId = ++_minted; _receipts[tokenId] = Receipt({ contributor: contributor, round: uint64(round), mintedAt: uint32(block.timestamp), paid: uint128(paid), wish: wish }); _mint(contributor, tokenId); emit ReceiptMinted(tokenId, contributor, round, paid, wish); } }