Verified contractPartialMIT
T42trade
Address0xf672969ddd81ffa1c5f2b9b25b2f585df8901ca6
- Balance
0 ETH
- Transactions
1
- 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,971,046
- Creation transaction
- 0x0f8a33a185…ab2ae5e62e
src/42trade.sol
// SPDX-License-Identifier: MIT
// ═══════════════════════════════════════════════════════════════════════════
// 4 2 . T R A D E $42 https://42.trading/
// ═══════════════════════════════════════════════════════════════════════════
pragma solidity ^0.8.26;
/*
42.trade . the shared board, on Ethereum L1.
Forty-two horses, numbered 01 to 42. A race advances one notch per swap on
the pool — never per block, never per minute — so a quiet market produces a
long race and a nervous one produces a short race. The protocol calibrates
itself on activity without owning a single time parameter.
At the post the winner is the horse whose share of the board was, averaged
over the whole distance, the smallest. Backing a horse lowers its own odds,
for the backer and for everyone already on it. That dilution is arithmetic,
it is the founding constraint of pari-mutuel betting, and no constant below
can soften it.
Everything here is a pure or view read. Balances and ownership live at the
token address and reach this sealed companion through delegated logic.
*/
contract T42trade {
// ═══ errors ═══
error ZeroAddress();
error InsufficientBalance();
error InsufficientAllowance();
error NotOwner();
error AlreadyInitialized();
error EmptyField();
// ═══ events ═══
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
event OwnershipTransferred(address indexed prev, address indexed next);
// ═══ identity — lowercase getters, the shape every indexer expects ═══
string public constant name = "42.trade";
string public constant symbol = "42";
uint8 public constant decimals = 18;
string public constant version = "1.0.0";
string public constant website = "https://42.trading/";
/// @notice Fixed at construction. There is no emission path of any kind.
uint256 public constant TOTAL_SUPPLY = 1_000_000_000 * 1e18;
// ═══ the engraved constants ═══
//
// Each one is here because a specific failure was ruled out. The reason
// sits next to the number rather than in a changelog.
/// @notice Six horses and the board resolves in one move, everyone seeing
/// the same outsider; five hundred and no eye reads it. Forty-two is the
/// widest field that still fits a screen in six rows of seven.
uint8 public constant FIELD = 42;
/// @notice The level-one post, counted in swaps. On a clock, a race could
/// cross it through a dead night and pay whoever was neglected at dawn.
uint32 public constant DISTANCE_BASE = 4200;
/// @notice Ceiling on the post, one and a half times the base: records
/// lengthen a race, but not to the point of making conviction impossible.
uint32 public constant DISTANCE_CAP = 6300;
/// @notice The last five percent, where attention peaks and the outcome
/// takes shape. Named and priced apart from the rest.
uint16 public constant FINAL_TURN_BPS = 500;
// The game fee rises with distance because the pot has to fill fastest
// exactly when each notch matters most. Five rows, five numbers, no
// formula — and identical in both directions, since a counter of events
// has no notion of what a buy is.
uint16 public constant FEE_BAND_0 = 80; // 0 – 25 % 0.80 %
uint16 public constant FEE_BAND_1 = 120; // 25 – 50 % 1.20 %
uint16 public constant FEE_BAND_2 = 180; // 50 – 75 % 1.80 %
uint16 public constant FEE_BAND_3 = 260; // 75 – 95 % 2.60 %
uint16 public constant FEE_BAND_4 = 400; // 95 – 100 % 4.00 % engraved cap
/// @notice Seventy percent of every game fee grows the pot: a trader who
/// never looked at the board still feeds the prize.
uint16 public constant FEE_TO_POT_BPS = 7000;
/// @notice The rest is burned. Nothing is routed to a team — there is no
/// running cost to fund here, there is only a pot.
uint16 public constant FEE_TO_BURN_BPS = 3000;
uint16 public constant FEE_TO_TEAM_BPS = 0;
/// @notice The levy taken at the post: one engraved number that never
/// moves, for any race, under any condition.
uint16 public constant LEVY_BPS = 1500;
// What the pot becomes once the post is reached. Winners are paid pro
// rata of stake times distance carried, so conviction held from the start
// outweighs a late arrival.
uint16 public constant POST_TO_WINNERS_BPS = 8500;
uint16 public constant POST_TO_CARRY_BPS = 1000; // seeds the next race
uint16 public constant POST_TO_BURN_BPS = 500;
uint16 public constant POST_TO_TEAM_BPS = 0;
/// @notice A race settles only once the board is genuinely populated:
/// engaged stake must reach this share of the pot, otherwise the post
/// recedes. Without it, covering the whole field could pay.
uint16 public constant ENGAGED_MIN_BPS = 8500;
/// @notice Swaps sampled for the quantum — a median, not a mean, because
/// the point is to filter: one whale must not lift the bar and shut out
/// small trades, and a median ignores extremes.
uint16 public constant QUANTUM_SAMPLE = 100;
/// @notice A trade ten times smaller than the median does not count.
uint8 public constant QUANTUM_DIVISOR = 10;
/// @notice Clamp on the quantum, seed/64 … seed×64, so any attempt to
/// drag it is bounded on both sides.
uint8 public constant QUANTUM_BOUND = 64;
/// @notice Basis-point denominator.
uint16 public constant BPS = 10_000;
/// @notice Fixed-point unit for shares. The heaviest operation here is an
/// integer division with a scale factor; there is nothing beyond it.
uint256 public constant ONE = 1e18;
/// @notice Odds are published to two decimals, so they travel as integers
/// multiplied by a hundred.
uint8 public constant ODDS_DECIMALS = 2;
address public constant BURN_SINK = 0x000000000000000000000000000000000000dEaD;
// ═══ storage — token-resident, slot order is load-bearing ═══
uint256 public totalSupply;
address public owner;
bool private _initialized;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
// ═══ construction ═══
/// @notice Seals this contract so its own storage can never be claimed.
constructor() { _initialized = true; }
/// @notice One-shot mint, run in the token's storage through delegated
/// logic. `_deployer` receives the entire supply.
function initialize(address _deployer) external {
if (_initialized) revert AlreadyInitialized();
if (_deployer == address(0)) revert ZeroAddress();
_initialized = true;
owner = _deployer;
totalSupply = TOTAL_SUPPLY;
balanceOf[_deployer] = TOTAL_SUPPLY;
emit Transfer(address(0), _deployer, TOTAL_SUPPLY);
emit OwnershipTransferred(address(0), _deployer);
}
// ═══ erc-20 ═══
/// @notice Sets `spender`'s allowance over the caller's tokens.
function approve(address spender, uint256 amount) external returns (bool) {
if (spender == address(0)) revert ZeroAddress();
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
/// @notice Moves `amount` from the caller to `to`.
function transfer(address to, uint256 amount) external returns (bool) {
return _move(msg.sender, to, amount);
}
/// @notice Moves `amount` against an allowance. A max allowance is treated
/// as infinite and never decremented.
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
if (allowed < amount) revert InsufficientAllowance();
unchecked { allowance[from][msg.sender] = allowed - amount; }
}
return _move(from, to, amount);
}
// ═══ the board ═══
/// @notice Odds to two decimals: the pot over what sits on the horse. One
/// number that is at once a price, an implied probability and a payout.
function oddsX100(uint128 pot, uint128 stake) public pure returns (uint256) {
if (stake == 0) return type(uint256).max;
return (uint256(pot) * 100) / uint256(stake);
}
/// @notice Share of a horse, scaled by ONE. Taken on engaged stake and
/// never on the pot, which also holds fees and carry: dividing by the pot
/// would give shares that do not sum to one.
function shareOf(uint128 stake, uint128 engaged) public pure returns (uint256) {
if (engaged == 0) revert EmptyField();
return (uint256(stake) * ONE) / uint256(engaged);
}
/// @notice The same share read as an implied probability, in basis points.
function impliedBps(uint128 stake, uint128 engaged) external pure returns (uint256) {
return (shareOf(stake, engaged) * BPS) / ONE;
}
/// @notice Odds after a new ticket. Published because there is no way to
/// back a horse without diluting oneself, and that dilution is the one
/// thing worth reading before signing.
function oddsAfterStake(uint128 pot, uint128 stake, uint128 added)
external pure returns (uint256)
{
return oddsX100(pot + added, stake + added);
}
// ═══ the distance ═══
/// @notice The post for a level: ten percent longer per record, capped.
function postFor(uint8 level) public pure returns (uint32) {
if (level <= 1) return DISTANCE_BASE;
uint8 n = level > 6 ? 6 : level;
uint256 d = DISTANCE_BASE;
for (uint8 i = 1; i < n; ++i) {
d = (d * 11) / 10;
if (d >= DISTANCE_CAP) return DISTANCE_CAP;
}
return uint32(d);
}
/// @notice Progress through the race, in basis points.
function progressBps(uint32 distance, uint32 post) public pure returns (uint256) {
if (post == 0) return 0;
if (distance >= post) return BPS;
return (uint256(distance) * BPS) / uint256(post);
}
/// @notice Swaps still to run — a countdown that needs no date.
function remaining(uint32 distance, uint32 post) external pure returns (uint32) {
return distance >= post ? 0 : post - distance;
}
/// @notice True once the race has entered the last five percent.
function isFinalTurn(uint32 distance, uint32 post) external pure returns (bool) {
return progressBps(distance, post) >= BPS - FINAL_TURN_BPS;
}
// ═══ the fees ═══
/// @notice Band index for a progress reading, from the five-row table.
function bandOf(uint256 progress) public pure returns (uint8) {
if (progress < 2500) return 0;
if (progress < 5000) return 1;
if (progress < 7500) return 2;
if (progress < 9500) return 3;
return 4;
}
/// @notice The game fee of a band, in basis points.
function feeBpsOfBand(uint8 band) public pure returns (uint16) {
if (band == 0) return FEE_BAND_0;
if (band == 1) return FEE_BAND_1;
if (band == 2) return FEE_BAND_2;
if (band == 3) return FEE_BAND_3;
return FEE_BAND_4;
}
/// @notice The fee a swap pays here. No branch tests trade direction.
function feeBpsAt(uint32 distance, uint32 post) public pure returns (uint16) {
return feeBpsOfBand(bandOf(progressBps(distance, post)));
}
/// @notice The game fee taken from a traded amount.
function feeOn(uint256 amount, uint32 distance, uint32 post)
external pure returns (uint256)
{
return (amount * feeBpsAt(distance, post)) / BPS;
}
/// @notice How a collected fee splits: to the pot, then burned.
function feeSplit(uint256 fee) external pure returns (uint256 toPot, uint256 toBurn) {
toPot = (fee * FEE_TO_POT_BPS) / BPS;
toBurn = (fee * FEE_TO_BURN_BPS) / BPS;
}
// ═══ the post ═══
/// @notice The two integer comparisons checked at the end of each notch.
function canSettle(uint32 distance, uint32 post, uint128 engaged, uint128 pot)
public pure returns (bool)
{
if (distance < post) return false;
if (pot == 0) return false;
return (uint256(engaged) * BPS) / uint256(pot) >= ENGAGED_MIN_BPS;
}
/// @notice Distance reached but the board too thin: the post moves back.
function postRecedes(uint32 distance, uint32 post, uint128 engaged, uint128 pot)
external pure returns (bool)
{
return distance >= post && !canSettle(distance, post, engaged, pot);
}
/// @notice The levy withheld from the pot at the post.
function levyOn(uint128 pot) external pure returns (uint256) {
return (uint256(pot) * LEVY_BPS) / BPS;
}
/// @notice How the pot splits once the post is reached.
function postSplit(uint128 pot)
external pure returns (uint256 toWinners, uint256 toCarry, uint256 toBurn)
{
toWinners = (uint256(pot) * POST_TO_WINNERS_BPS) / BPS;
toCarry = (uint256(pot) * POST_TO_CARRY_BPS) / BPS;
toBurn = (uint256(pot) * POST_TO_BURN_BPS) / BPS;
}
/// @notice The payout, announced as a racecourse announces it: what one
/// unit staked on the winner brings back, to two decimals.
function payoutX100(uint128 pot, uint128 weightedStake) external pure returns (uint256) {
if (weightedStake == 0) return 0;
uint256 purse = (uint256(pot) * POST_TO_WINNERS_BPS) / BPS;
return (purse * 100) / uint256(weightedStake);
}
/// @notice A ticket weighs its size times the distance it was carried.
function ticketWeight(uint128 stake, uint32 carried) external pure returns (uint256) {
return uint256(stake) * uint256(carried);
}
// ═══ the quantum ═══
/// @notice The bar a swap must clear to count as a notch. Below it a trade
/// still settles and still pays its fee; it just does not move the race.
function quantumFrom(uint256 median) public pure returns (uint256) {
return median / QUANTUM_DIVISOR;
}
/// @notice The two bounds the quantum may never leave.
function quantumBounds(uint256 seed) public pure returns (uint256 low, uint256 high) {
low = seed / QUANTUM_BOUND;
high = seed * QUANTUM_BOUND;
}
/// @notice The quantum actually applied, clamped to its bounds.
function clampQuantum(uint256 median, uint256 seed) external pure returns (uint256) {
(uint256 low, uint256 high) = quantumBounds(seed);
uint256 q = quantumFrom(median);
if (q < low) return low;
if (q > high) return high;
return q;
}
/// @notice Whether a swap clears the bar. Size buys no speed: a trade a
/// thousand times the quantum is one notch, and one only.
function countsAsNotch(uint256 amount, uint256 quantum) external pure returns (bool) {
return amount >= quantum;
}
// ═══ supply and ownership ═══
/// @notice What still trades: supply less whatever reached the sink.
function circulatingSupply() external view returns (uint256) {
return totalSupply - balanceOf[BURN_SINK];
}
/// @notice The supply this logic expects the token address to hold.
function expectedSupply() external pure returns (uint256) {
return TOTAL_SUPPLY;
}
/// @notice Drops ownership for good. There is nothing left to administer.
function renounceOwnership() external {
if (msg.sender != owner) revert NotOwner();
emit OwnershipTransferred(owner, address(0));
owner = address(0);
}
// ═══ internal ═══
function _move(address from, address to, uint256 amount) internal returns (bool) {
if (to == address(0)) revert ZeroAddress();
if (balanceOf[from] < amount) revert InsufficientBalance();
unchecked {
balanceOf[from] -= amount;
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
}
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.