Verified contractExactUNLICENSED
PairRegistry
Address0xab5d0cbd70b5f282d7ad118d9be158db7f7ec82c
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.30
- Same code
2 more contracts
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,191,878
- Creation transaction
- 0x8e3b5feb13…dadfb7b150
src/PairRegistry.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {quoteBandFloorFits} from "./venues/OpeningDust.sol";
/// @title PairRegistry
/// @notice One chain's list of what a launch may pair against besides the native coin.
///
/// THE NATIVE COIN IS NOT IN HERE, AND CANNOT BE TURNED OFF. A launch quoted in it is checked
/// against the price attestor's own band (`MIN/MAX_USD_PER_QUOTE`), exactly as before this
/// existed. Everything else -- a tokenized stock, say -- has to be listed here first, with:
///
/// - its decimals, read from the token when it is listed and fixed from then on. They decide
/// where the pool opens: a price in whole quote units becomes a price in raw units through
/// them, so a token that later reported different decimals cannot move an opening price.
/// - its plausibility band in USD, 1e18-scaled, which the attestor holds the signed price to,
/// exactly as it holds the native coin to its own. It exists to refuse an absurd value from a
/// compromised price signer, not to track the market: set it wide -- but not below 1e-30 USD
/// a base unit (an 18-decimal asset at $1e-12 a whole unit). Under that, a pool whose token
/// sorts above the asset could owe more quote dust at its opening than the seeder may pay
/// (OpeningDust.sol), and the launch would be refused on that chain after the others landed;
/// so such a band is refused here, when it is listed.
///
/// WHAT LISTING VOUCHES FOR, AND WHAT IT CANNOT CHECK. The pool, the fee hook and the fee
/// splitter account in raw balances, and Uniswap v4 itself does not support a token whose balance
/// moves without a transfer. So a listed asset must be a plain ERC-20: no fee taken on transfer,
/// no rebasing, no balance that changes on its own. None of that can be proven from a contract
/// read -- a fee can be switched on later, a rebase can be scheduled -- so it is the admin's to
/// check before listing, and the reason the list starts empty. What a listed token's issuer can
/// do to its holders -- pause it, freeze an account, force a transfer -- is a risk accepted
/// with the asset: a pool against a paused token stops trading until it is unpaused.
///
/// The routers a creator's payment may buy an asset through are not listed here: `PairPayment`
/// keeps that list itself.
contract PairRegistry {
struct Asset {
bool enabled;
uint8 decimals;
uint112 minUsdPerQuote;
uint112 maxUsdPerQuote;
}
mapping(address => Asset) internal _assets;
address public admin;
address public pendingAdmin;
event AssetSet(address indexed asset, bool enabled, uint8 decimals, uint256 minUsdPerQuote, uint256 maxUsdPerQuote);
event AdminProposed(address indexed from, address indexed to);
event AdminChanged(address indexed from, address indexed to);
error NotAdmin();
error NotPending();
error ZeroAddress();
error NotAContract(address account);
error InvalidBand(uint256 min, uint256 max);
error UnreadableDecimals(address asset);
error AssetNotListed(address asset);
/// @notice The band lets the asset be priced under 1e-30 USD a base unit (OpeningDust.sol).
error BandBelowFloor(uint256 minUsdPerQuote, uint8 decimals);
constructor(address admin_) {
if (admin_ == address(0)) revert ZeroAddress();
admin = admin_;
}
modifier onlyAdmin() {
if (msg.sender != admin) revert NotAdmin();
_;
}
/// @notice List an asset, change its band, or delist it.
/// @dev Listing reads the decimals from the token and stores them: a later read never reaches
/// a launch. Delisting stops new launches against the asset; pools already open against
/// it are untouched, as nothing here is consulted after a launch.
///
/// DELISTING ASKS NOTHING OF THE ASSET. `enabled == false` only clears the flag -- the
/// band arguments are ignored and the stored decimals and band are kept, for the record
/// (`assets`) -- so a token that has since self-destructed, or whose `decimals()` now
/// reverts, can still be delisted. `terms` and `isListed` refuse it from then on.
function setAsset(address asset, bool enabled, uint256 minUsdPerQuote, uint256 maxUsdPerQuote) external onlyAdmin {
if (asset == address(0)) revert ZeroAddress();
if (!enabled) {
Asset storage a = _assets[asset];
a.enabled = false;
emit AssetSet(asset, false, a.decimals, a.minUsdPerQuote, a.maxUsdPerQuote);
return;
}
if (asset.code.length == 0) revert NotAContract(asset);
if (minUsdPerQuote == 0 || maxUsdPerQuote < minUsdPerQuote || maxUsdPerQuote > type(uint112).max) {
revert InvalidBand(minUsdPerQuote, maxUsdPerQuote);
}
uint8 decimals;
try IERC20Metadata(asset).decimals() returns (uint8 d) {
decimals = d;
} catch {
revert UnreadableDecimals(asset);
}
// 10 ** decimals is multiplied into a price; past this it can overflow.
if (decimals > 36) revert UnreadableDecimals(asset);
// Every price the band lets the signer attest must leave an opening's dust within what the
// seeder may pay: the floor is 1e-30 USD a base unit.
if (!quoteBandFloorFits(minUsdPerQuote, decimals)) revert BandBelowFloor(minUsdPerQuote, decimals);
_assets[asset] = Asset(true, decimals, uint112(minUsdPerQuote), uint112(maxUsdPerQuote));
emit AssetSet(asset, true, decimals, minUsdPerQuote, maxUsdPerQuote);
}
/// @notice What a launch against `asset` is held to: its decimals and its USD band. Reverts
/// for an asset that is not listed, which is what refuses the launch.
function terms(address asset) external view returns (uint8 decimals, uint256 minUsdPerQuote, uint256 maxUsdPerQuote) {
Asset memory a = _assets[asset];
if (!a.enabled) revert AssetNotListed(asset);
return (a.decimals, a.minUsdPerQuote, a.maxUsdPerQuote);
}
/// @notice Whether a launch may pair against `asset` today.
function isListed(address asset) external view returns (bool) {
return _assets[asset].enabled;
}
/// @notice An asset's entry, listed or not.
function assets(address asset) external view returns (Asset memory) {
return _assets[asset];
}
function proposeAdmin(address to) external onlyAdmin {
if (to == address(0)) revert ZeroAddress();
pendingAdmin = to;
emit AdminProposed(admin, to);
}
function acceptAdmin() external {
if (msg.sender != pendingAdmin) revert NotPending();
emit AdminChanged(admin, msg.sender);
admin = msg.sender;
pendingAdmin = address(0);
}
}
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
src/venues/OpeningDust.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.30;
// The quote dust an in-range opening owes, and the quotes it can be owed in
//
// A pool whose token is currency1 -- every native-quoted one, and any asset that sorts below the
// token -- opens one unit of square-root price under the top of its range, so its liquidity is
// active from the first block (UniswapV4Seeder). The position then owes the pool the quote for the
// sliver between that price and the range's top:
//
// dust = ceil(L * 2^96 / (sqrtP * sqrtU)), sqrtU - sqrtP = 1, L ~ slice * 2^96 / sqrtP
// ~ slice / (p^1.5 * 2^96)
//
// where p is token base units per quote base unit. Every launch opens at a $3,000 market cap over
// its launch total T (base units), so p = u * T / 3000 with u the quote's USD per BASE unit, and
// with a slice of at most T:
//
// dust <= 3000^1.5 / (u^1.5 * T^0.5 * 2^96)
//
// It grows as the quote gets cheaper per base unit, and it is worth nothing in dollars anywhere:
// dust * u ~ 7.6e-27 / sqrt(p) USD.
//
// THE TWO NUMBERS. A quote may only be listed (PairRegistry) or attested as the native coin
// (PriceAttestor) with a price band whose floor is at least 1e-30 USD per base unit
// (`quoteBandFloorFits`), which is an 18-decimal asset at $1e-12 a whole unit -- below every
// real asset. At that floor, with the smallest launch the attestor accepts (one whole token,
// T = 1e9, all of it in one slice), the formula gives 6.6e16 base units; the default launch
// (a 200M slice of 1B) owes 4.2e11 there and exactly 1 for any quote worth more than ~$5.6e-5 a
// whole 18-decimal unit. So `MAX_OPENING_DUST` = 1e17 is enough for every launch the contracts
// accept against every quote they accept, and test/InRangeOpening.t.sol holds the two to each
// other.
//
// WHAT THE CAP IS FOR. The factory pays the exact dust from its float and nothing more -- the
// seeder pulls what the pool says the position owes -- so the cap is not what the float loses per
// launch. It is the sanity bound on that pull: a position on the wrong side of its price owes the
// slice's worth of quote, not dust, and is refused (UniswapV4Seeder.QuoteSideTooLarge) whenever
// that is more than the cap. Below the cap the float's own balance is the bound.
// The most quote, in its base units, an opening may owe and the factory may pay for it.
uint256 constant MAX_OPENING_DUST = 1e17;
// Base units of a quote that 1e18-scaled USD 1 (that is, $1e-18) may buy at the most: 1e12, which
// is 1e-30 USD a base unit. See `quoteBandFloorFits`.
uint256 constant MAX_QUOTE_BASE_UNITS_PER_WAD_USD = 1e12;
/// @notice Whether a band whose floor is `minUsdPerQuote` (USD per whole unit, 1e18-scaled) for a
/// quote of `decimals` keeps every opening's dust within `MAX_OPENING_DUST`: at least
/// 1e-30 USD a base unit.
/// @dev minUsdPerQuote >= 10^decimals / 1e12, the division exact (both powers of ten) and nothing
/// multiplied, so no band can overflow it. For 18 decimals the floor is 1e6 ($1e-12 a whole
/// unit); for 12 decimals or fewer it is 1, the least a band can be.
function quoteBandFloorFits(uint256 minUsdPerQuote, uint8 decimals) pure returns (bool) {
uint256 unit = 10 ** uint256(decimals);
uint256 floor = unit <= MAX_QUOTE_BASE_UNITS_PER_WAD_USD ? 1 : unit / MAX_QUOTE_BASE_UNITS_PER_WAD_USD;
return minUsdPerQuote >= floor;
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero/protocol-v2/",
"@layerzerolabs/oapp-evm/=lib/layerzero/oapp-evm/",
"@layerzerolabs/oft-evm/=lib/layerzero/oft-evm/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@uniswap/v4-core/=lib/uniswap-v4-core/",
"ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"layerzero/=lib/layerzero/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/solmate/",
"uniswap-v4-core/=lib/uniswap-v4-core/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.