Verified contractPartialMIT
Hypair
Address0xdecd1fb16ac1e4fbaa0cb94ae3e643a237c0f209
- 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,976,582
- Creation transaction
- 0xe39e06bd0a…9cf50ab606
6 files
- src/Hypair.solmain10.43 KB
- src/hypair/BandTable.sol2.55 KB
- src/hypair/FlipRoute.sol1.97 KB
- src/hypair/LevyBook.sol2.04 KB
- src/hypair/StampClock.sol2.05 KB
- src/hypair/ZeroLine.sol2.02 KB
src/Hypair.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
//
// ---
// hyPAIR
// website: http://hypair.exchange/
// x: https://x.com/HyPAIR_ethereum
// ---
//
import {BandTable} from "./hypair/BandTable.sol";
import {StampClock} from "./hypair/StampClock.sol";
import {LevyBook} from "./hypair/LevyBook.sol";
import {FlipRoute} from "./hypair/FlipRoute.sol";
import {ZeroLine} from "./hypair/ZeroLine.sol";
// ═══════════════════════════════════════════════════════════════════════════
// hyPAIR
// hourly stamp · signed distance · engraved band table · levy cap 100 bps
// 1 000 000 000 supply · Ethereum · Uniswap v4
// ═══════════════════════════════════════════════════════════════════════════
contract Hypair {
// [errors]
error ZeroAddress();
error InsufficientBalance();
error InsufficientAllowance();
error NotOwner();
error AlreadyInitialized();
// [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]
string public constant NAME = "hyPAIR";
string public constant SYMBOL = "hyPAIR";
uint8 public constant DECIMALS = 18;
string public constant VERSION = "1.0.0";
string public constant website = "https://hyPAIR.exchange";
string public constant twitterX = "https://x.com/HyPAIR_ethereum";
// [supply]
uint256 public constant TOTAL_SUPPLY = 1_000_000_000 * 1e18;
// [cadence · seconds between hourly stamps and grace tolerance]
uint32 public constant STAMP_INTERVAL = 3_600;
uint32 public constant GRACE_PERIOD = 900;
// [levy · hard ceiling and miss fallback split]
uint16 public constant LEVY_CEILING_BPS = 100;
uint16 public constant MISSED_SPLIT_BPS = 5_000;
// [band count]
uint8 public constant BAND_COUNT = 5;
// [unit · 100 cbp = 1 bp]
uint16 public constant CBP_PER_BP = 100;
// [storage · order fixed by TokenInit, do not reorder]
uint256 public totalSupply;
address public owner;
bool private _initialized;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
// [ctor · seals this logic module against re-entry of initialize]
constructor() { _initialized = true; }
// [init · one-shot mint, executes in the token contract storage]
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);
}
// [ownership]
function renounceOwnership() external {
if (msg.sender != owner) revert NotOwner();
emit OwnershipTransferred(owner, address(0));
owner = address(0);
}
// [erc20 · lowercase accessors · required by every indexer]
function name() external pure returns (string memory) { return NAME; }
function symbol() external pure returns (string memory) { return SYMBOL; }
function decimals() external pure returns (uint8) { return DECIMALS; }
// [erc20 · approve]
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;
}
// [erc20 · transfer]
function transfer(address to, uint256 amount) external returns (bool) {
return _move(msg.sender, to, amount);
}
// [erc20 · transferFrom]
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);
}
// [internals · balance move]
function _move(address from, address to, uint256 amount) internal returns (bool) {
if (to == address(0)) revert ZeroAddress();
uint256 bal = balanceOf[from];
if (bal < amount) revert InsufficientBalance();
unchecked { balanceOf[from] = bal - amount; balanceOf[to] += amount; }
emit Transfer(from, to, amount);
return true;
}
// ═══════════════════════════════════════════════════════════════════════
// protocol reads · pure views over the engraved mechanics
// ═══════════════════════════════════════════════════════════════════════
// [band · id from an unsigned distance in cbp]
function bandOf(uint256 distanceCbp) external pure returns (uint8) {
return BandTable.idOf(distanceCbp);
}
// [band · levy bps at the given distance]
function levyBpsAt(uint256 distanceCbp) external pure returns (uint16) {
return BandTable.levyBpsAt(distanceCbp);
}
// [band · [lo, hi) bounds for a band id]
function bandRange(uint8 band) external pure returns (uint256 lo, uint256 hi) {
return BandTable.rangeOf(band);
}
// [band · bps for a band id]
function bandBps(uint8 band) external pure returns (uint16) {
return BandTable.bpsOf(band);
}
// [levy · amount * bps / 10 000, honors the ceiling]
function levyFor(uint256 amount, uint16 bps) external pure returns (uint256) {
return LevyBook.levyFor(amount, bps);
}
// [levy · half bps after a double miss]
function halveLevy(uint16 bps) external pure returns (uint16) {
return LevyBook.halveLevy(bps);
}
// [levy · 50 / 50 share on the miss path]
function missedShare(uint256 amount) external pure returns (uint256) {
return LevyBook.missedShare(amount);
}
// [levy · true if within ceiling]
function isWithinCeiling(uint16 bps) external pure returns (bool) {
return LevyBook.isWithinCeiling(bps);
}
// [clock · seconds until the next stamp]
function secondsUntilStamp(uint256 lastStampAt) external view returns (uint256) {
return StampClock.secondsUntil(lastStampAt, block.timestamp);
}
// [clock · deadline of the current stamp window]
function stampDeadline(uint256 lastStampAt) external pure returns (uint256) {
return StampClock.deadlineOf(lastStampAt);
}
// [clock · miss detection]
function isMissed(uint256 lastStampAt) external view returns (bool) {
return StampClock.isMissed(lastStampAt, block.timestamp);
}
// [clock · double-miss detection]
function isDoubleMissed(uint256 lastStampAt) external view returns (bool) {
return StampClock.isDoubleMissed(lastStampAt, block.timestamp);
}
// [clock · in-hour phase]
function phaseInHour(uint256 lastStampAt) external view returns (uint256) {
return StampClock.phaseOf(lastStampAt, block.timestamp);
}
// [route · direction id from the signed reading]
function directionOf(int256 signedCbp) external pure returns (uint8) {
return FlipRoute.directionOf(signedCbp);
}
// [route · lp / holder share percentages]
function routeSharePct(int256 signedCbp) external pure returns (uint8 lpPct, uint8 holderPct) {
return FlipRoute.sharePct(signedCbp);
}
// [route · above / below / on zero]
function isAboveZero(int256 signedCbp) external pure returns (bool) {
return FlipRoute.isAboveZero(signedCbp);
}
function isBelowZero(int256 signedCbp) external pure returns (bool) {
return FlipRoute.isBelowZero(signedCbp);
}
function isOnZeroOrNull(int256 signedCbp) external pure returns (bool) {
return FlipRoute.isOnZeroOrNull(signedCbp);
}
// [zero · unsigned distance in cbp]
function absDistance(int256 signedCbp) external pure returns (uint256) {
return ZeroLine.absDistance(signedCbp);
}
// [zero · sign as {-1, 0, +1}]
function signOf(int256 signedCbp) external pure returns (int8) {
return ZeroLine.signOf(signedCbp);
}
// [zero · whole bp and remaining cbp]
function bpAndFraction(int256 signedCbp)
external pure returns (int256 wholeBps, uint256 remCbp)
{
return ZeroLine.toBpsAndFraction(signedCbp);
}
// [zero · true when the reading is inside the flip corridor B0]
function isNearFlip(int256 signedCbp) external pure returns (bool) {
return ZeroLine.isNearFlip(signedCbp, BandTable.B0_HI);
}
// [zero · defensive clamp for a raw feed]
function clampSignedCbp(int256 signedCbp, int256 low, int256 high) external pure returns (int256) {
return ZeroLine.clamp(signedCbp, low, high);
}
// [carry · engraved constants exposed as views]
function stampInterval() external pure returns (uint32) { return STAMP_INTERVAL; }
function gracePeriod() external pure returns (uint32) { return GRACE_PERIOD; }
function levyCeilingBps() external pure returns (uint16) { return LEVY_CEILING_BPS; }
function missedSplitBps() external pure returns (uint16) { return MISSED_SPLIT_BPS; }
function bandCount() external pure returns (uint8) { return BAND_COUNT; }
function cbpPerBp() external pure returns (uint16) { return CBP_PER_BP; }
function expectedSupply() external pure returns (uint256) { return TOTAL_SUPPLY; }
}
src/hypair/BandTable.sol
// SPDX-License-Identifier: MIT
// ═══════════════════════════════════════════════════════════════════════════
// hypair · BandTable · engraved lookup, not a curve
// ═══════════════════════════════════════════════════════════════════════════
pragma solidity ^0.8.26;
library BandTable {
// [bounds · cbp — 100 cbp = 1 bp]
uint256 internal constant B0_HI = 10;
uint256 internal constant B1_HI = 50;
uint256 internal constant B2_HI = 150;
uint256 internal constant B3_HI = 400;
// [levy · bps per band]
uint16 internal constant B0_BPS = 100;
uint16 internal constant B1_BPS = 80;
uint16 internal constant B2_BPS = 60;
uint16 internal constant B3_BPS = 40;
uint16 internal constant B4_BPS = 25;
// [count]
uint8 internal constant BANDS = 5;
// [errors]
error UnknownBand();
// [read · band id, 0..4]
function idOf(uint256 distanceCbp) internal pure returns (uint8) {
if (distanceCbp < B0_HI) return 0;
if (distanceCbp < B1_HI) return 1;
if (distanceCbp < B2_HI) return 2;
if (distanceCbp < B3_HI) return 3;
return 4;
}
// [read · levy in bps for the given distance]
function levyBpsAt(uint256 distanceCbp) internal pure returns (uint16) {
if (distanceCbp < B0_HI) return B0_BPS;
if (distanceCbp < B1_HI) return B1_BPS;
if (distanceCbp < B2_HI) return B2_BPS;
if (distanceCbp < B3_HI) return B3_BPS;
return B4_BPS;
}
// [read · [lo, hi) range for band id]
function rangeOf(uint8 band) internal pure returns (uint256 lo, uint256 hi) {
if (band == 0) return (0, B0_HI);
if (band == 1) return (B0_HI, B1_HI);
if (band == 2) return (B1_HI, B2_HI);
if (band == 3) return (B2_HI, B3_HI);
if (band == 4) return (B3_HI, type(uint256).max);
revert UnknownBand();
}
// [read · bps for band id]
function bpsOf(uint8 band) internal pure returns (uint16) {
if (band == 0) return B0_BPS;
if (band == 1) return B1_BPS;
if (band == 2) return B2_BPS;
if (band == 3) return B3_BPS;
if (band == 4) return B4_BPS;
revert UnknownBand();
}
}
src/hypair/FlipRoute.sol
// SPDX-License-Identifier: MIT
// ═══════════════════════════════════════════════════════════════════════════
// hypair · FlipRoute · signed distance decides the destination
// ═══════════════════════════════════════════════════════════════════════════
pragma solidity ^0.8.26;
library FlipRoute {
// [directions]
uint8 internal constant DIR_HOLDERS = 1;
uint8 internal constant DIR_LIQUIDITY = 2;
uint8 internal constant DIR_SPLIT = 3;
// [split percent · used on the miss path]
uint8 internal constant SPLIT_PCT = 50;
// [read · direction id from the signed distance in cbp]
function directionOf(int256 signedCbp) internal pure returns (uint8) {
if (signedCbp > 0) return DIR_LIQUIDITY;
if (signedCbp < 0) return DIR_HOLDERS;
return DIR_SPLIT;
}
// [read · share percentages for LP and holders]
function sharePct(int256 signedCbp)
internal pure
returns (uint8 lpPct, uint8 holderPct)
{
if (signedCbp > 0) return (100, 0);
if (signedCbp < 0) return (0, 100);
return (SPLIT_PCT, SPLIT_PCT);
}
// [read · true if the last stamp sits above the zero line]
function isAboveZero(int256 signedCbp) internal pure returns (bool) {
return signedCbp > 0;
}
// [read · true if the last stamp sits below the zero line]
function isBelowZero(int256 signedCbp) internal pure returns (bool) {
return signedCbp < 0;
}
// [read · true if the reading is missing or exactly on the zero line]
function isOnZeroOrNull(int256 signedCbp) internal pure returns (bool) {
return signedCbp == 0;
}
}
src/hypair/LevyBook.sol
// SPDX-License-Identifier: MIT
// ═══════════════════════════════════════════════════════════════════════════
// hypair · LevyBook · amount * bps / 10 000, capped at the ceiling
// ═══════════════════════════════════════════════════════════════════════════
pragma solidity ^0.8.26;
library LevyBook {
// [hard ceiling · bytecode literal, no address can raise it]
uint16 internal constant LEVY_CEILING_BPS = 100;
// [split · missed stamp fallback, 50 / 50]
uint16 internal constant MISSED_SPLIT_BPS = 5_000;
// [denominator · basis points]
uint16 internal constant BPS_DENOM = 10_000;
// [errors]
error OverCeiling(uint16 bps);
// [read · levy amount, respects the ceiling]
function levyFor(uint256 amount, uint16 bps) internal pure returns (uint256) {
uint16 use = bps;
if (use > LEVY_CEILING_BPS) use = LEVY_CEILING_BPS;
return (amount * use) / BPS_DENOM;
}
// [read · half levy · used after a double-missed stamp until a reading lands]
function halveLevy(uint16 bps) internal pure returns (uint16) {
unchecked { return bps / 2; }
}
// [read · true if the given bps sits at or below the ceiling]
function isWithinCeiling(uint16 bps) internal pure returns (bool) {
return bps <= LEVY_CEILING_BPS;
}
// [read · check and revert if a proposed bps breaks the ceiling]
function requireWithinCeiling(uint16 bps) internal pure {
if (bps > LEVY_CEILING_BPS) revert OverCeiling(bps);
}
// [read · pair-share amount for the missed-stamp 50 / 50 route]
function missedShare(uint256 amount) internal pure returns (uint256) {
return (amount * MISSED_SPLIT_BPS) / BPS_DENOM;
}
}
src/hypair/StampClock.sol
// SPDX-License-Identifier: MIT
// ═══════════════════════════════════════════════════════════════════════════
// hypair · StampClock · hourly cadence, grace, and missed detection
// ═══════════════════════════════════════════════════════════════════════════
pragma solidity ^0.8.26;
library StampClock {
// [cadence · seconds between stamps]
uint32 internal constant STAMP_INTERVAL = 3_600;
// [grace · window after which a stamp counts as missed]
uint32 internal constant GRACE_PERIOD = 900;
// [read · seconds until the next stamp, 0 if overdue]
function secondsUntil(uint256 lastStampAt, uint256 nowTs) internal pure returns (uint256) {
uint256 next = lastStampAt + STAMP_INTERVAL;
if (nowTs >= next) return 0;
return next - nowTs;
}
// [read · true if the next stamp has not landed within grace]
function isMissed(uint256 lastStampAt, uint256 nowTs) internal pure returns (bool) {
return nowTs > lastStampAt + STAMP_INTERVAL + GRACE_PERIOD;
}
// [read · true if two consecutive stamps are missed]
function isDoubleMissed(uint256 lastStampAt, uint256 nowTs) internal pure returns (bool) {
return nowTs > lastStampAt + (STAMP_INTERVAL * 2) + GRACE_PERIOD;
}
// [read · deadline of the current stamp window]
function deadlineOf(uint256 lastStampAt) internal pure returns (uint256) {
return lastStampAt + STAMP_INTERVAL + GRACE_PERIOD;
}
// [read · phase inside the hour, 0..STAMP_INTERVAL-1]
function phaseOf(uint256 lastStampAt, uint256 nowTs) internal pure returns (uint256) {
if (nowTs <= lastStampAt) return 0;
uint256 dt = nowTs - lastStampAt;
return dt % STAMP_INTERVAL;
}
}
src/hypair/ZeroLine.sol
// SPDX-License-Identifier: MIT
// ═══════════════════════════════════════════════════════════════════════════
// hypair · ZeroLine · distance to the printed baseline
// ═══════════════════════════════════════════════════════════════════════════
pragma solidity ^0.8.26;
library ZeroLine {
// [unit · 100 cbp = 1 bp]
uint16 internal constant CBP_PER_BP = 100;
// [read · unsigned distance in cbp]
function absDistance(int256 signedCbp) internal pure returns (uint256) {
if (signedCbp < 0) {
unchecked { return uint256(-signedCbp); }
}
return uint256(signedCbp);
}
// [read · sign as {-1, 0, +1}]
function signOf(int256 signedCbp) internal pure returns (int8) {
if (signedCbp > 0) return int8(1);
if (signedCbp < 0) return int8(-1);
return int8(0);
}
// [read · whole bp and remaining cbp fraction]
function toBpsAndFraction(int256 signedCbp)
internal pure
returns (int256 wholeBps, uint256 remCbp)
{
uint256 abs_ = absDistance(signedCbp);
wholeBps = int256(abs_ / CBP_PER_BP);
if (signedCbp < 0) wholeBps = -wholeBps;
remCbp = abs_ % CBP_PER_BP;
}
// [read · true if the distance sits inside band B0, the flip corridor]
function isNearFlip(int256 signedCbp, uint256 b0Hi) internal pure returns (bool) {
return absDistance(signedCbp) < b0Hi;
}
// [read · clamp a raw feed to a bounded window · defense in depth]
function clamp(int256 signedCbp, int256 low, int256 high) internal pure returns (int256) {
if (signedCbp < low) return low;
if (signedCbp > high) return high;
return signedCbp;
}
}
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.