Skip to content
Verified contractExact

Singularity

Address0x87e07c3e1c44b30cb652fa985e88b2018a3bd99c
Balance

0.00049 ETH

 

Transactions

5

 

Compiler

solc 0.8.36

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.36+commit.8a079791
Language
solidity
Optimization
Yes, 200 runs
License
Not stated
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,648,132
Creation transaction
0x95fd16e9dd…1987284eed

GravityHook/Singularity.sol

pragma solidity ^0.8.24;

interface IBody { function mint(address to) external returns (uint256); }

contract Singularity {
    string public constant name = "Singularity";
    string public constant symbol = "MASS";
    uint8  public constant decimals = 18;
    uint256 public constant SUPPLY = 100_000e18;
    uint256 private constant MAG = 2 ** 128;
    address public constant DEAD = 0x000000000000000000000000000000000000dEaD;

    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;
    mapping(address => bool) public excluded;

    address public owner;
    address public launch;
    address public hook;
    address public bodyNFT;
    bool public tradingOpen;

    address public constant POOL_MANAGER = 0x000000000004444c5dc75cB358380D2e3dE08A90;

    uint256 public magPerShare;
    uint256 public totalShares;
    uint256 public totalFees;
    uint256 public ethBuffer;
    mapping(address => uint256) public shares;
    mapping(address => int256) internal magCorr;
    mapping(address => uint256) public withdrawn;

    struct Body { uint128 peak; uint128 lost; uint40 bornAt; bool listed; bool minted; }
    mapping(address => Body) public bodies;
    address[] public holders;
    mapping(address => uint256) public holderId;
    uint256 public cursor;
    uint256 public eats;
    uint256 public totalBurned;

    uint256 public constant FLOOR = 10e18;
    uint256 public constant SHIELD = 5 minutes;
    uint256 public constant LOSS_CAP_BPS = 3000;
    uint16 public roche = 4;
    uint16 public accreteBps = 700;
    uint16 public radiateBps = 4000;
    uint16 public superCeilingBps = 300;
    uint16 public superBurnBps = 2000;
    uint8  public constant SCAN = 8;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Funded(uint256 amount, uint256 magPerShare);
    event Claimed(address indexed to, uint256 amount);
    event BodyListed(address indexed who, uint256 mass, uint256 bornAt);
    event Accreted(address indexed predator, address indexed prey, uint256 pulled, uint256 burned);
    event Supernova(address indexed who, uint256 burned);
    event TradingOpened();

    modifier onlyOwner() { require(msg.sender == owner, "not owner"); _; }

    constructor(address to) {
        owner = msg.sender;
        launch = to;
        totalSupply = SUPPLY;
        balanceOf[to] = SUPPLY;
        excluded[to] = true;
        excluded[address(0)] = true;
        excluded[address(this)] = true;
        excluded[DEAD] = true;
        excluded[POOL_MANAGER] = true;
        emit Transfer(address(0), to, SUPPLY);
    }

    function set_excluded(address a, bool v) external onlyOwner { excluded[a] = v; _setShares(a, v ? 0 : (balanceOf[a] >= FLOOR ? balanceOf[a] : 0)); }
    function set_hook(address h) external onlyOwner { hook = h; excluded[h] = true; }
    function set_body(address b) external onlyOwner { bodyNFT = b; }
    function startTrading() external onlyOwner { tradingOpen = true; emit TradingOpened(); }
    function renounce() external onlyOwner { owner = address(0); }
    function tune(uint16 roche_, uint16 accreteBps_, uint16 radiateBps_, uint16 superCeilingBps_, uint16 superBurnBps_) external onlyOwner {
        require(roche_ >= 1 && roche_ <= 16, "roche");
        require(accreteBps_ <= 1500 && radiateBps_ <= 8000, "rate");
        require(superCeilingBps_ >= 100 && superCeilingBps_ <= 2000 && superBurnBps_ <= 5000, "super");
        roche = roche_; accreteBps = accreteBps_; radiateBps = radiateBps_;
        superCeilingBps = superCeilingBps_; superBurnBps = superBurnBps_;
    }

    function approve(address s, uint256 a) external returns (bool) { allowance[msg.sender][s] = a; emit Approval(msg.sender, s, a); return true; }
    function transfer(address to, uint256 a) external returns (bool) { _move(msg.sender, to, a); return true; }
    function transferFrom(address f, address to, uint256 a) external returns (bool) {
        uint256 al = allowance[f][msg.sender];
        if (al != type(uint256).max) allowance[f][msg.sender] = al - a;
        _move(f, to, a); return true;
    }
    function _move(address from, address to, uint256 amount) internal {
        if (!tradingOpen) require(from == launch || to == launch || from == owner || to == owner, "trading not open");
        balanceOf[from] -= amount;
        unchecked { balanceOf[to] += amount; }
        emit Transfer(from, to, amount);
        _touch(from);
        _touch(to);
    }

    function _touch(address a) internal {
        if (excluded[a]) { if (shares[a] != 0) _setShares(a, 0); return; }
        uint256 m = balanceOf[a];
        Body storage B = bodies[a];
        if (m > uint256(B.peak)) B.peak = uint128(m);
        if (!B.listed && m >= FLOOR) {
            B.listed = true;
            B.bornAt = uint40(block.timestamp);
            holders.push(a);
            holderId[a] = holders.length;
            emit BodyListed(a, m, block.timestamp);
        }
        _setShares(a, m >= FLOOR ? m : 0);
    }
    function _setShares(address a, uint256 ns) internal {
        uint256 old = shares[a];
        if (ns > old) { uint256 d = ns - old; magCorr[a] -= int256(magPerShare * d); totalShares += d; }
        else if (ns < old) { uint256 d = old - ns; magCorr[a] += int256(magPerShare * d); totalShares -= d; }
        shares[a] = ns;
    }

    receive() external payable { _fund(msg.value); }
    function route_fee() external payable { _fund(msg.value); }
    function _fund(uint256 v) internal {
        if (v == 0) return;
        totalFees += v;
        if (totalShares > 0) {
            if (ethBuffer > 0) { magPerShare += ethBuffer * MAG / totalShares; ethBuffer = 0; }
            magPerShare += v * MAG / totalShares;
        } else { ethBuffer += v; }
        emit Funded(v, magPerShare);
    }
    function flush() external { if (ethBuffer > 0 && totalShares > 0) { magPerShare += ethBuffer * MAG / totalShares; ethBuffer = 0; } }

    function withdrawableOf(address a) public view returns (uint256) {
        uint256 acc = uint256(int256(magPerShare * shares[a]) + magCorr[a]) / MAG;
        return acc - withdrawn[a];
    }
    function claimableOf(address a) external view returns (uint256) { return withdrawableOf(a); }
    function claim() external returns (uint256 amt) {
        amt = withdrawableOf(msg.sender);
        if (amt > 0) {
            withdrawn[msg.sender] += amt;
            (bool ok, ) = payable(msg.sender).call{value: amt}("");
            require(ok, "pay");
            emit Claimed(msg.sender, amt);
        }
    }

    function onSwap(address trader) external {
        require(msg.sender == hook, "hook");
        _supernova(trader);
        _accrete();
    }

    function _accrete() internal {
        uint256 n = holders.length;
        if (n < 2) return;

        address prey; uint256 pm;
        for (uint256 s = 0; s < SCAN; s++) {
            cursor = (cursor + 1) % n;
            address c = holders[cursor];
            Body storage V = bodies[c];
            if (!V.listed || excluded[c]) continue;
            uint256 m = balanceOf[c];
            if (m < FLOOR) continue;
            if (block.timestamp < uint256(V.bornAt) + SHIELD) continue;
            if (uint256(V.lost) >= uint256(V.peak) * LOSS_CAP_BPS / 10000) continue;
            prey = c; pm = m; break;
        }
        if (prey == address(0)) return;

        address pred; uint256 best;
        for (uint256 k = 1; k <= SCAN; k++) {
            address c = holders[(cursor + k) % n];
            if (c == prey || excluded[c] || !bodies[c].listed) continue;
            uint256 m = balanceOf[c];
            if (m < pm || m > pm * roche) continue;
            if (m > best) { best = m; pred = c; }
        }
        if (pred == address(0)) return;
        uint256 cap = uint256(bodies[prey].peak) * LOSS_CAP_BPS / 10000;
        uint256 slice = pm * accreteBps / 10000;
        uint256 room = cap - uint256(bodies[prey].lost);
        if (slice > room) slice = room;
        if (slice == 0) return;
        uint256 burned = slice * radiateBps / 10000;
        uint256 pulled = slice - burned;
        balanceOf[prey] -= slice;
        unchecked { balanceOf[pred] += pulled; totalSupply -= burned; totalBurned += burned; }
        bodies[prey].lost = uint128(uint256(bodies[prey].lost) + slice);
        eats++;
        emit Transfer(prey, pred, pulled);
        emit Transfer(prey, address(0), burned);
        emit Accreted(pred, prey, pulled, burned);
        _touch(prey);
        _touch(pred);
        _supernova(pred);
    }

    function _supernova(address a) internal {
        if (excluded[a]) return;
        uint256 m = balanceOf[a];
        uint256 ceil_ = totalSupply * superCeilingBps / 10000;
        if (m <= ceil_ || ceil_ == 0) return;
        uint256 burn = (m - ceil_) + (ceil_ * superBurnBps / 10000);
        if (burn > m) burn = m;
        balanceOf[a] -= burn;
        unchecked { totalSupply -= burn; totalBurned += burn; }
        emit Transfer(a, address(0), burn);
        emit Supernova(a, burn);
        _touch(a);
    }

    function mintBody() external returns (uint256 id) {
        require(bodyNFT != address(0), "no body");
        Body storage B = bodies[msg.sender];
        require(B.listed && !B.minted, "not eligible");
        B.minted = true;
        id = IBody(bodyNFT).mint(msg.sender);
    }

    function holderCount() external view returns (uint256) { return holders.length; }
    function massOf(address a) external view returns (uint256) { return balanceOf[a]; }
    function ceiling() external view returns (uint256) { return totalSupply * superCeilingBps / 10000; }
    function bodyInfo(address a) external view returns (uint256 mass, uint256 peak, uint256 lost, uint256 bornAt, bool listed, bool shielded) {
        Body storage B = bodies[a];
        mass = balanceOf[a]; peak = B.peak; lost = B.lost; bornAt = B.bornAt; listed = B.listed;
        shielded = B.listed && block.timestamp < uint256(B.bornAt) + SHIELD;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.