Feature Tip: Add private address tag to any address under My Name Tag !
Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
DelphiiDev
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// ---------------------------
// OpenZeppelin Upgradeable
// ---------------------------
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
// ---------------------------
// Thirdweb Extensions
// ---------------------------
import {Ownable} from "@thirdweb-dev/contracts/extension/Ownable.sol";
// ---------------------------
// OpenZeppelin & External
// ---------------------------
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "abdk-libraries-solidity/ABDKMath64x64.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
using Strings for uint256;
// USDC contract address on mainnet 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
// USDC contract address on TESTNET 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238
// ----------------------------------------------------
// DelphiiDev: UUPS Upgradeable Version
// ----------------------------------------------------
contract DelphiiDev is
Initializable, // For proxy-safe initialization
UUPSUpgradeable, // For UUPS upgrade logic
ReentrancyGuardUpgradeable, // Upgradeable Reentrancy Guard
Ownable // Thirdweb's Ownable extension
{
// ------------------------------------------------
// Enums & Structs (same as before)
// ------------------------------------------------
enum MarketOutcome {
UNRESOLVED,
OPTION_A,
OPTION_B
}
struct Market {
uint256 id;
string question;
string rules;
uint256 endTime;
MarketOutcome outcome;
string optionA;
string optionB;
// The total USDC liquidity in this market
uint256 liquidity;
// Total share counts for each outcome
uint256 totalOptionAShares;
uint256 totalOptionBShares;
bool resolved;
// LMSR liquidity parameter
uint256 b;
// Scales the logistic probabilities for pricing (1e6-based now)
uint256 initialPriceScaling;
// Tracks user share balances
mapping(address => uint256) optionAShares;
mapping(address => uint256) optionBShares;
// >>> Keep track of addresses that hold shares <<<
address[] optionAHolders;
address[] optionBHolders;
// Optional: track whether an address is already in optionAHolders/optionBHolders
mapping(address => bool) isOptionAHolder;
mapping(address => bool) isOptionBHolder;
}
// ------------------------------------------------
// State Variables
// ------------------------------------------------
IERC20 public usdc; // The USDC token
uint256 public marketCount;
mapping(uint256 => Market) public markets;
// 2% trading fee
uint256 public constant FEE_PERCENTAGE = 0;
// ------------------------------------------------
// Events (same as before)
// ------------------------------------------------
event MarketCreated(
uint256 indexed marketId,
string question,
string rules,
string optionA,
string optionB,
uint256 endTime,
uint256 scaling,
uint256 liquidity
);
event MarketResolved(uint256 indexed marketId, MarketOutcome outcome);
event Claimed(
uint256 indexed marketId,
address indexed user,
uint256 amount
);
event BoughtShares(
uint256 indexed marketId,
address indexed user,
uint256 shareAmount
);
event Failure(uint256 indexed marketId, address indexed user, string err);
event MarketCreationLog(
string message,
address indexed user,
uint256 amount
);
event GenericLog(
string message,
address indexed user,
uint256 marketId,
string payload
);
error ErrorHandler(uint256 marketId, address user, string err);
// ------------------------------------------------
// UUPS-Related Functions
// ------------------------------------------------
/**
* @dev UUPS requires we implement _authorizeUpgrade.
* Restrict this to onlyOwner (from Thirdweb’s Ownable).
*/
function _authorizeUpgrade(
address newImplementation
) internal override onlyOwner {}
/**
* @dev By default, Thirdweb's Ownable extension prevents changing the owner
* unless `_canSetOwner()` returns true. We’ll leave it disabled below
* so only upgrades are possible, but feel free to adjust as needed.
*/
function _canSetOwner() internal view virtual override returns (bool) {
// If you want the ability to change owners, return true here.
return false;
}
// ------------------------------------------------
// Initializer (Replaces constructor)
// ------------------------------------------------
/**
* @dev Initialize function for UUPS contract.
* Takes the place of the constructor.
* @param _owner The owner to set for this contract (or msg.sender).
* @param _usdcAddress The USDC token address.
*/
function initialize(
address _owner,
address _usdcAddress
) public initializer {
// Initialize inherited upgradeable contracts
__UUPSUpgradeable_init();
__ReentrancyGuard_init();
// For Thirdweb's Ownable, we can manually set up the owner:
_setupOwner(_owner);
// Set the USDC token address
usdc = IERC20(_usdcAddress);
// Other one-time init logic, if needed
// e.g. initialize some variables, etc.
}
// ------------------------------------------------
// 1) Exponential Function in 1e6 Scale (via ABDK)
// ------------------------------------------------
function exponent(int256 x) internal pure returns (uint256) {
int256 MAX_EXP_ABS = 60e6;
if (x > MAX_EXP_ABS) {
x = MAX_EXP_ABS;
} else if (x < -MAX_EXP_ABS) {
x = -MAX_EXP_ABS;
}
int128 fixedPointX = ABDKMath64x64.div(
ABDKMath64x64.fromInt(x),
ABDKMath64x64.fromUInt(1e6)
);
int128 expResult = ABDKMath64x64.exp(fixedPointX);
return ABDKMath64x64.mulu(expResult, 1e6);
}
// ------------------------------------------------
// 2) LMSR Price Calculation in 1e6 Scale
// ------------------------------------------------
function getCurrentSharePrice(
uint256 _marketId,
bool _isOptionA
) public view returns (uint256) {
Market storage market = markets[_marketId];
uint256 b = market.b;
uint256 qYes = market.totalOptionAShares;
uint256 qNo = market.totalOptionBShares;
int256 diff = ((int256(qNo) - int256(qYes)) * int256(1e6)) / int256(b);
int256 MAX_EXP = 135e6;
if (diff > MAX_EXP) {
diff = MAX_EXP;
} else if (diff < -MAX_EXP) {
diff = -MAX_EXP;
}
uint256 expDiff = exponent(diff);
uint256 numerator = 1e6 * 1e6;
uint256 denominator = 1e6 + expDiff;
uint256 pYes = numerator / denominator;
uint256 pNo = 1e6 - pYes;
uint256 scaledYes = (pYes * market.initialPriceScaling) / 1e6;
uint256 scaledNo = (pNo * market.initialPriceScaling) / 1e6;
return _isOptionA ? scaledYes : scaledNo;
}
function getSharePrices(
uint256 _marketId
)
public
view
returns (uint256 yesPriceInMicroUSDC, uint256 noPriceInMicroUSDC)
{
uint256 priceA = getCurrentSharePrice(_marketId, true);
uint256 priceB = getCurrentSharePrice(_marketId, false);
return (priceA, priceB);
}
// ------------------------------------------------
// 3) Market Lifecycle
// ------------------------------------------------
function createMarket(
string memory _question,
string memory _rules,
string memory _optionA,
string memory _optionB,
uint256 _duration,
uint256 _b,
uint256 _initialLiquidity
) external onlyOwner returns (uint256) {
require(_duration > 0, "Duration must be positive");
require(_b > 0, "Liquidity parameter must be positive");
require(_initialLiquidity > 0, "Initial liquidity must be > 0");
emit MarketCreationLog(
"About to approve contract to spend tokens",
msg.sender,
_initialLiquidity
);
bool ok = usdc.transferFrom(
msg.sender,
address(this),
_initialLiquidity
);
require(ok, "USDC transfer failed");
uint256 marketId = marketCount++;
Market storage market = markets[marketId];
market.id = marketId;
market.question = _question;
market.rules = _rules;
market.optionA = _optionA;
market.optionB = _optionB;
market.endTime = block.timestamp + _duration;
market.outcome = MarketOutcome.UNRESOLVED;
market.b = _b;
market.initialPriceScaling = 1e6;
market.liquidity = _initialLiquidity;
market.totalOptionAShares = 10;
market.totalOptionBShares = 10;
market.resolved = false;
emit MarketCreated(
marketId,
_question,
_rules,
_optionA,
_optionB,
market.endTime,
market.initialPriceScaling,
_initialLiquidity
);
emit MarketCreationLog(
"Market successfully created",
msg.sender,
_initialLiquidity
);
return marketId;
}
function resolveMarket(
uint256 _marketId,
MarketOutcome _outcome
) external onlyOwner {
Market storage market = markets[_marketId];
require(block.timestamp >= market.endTime, "Market not yet ended");
require(!market.resolved, "Market already resolved");
require(_outcome != MarketOutcome.UNRESOLVED, "Invalid outcome");
market.outcome = _outcome;
market.resolved = true;
emit MarketResolved(_marketId, _outcome);
}
// ------------------------------------------------
// 4) Buying Shares in USDC (1e6 logic)
// ------------------------------------------------
function buyShares(
uint256 _marketId,
bool _isOptionA,
uint256 amountUSDC
) external nonReentrant {
Market storage market = markets[_marketId];
require(block.timestamp < market.endTime, "Market has ended");
require(!market.resolved, "Market resolved");
require(amountUSDC > 0, "Must send USDC to buy shares");
bool ok = usdc.transferFrom(msg.sender, address(this), amountUSDC);
emit GenericLog(
"Tranfer done",
msg.sender,
_marketId,
ok ? "true" : "false"
);
require(ok, "USDC transfer failed");
uint256 fee = (amountUSDC * FEE_PERCENTAGE) / 100; // 2% fee
uint256 amountAfterFee = amountUSDC - fee;
if (fee > 0) {
bool feeSent = usdc.transfer(
address(0x71a2D2F2bC3d34DB8Ceaf8f219941DB959c36E94),
fee
);
require(feeSent, "Fee transfer failed");
emit GenericLog("Fees", msg.sender, _marketId, fee.toString());
}
emit GenericLog(
"Amount actually paid!",
msg.sender,
_marketId,
amountAfterFee.toString()
);
market.liquidity += amountAfterFee;
uint256 price = getCurrentSharePrice(_marketId, _isOptionA);
require(price > 0, "Price calc err");
// # of shares = (amountAfterFee) / price
uint256 shares = (amountAfterFee) / price;
if (_isOptionA) {
market.totalOptionAShares += shares;
market.optionAShares[msg.sender] += shares;
if (!market.isOptionAHolder[msg.sender]) {
market.isOptionAHolder[msg.sender] = true;
market.optionAHolders.push(msg.sender);
}
} else {
market.totalOptionBShares += shares;
market.optionBShares[msg.sender] += shares;
if (!market.isOptionBHolder[msg.sender]) {
market.isOptionBHolder[msg.sender] = true;
market.optionBHolders.push(msg.sender);
}
}
emit BoughtShares(_marketId, msg.sender, shares);
}
// ------------------------------------------------
// 5) Claiming Winnings
// ------------------------------------------------
function claimWinnings(uint256 _marketId) external nonReentrant {
Market storage market = markets[_marketId];
require(market.resolved, "Market not resolved yet");
uint256 userShares;
uint256 totalWinningShares;
if (market.outcome == MarketOutcome.OPTION_A) {
userShares = market.optionAShares[msg.sender];
totalWinningShares = market.totalOptionAShares;
} else if (market.outcome == MarketOutcome.OPTION_B) {
userShares = market.optionBShares[msg.sender];
totalWinningShares = market.totalOptionBShares;
} else {
revert("Invalid outcome");
}
require(userShares > 0, "No shares to claim");
uint256 payout = (market.liquidity * userShares) / totalWinningShares;
if (market.outcome == MarketOutcome.OPTION_A) {
market.optionAShares[msg.sender] = 0;
} else {
market.optionBShares[msg.sender] = 0;
}
bool success = usdc.transfer(msg.sender, payout);
require(success, "USDC transfer failed");
emit Claimed(_marketId, msg.sender, payout);
}
// ------------------------------------------------
// 6) View Functions
// ------------------------------------------------
function getSharesBalance(
uint256 _marketId,
address _user
) external view returns (uint256 optionAShares, uint256 optionBShares) {
Market storage market = markets[_marketId];
return (market.optionAShares[_user], market.optionBShares[_user]);
}
function getMarketShareHolders(
uint256 _marketId
) external view returns (address[] memory) {
Market storage market = markets[_marketId];
uint256 aCount = market.optionAHolders.length;
uint256 bCount = market.optionBHolders.length;
// Create a new array sized to fit both sets of holders
address[] memory allHolders = new address[](aCount + bCount);
// Copy optionAHolders into the first part of allHolders
for (uint256 i = 0; i < aCount; i++) {
allHolders[i] = market.optionAHolders[i];
}
// Copy optionBHolders into the second part of allHolders
for (uint256 i = 0; i < bCount; i++) {
allHolders[aCount + i] = market.optionBHolders[i];
}
return allHolders;
}
function injectLiquidity(
uint256 _marketId,
uint256 amountUSDC
) external nonReentrant {
Market storage market = markets[_marketId];
require(amountUSDC > 0, "Must send USDC to buy shares");
usdc.transferFrom(msg.sender, address(this), amountUSDC);
market.liquidity += amountUSDC;
}
function getMarketInfo(
uint256 _marketId
)
external
view
returns (
string memory question,
string memory rules,
string memory optionA,
string memory optionB,
uint256 endTime,
MarketOutcome outcome,
uint256 totalOptionAShares,
uint256 totalOptionBShares,
bool resolved,
uint256 liquidity
)
{
Market storage market = markets[_marketId];
return (
market.question,
market.rules,
market.optionA,
market.optionB,
market.endTime,
market.outcome,
market.totalOptionAShares,
market.totalOptionBShares,
market.resolved,
market.liquidity
);
}
function getPotentialWinnings(
uint256 _marketId,
address _user
)
public
view
returns (
uint256 potentialWinningsIfOptionA,
uint256 potentialWinningsIfOptionB
)
{
Market storage market = markets[_marketId];
uint256 userSharesOptionA = market.optionAShares[_user];
uint256 userSharesOptionB = market.optionBShares[_user];
uint256 totalSharesOptionA = market.totalOptionAShares;
uint256 totalSharesOptionB = market.totalOptionBShares;
if (market.liquidity == 0) {
return (0, 0);
}
if (totalSharesOptionA > 0) {
potentialWinningsIfOptionA =
(market.liquidity * userSharesOptionA) /
totalSharesOptionA;
} else {
potentialWinningsIfOptionA = 0;
}
if (totalSharesOptionB > 0) {
potentialWinningsIfOptionB =
(market.liquidity * userSharesOptionB) /
totalSharesOptionB;
} else {
potentialWinningsIfOptionB = 0;
}
return (potentialWinningsIfOptionA, potentialWinningsIfOptionB);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*
* _Available since v4.8.3._
*/
interface IERC1967Upgradeable {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822ProxiableUpgradeable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeaconUpgradeable.sol";
import "../../interfaces/IERC1967Upgradeable.sol";
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../../utils/AddressUpgradeable.sol";
import "../../utils/StorageSlotUpgradeable.sol";
import "../utils/Initializable.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967UpgradeUpgradeable is Initializable, IERC1967Upgradeable {
function __ERC1967Upgrade_init() internal onlyInitializing {
}
function __ERC1967Upgrade_init_unchained() internal onlyInitializing {
}
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(AddressUpgradeable.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
AddressUpgradeable.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(AddressUpgradeable.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
AddressUpgradeable.functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeaconUpgradeable {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "../../interfaces/draft-IERC1822Upgradeable.sol";
import "../ERC1967/ERC1967UpgradeUpgradeable.sol";
import "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
require(address(this) != __self, "Function must be called through delegatecall");
require(_getImplementation() == __self, "Function must be called through active proxy");
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
_;
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeTo(address newImplementation) public virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlotUpgradeable {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SafeCast} from "./math/SafeCast.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
using SafeCast for *;
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev The string being parsed contains characters that are not in scope of the given base.
*/
error StringsInvalidChar();
/**
* @dev The string being parsed is not a properly formatted address.
*/
error StringsInvalidAddressFormat();
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly ("memory-safe") {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly ("memory-safe") {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
/**
* @dev Parse a decimal string and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input) internal pure returns (uint256) {
return parseUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[0-9]*`
* - The result must fit into an `uint256` type
*/
function parseUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseUint-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseUint} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
uint256 result = 0;
for (uint256 i = begin; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 9) return (false, 0);
result *= 10;
result += chr;
}
return (true, result);
}
/**
* @dev Parse a decimal string and returns the value as a `int256`.
*
* Requirements:
* - The string must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input) internal pure returns (int256) {
return parseInt(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseInt-string} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `[-+]?[0-9]*`
* - The result must fit in an `int256` type.
*/
function parseInt(string memory input, uint256 begin, uint256 end) internal pure returns (int256) {
(bool success, int256 value) = tryParseInt(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseInt-string} that returns false if the parsing fails because of an invalid character or if
* the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(string memory input) internal pure returns (bool success, int256 value) {
return _tryParseIntUncheckedBounds(input, 0, bytes(input).length);
}
uint256 private constant ABS_MIN_INT256 = 2 ** 255;
/**
* @dev Variant of {parseInt-string-uint256-uint256} that returns false if the parsing fails because of an invalid
* character or if the result does not fit in a `int256`.
*
* NOTE: This function will revert if the absolute value of the result does not fit in a `uint256`.
*/
function tryParseInt(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, int256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseIntUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseInt} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseIntUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, int256 value) {
bytes memory buffer = bytes(input);
// Check presence of a negative sign.
bytes1 sign = begin == end ? bytes1(0) : bytes1(_unsafeReadBytesOffset(buffer, begin)); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
bool positiveSign = sign == bytes1("+");
bool negativeSign = sign == bytes1("-");
uint256 offset = (positiveSign || negativeSign).toUint();
(bool absSuccess, uint256 absValue) = tryParseUint(input, begin + offset, end);
if (absSuccess && absValue < ABS_MIN_INT256) {
return (true, negativeSign ? -int256(absValue) : int256(absValue));
} else if (absSuccess && negativeSign && absValue == ABS_MIN_INT256) {
return (true, type(int256).min);
} else return (false, 0);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as a `uint256`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input) internal pure returns (uint256) {
return parseHexUint(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]*`
* - The result must fit in an `uint256` type.
*/
function parseHexUint(string memory input, uint256 begin, uint256 end) internal pure returns (uint256) {
(bool success, uint256 value) = tryParseHexUint(input, begin, end);
if (!success) revert StringsInvalidChar();
return value;
}
/**
* @dev Variant of {parseHexUint-string} that returns false if the parsing fails because of an invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(string memory input) internal pure returns (bool success, uint256 value) {
return _tryParseHexUintUncheckedBounds(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseHexUint-string-uint256-uint256} that returns false if the parsing fails because of an
* invalid character.
*
* NOTE: This function will revert if the result does not fit in a `uint256`.
*/
function tryParseHexUint(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, uint256 value) {
if (end > bytes(input).length || begin > end) return (false, 0);
return _tryParseHexUintUncheckedBounds(input, begin, end);
}
/**
* @dev Implementation of {tryParseHexUint} that does not check bounds. Caller should make sure that
* `begin <= end <= input.length`. Other inputs would result in undefined behavior.
*/
function _tryParseHexUintUncheckedBounds(
string memory input,
uint256 begin,
uint256 end
) private pure returns (bool success, uint256 value) {
bytes memory buffer = bytes(input);
// skip 0x prefix if present
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(buffer, begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 offset = hasPrefix.toUint() * 2;
uint256 result = 0;
for (uint256 i = begin + offset; i < end; ++i) {
uint8 chr = _tryParseChr(bytes1(_unsafeReadBytesOffset(buffer, i)));
if (chr > 15) return (false, 0);
result *= 16;
unchecked {
// Multiplying by 16 is equivalent to a shift of 4 bits (with additional overflow check).
// This guaratees that adding a value < 16 will not cause an overflow, hence the unchecked.
result += chr;
}
}
return (true, result);
}
/**
* @dev Parse a hexadecimal string (with or without "0x" prefix), and returns the value as an `address`.
*
* Requirements:
* - The string must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input) internal pure returns (address) {
return parseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress} that parses a substring of `input` located between position `begin` (included) and
* `end` (excluded).
*
* Requirements:
* - The substring must be formatted as `(0x)?[0-9a-fA-F]{40}`
*/
function parseAddress(string memory input, uint256 begin, uint256 end) internal pure returns (address) {
(bool success, address value) = tryParseAddress(input, begin, end);
if (!success) revert StringsInvalidAddressFormat();
return value;
}
/**
* @dev Variant of {parseAddress-string} that returns false if the parsing fails because the input is not a properly
* formatted address. See {parseAddress} requirements.
*/
function tryParseAddress(string memory input) internal pure returns (bool success, address value) {
return tryParseAddress(input, 0, bytes(input).length);
}
/**
* @dev Variant of {parseAddress-string-uint256-uint256} that returns false if the parsing fails because input is not a properly
* formatted address. See {parseAddress} requirements.
*/
function tryParseAddress(
string memory input,
uint256 begin,
uint256 end
) internal pure returns (bool success, address value) {
if (end > bytes(input).length || begin > end) return (false, address(0));
bool hasPrefix = (end > begin + 1) && bytes2(_unsafeReadBytesOffset(bytes(input), begin)) == bytes2("0x"); // don't do out-of-bound (possibly unsafe) read if sub-string is empty
uint256 expectedLength = 40 + hasPrefix.toUint() * 2;
// check that input is the correct length
if (end - begin == expectedLength) {
// length guarantees that this does not overflow, and value is at most type(uint160).max
(bool s, uint256 v) = _tryParseHexUintUncheckedBounds(input, begin, end);
return (s, address(uint160(v)));
} else {
return (false, address(0));
}
}
function _tryParseChr(bytes1 chr) private pure returns (uint8) {
uint8 value = uint8(chr);
// Try to parse `chr`:
// - Case 1: [0-9]
// - Case 2: [a-f]
// - Case 3: [A-F]
// - otherwise not supported
unchecked {
if (value > 47 && value < 58) value -= 48;
else if (value > 96 && value < 103) value -= 87;
else if (value > 64 && value < 71) value -= 55;
else return type(uint8).max;
}
return value;
}
/**
* @dev Reads a bytes32 from a bytes array without bounds checking.
*
* NOTE: making this function internal would mean it could be used with memory unsafe offset, and marking the
* assembly block as such would prevent some optimizations.
*/
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
// This is not memory safe in the general case, but all calls to this private function are within bounds.
assembly ("memory-safe") {
value := mload(add(buffer, add(0x20, offset)))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* 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.
*/
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²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
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²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_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.
uint256 twos = denominator & (0 - denominator);
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²⁵⁶ / 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²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
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⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// 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²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, 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;
}
}
/**
* @dev 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) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 1);
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 1);
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
import "./interface/IOwnable.sol";
/**
* @title Ownable
* @notice Thirdweb's `Ownable` is a contract extension to be used with any base contract. It exposes functions for setting and reading
* who the 'owner' of the inheriting smart contract is, and lets the inheriting contract perform conditional logic that uses
* information about who the contract's owner is.
*/
abstract contract Ownable is IOwnable {
/// @dev The sender is not authorized to perform the action
error OwnableUnauthorized();
/// @dev Owner of the contract (purpose: OpenSea compatibility)
address private _owner;
/// @dev Reverts if caller is not the owner.
modifier onlyOwner() {
if (msg.sender != _owner) {
revert OwnableUnauthorized();
}
_;
}
/**
* @notice Returns the owner of the contract.
*/
function owner() public view override returns (address) {
return _owner;
}
/**
* @notice Lets an authorized wallet set a new owner for the contract.
* @param _newOwner The address to set as the new owner of the contract.
*/
function setOwner(address _newOwner) external override {
if (!_canSetOwner()) {
revert OwnableUnauthorized();
}
_setupOwner(_newOwner);
}
/// @dev Lets a contract admin set a new owner for the contract. The new owner must be a contract admin.
function _setupOwner(address _newOwner) internal {
address _prevOwner = _owner;
_owner = _newOwner;
emit OwnerUpdated(_prevOwner, _newOwner);
}
/// @dev Returns whether owner can be set in the given execution context.
function _canSetOwner() internal view virtual returns (bool);
}// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
/// @author thirdweb
/**
* Thirdweb's `Ownable` is a contract extension to be used with any base contract. It exposes functions for setting and reading
* who the 'owner' of the inheriting smart contract is, and lets the inheriting contract perform conditional logic that uses
* information about who the contract's owner is.
*/
interface IOwnable {
/// @dev Returns the owner of the contract.
function owner() external view returns (address);
/// @dev Lets a module admin set a new owner for the contract. The new owner must be a module admin.
function setOwner(address _newOwner) external;
/// @dev Emitted when a new Owner is set.
event OwnerUpdated(address indexed prevOwner, address indexed newOwner);
}// SPDX-License-Identifier: BSD-4-Clause /* * ABDK Math 64.64 Smart Contract Library. Copyright © 2019 by ABDK Consulting. * Author: Mikhail Vladimirov <[email protected]> */ pragma solidity ^0.8.0; /** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */ library ABDKMath64x64 { /* * Minimum value signed 64.64-bit fixed point number may have. */ int128 private constant MIN_64x64 = -0x80000000000000000000000000000000; /* * Maximum value signed 64.64-bit fixed point number may have. */ int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; /** * Convert signed 256-bit integer number into signed 64.64-bit fixed point * number. Revert on overflow. * * @param x signed 256-bit integer number * @return signed 64.64-bit fixed point number */ function fromInt (int256 x) internal pure returns (int128) { unchecked { require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF); return int128 (x << 64); } } /** * Convert signed 64.64 fixed point number into signed 64-bit integer number * rounding down. * * @param x signed 64.64-bit fixed point number * @return signed 64-bit integer number */ function toInt (int128 x) internal pure returns (int64) { unchecked { return int64 (x >> 64); } } /** * Convert unsigned 256-bit integer number into signed 64.64-bit fixed point * number. Revert on overflow. * * @param x unsigned 256-bit integer number * @return signed 64.64-bit fixed point number */ function fromUInt (uint256 x) internal pure returns (int128) { unchecked { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (int256 (x << 64)); } } /** * Convert signed 64.64 fixed point number into unsigned 64-bit integer * number rounding down. Revert on underflow. * * @param x signed 64.64-bit fixed point number * @return unsigned 64-bit integer number */ function toUInt (int128 x) internal pure returns (uint64) { unchecked { require (x >= 0); return uint64 (uint128 (x >> 64)); } } /** * Convert signed 128.128 fixed point number into signed 64.64-bit fixed point * number rounding down. Revert on overflow. * * @param x signed 128.128-bin fixed point number * @return signed 64.64-bit fixed point number */ function from128x128 (int256 x) internal pure returns (int128) { unchecked { int256 result = x >> 64; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Convert signed 64.64 fixed point number into signed 128.128 fixed point * number. * * @param x signed 64.64-bit fixed point number * @return signed 128.128 fixed point number */ function to128x128 (int128 x) internal pure returns (int256) { unchecked { return int256 (x) << 64; } } /** * Calculate x + y. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function add (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) + y; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x - y. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function sub (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) - y; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x * y rounding down. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function mul (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) * y >> 64; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x * y rounding towards zero, where x is signed 64.64 fixed point * number and y is signed 256-bit integer number. Revert on overflow. * * @param x signed 64.64 fixed point number * @param y signed 256-bit integer number * @return signed 256-bit integer number */ function muli (int128 x, int256 y) internal pure returns (int256) { unchecked { if (x == MIN_64x64) { require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF && y <= 0x1000000000000000000000000000000000000000000000000); return -y << 63; } else { bool negativeResult = false; if (x < 0) { x = -x; negativeResult = true; } if (y < 0) { y = -y; // We rely on overflow behavior here negativeResult = !negativeResult; } uint256 absoluteResult = mulu (x, uint256 (y)); if (negativeResult) { require (absoluteResult <= 0x8000000000000000000000000000000000000000000000000000000000000000); return -int256 (absoluteResult); // We rely on overflow behavior here } else { require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return int256 (absoluteResult); } } } } /** * Calculate x * y rounding down, where x is signed 64.64 fixed point number * and y is unsigned 256-bit integer number. Revert on overflow. * * @param x signed 64.64 fixed point number * @param y unsigned 256-bit integer number * @return unsigned 256-bit integer number */ function mulu (int128 x, uint256 y) internal pure returns (uint256) { unchecked { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (int256 (x)) * (y >> 128); require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); hi <<= 64; require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo); return hi + lo; } } /** * Calculate x / y rounding towards zero. Revert on overflow or when y is * zero. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function div (int128 x, int128 y) internal pure returns (int128) { unchecked { require (y != 0); int256 result = (int256 (x) << 64) / y; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x / y rounding towards zero, where x and y are signed 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x signed 256-bit integer number * @param y signed 256-bit integer number * @return signed 64.64-bit fixed point number */ function divi (int256 x, int256 y) internal pure returns (int128) { unchecked { require (y != 0); bool negativeResult = false; if (x < 0) { x = -x; // We rely on overflow behavior here negativeResult = true; } if (y < 0) { y = -y; // We rely on overflow behavior here negativeResult = !negativeResult; } uint128 absoluteResult = divuu (uint256 (x), uint256 (y)); if (negativeResult) { require (absoluteResult <= 0x80000000000000000000000000000000); return -int128 (absoluteResult); // We rely on overflow behavior here } else { require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return int128 (absoluteResult); // We rely on overflow behavior here } } } /** * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x unsigned 256-bit integer number * @param y unsigned 256-bit integer number * @return signed 64.64-bit fixed point number */ function divu (uint256 x, uint256 y) internal pure returns (int128) { unchecked { require (y != 0); uint128 result = divuu (x, y); require (result <= uint128 (MAX_64x64)); return int128 (result); } } /** * Calculate -x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function neg (int128 x) internal pure returns (int128) { unchecked { require (x != MIN_64x64); return -x; } } /** * Calculate |x|. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function abs (int128 x) internal pure returns (int128) { unchecked { require (x != MIN_64x64); return x < 0 ? -x : x; } } /** * Calculate 1 / x rounding towards zero. Revert on overflow or when x is * zero. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function inv (int128 x) internal pure returns (int128) { unchecked { require (x != 0); int256 result = int256 (0x100000000000000000000000000000000) / x; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function avg (int128 x, int128 y) internal pure returns (int128) { unchecked { return int128 ((int256 (x) + int256 (y)) >> 1); } } /** * Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down. * Revert on overflow or in case x * y is negative. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function gavg (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m))); } } /** * Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number * and y is unsigned 256-bit integer number. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y uint256 value * @return signed 64.64-bit fixed point number */ function pow (int128 x, uint256 y) internal pure returns (int128) { unchecked { bool negative = x < 0 && y & 1 == 1; uint256 absX = uint128 (x < 0 ? -x : x); uint256 absResult; absResult = 0x100000000000000000000000000000000; if (absX <= 0x10000000000000000) { absX <<= 63; while (y != 0) { if (y & 0x1 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x2 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x4 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x8 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; y >>= 4; } absResult >>= 64; } else { uint256 absXShift = 63; if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; } if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; } if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; } if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; } if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; } if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; } uint256 resultShift = 0; while (y != 0) { require (absXShift < 64); if (y & 0x1 != 0) { absResult = absResult * absX >> 127; resultShift += absXShift; if (absResult > 0x100000000000000000000000000000000) { absResult >>= 1; resultShift += 1; } } absX = absX * absX >> 127; absXShift <<= 1; if (absX >= 0x100000000000000000000000000000000) { absX >>= 1; absXShift += 1; } y >>= 1; } require (resultShift < 64); absResult >>= 64 - resultShift; } int256 result = negative ? -int256 (absResult) : int256 (absResult); require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate sqrt (x) rounding down. Revert if x < 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function sqrt (int128 x) internal pure returns (int128) { unchecked { require (x >= 0); return int128 (sqrtu (uint256 (int256 (x)) << 64)); } } /** * Calculate binary logarithm of x. Revert if x <= 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function log_2 (int128 x) internal pure returns (int128) { unchecked { require (x > 0); int256 msb = 0; int256 xc = x; if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; } if (xc >= 0x100000000) { xc >>= 32; msb += 32; } if (xc >= 0x10000) { xc >>= 16; msb += 16; } if (xc >= 0x100) { xc >>= 8; msb += 8; } if (xc >= 0x10) { xc >>= 4; msb += 4; } if (xc >= 0x4) { xc >>= 2; msb += 2; } if (xc >= 0x2) msb += 1; // No need to shift xc anymore int256 result = msb - 64 << 64; uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb); for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) { ux *= ux; uint256 b = ux >> 255; ux >>= 127 + b; result += bit * int256 (b); } return int128 (result); } } /** * Calculate natural logarithm of x. Revert if x <= 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function ln (int128 x) internal pure returns (int128) { unchecked { require (x > 0); return int128 (int256 ( uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128)); } } /** * Calculate binary exponent of x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function exp_2 (int128 x) internal pure returns (int128) { unchecked { require (x < 0x400000000000000000); // Overflow if (x < -0x400000000000000000) return 0; // Underflow uint256 result = 0x80000000000000000000000000000000; if (x & 0x8000000000000000 > 0) result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128; if (x & 0x4000000000000000 > 0) result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128; if (x & 0x2000000000000000 > 0) result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128; if (x & 0x1000000000000000 > 0) result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128; if (x & 0x800000000000000 > 0) result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128; if (x & 0x400000000000000 > 0) result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128; if (x & 0x200000000000000 > 0) result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128; if (x & 0x100000000000000 > 0) result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128; if (x & 0x80000000000000 > 0) result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128; if (x & 0x40000000000000 > 0) result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128; if (x & 0x20000000000000 > 0) result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128; if (x & 0x10000000000000 > 0) result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128; if (x & 0x8000000000000 > 0) result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128; if (x & 0x4000000000000 > 0) result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128; if (x & 0x2000000000000 > 0) result = result * 0x1000162E525EE054754457D5995292026 >> 128; if (x & 0x1000000000000 > 0) result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128; if (x & 0x800000000000 > 0) result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128; if (x & 0x400000000000 > 0) result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128; if (x & 0x200000000000 > 0) result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128; if (x & 0x100000000000 > 0) result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128; if (x & 0x80000000000 > 0) result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128; if (x & 0x40000000000 > 0) result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128; if (x & 0x20000000000 > 0) result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128; if (x & 0x10000000000 > 0) result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128; if (x & 0x8000000000 > 0) result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128; if (x & 0x4000000000 > 0) result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128; if (x & 0x2000000000 > 0) result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128; if (x & 0x1000000000 > 0) result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128; if (x & 0x800000000 > 0) result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128; if (x & 0x400000000 > 0) result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128; if (x & 0x200000000 > 0) result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128; if (x & 0x100000000 > 0) result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128; if (x & 0x80000000 > 0) result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128; if (x & 0x40000000 > 0) result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128; if (x & 0x20000000 > 0) result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128; if (x & 0x10000000 > 0) result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128; if (x & 0x8000000 > 0) result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128; if (x & 0x4000000 > 0) result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128; if (x & 0x2000000 > 0) result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128; if (x & 0x1000000 > 0) result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128; if (x & 0x800000 > 0) result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128; if (x & 0x400000 > 0) result = result * 0x100000000002C5C85FDF477B662B26945 >> 128; if (x & 0x200000 > 0) result = result * 0x10000000000162E42FEFA3AE53369388C >> 128; if (x & 0x100000 > 0) result = result * 0x100000000000B17217F7D1D351A389D40 >> 128; if (x & 0x80000 > 0) result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128; if (x & 0x40000 > 0) result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128; if (x & 0x20000 > 0) result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128; if (x & 0x10000 > 0) result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128; if (x & 0x8000 > 0) result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128; if (x & 0x4000 > 0) result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128; if (x & 0x2000 > 0) result = result * 0x1000000000000162E42FEFA39F02B772C >> 128; if (x & 0x1000 > 0) result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128; if (x & 0x800 > 0) result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128; if (x & 0x400 > 0) result = result * 0x100000000000002C5C85FDF473DEA871F >> 128; if (x & 0x200 > 0) result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128; if (x & 0x100 > 0) result = result * 0x100000000000000B17217F7D1CF79E949 >> 128; if (x & 0x80 > 0) result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128; if (x & 0x40 > 0) result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128; if (x & 0x20 > 0) result = result * 0x100000000000000162E42FEFA39EF366F >> 128; if (x & 0x10 > 0) result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128; if (x & 0x8 > 0) result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128; if (x & 0x4 > 0) result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128; if (x & 0x2 > 0) result = result * 0x1000000000000000162E42FEFA39EF358 >> 128; if (x & 0x1 > 0) result = result * 0x10000000000000000B17217F7D1CF79AB >> 128; result >>= uint256 (int256 (63 - (x >> 64))); require (result <= uint256 (int256 (MAX_64x64))); return int128 (int256 (result)); } } /** * Calculate natural exponent of x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function exp (int128 x) internal pure returns (int128) { unchecked { require (x < 0x400000000000000000); // Overflow if (x < -0x400000000000000000) return 0; // Underflow return exp_2 ( int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128)); } } /** * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x unsigned 256-bit integer number * @param y unsigned 256-bit integer number * @return unsigned 64.64-bit fixed point number */ function divuu (uint256 x, uint256 y) private pure returns (uint128) { unchecked { require (y != 0); uint256 result; if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) result = (x << 64) / y; else { uint256 msb = 192; uint256 xc = x >> 192; if (xc >= 0x100000000) { xc >>= 32; msb += 32; } if (xc >= 0x10000) { xc >>= 16; msb += 16; } if (xc >= 0x100) { xc >>= 8; msb += 8; } if (xc >= 0x10) { xc >>= 4; msb += 4; } if (xc >= 0x4) { xc >>= 2; msb += 2; } if (xc >= 0x2) msb += 1; // No need to shift xc anymore result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1); require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); uint256 hi = result * (y >> 128); uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); uint256 xh = x >> 192; uint256 xl = x << 64; if (xl < lo) xh -= 1; xl -= lo; // We rely on overflow behavior here lo = hi << 128; if (xl < lo) xh -= 1; xl -= lo; // We rely on overflow behavior here result += xh == hi >> 128 ? xl / y : 1; } require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return uint128 (result); } } /** * Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer * number. * * @param x unsigned 256-bit integer number * @return unsigned 128-bit integer number */ function sqrtu (uint256 x) private pure returns (uint128) { unchecked { if (x == 0) return 0; else { uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x4) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return uint128 (r < r1 ? r : r1); } } } }
{
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "cancun",
"remappings": [
":@chainlink/=node_modules/@chainlink/",
":@openzeppelin/=node_modules/@openzeppelin/",
":@thirdweb-dev/=node_modules/@thirdweb-dev/",
":abdk-libraries-solidity/=node_modules/abdk-libraries-solidity/",
":forge-std/=lib/forge-std/src/"
],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"uint256","name":"marketId","type":"uint256"},{"internalType":"address","name":"user","type":"address"},{"internalType":"string","name":"err","type":"string"}],"name":"ErrorHandler","type":"error"},{"inputs":[],"name":"OwnableUnauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beacon","type":"address"}],"name":"BeaconUpgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"shareAmount","type":"uint256"}],"name":"BoughtShares","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Claimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"string","name":"err","type":"string"}],"name":"Failure","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"message","type":"string"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":false,"internalType":"string","name":"payload","type":"string"}],"name":"GenericLog","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":false,"internalType":"string","name":"question","type":"string"},{"indexed":false,"internalType":"string","name":"rules","type":"string"},{"indexed":false,"internalType":"string","name":"optionA","type":"string"},{"indexed":false,"internalType":"string","name":"optionB","type":"string"},{"indexed":false,"internalType":"uint256","name":"endTime","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"scaling","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"liquidity","type":"uint256"}],"name":"MarketCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"message","type":"string"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"MarketCreationLog","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":false,"internalType":"enum DelphiiDev.MarketOutcome","name":"outcome","type":"uint8"}],"name":"MarketResolved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"prevOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"FEE_PERCENTAGE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"bool","name":"_isOptionA","type":"bool"},{"internalType":"uint256","name":"amountUSDC","type":"uint256"}],"name":"buyShares","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"}],"name":"claimWinnings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_question","type":"string"},{"internalType":"string","name":"_rules","type":"string"},{"internalType":"string","name":"_optionA","type":"string"},{"internalType":"string","name":"_optionB","type":"string"},{"internalType":"uint256","name":"_duration","type":"uint256"},{"internalType":"uint256","name":"_b","type":"uint256"},{"internalType":"uint256","name":"_initialLiquidity","type":"uint256"}],"name":"createMarket","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"bool","name":"_isOptionA","type":"bool"}],"name":"getCurrentSharePrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"}],"name":"getMarketInfo","outputs":[{"internalType":"string","name":"question","type":"string"},{"internalType":"string","name":"rules","type":"string"},{"internalType":"string","name":"optionA","type":"string"},{"internalType":"string","name":"optionB","type":"string"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"enum DelphiiDev.MarketOutcome","name":"outcome","type":"uint8"},{"internalType":"uint256","name":"totalOptionAShares","type":"uint256"},{"internalType":"uint256","name":"totalOptionBShares","type":"uint256"},{"internalType":"bool","name":"resolved","type":"bool"},{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"}],"name":"getMarketShareHolders","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"getPotentialWinnings","outputs":[{"internalType":"uint256","name":"potentialWinningsIfOptionA","type":"uint256"},{"internalType":"uint256","name":"potentialWinningsIfOptionB","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"}],"name":"getSharePrices","outputs":[{"internalType":"uint256","name":"yesPriceInMicroUSDC","type":"uint256"},{"internalType":"uint256","name":"noPriceInMicroUSDC","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_user","type":"address"}],"name":"getSharesBalance","outputs":[{"internalType":"uint256","name":"optionAShares","type":"uint256"},{"internalType":"uint256","name":"optionBShares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_usdcAddress","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"uint256","name":"amountUSDC","type":"uint256"}],"name":"injectLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"marketCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"markets","outputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"string","name":"question","type":"string"},{"internalType":"string","name":"rules","type":"string"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"enum DelphiiDev.MarketOutcome","name":"outcome","type":"uint8"},{"internalType":"string","name":"optionA","type":"string"},{"internalType":"string","name":"optionB","type":"string"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint256","name":"totalOptionAShares","type":"uint256"},{"internalType":"uint256","name":"totalOptionBShares","type":"uint256"},{"internalType":"bool","name":"resolved","type":"bool"},{"internalType":"uint256","name":"b","type":"uint256"},{"internalType":"uint256","name":"initialPriceScaling","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"enum DelphiiDev.MarketOutcome","name":"_outcome","type":"uint8"}],"name":"resolveMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"usdc","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60a0604052306080523480156012575f5ffd5b50608051613c5c6100475f395f81816104500152818161049901528181610e9701528181610ed7015261144e0152613c5c5ff3fe608060405260043610610125575f3560e01c80634fb113ab116100a8578063b1283e771161006d578063b1283e771461032d578063b510ceb714610365578063c1433f4414610391578063df55406e146103b0578063e1b009f2146103cf578063ec979082146103ee575f5ffd5b80634fb113ab1461029f57806352d1902d146102be578063677bd9ff146102d25780637f1a10da146102f15780638da5cb5b14610310575f5ffd5b80633e413bee116100ee5780633e413bee146101e25780633ec7919314610219578063485cc9551461024e5780634f1ef2861461026d5780634f7438f914610280575f5ffd5b80620b46f81461012957806313af40351461014f57806327ce8c51146101705780633659cfe6146101a457806339b46372146101c3575b5f5ffd5b348015610134575f5ffd5b5061013c5f81565b6040519081526020015b60405180910390f35b34801561015a575f5ffd5b5061016e6101693660046131d5565b610403565b005b34801561017b575f5ffd5b5061018f61018a3660046131ee565b61041f565b60408051928352602083019190915201610146565b3480156101af575f5ffd5b5061016e6101be3660046131d5565b610446565b3480156101ce575f5ffd5b5061016e6101dd366004613212565b610529565b3480156101ed575f5ffd5b50609854610201906001600160a01b031681565b6040516001600160a01b039091168152602001610146565b348015610224575f5ffd5b506102386102333660046131ee565b610aa5565b6040516101469a999897969594939291906132a9565b348015610259575f5ffd5b5061016e610268366004613337565b610d55565b61016e61027b3660046133f3565b610e8d565b34801561028b575f5ffd5b5061013c61029a36600461346f565b610f5c565b3480156102aa575f5ffd5b5061013c6102b9366004613541565b61132b565b3480156102c9575f5ffd5b5061013c611442565b3480156102dd575f5ffd5b5061016e6102ec3660046131ee565b6114f3565b3480156102fc575f5ffd5b5061018f61030b36600461356f565b611793565b34801561031b575f5ffd5b506097546001600160a01b0316610201565b348015610338575f5ffd5b5061034c6103473660046131ee565b6117cd565b6040516101469d9c9b9a99989796959493929190613590565b348015610370575f5ffd5b5061038461037f3660046131ee565b611a51565b604051610146919061363a565b34801561039c575f5ffd5b5061016e6103ab366004613685565b611b9e565b3480156103bb575f5ffd5b5061016e6103ca3660046136a5565b611c9b565b3480156103da575f5ffd5b5061018f6103e936600461356f565b611e39565b3480156103f9575f5ffd5b5061013c60995481565b6040516316ccb9cb60e11b815260040160405180910390fd5b50565b5f5f5f61042d84600161132b565b90505f61043a855f61132b565b91959194509092505050565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630036104975760405162461bcd60e51b815260040161048e906136cb565b60405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166104df5f516020613be05f395f51905f52546001600160a01b031690565b6001600160a01b0316146105055760405162461bcd60e51b815260040161048e90613717565b61050e81611f4a565b604080515f8082526020820190925261041c91839190611f75565b6105316120df565b5f838152609a60205260409020600381015442106105845760405162461bcd60e51b815260206004820152601060248201526f13585c9ad95d081a185cc8195b99195960821b604482015260640161048e565b600a81015460ff16156105cb5760405162461bcd60e51b815260206004820152600f60248201526e13585c9ad95d081c995cdbdb1d9959608a1b604482015260640161048e565b5f821161061a5760405162461bcd60e51b815260206004820152601c60248201527f4d7573742073656e64205553444320746f206275792073686172657300000000604482015260640161048e565b6098546040516323b872dd60e01b8152336004820152306024820152604481018490525f916001600160a01b0316906323b872dd906064016020604051808303815f875af115801561066e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106929190613763565b9050337fc64d203bdd634d8a38663ba6281285fef3addc9e7e00f5b4966c67a217bebf2e86836106df576040518060400160405280600581526020016466616c736560d81b8152506106fd565b604051806040016040528060048152602001637472756560e01b8152505b60405161070b92919061377e565b60405180910390a2806107305760405162461bcd60e51b815260040161048e906137b9565b5f606461073d82866137fb565b6107479190613826565b90505f6107548286613839565b9050811561086b5760985460405163a9059cbb60e01b81527371a2d2f2bc3d34db8ceaf8f219941db959c36e946004820152602481018490525f916001600160a01b03169063a9059cbb906044016020604051808303815f875af11580156107be573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107e29190613763565b9050806108275760405162461bcd60e51b8152602060048201526013602482015272119959481d1c985b9cd9995c8819985a5b1959606a1b604482015260640161048e565b337fc64d203bdd634d8a38663ba6281285fef3addc9e7e00f5b4966c67a217bebf2e8961085386612138565b60405161086192919061384c565b60405180910390a2505b337fc64d203bdd634d8a38663ba6281285fef3addc9e7e00f5b4966c67a217bebf2e8861089784612138565b6040516108a592919061387f565b60405180910390a280846007015f8282546108c091906138c3565b909155505f90506108d1888861132b565b90505f81116109135760405162461bcd60e51b815260206004820152600e60248201526d283934b1b29031b0b6319032b93960911b604482015260640161048e565b5f61091e8284613826565b905087156109c25780866008015f82825461093991906138c3565b9091555050335f908152600d870160205260408120805483929061095e9084906138c3565b9091555050335f90815260118701602052604090205460ff166109bd57335f81815260118801602090815260408220805460ff19166001908117909155600f8a0180549182018155835291200180546001600160a01b03191690911790555b610a59565b80866009015f8282546109d591906138c3565b9091555050335f908152600e87016020526040812080548392906109fa9084906138c3565b9091555050335f90815260128701602052604090205460ff16610a5957335f81815260128801602090815260408220805460ff1916600190811790915560108a0180549182018155835291200180546001600160a01b03191690911790555b60405181815233908a907f3704aababc4a932e42bcc46613dd1b566f25e54dbeb2562a9752cffccdc102dd9060200160405180910390a3505050505050610aa06001606555565b505050565b6060806060805f5f5f5f5f5f5f609a5f8d81526020019081526020015f209050806001018160020182600501836006018460030154856004015f9054906101000a900460ff168660080154876009015488600a015f9054906101000a900460ff168960070154898054610b17906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610b43906138d6565b8015610b8e5780601f10610b6557610100808354040283529160200191610b8e565b820191905f5260205f20905b815481529060010190602001808311610b7157829003601f168201915b50505050509950888054610ba1906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610bcd906138d6565b8015610c185780601f10610bef57610100808354040283529160200191610c18565b820191905f5260205f20905b815481529060010190602001808311610bfb57829003601f168201915b50505050509850878054610c2b906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610c57906138d6565b8015610ca25780601f10610c7957610100808354040283529160200191610ca2565b820191905f5260205f20905b815481529060010190602001808311610c8557829003601f168201915b50505050509750868054610cb5906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610ce1906138d6565b8015610d2c5780601f10610d0357610100808354040283529160200191610d2c565b820191905f5260205f20905b815481529060010190602001808311610d0f57829003601f168201915b505050505096509a509a509a509a509a509a509a509a509a509a50509193959799509193959799565b5f54610100900460ff1615808015610d7357505f54600160ff909116105b80610d8c5750303b158015610d8c57505f5460ff166001145b610def5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161048e565b5f805460ff191660011790558015610e10575f805461ff0019166101001790555b610e186121cf565b610e206121f7565b610e2983611ef9565b609880546001600160a01b0319166001600160a01b0384161790558015610aa0575f805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163003610ed55760405162461bcd60e51b815260040161048e906136cb565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610f1d5f516020613be05f395f51905f52546001600160a01b031690565b6001600160a01b031614610f435760405162461bcd60e51b815260040161048e90613717565b610f4c82611f4a565b610f5882826001611f75565b5050565b6097545f906001600160a01b03163314610f89576040516316ccb9cb60e11b815260040160405180910390fd5b5f8411610fd85760405162461bcd60e51b815260206004820152601960248201527f4475726174696f6e206d75737420626520706f73697469766500000000000000604482015260640161048e565b5f83116110335760405162461bcd60e51b8152602060048201526024808201527f4c697175696469747920706172616d65746572206d75737420626520706f73696044820152637469766560e01b606482015260840161048e565b5f82116110825760405162461bcd60e51b815260206004820152601d60248201527f496e697469616c206c6971756964697479206d757374206265203e2030000000604482015260640161048e565b604080518181526029818301527f41626f757420746f20617070726f766520636f6e747261637420746f207370656060820152686e6420746f6b656e7360b81b608082015260208101849052905133917f76da6772a2e95e57d9e4d33e2afe7ae4679a7b267f98756879808547d2dfef52919081900360a00190a26098546040516323b872dd60e01b8152336004820152306024820152604481018490525f916001600160a01b0316906323b872dd906064016020604051808303815f875af1158015611151573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111759190613763565b9050806111945760405162461bcd60e51b815260040161048e906137b9565b609980545f91826111a48361390e565b909155505f818152609a60205260409020818155909150600181016111c98c82613971565b50600281016111d88b82613971565b50600581016111e78a82613971565b50600681016111f68982613971565b5061120187426138c3565b60038201556004810180545f919060ff191660018302179055508581600b0181905550620f424081600c0181905550848160070181905550600a8160080181905550600a81600901819055505f81600a015f6101000a81548160ff021916908315150217905550817f03381006daa9d80a6e22b92f6a6c56de1478beaa1cf38f27c9ce5d69fcb139268c8c8c8c866003015487600c01548c6040516112ac9796959493929190613a2c565b60405180910390a260408051818152601b818301527f4d61726b6574207375636365737366756c6c7920637265617465640000000000606082015260208101879052905133917f76da6772a2e95e57d9e4d33e2afe7ae4679a7b267f98756879808547d2dfef52919081900360800190a2509998505050505050505050565b5f828152609a60205260408120600b810154600882015460098301548483620f42406113578585613a98565b6113619190613abe565b61136b9190613aed565b905063080befc0808213156113825780915061139e565b61138b81613b19565b82121561139e5761139b81613b19565b91505b5f6113a883612225565b905064e8d4a510005f6113be83620f42406138c3565b90505f6113cb8284613826565b90505f6113db82620f4240613839565b90505f620f42408c600c0154846113f291906137fb565b6113fc9190613826565b90505f620f42408d600c01548461141391906137fb565b61141d9190613826565b90508e61142a578061142c565b815b9d50505050505050505050505050505b92915050565b5f306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146114e15760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c0000000000000000606482015260840161048e565b505f516020613be05f395f51905f5290565b6114fb6120df565b5f818152609a60205260409020600a81015460ff1661155c5760405162461bcd60e51b815260206004820152601760248201527f4d61726b6574206e6f74207265736f6c76656420796574000000000000000000604482015260640161048e565b5f806001600484015460ff16600281111561157957611579613275565b0361159b575050335f908152600d820160205260409020546008820154611612565b6002600484015460ff1660028111156115b6576115b6613275565b036115d8575050335f908152600e820160205260409020546009820154611612565b60405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206f7574636f6d6560881b604482015260640161048e565b5f82116116565760405162461bcd60e51b81526020600482015260126024820152714e6f2073686172657320746f20636c61696d60701b604482015260640161048e565b5f8183856007015461166891906137fb565b6116729190613826565b90506001600485015460ff16600281111561168f5761168f613275565b036116aa57335f908152600d850160205260408120556116bc565b335f908152600e850160205260408120555b60985460405163a9059cbb60e01b8152336004820152602481018390525f916001600160a01b03169063a9059cbb906044016020604051808303815f875af115801561170a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061172e9190613763565b90508061174d5760405162461bcd60e51b815260040161048e906137b9565b604051828152339087907f4ec90e965519d92681267467f775ada5bd214aa92c0dc93d90a5e880ce9ed0269060200160405180910390a3505050505061041c6001606555565b5f828152609a602090815260408083206001600160a01b0385168452600d8101835281842054600e909101909252909120545b9250929050565b609a6020525f9081526040902080546001820180549192916117ee906138d6565b80601f016020809104026020016040519081016040528092919081815260200182805461181a906138d6565b80156118655780601f1061183c57610100808354040283529160200191611865565b820191905f5260205f20905b81548152906001019060200180831161184857829003601f168201915b50505050509080600201805461187a906138d6565b80601f01602080910402602001604051908101604052809291908181526020018280546118a6906138d6565b80156118f15780601f106118c8576101008083540402835291602001916118f1565b820191905f5260205f20905b8154815290600101906020018083116118d457829003601f168201915b50505050600383015460048401546005850180549495929460ff90921693509061191a906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054611946906138d6565b80156119915780601f1061196857610100808354040283529160200191611991565b820191905f5260205f20905b81548152906001019060200180831161197457829003601f168201915b5050505050908060060180546119a6906138d6565b80601f01602080910402602001604051908101604052809291908181526020018280546119d2906138d6565b8015611a1d5780601f106119f457610100808354040283529160200191611a1d565b820191905f5260205f20905b815481529060010190602001808311611a0057829003601f168201915b505050600784015460088501546009860154600a870154600b880154600c909801549697939692955090935060ff1691908d565b5f818152609a60205260408120600f8101546010820154606093611a7582846138c3565b67ffffffffffffffff811115611a8d57611a8d613368565b604051908082528060200260200182016040528015611ab6578160200160208202803683370190505b5090505f5b83811015611b255784600f018181548110611ad857611ad8613b33565b905f5260205f20015f9054906101000a90046001600160a01b0316828281518110611b0557611b05613b33565b6001600160a01b0390921660209283029190910190910152600101611abb565b505f5b82811015611b9457846010018181548110611b4557611b45613b33565b5f918252602090912001546001600160a01b031682611b6483876138c3565b81518110611b7457611b74613b33565b6001600160a01b0390921660209283029190910190910152600101611b28565b5095945050505050565b611ba66120df565b5f828152609a6020526040902081611c005760405162461bcd60e51b815260206004820152601c60248201527f4d7573742073656e64205553444320746f206275792073686172657300000000604482015260640161048e565b6098546040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b03909116906323b872dd906064016020604051808303815f875af1158015611c54573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c789190613763565b5081816007015f828254611c8c91906138c3565b90915550506001606555505050565b6097546001600160a01b03163314611cc6576040516316ccb9cb60e11b815260040160405180910390fd5b5f828152609a602052604090206003810154421015611d1e5760405162461bcd60e51b815260206004820152601460248201527313585c9ad95d081b9bdd081e595d08195b99195960621b604482015260640161048e565b600a81015460ff1615611d735760405162461bcd60e51b815260206004820152601760248201527f4d61726b657420616c7265616479207265736f6c766564000000000000000000604482015260640161048e565b5f826002811115611d8657611d86613275565b03611dc55760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206f7574636f6d6560881b604482015260640161048e565b60048101805483919060ff19166001836002811115611de657611de6613275565b0217905550600a8101805460ff1916600117905560405183907f739f283563fb51ab6b89ee95d937b2e63a6cfcb83c385dbebb629f9d97bd43e690611e2c908590613b47565b60405180910390a2505050565b5f828152609a602090815260408083206001600160a01b0385168452600d8101835281842054600e8201909352908320546008820154600983015460078401548695939291908603611e95575f5f9650965050505050506117c6565b8115611ebd5781848660070154611eac91906137fb565b611eb69190613826565b9650611ec1565b5f96505b8015611ee95780838660070154611ed891906137fb565b611ee29190613826565b9550611eed565b5f95505b50505050509250929050565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76905f90a35050565b6097546001600160a01b0316331461041c576040516316ccb9cb60e11b815260040160405180910390fd5b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615611fa857610aa083612299565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612002575060408051601f3d908101601f19168201909252611fff91810190613b55565b60015b6120655760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b606482015260840161048e565b5f516020613be05f395f51905f5281146120d35760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b606482015260840161048e565b50610aa0838383612334565b6002606554036121315760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161048e565b6002606555565b60605f6121448361235e565b60010190505f8167ffffffffffffffff81111561216357612163613368565b6040519080825280601f01601f19166020018201604052801561218d576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461219757509392505050565b6001606555565b5f54610100900460ff166121f55760405162461bcd60e51b815260040161048e90613b6c565b565b5f54610100900460ff1661221d5760405162461bcd60e51b815260040161048e90613b6c565b6121f5612435565b5f63039387008083131561223b57809250612257565b61224481613b19565b8312156122575761225481613b19565b92505b5f6122756122648561245b565b612270620f424061248c565b6124a1565b90505f61228182612504565b905061229081620f4240612556565b95945050505050565b6001600160a01b0381163b6123065760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b606482015260840161048e565b5f516020613be05f395f51905f5280546001600160a01b0319166001600160a01b0392909216919091179055565b61233d836125c3565b5f825111806123495750805b15610aa0576123588383612602565b50505050565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061239c5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef810000000083106123c8576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106123e657662386f26fc10000830492506010015b6305f5e10083106123fe576305f5e100830492506008015b612710831061241257612710830492506004015b60648310612424576064830492506002015b600a831061143c5760010192915050565b5f54610100900460ff166121c85760405162461bcd60e51b815260040161048e90613b6c565b5f677fffffffffffffff19821215801561247d5750677fffffffffffffff8213155b612485575f5ffd5b5060401b90565b5f677fffffffffffffff821115612485575f5ffd5b5f81600f0b5f036124b0575f5ffd5b5f82600f0b604085600f0b901b816124ca576124ca613812565b0590506f7fffffffffffffffffffffffffffffff1981128015906124f5575060016001607f1b038113155b6124fd575f5ffd5b9392505050565b5f600160461b82600f0b12612517575f5ffd5b683fffffffffffffffff1982600f0b121561253357505f919050565b61143c608083600f0b700171547652b82fe1777d0ffda0d23a7d1202901d612627565b5f815f0361256557505f61143c565b5f83600f0b1215612574575f5ffd5b600f83900b6fffffffffffffffffffffffffffffffff8316810260401c90608084901c026001600160c01b038111156125ab575f5ffd5b60401b81198111156125bb575f5ffd5b019392505050565b6125cc81612299565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a250565b60606124fd8383604051806060016040528060278152602001613c006027913961309c565b5f600160461b82600f0b1261263a575f5ffd5b683fffffffffffffffff1982600f0b121561265657505f919050565b6001607f1b5f6780000000000000008416600f0b13156126875770016a09e667f3bcc908b2fb1366ea957d3e0260801c5b5f8367400000000000000016600f0b13156126b3577001306fe0a31b7152de8d5a46305c85edec0260801c5b5f8367200000000000000016600f0b13156126df577001172b83c7d517adcdf7c8c50eb14a791f0260801c5b5f8367100000000000000016600f0b131561270b5770010b5586cf9890f6298b92b71842a983630260801c5b5f8367080000000000000016600f0b1315612737577001059b0d31585743ae7c548eb68ca417fd0260801c5b5f8367040000000000000016600f0b131561276357700102c9a3e778060ee6f7caca4f7a29bde80260801c5b5f8367020000000000000016600f0b131561278f5770010163da9fb33356d84a66ae336dcdfa3f0260801c5b5f8367010000000000000016600f0b13156127bb57700100b1afa5abcbed6129ab13ec11dc95430260801c5b5f83668000000000000016600f0b13156127e65770010058c86da1c09ea1ff19d294cf2f679b0260801c5b5f83664000000000000016600f0b1315612811577001002c605e2e8cec506d21bfc89a23a00f0260801c5b5f83662000000000000016600f0b131561283c57700100162f3904051fa128bca9c55c31e5df0260801c5b5f83661000000000000016600f0b1315612867577001000b175effdc76ba38e31671ca9397250260801c5b5f83660800000000000016600f0b131561289257700100058ba01fb9f96d6cacd4b180917c3d0260801c5b5f83660400000000000016600f0b13156128bd5770010002c5cc37da9491d0985c348c68e7b30260801c5b5f83660200000000000016600f0b13156128e8577001000162e525ee054754457d59952920260260801c5b5f83660100000000000016600f0b13156129135770010000b17255775c040618bf4a4ade83fc0260801c5b5f836580000000000016600f0b131561293d577001000058b91b5bc9ae2eed81e9b7d4cfab0260801c5b5f836540000000000016600f0b131561296757700100002c5c89d5ec6ca4d7c8acc017b7c90260801c5b5f836520000000000016600f0b13156129915770010000162e43f4f831060e02d839a9d16d0260801c5b5f836510000000000016600f0b13156129bb57700100000b1721bcfc99d9f890ea069117630260801c5b5f836508000000000016600f0b13156129e55770010000058b90cf1e6d97f9ca14dbcc16280260801c5b5f836504000000000016600f0b1315612a0f577001000002c5c863b73f016468f6bac5ca2b0260801c5b5f836502000000000016600f0b1315612a3957700100000162e430e5a18f6119e3c02282a50260801c5b5f836501000000000016600f0b1315612a63577001000000b1721835514b86e6d96efd1bfe0260801c5b5f8364800000000016600f0b1315612a8c57700100000058b90c0b48c6be5df846c5b2ef0260801c5b5f8364400000000016600f0b1315612ab55770010000002c5c8601cc6b9e94213c72737a0260801c5b5f8364200000000016600f0b1315612ade577001000000162e42fff037df38aa2b219f060260801c5b5f8364100000000016600f0b1315612b075770010000000b17217fba9c739aa5819f44f90260801c5b5f8364080000000016600f0b1315612b30577001000000058b90bfcdee5acd3c1cedc8230260801c5b5f8364040000000016600f0b1315612b5957700100000002c5c85fe31f35a6a30da1be500260801c5b5f8364020000000016600f0b1315612b825770010000000162e42ff0999ce3541b9fffcf0260801c5b5f8364010000000016600f0b1315612bab57700100000000b17217f80f4ef5aadda455540260801c5b5f83638000000016600f0b1315612bd35770010000000058b90bfbf8479bd5a81b51ad0260801c5b5f83634000000016600f0b1315612bfb577001000000002c5c85fdf84bd62ae30a74cc0260801c5b5f83632000000016600f0b1315612c2357700100000000162e42fefb2fed257559bdaa0260801c5b5f83631000000016600f0b1315612c4b577001000000000b17217f7d5a7716bba4a9ae0260801c5b5f83630800000016600f0b1315612c7357700100000000058b90bfbe9ddbac5e109cce0260801c5b5f83630400000016600f0b1315612c9b5770010000000002c5c85fdf4b15de6f17eb0d0260801c5b5f83630200000016600f0b1315612cc3577001000000000162e42fefa494f1478fde050260801c5b5f83630100000016600f0b1315612ceb5770010000000000b17217f7d20cf927c8e94c0260801c5b5f836280000016600f0b1315612d12577001000000000058b90bfbe8f71cb4e4b33d0260801c5b5f836240000016600f0b1315612d3957700100000000002c5c85fdf477b662b269450260801c5b5f836220000016600f0b1315612d605770010000000000162e42fefa3ae53369388c0260801c5b5f836210000016600f0b1315612d8757700100000000000b17217f7d1d351a389d400260801c5b5f836208000016600f0b1315612dae5770010000000000058b90bfbe8e8b2d3d4ede0260801c5b5f836204000016600f0b1315612dd5577001000000000002c5c85fdf4741bea6e77e0260801c5b5f836202000016600f0b1315612dfc57700100000000000162e42fefa39fe95583c20260801c5b5f836201000016600f0b1315612e23577001000000000000b17217f7d1cfb72b45e10260801c5b5f8361800016600f0b1315612e4957700100000000000058b90bfbe8e7cc35c3f00260801c5b5f8361400016600f0b1315612e6f5770010000000000002c5c85fdf473e242ea380260801c5b5f8361200016600f0b1315612e95577001000000000000162e42fefa39f02b772c0260801c5b5f8361100016600f0b1315612ebb5770010000000000000b17217f7d1cf7d83c1a0260801c5b5f8361080016600f0b1315612ee1577001000000000000058b90bfbe8e7bdcbe2e0260801c5b5f8361040016600f0b1315612f0757700100000000000002c5c85fdf473dea871f0260801c5b5f8361020016600f0b1315612f2d5770010000000000000162e42fefa39ef44d910260801c5b5f8361010016600f0b1315612f5357700100000000000000b17217f7d1cf79e9490260801c5b5f83608016600f0b1315612f785770010000000000000058b90bfbe8e7bce5440260801c5b5f83604016600f0b1315612f9d577001000000000000002c5c85fdf473de6eca0260801c5b5f83602016600f0b1315612fc257700100000000000000162e42fefa39ef366f0260801c5b5f83601016600f0b1315612fe7577001000000000000000b17217f7d1cf79afa0260801c5b5f83600816600f0b131561300c57700100000000000000058b90bfbe8e7bcd6d0260801c5b5f83600416600f0b13156130315770010000000000000002c5c85fdf473de6b20260801c5b5f83600216600f0b1315613056577001000000000000000162e42fefa39ef3580260801c5b5f83600116600f0b131561307b5770010000000000000000b17217f7d1cf79ab0260801c5b600f83810b60401d603f03900b1c60016001607f1b0381111561143c575f5ffd5b60605f5f856001600160a01b0316856040516130b89190613bb7565b5f60405180830381855af49150503d805f81146130f0576040519150601f19603f3d011682016040523d82523d5f602084013e6130f5565b606091505b509150915061310686838387613110565b9695505050505050565b6060831561317e5782515f03613177576001600160a01b0385163b6131775760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161048e565b5081613188565b6131888383613190565b949350505050565b8151156131a05781518083602001fd5b8060405162461bcd60e51b815260040161048e9190613bcd565b80356001600160a01b03811681146131d0575f5ffd5b919050565b5f602082840312156131e5575f5ffd5b6124fd826131ba565b5f602082840312156131fe575f5ffd5b5035919050565b801515811461041c575f5ffd5b5f5f5f60608486031215613224575f5ffd5b83359250602084013561323681613205565b929592945050506040919091013590565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b634e487b7160e01b5f52602160045260245ffd5b600381106132a557634e487b7160e01b5f52602160045260245ffd5b9052565b61014081525f6132bd61014083018d613247565b82810360208401526132cf818d613247565b905082810360408401526132e3818c613247565b905082810360608401526132f7818b613247565b91505087608083015261330d60a0830188613289565b60c082019590955260e0810193909352901515610100830152610120909101529695505050505050565b5f5f60408385031215613348575f5ffd5b613351836131ba565b915061335f602084016131ba565b90509250929050565b634e487b7160e01b5f52604160045260245ffd5b5f5f67ffffffffffffffff84111561339657613396613368565b50604051601f19601f85018116603f0116810181811067ffffffffffffffff821117156133c5576133c5613368565b6040528381529050808284018510156133dc575f5ffd5b838360208301375f60208583010152509392505050565b5f5f60408385031215613404575f5ffd5b61340d836131ba565b9150602083013567ffffffffffffffff811115613428575f5ffd5b8301601f81018513613438575f5ffd5b6134478582356020840161337c565b9150509250929050565b5f82601f830112613460575f5ffd5b6124fd8383356020850161337c565b5f5f5f5f5f5f5f60e0888a031215613485575f5ffd5b873567ffffffffffffffff81111561349b575f5ffd5b6134a78a828b01613451565b975050602088013567ffffffffffffffff8111156134c3575f5ffd5b6134cf8a828b01613451565b965050604088013567ffffffffffffffff8111156134eb575f5ffd5b6134f78a828b01613451565b955050606088013567ffffffffffffffff811115613513575f5ffd5b61351f8a828b01613451565b979a969950949760808101359660a0820135965060c090910135945092505050565b5f5f60408385031215613552575f5ffd5b82359150602083013561356481613205565b809150509250929050565b5f5f60408385031215613580575f5ffd5b8235915061335f602084016131ba565b8d81526101a060208201525f6135aa6101a083018f613247565b82810360408401526135bc818f613247565b90508c60608401526135d1608084018d613289565b82810360a08401526135e3818c613247565b905082810360c08401526135f7818b613247565b9150508760e0830152866101008301528561012083015261361d61014083018615159052565b61016082019390935261018001529b9a5050505050505050505050565b602080825282518282018190525f918401906040840190835b8181101561367a5783516001600160a01b0316835260209384019390920191600101613653565b509095945050505050565b5f5f60408385031215613696575f5ffd5b50508035926020909101359150565b5f5f604083850312156136b6575f5ffd5b82359150602083013560038110613564575f5ffd5b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b5f60208284031215613773575f5ffd5b81516124fd81613205565b60608152600c60608201526b5472616e66657220646f6e6560a01b608082015282602082015260a060408201525f61318860a0830184613247565b6020808252601490820152731554d110c81d1c985b9cd9995c8819985a5b195960621b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761143c5761143c6137e7565b634e487b7160e01b5f52601260045260245ffd5b5f8261383457613834613812565b500490565b8181038181111561143c5761143c6137e7565b6060815260046060820152634665657360e01b608082015282602082015260a060408201525f61318860a0830184613247565b606081526015606082015274416d6f756e742061637475616c6c7920706169642160581b608082015282602082015260a060408201525f61318860a0830184613247565b8082018082111561143c5761143c6137e7565b600181811c908216806138ea57607f821691505b60208210810361390857634e487b7160e01b5f52602260045260245ffd5b50919050565b5f6001820161391f5761391f6137e7565b5060010190565b601f821115610aa057805f5260205f20601f840160051c8101602085101561394b5750805b601f840160051c820191505b8181101561396a575f8155600101613957565b5050505050565b815167ffffffffffffffff81111561398b5761398b613368565b61399f8161399984546138d6565b84613926565b6020601f8211600181146139d1575f83156139ba5750848201515b5f19600385901b1c1916600184901b17845561396a565b5f84815260208120601f198516915b82811015613a0057878501518255602094850194600190920191016139e0565b5084821015613a1d57868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b60e081525f613a3e60e083018a613247565b8281036020840152613a50818a613247565b90508281036040840152613a648189613247565b90508281036060840152613a788188613247565b6080840196909652505060a081019290925260c090910152949350505050565b8181035f831280158383131683831282161715613ab757613ab76137e7565b5092915050565b8082025f8212600160ff1b84141615613ad957613ad96137e7565b818105831482151761143c5761143c6137e7565b5f82613afb57613afb613812565b600160ff1b82145f1984141615613b1457613b146137e7565b500590565b5f600160ff1b8201613b2d57613b2d6137e7565b505f0390565b634e487b7160e01b5f52603260045260245ffd5b6020810161143c8284613289565b5f60208284031215613b65575f5ffd5b5051919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b5f82518060208501845e5f920191825250919050565b602081525f6124fd602083018461324756fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212203ab761c067a10c296ec374173ffa688f9bef59fb9b5a84883bad48208956833a64736f6c634300081c0033
Deployed Bytecode
0x608060405260043610610125575f3560e01c80634fb113ab116100a8578063b1283e771161006d578063b1283e771461032d578063b510ceb714610365578063c1433f4414610391578063df55406e146103b0578063e1b009f2146103cf578063ec979082146103ee575f5ffd5b80634fb113ab1461029f57806352d1902d146102be578063677bd9ff146102d25780637f1a10da146102f15780638da5cb5b14610310575f5ffd5b80633e413bee116100ee5780633e413bee146101e25780633ec7919314610219578063485cc9551461024e5780634f1ef2861461026d5780634f7438f914610280575f5ffd5b80620b46f81461012957806313af40351461014f57806327ce8c51146101705780633659cfe6146101a457806339b46372146101c3575b5f5ffd5b348015610134575f5ffd5b5061013c5f81565b6040519081526020015b60405180910390f35b34801561015a575f5ffd5b5061016e6101693660046131d5565b610403565b005b34801561017b575f5ffd5b5061018f61018a3660046131ee565b61041f565b60408051928352602083019190915201610146565b3480156101af575f5ffd5b5061016e6101be3660046131d5565b610446565b3480156101ce575f5ffd5b5061016e6101dd366004613212565b610529565b3480156101ed575f5ffd5b50609854610201906001600160a01b031681565b6040516001600160a01b039091168152602001610146565b348015610224575f5ffd5b506102386102333660046131ee565b610aa5565b6040516101469a999897969594939291906132a9565b348015610259575f5ffd5b5061016e610268366004613337565b610d55565b61016e61027b3660046133f3565b610e8d565b34801561028b575f5ffd5b5061013c61029a36600461346f565b610f5c565b3480156102aa575f5ffd5b5061013c6102b9366004613541565b61132b565b3480156102c9575f5ffd5b5061013c611442565b3480156102dd575f5ffd5b5061016e6102ec3660046131ee565b6114f3565b3480156102fc575f5ffd5b5061018f61030b36600461356f565b611793565b34801561031b575f5ffd5b506097546001600160a01b0316610201565b348015610338575f5ffd5b5061034c6103473660046131ee565b6117cd565b6040516101469d9c9b9a99989796959493929190613590565b348015610370575f5ffd5b5061038461037f3660046131ee565b611a51565b604051610146919061363a565b34801561039c575f5ffd5b5061016e6103ab366004613685565b611b9e565b3480156103bb575f5ffd5b5061016e6103ca3660046136a5565b611c9b565b3480156103da575f5ffd5b5061018f6103e936600461356f565b611e39565b3480156103f9575f5ffd5b5061013c60995481565b6040516316ccb9cb60e11b815260040160405180910390fd5b50565b5f5f5f61042d84600161132b565b90505f61043a855f61132b565b91959194509092505050565b6001600160a01b037f000000000000000000000000364b44cdc418becd390516cede656c9ecfcbd76e1630036104975760405162461bcd60e51b815260040161048e906136cb565b60405180910390fd5b7f000000000000000000000000364b44cdc418becd390516cede656c9ecfcbd76e6001600160a01b03166104df5f516020613be05f395f51905f52546001600160a01b031690565b6001600160a01b0316146105055760405162461bcd60e51b815260040161048e90613717565b61050e81611f4a565b604080515f8082526020820190925261041c91839190611f75565b6105316120df565b5f838152609a60205260409020600381015442106105845760405162461bcd60e51b815260206004820152601060248201526f13585c9ad95d081a185cc8195b99195960821b604482015260640161048e565b600a81015460ff16156105cb5760405162461bcd60e51b815260206004820152600f60248201526e13585c9ad95d081c995cdbdb1d9959608a1b604482015260640161048e565b5f821161061a5760405162461bcd60e51b815260206004820152601c60248201527f4d7573742073656e64205553444320746f206275792073686172657300000000604482015260640161048e565b6098546040516323b872dd60e01b8152336004820152306024820152604481018490525f916001600160a01b0316906323b872dd906064016020604051808303815f875af115801561066e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106929190613763565b9050337fc64d203bdd634d8a38663ba6281285fef3addc9e7e00f5b4966c67a217bebf2e86836106df576040518060400160405280600581526020016466616c736560d81b8152506106fd565b604051806040016040528060048152602001637472756560e01b8152505b60405161070b92919061377e565b60405180910390a2806107305760405162461bcd60e51b815260040161048e906137b9565b5f606461073d82866137fb565b6107479190613826565b90505f6107548286613839565b9050811561086b5760985460405163a9059cbb60e01b81527371a2d2f2bc3d34db8ceaf8f219941db959c36e946004820152602481018490525f916001600160a01b03169063a9059cbb906044016020604051808303815f875af11580156107be573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107e29190613763565b9050806108275760405162461bcd60e51b8152602060048201526013602482015272119959481d1c985b9cd9995c8819985a5b1959606a1b604482015260640161048e565b337fc64d203bdd634d8a38663ba6281285fef3addc9e7e00f5b4966c67a217bebf2e8961085386612138565b60405161086192919061384c565b60405180910390a2505b337fc64d203bdd634d8a38663ba6281285fef3addc9e7e00f5b4966c67a217bebf2e8861089784612138565b6040516108a592919061387f565b60405180910390a280846007015f8282546108c091906138c3565b909155505f90506108d1888861132b565b90505f81116109135760405162461bcd60e51b815260206004820152600e60248201526d283934b1b29031b0b6319032b93960911b604482015260640161048e565b5f61091e8284613826565b905087156109c25780866008015f82825461093991906138c3565b9091555050335f908152600d870160205260408120805483929061095e9084906138c3565b9091555050335f90815260118701602052604090205460ff166109bd57335f81815260118801602090815260408220805460ff19166001908117909155600f8a0180549182018155835291200180546001600160a01b03191690911790555b610a59565b80866009015f8282546109d591906138c3565b9091555050335f908152600e87016020526040812080548392906109fa9084906138c3565b9091555050335f90815260128701602052604090205460ff16610a5957335f81815260128801602090815260408220805460ff1916600190811790915560108a0180549182018155835291200180546001600160a01b03191690911790555b60405181815233908a907f3704aababc4a932e42bcc46613dd1b566f25e54dbeb2562a9752cffccdc102dd9060200160405180910390a3505050505050610aa06001606555565b505050565b6060806060805f5f5f5f5f5f5f609a5f8d81526020019081526020015f209050806001018160020182600501836006018460030154856004015f9054906101000a900460ff168660080154876009015488600a015f9054906101000a900460ff168960070154898054610b17906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610b43906138d6565b8015610b8e5780601f10610b6557610100808354040283529160200191610b8e565b820191905f5260205f20905b815481529060010190602001808311610b7157829003601f168201915b50505050509950888054610ba1906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610bcd906138d6565b8015610c185780601f10610bef57610100808354040283529160200191610c18565b820191905f5260205f20905b815481529060010190602001808311610bfb57829003601f168201915b50505050509850878054610c2b906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610c57906138d6565b8015610ca25780601f10610c7957610100808354040283529160200191610ca2565b820191905f5260205f20905b815481529060010190602001808311610c8557829003601f168201915b50505050509750868054610cb5906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054610ce1906138d6565b8015610d2c5780601f10610d0357610100808354040283529160200191610d2c565b820191905f5260205f20905b815481529060010190602001808311610d0f57829003601f168201915b505050505096509a509a509a509a509a509a509a509a509a509a50509193959799509193959799565b5f54610100900460ff1615808015610d7357505f54600160ff909116105b80610d8c5750303b158015610d8c57505f5460ff166001145b610def5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840161048e565b5f805460ff191660011790558015610e10575f805461ff0019166101001790555b610e186121cf565b610e206121f7565b610e2983611ef9565b609880546001600160a01b0319166001600160a01b0384161790558015610aa0575f805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a1505050565b6001600160a01b037f000000000000000000000000364b44cdc418becd390516cede656c9ecfcbd76e163003610ed55760405162461bcd60e51b815260040161048e906136cb565b7f000000000000000000000000364b44cdc418becd390516cede656c9ecfcbd76e6001600160a01b0316610f1d5f516020613be05f395f51905f52546001600160a01b031690565b6001600160a01b031614610f435760405162461bcd60e51b815260040161048e90613717565b610f4c82611f4a565b610f5882826001611f75565b5050565b6097545f906001600160a01b03163314610f89576040516316ccb9cb60e11b815260040160405180910390fd5b5f8411610fd85760405162461bcd60e51b815260206004820152601960248201527f4475726174696f6e206d75737420626520706f73697469766500000000000000604482015260640161048e565b5f83116110335760405162461bcd60e51b8152602060048201526024808201527f4c697175696469747920706172616d65746572206d75737420626520706f73696044820152637469766560e01b606482015260840161048e565b5f82116110825760405162461bcd60e51b815260206004820152601d60248201527f496e697469616c206c6971756964697479206d757374206265203e2030000000604482015260640161048e565b604080518181526029818301527f41626f757420746f20617070726f766520636f6e747261637420746f207370656060820152686e6420746f6b656e7360b81b608082015260208101849052905133917f76da6772a2e95e57d9e4d33e2afe7ae4679a7b267f98756879808547d2dfef52919081900360a00190a26098546040516323b872dd60e01b8152336004820152306024820152604481018490525f916001600160a01b0316906323b872dd906064016020604051808303815f875af1158015611151573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111759190613763565b9050806111945760405162461bcd60e51b815260040161048e906137b9565b609980545f91826111a48361390e565b909155505f818152609a60205260409020818155909150600181016111c98c82613971565b50600281016111d88b82613971565b50600581016111e78a82613971565b50600681016111f68982613971565b5061120187426138c3565b60038201556004810180545f919060ff191660018302179055508581600b0181905550620f424081600c0181905550848160070181905550600a8160080181905550600a81600901819055505f81600a015f6101000a81548160ff021916908315150217905550817f03381006daa9d80a6e22b92f6a6c56de1478beaa1cf38f27c9ce5d69fcb139268c8c8c8c866003015487600c01548c6040516112ac9796959493929190613a2c565b60405180910390a260408051818152601b818301527f4d61726b6574207375636365737366756c6c7920637265617465640000000000606082015260208101879052905133917f76da6772a2e95e57d9e4d33e2afe7ae4679a7b267f98756879808547d2dfef52919081900360800190a2509998505050505050505050565b5f828152609a60205260408120600b810154600882015460098301548483620f42406113578585613a98565b6113619190613abe565b61136b9190613aed565b905063080befc0808213156113825780915061139e565b61138b81613b19565b82121561139e5761139b81613b19565b91505b5f6113a883612225565b905064e8d4a510005f6113be83620f42406138c3565b90505f6113cb8284613826565b90505f6113db82620f4240613839565b90505f620f42408c600c0154846113f291906137fb565b6113fc9190613826565b90505f620f42408d600c01548461141391906137fb565b61141d9190613826565b90508e61142a578061142c565b815b9d50505050505050505050505050505b92915050565b5f306001600160a01b037f000000000000000000000000364b44cdc418becd390516cede656c9ecfcbd76e16146114e15760405162461bcd60e51b815260206004820152603860248201527f555550535570677261646561626c653a206d757374206e6f742062652063616c60448201527f6c6564207468726f7567682064656c656761746563616c6c0000000000000000606482015260840161048e565b505f516020613be05f395f51905f5290565b6114fb6120df565b5f818152609a60205260409020600a81015460ff1661155c5760405162461bcd60e51b815260206004820152601760248201527f4d61726b6574206e6f74207265736f6c76656420796574000000000000000000604482015260640161048e565b5f806001600484015460ff16600281111561157957611579613275565b0361159b575050335f908152600d820160205260409020546008820154611612565b6002600484015460ff1660028111156115b6576115b6613275565b036115d8575050335f908152600e820160205260409020546009820154611612565b60405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206f7574636f6d6560881b604482015260640161048e565b5f82116116565760405162461bcd60e51b81526020600482015260126024820152714e6f2073686172657320746f20636c61696d60701b604482015260640161048e565b5f8183856007015461166891906137fb565b6116729190613826565b90506001600485015460ff16600281111561168f5761168f613275565b036116aa57335f908152600d850160205260408120556116bc565b335f908152600e850160205260408120555b60985460405163a9059cbb60e01b8152336004820152602481018390525f916001600160a01b03169063a9059cbb906044016020604051808303815f875af115801561170a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061172e9190613763565b90508061174d5760405162461bcd60e51b815260040161048e906137b9565b604051828152339087907f4ec90e965519d92681267467f775ada5bd214aa92c0dc93d90a5e880ce9ed0269060200160405180910390a3505050505061041c6001606555565b5f828152609a602090815260408083206001600160a01b0385168452600d8101835281842054600e909101909252909120545b9250929050565b609a6020525f9081526040902080546001820180549192916117ee906138d6565b80601f016020809104026020016040519081016040528092919081815260200182805461181a906138d6565b80156118655780601f1061183c57610100808354040283529160200191611865565b820191905f5260205f20905b81548152906001019060200180831161184857829003601f168201915b50505050509080600201805461187a906138d6565b80601f01602080910402602001604051908101604052809291908181526020018280546118a6906138d6565b80156118f15780601f106118c8576101008083540402835291602001916118f1565b820191905f5260205f20905b8154815290600101906020018083116118d457829003601f168201915b50505050600383015460048401546005850180549495929460ff90921693509061191a906138d6565b80601f0160208091040260200160405190810160405280929190818152602001828054611946906138d6565b80156119915780601f1061196857610100808354040283529160200191611991565b820191905f5260205f20905b81548152906001019060200180831161197457829003601f168201915b5050505050908060060180546119a6906138d6565b80601f01602080910402602001604051908101604052809291908181526020018280546119d2906138d6565b8015611a1d5780601f106119f457610100808354040283529160200191611a1d565b820191905f5260205f20905b815481529060010190602001808311611a0057829003601f168201915b505050600784015460088501546009860154600a870154600b880154600c909801549697939692955090935060ff1691908d565b5f818152609a60205260408120600f8101546010820154606093611a7582846138c3565b67ffffffffffffffff811115611a8d57611a8d613368565b604051908082528060200260200182016040528015611ab6578160200160208202803683370190505b5090505f5b83811015611b255784600f018181548110611ad857611ad8613b33565b905f5260205f20015f9054906101000a90046001600160a01b0316828281518110611b0557611b05613b33565b6001600160a01b0390921660209283029190910190910152600101611abb565b505f5b82811015611b9457846010018181548110611b4557611b45613b33565b5f918252602090912001546001600160a01b031682611b6483876138c3565b81518110611b7457611b74613b33565b6001600160a01b0390921660209283029190910190910152600101611b28565b5095945050505050565b611ba66120df565b5f828152609a6020526040902081611c005760405162461bcd60e51b815260206004820152601c60248201527f4d7573742073656e64205553444320746f206275792073686172657300000000604482015260640161048e565b6098546040516323b872dd60e01b8152336004820152306024820152604481018490526001600160a01b03909116906323b872dd906064016020604051808303815f875af1158015611c54573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c789190613763565b5081816007015f828254611c8c91906138c3565b90915550506001606555505050565b6097546001600160a01b03163314611cc6576040516316ccb9cb60e11b815260040160405180910390fd5b5f828152609a602052604090206003810154421015611d1e5760405162461bcd60e51b815260206004820152601460248201527313585c9ad95d081b9bdd081e595d08195b99195960621b604482015260640161048e565b600a81015460ff1615611d735760405162461bcd60e51b815260206004820152601760248201527f4d61726b657420616c7265616479207265736f6c766564000000000000000000604482015260640161048e565b5f826002811115611d8657611d86613275565b03611dc55760405162461bcd60e51b815260206004820152600f60248201526e496e76616c6964206f7574636f6d6560881b604482015260640161048e565b60048101805483919060ff19166001836002811115611de657611de6613275565b0217905550600a8101805460ff1916600117905560405183907f739f283563fb51ab6b89ee95d937b2e63a6cfcb83c385dbebb629f9d97bd43e690611e2c908590613b47565b60405180910390a2505050565b5f828152609a602090815260408083206001600160a01b0385168452600d8101835281842054600e8201909352908320546008820154600983015460078401548695939291908603611e95575f5f9650965050505050506117c6565b8115611ebd5781848660070154611eac91906137fb565b611eb69190613826565b9650611ec1565b5f96505b8015611ee95780838660070154611ed891906137fb565b611ee29190613826565b9550611eed565b5f95505b50505050509250929050565b609780546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76905f90a35050565b6097546001600160a01b0316331461041c576040516316ccb9cb60e11b815260040160405180910390fd5b7f4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd91435460ff1615611fa857610aa083612299565b826001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015612002575060408051601f3d908101601f19168201909252611fff91810190613b55565b60015b6120655760405162461bcd60e51b815260206004820152602e60248201527f45524331393637557067726164653a206e657720696d706c656d656e7461746960448201526d6f6e206973206e6f74205555505360901b606482015260840161048e565b5f516020613be05f395f51905f5281146120d35760405162461bcd60e51b815260206004820152602960248201527f45524331393637557067726164653a20756e737570706f727465642070726f786044820152681a58589b195555525160ba1b606482015260840161048e565b50610aa0838383612334565b6002606554036121315760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161048e565b6002606555565b60605f6121448361235e565b60010190505f8167ffffffffffffffff81111561216357612163613368565b6040519080825280601f01601f19166020018201604052801561218d576020820181803683370190505b5090508181016020015b5f19016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a850494508461219757509392505050565b6001606555565b5f54610100900460ff166121f55760405162461bcd60e51b815260040161048e90613b6c565b565b5f54610100900460ff1661221d5760405162461bcd60e51b815260040161048e90613b6c565b6121f5612435565b5f63039387008083131561223b57809250612257565b61224481613b19565b8312156122575761225481613b19565b92505b5f6122756122648561245b565b612270620f424061248c565b6124a1565b90505f61228182612504565b905061229081620f4240612556565b95945050505050565b6001600160a01b0381163b6123065760405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b606482015260840161048e565b5f516020613be05f395f51905f5280546001600160a01b0319166001600160a01b0392909216919091179055565b61233d836125c3565b5f825111806123495750805b15610aa0576123588383612602565b50505050565b5f8072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b831061239c5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef810000000083106123c8576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc1000083106123e657662386f26fc10000830492506010015b6305f5e10083106123fe576305f5e100830492506008015b612710831061241257612710830492506004015b60648310612424576064830492506002015b600a831061143c5760010192915050565b5f54610100900460ff166121c85760405162461bcd60e51b815260040161048e90613b6c565b5f677fffffffffffffff19821215801561247d5750677fffffffffffffff8213155b612485575f5ffd5b5060401b90565b5f677fffffffffffffff821115612485575f5ffd5b5f81600f0b5f036124b0575f5ffd5b5f82600f0b604085600f0b901b816124ca576124ca613812565b0590506f7fffffffffffffffffffffffffffffff1981128015906124f5575060016001607f1b038113155b6124fd575f5ffd5b9392505050565b5f600160461b82600f0b12612517575f5ffd5b683fffffffffffffffff1982600f0b121561253357505f919050565b61143c608083600f0b700171547652b82fe1777d0ffda0d23a7d1202901d612627565b5f815f0361256557505f61143c565b5f83600f0b1215612574575f5ffd5b600f83900b6fffffffffffffffffffffffffffffffff8316810260401c90608084901c026001600160c01b038111156125ab575f5ffd5b60401b81198111156125bb575f5ffd5b019392505050565b6125cc81612299565b6040516001600160a01b038216907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a250565b60606124fd8383604051806060016040528060278152602001613c006027913961309c565b5f600160461b82600f0b1261263a575f5ffd5b683fffffffffffffffff1982600f0b121561265657505f919050565b6001607f1b5f6780000000000000008416600f0b13156126875770016a09e667f3bcc908b2fb1366ea957d3e0260801c5b5f8367400000000000000016600f0b13156126b3577001306fe0a31b7152de8d5a46305c85edec0260801c5b5f8367200000000000000016600f0b13156126df577001172b83c7d517adcdf7c8c50eb14a791f0260801c5b5f8367100000000000000016600f0b131561270b5770010b5586cf9890f6298b92b71842a983630260801c5b5f8367080000000000000016600f0b1315612737577001059b0d31585743ae7c548eb68ca417fd0260801c5b5f8367040000000000000016600f0b131561276357700102c9a3e778060ee6f7caca4f7a29bde80260801c5b5f8367020000000000000016600f0b131561278f5770010163da9fb33356d84a66ae336dcdfa3f0260801c5b5f8367010000000000000016600f0b13156127bb57700100b1afa5abcbed6129ab13ec11dc95430260801c5b5f83668000000000000016600f0b13156127e65770010058c86da1c09ea1ff19d294cf2f679b0260801c5b5f83664000000000000016600f0b1315612811577001002c605e2e8cec506d21bfc89a23a00f0260801c5b5f83662000000000000016600f0b131561283c57700100162f3904051fa128bca9c55c31e5df0260801c5b5f83661000000000000016600f0b1315612867577001000b175effdc76ba38e31671ca9397250260801c5b5f83660800000000000016600f0b131561289257700100058ba01fb9f96d6cacd4b180917c3d0260801c5b5f83660400000000000016600f0b13156128bd5770010002c5cc37da9491d0985c348c68e7b30260801c5b5f83660200000000000016600f0b13156128e8577001000162e525ee054754457d59952920260260801c5b5f83660100000000000016600f0b13156129135770010000b17255775c040618bf4a4ade83fc0260801c5b5f836580000000000016600f0b131561293d577001000058b91b5bc9ae2eed81e9b7d4cfab0260801c5b5f836540000000000016600f0b131561296757700100002c5c89d5ec6ca4d7c8acc017b7c90260801c5b5f836520000000000016600f0b13156129915770010000162e43f4f831060e02d839a9d16d0260801c5b5f836510000000000016600f0b13156129bb57700100000b1721bcfc99d9f890ea069117630260801c5b5f836508000000000016600f0b13156129e55770010000058b90cf1e6d97f9ca14dbcc16280260801c5b5f836504000000000016600f0b1315612a0f577001000002c5c863b73f016468f6bac5ca2b0260801c5b5f836502000000000016600f0b1315612a3957700100000162e430e5a18f6119e3c02282a50260801c5b5f836501000000000016600f0b1315612a63577001000000b1721835514b86e6d96efd1bfe0260801c5b5f8364800000000016600f0b1315612a8c57700100000058b90c0b48c6be5df846c5b2ef0260801c5b5f8364400000000016600f0b1315612ab55770010000002c5c8601cc6b9e94213c72737a0260801c5b5f8364200000000016600f0b1315612ade577001000000162e42fff037df38aa2b219f060260801c5b5f8364100000000016600f0b1315612b075770010000000b17217fba9c739aa5819f44f90260801c5b5f8364080000000016600f0b1315612b30577001000000058b90bfcdee5acd3c1cedc8230260801c5b5f8364040000000016600f0b1315612b5957700100000002c5c85fe31f35a6a30da1be500260801c5b5f8364020000000016600f0b1315612b825770010000000162e42ff0999ce3541b9fffcf0260801c5b5f8364010000000016600f0b1315612bab57700100000000b17217f80f4ef5aadda455540260801c5b5f83638000000016600f0b1315612bd35770010000000058b90bfbf8479bd5a81b51ad0260801c5b5f83634000000016600f0b1315612bfb577001000000002c5c85fdf84bd62ae30a74cc0260801c5b5f83632000000016600f0b1315612c2357700100000000162e42fefb2fed257559bdaa0260801c5b5f83631000000016600f0b1315612c4b577001000000000b17217f7d5a7716bba4a9ae0260801c5b5f83630800000016600f0b1315612c7357700100000000058b90bfbe9ddbac5e109cce0260801c5b5f83630400000016600f0b1315612c9b5770010000000002c5c85fdf4b15de6f17eb0d0260801c5b5f83630200000016600f0b1315612cc3577001000000000162e42fefa494f1478fde050260801c5b5f83630100000016600f0b1315612ceb5770010000000000b17217f7d20cf927c8e94c0260801c5b5f836280000016600f0b1315612d12577001000000000058b90bfbe8f71cb4e4b33d0260801c5b5f836240000016600f0b1315612d3957700100000000002c5c85fdf477b662b269450260801c5b5f836220000016600f0b1315612d605770010000000000162e42fefa3ae53369388c0260801c5b5f836210000016600f0b1315612d8757700100000000000b17217f7d1d351a389d400260801c5b5f836208000016600f0b1315612dae5770010000000000058b90bfbe8e8b2d3d4ede0260801c5b5f836204000016600f0b1315612dd5577001000000000002c5c85fdf4741bea6e77e0260801c5b5f836202000016600f0b1315612dfc57700100000000000162e42fefa39fe95583c20260801c5b5f836201000016600f0b1315612e23577001000000000000b17217f7d1cfb72b45e10260801c5b5f8361800016600f0b1315612e4957700100000000000058b90bfbe8e7cc35c3f00260801c5b5f8361400016600f0b1315612e6f5770010000000000002c5c85fdf473e242ea380260801c5b5f8361200016600f0b1315612e95577001000000000000162e42fefa39f02b772c0260801c5b5f8361100016600f0b1315612ebb5770010000000000000b17217f7d1cf7d83c1a0260801c5b5f8361080016600f0b1315612ee1577001000000000000058b90bfbe8e7bdcbe2e0260801c5b5f8361040016600f0b1315612f0757700100000000000002c5c85fdf473dea871f0260801c5b5f8361020016600f0b1315612f2d5770010000000000000162e42fefa39ef44d910260801c5b5f8361010016600f0b1315612f5357700100000000000000b17217f7d1cf79e9490260801c5b5f83608016600f0b1315612f785770010000000000000058b90bfbe8e7bce5440260801c5b5f83604016600f0b1315612f9d577001000000000000002c5c85fdf473de6eca0260801c5b5f83602016600f0b1315612fc257700100000000000000162e42fefa39ef366f0260801c5b5f83601016600f0b1315612fe7577001000000000000000b17217f7d1cf79afa0260801c5b5f83600816600f0b131561300c57700100000000000000058b90bfbe8e7bcd6d0260801c5b5f83600416600f0b13156130315770010000000000000002c5c85fdf473de6b20260801c5b5f83600216600f0b1315613056577001000000000000000162e42fefa39ef3580260801c5b5f83600116600f0b131561307b5770010000000000000000b17217f7d1cf79ab0260801c5b600f83810b60401d603f03900b1c60016001607f1b0381111561143c575f5ffd5b60605f5f856001600160a01b0316856040516130b89190613bb7565b5f60405180830381855af49150503d805f81146130f0576040519150601f19603f3d011682016040523d82523d5f602084013e6130f5565b606091505b509150915061310686838387613110565b9695505050505050565b6060831561317e5782515f03613177576001600160a01b0385163b6131775760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161048e565b5081613188565b6131888383613190565b949350505050565b8151156131a05781518083602001fd5b8060405162461bcd60e51b815260040161048e9190613bcd565b80356001600160a01b03811681146131d0575f5ffd5b919050565b5f602082840312156131e5575f5ffd5b6124fd826131ba565b5f602082840312156131fe575f5ffd5b5035919050565b801515811461041c575f5ffd5b5f5f5f60608486031215613224575f5ffd5b83359250602084013561323681613205565b929592945050506040919091013590565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b634e487b7160e01b5f52602160045260245ffd5b600381106132a557634e487b7160e01b5f52602160045260245ffd5b9052565b61014081525f6132bd61014083018d613247565b82810360208401526132cf818d613247565b905082810360408401526132e3818c613247565b905082810360608401526132f7818b613247565b91505087608083015261330d60a0830188613289565b60c082019590955260e0810193909352901515610100830152610120909101529695505050505050565b5f5f60408385031215613348575f5ffd5b613351836131ba565b915061335f602084016131ba565b90509250929050565b634e487b7160e01b5f52604160045260245ffd5b5f5f67ffffffffffffffff84111561339657613396613368565b50604051601f19601f85018116603f0116810181811067ffffffffffffffff821117156133c5576133c5613368565b6040528381529050808284018510156133dc575f5ffd5b838360208301375f60208583010152509392505050565b5f5f60408385031215613404575f5ffd5b61340d836131ba565b9150602083013567ffffffffffffffff811115613428575f5ffd5b8301601f81018513613438575f5ffd5b6134478582356020840161337c565b9150509250929050565b5f82601f830112613460575f5ffd5b6124fd8383356020850161337c565b5f5f5f5f5f5f5f60e0888a031215613485575f5ffd5b873567ffffffffffffffff81111561349b575f5ffd5b6134a78a828b01613451565b975050602088013567ffffffffffffffff8111156134c3575f5ffd5b6134cf8a828b01613451565b965050604088013567ffffffffffffffff8111156134eb575f5ffd5b6134f78a828b01613451565b955050606088013567ffffffffffffffff811115613513575f5ffd5b61351f8a828b01613451565b979a969950949760808101359660a0820135965060c090910135945092505050565b5f5f60408385031215613552575f5ffd5b82359150602083013561356481613205565b809150509250929050565b5f5f60408385031215613580575f5ffd5b8235915061335f602084016131ba565b8d81526101a060208201525f6135aa6101a083018f613247565b82810360408401526135bc818f613247565b90508c60608401526135d1608084018d613289565b82810360a08401526135e3818c613247565b905082810360c08401526135f7818b613247565b9150508760e0830152866101008301528561012083015261361d61014083018615159052565b61016082019390935261018001529b9a5050505050505050505050565b602080825282518282018190525f918401906040840190835b8181101561367a5783516001600160a01b0316835260209384019390920191600101613653565b509095945050505050565b5f5f60408385031215613696575f5ffd5b50508035926020909101359150565b5f5f604083850312156136b6575f5ffd5b82359150602083013560038110613564575f5ffd5b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b19195b1959d85d1958d85b1b60a21b606082015260800190565b6020808252602c908201527f46756e6374696f6e206d7573742062652063616c6c6564207468726f7567682060408201526b6163746976652070726f787960a01b606082015260800190565b5f60208284031215613773575f5ffd5b81516124fd81613205565b60608152600c60608201526b5472616e66657220646f6e6560a01b608082015282602082015260a060408201525f61318860a0830184613247565b6020808252601490820152731554d110c81d1c985b9cd9995c8819985a5b195960621b604082015260600190565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761143c5761143c6137e7565b634e487b7160e01b5f52601260045260245ffd5b5f8261383457613834613812565b500490565b8181038181111561143c5761143c6137e7565b6060815260046060820152634665657360e01b608082015282602082015260a060408201525f61318860a0830184613247565b606081526015606082015274416d6f756e742061637475616c6c7920706169642160581b608082015282602082015260a060408201525f61318860a0830184613247565b8082018082111561143c5761143c6137e7565b600181811c908216806138ea57607f821691505b60208210810361390857634e487b7160e01b5f52602260045260245ffd5b50919050565b5f6001820161391f5761391f6137e7565b5060010190565b601f821115610aa057805f5260205f20601f840160051c8101602085101561394b5750805b601f840160051c820191505b8181101561396a575f8155600101613957565b5050505050565b815167ffffffffffffffff81111561398b5761398b613368565b61399f8161399984546138d6565b84613926565b6020601f8211600181146139d1575f83156139ba5750848201515b5f19600385901b1c1916600184901b17845561396a565b5f84815260208120601f198516915b82811015613a0057878501518255602094850194600190920191016139e0565b5084821015613a1d57868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b60e081525f613a3e60e083018a613247565b8281036020840152613a50818a613247565b90508281036040840152613a648189613247565b90508281036060840152613a788188613247565b6080840196909652505060a081019290925260c090910152949350505050565b8181035f831280158383131683831282161715613ab757613ab76137e7565b5092915050565b8082025f8212600160ff1b84141615613ad957613ad96137e7565b818105831482151761143c5761143c6137e7565b5f82613afb57613afb613812565b600160ff1b82145f1984141615613b1457613b146137e7565b500590565b5f600160ff1b8201613b2d57613b2d6137e7565b505f0390565b634e487b7160e01b5f52603260045260245ffd5b6020810161143c8284613289565b5f60208284031215613b65575f5ffd5b5051919050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b5f82518060208501845e5f920191825250919050565b602081525f6124fd602083018461324756fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a26469706673582212203ab761c067a10c296ec374173ffa688f9bef59fb9b5a84883bad48208956833a64736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.