// SPDX-License-Identifier: MIT pragma solidity 0.8.26; import {IHooks} from "v4-core/interfaces/IHooks.sol"; import {IPoolManager} from "v4-core/interfaces/IPoolManager.sol"; import {IUnlockCallback} from "v4-core/interfaces/callback/IUnlockCallback.sol"; import {Hooks} from "v4-core/libraries/Hooks.sol"; import {FullMath} from "v4-core/libraries/FullMath.sol"; import {PoolKey} from "v4-core/types/PoolKey.sol"; import {PoolId} from "v4-core/types/PoolId.sol"; import {Currency} from "v4-core/types/Currency.sol"; import {BalanceDelta} from "v4-core/types/BalanceDelta.sol"; import {BeforeSwapDelta, toBeforeSwapDelta} from "v4-core/types/BeforeSwapDelta.sol"; import {ModifyLiquidityParams, SwapParams} from "v4-core/types/PoolOperation.sol"; /// @title Firmquote /// @notice A firm-quote venue on Uniswap v4. Market makers keep inventory here and write one 32-byte price per pool; /// any v4 swap into a Firmquote pool is filled by the best live price instead of a curve. Firmquote never prices /// anything itself: it enforces what each maker wrote (expiry, staleness widening, per-block size, side switches). /// /// Price slot (one uint256 per maker per pool, low bit first): /// [ 0, 56) mant price mantissa } price = mant * 10^(exp - 128), in token1 base units per token0 base unit /// [ 56, 64) exp price exponent + 128 } /// [ 64, 80) bid spread under the price when the taker sells token0, in pips (1 pip = 0.0001 %) /// [ 80, 96) ask spread over the price when the taker buys token0, in pips /// [ 96,136) capM } most token0 this price fills per L2 block = capM * 10^capE (capM = 0: no limit) /// [136,144) capE } /// [144,160) impact extra pips charged at a fill of the full block size, linear in size /// [160,176) widen extra pips charged per L2 block since the price was written /// [176,192) life L2 blocks the price stays fillable after it was written (0 = price off) /// [192,232) born L2 block the price was written in (set by the contract, whatever the maker sends) /// [232,248) nonce free for the maker's own bookkeeping /// [248,256) flags bit 0 same-block only, bit 1 no bid, bit 2 no ask contract Firmquote is IHooks, IUnlockCallback { // ------------------------------------------------------------------ errors and events error NotPoolManager(); error NotOwner(); error NotGuardian(); error NotMaker(); error Unsupported(); error UnknownPool(); error Halted(); error NoLiveQuote(); error BadInput(); error OverCap(); error TooManyMakers(); error TransferFailed(); event PoolListed(uint256 indexed idx, bytes32 indexed poolId, address currency0, address currency1); event MakerJoined(address indexed maker); event OperatorSet(address indexed maker, address indexed operator, bool allowed); event QuoterChanged(address indexed maker, address indexed quoter); event MakerPaused(address indexed maker, bool paused, address by); event Deposited(address indexed maker, uint256 indexed idx, address currency, uint256 amount); event Withdrawn(address indexed maker, uint256 indexed idx, address currency, uint256 amount, address to); event Priced(address indexed writer, uint256 indexed idx, uint256 slot); event Filled( uint256 indexed idx, address indexed maker, address indexed router, address origin, bool zeroForOne, uint256 amountIn, uint256 amountOut, uint256 fee ); event FeeSet(uint24 pips); event FeesCollected(address currency, uint256 amount, address to); event GuardianSet(address guardian); event TreasurySet(address treasury); event HaltSet(bool halted); event PoolPaused(uint256 indexed idx, bool paused); event PoolCapSet(uint256 indexed idx, uint128 cap0, uint128 cap1); event OwnershipTransferred(address indexed from, address indexed to); // ------------------------------------------------------------------ constants uint256 internal constant PIPS = 1_000_000; uint24 public constant MAX_FEE = 500; // 5 bp, hard cap uint256 public constant MAX_MAKERS = 12; // per pool, bounds the swap's search uint160 internal constant MIN_SQRT = 4295128739; uint160 internal constant SQRT_ONE = 79228162514264337593543950336; // price 1, the pool's curve is never used uint256 internal constant F_SAME_BLOCK = 1; uint256 internal constant F_NO_BID = 2; uint256 internal constant F_NO_ASK = 4; IPoolManager public immutable poolManager; // ------------------------------------------------------------------ storage struct Maker { bool joined; bool paused; address quoter; // whose slots the venue reads for this maker: the newest operator, or the maker itself } struct Listing { PoolKey key; bool paused; uint128 cap0; // most token0 one maker may hold in this pool (0 = no cap) uint128 cap1; } address public owner; address public pendingOwner; address public guardian; address public treasury; uint24 public feePips; bool public halted; Listing[] internal listings; mapping(PoolId => uint256) internal idxPlusOne; mapping(uint256 => address[]) internal poolMakers; mapping(address => mapping(uint256 => bool)) public inPool; mapping(address => Maker) public makers; mapping(address => mapping(address => bool)) public isOperator; mapping(address => mapping(uint256 => uint256)) internal slotOf; // writer => pool => price slot mapping(address => mapping(uint256 => uint256)) internal stock; // maker => pool => bal0 | bal1 << 128 mapping(address => mapping(uint256 => uint256)) internal used; // maker => pool => l2 block | token0 filled << 64 mapping(Currency => uint256) public feesOwed; constructor(IPoolManager pm, address owner_) { poolManager = pm; owner = owner_; guardian = owner_; treasury = owner_; feePips = 50; // 0.5 bp Hooks.validateHookPermissions( IHooks(address(this)), Hooks.Permissions({ beforeInitialize: true, afterInitialize: false, beforeAddLiquidity: true, afterAddLiquidity: false, beforeRemoveLiquidity: false, afterRemoveLiquidity: false, beforeSwap: true, afterSwap: false, beforeDonate: false, afterDonate: false, beforeSwapReturnDelta: true, afterSwapReturnDelta: false, afterAddLiquidityReturnDelta: false, afterRemoveLiquidityReturnDelta: false }) ); emit OwnershipTransferred(address(0), owner_); } modifier onlyPM() { if (msg.sender != address(poolManager)) revert NotPoolManager(); _; } modifier onlyOwner() { if (msg.sender != owner) revert NotOwner(); _; } // ------------------------------------------------------------------ the L2 clock /// @notice Elysium is an Arbitrum Orbit chain: block.number there is the parent chain's block, so ages are counted /// in L2 blocks read from ArbSys. Off Orbit (tests, forks) it falls back to block.number. function l2Block() public view returns (uint256 n) { (bool ok, bytes memory r) = address(100).staticcall{gas: 20_000}(abi.encodeWithSelector(0xa3b1b31d)); n = ok && r.length == 32 ? abi.decode(r, (uint256)) : block.number; } // ------------------------------------------------------------------ listings function list(Currency c0, Currency c1) external onlyOwner returns (uint256 idx) { if (Currency.unwrap(c0) >= Currency.unwrap(c1)) revert BadInput(); PoolKey memory key = PoolKey({currency0: c0, currency1: c1, fee: 0, tickSpacing: 1, hooks: IHooks(address(this))}); PoolId id = key.toId(); if (idxPlusOne[id] != 0) revert BadInput(); idx = listings.length; listings.push(Listing({key: key, paused: false, cap0: 0, cap1: 0})); idxPlusOne[id] = idx + 1; poolManager.initialize(key, SQRT_ONE); emit PoolListed(idx, PoolId.unwrap(id), Currency.unwrap(c0), Currency.unwrap(c1)); } function poolCount() external view returns (uint256) { return listings.length; } function poolKey(uint256 idx) external view returns (PoolKey memory) { return _listing(idx).key; } function poolIndex(PoolKey calldata key) public view returns (uint256) { uint256 i = idxPlusOne[key.toId()]; if (i == 0) revert UnknownPool(); return i - 1; } function poolInfo(uint256 idx) external view returns (Listing memory) { return _listing(idx); } function makersOf(uint256 idx) external view returns (address[] memory) { return poolMakers[idx]; } function _listing(uint256 idx) internal view returns (Listing storage) { if (idx >= listings.length) revert UnknownPool(); return listings[idx]; } // ------------------------------------------------------------------ makers function join() public { Maker storage m = makers[msg.sender]; if (m.joined) return; m.joined = true; m.quoter = msg.sender; emit MakerJoined(msg.sender); emit QuoterChanged(msg.sender, msg.sender); } /// @notice An operator is a hot key for the pricing bot: it writes prices and can pause, never moves funds. /// The newest operator becomes the key whose prices the venue reads; revoking it falls back to the maker. function setOperator(address op, bool allowed) external { Maker storage m = makers[msg.sender]; if (!m.joined) revert NotMaker(); if (op == address(0) || op == msg.sender) revert BadInput(); isOperator[msg.sender][op] = allowed; emit OperatorSet(msg.sender, op, allowed); if (allowed) m.quoter = op; else if (m.quoter == op) m.quoter = msg.sender; else return; emit QuoterChanged(msg.sender, m.quoter); } function setPaused(address maker, bool paused) external { bool self = msg.sender == maker; if (!self && !(paused && isOperator[maker][msg.sender])) revert NotMaker(); if (!makers[maker].joined) revert NotMaker(); makers[maker].paused = paused; emit MakerPaused(maker, paused, msg.sender); } /// @notice Writes prices for the caller. data = repeated (uint16 pool index, uint256 slot), 34 bytes each. /// The contract stamps each slot with the current L2 block, so a maker never has to guess its inclusion block. function price(bytes calldata data) external { if (data.length == 0 || data.length % 34 != 0) revert BadInput(); uint256 now_ = l2Block() & ((1 << 40) - 1); uint256 n = listings.length; for (uint256 o; o < data.length; o += 34) { uint256 idx = uint16(bytes2(data[o:o + 2])); if (idx >= n) revert UnknownPool(); uint256 s = uint256(bytes32(data[o + 2:o + 34])); s = (s & ~(uint256((1 << 40) - 1) << 192)) | (now_ << 192); slotOf[msg.sender][idx] = s; emit Priced(msg.sender, idx, s); } } function deposit(uint256 idx, bool token1, uint256 amount) external payable { Listing storage L = _listing(idx); if (amount == 0) revert BadInput(); join(); if (!inPool[msg.sender][idx]) { if (poolMakers[idx].length >= MAX_MAKERS) revert TooManyMakers(); inPool[msg.sender][idx] = true; poolMakers[idx].push(msg.sender); } Currency c = token1 ? L.key.currency1 : L.key.currency0; if (c.isAddressZero() ? msg.value != amount : msg.value != 0) revert BadInput(); uint256 paid = abi.decode(poolManager.unlock(abi.encode(uint8(1), msg.sender, c, amount, address(0))), (uint256)); (uint256 b0, uint256 b1) = _stock(msg.sender, idx); if (token1) b1 += paid; else b0 += paid; if ((L.cap0 != 0 && b0 > L.cap0) || (L.cap1 != 0 && b1 > L.cap1)) revert OverCap(); _setStock(msg.sender, idx, b0, b1); emit Deposited(msg.sender, idx, Currency.unwrap(c), paid); } /// @notice Always open to the maker, even while the venue, the pool or the maker is paused. function withdraw(uint256 idx, bool token1, uint256 amount, address to) external { Listing storage L = _listing(idx); (uint256 b0, uint256 b1) = _stock(msg.sender, idx); if (token1) { if (amount > b1) revert BadInput(); b1 -= amount; } else { if (amount > b0) revert BadInput(); b0 -= amount; } if (amount == 0 || to == address(0)) revert BadInput(); _setStock(msg.sender, idx, b0, b1); Currency c = token1 ? L.key.currency1 : L.key.currency0; poolManager.unlock(abi.encode(uint8(2), msg.sender, c, amount, to)); emit Withdrawn(msg.sender, idx, Currency.unwrap(c), amount, to); } function stockOf(address maker, uint256 idx) external view returns (uint256 bal0, uint256 bal1) { return _stock(maker, idx); } function slotFor(address maker, uint256 idx) public view returns (uint256) { return slotOf[makers[maker].quoter][idx]; } function _stock(address maker, uint256 idx) internal view returns (uint256, uint256) { uint256 s = stock[maker][idx]; return (uint128(s), s >> 128); } function _setStock(address maker, uint256 idx, uint256 b0, uint256 b1) internal { if (b0 > type(uint128).max || b1 > type(uint128).max) revert BadInput(); stock[maker][idx] = b0 | (b1 << 128); } function unlockCallback(bytes calldata data) external onlyPM returns (bytes memory) { (uint8 action, address who, Currency c, uint256 amount, address to) = abi.decode(data, (uint8, address, Currency, uint256, address)); if (action == 1) { poolManager.sync(c); uint256 paid; if (c.isAddressZero()) { paid = poolManager.settle{value: amount}(); } else { _pull(Currency.unwrap(c), who, address(poolManager), amount); paid = poolManager.settle(); } poolManager.mint(address(this), c.toId(), paid); return abi.encode(paid); } poolManager.burn(address(this), c.toId(), amount); poolManager.take(c, to, amount); return ""; } function _pull(address token, address from, address to, uint256 amount) internal { (bool ok, bytes memory r) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, amount)); if (!ok || (r.length != 0 && !abi.decode(r, (bool))) || token.code.length == 0) revert TransferFailed(); } // ------------------------------------------------------------------ pricing struct Fill { address maker; uint256 amountIn; // what the taker pays, fee included uint256 amountOut; // what the taker receives uint256 makerIn; // what the maker receives uint256 fee; uint256 size0; // token0 size counted against the maker's per-block limit } /// @notice Same code as the swap: the numbers match a swap in the same block to the base unit. function quoteExactIn(uint256 idx, bool zeroForOne, uint256 amountIn) external view returns (uint256 amountOut, address maker) { Fill memory f = _best(idx, zeroForOne, true, amountIn); return (f.amountOut, f.maker); } function quoteExactOut(uint256 idx, bool zeroForOne, uint256 amountOut) external view returns (uint256 amountIn, address maker) { Fill memory f = _best(idx, zeroForOne, false, amountOut); return (f.amountIn, f.maker); } /// @notice Everything a screen needs about one pool in one call. function book(uint256 idx) external view returns (address[] memory who, uint256[] memory slots, uint256[] memory bal0, uint256[] memory bal1, bool[] memory paused, uint256 l2) { _listing(idx); who = poolMakers[idx]; uint256 n = who.length; slots = new uint256[](n); bal0 = new uint256[](n); bal1 = new uint256[](n); paused = new bool[](n); for (uint256 i; i < n; i++) { slots[i] = slotFor(who[i], idx); (bal0[i], bal1[i]) = _stock(who[i], idx); paused[i] = makers[who[i]].paused; } l2 = l2Block(); } function _best(uint256 idx, bool zeroForOne, bool exactIn, uint256 amount) internal view returns (Fill memory best) { Listing storage L = _listing(idx); if (halted || L.paused) revert Halted(); if (amount == 0) revert BadInput(); address[] storage list_ = poolMakers[idx]; uint256 now_ = l2Block(); uint256 fee = feePips; for (uint256 i; i < list_.length; i++) { (bool ok, Fill memory f) = _try(list_[i], idx, zeroForOne, exactIn, amount, now_, fee); if (!ok) continue; if (best.maker == address(0) || (exactIn ? f.amountOut > best.amountOut : f.amountIn < best.amountIn)) best = f; } if (best.maker == address(0)) revert NoLiveQuote(); } function _pow10(uint256 k) internal pure returns (uint256) { return 10 ** k; } /// @dev Prices one maker's fill; ok = false when this maker cannot fill it (any reason). function _try(address maker, uint256 idx, bool zeroForOne, bool exactIn, uint256 amount, uint256 now_, uint256 feeP) internal view returns (bool ok, Fill memory f) { Maker storage M = makers[maker]; if (M.paused) return (false, f); uint256 s = slotOf[M.quoter][idx]; uint256 life = (s >> 176) & 0xffff; if (life == 0) return (false, f); uint256 born = (s >> 192) & ((1 << 40) - 1); uint256 nowT = now_ & ((1 << 40) - 1); if (nowT < born) return (false, f); uint256 age = nowT - born; uint256 flags = s >> 248; if (age >= life || (flags & F_SAME_BLOCK != 0 && age != 0)) return (false, f); if (flags & (zeroForOne ? F_NO_BID : F_NO_ASK) != 0) return (false, f); uint256 mant = s & ((1 << 56) - 1); uint256 e = (s >> 56) & 0xff; if (mant == 0 || e < 68 || e > 158) return (false, f); // price exponent kept within 10^-60 .. 10^30 uint256 capM = (s >> 96) & ((1 << 40) - 1); uint256 cap = capM == 0 ? 0 : capM * _pow10((s >> 136) & 0xff > 30 ? 30 : (s >> 136) & 0xff); // size in token0 terms: exact when token0 is the specified side, at the plain price otherwise uint256 net = amount; if (exactIn) { f.fee = FullMath.mulDivRoundingUp(amount, feeP, PIPS); net = amount - f.fee; if (net == 0) return (false, f); } uint256 size0; if (zeroForOne == exactIn) size0 = net; // sell token0 exact in, or buy token0 exact out else size0 = _div(net, mant * PIPS, e); uint256 spread = (zeroForOne ? (s >> 64) : (s >> 80)) & 0xffff; spread += age * ((s >> 160) & 0xffff); if (cap != 0) { uint256 u = used[maker][idx]; uint256 done = (u & type(uint64).max) == now_ ? u >> 64 : 0; if (size0 + done > cap) return (false, f); spread += FullMath.mulDiv((s >> 144) & 0xffff, size0, cap); } if (zeroForOne && spread >= PIPS) return (false, f); uint256 num = mant * (zeroForOne ? PIPS - spread : PIPS + spread); (uint256 b0, uint256 b1) = _stock(maker, idx); if (zeroForOne) { // taker sells token0, receives token1 at the bid if (exactIn) { f.makerIn = net; f.amountOut = _mul(net, num, e, false); } else { f.amountOut = amount; f.makerIn = _div(amount, num, e) + 1; // rounded up } if (f.amountOut == 0 || f.amountOut > b1) return (false, f); } else { // taker buys token0, pays token1 at the ask if (exactIn) { f.makerIn = net; f.amountOut = _div(net, num, e); } else { f.amountOut = amount; f.makerIn = _mul(amount, num, e, true); } if (f.amountOut == 0 || f.amountOut > b0) return (false, f); } if (!exactIn) f.fee = FullMath.mulDivRoundingUp(f.makerIn, feeP, PIPS); f.amountIn = f.makerIn + f.fee; if (f.amountIn > uint256(uint128(type(int128).max)) || f.amountOut > uint256(uint128(type(int128).max))) return (false, f); f.size0 = zeroForOne ? (exactIn ? f.makerIn : _div(f.amountOut, mant * PIPS, e)) : f.amountOut; if (cap != 0) { uint256 u = used[maker][idx]; uint256 done = (u & type(uint64).max) == now_ ? u >> 64 : 0; if (f.size0 + done > cap) return (false, f); } f.maker = maker; ok = true; } /// @dev x * num * 10^(e-128) / PIPS function _mul(uint256 x, uint256 num, uint256 e, bool up) internal pure returns (uint256) { if (e >= 128) { uint256 n = num * _pow10(e - 128); return up ? FullMath.mulDivRoundingUp(x, n, PIPS) : FullMath.mulDiv(x, n, PIPS); } uint256 d = PIPS * _pow10(128 - e); return up ? FullMath.mulDivRoundingUp(x, num, d) : FullMath.mulDiv(x, num, d); } /// @dev x * PIPS / (num * 10^(e-128)), rounded down function _div(uint256 x, uint256 num, uint256 e) internal pure returns (uint256) { if (e >= 128) return FullMath.mulDiv(x, PIPS, num * _pow10(e - 128)); return FullMath.mulDiv(x, PIPS * _pow10(128 - e), num); } // ------------------------------------------------------------------ v4 hook function beforeInitialize(address sender, PoolKey calldata, uint160) external view onlyPM returns (bytes4) { if (sender != address(this)) revert Unsupported(); return IHooks.beforeInitialize.selector; } function beforeAddLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata) external view onlyPM returns (bytes4) { revert Unsupported(); // prices come from makers, never from a curve } function beforeSwap(address router, PoolKey calldata key, SwapParams calldata params, bytes calldata) external onlyPM returns (bytes4, BeforeSwapDelta, uint24) { uint256 idx = poolIndex(key); bool exactIn = params.amountSpecified < 0; uint256 amount = exactIn ? uint256(-params.amountSpecified) : uint256(params.amountSpecified); Fill memory f = _best(idx, params.zeroForOne, exactIn, amount); // the maker's books (uint256 b0, uint256 b1) = _stock(f.maker, idx); if (params.zeroForOne) { b0 += f.makerIn; b1 -= f.amountOut; } else { b1 += f.makerIn; b0 -= f.amountOut; } _setStock(f.maker, idx, b0, b1); uint256 now_ = l2Block(); uint256 u = used[f.maker][idx]; uint256 done = (u & type(uint64).max) == now_ ? u >> 64 : 0; used[f.maker][idx] = uint64(now_) | ((done + f.size0) << 64); (Currency cIn, Currency cOut) = params.zeroForOne ? (key.currency0, key.currency1) : (key.currency1, key.currency0); feesOwed[cIn] += f.fee; // settle with the PoolManager in claims: take the taker's input as claims, pay the output out of claims poolManager.mint(address(this), cIn.toId(), f.amountIn); poolManager.burn(address(this), cOut.toId(), f.amountOut); emit Filled(idx, f.maker, router, tx.origin, params.zeroForOne, f.amountIn, f.amountOut, f.fee); BeforeSwapDelta d = exactIn ? toBeforeSwapDelta(int128(int256(f.amountIn)), -int128(int256(f.amountOut))) : toBeforeSwapDelta(-int128(int256(f.amountOut)), int128(int256(f.amountIn))); return (IHooks.beforeSwap.selector, d, 0); } function afterInitialize(address, PoolKey calldata, uint160, int24) external pure returns (bytes4) { revert Unsupported(); } function afterAddLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, BalanceDelta, BalanceDelta, bytes calldata) external pure returns (bytes4, BalanceDelta) { revert Unsupported(); } function beforeRemoveLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, bytes calldata) external pure returns (bytes4) { revert Unsupported(); } function afterRemoveLiquidity(address, PoolKey calldata, ModifyLiquidityParams calldata, BalanceDelta, BalanceDelta, bytes calldata) external pure returns (bytes4, BalanceDelta) { revert Unsupported(); } function afterSwap(address, PoolKey calldata, SwapParams calldata, BalanceDelta, bytes calldata) external pure returns (bytes4, int128) { revert Unsupported(); } function beforeDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) external pure returns (bytes4) { revert Unsupported(); } function afterDonate(address, PoolKey calldata, uint256, uint256, bytes calldata) external pure returns (bytes4) { revert Unsupported(); } // ------------------------------------------------------------------ admin, bounded function setFee(uint24 pips) external onlyOwner { if (pips > MAX_FEE) revert BadInput(); feePips = pips; emit FeeSet(pips); } function setGuardian(address g) external onlyOwner { guardian = g; emit GuardianSet(g); } function setTreasury(address t) external onlyOwner { if (t == address(0)) revert BadInput(); treasury = t; emit TreasurySet(t); } function setPoolCap(uint256 idx, uint128 cap0, uint128 cap1) external onlyOwner { Listing storage L = _listing(idx); L.cap0 = cap0; L.cap1 = cap1; emit PoolCapSet(idx, cap0, cap1); } /// @notice Fees only: no admin path reaches maker stock. function collect(Currency c) external { uint256 a = feesOwed[c]; if (a == 0) revert BadInput(); feesOwed[c] = 0; poolManager.unlock(abi.encode(uint8(2), address(0), c, a, treasury)); emit FeesCollected(Currency.unwrap(c), a, treasury); } function halt(bool h) external { if (msg.sender != guardian && msg.sender != owner) revert NotGuardian(); halted = h; emit HaltSet(h); } /// @notice Takes a maker out of a pool's search list (dust squatting a seat). Its stock stays withdrawable. function delist(uint256 idx, address maker) external { if (msg.sender != guardian && msg.sender != owner) revert NotGuardian(); if (!inPool[maker][idx]) revert BadInput(); address[] storage a = poolMakers[idx]; for (uint256 i; i < a.length; i++) { if (a[i] == maker) { a[i] = a[a.length - 1]; a.pop(); break; } } inPool[maker][idx] = false; } function pausePool(uint256 idx, bool p) external { if (msg.sender != guardian && msg.sender != owner) revert NotGuardian(); _listing(idx).paused = p; emit PoolPaused(idx, p); } function transferOwnership(address to) external onlyOwner { pendingOwner = to; } function acceptOwnership() external { if (msg.sender != pendingOwner) revert NotOwner(); emit OwnershipTransferred(owner, msg.sender); owner = msg.sender; pendingOwner = address(0); } receive() external payable { if (msg.sender != address(poolManager)) revert Unsupported(); } }