Verified contractExactMIT
Ratchet
Address0x792ebdc632bbd4d41f2521ffb502d2424b1f2338
- Balance
0.000182 ETH
- Transactions
9
- Compiler
solc 0.8.24
- Same code
Only this contract
Details
- Compiler
- solc 0.8.24+commit.e11b9ed9
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,870,439
- Creation transaction
- 0x50738323a8…cb3cedf5b5
5 files
- src/pieces/Ratchet.solmain1.26 KB
- src/Interfaces.sol1.04 KB
- src/base/Collectible.sol2.83 KB
- src/base/ERC721.sol3.58 KB
- src/lib/Meta.sol3.18 KB
src/pieces/Ratchet.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Collectible, IArt} from "../base/Collectible.sol";
import {Meta} from "../lib/Meta.sol";
/// @title Ratchet - the price only ever rises.
/// To take it, pay more than the last price. The seller keeps the gain. No fee.
contract Ratchet is Collectible {
uint256 public last; // last price paid; the next buyer must exceed it
constructor(address steward_, IArt art_, uint256 start) Collectible("Ratchet", "RTCH", steward_, art_) {
last = start;
_mint(steward_, 1);
}
function buy() external payable {
require(msg.value > last, "must exceed");
address holder = ownerOf(1);
last = msg.value;
_sold(msg.value);
_move(holder, msg.sender, 1);
_pay(holder, msg.value); // conviction rewarded: the seller keeps the gain
}
function defaultRender(uint256) public pure override returns (string memory) {
return Meta.uri("Ratchet", "never anything but up",
Meta.plate("Ratchet", "#faf8f3", "#141210"));
}
function rules() external pure override returns (string memory) {
return "Ratchet. the price only rises. to take it, pay more than the last; the seller keeps the gain.";
}
}
src/Interfaces.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// A community-adopted renderer. Receives the piece's address so it may read the
/// piece's live state and return a static image OR a state-reactive one (Tug, Ask).
interface IRenderer {
function render(address piece, uint256 id) external view returns (string memory uri);
}
/// Every piece of the collection exposes these to Art.
interface ICollectible {
/// cumulative ETH that has ever changed hands through this piece (primary + secondary).
function volume() external view returns (uint256);
/// the piece's own honest rendering, used until the community adopts an Art renderer
/// (Ask -> its price, Tug -> its colour, the rest -> their word).
function defaultRender(uint256 id) external view returns (string memory uri);
}
/// Fork is the membership token: one endorsement weight per edition held.
interface IFork {
function totalSupply() external view returns (uint256);
function balanceOf(address holder) external view returns (uint256);
}
src/base/Collectible.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {ERC721} from "./ERC721.sol";
import {ICollectible} from "../Interfaces.sol";
interface IArt {
function rendering(uint256 id) external view returns (string memory);
function allPieces() external view returns (address[] memory);
}
/// @notice Common ground for every piece of the collection.
///
/// - the image is delegated to `Art` (which falls back to this piece's own
/// `defaultRender`), so the community can dress the collection later; `art` is
/// fixed at construction - no piece can ever be re-pointed;
/// - `beacon` is a strictly separate bag of ETH the steward may top up and pull back
/// for discovery - it can never touch a sale, a fee, or a holder's funds;
/// - `volume` is the cumulative ETH that has moved through the piece; Art sums it
/// across the ring to gate the community's power.
abstract contract Collectible is ERC721, ICollectible {
address public immutable steward; // the deployer (0xflorent) - beacon only
IArt public immutable art;
uint256 public volume; // cumulative sales (ICollectible)
uint256 public beaconBalance; // discovery bait, segregated
uint256 public lifeBalance; // fed by Proof of Life's heartbeat, never withdrawable
constructor(string memory n, string memory s, address steward_, IArt art_) ERC721(n, s) {
steward = steward_;
art = art_;
}
modifier onlySteward() { require(msg.sender == steward, "not steward"); _; }
function tokenURI(uint256 id) public view override returns (string memory) {
ownerOf(id); // reverts if not minted
return art.rendering(id);
}
// --- the piece's own permanent look (used until the community adopts art) ---
function defaultRender(uint256 id) public view virtual returns (string memory);
// --- the on-chain readme, read by scanners and humans ---
function rules() external view virtual returns (string memory);
// --- beacon: discovery bait the steward may add and reclaim, nothing else ---
function seedBeacon() external payable onlySteward { beaconBalance += msg.value; }
function pullBeacon(uint256 amount) external onlySteward {
require(amount <= beaconBalance, "over beacon");
beaconBalance -= amount;
(bool ok,) = msg.sender.call{value: amount}("");
require(ok, "send");
}
/// anyone (Proof of Life's heartbeat) may add permanent, non-withdrawable life
function pulse() external payable { lifeBalance += msg.value; }
// --- internal: record a sale toward the collection's proven volume ---
function _sold(uint256 amount) internal { volume += amount; }
function _pay(address to, uint256 amount) internal {
(bool ok,) = to.call{value: amount}("");
require(ok, "pay");
}
}
src/base/ERC721.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice Minimal ERC-721 (single-file, no deps). Enough for the collection:
/// ownership, transfer, approval, enumerable-free. `tokenURI` is left abstract.
abstract contract ERC721 {
string public name;
string public symbol;
mapping(uint256 => address) internal _ownerOf;
mapping(address => uint256) internal _balanceOf;
mapping(uint256 => address) public getApproved;
mapping(address => mapping(address => bool)) public isApprovedForAll;
event Transfer(address indexed from, address indexed to, uint256 indexed id);
event Approval(address indexed owner, address indexed spender, uint256 indexed id);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
constructor(string memory _name, string memory _symbol) {
name = _name;
symbol = _symbol;
}
function tokenURI(uint256 id) public view virtual returns (string memory);
function ownerOf(uint256 id) public view virtual returns (address owner) {
require((owner = _ownerOf[id]) != address(0), "not minted");
}
function balanceOf(address owner) public view virtual returns (uint256) {
require(owner != address(0), "zero");
return _balanceOf[owner];
}
function approve(address spender, uint256 id) public virtual {
address owner = _ownerOf[id];
require(msg.sender == owner || isApprovedForAll[owner][msg.sender], "not authorized");
getApproved[id] = spender;
emit Approval(owner, spender, id);
}
function setApprovalForAll(address operator, bool approved) public virtual {
isApprovedForAll[msg.sender][operator] = approved;
emit ApprovalForAll(msg.sender, operator, approved);
}
/// override point for pieces with special transfer rules (soulbound, gift-only, ...)
function _beforeTransfer(address from, address to, uint256 id) internal virtual {}
function transferFrom(address from, address to, uint256 id) public virtual {
require(from == _ownerOf[id], "wrong from");
require(to != address(0), "zero to");
require(
msg.sender == from || isApprovedForAll[from][msg.sender] || msg.sender == getApproved[id],
"not authorized"
);
_beforeTransfer(from, to, id);
_balanceOf[from]--;
_balanceOf[to]++;
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
function safeTransferFrom(address from, address to, uint256 id) public virtual {
transferFrom(from, to, id);
}
function supportsInterface(bytes4 iid) public pure virtual returns (bool) {
return iid == 0x80ac58cd || iid == 0x01ffc9a7 || iid == 0x5b5e139f; // 721, 165, metadata
}
// --- internal mint / move used by piece mechanics ---
function _mint(address to, uint256 id) internal virtual {
require(to != address(0), "zero");
require(_ownerOf[id] == address(0), "exists");
_balanceOf[to]++;
_ownerOf[id] = to;
emit Transfer(address(0), to, id);
}
/// mechanic-driven move (a sale, a paint, a beat): bypasses approvals AND the
/// public-transfer guard, so gift-only / soulbound pieces still run their own logic
function _move(address from, address to, uint256 id) internal virtual {
if (from != address(0)) _balanceOf[from]--;
_balanceOf[to]++;
_ownerOf[id] = to;
delete getApproved[id];
emit Transfer(from, to, id);
}
}
src/lib/Meta.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice Tiny on-chain rendering helpers. Everything is a `utf8` data URI - no
/// base64, no libraries - so the primary render of every piece is plain, permanent
/// and legible in the bytecode itself. SVG uses single quotes so it nests inside
/// the JSON's double quotes without escaping.
library Meta {
/// unsigned integer -> decimal string
function str(uint256 v) internal pure returns (string memory) {
if (v == 0) return "0";
uint256 n = v;
uint256 len;
while (n != 0) { len++; n /= 10; }
bytes memory b = new bytes(len);
while (v != 0) { b[--len] = bytes1(uint8(48 + v % 10)); v /= 10; }
return string(b);
}
/// wei -> "12.34" ETH string, trimmed to `decimals` places
function eth(uint256 wei_, uint256 decimals) internal pure returns (string memory) {
uint256 whole = wei_ / 1e18;
uint256 frac = (wei_ % 1e18) / (10 ** (18 - decimals));
bytes memory f = bytes(str(frac));
// left-pad the fraction to `decimals` digits
bytes memory pad = new bytes(decimals);
for (uint256 i; i < decimals; ++i) pad[i] = "0";
for (uint256 i; i < f.length; ++i) pad[decimals - f.length + i] = f[i];
return string(abi.encodePacked(str(whole), ".", pad));
}
/// #rrggbb from a packed uint24
function color(uint24 c) internal pure returns (string memory) {
bytes16 hexd = "0123456789abcdef";
bytes memory s = new bytes(7);
s[0] = "#";
for (uint256 i; i < 6; ++i) s[6 - i] = hexd[(uint256(c) >> (4 * i)) & 0xf];
return string(s);
}
/// wrap an <svg> body into a full data URI with name + description
function uri(string memory name, string memory desc, string memory svg)
internal pure returns (string memory)
{
return string(abi.encodePacked(
"data:application/json;utf8,",
'{"name":"', name, '","description":"', desc,
'","image":"data:image/svg+xml;utf8,', svg, '"}'
));
}
/// the primary look: one thing, centred, on a ground. `main` is the word / number,
/// `bg` the ground, `fg` the ink. No ornament - the word carries it.
function plate(string memory main, string memory bg, string memory fg)
internal pure returns (string memory)
{
return string(abi.encodePacked(
"<svg xmlns='http://www.w3.org/2000/svg' width='600' height='600' viewBox='0 0 600 600'>",
"<rect width='600' height='600' fill='", bg, "'/>",
"<text x='300' y='318' text-anchor='middle' ",
"font-family='Didot, \"Bodoni MT\", \"Hoefler Text\", Georgia, serif' ",
"font-size='72' fill='", fg, "'>", main, "</text></svg>"
));
}
/// a full field of one colour - Tug's primary look
function field(string memory hexColor) internal pure returns (string memory) {
return string(abi.encodePacked(
"<svg xmlns='http://www.w3.org/2000/svg' width='600' height='600'>",
"<rect width='600' height='600' fill='", hexColor, "'/></svg>"
));
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.