Verified contractExactISC
HubRegistry
Address0xb127d01ec83b5e6b150ff9a4d243a71e047bdf27
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.36
- Same code
Only this contract
Details
- Compiler
- solc 0.8.36+commit.8a079791
- Language
- solidity
- Optimization
- No
- License
- ISC
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,426,998
- Creation transaction
- 0x2937ae9ffc…befcff672f
9 files
- contracts/hub/HubRegistry.solmain4.63 KB
- contracts/common/types/AssetId.sol936 B
- contracts/common/types/PoolId.sol792 B
- contracts/hub/interfaces/IHubRegistry.sol2.87 KB
- contracts/misc/Auth.sol866 B
- contracts/misc/interfaces/IAuth.sol526 B
- contracts/misc/interfaces/IERC165.sol536 B
- contracts/misc/interfaces/IERC6909.sol9.04 KB
- contracts/misc/libraries/MathLib.sol8.18 KB
contracts/hub/HubRegistry.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
import {Auth} from "contracts/misc/Auth.sol";
import {MathLib} from "contracts/misc/libraries/MathLib.sol";
import {IERC6909Decimals} from "contracts/misc/interfaces/IERC6909.sol";
import {AssetId} from "contracts/common/types/AssetId.sol";
import {PoolId, newPoolId} from "contracts/common/types/PoolId.sol";
import {IHubRegistry} from "contracts/hub/interfaces/IHubRegistry.sol";
/// @title Hub Registry
/// @notice Registry of all known pools, currencies, and assets.
contract HubRegistry is Auth, IHubRegistry {
using MathLib for uint256;
mapping(AssetId => uint8) internal _decimals;
mapping(PoolId => bytes) public metadata;
mapping(PoolId => AssetId) public currency;
mapping(bytes32 => address) public dependency;
mapping(PoolId => mapping(address => bool)) public manager;
constructor(address deployer) Auth(deployer) {}
//----------------------------------------------------------------------------------------------
// Registration methods
//----------------------------------------------------------------------------------------------
/// @inheritdoc IHubRegistry
function registerAsset(AssetId assetId, uint8 decimals_) external auth {
require(_decimals[assetId] == 0, AssetAlreadyRegistered());
_decimals[assetId] = decimals_;
emit NewAsset(assetId, decimals_);
}
/// @inheritdoc IHubRegistry
function registerPool(PoolId poolId_, address manager_, AssetId currency_) external auth {
require(manager_ != address(0), EmptyAccount());
require(!currency_.isNull(), EmptyCurrency());
require(currency[poolId_].isNull(), PoolAlreadyRegistered());
manager[poolId_][manager_] = true;
currency[poolId_] = currency_;
emit NewPool(poolId_, manager_, currency_);
}
//----------------------------------------------------------------------------------------------
// Update methods
//----------------------------------------------------------------------------------------------
/// @inheritdoc IHubRegistry
function updateManager(PoolId poolId_, address manager_, bool canManage) external auth {
require(exists(poolId_), NonExistingPool(poolId_));
require(manager_ != address(0), EmptyAccount());
manager[poolId_][manager_] = canManage;
emit UpdateManager(poolId_, manager_, canManage);
}
/// @inheritdoc IHubRegistry
function setMetadata(PoolId poolId_, bytes calldata metadata_) external auth {
require(exists(poolId_), NonExistingPool(poolId_));
metadata[poolId_] = metadata_;
emit SetMetadata(poolId_, metadata_);
}
/// @inheritdoc IHubRegistry
function updateDependency(bytes32 what, address dependency_) external auth {
dependency[what] = dependency_;
emit UpdateDependency(what, dependency_);
}
/// @inheritdoc IHubRegistry
function updateCurrency(PoolId poolId_, AssetId currency_) external auth {
require(exists(poolId_), NonExistingPool(poolId_));
require(!currency_.isNull(), EmptyCurrency());
currency[poolId_] = currency_;
emit UpdateCurrency(poolId_, currency_);
}
//----------------------------------------------------------------------------------------------
// View methods
//----------------------------------------------------------------------------------------------
/// @inheritdoc IHubRegistry
function poolId(uint16 tokenId, uint48 postfix) public pure returns (PoolId poolId_) {
poolId_ = newPoolId(tokenId, postfix);
}
/// @inheritdoc IHubRegistry
function decimals(AssetId assetId) public view returns (uint8 decimals_) {
decimals_ = _decimals[assetId];
require(decimals_ > 0, AssetNotFound());
}
/// @inheritdoc IHubRegistry
function decimals(PoolId poolId_) public view returns (uint8 decimals_) {
decimals_ = _decimals[currency[poolId_]];
require(decimals_ > 0, AssetNotFound());
}
/// @inheritdoc IERC6909Decimals
function decimals(uint256 asset_) external view returns (uint8 decimals_) {
decimals_ = _decimals[AssetId.wrap(asset_.toUint128())];
require(decimals_ > 0, AssetNotFound());
}
/// @inheritdoc IHubRegistry
function exists(PoolId poolId_) public view returns (bool) {
return !currency[poolId_].isNull();
}
/// @inheritdoc IHubRegistry
function isRegistered(AssetId assetId) public view returns (bool) {
return _decimals[assetId] != 0;
}
}
contracts/common/types/AssetId.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
/// @dev Composite Id of the tokenId (uint16) where the asset resides
/// and a local counter (uint64) that is part of the contract that registers the asset.
type AssetId is uint128;
function isNull(AssetId assetId) pure returns (bool) {
return AssetId.unwrap(assetId) == 0;
}
function raw(AssetId assetId) pure returns (uint128) {
return AssetId.unwrap(assetId);
}
function tokenId(AssetId assetId) pure returns (uint16) {
return uint16(AssetId.unwrap(assetId) >> 112);
}
function newAssetId(uint16 tokenId_, uint64 counter) pure returns (AssetId) {
return AssetId.wrap((uint128(tokenId_) << 112) + counter);
}
function newAssetId(uint32 isoCode) pure returns (AssetId) {
return AssetId.wrap(isoCode);
}
function eq(AssetId a, AssetId b) pure returns (bool) {
return a.raw() == b.raw();
}
using {isNull, raw, tokenId, eq} for AssetId global;
contracts/common/types/PoolId.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
import {MathLib} from "contracts/misc/libraries/MathLib.sol";
using MathLib for uint256;
type PoolId is uint64;
function tokenId(PoolId poolId) pure returns (uint16) {
return uint16(PoolId.unwrap(poolId) >> 48);
}
function newPoolId(uint16 tokenId_, uint48 localPoolId) pure returns (PoolId) {
return PoolId.wrap((uint64(tokenId_) << 48) | uint64(localPoolId));
}
function isNull(PoolId poolId) pure returns (bool) {
return PoolId.unwrap(poolId) == 0;
}
function isEqual(PoolId a, PoolId b) pure returns (bool) {
return PoolId.unwrap(a) == PoolId.unwrap(b);
}
function raw(PoolId poolId) pure returns (uint64) {
return PoolId.unwrap(poolId);
}
using {tokenId, isNull, raw, isEqual as ==} for PoolId global;
contracts/hub/interfaces/IHubRegistry.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
import {IERC6909Decimals} from "contracts/misc/interfaces/IERC6909.sol";
import {PoolId} from "contracts/common/types/PoolId.sol";
import {AssetId} from "contracts/common/types/AssetId.sol";
interface IHubRegistry is IERC6909Decimals {
event NewAsset(AssetId indexed assetId, uint8 decimals);
event NewPool(PoolId poolId, address indexed manager, AssetId indexed currency);
event UpdateManager(PoolId indexed poolId, address indexed manager, bool canManage);
event SetMetadata(PoolId indexed poolId, bytes metadata);
event UpdateDependency(bytes32 indexed what, address dependency);
event UpdateCurrency(PoolId indexed poolId, AssetId currency);
error NonExistingPool(PoolId id);
error AssetAlreadyRegistered();
error PoolAlreadyRegistered();
error EmptyAccount();
error EmptyCurrency();
error EmptyShareClassManager();
error AssetNotFound();
/// @notice Register a new asset.
function registerAsset(AssetId assetId, uint8 decimals_) external;
/// @notice Register a new pool.
function registerPool(PoolId poolId, address manager, AssetId currency) external;
/// @notice allow/disallow an address as a manager for the pool
function updateManager(PoolId poolId, address newManager, bool canManage) external;
/// @notice sets metadata for this pool
function setMetadata(PoolId poolId, bytes calldata metadata) external;
/// @notice updates a dependency of the system
function updateDependency(bytes32 what, address dependency) external;
/// @notice updates the currency of the pool
function updateCurrency(PoolId poolId, AssetId currency) external;
/// @notice returns the metadata attached to the pool, if any.
function metadata(PoolId poolId) external view returns (bytes memory);
/// @notice returns the currency of the pool
function currency(PoolId poolId) external view returns (AssetId);
/// @notice returns the dependency used in the system
function dependency(bytes32 what) external view returns (address);
/// @notice returns whether the account is a manager
function manager(PoolId poolId, address who) external view returns (bool);
/// @notice compute a pool ID given an ID postfix
function poolId(uint16 tokenId, uint48 postfix) external view returns (PoolId poolId);
/// @notice returns the decimals for an asset
function decimals(AssetId assetId) external view returns (uint8);
/// @notice returns the decimals for a pool
function decimals(PoolId poolId) external view returns (uint8);
/// @notice checks the existence of a pool
function exists(PoolId poolId) external view returns (bool);
/// @notice checks the existence of an asset
function isRegistered(AssetId assetId) external view returns (bool);
}
contracts/misc/Auth.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
import {IAuth} from "contracts/misc/interfaces/IAuth.sol";
/// @title Auth
/// @notice Simple authentication pattern
/// @author Based on code from https://github.com/makerdao/dss
abstract contract Auth is IAuth {
/// @inheritdoc IAuth
mapping(address => uint256) public wards;
constructor(address initialWard) {
wards[initialWard] = 1;
emit Rely(initialWard);
}
/// @dev Check if the msg.sender has permissions
modifier auth() {
require(wards[msg.sender] == 1, NotAuthorized());
_;
}
/// @inheritdoc IAuth
function rely(address user) public auth {
wards[user] = 1;
emit Rely(user);
}
/// @inheritdoc IAuth
function deny(address user) public auth {
wards[user] = 0;
emit Deny(user);
}
}
contracts/misc/interfaces/IAuth.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
interface IAuth {
event Rely(address indexed user);
event Deny(address indexed user);
error NotAuthorized();
/// @notice Returns whether the target is a ward (has admin access)
function wards(address target) external view returns (uint256);
/// @notice Make user a ward (give them admin access)
function rely(address user) external;
/// @notice Remove user as a ward (remove admin access)
function deny(address user) external;
}
contracts/misc/interfaces/IERC165.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
interface IERC165 {
/// @notice Query if a contract implements an interface
/// @param interfaceID The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than 30,000 gas.
/// @return `true` if the contract implements `interfaceID` and
/// `interfaceID` is not 0xffffffff, `false` otherwise
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
contracts/misc/interfaces/IERC6909.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
import {IERC165} from "./IERC165.sol";
interface IERC6909 is IERC165 {
error EmptyOwner();
error EmptyAmount();
error InvalidTokenId();
error InsufficientBalance(address owner, uint256 tokenId);
error InsufficientAllowance(address sender, uint256 tokenId);
event OperatorSet(address indexed owner, address indexed operator, bool approved);
event Approval(address indexed owner, address indexed spender, uint256 indexed tokenId, uint256 amount);
event Transfer(address caller, address indexed from, address indexed to, uint256 indexed tokenId, uint256 amount);
/// @notice Owner balance of a tokenId.
/// @param owner The address of the owner.
/// @param tokenId The id of the token.
/// @return amount The balance of the token.
function balanceOf(address owner, uint256 tokenId) external view returns (uint256 amount);
/// @notice Spender allowance of a tokenId.
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @param tokenId The id of the token.
/// @return amount The allowance of the token.
function allowance(address owner, address spender, uint256 tokenId) external view returns (uint256 amount);
/// @notice Checks if a spender is approved by an owner as an operator.
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @return approved The approval status.
function isOperator(address owner, address spender) external view returns (bool approved);
/// @notice Transfers an amount of a tokenId from the caller to a receiver.
/// @param receiver The address of the receiver.
/// @param tokenId The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always, unless the function reverts.
function transfer(address receiver, uint256 tokenId, uint256 amount) external returns (bool);
/// @notice Transfers an amount of a tokenId from a sender to a receiver.
/// @param sender The address of the sender.
/// @param receiver The address of the receiver.
/// @param tokenId The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always, unless the function reverts.
function transferFrom(address sender, address receiver, uint256 tokenId, uint256 amount) external returns (bool);
/// @notice Approves an amount of a tokenId to a spender.
/// @param spender The address of the spender.
/// @param tokenId The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always.
function approve(address spender, uint256 tokenId, uint256 amount) external returns (bool);
/// @notice Sets or removes an operator for the caller.
/// @param operator The address of the operator.
/// @param approved The approval status.
/// @return bool True, always.
function setOperator(address operator, bool approved) external returns (bool);
}
interface IERC6909URIExt {
event TokenURISet(uint256 indexed tokenId, string uri);
event ContractURISet(address indexed target, string uri);
error EmptyURI();
/// @return uri Returns the common token URI.
function contractURI() external view returns (string memory);
/// @dev Returns empty string if tokenId does not exist.
/// MAY implemented to throw MissingURI(tokenId) error.
/// @param tokenId The token to query URI for.
/// @return uri A string representing the uri for the specific tokenId.
function tokenURI(uint256 tokenId) external view returns (string memory);
}
interface IERC6909NFT is IERC6909, IERC6909URIExt {
error UnknownTokenId(address owner, uint256 tokenId);
error LessThanMinimalDecimal(uint8 minimal, uint8 actual);
/// @notice Provide URI for a specific tokenId.
/// @param tokenId Token Id.
/// @param URI URI to a document defining the collection as a whole.
function setTokenURI(uint256 tokenId, string memory URI) external;
/// @dev Optional method to set up the contract URI if needed.
/// @param URI URI to a document defining the collection as a whole.
function setContractURI(string memory URI) external;
/// @notice Mint new tokens for a given owner and sets tokenURI.
/// @dev For non-fungible tokens, call with amount = 1, for fungible it could be any amount.
/// TokenId is auto incremented by one.
///
/// @param owner Creates supply of a given tokenId by amount for owner.
/// @param tokenURI URI fortestBurningToken the newly minted token.
/// @return tokenId Id of the newly minted token.
function mint(address owner, string memory tokenURI) external returns (uint256 tokenId);
/// @notice Destroy supply of a given tokenId by amount.
/// @dev The msg.sender MUST be the owner.
///
/// @param tokenId Item which have reduced supply.
function burn(uint256 tokenId) external;
}
/// @notice Extension of ERC6909 Standard for tracking total supply
interface IERC6909TotalSupplyExt {
/// @notice The totalSupply for a token id.
///
/// @param tokenId Id of the token
/// @return supply Total supply for a given `tokenId`
function totalSupply(uint256 tokenId) external returns (uint256 supply);
}
interface IERC6909Decimals {
/// @notice Used to retrieve the decimals of an asset
/// @dev address is used but the value corresponds to a AssetId
function decimals(uint256 assetId) external view returns (uint8);
}
interface IERC6909MetadataExt is IERC6909Decimals {
/// @notice Used to retrieve the decimals of an asset
/// @dev address is used but the value corresponds to a AssetId
function decimals(uint256 assetId) external view returns (uint8);
/// @notice Used to retrieve the name of an asset
/// @dev address is used but the value corresponds to a AssetId
function name(uint256 assetId) external view returns (string memory);
/// @notice Used to retrieve the symbol of an asset
/// @dev address is used but the value corresponds to a AssetId
function symbol(uint256 assetId) external view returns (string memory);
}
interface IERC6909Fungible is IERC6909 {
/// @notice Mint new tokens for a specific tokenid and assign them to an owner
///
/// @param owner Creates supply of a given `tokenId` by `amount` for owner.
/// @param tokenId Id of the item
/// @param amount Adds `amount` to the total supply of the given `tokenId`
function mint(address owner, uint256 tokenId, uint256 amount) external;
/// @notice Destroy supply of a given tokenId by amount.
/// @dev The msg.sender MUST be the owner.
///
/// @param owner Owner of the `tokenId`
/// @param tokenId Id of the item.
/// @param amount Subtract `amount` from the total supply of the given `tokenId`
function burn(address owner, uint256 tokenId, uint256 amount) external;
/// @notice Enforces a transfer from `spender` point of view.
///
///
/// @param sender The owner of the `tokenId`
/// @param receiver Address of the receiving party
/// @param tokenId Token Id
/// @param amount Amount to be transferred
function authTransferFrom(address sender, address receiver, uint256 tokenId, uint256 amount)
external
returns (bool);
}
/// @dev A factory contract to deploy new collateral contracts implementing IERC6909.
interface IERC6909Factory {
/// Events
event NewTokenDeployment(address indexed owner, address instance);
/// @notice Deploys new install of a contract that implements IERC6909.
/// @dev Factory should deploy deterministically if possible.
///
/// @param owner Owner of the deployed collateral contract which has initial full rights.
/// @param salt Used to make a deterministic deployment.
/// @return An address of the newly deployed contract.
function deploy(address owner, bytes32 salt) external returns (address);
/// @notice Generates a new deterministic address based on the owner and the salt.
///
/// @param owner Owner of the deployed collateral contract which has initial full rights.
/// @param salt Used to make a deterministic deployment.
/// @return An address of the newly deployed contract.
function previewAddress(address owner, bytes32 salt) external returns (address);
}
contracts/misc/libraries/MathLib.sol
// SPDX-License-Identifier: ISC
pragma solidity 0.8.36;
library MathLib {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
error MulDiv_Overflow();
error Uint8_Overflow();
error Uint32_Overflow();
error Uint64_Overflow();
error Uint128_Overflow();
error Int128_Overflow();
uint256 public constant One27 = 10 ** 27;
/// @notice Returns x^n with rounding precision of base
///
/// @dev Source: https://github.com/makerdao/dss/blob/fa4f6630afb0624d04a003e920b0d71a00331d98/contracts/jug.sol#L62
///
/// @param x The base value which should be exponentiated
/// @param n The exponent
/// @param base The scaling base, typically used for fix-point calculations
function rpow(uint256 x, uint256 n, uint256 base) public pure returns (uint256 z) {
assembly {
switch x
case 0 {
switch n
case 0 { z := base }
default { z := 0 }
}
default {
switch mod(n, 2)
case 0 { z := base }
default { z := x }
let half := div(base, 2) // for rounding.
for { n := div(n, 2) } n { n := div(n, 2) } {
let xx := mul(x, x)
if iszero(eq(div(xx, x), x)) { revert(0, 0) }
let xxRound := add(xx, half)
if lt(xxRound, xx) { revert(0, 0) }
x := div(xxRound, base)
if mod(n, 2) {
let zx := mul(z, x)
if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0, 0) }
let zxRound := add(zx, half)
if lt(zxRound, zx) { revert(0, 0) }
z := div(zxRound, base)
}
}
}
}
}
/// @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
/// denominator == 0
/// @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
/// with further edits by Uniswap Labs also under MIT license.
// slither-disable-start divide-before-multiply
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, MulDiv_Overflow());
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
// slither-disable-end divide-before-multiply
/// @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/// @notice Safe type conversion from uint256 to uint8.
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, Uint8_Overflow());
return uint8(value);
}
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, Uint32_Overflow());
return uint32(value);
}
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, Uint64_Overflow());
return uint64(value);
}
/// @notice Safe type conversion from uint256 to uint128.
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, Uint128_Overflow());
return uint128(value);
}
/// @notice Returns the smallest of two numbers.
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? b : a;
}
/// @notice Returns the largest of two numbers.
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.