Skip to content
Verified contractPartialMIT

BRS

Address0x5bf15c3b06f2e606c8ab9082471c1e72b5fc7b0e
Balance

0 ETH

 

Transactions

5

 

Compiler

solc 0.8.28

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 2,000 runs
EVM version
prague
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,187,131
Creation transaction
0x70d51eb498…12a1cf4e9b

src/BRS.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

// site: https://boursev4.xyz   x: https://x.com/bourse_v4
//
// ================================================================================================
//  THE BOURSE . RULEBOOK . CHAPTER I . THE LISTED SECURITY
// ================================================================================================
//
//  Rule 1.1  Issue. Bourse ($BRS): 1,000,000,000 units, issued once, all of them to the owner, who
//            places them in the pool at the opening (BourseHook Rule 2.1). No owner function, no further
//            issue, no pause, no fee inside the token.
//
//  Rule 1.2  Seniority. Every balance carries an age: the balance-weighted time its units were
//            acquired. Units leaving the exchange's own books (the pool, the order book, the stream
//            desk) are age zero. Units sent wallet to wallet keep their age.
//
//  Rule 1.3  Dividends. The exchange sends holders' ETH here (notify). It accrues per unit over the
//            eligible supply: every balance except the exchange's own books and the burn address. What
//            has accrued vests with the age of the units, linearly to AGE_FULL (14 days). Units that
//            leave a balance hand back their unvested part to the holders who stay.
//
//  Rule 1.3a Banked. Whenever a balance changes or claims, the part of its dividends vested at its
//            current age is banked, and the vested fraction already counted is recorded, so the same age
//            never vests the same credit twice: claiming repeatedly, or receiving dust, pays nothing more.
//            Buying more never takes back what had vested; the rest restarts from the new average age.
//            Nothing is forfeited by claiming, only by selling or sending units before their dividends
//            have vested.
//
//  Rule 1.4  Thin market. While the eligible supply is under MIN_DENOM (1% of supply), ETH is shared
//            as if MIN_DENOM were held; the missing share waits in `carry`. The first holder cannot
//            take the opening dividends alone.
//
//  Rule 1.5  Rounding. Accrual rounds down for holders and debts round up, so paid never exceeds
//            notified. A few wei per account stay behind.
// ------------------------------------------------------------------------------------------------

contract BRS {
    string public constant name = "Bourse";
    string public constant symbol = "BRS";
    uint8 public constant decimals = 18;
    uint256 public constant SUPPLY = 1_000_000_000 ether;
    uint256 public constant AGE_FULL = 14 days;
    uint256 public constant MIN_DENOM = SUPPLY / 100;
    uint256 internal constant ACC = 1e36;
    address internal constant DEAD = 0x000000000000000000000000000000000000dEaD;

    address public immutable HOOK;
    address public immutable POOL_MANAGER;
    address public immutable BOOK;
    address public immutable STREAM;

    uint256 public totalSupply;
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;
    mapping(address => uint64) public acquiredAt;

    struct Acct {
        uint256 debt;
        uint256 credit; // accrued, vesting with the balance's age
        uint256 banked; // vested and set aside: always claimable
        uint256 vf; // the vested fraction (1e18 = all) already counted against credit
    }

    mapping(address => Acct) public accts;
    uint256 public accPerToken;
    uint256 public eligibleSupply;
    uint256 public carry;
    uint256 public notified;
    uint256 public paid;

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event Notified(uint256 eth, uint256 accPerToken);
    event Claimed(address indexed holder, uint256 paid, uint256 handedBack);

    error Insufficient();
    error PayFailed();

    constructor(address hook, address poolManager, address book, address stream, address owner) {
        HOOK = hook;
        POOL_MANAGER = poolManager;
        BOOK = book;
        STREAM = stream;
        totalSupply = SUPPLY;
        balanceOf[owner] = SUPPLY;
        acquiredAt[owner] = uint64(block.timestamp);
        eligibleSupply = SUPPLY;
        emit Transfer(address(0), owner, SUPPLY);
    }

    // ───────────────────────────────────────────────────────────── ERC-20

    function transfer(address to, uint256 value) external returns (bool) {
        _move(msg.sender, to, value);
        return true;
    }

    function transferFrom(address from, address to, uint256 value) external returns (bool) {
        uint256 a = allowance[from][msg.sender];
        if (a != type(uint256).max) {
            if (a < value) revert Insufficient();
            unchecked {
                allowance[from][msg.sender] = a - value;
            }
        }
        _move(from, to, value);
        return true;
    }

    function approve(address spender, uint256 value) external returns (bool) {
        allowance[msg.sender][spender] = value;
        emit Approval(msg.sender, spender, value);
        return true;
    }

    /// @notice Burn your own units. Supply falls.
    function burn(uint256 value) external {
        address from = msg.sender;
        uint256 b = balanceOf[from];
        if (b < value) revert Insufficient();
        bool el = _eligible(from);
        if (el) {
            _settle(from);
            _vest(from);
        }
        uint256 back = el ? _handBack(from, value, b) : 0;
        unchecked {
            balanceOf[from] = b - value;
            totalSupply -= value;
        }
        if (el) {
            eligibleSupply -= value;
            _checkpoint(from);
        }
        if (back != 0) _share(back);
        emit Transfer(from, address(0), value);
    }

    // ───────────────────────────────────────────────────────────── dividends

    function notify() external payable {
        notified += msg.value;
        _share(msg.value);
    }

    function claim() external returns (uint256 pay) {
        address a = msg.sender;
        bool el = _eligible(a);
        if (el) _settle(a);
        Acct storage s = accts[a];
        _vest(a);
        pay = s.banked;
        if (pay == 0) return 0;
        s.banked = 0;
        if (el) _checkpoint(a);
        paid += pay;
        emit Claimed(a, pay, 0);
        if (pay != 0) {
            (bool ok,) = a.call{value: pay}("");
            if (!ok) revert PayFailed();
        }
    }

    function ageOf(address a) public view returns (uint256) {
        if (balanceOf[a] == 0) return 0;
        return block.timestamp - acquiredAt[a];
    }

    function vested(address a) public view returns (uint256) {
        uint256 age = ageOf(a);
        return age >= AGE_FULL ? 1e18 : (age * 1e18) / AGE_FULL;
    }

    function pending(address a) external view returns (uint256 accrued, uint256 claimable) {
        uint256 c = accts[a].credit;
        if (_eligible(a)) {
            uint256 earned = (balanceOf[a] * accPerToken) / ACC;
            uint256 d = accts[a].debt;
            if (earned > d) c += earned - d;
        }
        Acct memory s = accts[a];
        accrued = s.banked + c;
        claimable = s.banked + _part(c, vested(a), s.vf);
    }

    // ───────────────────────────────────────────────────────────── internals

    function _book(address a) internal view returns (bool) {
        return a == POOL_MANAGER || a == HOOK || a == BOOK || a == STREAM;
    }

    function _eligible(address a) internal view returns (bool) {
        return !_book(a) && a != address(this) && a != DEAD && a != address(0);
    }

    function _move(address from, address to, uint256 value) internal {
        uint256 bf = balanceOf[from];
        if (bf < value) revert Insufficient();
        bool ef = _eligible(from);
        bool et = _eligible(to);
        if (ef) {
            _settle(from);
            _vest(from);
        }
        if (et) {
            _settle(to);
            _vest(to);
        }
        uint256 back = ef && from != to ? _handBack(from, value, bf) : 0;

        uint256 bt = balanceOf[to];
        if (from != to && value != 0) {
            uint256 src = _book(from) || bf == 0 ? block.timestamp : acquiredAt[from];
            uint256 cur = bt == 0 ? src : acquiredAt[to];
            acquiredAt[to] = uint64((bt * cur + value * src) / (bt + value));
        }
        unchecked {
            balanceOf[from] = bf - value;
        }
        balanceOf[to] += value;
        // the receiving balance's age changed: its remaining credit vests from the new age
        if (et && from != to && value != 0) accts[to].vf = vested(to);
        if (ef && !et) eligibleSupply -= value;
        else if (!ef && et) eligibleSupply += value;
        if (ef) _checkpoint(from);
        if (et) _checkpoint(to);
        if (back != 0) _share(back);
        emit Transfer(from, to, value);
    }

    /// @dev The part of `c` that vests between the fraction already counted (`vf`) and `v`.
    function _part(uint256 c, uint256 v, uint256 vf) internal pure returns (uint256) {
        if (v >= 1e18) return c;
        if (v <= vf) return 0;
        return (c * (v - vf)) / (1e18 - vf);
    }

    /// @dev Bank what has vested at the current age, once: the same age never vests the same credit twice.
    function _vest(address a) internal {
        Acct storage s = accts[a];
        uint256 v = vested(a);
        uint256 c = s.credit;
        if (c != 0) {
            uint256 p = _part(c, v, s.vf);
            if (p != 0) {
                s.banked += p;
                s.credit = c - p;
            }
        }
        if (v > s.vf || v >= 1e18) s.vf = v;
    }

    function _settle(address a) internal {
        Acct storage s = accts[a];
        uint256 earned = (balanceOf[a] * accPerToken) / ACC;
        if (earned > s.debt) s.credit += earned - s.debt;
        s.debt = earned;
    }

    function _checkpoint(address a) internal {
        uint256 x = balanceOf[a] * accPerToken;
        accts[a].debt = x / ACC + (x % ACC == 0 ? 0 : 1);
    }

    /// @dev After _vest, all remaining credit is unvested: the share leaving with `value` units goes back.
    function _handBack(address a, uint256 value, uint256 bal) internal returns (uint256 back) {
        Acct storage s = accts[a];
        uint256 c = s.credit;
        if (c == 0 || bal == 0) return 0;
        back = (c * value) / bal;
        s.credit = c - back;
    }

    function _share(uint256 eth) internal {
        uint256 total = eth + carry;
        uint256 el = eligibleSupply;
        if (el == 0) {
            carry = total;
            return;
        }
        uint256 denom = el > MIN_DENOM ? el : MIN_DENOM;
        uint256 inc = (total * ACC) / denom;
        uint256 assigned = (inc * el) / ACC;
        accPerToken += inc;
        carry = total - assigned;
        emit Notified(eth, accPerToken);
    }

    receive() external payable {
        notified += msg.value;
        _share(msg.value);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 2000,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "@uniswap/v4-core/=lib/v4-core/",
    "v4-core/=lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "v4-periphery/=lib/v4-periphery/",
    "solmate/=lib/solmate/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "permit2/=lib/permit2/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.