Source Code
Overview
MON Balance
MON Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
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:
Vault
Compiler Version
v0.8.30+commit.73712a01
Optimization Enabled:
No with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
// ============ Internal Imports ============
import {IOrderBook} from "./interfaces/IOrderBook.sol";
import {IVault} from "./interfaces/IVault.sol";
import {IMarginAccount} from "./interfaces/IMarginAccount.sol";
import {Events, Errors} from "./libraries/EventsErrors.sol";
import {LiquidityShares} from "./libraries/LiquidityShares.sol";
import {IKuruFlowEntrypoint} from "./interfaces/IKuruFlowEntrypoint.sol";
// ============ External Imports ============
import {Ownable} from "solady/auth/Ownable.sol";
import {Initializable} from "solady/utils/Initializable.sol";
import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol";
import {ReentrancyGuardTransient} from "solady/utils/ReentrancyGuardTransient.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
contract Vault is Initializable, Ownable, UUPSUpgradeable, ReentrancyGuardTransient, IVault, LiquidityShares {
MarketParams public ctx;
address public operator;
address public gasCrank;
uint256 public gasFeeOutMax;
uint256 public gasCrankCooldown;
uint256 public lastCrankTime;
IMarginAccount public marginAccount;
using SafeTransferLib for address;
// ============ AUTH ==================
function _guardInitializeOwner() internal pure override returns (bool guard) {
guard = true;
}
/**
* @dev Makes sure owner is the one upgrading contract
*/
function _authorizeUpgrade(address) internal view override {
_checkOwner();
}
function _verifyOperator() internal view {
require(msg.sender == operator, "Vault: not operator");
}
function _verifyGasCrank() internal view {
require(msg.sender == gasCrank, "Vault: not gas crank");
}
// ============ Initializer ============
function initialize(
address _owner,
address _operator,
address _gasCrank,
address _targetMarket,
address _marginAccount,
uint256 _unlockInterval,
uint256 _gasFeeOutMax,
uint256 _gasCrankCooldown
) public initializer {
require(_operator != address(0), Errors.InvalidInput());
require(_gasCrank != address(0), Errors.InvalidInput());
require(_targetMarket != address(0), Errors.InvalidInput());
require(_marginAccount != address(0), Errors.InvalidInput());
require(_unlockInterval > 0, Errors.InvalidInput());
require(_gasFeeOutMax > 0 && _gasFeeOutMax <= 10000, Errors.InvalidInput());
require(_gasCrankCooldown > 0, Errors.InvalidInput());
_initializeOwner(_owner);
_populateCtx(_targetMarket);
operator = _operator;
gasCrank = _gasCrank;
marginAccount = IMarginAccount(_marginAccount);
unlockInterval = _unlockInterval;
gasFeeOutMax = _gasFeeOutMax;
gasCrankCooldown = _gasCrankCooldown;
if (ctx.base != address(0)) {
IERC20Metadata(ctx.base).approve(address(marginAccount), type(uint256).max);
}
if (ctx.quote != address(0)) {
IERC20Metadata(ctx.quote).approve(address(marginAccount), type(uint256).max);
}
}
// ============ Admin operations ===================
function setUnlockInterval(uint256 _unlockInterval) external onlyOwner {
unlockInterval = _unlockInterval;
}
function setGasParams(address _gasCrank, uint256 _gasFeeOutMax, uint256 _gasCrankCooldown) external onlyOwner {
if (_gasCrank != address(0)) {
gasCrank = _gasCrank;
}
if (_gasFeeOutMax != 0) {
gasFeeOutMax = _gasFeeOutMax;
}
if (_gasCrankCooldown != 0) {
gasCrankCooldown = _gasCrankCooldown;
}
}
// ============ User Operations ====================
function previewDepositInShares(uint256 _baseAmount, uint256 _quoteAmount) external view returns (uint256) {
(uint256 _baseAmountNotional, uint256 _quoteAmountNotional) = calculateNotionalValue();
(uint256 _shares,,) =
_calculateSharesToMint(_baseAmount, _baseAmountNotional, _quoteAmount, _quoteAmountNotional);
return _shares;
}
function previewDepositInAmounts(uint256 _shares) external view returns (uint256, uint256) {
(uint256 _baseAmountNotional, uint256 _quoteAmountNotional) = calculateNotionalValue();
return _calculateAmountForShares(_shares, totalSupply(), _baseAmountNotional, _quoteAmountNotional, true);
}
function previewWithdrawInShares(uint256 _baseAmount, uint256 _quoteAmount) external view returns (uint256) {
(uint256 _baseAmountNotional, uint256 _quoteAmountNotional) = calculateNotionalValue();
return _calculateSharesToBurn(_baseAmount, _baseAmountNotional, _quoteAmount, _quoteAmountNotional);
}
function previewWithdrawInAmounts(uint256 _shares) external view returns (uint256, uint256) {
(uint256 _baseAmountNotional, uint256 _quoteAmountNotional) = calculateNotionalValue();
return _calculateAmountForShares(_shares, totalSupply(), _baseAmountNotional, _quoteAmountNotional, false);
}
function depositSingleSide(uint256 _totalAmountToPull, uint256 _amountToSwap, uint256 _minOut, bool _isBaseAsset)
external
payable
nonReentrant
returns (uint256)
{
require(_amountToSwap > 0 && _totalAmountToPull > _amountToSwap, Errors.InvalidInput());
MarketParams memory _ctx = ctx;
uint256 _prevBaseBalance = _currentBalance(_ctx.base, true);
uint256 _prevQuoteBalance = _currentBalance(_ctx.quote, true);
address _tokenToSwap = _isBaseAsset ? _ctx.base : _ctx.quote;
uint256 _value;
if (_tokenToSwap != address(0)) {
_tokenToSwap.safeTransferFrom(msg.sender, address(this), _totalAmountToPull);
_tokenToSwap.safeApprove(address(_ctx.book), _amountToSwap);
} else {
require(msg.value == _totalAmountToPull, Errors.NativeAssetInsufficient());
_value = _amountToSwap;
}
if (_isBaseAsset) {
_ctx.book.placeAndExecuteMarketSell{value: _value}(
toU96(_amountToSwap * _ctx.sizePrecision / 10 ** _ctx.baseDecimals), _minOut, false, true
);
} else {
_ctx.book.placeAndExecuteMarketBuy{value: _value}(
toU96(_amountToSwap * _ctx.pricePrecision / 10 ** _ctx.quoteDecimals), _minOut, false, true
);
}
if (_tokenToSwap != address(0)) {
_tokenToSwap.safeApprove(address(_ctx.book), 0);
}
(uint256 _baseAmountNotional, uint256 _quoteAmountNotional) = calculateNotionalValue();
uint256 _sharesToMint;
uint256 _requiredBaseAmount = _currentBalance(_ctx.base, false) - _prevBaseBalance;
uint256 _requiredQuoteAmount = _currentBalance(_ctx.quote, false) - _prevQuoteBalance;
(_sharesToMint, _requiredBaseAmount, _requiredQuoteAmount) =
_calculateSharesToMint(_requiredBaseAmount, _baseAmountNotional, _requiredQuoteAmount, _quoteAmountNotional);
require(_sharesToMint > 0, Errors.SharesMintedZero());
_mint(msg.sender, _sharesToMint);
lastDepositTime[msg.sender] = block.timestamp;
_depositToMarginAccountSingle(_requiredBaseAmount, _ctx.base);
_depositToMarginAccountSingle(_requiredQuoteAmount, _ctx.quote);
emit Events.ActiveVaultDeposit(msg.sender, _requiredBaseAmount, _requiredQuoteAmount, _sharesToMint);
// Calculate refund, underflows + reverts if excess consumed
_requiredBaseAmount = _currentBalance(_ctx.base, false) - _prevBaseBalance;
_requiredQuoteAmount = _currentBalance(_ctx.quote, false) - _prevQuoteBalance;
if (_requiredBaseAmount > 0) {
_sendToRecipient(_requiredBaseAmount, _ctx.base, msg.sender);
}
if (_requiredQuoteAmount > 0) {
_sendToRecipient(_requiredQuoteAmount, _ctx.quote, msg.sender);
}
return _sharesToMint;
}
function withdrawSingleSide(uint256 _shares, bool _isBaseForSwap, uint256 _minOut)
external
nonReentrant
returns (uint256, uint256)
{
require(_shares > 0, Errors.SharesBurnedZero());
require(lastDepositTime[msg.sender] + unlockInterval < block.timestamp, Locked());
MarketParams memory _ctx = ctx;
uint256 _prevBaseBalance = _currentBalance(_ctx.base, true);
uint256 _prevQuoteBalance = _currentBalance(_ctx.quote, true);
(uint256 _restingBaseAmount, uint256 _restingQuoteAmount) = getRestingBalances();
(uint256 _postedBaseAmount, uint256 _postedQuoteAmount) = getPostedBalances();
(uint256 _baseAmountForWithdraw, uint256 _quoteAmountForWithdraw) = _calculateAmountForShares(
_shares,
totalSupply(),
_restingBaseAmount + _postedBaseAmount,
_restingQuoteAmount + _postedQuoteAmount,
false
);
if (_baseAmountForWithdraw > _restingBaseAmount || _quoteAmountForWithdraw > _restingQuoteAmount) {
revert Errors.WithdrawalExceedsRestingBalance();
}
_burn(msg.sender, _shares);
_withdrawFromMarginAccountSingle(_baseAmountForWithdraw, _ctx.base);
_withdrawFromMarginAccountSingle(_quoteAmountForWithdraw, _ctx.quote);
uint256 _value;
if (_isBaseForSwap) {
if (_ctx.base == address(0)) {
_value = _baseAmountForWithdraw;
} else {
_ctx.base.safeApprove(address(_ctx.book), _baseAmountForWithdraw);
}
} else if (!_isBaseForSwap) {
if (_ctx.quote == address(0)) {
_value = _quoteAmountForWithdraw;
} else {
_ctx.quote.safeApprove(address(_ctx.book), _quoteAmountForWithdraw);
}
}
if (_isBaseForSwap) {
_ctx.book.placeAndExecuteMarketSell{value: _value}(
toU96(_baseAmountForWithdraw * _ctx.sizePrecision / 10 ** _ctx.baseDecimals), 0, false, true
);
} else {
_ctx.book.placeAndExecuteMarketBuy{value: _value}(
toU96(_quoteAmountForWithdraw * _ctx.pricePrecision / 10 ** _ctx.quoteDecimals), 0, false, true
);
}
if (_isBaseForSwap && _ctx.base != address(0)) {
_ctx.base.safeApprove(address(_ctx.book), 0);
} else if (!_isBaseForSwap && _ctx.quote != address(0)) {
_ctx.quote.safeApprove(address(_ctx.book), 0);
}
uint256 _requiredBaseAmount = _currentBalance(_ctx.base, false) - _prevBaseBalance;
uint256 _requiredQuoteAmount = _currentBalance(_ctx.quote, false) - _prevQuoteBalance;
require(
_isBaseForSwap && _requiredQuoteAmount >= _minOut || !_isBaseForSwap && _requiredBaseAmount >= _minOut,
Errors.WithdrawSwapMinOutNotMet()
);
if (_requiredBaseAmount > 0) {
_sendToRecipient(_requiredBaseAmount, _ctx.base, msg.sender);
}
if (_requiredQuoteAmount > 0) {
_sendToRecipient(_requiredQuoteAmount, _ctx.quote, msg.sender);
}
emit Events.ActiveVaultWithdraw(msg.sender, _baseAmountForWithdraw, _quoteAmountForWithdraw, _shares);
return (_baseAmountForWithdraw, _quoteAmountForWithdraw);
}
function deposit(uint256 _baseAmount, uint256 _quoteAmount) external payable nonReentrant returns (uint256) {
require(
(ctx.base == address(0) || ctx.quote == address(0))
? msg.value == (ctx.base == address(0) ? _baseAmount : _quoteAmount)
: msg.value == 0,
Errors.NativeAssetMismatch()
);
return _depositAndMint(_baseAmount, _quoteAmount);
}
function _depositAndMint(uint256 _baseAmount, uint256 _quoteAmount) internal returns (uint256) {
(uint256 _baseAmountNotional, uint256 _quoteAmountNotional) = calculateNotionalValue();
uint256 _shares;
(_shares, _baseAmount, _quoteAmount) =
_calculateSharesToMint(_baseAmount, _baseAmountNotional, _quoteAmount, _quoteAmountNotional);
require(_shares > 0, Errors.SharesMintedZero());
_mint(msg.sender, _shares);
lastDepositTime[msg.sender] = block.timestamp;
uint256 _nativeRefund;
if (ctx.base == address(0)) {
_nativeRefund = msg.value - _baseAmount;
} else if (ctx.quote == address(0)) {
_nativeRefund = msg.value - _quoteAmount;
}
_depositToMarginAccount(_baseAmount, _quoteAmount);
if (_nativeRefund > 0) {
_sendToRecipient(_nativeRefund, address(0), msg.sender);
}
emit Events.ActiveVaultDeposit(msg.sender, _baseAmount, _quoteAmount, _shares);
return _shares;
}
function withdraw(uint256 _shares) external nonReentrant returns (uint256, uint256) {
require(_shares > 0, Errors.SharesBurnedZero());
require(lastDepositTime[msg.sender] + unlockInterval < block.timestamp, Locked());
(uint256 _restingBaseAmount, uint256 _restingQuoteAmount) = getRestingBalances();
(uint256 _postedBaseAmount, uint256 _postedQuoteAmount) = getPostedBalances();
(uint256 _baseAmountForWithdraw, uint256 _quoteAmountForWithdraw) = _calculateAmountForShares(
_shares,
totalSupply(),
_restingBaseAmount + _postedBaseAmount,
_restingQuoteAmount + _postedQuoteAmount,
false
);
if (_baseAmountForWithdraw > _restingBaseAmount || _quoteAmountForWithdraw > _restingQuoteAmount) {
revert Errors.WithdrawalExceedsRestingBalance();
}
_burn(msg.sender, _shares);
_withdrawFromMarginAccount(_baseAmountForWithdraw, _quoteAmountForWithdraw, msg.sender);
emit Events.ActiveVaultWithdraw(msg.sender, _baseAmountForWithdraw, _quoteAmountForWithdraw, _shares);
return (_baseAmountForWithdraw, _quoteAmountForWithdraw);
}
// ================== accounting ===================
function calculateNotionalValue() public view returns (uint256, uint256) {
(uint256 _baseAmountResting, uint256 _quoteAmountResting) = getRestingBalances();
(uint256 _baseAmountPosted, uint256 _quoteAmountPosted) = getPostedBalances();
return (_baseAmountResting + _baseAmountPosted, _quoteAmountResting + _quoteAmountPosted);
}
function getRestingBalances() public view returns (uint256 baseAmount, uint256 quoteAmount) {
baseAmount = marginAccount.getBalance(address(this), ctx.base);
quoteAmount = marginAccount.getBalance(address(this), ctx.quote);
}
function getPostedBalances() public view returns (uint256 baseAmountPosted, uint256 quoteAmountPosted) {
uint40 current = ctx.head;
uint40 tail = ctx.tail;
if (current == 0) return (0, 0);
while (current <= tail) {
(uint256 _orderValue, bool _isBuy) = calculateCurrentOrderValue(current);
if (_isBuy) {
quoteAmountPosted += _orderValue;
} else {
baseAmountPosted += _orderValue;
}
current++;
}
}
function calculateCurrentOrderValue(uint40 _orderId) internal view returns (uint256, bool) {
(, uint96 _size,,,, uint32 _price,, bool _isBuy) = ctx.book.s_orders(_orderId);
(uint40 _ppHead,) = _isBuy ? ctx.book.s_buyPricePoints(_price) : ctx.book.s_sellPricePoints(_price);
if (_ppHead > _orderId) {
return (0, _isBuy);
}
uint256 _orderValue;
if (_isBuy) {
_orderValue = ((uint256(_price) * _size / ctx.sizePrecision) * 10 ** ctx.quoteDecimals) / ctx.pricePrecision;
} else {
_orderValue = (uint256(_size) * 10 ** ctx.baseDecimals) / ctx.sizePrecision;
}
return (_orderValue, _isBuy);
}
// ============ gas crank functions ============
function crankGas(uint256 _baseWithdraw, uint256 _quoteWithdraw) external {
_verifyGasCrank();
if (block.timestamp < lastCrankTime + gasCrankCooldown) {
revert Errors.GasCrankCooldown();
}
(uint256 _baseAmountTotal, uint256 _quoteAmountTotal) = calculateNotionalValue();
uint256 _baseAmountMaxWithdrawable = _baseAmountTotal * gasFeeOutMax / 10000;
uint256 _quoteAmountMaxWithdrawable = _quoteAmountTotal * gasFeeOutMax / 10000;
if (_baseWithdraw > _baseAmountMaxWithdrawable || _quoteWithdraw > _quoteAmountMaxWithdrawable) {
revert Errors.GasCrankWithdrawExceedsMax();
}
lastCrankTime = block.timestamp;
_withdrawFromMarginAccount(_baseWithdraw, _quoteWithdraw, gasCrank);
emit Events.GasCrankWithdraw(gasCrank, _baseWithdraw, _quoteWithdraw);
}
// ============ market making functions ============
function cancelAllReplace(
uint32[] calldata buyPrices,
uint32[] calldata sellPrices,
uint96[] calldata buySizes,
uint96[] calldata sellSizes
) external {
_verifyOperator();
if (buyPrices.length != buySizes.length || sellPrices.length != sellSizes.length) {
revert Errors.InvalidLength();
}
MarketParams memory _ctx = ctx;
if (_ctx.head != 0) {
uint40[] memory _cancelIds = new uint40[](_ctx.tail - _ctx.head + 1);
for (uint40 i = _ctx.head; i <= _ctx.tail; i++) {
_cancelIds[i - _ctx.head] = i;
}
_ctx.book.batchUpdate(new uint32[](0), new uint96[](0), new uint32[](0), new uint96[](0), _cancelIds, true);
}
if (buyPrices.length > 0 || sellPrices.length > 0) {
uint40 _oldCounter = _ctx.book.s_orderIdCounter();
try _ctx.book.batchUpdate(buyPrices, buySizes, sellPrices, sellSizes, new uint40[](0), true) {
uint40 _newCounter = _ctx.book.s_orderIdCounter();
ctx.head = _oldCounter + 1;
ctx.tail = _newCounter;
} catch {
ctx.head = 0;
ctx.tail = 0;
}
} else {
ctx.head = 0;
ctx.tail = 0;
}
}
// ============ Internal Functions ============
function _withdrawFromMarginAccount(uint256 _baseAmount, uint256 _quoteAmount, address _recipient) internal {
address _base = ctx.base;
address _quote = ctx.quote;
_withdrawFromMarginAccountSingle(_baseAmount, _base);
_withdrawFromMarginAccountSingle(_quoteAmount, _quote);
_sendToRecipient(_baseAmount, _base, _recipient);
_sendToRecipient(_quoteAmount, _quote, _recipient);
}
function _depositToMarginAccount(uint256 _baseAmount, uint256 _quoteAmount) internal {
address _base = ctx.base;
address _quote = ctx.quote;
if (_base != address(0)) {
_receiveTokensFromAddress(_base, _baseAmount);
}
if (_quote != address(0)) {
_receiveTokensFromAddress(_quote, _quoteAmount);
}
_depositToMarginAccountSingle(_baseAmount, _base);
_depositToMarginAccountSingle(_quoteAmount, _quote);
}
function _currentBalance(address _token, bool _includeMsgValue) internal view returns (uint256) {
if (_token == address(0)) {
return address(this).balance - (_includeMsgValue ? msg.value : 0);
}
return IERC20Metadata(_token).balanceOf(address(this));
}
function _withdrawFromMarginAccountSingle(uint256 _amount, address _token) internal {
marginAccount.withdraw(_amount, _token);
}
function _receiveTokensFromAddress(address _token, uint256 _amount) internal {
_token.safeTransferFrom(msg.sender, address(this), _amount);
}
function _sendToRecipient(uint256 _amount, address _token, address _recipient) internal {
if (_token == address(0)) {
_recipient.safeTransferETH(_amount);
return;
}
_token.safeTransfer(_recipient, _amount);
}
function _depositToMarginAccountSingle(uint256 _amount, address _token) internal {
if (_token == address(0)) {
marginAccount.deposit{value: _amount}(address(this), _token, _amount);
return;
}
marginAccount.deposit(address(this), _token, _amount);
}
function _populateCtx(address _targetMarket) internal {
ctx.book = IOrderBook(_targetMarket);
(
uint32 pricePrecision,
uint96 sizePrecision,
address base,
uint256 baseDecimals,
address quote,
uint256 quoteDecimals,
,
,
,
,
) = ctx.book.getMarketParams();
ctx.pricePrecision = pricePrecision;
ctx.sizePrecision = sizePrecision;
ctx.base = base;
ctx.baseDecimals = uint8(baseDecimals);
ctx.quote = quote;
ctx.quoteDecimals = uint8(quoteDecimals);
}
function toU96(uint256 _from) internal pure returns (uint96 _to) {
require((_to = uint96(_from)) == _from, Errors.Uint96Overflow());
}
receive() external payable {}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IOrderBook {
enum OrderBookType {
NO_NATIVE,
NATIVE_IN_BASE,
NATIVE_IN_QUOTE
}
struct Order {
address ownerAddress;
uint96 size;
uint40 prev;
uint40 next;
uint40 flippedId;
uint32 price;
uint32 flippedPrice;
bool isBuy;
}
/**
* @dev Emitted for each cancel
*/
event OrderCanceled(uint40 orderId, address owner, uint32 price, uint96 size, bool isBuy);
/**
* @dev Emitted when a new order is created.
* @param orderId Unique identifier for the newly created order.
* @param owner Address of the user who created the order.
* @param price Price point of the order in the specified precision.
* @param size Size of the order in the specified precision.
* @param isBuy Boolean indicating if the order is a buy (true) or sell (false) order.
*/
event OrderCreated(uint40 orderId, address owner, uint96 size, uint32 price, bool isBuy);
/**
* @dev Emitted when a flip order is created
* @param orderId Unique identifier for the newly created order.
* @param flippedId Unique identifier for the flipped order.
* @param owner Address of the user who created the order.
* @param size Size of the order in the specified precision.
* @param price Price point of the order in the specified precision.
* @param flippedPrice Price point of the flipped order in the specified precision.
* @param isBuy Boolean indicating if the order is a buy (true) or sell (false) order.
*/
event FlipOrderCreated(
uint40 orderId, uint40 flippedId, address owner, uint96 size, uint32 price, uint32 flippedPrice, bool isBuy
);
/**
* @dev Emitted when a flip order is partially/completely filled and it results in a new order
* @param orderId Unique identifier for the newly created order.
* @param flippedId Unique identifier for the flipped order.
* @param owner Address of the user who created the order.
* @param size Size of the order in the specified precision.
* @param price Price point of the order in the specified precision.
* @param flippedPrice Price point of the flipped order in the specified precision.
* @param isBuy Boolean indicating if the order is a buy (true) or sell (false) order.
*/
event FlippedOrderCreated(
uint40 orderId, uint40 flippedId, address owner, uint96 size, uint32 price, uint32 flippedPrice, bool isBuy
);
/**
* @dev Emitted when a flip order is updated
* @param orderId Unique identifier for the order.
* @param size Size of the order in the specified precision.
*/
event FlipOrderUpdated(uint40 orderId, uint96 size);
/**
* @dev Emitted when one or more flip orders are canceled
* @param orderIds Array of order identifiers that were canceled.
* @param owner Address of the user who canceled the orders.
*/
event FlipOrdersCanceled(uint40[] orderIds, address owner);
/**
* @dev Emitted when one or more orders are completed or canceled.
* @param orderId Array of order identifiers that were completed or canceled.
*/
event OrdersCanceled(uint40[] orderId, address owner);
/**
*
* @dev Emitted when a trade goes through.
* @param orderId Order Id of the order that was filled.
* PS. All data regarding the original order can be found out from the order ID
* @param updatedSize New size of the order
* @param takerAddress Address of the taker.
* @param filledSize Size taken by the taker.
*/
event Trade(
uint40 orderId,
address makerAddress,
bool isBuy,
uint256 price,
uint96 updatedSize,
address takerAddress,
address txOrigin,
uint96 filledSize
);
function initialize(
address _factory,
OrderBookType _type,
address _baseAssetAddress,
uint256 _baseAssetDecimals,
address _quoteAssetAddress,
uint256 _quoteAssetDecimals,
address _marginAccountAddress,
uint96 _sizePrecision,
uint32 _pricePrecision,
uint32 _tickSize,
uint96 _minSize,
uint96 _maxSize,
uint256 _takerFeeBps,
uint256 _makerFeeBps,
address _kuruAmmVault,
uint96 _kuruAmmSpread,
address __trustedForwarder
) external;
function s_orderIdCounter() external returns (uint40);
function s_orders(uint40 _orderId)
external
view
returns (
address _user,
uint96 _size,
uint40 _prev,
uint40 _next,
uint40 _flippedId,
uint32 _price,
uint32 _flippedPrice,
bool _isBuy
);
function s_buyPricePoints(uint256 _price) external view returns (uint40, uint40);
function s_sellPricePoints(uint256 _price) external view returns (uint40, uint40);
function toggleMarkets(bool _state) external;
function addBuyOrder(uint32 _price, uint96 size, bool _postOnly) external;
function addFlipBuyOrder(uint32 _price, uint32 _flippedPrice, uint96 _size, bool _provisionOrRevert) external;
function addSellOrder(uint32 _price, uint96 size, bool _postOnly) external;
function addFlipSellOrder(uint32 _price, uint32 _flippedPrice, uint96 _size, bool _provisionOrRevert) external;
function batchCancelOrders(uint40[] calldata _orderIds) external;
function batchCancelFlipOrders(uint40[] calldata _orderIds) external;
function batchUpdate(
uint32[] calldata buyPrices,
uint96[] calldata buySizes,
uint32[] calldata sellPrices,
uint96[] calldata sellSizes,
uint40[] calldata orderIdsToCancel,
bool postOnly
) external;
function placeMultipleBuyOrders(uint32[] memory _prices, uint96[] memory _sizes, bool _postOnly) external;
function placeMultipleSellOrders(uint32[] memory _prices, uint96[] memory _sizes, bool _postOnly) external;
function placeAndExecuteMarketBuy(uint96 _quoteAmount, uint256 _minAmountOut, bool _isMargin, bool _isFillOrKill)
external
payable
returns (uint256);
function placeAndExecuteMarketSell(uint96 _size, uint256 _minAmountOut, bool _isMargin, bool _isFillOrKill)
external
payable
returns (uint256);
function bestBidAsk() external view returns (uint256, uint256);
function updateVaultOrdSz(uint96 _askSize, uint96 _bidSize, uint256 _askPrice, uint256 _bidPrice) external;
function getMarketParams()
external
view
returns (uint32, uint96, address, uint256, address, uint256, uint32, uint96, uint96, uint256, uint256);
function getVaultParams()
external
view
returns (address, uint256, uint96, uint256, uint96, uint96, uint96, uint96);
function vaultAskOrderSize() external view returns (uint96);
function vaultBestAsk() external view returns (uint256);
function owner() external view returns (address);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
// ============ External Imports ============
import {IOrderBook} from "./IOrderBook.sol";
interface IVault {
struct MarketParams {
IOrderBook book;
uint32 pricePrecision;
uint8 baseDecimals;
uint8 quoteDecimals;
address base;
uint96 sizePrecision;
address quote;
uint40 head;
uint40 tail;
}
struct Order {
uint40 prev;
uint40 next;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IMarginAccount {
function updateMarkets(address _marketAddress) external;
function deposit(address _user, address _token, uint256 _amount) external payable;
function withdraw(uint256 _amount, address _token) external;
function debitUser(address _user, address _token, uint256 _amount) external;
function creditFee(address _assetA, uint256 _feeA, address _assetB, uint256 _feeB) external returns (bool);
function creditUser(address _user, address _token, uint256 _amount, bool _useMargin) external returns (bool);
function creditUsersEncoded(bytes calldata _encodedData) external returns (bool);
function getBalance(address _user, address _token) external view returns (uint256);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
library Errors {
error InvalidLength();
error InvalidInput();
error SwapFailed();
error NativeAssetMismatch();
error NativeAssetInsufficient();
error SharesMintedZero();
error SharesBurnedZero();
error NativeTransferFailed();
error WithdrawalExceedsRestingBalance();
error WithdrawSwapMinOutNotMet();
error GasCrankCooldown();
error GasCrankWithdrawExceedsMax();
error Uint96Overflow();
}
library Events {
event ActiveVaultDeposit(address user, uint256 baseAmount, uint256 quoteAmount, uint256 sharesMinted);
event ActiveVaultWithdraw(address user, uint256 baseAmount, uint256 quoteAmount, uint256 sharesBurned);
event GasCrankWithdraw(address gasCrank, uint256 baseAmount, uint256 quoteAmount);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {ERC20} from "solady/tokens/ERC20.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
abstract contract LiquidityShares is ERC20 {
uint8 internal constant PRECISION = 18;
uint256 public unlockInterval;
mapping(address user => uint256 timestamp) public lastDepositTime;
error Locked();
event Deposit(address indexed user, uint256 baseAmount, uint256 quoteAmount, uint256 sharesMinted);
event Withdraw(address indexed user, uint256 baseAmount, uint256 quoteAmount, uint256 sharesBurned);
function name() public pure override returns (string memory) {
return "Kuru Vault";
}
function symbol() public pure override returns (string memory) {
return "KURU-VAULT";
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
if (lastDepositTime[msg.sender] + unlockInterval > block.timestamp) {
revert Locked();
}
return super.transfer(to, amount);
}
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
if (lastDepositTime[from] + unlockInterval > block.timestamp) {
revert Locked();
}
return super.transferFrom(from, to, amount);
}
function _calculateSharesToMint(
uint256 _baseAmountToDeposit,
uint256 _baseAmountNotional,
uint256 _quoteAmountToDeposit,
uint256 _quoteAmountNotional
) internal view returns (uint256, uint256, uint256) {
uint256 _totalSupply = totalSupply();
uint256 _sharesWithBase = _toShares(_baseAmountToDeposit, _totalSupply, _baseAmountNotional, false);
uint256 _sharesWithQuote = _toShares(_quoteAmountToDeposit, _totalSupply, _quoteAmountNotional, false);
uint256 _effectiveOutShares = FixedPointMathLib.min(_sharesWithBase, _sharesWithQuote);
if (_totalSupply == 0) {
return (_effectiveOutShares, _baseAmountToDeposit, _quoteAmountToDeposit);
}
if (_effectiveOutShares == _sharesWithBase) {
// testing mode
_quoteAmountToDeposit = _toAmount(_sharesWithBase, _totalSupply, _quoteAmountNotional, true);
_effectiveOutShares = FixedPointMathLib.min(
_toShares(_baseAmountToDeposit, _totalSupply, _baseAmountNotional, false),
_toShares(_quoteAmountToDeposit, _totalSupply, _quoteAmountNotional, false)
);
return (_effectiveOutShares, _baseAmountToDeposit, _quoteAmountToDeposit);
} else {
// testing mode
_baseAmountToDeposit = _toAmount(_effectiveOutShares, _totalSupply, _baseAmountNotional, true);
_effectiveOutShares = FixedPointMathLib.min(
_toShares(_baseAmountToDeposit, _totalSupply, _baseAmountNotional, false),
_toShares(_quoteAmountToDeposit, _totalSupply, _quoteAmountNotional, false)
);
return (_effectiveOutShares, _baseAmountToDeposit, _quoteAmountToDeposit);
}
}
function _calculateSharesToBurn(
uint256 _baseAmountToWithdraw,
uint256 _baseAmountNotional,
uint256 _quoteAmountToWithdraw,
uint256 _quoteAmountNotional
) internal view returns (uint256) {
uint256 _totalSupply = totalSupply();
return FixedPointMathLib.min(
_toShares(_baseAmountToWithdraw, _totalSupply, _baseAmountNotional, true),
_toShares(_quoteAmountToWithdraw, _totalSupply, _quoteAmountNotional, true)
);
}
function _calculateAmountForShares(
uint256 _shares,
uint256 _totalSupply,
uint256 _baseNotional,
uint256 _quoteNotional,
bool _isDeposit
) internal pure returns (uint256, uint256) {
uint256 _baseAmount = _toAmount(_shares, _totalSupply, _baseNotional, _isDeposit);
uint256 _quoteAmount = _toAmount(_shares, _totalSupply, _quoteNotional, _isDeposit);
return (_baseAmount, _quoteAmount);
}
/// @notice Calculates the base value in relationship to `elastic` and `total`.
function _toShares(uint256 amount, uint256 totalShares_, uint256 totalAmount, bool roundUp)
internal
pure
returns (uint256 share)
{
// To prevent reseting the ratio due to withdrawal of all shares, we start with
// 1 amount/1e8 shares already burned. This also starts with a 1 : 1e8 ratio which
// functions like 8 decimal fixed point math. This prevents ratio attacks or inaccuracy
// due to 'gifting' or rebasing tokens. (Up to a certain degree)
totalAmount++;
totalShares_ += 1e8;
// Calculte the shares using te current amount to share ratio
share = (amount * totalShares_) / totalAmount;
// Default is to round down (Solidity), round up if required
if (roundUp && (share * totalAmount) / totalShares_ < amount) {
share++;
}
}
/// @notice Calculates the elastic value in relationship to `base` and `total`.
function _toAmount(uint256 share, uint256 totalShares_, uint256 totalAmount, bool roundUp)
internal
pure
returns (uint256 amount)
{
// To prevent reseting the ratio due to withdrawal of all shares, we start with
// 1 amount/1e8 shares already burned. This also starts with a 1 : 1e8 ratio which
// functions like 8 decimal fixed point math. This prevents ratio attacks or inaccuracy
// due to 'gifting' or rebasing tokens. (Up to a certain degree)
totalAmount++;
totalShares_ += 1e8;
// Calculte the amount using te current amount to share ratio
amount = (share * totalAmount) / totalShares_;
// Default is to round down (Solidity), round up if required
if (roundUp && (amount * totalShares_) / totalAmount < share) {
amount++;
}
}
}//SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IKuruFlowEntrypoint {
struct SwapIntent {
address tokenUserBuys;
uint256 minAmountUserBuys;
address tokenUserSells;
uint256 amountUserSells;
}
struct FeeCollection {
address feeCollectorAddress;
uint256 feeBps;
address referrerAddress;
uint256 referrerFeeBps;
bool isInTokenFee;
}
function executeSwap(SwapIntent calldata swapIntent, FeeCollection calldata feeCollection, bytes calldata program)
external
payable
returns (uint256 amountOut);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
///
/// @dev Note:
/// This implementation does NOT auto-initialize the owner to `msg.sender`.
/// You MUST call the `_initializeOwner` in the constructor / initializer.
///
/// While the ownable portion follows
/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
/// the nomenclature for the 2-step ownership handover may be unique to this codebase.
abstract contract Ownable {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The caller is not authorized to call the function.
error Unauthorized();
/// @dev The `newOwner` cannot be the zero address.
error NewOwnerIsZeroAddress();
/// @dev The `pendingOwner` does not have a valid handover request.
error NoHandoverRequest();
/// @dev Cannot double-initialize.
error AlreadyInitialized();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ownership is transferred from `oldOwner` to `newOwner`.
/// This event is intentionally kept the same as OpenZeppelin's Ownable to be
/// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
/// despite it not being as lightweight as a single argument event.
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
/// @dev An ownership handover to `pendingOwner` has been requested.
event OwnershipHandoverRequested(address indexed pendingOwner);
/// @dev The ownership handover to `pendingOwner` has been canceled.
event OwnershipHandoverCanceled(address indexed pendingOwner);
/// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;
/// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;
/// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The owner slot is given by:
/// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
/// It is intentionally chosen to be a high value
/// to avoid collision with lower slots.
/// The choice of manual storage layout is to enable compatibility
/// with both regular and upgradeable contracts.
bytes32 internal constant _OWNER_SLOT =
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;
/// The ownership handover slot of `newOwner` is given by:
/// ```
/// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
/// let handoverSlot := keccak256(0x00, 0x20)
/// ```
/// It stores the expiry timestamp of the two-step ownership handover.
uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
function _guardInitializeOwner() internal pure virtual returns (bool guard) {}
/// @dev Initializes the owner directly without authorization guard.
/// This function must be called upon initialization,
/// regardless of whether the contract is upgradeable or not.
/// This is to enable generalization to both regular and upgradeable contracts,
/// and to save gas in case the initial owner is not the caller.
/// For performance reasons, this function will not check if there
/// is an existing owner.
function _initializeOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
if sload(ownerSlot) {
mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
revert(0x1c, 0x04)
}
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
} else {
/// @solidity memory-safe-assembly
assembly {
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(_OWNER_SLOT, newOwner)
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
}
}
/// @dev Sets the owner directly without authorization guard.
function _setOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
}
} else {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, newOwner)
}
}
}
/// @dev Throws if the sender is not the owner.
function _checkOwner() internal view virtual {
/// @solidity memory-safe-assembly
assembly {
// If the caller is not the stored owner, revert.
if iszero(eq(caller(), sload(_OWNER_SLOT))) {
mstore(0x00, 0x82b42900) // `Unauthorized()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Returns how long a two-step ownership handover is valid for in seconds.
/// Override to return a different value if needed.
/// Made internal to conserve bytecode. Wrap it in a public function if needed.
function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
return 48 * 3600;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC UPDATE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Allows the owner to transfer the ownership to `newOwner`.
function transferOwnership(address newOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
if iszero(shl(96, newOwner)) {
mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
revert(0x1c, 0x04)
}
}
_setOwner(newOwner);
}
/// @dev Allows the owner to renounce their ownership.
function renounceOwnership() public payable virtual onlyOwner {
_setOwner(address(0));
}
/// @dev Request a two-step ownership handover to the caller.
/// The request will automatically expire in 48 hours (172800 seconds) by default.
function requestOwnershipHandover() public payable virtual {
unchecked {
uint256 expires = block.timestamp + _ownershipHandoverValidFor();
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to `expires`.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), expires)
// Emit the {OwnershipHandoverRequested} event.
log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
}
}
}
/// @dev Cancels the two-step ownership handover to the caller, if any.
function cancelOwnershipHandover() public payable virtual {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), 0)
// Emit the {OwnershipHandoverCanceled} event.
log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
}
}
/// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
/// Reverts if there is no existing ownership handover requested by `pendingOwner`.
function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
let handoverSlot := keccak256(0x0c, 0x20)
// If the handover does not exist, or has expired.
if gt(timestamp(), sload(handoverSlot)) {
mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
revert(0x1c, 0x04)
}
// Set the handover slot to 0.
sstore(handoverSlot, 0)
}
_setOwner(pendingOwner);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC READ FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the owner of the contract.
function owner() public view virtual returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := sload(_OWNER_SLOT)
}
}
/// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
function ownershipHandoverExpiresAt(address pendingOwner)
public
view
virtual
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
// Compute the handover slot.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
// Load the handover slot.
result := sload(keccak256(0x0c, 0x20))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* MODIFIERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Marks a function as only callable by the owner.
modifier onlyOwner() virtual {
_checkOwner();
_;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Initializable mixin for the upgradeable contracts.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Initializable.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/proxy/utils/Initializable.sol)
abstract contract Initializable {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The contract is already initialized.
error InvalidInitialization();
/// @dev The contract is not initializing.
error NotInitializing();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Triggered when the contract has been initialized.
event Initialized(uint64 version);
/// @dev `keccak256(bytes("Initialized(uint64)"))`.
bytes32 private constant _INITIALIZED_EVENT_SIGNATURE =
0xc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The default initializable slot is given by:
/// `bytes32(~uint256(uint32(bytes4(keccak256("_INITIALIZABLE_SLOT")))))`.
///
/// Bits Layout:
/// - [0] `initializing`
/// - [1..64] `initializedVersion`
bytes32 private constant _INITIALIZABLE_SLOT =
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffbf601132;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTRUCTOR */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
constructor() {
// Construction time check to ensure that `_initializableSlot()` is not
// overridden to zero. Will be optimized away if there is no revert.
require(_initializableSlot() != bytes32(0));
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Override to return a non-zero custom storage slot if required.
function _initializableSlot() internal pure virtual returns (bytes32) {
return _INITIALIZABLE_SLOT;
}
/// @dev Guards an initializer function so that it can be invoked at most once.
///
/// You can guard a function with `onlyInitializing` such that it can be called
/// through a function guarded with `initializer`.
///
/// This is similar to `reinitializer(1)`, except that in the context of a constructor,
/// an `initializer` guarded function can be invoked multiple times.
/// This can be useful during testing and is not expected to be used in production.
///
/// Emits an {Initialized} event.
modifier initializer() virtual {
bytes32 s = _initializableSlot();
/// @solidity memory-safe-assembly
assembly {
let i := sload(s)
// Set `initializing` to 1, `initializedVersion` to 1.
sstore(s, 3)
// If `!(initializing == 0 && initializedVersion == 0)`.
if i {
// If `!(address(this).code.length == 0 && initializedVersion == 1)`.
if iszero(lt(extcodesize(address()), eq(shr(1, i), 1))) {
mstore(0x00, 0xf92ee8a9) // `InvalidInitialization()`.
revert(0x1c, 0x04)
}
s := shl(shl(255, i), s) // Skip initializing if `initializing == 1`.
}
}
_;
/// @solidity memory-safe-assembly
assembly {
if s {
// Set `initializing` to 0, `initializedVersion` to 1.
sstore(s, 2)
// Emit the {Initialized} event.
mstore(0x20, 1)
log1(0x20, 0x20, _INITIALIZED_EVENT_SIGNATURE)
}
}
}
/// @dev Guards a reinitializer function so that it can be invoked at most once.
///
/// You can guard a function with `onlyInitializing` such that it can be called
/// through a function guarded with `reinitializer`.
///
/// Emits an {Initialized} event.
modifier reinitializer(uint64 version) virtual {
bytes32 s = _initializableSlot();
/// @solidity memory-safe-assembly
assembly {
// Clean upper bits, and shift left by 1 to make space for the initializing bit.
version := shl(1, and(version, 0xffffffffffffffff))
let i := sload(s)
// If `initializing == 1 || initializedVersion >= version`.
if iszero(lt(and(i, 1), lt(i, version))) {
mstore(0x00, 0xf92ee8a9) // `InvalidInitialization()`.
revert(0x1c, 0x04)
}
// Set `initializing` to 1, `initializedVersion` to `version`.
sstore(s, or(1, version))
}
_;
/// @solidity memory-safe-assembly
assembly {
// Set `initializing` to 0, `initializedVersion` to `version`.
sstore(s, version)
// Emit the {Initialized} event.
mstore(0x20, shr(1, version))
log1(0x20, 0x20, _INITIALIZED_EVENT_SIGNATURE)
}
}
/// @dev Guards a function such that it can only be called in the scope
/// of a function guarded with `initializer` or `reinitializer`.
modifier onlyInitializing() virtual {
_checkInitializing();
_;
}
/// @dev Reverts if the contract is not initializing.
function _checkInitializing() internal view virtual {
bytes32 s = _initializableSlot();
/// @solidity memory-safe-assembly
assembly {
if iszero(and(1, sload(s))) {
mstore(0x00, 0xd7e6bcf8) // `NotInitializing()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Locks any future initializations by setting the initialized version to `2**64 - 1`.
///
/// Calling this in the constructor will prevent the contract from being initialized
/// or reinitialized. 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 called.
function _disableInitializers() internal virtual {
bytes32 s = _initializableSlot();
/// @solidity memory-safe-assembly
assembly {
let i := sload(s)
if and(i, 1) {
mstore(0x00, 0xf92ee8a9) // `InvalidInitialization()`.
revert(0x1c, 0x04)
}
let uint64max := 0xffffffffffffffff
if iszero(eq(shr(1, i), uint64max)) {
// Set `initializing` to 0, `initializedVersion` to `2**64 - 1`.
sstore(s, shl(1, uint64max))
// Emit the {Initialized} event.
mstore(0x20, uint64max)
log1(0x20, 0x20, _INITIALIZED_EVENT_SIGNATURE)
}
}
}
/// @dev Returns the highest version that has been initialized.
function _getInitializedVersion() internal view virtual returns (uint64 version) {
bytes32 s = _initializableSlot();
/// @solidity memory-safe-assembly
assembly {
version := shr(1, sload(s))
}
}
/// @dev Returns whether the contract is currently initializing.
function _isInitializing() internal view virtual returns (bool result) {
bytes32 s = _initializableSlot();
/// @solidity memory-safe-assembly
assembly {
result := and(1, sload(s))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {CallContextChecker} from "./CallContextChecker.sol";
/// @notice UUPS proxy mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/UUPSUpgradeable.sol)
/// @author Modified from OpenZeppelin
/// (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/utils/UUPSUpgradeable.sol)
///
/// @dev Note:
/// - This implementation is intended to be used with ERC1967 proxies.
/// See: `LibClone.deployERC1967` and related functions.
/// - This implementation is NOT compatible with legacy OpenZeppelin proxies
/// which do not store the implementation at `_ERC1967_IMPLEMENTATION_SLOT`.
abstract contract UUPSUpgradeable is CallContextChecker {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The upgrade failed.
error UpgradeFailed();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Emitted when the proxy's implementation is upgraded.
event Upgraded(address indexed implementation);
/// @dev `keccak256(bytes("Upgraded(address)"))`.
uint256 private constant _UPGRADED_EVENT_SIGNATURE =
0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ERC-1967 storage slot for the implementation in the proxy.
/// `uint256(keccak256("eip1967.proxy.implementation")) - 1`.
bytes32 internal constant _ERC1967_IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* UUPS OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Please override this function to check if `msg.sender` is authorized
/// to upgrade the proxy to `newImplementation`, reverting if not.
/// ```
/// function _authorizeUpgrade(address) internal override onlyOwner {}
/// ```
function _authorizeUpgrade(address newImplementation) internal virtual;
/// @dev Returns the storage slot used by the implementation,
/// as specified in [ERC1822](https://eips.ethereum.org/EIPS/eip-1822).
///
/// Note: The `notDelegated` modifier prevents accidental upgrades to
/// an implementation that is a proxy contract.
function proxiableUUID() public view virtual notDelegated returns (bytes32) {
// This function must always return `_ERC1967_IMPLEMENTATION_SLOT` to comply with ERC1967.
return _ERC1967_IMPLEMENTATION_SLOT;
}
/// @dev Upgrades the proxy's implementation to `newImplementation`.
/// Emits a {Upgraded} event.
///
/// Note: Passing in empty `data` skips the delegatecall to `newImplementation`.
function upgradeToAndCall(address newImplementation, bytes calldata data)
public
payable
virtual
onlyProxy
{
_authorizeUpgrade(newImplementation);
/// @solidity memory-safe-assembly
assembly {
newImplementation := shr(96, shl(96, newImplementation)) // Clears upper 96 bits.
mstore(0x00, returndatasize())
mstore(0x01, 0x52d1902d) // `proxiableUUID()`.
let s := _ERC1967_IMPLEMENTATION_SLOT
// Check if `newImplementation` implements `proxiableUUID` correctly.
if iszero(eq(mload(staticcall(gas(), newImplementation, 0x1d, 0x04, 0x01, 0x20)), s)) {
mstore(0x01, 0x55299b49) // `UpgradeFailed()`.
revert(0x1d, 0x04)
}
// Emit the {Upgraded} event.
log2(codesize(), 0x00, _UPGRADED_EVENT_SIGNATURE, newImplementation)
sstore(s, newImplementation) // Updates the implementation.
// Perform a delegatecall to `newImplementation` if `data` is non-empty.
if data.length {
// Forwards the `data` to `newImplementation` via delegatecall.
let m := mload(0x40)
calldatacopy(m, data.offset, data.length)
if iszero(delegatecall(gas(), newImplementation, m, data.length, codesize(), 0x00))
{
// Bubble up the revert if the call reverts.
returndatacopy(m, 0x00, returndatasize())
revert(m, returndatasize())
}
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice Reentrancy guard mixin (transient storage variant).
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuardTransient.sol)
///
/// @dev Note: This implementation utilizes the `TSTORE` and `TLOAD` opcodes.
/// Please ensure that the chain you are deploying on supports them.
abstract contract ReentrancyGuardTransient {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Unauthorized reentrant call.
error Reentrancy();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Equivalent to: `uint32(bytes4(keccak256("Reentrancy()"))) | 1 << 71`.
/// 9 bytes is large enough to avoid collisions in practice,
/// but not too large to result in excessive bytecode bloat.
uint256 private constant _REENTRANCY_GUARD_SLOT = 0x8000000000ab143c06;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* REENTRANCY GUARD */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Guards a function from reentrancy.
modifier nonReentrant() virtual {
if (_useTransientReentrancyGuardOnlyOnMainnet()) {
uint256 s = _REENTRANCY_GUARD_SLOT;
if (block.chainid == 1) {
/// @solidity memory-safe-assembly
assembly {
if tload(s) {
mstore(0x00, s) // `Reentrancy()`.
revert(0x1c, 0x04)
}
tstore(s, address())
}
} else {
/// @solidity memory-safe-assembly
assembly {
if eq(sload(s), address()) {
mstore(0x00, s) // `Reentrancy()`.
revert(0x1c, 0x04)
}
sstore(s, address())
}
}
} else {
/// @solidity memory-safe-assembly
assembly {
if tload(_REENTRANCY_GUARD_SLOT) {
mstore(0x00, 0xab143c06) // `Reentrancy()`.
revert(0x1c, 0x04)
}
tstore(_REENTRANCY_GUARD_SLOT, address())
}
}
_;
if (_useTransientReentrancyGuardOnlyOnMainnet()) {
uint256 s = _REENTRANCY_GUARD_SLOT;
if (block.chainid == 1) {
/// @solidity memory-safe-assembly
assembly {
tstore(s, 0)
}
} else {
/// @solidity memory-safe-assembly
assembly {
sstore(s, s)
}
}
} else {
/// @solidity memory-safe-assembly
assembly {
tstore(_REENTRANCY_GUARD_SLOT, 0)
}
}
}
/// @dev Guards a view function from read-only reentrancy.
modifier nonReadReentrant() virtual {
if (_useTransientReentrancyGuardOnlyOnMainnet()) {
uint256 s = _REENTRANCY_GUARD_SLOT;
if (block.chainid == 1) {
/// @solidity memory-safe-assembly
assembly {
if tload(s) {
mstore(0x00, s) // `Reentrancy()`.
revert(0x1c, 0x04)
}
}
} else {
/// @solidity memory-safe-assembly
assembly {
if eq(sload(s), address()) {
mstore(0x00, s) // `Reentrancy()`.
revert(0x1c, 0x04)
}
}
}
} else {
/// @solidity memory-safe-assembly
assembly {
if tload(_REENTRANCY_GUARD_SLOT) {
mstore(0x00, 0xab143c06) // `Reentrancy()`.
revert(0x1c, 0x04)
}
}
}
_;
}
/// @dev For widespread compatibility with L2s.
/// Only Ethereum mainnet is expensive anyways.
function _useTransientReentrancyGuardOnlyOnMainnet() internal view virtual returns (bool) {
return true;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)
///
/// @dev Note:
/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
library SafeTransferLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ETH transfer has failed.
error ETHTransferFailed();
/// @dev The ERC20 `transferFrom` has failed.
error TransferFromFailed();
/// @dev The ERC20 `transfer` has failed.
error TransferFailed();
/// @dev The ERC20 `approve` has failed.
error ApproveFailed();
/// @dev The ERC20 `totalSupply` query has failed.
error TotalSupplyQueryFailed();
/// @dev The Permit2 operation has failed.
error Permit2Failed();
/// @dev The Permit2 amount must be less than `2**160 - 1`.
error Permit2AmountOverflow();
/// @dev The Permit2 approve operation has failed.
error Permit2ApproveFailed();
/// @dev The Permit2 lockdown operation has failed.
error Permit2LockdownFailed();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;
/// @dev Suggested gas stipend for contract receiving ETH to perform a few
/// storage reads and writes, but low enough to prevent griefing.
uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;
/// @dev The unique EIP-712 domain separator for the DAI token contract.
bytes32 internal constant DAI_DOMAIN_SEPARATOR =
0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;
/// @dev The address for the WETH9 contract on Ethereum mainnet.
address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
/// @dev The canonical Permit2 address.
/// [Github](https://github.com/Uniswap/permit2)
/// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
/// @dev The canonical address of the `SELFDESTRUCT` ETH mover.
/// See: https://gist.github.com/Vectorized/1cb8ad4cf393b1378e08f23f79bd99fa
/// [Etherscan](https://etherscan.io/address/0x00000000000073c48c8055bD43D1A53799176f0D)
address internal constant ETH_MOVER = 0x00000000000073c48c8055bD43D1A53799176f0D;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ETH OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
//
// The regular variants:
// - Forwards all remaining gas to the target.
// - Reverts if the target reverts.
// - Reverts if the current contract has insufficient balance.
//
// The force variants:
// - Forwards with an optional gas stipend
// (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
// - If the target reverts, or if the gas stipend is exhausted,
// creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
// Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
// - Reverts if the current contract has insufficient balance.
//
// The try variants:
// - Forwards with a mandatory gas stipend.
// - Instead of reverting, returns whether the transfer succeeded.
/// @dev Sends `amount` (in wei) ETH to `to`.
function safeTransferETH(address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Sends all the ETH in the current contract to `to`.
function safeTransferAllETH(address to) internal {
/// @solidity memory-safe-assembly
assembly {
// Transfer all the ETH and check if it succeeded or not.
if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
/// @solidity memory-safe-assembly
assembly {
if lt(selfbalance(), amount) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
/// @solidity memory-safe-assembly
assembly {
if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
function forceSafeTransferETH(address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
if lt(selfbalance(), amount) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
function forceSafeTransferAllETH(address to) internal {
/// @solidity memory-safe-assembly
assembly {
// forgefmt: disable-next-item
if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
}
}
/// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
function trySafeTransferAllETH(address to, uint256 gasStipend)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
}
}
/// @dev Force transfers ETH to `to`, without triggering the fallback (if any).
/// This method attempts to use a separate contract to send via `SELFDESTRUCT`,
/// and upon failure, deploys a minimal vault to accrue the ETH.
function safeMoveETH(address to, uint256 amount) internal returns (address vault) {
/// @solidity memory-safe-assembly
assembly {
to := shr(96, shl(96, to)) // Clean upper 96 bits.
for { let mover := ETH_MOVER } iszero(eq(to, address())) {} {
let selfBalanceBefore := selfbalance()
if or(lt(selfBalanceBefore, amount), eq(to, mover)) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
if extcodesize(mover) {
let balanceBefore := balance(to) // Check via delta, in case `SELFDESTRUCT` is bricked.
mstore(0x00, to)
pop(call(gas(), mover, amount, 0x00, 0x20, codesize(), 0x00))
// If `address(to).balance >= amount + balanceBefore`, skip vault workflow.
if iszero(lt(balance(to), add(amount, balanceBefore))) { break }
// Just in case `SELFDESTRUCT` is changed to not revert and do nothing.
if lt(selfBalanceBefore, selfbalance()) { invalid() }
}
let m := mload(0x40)
// If the mover is missing or bricked, deploy a minimal vault
// that withdraws all ETH to `to` when being called only by `to`.
// forgefmt: disable-next-item
mstore(add(m, 0x20), 0x33146025575b600160005260206000f35b3d3d3d3d47335af1601a5760003dfd)
mstore(m, or(to, shl(160, 0x6035600b3d3960353df3fe73)))
// Compute and store the bytecode hash.
mstore8(0x00, 0xff) // Write the prefix.
mstore(0x35, keccak256(m, 0x40))
mstore(0x01, shl(96, address())) // Deployer.
mstore(0x15, 0) // Salt.
vault := keccak256(0x00, 0x55)
pop(call(gas(), vault, amount, codesize(), 0x00, codesize(), 0x00))
// The vault returns a single word on success. Failure reverts with empty data.
if iszero(returndatasize()) {
if iszero(create2(0, m, 0x40, 0)) { revert(codesize(), codesize()) } // For gas estimation.
}
mstore(0x40, m) // Restore the free memory pointer.
break
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
/// Reverts upon failure.
///
/// The `from` account must have at least `amount` approved for
/// the current contract to manage.
function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x60, amount) // Store the `amount` argument.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
///
/// The `from` account must have at least `amount` approved for the current contract to manage.
function trySafeTransferFrom(address token, address from, address to, uint256 amount)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x60, amount) // Store the `amount` argument.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
success := lt(or(iszero(extcodesize(token)), returndatasize()), success)
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends all of ERC20 `token` from `from` to `to`.
/// Reverts upon failure.
///
/// The `from` account must have their entire balance approved for the current contract to manage.
function safeTransferAllFrom(address token, address from, address to)
internal
returns (uint256 amount)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
// Read the balance, reverting upon failure.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
)
) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
/// Reverts upon failure.
function safeTransfer(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sends all of ERC20 `token` from the current contract to `to`.
/// Reverts upon failure.
function safeTransferAll(address token, address to) internal returns (uint256 amount) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
mstore(0x20, address()) // Store the address of the current contract.
// Read the balance, reverting upon failure.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
)
) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
mstore(0x14, to) // Store the `to` argument.
amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
/// Reverts upon failure.
function safeApprove(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
/// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
/// then retries the approval again (some tokens, e.g. USDT, requires this).
/// Reverts upon failure.
function safeApproveWithRetry(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
// Perform the approval, retrying upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x34, 0) // Store 0 for the `amount`.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
mstore(0x34, amount) // Store back the original `amount`.
// Retry the approval, reverting upon failure.
success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
// Check the `extcodesize` again just in case the token selfdestructs lol.
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
revert(0x1c, 0x04)
}
}
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Returns the amount of ERC20 `token` owned by `account`.
/// Returns zero if the `token` does not exist.
function balanceOf(address token, address account) internal view returns (uint256 amount) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, account) // Store the `account` argument.
mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
amount :=
mul( // The arguments of `mul` are evaluated from right to left.
mload(0x20),
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
)
)
}
}
/// @dev Performs a `token.balanceOf(account)` check.
/// `implemented` denotes whether the `token` does not implement `balanceOf`.
/// `amount` is zero if the `token` does not implement `balanceOf`.
function checkBalanceOf(address token, address account)
internal
view
returns (bool implemented, uint256 amount)
{
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, account) // Store the `account` argument.
mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
implemented :=
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
)
amount := mul(mload(0x20), implemented)
}
}
/// @dev Returns the total supply of the `token`.
/// Reverts if the token does not exist or does not implement `totalSupply()`.
function totalSupply(address token) internal view returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x18160ddd) // `totalSupply()`.
if iszero(
and(gt(returndatasize(), 0x1f), staticcall(gas(), token, 0x1c, 0x04, 0x00, 0x20))
) {
mstore(0x00, 0x54cd9435) // `TotalSupplyQueryFailed()`.
revert(0x1c, 0x04)
}
result := mload(0x00)
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
/// If the initial attempt fails, try to use Permit2 to transfer the token.
/// Reverts upon failure.
///
/// The `from` account must have at least `amount` approved for the current contract to manage.
function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {
if (!trySafeTransferFrom(token, from, to, amount)) {
permit2TransferFrom(token, from, to, amount);
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.
/// Reverts upon failure.
function permit2TransferFrom(address token, address from, address to, uint256 amount)
internal
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(add(m, 0x74), shr(96, shl(96, token)))
mstore(add(m, 0x54), amount)
mstore(add(m, 0x34), to)
mstore(add(m, 0x20), shl(96, from))
// `transferFrom(address,address,uint160,address)`.
mstore(m, 0x36c78516000000000000000000000000)
let p := PERMIT2
let exists := eq(chainid(), 1)
if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }
if iszero(
and(
call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00),
lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists.
)
) {
mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.
revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)
}
}
}
/// @dev Permit a user to spend a given amount of
/// another user's tokens via native EIP-2612 permit if possible, falling
/// back to Permit2 if native permit fails or is not implemented on the token.
function permit2(
address token,
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
for {} shl(96, xor(token, WETH9)) {} {
mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.
// Gas stipend to limit gas burn for tokens that don't refund gas when
// an non-existing function is called. 5K should be enough for a SLOAD.
staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)
)
) { break }
// After here, we can be sure that token is a contract.
let m := mload(0x40)
mstore(add(m, 0x34), spender)
mstore(add(m, 0x20), shl(96, owner))
mstore(add(m, 0x74), deadline)
if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {
mstore(0x14, owner)
mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.
mstore(
add(m, 0x94),
lt(iszero(amount), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))
)
mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.
// `nonces` is already at `add(m, 0x54)`.
// `amount != 0` is already stored at `add(m, 0x94)`.
mstore(add(m, 0xb4), and(0xff, v))
mstore(add(m, 0xd4), r)
mstore(add(m, 0xf4), s)
success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)
break
}
mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.
mstore(add(m, 0x54), amount)
mstore(add(m, 0x94), and(0xff, v))
mstore(add(m, 0xb4), r)
mstore(add(m, 0xd4), s)
success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)
break
}
}
if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);
}
/// @dev Simple permit on the Permit2 contract.
function simplePermit2(
address token,
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, 0x927da105) // `allowance(address,address,address)`.
{
let addressMask := shr(96, not(0))
mstore(add(m, 0x20), and(addressMask, owner))
mstore(add(m, 0x40), and(addressMask, token))
mstore(add(m, 0x60), and(addressMask, spender))
mstore(add(m, 0xc0), and(addressMask, spender))
}
let p := mul(PERMIT2, iszero(shr(160, amount)))
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.
staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)
)
) {
mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.
revert(add(0x18, shl(2, iszero(p))), 0x04)
}
mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).
// `owner` is already `add(m, 0x20)`.
// `token` is already at `add(m, 0x40)`.
mstore(add(m, 0x60), amount)
mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.
// `nonce` is already at `add(m, 0xa0)`.
// `spender` is already at `add(m, 0xc0)`.
mstore(add(m, 0xe0), deadline)
mstore(add(m, 0x100), 0x100) // `signature` offset.
mstore(add(m, 0x120), 0x41) // `signature` length.
mstore(add(m, 0x140), r)
mstore(add(m, 0x160), s)
mstore(add(m, 0x180), shl(248, v))
if iszero( // Revert if token does not have code, or if the call fails.
mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))) {
mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Approves `spender` to spend `amount` of `token` for `address(this)`.
function permit2Approve(address token, address spender, uint160 amount, uint48 expiration)
internal
{
/// @solidity memory-safe-assembly
assembly {
let addressMask := shr(96, not(0))
let m := mload(0x40)
mstore(m, 0x87517c45) // `approve(address,address,uint160,uint48)`.
mstore(add(m, 0x20), and(addressMask, token))
mstore(add(m, 0x40), and(addressMask, spender))
mstore(add(m, 0x60), and(addressMask, amount))
mstore(add(m, 0x80), and(0xffffffffffff, expiration))
if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) {
mstore(0x00, 0x324f14ae) // `Permit2ApproveFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Revokes an approval for `token` and `spender` for `address(this)`.
function permit2Lockdown(address token, address spender) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, 0xcc53287f) // `Permit2.lockdown`.
mstore(add(m, 0x20), 0x20) // Offset of the `approvals`.
mstore(add(m, 0x40), 1) // `approvals.length`.
mstore(add(m, 0x60), shr(96, shl(96, token)))
mstore(add(m, 0x80), shr(96, shl(96, spender)))
if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) {
mstore(0x00, 0x96b3de23) // `Permit2LockdownFailed()`.
revert(0x1c, 0x04)
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple ERC20 + EIP-2612 implementation.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol)
///
/// @dev Note:
/// - The ERC20 standard allows minting and transferring to and from the zero address,
/// minting and transferring zero tokens, as well as self-approvals.
/// For performance, this implementation WILL NOT revert for such actions.
/// Please add any checks with overrides if desired.
/// - The `permit` function uses the ecrecover precompile (0x1).
///
/// If you are overriding:
/// - NEVER violate the ERC20 invariant:
/// the total sum of all balances must be equal to `totalSupply()`.
/// - Check that the overridden function is actually used in the function you want to
/// change the behavior of. Much of the code has been manually inlined for performance.
abstract contract ERC20 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The total supply has overflowed.
error TotalSupplyOverflow();
/// @dev The allowance has overflowed.
error AllowanceOverflow();
/// @dev The allowance has underflowed.
error AllowanceUnderflow();
/// @dev Insufficient balance.
error InsufficientBalance();
/// @dev Insufficient allowance.
error InsufficientAllowance();
/// @dev The permit is invalid.
error InvalidPermit();
/// @dev The permit has expired.
error PermitExpired();
/// @dev The allowance of Permit2 is fixed at infinity.
error Permit2AllowanceIsFixedAtInfinity();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Emitted when `amount` tokens is transferred from `from` to `to`.
event Transfer(address indexed from, address indexed to, uint256 amount);
/// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`.
event Approval(address indexed owner, address indexed spender, uint256 amount);
/// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`.
uint256 private constant _TRANSFER_EVENT_SIGNATURE =
0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;
/// @dev `keccak256(bytes("Approval(address,address,uint256)"))`.
uint256 private constant _APPROVAL_EVENT_SIGNATURE =
0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The storage slot for the total supply.
uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c;
/// @dev The balance slot of `owner` is given by:
/// ```
/// mstore(0x0c, _BALANCE_SLOT_SEED)
/// mstore(0x00, owner)
/// let balanceSlot := keccak256(0x0c, 0x20)
/// ```
uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2;
/// @dev The allowance slot of (`owner`, `spender`) is given by:
/// ```
/// mstore(0x20, spender)
/// mstore(0x0c, _ALLOWANCE_SLOT_SEED)
/// mstore(0x00, owner)
/// let allowanceSlot := keccak256(0x0c, 0x34)
/// ```
uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20;
/// @dev The nonce slot of `owner` is given by:
/// ```
/// mstore(0x0c, _NONCES_SLOT_SEED)
/// mstore(0x00, owner)
/// let nonceSlot := keccak256(0x0c, 0x20)
/// ```
uint256 private constant _NONCES_SLOT_SEED = 0x38377508;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`.
uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901;
/// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`.
bytes32 private constant _DOMAIN_TYPEHASH =
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;
/// @dev `keccak256("1")`.
/// If you need to use a different version, override `_versionHash`.
bytes32 private constant _DEFAULT_VERSION_HASH =
0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6;
/// @dev `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`.
bytes32 private constant _PERMIT_TYPEHASH =
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
/// @dev The canonical Permit2 address.
/// For signature-based allowance granting for single transaction ERC20 `transferFrom`.
/// Enabled by default. To disable, override `_givePermit2InfiniteAllowance()`.
/// [Github](https://github.com/Uniswap/permit2)
/// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
address internal constant _PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 METADATA */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the name of the token.
function name() public view virtual returns (string memory);
/// @dev Returns the symbol of the token.
function symbol() public view virtual returns (string memory);
/// @dev Returns the decimals places of the token.
function decimals() public view virtual returns (uint8) {
return 18;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the amount of tokens in existence.
function totalSupply() public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := sload(_TOTAL_SUPPLY_SLOT)
}
}
/// @dev Returns the amount of tokens owned by `owner`.
function balanceOf(address owner) public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x20))
}
}
/// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`.
function allowance(address owner, address spender)
public
view
virtual
returns (uint256 result)
{
if (_givePermit2InfiniteAllowance()) {
if (spender == _PERMIT2) return type(uint256).max;
}
/// @solidity memory-safe-assembly
assembly {
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x34))
}
}
/// @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
///
/// Emits a {Approval} event.
function approve(address spender, uint256 amount) public virtual returns (bool) {
if (_givePermit2InfiniteAllowance()) {
/// @solidity memory-safe-assembly
assembly {
// If `spender == _PERMIT2 && amount != type(uint256).max`.
if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) {
mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`.
revert(0x1c, 0x04)
}
}
}
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and store the amount.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x34), amount)
// Emit the {Approval} event.
mstore(0x00, amount)
log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, caller(), shr(96, mload(0x2c)))
}
return true;
}
/// @dev Transfer `amount` tokens from the caller to `to`.
///
/// Requirements:
/// - `from` must at least have `amount`.
///
/// Emits a {Transfer} event.
function transfer(address to, uint256 amount) public virtual returns (bool) {
_beforeTokenTransfer(msg.sender, to, amount);
/// @solidity memory-safe-assembly
assembly {
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, caller())
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, caller(), shr(96, mload(0x0c)))
}
_afterTokenTransfer(msg.sender, to, amount);
return true;
}
/// @dev Transfers `amount` tokens from `from` to `to`.
///
/// Note: Does not update the allowance if it is the maximum uint256 value.
///
/// Requirements:
/// - `from` must at least have `amount`.
/// - The caller must have at least `amount` of allowance to transfer the tokens of `from`.
///
/// Emits a {Transfer} event.
function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
_beforeTokenTransfer(from, to, amount);
// Code duplication is for zero-cost abstraction if possible.
if (_givePermit2InfiniteAllowance()) {
/// @solidity memory-safe-assembly
assembly {
let from_ := shl(96, from)
if iszero(eq(caller(), _PERMIT2)) {
// Compute the allowance slot and load its value.
mstore(0x20, caller())
mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED))
let allowanceSlot := keccak256(0x0c, 0x34)
let allowance_ := sload(allowanceSlot)
// If the allowance is not the maximum uint256 value.
if not(allowance_) {
// Revert if the amount to be transferred exceeds the allowance.
if gt(amount, allowance_) {
mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
sstore(allowanceSlot, sub(allowance_, amount))
}
}
// Compute the balance slot and load its value.
mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
}
} else {
/// @solidity memory-safe-assembly
assembly {
let from_ := shl(96, from)
// Compute the allowance slot and load its value.
mstore(0x20, caller())
mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED))
let allowanceSlot := keccak256(0x0c, 0x34)
let allowance_ := sload(allowanceSlot)
// If the allowance is not the maximum uint256 value.
if not(allowance_) {
// Revert if the amount to be transferred exceeds the allowance.
if gt(amount, allowance_) {
mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
sstore(allowanceSlot, sub(allowance_, amount))
}
// Compute the balance slot and load its value.
mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
}
}
_afterTokenTransfer(from, to, amount);
return true;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EIP-2612 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev For more performance, override to return the constant value
/// of `keccak256(bytes(name()))` if `name()` will never change.
function _constantNameHash() internal view virtual returns (bytes32 result) {}
/// @dev If you need a different value, override this function.
function _versionHash() internal view virtual returns (bytes32 result) {
result = _DEFAULT_VERSION_HASH;
}
/// @dev For inheriting contracts to increment the nonce.
function _incrementNonce(address owner) internal virtual {
/// @solidity memory-safe-assembly
assembly {
mstore(0x0c, _NONCES_SLOT_SEED)
mstore(0x00, owner)
let nonceSlot := keccak256(0x0c, 0x20)
sstore(nonceSlot, add(1, sload(nonceSlot)))
}
}
/// @dev Returns the current nonce for `owner`.
/// This value is used to compute the signature for EIP-2612 permit.
function nonces(address owner) public view virtual returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
// Compute the nonce slot and load its value.
mstore(0x0c, _NONCES_SLOT_SEED)
mstore(0x00, owner)
result := sload(keccak256(0x0c, 0x20))
}
}
/// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`,
/// authorized by a signed approval by `owner`.
///
/// Emits a {Approval} event.
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (_givePermit2InfiniteAllowance()) {
/// @solidity memory-safe-assembly
assembly {
// If `spender == _PERMIT2 && value != type(uint256).max`.
if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(value)))) {
mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`.
revert(0x1c, 0x04)
}
}
}
bytes32 nameHash = _constantNameHash();
// We simply calculate it on-the-fly to allow for cases where the `name` may change.
if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
bytes32 versionHash = _versionHash();
/// @solidity memory-safe-assembly
assembly {
// Revert if the block timestamp is greater than `deadline`.
if gt(timestamp(), deadline) {
mstore(0x00, 0x1a15a3cc) // `PermitExpired()`.
revert(0x1c, 0x04)
}
let m := mload(0x40) // Grab the free memory pointer.
// Clean the upper 96 bits.
owner := shr(96, shl(96, owner))
spender := shr(96, shl(96, spender))
// Compute the nonce slot and load its value.
mstore(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX)
mstore(0x00, owner)
let nonceSlot := keccak256(0x0c, 0x20)
let nonceValue := sload(nonceSlot)
// Prepare the domain separator.
mstore(m, _DOMAIN_TYPEHASH)
mstore(add(m, 0x20), nameHash)
mstore(add(m, 0x40), versionHash)
mstore(add(m, 0x60), chainid())
mstore(add(m, 0x80), address())
mstore(0x2e, keccak256(m, 0xa0))
// Prepare the struct hash.
mstore(m, _PERMIT_TYPEHASH)
mstore(add(m, 0x20), owner)
mstore(add(m, 0x40), spender)
mstore(add(m, 0x60), value)
mstore(add(m, 0x80), nonceValue)
mstore(add(m, 0xa0), deadline)
mstore(0x4e, keccak256(m, 0xc0))
// Prepare the ecrecover calldata.
mstore(0x00, keccak256(0x2c, 0x42))
mstore(0x20, and(0xff, v))
mstore(0x40, r)
mstore(0x60, s)
let t := staticcall(gas(), 1, 0x00, 0x80, 0x20, 0x20)
// If the ecrecover fails, the returndatasize will be 0x00,
// `owner` will be checked if it equals the hash at 0x00,
// which evaluates to false (i.e. 0), and we will revert.
// If the ecrecover succeeds, the returndatasize will be 0x20,
// `owner` will be compared against the returned address at 0x20.
if iszero(eq(mload(returndatasize()), owner)) {
mstore(0x00, 0xddafbaef) // `InvalidPermit()`.
revert(0x1c, 0x04)
}
// Increment and store the updated nonce.
sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds.
// Compute the allowance slot and store the value.
// The `owner` is already at slot 0x20.
mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender))
sstore(keccak256(0x2c, 0x34), value)
// Emit the {Approval} event.
log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender)
mstore(0x40, m) // Restore the free memory pointer.
mstore(0x60, 0) // Restore the zero pointer.
}
}
/// @dev Returns the EIP-712 domain separator for the EIP-2612 permit.
function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) {
bytes32 nameHash = _constantNameHash();
// We simply calculate it on-the-fly to allow for cases where the `name` may change.
if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name()));
bytes32 versionHash = _versionHash();
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Grab the free memory pointer.
mstore(m, _DOMAIN_TYPEHASH)
mstore(add(m, 0x20), nameHash)
mstore(add(m, 0x40), versionHash)
mstore(add(m, 0x60), chainid())
mstore(add(m, 0x80), address())
result := keccak256(m, 0xa0)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL MINT FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Mints `amount` tokens to `to`, increasing the total supply.
///
/// Emits a {Transfer} event.
function _mint(address to, uint256 amount) internal virtual {
_beforeTokenTransfer(address(0), to, amount);
/// @solidity memory-safe-assembly
assembly {
let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT)
let totalSupplyAfter := add(totalSupplyBefore, amount)
// Revert if the total supply overflows.
if lt(totalSupplyAfter, totalSupplyBefore) {
mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`.
revert(0x1c, 0x04)
}
// Store the updated total supply.
sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter)
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c)))
}
_afterTokenTransfer(address(0), to, amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL BURN FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Burns `amount` tokens from `from`, reducing the total supply.
///
/// Emits a {Transfer} event.
function _burn(address from, uint256 amount) internal virtual {
_beforeTokenTransfer(from, address(0), amount);
/// @solidity memory-safe-assembly
assembly {
// Compute the balance slot and load its value.
mstore(0x0c, _BALANCE_SLOT_SEED)
mstore(0x00, from)
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Subtract and store the updated total supply.
sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount))
// Emit the {Transfer} event.
mstore(0x00, amount)
log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0)
}
_afterTokenTransfer(from, address(0), amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL TRANSFER FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Moves `amount` of tokens from `from` to `to`.
function _transfer(address from, address to, uint256 amount) internal virtual {
_beforeTokenTransfer(from, to, amount);
/// @solidity memory-safe-assembly
assembly {
let from_ := shl(96, from)
// Compute the balance slot and load its value.
mstore(0x0c, or(from_, _BALANCE_SLOT_SEED))
let fromBalanceSlot := keccak256(0x0c, 0x20)
let fromBalance := sload(fromBalanceSlot)
// Revert if insufficient balance.
if gt(amount, fromBalance) {
mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated balance.
sstore(fromBalanceSlot, sub(fromBalance, amount))
// Compute the balance slot of `to`.
mstore(0x00, to)
let toBalanceSlot := keccak256(0x0c, 0x20)
// Add and store the updated balance of `to`.
// Will not overflow because the sum of all user balances
// cannot exceed the maximum uint256 value.
sstore(toBalanceSlot, add(sload(toBalanceSlot), amount))
// Emit the {Transfer} event.
mstore(0x20, amount)
log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c)))
}
_afterTokenTransfer(from, to, amount);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL ALLOWANCE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Updates the allowance of `owner` for `spender` based on spent `amount`.
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
if (_givePermit2InfiniteAllowance()) {
if (spender == _PERMIT2) return; // Do nothing, as allowance is infinite.
}
/// @solidity memory-safe-assembly
assembly {
// Compute the allowance slot and load its value.
mstore(0x20, spender)
mstore(0x0c, _ALLOWANCE_SLOT_SEED)
mstore(0x00, owner)
let allowanceSlot := keccak256(0x0c, 0x34)
let allowance_ := sload(allowanceSlot)
// If the allowance is not the maximum uint256 value.
if not(allowance_) {
// Revert if the amount to be transferred exceeds the allowance.
if gt(amount, allowance_) {
mstore(0x00, 0x13be252b) // `InsufficientAllowance()`.
revert(0x1c, 0x04)
}
// Subtract and store the updated allowance.
sstore(allowanceSlot, sub(allowance_, amount))
}
}
}
/// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`.
///
/// Emits a {Approval} event.
function _approve(address owner, address spender, uint256 amount) internal virtual {
if (_givePermit2InfiniteAllowance()) {
/// @solidity memory-safe-assembly
assembly {
// If `spender == _PERMIT2 && amount != type(uint256).max`.
if iszero(or(xor(shr(96, shl(96, spender)), _PERMIT2), iszero(not(amount)))) {
mstore(0x00, 0x3f68539a) // `Permit2AllowanceIsFixedAtInfinity()`.
revert(0x1c, 0x04)
}
}
}
/// @solidity memory-safe-assembly
assembly {
let owner_ := shl(96, owner)
// Compute the allowance slot and store the amount.
mstore(0x20, spender)
mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED))
sstore(keccak256(0x0c, 0x34), amount)
// Emit the {Approval} event.
mstore(0x00, amount)
log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, owner_), shr(96, mload(0x2c)))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HOOKS TO OVERRIDE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Hook that is called before any transfer of tokens.
/// This includes minting and burning.
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/// @dev Hook that is called after any transfer of tokens.
/// This includes minting and burning.
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PERMIT2 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns whether to fix the Permit2 contract's allowance at infinity.
///
/// This value should be kept constant after contract initialization,
/// or else the actual allowance values may not match with the {Approval} events.
/// For best performance, return a compile-time constant for zero-cost abstraction.
function _givePermit2InfiniteAllowance() internal view virtual returns (bool) {
return true;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error ExpOverflow();
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error FactorialOverflow();
/// @dev The operation failed, due to an overflow.
error RPowOverflow();
/// @dev The mantissa is too big to fit.
error MantissaOverflow();
/// @dev The operation failed, due to an multiplication overflow.
error MulWadFailed();
/// @dev The operation failed, due to an multiplication overflow.
error SMulWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error DivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error SDivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error MulDivFailed();
/// @dev The division failed, as the denominator is zero.
error DivFailed();
/// @dev The full precision multiply-divide operation failed, either due
/// to the result being larger than 256 bits, or a division by a zero.
error FullMulDivFailed();
/// @dev The output is undefined, as the input is less-than-or-equal to zero.
error LnWadUndefined();
/// @dev The input outside the acceptable domain.
error OutOfDomain();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The scalar of ETH and most ERC20s.
uint256 internal constant WAD = 1e18;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* SIMPLIFIED FIXED POINT OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if gt(x, div(not(0), y)) {
if y {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
}
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.
if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {
mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(z, WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up.
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if iszero(eq(div(z, y), x)) {
if y {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
}
z := add(iszero(iszero(mod(z, WAD))), div(z, WAD))
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.
function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.
if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, WAD)
// Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.
if iszero(mul(y, eq(sdiv(z, WAD), x))) {
mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(z, y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up.
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.
if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.
function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `x` to the power of `y`.
/// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
/// Note: This function is an approximation.
function powWad(int256 x, int256 y) internal pure returns (int256) {
// Using `ln(x)` means `x` must be greater than 0.
return expWad((lnWad(x) * y) / int256(WAD));
}
/// @dev Returns `exp(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
/// Note: This function is an approximation. Monotonically increasing.
function expWad(int256 x) internal pure returns (int256 r) {
unchecked {
// When the result is less than 0.5 we return zero.
// This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
if (x <= -41446531673892822313) return r;
/// @solidity memory-safe-assembly
assembly {
// When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
// an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
if iszero(slt(x, 135305999368893231589)) {
mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
revert(0x1c, 0x04)
}
}
// `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
// for more intermediate precision and a binary basis. This base conversion
// is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
x = (x << 78) / 5 ** 18;
// Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
// of two such that exp(x) = exp(x') * 2**k, where k is an integer.
// Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
x = x - k * 54916777467707473351141471128;
// `k` is in the range `[-61, 195]`.
// Evaluate using a (6, 7)-term rational approximation.
// `p` is made monic, we'll multiply by a scale factor later.
int256 y = x + 1346386616545796478920950773328;
y = ((y * x) >> 96) + 57155421227552351082224309758442;
int256 p = y + x - 94201549194550492254356042504812;
p = ((p * y) >> 96) + 28719021644029726153956944680412240;
p = p * x + (4385272521454847904659076985693276 << 96);
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
int256 q = x - 2855989394907223263936484059900;
q = ((q * x) >> 96) + 50020603652535783019961831881945;
q = ((q * x) >> 96) - 533845033583426703283633433725380;
q = ((q * x) >> 96) + 3604857256930695427073651918091429;
q = ((q * x) >> 96) - 14423608567350463180887372962807573;
q = ((q * x) >> 96) + 26449188498355588339934803723976023;
/// @solidity memory-safe-assembly
assembly {
// Div in assembly because solidity adds a zero check despite the unchecked.
// The q polynomial won't have zeros in the domain as all its roots are complex.
// No scaling is necessary because p is already `2**96` too large.
r := sdiv(p, q)
}
// r should be in the range `(0.09, 0.25) * 2**96`.
// We now need to multiply r by:
// - The scale factor `s ≈ 6.031367120`.
// - The `2**k` factor from the range reduction.
// - The `1e18 / 2**96` factor for base conversion.
// We do this all at once, with an intermediate result in `2**213`
// basis, so the final right shift is always by a positive amount.
r = int256(
(uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
);
}
}
/// @dev Returns `ln(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
/// Note: This function is an approximation. Monotonically increasing.
function lnWad(int256 x) internal pure returns (int256 r) {
/// @solidity memory-safe-assembly
assembly {
// We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
// We do this by multiplying by `2**96 / 10**18`. But since
// `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
// and add `ln(2**96 / 10**18)` at the end.
// Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// We place the check here for more optimal stack operations.
if iszero(sgt(x, 0)) {
mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
revert(0x1c, 0x04)
}
// forgefmt: disable-next-item
r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))
// Reduce range of x to (1, 2) * 2**96
// ln(2^k * x) = k * ln(2) + ln(x)
x := shr(159, shl(r, x))
// Evaluate using a (8, 8)-term rational approximation.
// `p` is made monic, we will multiply by a scale factor later.
// forgefmt: disable-next-item
let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
sar(96, mul(add(43456485725739037958740375743393,
sar(96, mul(add(24828157081833163892658089445524,
sar(96, mul(add(3273285459638523848632254066296,
x), x))), x))), x)), 11111509109440967052023855526967)
p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
// `q` is monic by convention.
let q := add(5573035233440673466300451813936, x)
q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
q := add(909429971244387300277376558375, sar(96, mul(x, q)))
// `p / q` is in the range `(0, 0.125) * 2**96`.
// Finalization, we need to:
// - Multiply by the scale factor `s = 5.549…`.
// - Add `ln(2**96 / 10**18)`.
// - Add `k * ln(2)`.
// - Multiply by `10**18 / 2**96 = 5**18 >> 78`.
// The q polynomial is known not to have zeros in the domain.
// No scaling required because p is already `2**96` too large.
p := sdiv(p, q)
// Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
p := mul(1677202110996718588342820967067443963516166, p)
// Add `ln(2) * k * 5**18 * 2**192`.
// forgefmt: disable-next-item
p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
// Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
// Base conversion: mul `2**18 / 2**192`.
r := sar(174, p)
}
}
/// @dev Returns `W_0(x)`, denominated in `WAD`.
/// See: https://en.wikipedia.org/wiki/Lambert_W_function
/// a.k.a. Product log function. This is an approximation of the principal branch.
/// Note: This function is an approximation. Monotonically increasing.
function lambertW0Wad(int256 x) internal pure returns (int256 w) {
// forgefmt: disable-next-item
unchecked {
if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.
(int256 wad, int256 p) = (int256(WAD), x);
uint256 c; // Whether we need to avoid catastrophic cancellation.
uint256 i = 4; // Number of iterations.
if (w <= 0x1ffffffffffff) {
if (-0x4000000000000 <= w) {
i = 1; // Inputs near zero only take one step to converge.
} else if (w <= -0x3ffffffffffffff) {
i = 32; // Inputs near `-1/e` take very long to converge.
}
} else if (uint256(w >> 63) == uint256(0)) {
/// @solidity memory-safe-assembly
assembly {
// Inline log2 for more performance, since the range is small.
let v := shr(49, w)
let l := shl(3, lt(0xff, v))
l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000)), 49)
w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))
c := gt(l, 60)
i := add(2, add(gt(l, 53), c))
}
} else {
int256 ll = lnWad(w = lnWad(w));
/// @solidity memory-safe-assembly
assembly {
// `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.
w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))
i := add(3, iszero(shr(68, x)))
c := iszero(shr(143, x))
}
if (c == uint256(0)) {
do { // If `x` is big, use Newton's so that intermediate values won't overflow.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := mul(w, div(e, wad))
w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))
}
if (p <= w) break;
p = w;
} while (--i != uint256(0));
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
return w;
}
}
do { // Otherwise, use Halley's for faster convergence.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := add(w, wad)
let s := sub(mul(w, e), mul(x, wad))
w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))
}
if (p <= w) break;
p = w;
} while (--i != c);
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
// For certain ranges of `x`, we'll use the quadratic-rate recursive formula of
// R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.
if (c == uint256(0)) return w;
int256 t = w | 1;
/// @solidity memory-safe-assembly
assembly {
x := sdiv(mul(x, wad), t)
}
x = (t * (wad + lnWad(x)));
/// @solidity memory-safe-assembly
assembly {
w := sdiv(x, add(wad, t))
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* GENERAL NUMBER UTILITIES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `a * b == x * y`, with full precision.
function fullMulEq(uint256 a, uint256 b, uint256 x, uint256 y)
internal
pure
returns (bool result)
{
/// @solidity memory-safe-assembly
assembly {
result := and(eq(mul(a, b), mul(x, y)), eq(mulmod(x, y, not(0)), mulmod(a, b, not(0))))
}
}
/// @dev Calculates `floor(x * y / d)` with full precision.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// 512-bit multiply `[p1 p0] = x * y`.
// Compute the product mod `2**256` and mod `2**256 - 1`
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that `product = p1 * 2**256 + p0`.
// Temporarily use `z` as `p0` to save gas.
z := mul(x, y) // Lower 256 bits of `x * y`.
for {} 1 {} {
// If overflows.
if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
let mm := mulmod(x, y, not(0))
let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.
/*------------------- 512 by 256 division --------------------*/
// Make division exact by subtracting the remainder from `[p1 p0]`.
let r := mulmod(x, y, d) // Compute remainder using mulmod.
let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`.
// Make sure `z` is less than `2**256`. Also prevents `d == 0`.
// Placing the check here seems to give more optimal stack operations.
if iszero(gt(d, p1)) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
d := div(d, t) // Divide `d` by `t`, which is a power of two.
// Invert `d mod 2**256`
// Now that `d` is an odd number, it has an inverse
// modulo `2**256` such that `d * inv = 1 mod 2**256`.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, `d * inv = 1 mod 2**4`.
let inv := xor(2, mul(3, d))
// Now use 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.
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
z :=
mul(
// Divide [p1 p0] by the factors of two.
// Shift in bits from `p1` into `p0`. For this we need
// to flip `t` such that it is `2**256 / t`.
or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),
mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256
)
break
}
z := div(z, d)
break
}
}
}
/// @dev Calculates `floor(x * y / d)` with full precision.
/// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits.
/// Performs the full 512 bit calculation regardless.
function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d)
internal
pure
returns (uint256 z)
{
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
let mm := mulmod(x, y, not(0))
let p1 := sub(mm, add(z, lt(mm, z)))
let t := and(d, sub(0, d))
let r := mulmod(x, y, d)
d := div(d, t)
let inv := xor(2, mul(3, d))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
z :=
mul(
or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),
mul(sub(2, mul(d, inv)), inv)
)
}
}
/// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Uniswap-v3-core under MIT license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
z = fullMulDiv(x, y, d);
/// @solidity memory-safe-assembly
assembly {
if mulmod(x, y, d) {
z := add(z, 1)
if iszero(z) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
}
}
}
/// @dev Calculates `floor(x * y / 2 ** n)` with full precision.
/// Throws if result overflows a uint256.
/// Credit to Philogy under MIT license:
/// https://github.com/SorellaLabs/angstrom/blob/main/contracts/src/libraries/X128MathLib.sol
function fullMulDivN(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Temporarily use `z` as `p0` to save gas.
z := mul(x, y) // Lower 256 bits of `x * y`. We'll call this `z`.
for {} 1 {} {
if iszero(or(iszero(x), eq(div(z, x), y))) {
let k := and(n, 0xff) // `n`, cleaned.
let mm := mulmod(x, y, not(0))
let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.
// | p1 | z |
// Before: | p1_0 ¦ p1_1 | z_0 ¦ z_1 |
// Final: | 0 ¦ p1_0 | p1_1 ¦ z_0 |
// Check that final `z` doesn't overflow by checking that p1_0 = 0.
if iszero(shr(k, p1)) {
z := add(shl(sub(256, k), p1), shr(k, z))
break
}
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
z := shr(and(n, 0xff), z)
break
}
}
}
/// @dev Returns `floor(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := div(z, d)
}
}
/// @dev Returns `ceil(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(z, d))), div(z, d))
}
}
/// @dev Returns `x`, the modular multiplicative inverse of `a`, such that `(a * x) % n == 1`.
function invMod(uint256 a, uint256 n) internal pure returns (uint256 x) {
/// @solidity memory-safe-assembly
assembly {
let g := n
let r := mod(a, n)
for { let y := 1 } 1 {} {
let q := div(g, r)
let t := g
g := r
r := sub(t, mul(r, q))
let u := x
x := y
y := sub(u, mul(y, q))
if iszero(r) { break }
}
x := mul(eq(g, 1), add(x, mul(slt(x, 0), n)))
}
}
/// @dev Returns `ceil(x / d)`.
/// Reverts if `d` is zero.
function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
if iszero(d) {
mstore(0x00, 0x65244e4e) // `DivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(x, d))), div(x, d))
}
}
/// @dev Returns `max(0, x - y)`. Alias for `saturatingSub`.
function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Returns `max(0, x - y)`.
function saturatingSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Returns `min(2 ** 256 - 1, x + y)`.
function saturatingAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(sub(0, lt(add(x, y), x)), add(x, y))
}
}
/// @dev Returns `min(2 ** 256 - 1, x * y)`.
function saturatingMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(sub(or(iszero(x), eq(div(mul(x, y), x), y)), 1), mul(x, y))
}
}
/// @dev Returns `condition ? x : y`, without branching.
function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), iszero(condition)))
}
}
/// @dev Returns `condition ? x : y`, without branching.
function ternary(bool condition, bytes32 x, bytes32 y) internal pure returns (bytes32 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), iszero(condition)))
}
}
/// @dev Returns `condition ? x : y`, without branching.
function ternary(bool condition, address x, address y) internal pure returns (address z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), iszero(condition)))
}
}
/// @dev Returns `x != 0 ? x : y`, without branching.
function coalesce(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(x, mul(y, iszero(x)))
}
}
/// @dev Returns `x != bytes32(0) ? x : y`, without branching.
function coalesce(bytes32 x, bytes32 y) internal pure returns (bytes32 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(x, mul(y, iszero(x)))
}
}
/// @dev Returns `x != address(0) ? x : y`, without branching.
function coalesce(address x, address y) internal pure returns (address z) {
/// @solidity memory-safe-assembly
assembly {
z := or(x, mul(y, iszero(shl(96, x))))
}
}
/// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.
/// Reverts if the computation overflows.
function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.
if x {
z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`
let half := shr(1, b) // Divide `b` by 2.
// Divide `y` by 2 every iteration.
for { y := shr(1, y) } y { y := shr(1, y) } {
let xx := mul(x, x) // Store x squared.
let xxRound := add(xx, half) // Round to the nearest number.
// Revert if `xx + half` overflowed, or if `x ** 2` overflows.
if or(lt(xxRound, xx), shr(128, x)) {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
x := div(xxRound, b) // Set `x` to scaled `xxRound`.
// If `y` is odd:
if and(y, 1) {
let zx := mul(z, x) // Compute `z * x`.
let zxRound := add(zx, half) // Round to the nearest number.
// If `z * x` overflowed or `zx + half` overflowed:
if or(xor(div(zx, x), z), lt(zxRound, zx)) {
// Revert if `x` is non-zero.
if x {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
}
z := div(zxRound, b) // Return properly scaled `zxRound`.
}
}
}
}
}
/// @dev Returns the square root of `x`, rounded down.
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
// but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffffff, shr(r, x))))
z := shl(shr(1, r), z)
// Goal was to get `z*z*y` within a small factor of `x`. More iterations could
// get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
// We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
// That's not possible if `x < 256` but we can just verify those cases exhaustively.
// Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
// Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
// Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
// For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
// is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
// with largest error when `s = 1` and when `s = 256` or `1/256`.
// Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
// Then we can estimate `sqrt(y)` using
// `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
// There is no overflow risk here since `y < 2**136` after the first branch above.
z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If `x+1` is a perfect square, the Babylonian method cycles between
// `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
z := sub(z, lt(div(x, z), z))
}
}
/// @dev Returns the cube root of `x`, rounded down.
/// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
/// https://github.com/pcaversaccio/snekmate/blob/main/src/snekmate/utils/math.vy
/// Formally verified by xuwinnie:
/// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf
function cbrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// Makeshift lookup table to nudge the approximate log2 result.
z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))
// Newton-Raphson's.
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
// Round down.
z := sub(z, lt(div(x, mul(z, z)), z))
}
}
/// @dev Returns the square root of `x`, denominated in `WAD`, rounded down.
function sqrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18);
z = (1 + sqrt(x)) * 10 ** 9;
z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1;
}
/// @solidity memory-safe-assembly
assembly {
z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1))) // Round down.
}
}
/// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down.
/// Formally verified by xuwinnie:
/// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf
function cbrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36);
z = (1 + cbrt(x)) * 10 ** 12;
z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3;
}
/// @solidity memory-safe-assembly
assembly {
let p := x
for {} 1 {} {
if iszero(shr(229, p)) {
if iszero(shr(199, p)) {
p := mul(p, 100000000000000000) // 10 ** 17.
break
}
p := mul(p, 100000000) // 10 ** 8.
break
}
if iszero(shr(249, p)) { p := mul(p, 100) }
break
}
let t := mulmod(mul(z, z), z, p)
z := sub(z, gt(lt(t, shr(1, p)), iszero(t))) // Round down.
}
}
/// @dev Returns `sqrt(x * y)`. Also called the geometric mean.
function mulSqrt(uint256 x, uint256 y) internal pure returns (uint256 z) {
if (x == y) return x;
uint256 p = rawMul(x, y);
if (y == rawDiv(p, x)) return sqrt(p);
for (z = saturatingMul(rawAdd(sqrt(x), 1), rawAdd(sqrt(y), 1));; z = avg(z, p)) {
if ((p = fullMulDivUnchecked(x, y, z)) >= z) break;
}
}
/// @dev Returns the factorial of `x`.
function factorial(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := 1
if iszero(lt(x, 58)) {
mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
revert(0x1c, 0x04)
}
for {} x { x := sub(x, 1) } { z := mul(z, x) }
}
}
/// @dev Returns the log2 of `x`.
/// Equivalent to computing the index of the most significant bit (MSB) of `x`.
/// Returns 0 if `x` is zero.
function log2(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// forgefmt: disable-next-item
r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000))
}
}
/// @dev Returns the log2 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log2Up(uint256 x) internal pure returns (uint256 r) {
r = log2(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(r, 1), x))
}
}
/// @dev Returns the log10 of `x`.
/// Returns 0 if `x` is zero.
function log10(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(x, 100000000000000000000000000000000000000)) {
x := div(x, 100000000000000000000000000000000000000)
r := 38
}
if iszero(lt(x, 100000000000000000000)) {
x := div(x, 100000000000000000000)
r := add(r, 20)
}
if iszero(lt(x, 10000000000)) {
x := div(x, 10000000000)
r := add(r, 10)
}
if iszero(lt(x, 100000)) {
x := div(x, 100000)
r := add(r, 5)
}
r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))
}
}
/// @dev Returns the log10 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log10Up(uint256 x) internal pure returns (uint256 r) {
r = log10(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(exp(10, r), x))
}
}
/// @dev Returns the log256 of `x`.
/// Returns 0 if `x` is zero.
function log256(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(shr(3, r), lt(0xff, shr(r, x)))
}
}
/// @dev Returns the log256 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log256Up(uint256 x) internal pure returns (uint256 r) {
r = log256(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(shl(3, r), 1), x))
}
}
/// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.
/// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).
function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {
/// @solidity memory-safe-assembly
assembly {
mantissa := x
if mantissa {
if iszero(mod(mantissa, 1000000000000000000000000000000000)) {
mantissa := div(mantissa, 1000000000000000000000000000000000)
exponent := 33
}
if iszero(mod(mantissa, 10000000000000000000)) {
mantissa := div(mantissa, 10000000000000000000)
exponent := add(exponent, 19)
}
if iszero(mod(mantissa, 1000000000000)) {
mantissa := div(mantissa, 1000000000000)
exponent := add(exponent, 12)
}
if iszero(mod(mantissa, 1000000)) {
mantissa := div(mantissa, 1000000)
exponent := add(exponent, 6)
}
if iszero(mod(mantissa, 10000)) {
mantissa := div(mantissa, 10000)
exponent := add(exponent, 4)
}
if iszero(mod(mantissa, 100)) {
mantissa := div(mantissa, 100)
exponent := add(exponent, 2)
}
if iszero(mod(mantissa, 10)) {
mantissa := div(mantissa, 10)
exponent := add(exponent, 1)
}
}
}
}
/// @dev Convenience function for packing `x` into a smaller number using `sci`.
/// The `mantissa` will be in bits [7..255] (the upper 249 bits).
/// The `exponent` will be in bits [0..6] (the lower 7 bits).
/// Use `SafeCastLib` to safely ensure that the `packed` number is small
/// enough to fit in the desired unsigned integer type:
/// ```
/// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));
/// ```
function packSci(uint256 x) internal pure returns (uint256 packed) {
(x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.
/// @solidity memory-safe-assembly
assembly {
if shr(249, x) {
mstore(0x00, 0xce30380c) // `MantissaOverflow()`.
revert(0x1c, 0x04)
}
packed := or(shl(7, x), packed)
}
}
/// @dev Convenience function for unpacking a packed number from `packSci`.
function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {
unchecked {
unpacked = (packed >> 7) * 10 ** (packed & 0x7f);
}
}
/// @dev Returns the average of `x` and `y`. Rounds towards zero.
function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = (x & y) + ((x ^ y) >> 1);
}
}
/// @dev Returns the average of `x` and `y`. Rounds towards negative infinity.
function avg(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = (x >> 1) + (y >> 1) + (x & y & 1);
}
}
/// @dev Returns the absolute value of `x`.
function abs(int256 x) internal pure returns (uint256 z) {
unchecked {
z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255);
}
}
/// @dev Returns the absolute distance between `x` and `y`.
function dist(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(xor(sub(0, gt(x, y)), sub(y, x)), gt(x, y))
}
}
/// @dev Returns the absolute distance between `x` and `y`.
function dist(int256 x, int256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(xor(sub(0, sgt(x, y)), sub(y, x)), sgt(x, y))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), slt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), gt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), sgt(y, x)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(uint256 x, uint256 minValue, uint256 maxValue)
internal
pure
returns (uint256 z)
{
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), gt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))
}
}
/// @dev Returns greatest common divisor of `x` and `y`.
function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
for { z := x } y {} {
let t := y
y := mod(z, y)
z := t
}
}
}
/// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`,
/// with `t` clamped between `begin` and `end` (inclusive).
/// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
/// If `begins == end`, returns `t <= begin ? a : b`.
function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end)
internal
pure
returns (uint256)
{
if (begin > end) (t, begin, end) = (~t, ~begin, ~end);
if (t <= begin) return a;
if (t >= end) return b;
unchecked {
if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin);
return a - fullMulDiv(a - b, t - begin, end - begin);
}
}
/// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`.
/// with `t` clamped between `begin` and `end` (inclusive).
/// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
/// If `begins == end`, returns `t <= begin ? a : b`.
function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end)
internal
pure
returns (int256)
{
if (begin > end) (t, begin, end) = (~t, ~begin, ~end);
if (t <= begin) return a;
if (t >= end) return b;
// forgefmt: disable-next-item
unchecked {
if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b - a),
uint256(t - begin), uint256(end - begin)));
return int256(uint256(a) - fullMulDiv(uint256(a - b),
uint256(t - begin), uint256(end - begin)));
}
}
/// @dev Returns if `x` is an even number. Some people may need this.
function isEven(uint256 x) internal pure returns (bool) {
return x & uint256(1) == uint256(0);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* RAW NUMBER OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(x, y)
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mod(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := smod(x, y)
}
}
/// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := addmod(x, y, d)
}
}
/// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mulmod(x, y, d)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Call context checker mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/CallContextChecker.sol)
contract CallContextChecker {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The call is from an unauthorized call context.
error UnauthorizedCallContext();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* IMMUTABLES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev For checking if the context is a delegate call.
///
/// Note: To enable use cases with an immutable default implementation in the bytecode,
/// (see: ERC6551Proxy), we don't require that the proxy address must match the
/// value stored in the implementation slot, which may not be initialized.
uint256 private immutable __self = uint256(uint160(address(this)));
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CALL CONTEXT CHECKS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// A proxy call can be either via a `delegatecall` to an implementation,
// or a 7702 call on an authority that points to a delegation.
/// @dev Returns whether the current call context is on a EIP7702 authority
/// (i.e. externally owned account).
function _onEIP7702Authority() internal view virtual returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
extcodecopy(address(), 0x00, 0x00, 0x20)
// Note: Checking that it starts with hex"ef01" is the most general and futureproof.
// 7702 bytecode is `abi.encodePacked(hex"ef01", uint8(version), address(delegation))`.
result := eq(0xef01, shr(240, mload(0x00)))
}
}
/// @dev Returns the implementation of this contract.
function _selfImplementation() internal view virtual returns (address) {
return address(uint160(__self));
}
/// @dev Returns whether the current call context is on the implementation itself.
function _onImplementation() internal view virtual returns (bool) {
return __self == uint160(address(this));
}
/// @dev Requires that the current call context is performed via a EIP7702 authority.
function _checkOnlyEIP7702Authority() internal view virtual {
if (!_onEIP7702Authority()) _revertUnauthorizedCallContext();
}
/// @dev Requires that the current call context is performed via a proxy.
function _checkOnlyProxy() internal view virtual {
if (_onImplementation()) _revertUnauthorizedCallContext();
}
/// @dev Requires that the current call context is NOT performed via a proxy.
/// This is the opposite of `checkOnlyProxy`.
function _checkNotDelegated() internal view virtual {
if (!_onImplementation()) _revertUnauthorizedCallContext();
}
/// @dev Requires that the current call context is performed via a EIP7702 authority.
modifier onlyEIP7702Authority() virtual {
_checkOnlyEIP7702Authority();
_;
}
/// @dev Requires that the current call context is performed via a proxy.
modifier onlyProxy() virtual {
_checkOnlyProxy();
_;
}
/// @dev Requires that the current call context is NOT performed via a proxy.
/// This is the opposite of `onlyProxy`.
modifier notDelegated() virtual {
_checkNotDelegated();
_;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PRIVATE HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
function _revertUnauthorizedCallContext() private pure {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x9f03a026) // `UnauthorizedCallContext()`.
revert(0x1c, 0x04)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @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);
}{
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solady/=lib/solady/src/"
],
"optimizer": {
"enabled": false,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": true
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"AllowanceOverflow","type":"error"},{"inputs":[],"name":"AllowanceUnderflow","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"GasCrankCooldown","type":"error"},{"inputs":[],"name":"GasCrankWithdrawExceedsMax","type":"error"},{"inputs":[],"name":"InsufficientAllowance","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidInput","type":"error"},{"inputs":[],"name":"InvalidLength","type":"error"},{"inputs":[],"name":"InvalidPermit","type":"error"},{"inputs":[],"name":"Locked","type":"error"},{"inputs":[],"name":"NativeAssetInsufficient","type":"error"},{"inputs":[],"name":"NativeAssetMismatch","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"Permit2AllowanceIsFixedAtInfinity","type":"error"},{"inputs":[],"name":"PermitExpired","type":"error"},{"inputs":[],"name":"Reentrancy","type":"error"},{"inputs":[],"name":"SharesBurnedZero","type":"error"},{"inputs":[],"name":"SharesMintedZero","type":"error"},{"inputs":[],"name":"TotalSupplyOverflow","type":"error"},{"inputs":[],"name":"Uint96Overflow","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"UnauthorizedCallContext","type":"error"},{"inputs":[],"name":"UpgradeFailed","type":"error"},{"inputs":[],"name":"WithdrawSwapMinOutNotMet","type":"error"},{"inputs":[],"name":"WithdrawalExceedsRestingBalance","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"baseAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quoteAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"name":"ActiveVaultDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"baseAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quoteAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesBurned","type":"uint256"}],"name":"ActiveVaultWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"baseAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quoteAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"gasCrank","type":"address"},{"indexed":false,"internalType":"uint256","name":"baseAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quoteAmount","type":"uint256"}],"name":"GasCrankWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"baseAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"quoteAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharesBurned","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"result","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calculateNotionalValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32[]","name":"buyPrices","type":"uint32[]"},{"internalType":"uint32[]","name":"sellPrices","type":"uint32[]"},{"internalType":"uint96[]","name":"buySizes","type":"uint96[]"},{"internalType":"uint96[]","name":"sellSizes","type":"uint96[]"}],"name":"cancelAllReplace","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_baseWithdraw","type":"uint256"},{"internalType":"uint256","name":"_quoteWithdraw","type":"uint256"}],"name":"crankGas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"ctx","outputs":[{"internalType":"contract IOrderBook","name":"book","type":"address"},{"internalType":"uint32","name":"pricePrecision","type":"uint32"},{"internalType":"uint8","name":"baseDecimals","type":"uint8"},{"internalType":"uint8","name":"quoteDecimals","type":"uint8"},{"internalType":"address","name":"base","type":"address"},{"internalType":"uint96","name":"sizePrecision","type":"uint96"},{"internalType":"address","name":"quote","type":"address"},{"internalType":"uint40","name":"head","type":"uint40"},{"internalType":"uint40","name":"tail","type":"uint40"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_baseAmount","type":"uint256"},{"internalType":"uint256","name":"_quoteAmount","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_totalAmountToPull","type":"uint256"},{"internalType":"uint256","name":"_amountToSwap","type":"uint256"},{"internalType":"uint256","name":"_minOut","type":"uint256"},{"internalType":"bool","name":"_isBaseAsset","type":"bool"}],"name":"depositSingleSide","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"gasCrank","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gasCrankCooldown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gasFeeOutMax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPostedBalances","outputs":[{"internalType":"uint256","name":"baseAmountPosted","type":"uint256"},{"internalType":"uint256","name":"quoteAmountPosted","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRestingBalances","outputs":[{"internalType":"uint256","name":"baseAmount","type":"uint256"},{"internalType":"uint256","name":"quoteAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_operator","type":"address"},{"internalType":"address","name":"_gasCrank","type":"address"},{"internalType":"address","name":"_targetMarket","type":"address"},{"internalType":"address","name":"_marginAccount","type":"address"},{"internalType":"uint256","name":"_unlockInterval","type":"uint256"},{"internalType":"uint256","name":"_gasFeeOutMax","type":"uint256"},{"internalType":"uint256","name":"_gasCrankCooldown","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastCrankTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"lastDepositTime","outputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marginAccount","outputs":[{"internalType":"contract IMarginAccount","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"operator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"}],"name":"previewDepositInAmounts","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_baseAmount","type":"uint256"},{"internalType":"uint256","name":"_quoteAmount","type":"uint256"}],"name":"previewDepositInShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"}],"name":"previewWithdrawInAmounts","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_baseAmount","type":"uint256"},{"internalType":"uint256","name":"_quoteAmount","type":"uint256"}],"name":"previewWithdrawInShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_gasCrank","type":"address"},{"internalType":"uint256","name":"_gasFeeOutMax","type":"uint256"},{"internalType":"uint256","name":"_gasCrankCooldown","type":"uint256"}],"name":"setGasParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_unlockInterval","type":"uint256"}],"name":"setUnlockInterval","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"unlockInterval","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_shares","type":"uint256"},{"internalType":"bool","name":"_isBaseForSwap","type":"bool"},{"internalType":"uint256","name":"_minOut","type":"uint256"}],"name":"withdrawSingleSide","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
60a0604052346100305761001161003f565b610019610035565b61685c6101c18239608051816166ae015261685c90f35b61003b565b60405190565b5f80fd5b610047610049565b565b610051610053565b565b61005b61005d565b565b610065610067565b565b61006f610071565b565b6100796100e8565b565b60018060a01b031690565b90565b61009d6100986100a29261007b565b610086565b61007b565b90565b6100ae90610089565b90565b6100ba906100a5565b90565b6100c690610089565b90565b90565b6100e06100db6100e59261007b565b610086565b6100c9565b90565b6100f061010e565b6101096101046100ff306100b1565b6100bd565b6100cc565b608052565b61011661014a565b565b90565b90565b5f1b90565b61013761013261013c92610118565b61011e565b61011b565b90565b1561014657565b5f80fd5b6101766101556101ac565b61016f6101696101645f610123565b61011b565b9161011b565b141561013f565b565b5f90565b90565b61019361018e6101989261017c565b61011e565b61011b565b90565b6101a963409feecd1961017f565b90565b6101b4610178565b506101bd61019b565b9056fe60c06040526004361015610015575b3661173457005b61001f5f356102fe565b806302527753146102f95780630516c55b146102f457806306fdde03146102ef578063095ea7b3146102ea57806318160ddd146102e55780631c26e621146102e057806321729db3146102db57806323b872dd146102d657806325692962146102d1578063277838df146102cc5780632e1a7d4d146102c75780633098f459146102c2578063313ce567146102bd578063322f1b35146102b8578063343054cd146102b3578063362a1f57146102ae5780633644e515146102a957806349476574146102a45780634e7e156e1461029f5780634f1ef2861461029a57806352d1902d1461029557806354d1f13d1461029057806354f9137a1461028b578063570ca735146102865780636463ffd114610281578063699f706e1461027c57806370a0823114610277578063715018a6146102725780637403c6cd1461026d5780637ecebe00146102685780638340582b146102635780638a69f5f21461025e5780638da5cb5b14610259578063905221a41461025457806395d89b411461024f578063a9059cbb1461024a578063d505accf14610245578063dd62ed3e14610240578063e04d89da1461023b578063e2bbb15814610236578063f04e283e14610231578063f0c175a31461022c578063f2fde38b14610227578063f742269d14610222578063fae5df6a1461021d5763fee81cf40361000e576116ff565b6116c9565b611694565b6115fd565b6115c9565b6115a0565b611574565b61153e565b611508565b6114a1565b6113b5565b611380565b61134b565b611307565b6112d1565b6112a2565b611227565b6111ea565b611140565b61110b565b6110d5565b611098565b610f36565b610ef0565b610e6a565b610e35565b610e0b565b610d45565b610d01565b610c82565b610c28565b610be4565b610ba3565b610b6e565b610b23565b610aed565b610aae565b6107a9565b610773565b610705565b610690565b61062e565b6105f8565b61056f565b6104bf565b610426565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f80fd5b60018060a01b031690565b61032a90610316565b90565b61033681610321565b0361033d57565b5f80fd5b9050359061034e8261032d565b565b9060208282031261036957610366915f01610341565b90565b61030e565b90565b61038561038061038a92610316565b61036e565b610316565b90565b61039690610371565b90565b6103a29061038d565b90565b906103af90610399565b5f5260205260405f2090565b1c90565b90565b6103d29060086103d793026103bb565b6103bf565b90565b906103e591546103c2565b90565b6103fe906103f96001915f926103a5565b6103da565b90565b90565b61040d90610401565b9052565b9190610424905f60208501940190610404565b565b346104565761045261044161043c366004610350565b6103e8565b610449610304565b91829182610411565b0390f35b61030a565b61046481610401565b0361046b57565b5f80fd5b9050359061047c8261045b565b565b9060208282031261049757610494915f0161046f565b90565b61030e565b9160206104bd9294936104b660408201965f830190610404565b0190610404565b565b346104f0576104d76104d236600461047e565b61173c565b906104ec6104e3610304565b9283928361049c565b0390f35b61030a565b5f9103126104ff57565b61030e565b5190565b60209181520190565b90825f9392825e0152565b601f801991011690565b61054561054e6020936105539361053c81610504565b93848093610508565b95869101610511565b61051c565b0190565b61056c9160208201915f818403910152610526565b90565b3461059f5761057f3660046104f5565b61059b61058a61184f565b610592610304565b91829182610557565b0390f35b61030a565b91906040838203126105cc57806105c06105c9925f8601610341565b9360200161046f565b90565b61030e565b151590565b6105df906105d1565b9052565b91906105f6905f602085019401906105d6565b565b346106295761062561061461060e3660046105a4565b90611867565b61061c610304565b918291826105e3565b0390f35b61030a565b3461065e5761063e3660046104f5565b61065a6106496118f2565b610651610304565b91829182610411565b0390f35b61030a565b919060408382031261068b578061067f610688925f860161046f565b9360200161046f565b90565b61030e565b346106c1576106bd6106ac6106a6366004610663565b90611909565b6106b4610304565b91829182610411565b0390f35b61030a565b90916060828403126106fb576106f86106e1845f8501610341565b936106ef816020860161046f565b9360400161046f565b90565b61030e565b5f0190565b346107345761071e6107183660046106c6565b91611ab0565b610726610304565b8061073081610700565b0390f35b61030a565b909160608284031261076e5761076b610754845f8501610341565b936107628160208601610341565b9360400161046f565b90565b61030e565b346107a4576107a061078f610789366004610739565b91611b17565b610797610304565b918291826105e3565b0390f35b61030a565b6107b43660046104f5565b6107bc611bc0565b6107c4610304565b806107ce81610700565b0390f35b5f1c90565b60018060a01b031690565b6107ee6107f3916107d2565b6107d7565b90565b61080090546107e2565b90565b60a01c90565b63ffffffff1690565b61081e61082391610803565b610809565b90565b6108309054610812565b90565b60c01c90565b60ff1690565b61084b61085091610833565b610839565b90565b61085d905461083f565b90565b60c81c90565b61087261087791610860565b610839565b90565b6108849054610866565b90565b60018060a01b031690565b61089e6108a3916107d2565b610887565b90565b6108b09054610892565b90565b6bffffffffffffffffffffffff1690565b6108d06108d591610803565b6108b3565b90565b6108e290546108c4565b90565b64ffffffffff1690565b6108fb61090091610803565b6108e5565b90565b61090d90546108ef565b90565b61091c61092191610860565b6108e5565b90565b61092e9054610910565b90565b600261093e5f82016107f6565b9161094a5f8301610826565b916109565f8201610853565b916109625f830161087a565b9161096f600182016108a6565b9161097c600183016108d8565b91610989600282016108a6565b916109a1600261099a818501610903565b9301610924565b90565b6109ad9061038d565b90565b6109b9906109a4565b9052565b63ffffffff1690565b6109cf906109bd565b9052565b60ff1690565b6109e2906109d3565b9052565b6109ef90610321565b9052565b6bffffffffffffffffffffffff1690565b610a0d906109f3565b9052565b64ffffffffff1690565b610a2490610a11565b9052565b9694929099989795939161012088019a5f8901610a44916109b0565b60208801610a51916109c6565b60408701610a5e916109d9565b60608601610a6b916109d9565b60808501610a78916109e6565b60a08401610a8591610a04565b60c08301610a92916109e6565b60e08201610a9f91610a1b565b61010001610aac91610a1b565b565b34610ae857610abe3660046104f5565b610ae4610ac9610931565b95610adb999799959195949294610304565b998a998a610a28565b0390f35b61030a565b34610b1e57610b05610b0036600461047e565b611f36565b90610b1a610b11610304565b9283928361049c565b0390f35b61030a565b34610b5457610b3b610b3636600461047e565b611f54565b90610b50610b47610304565b9283928361049c565b0390f35b61030a565b9190610b6c905f602085019401906109d9565b565b34610b9e57610b7e3660046104f5565b610b9a610b89611fad565b610b91610304565b91829182610b59565b0390f35b61030a565b34610bd157610bbb610bb636600461047e565b611fe2565b610bc3610304565b80610bcd81610700565b0390f35b61030a565b610be15f5f906103da565b90565b34610c1457610bf43660046104f5565b610c10610bff610bd6565b610c07610304565b91829182610411565b0390f35b61030a565b610c2560095f906103da565b90565b34610c5857610c383660046104f5565b610c54610c43610c19565b610c4b610304565b91829182610411565b0390f35b61030a565b90565b610c6990610c5d565b9052565b9190610c80905f60208501940190610c60565b565b34610cb257610c923660046104f5565b610cae610c9d61201a565b610ca5610304565b91829182610c6d565b0390f35b61030a565b610cc7906008610ccc93026103bb565b610887565b90565b90610cda9154610cb7565b90565b610ce960065f90610ccf565b90565b9190610cff905f602085019401906109e6565b565b34610d3157610d113660046104f5565b610d2d610d1c610cdd565b610d24610304565b91829182610cec565b0390f35b61030a565b610d4260085f906103da565b90565b34610d7557610d553660046104f5565b610d71610d60610d36565b610d68610304565b91829182610411565b0390f35b61030a565b5f80fd5b5f80fd5b5f80fd5b909182601f83011215610dc05781359167ffffffffffffffff8311610dbb576020019260018302840111610db657565b610d82565b610d7e565b610d7a565b919091604081840312610e0657610dde835f8301610341565b92602082013567ffffffffffffffff8111610e0157610dfd9201610d86565b9091565b610312565b61030e565b610e1f610e19366004610dc5565b9161218d565b610e27610304565b80610e3181610700565b0390f35b34610e6557610e453660046104f5565b610e61610e50612205565b610e58610304565b91829182610c6d565b0390f35b61030a565b610e753660046104f5565b610e7d612218565b610e85610304565b80610e8f81610700565b0390f35b610e9c816105d1565b03610ea357565b5f80fd5b90503590610eb482610e93565b565b9091606082840312610eeb57610ee8610ed1845f850161046f565b93610edf8160208601610ea7565b9360400161046f565b90565b61030e565b34610f2257610f09610f03366004610eb6565b91612cd4565b90610f1e610f15610304565b9283928361049c565b0390f35b61030a565b610f3360055f90610ccf565b90565b34610f6657610f463660046104f5565b610f62610f51610f27565b610f59610304565b91829182610cec565b0390f35b61030a565b909182601f83011215610fa55781359167ffffffffffffffff8311610fa0576020019260208302840111610f9b57565b610d82565b610d7e565b610d7a565b909182601f83011215610fe45781359167ffffffffffffffff8311610fdf576020019260208302840111610fda57565b610d82565b610d7e565b610d7a565b9091608082840312611093575f82013567ffffffffffffffff811161108e5783611014918401610f6b565b929093602082013567ffffffffffffffff81116110895781611037918401610f6b565b929093604082013567ffffffffffffffff8111611084578361105a918401610faa565b929093606082013567ffffffffffffffff811161107f5761107b9201610faa565b9091565b610312565b610312565b610312565b610312565b61030e565b346110d0576110ba6110ab366004610fe9565b969590959491949392936133b5565b6110c2610304565b806110cc81610700565b0390f35b61030a565b34611106576110e53660046104f5565b6110ed6138d8565b906111026110f9610304565b9283928361049c565b0390f35b61030a565b3461113b57611137611126611121366004610350565b613997565b61112e610304565b91829182610411565b0390f35b61030a565b61114b3660046104f5565b6111536139d8565b61115b610304565b8061116581610700565b0390f35b9190610100838203126111e557611182815f8501610341565b926111908260208301610341565b9261119e8360408401610341565b926111ac8160608501610341565b926111ba8260808301610341565b926111e26111cb8460a0850161046f565b936111d98160c0860161046f565b9360e00161046f565b90565b61030e565b346112225761120c6111fd366004611169565b96959095949194939293613ec9565b611214610304565b8061121e81610700565b0390f35b61030a565b346112575761125361124261123d366004610350565b613edb565b61124a610304565b91829182610411565b0390f35b61030a565b60808183031261129d57611272825f830161046f565b9261129a611283846020850161046f565b93611291816040860161046f565b93606001610ea7565b90565b61030e565b6112cd6112bc6112b336600461125c565b9291909161455c565b6112c4610304565b91829182610411565b0390f35b34611302576112e13660046104f5565b6112e9614573565b906112fe6112f5610304565b9283928361049c565b0390f35b61030a565b34611337576113173660046104f5565b6113336113226145b1565b61132a610304565b91829182610cec565b0390f35b61030a565b61134860075f906103da565b90565b3461137b5761135b3660046104f5565b61137761136661133c565b61136e610304565b91829182610411565b0390f35b61030a565b346113b0576113903660046104f5565b6113ac61139b61460f565b6113a3610304565b91829182610557565b0390f35b61030a565b346113e6576113e26113d16113cb3660046105a4565b90614623565b6113d9610304565b918291826105e3565b0390f35b61030a565b6113f4816109d3565b036113fb57565b5f80fd5b9050359061140c826113eb565b565b61141781610c5d565b0361141e57565b5f80fd5b9050359061142f8261140e565b565b60e08183031261149c57611447825f8301610341565b926114558360208401610341565b92611463816040850161046f565b92611471826060830161046f565b9261149961148284608085016113ff565b936114908160a08601611422565b9360c001611422565b90565b61030e565b346114d6576114c06114b4366004611431565b95949094939193614692565b6114c8610304565b806114d281610700565b0390f35b61030a565b919060408382031261150357806114f7611500925f8601610341565b93602001610341565b90565b61030e565b346115395761153561152461151e3660046114db565b90614881565b61152c610304565b91829182610411565b0390f35b61030a565b3461156f5761154e3660046104f5565b6115566148f7565b9061156b611562610304565b9283928361049c565b0390f35b61030a565b61159c61158b611585366004610663565b90614c44565b611593610304565b91829182610411565b0390f35b6115b36115ae366004610350565b614c9f565b6115bb610304565b806115c581610700565b0390f35b346115f8576115e26115dc366004610663565b90614cdc565b6115ea610304565b806115f481610700565b0390f35b61030a565b61161061160b366004610350565b614e84565b611618610304565b8061162281610700565b0390f35b60018060a01b031690565b61164190600861164693026103bb565b611626565b90565b906116549154611631565b90565b611663600a5f90611649565b90565b61166f9061038d565b90565b61167b90611666565b9052565b9190611692905f60208501940190611672565b565b346116c4576116a43660046104f5565b6116c06116af611657565b6116b7610304565b9182918261167f565b0390f35b61030a565b346116fa576116f66116e56116df366004610663565b90614e8f565b6116ed610304565b91829182610411565b0390f35b61030a565b3461172f5761172b61171a611715366004610350565b614eb5565b611722610304565b91829182610411565b0390f35b61030a565b5f80fd5b5f90565b61176d90611748611738565b50611751611738565b5061175a614573565b6117626118f2565b919091600193614ed1565b91909190565b606090565b634e487b7160e01b5f52604160045260245ffd5b906117969061051c565b810190811067ffffffffffffffff8211176117b057604052565b611778565b906117c86117c1610304565b928361178c565b565b67ffffffffffffffff81116117e8576117e460209161051c565b0190565b611778565b906117ff6117fa836117ca565b6117b5565b918252565b5f7f4b757275205661756c7400000000000000000000000000000000000000000000910152565b611835600a6117ed565b9061184260208301611804565b565b61184c61182b565b90565b611857611773565b50611860611844565b90565b5f90565b61186f611863565b50611878614f06565b6118c5575b602052637f5e9f20600c52335f52806034600c20555f52602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560205fa3600190565b8119156e22d473030f116ddee9f6b43ac78ba38260601b60601c181761187d57633f68539a5f526004601cfd5b6118fa611738565b506805345cdf77eb68f44c5490565b9061192c91611916611738565b5061191f614573565b9290929192909192614f14565b505090565b90611944929161193f615024565b611a25565b565b90565b61195d61195861196292611946565b61036e565b610316565b90565b61196e90611949565b90565b5f1b90565b9061198760018060a01b0391611971565b9181191691161790565b90565b906119a96119a46119b092610399565b611991565b8254611976565b9055565b6119c86119c36119cd92611946565b61036e565b610401565b90565b906119dc5f1991611971565b9181191691161790565b6119fa6119f56119ff92610401565b61036e565b610401565b90565b90565b90611a1a611a15611a21926119e6565b611a02565b82546119d0565b9055565b80611a40611a3a611a355f611965565b610321565b91610321565b03611a9f575b5080611a5a611a545f6119b4565b91610401565b03611a8e575b5080611a74611a6e5f6119b4565b91610401565b03611a7d575b50565b611a88906008611a05565b5f611a7a565b611a99906007611a05565b5f611a60565b611aaa906006611994565b5f611a46565b90611abb9291611931565b565b611ac9611ace916107d2565b6103bf565b90565b611adb9054611abd565b90565b634e487b7160e01b5f52601160045260245ffd5b611b01611b0791939293610401565b92610401565b8201809211611b1257565b611ade565b91611b20611863565b50611b47611b38611b33600186906103a5565b611ad1565b611b415f611ad1565b90611af2565b611b59611b5342610401565b91610401565b11611b6d57611b6a92919091615040565b90565b5f6303cb96db60e21b815280611b8560048201610700565b0390fd5b67ffffffffffffffff1690565b611baa611ba5611baf92611b89565b61036e565b610401565b90565b90611bbd9101610401565b90565b611bda42611bd4611bcf6151fa565b611b96565b90611bb2565b63389a75e1600c52335f526020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d5f80a2565b90565b611c29611c24611c2e92611c12565b61036e565b610401565b90565b611c43688000000000ab143c06611c15565b90565b90565b611c5d611c58611c6292611c46565b61036e565b610401565b90565b929190611c70615212565b5f14611d2857611c7e611c31565b9346611c93611c8d6001611c49565b91610401565b145f14611d0a57845c611d0157611caf939430905d5b5b611de0565b9091611cb9615212565b5f14611cf057611cc7611c31565b46611cdb611cd56001611c49565b91610401565b145f14611ce9575f905d5b5b565b8055611ce6565b5f688000000000ab143c065d611ce7565b845f526004601cfd5b30855414611d1f57611caf9394309055611ca9565b845f526004601cfd5b688000000000ab143c069392935c611d4f57611caf9230688000000000ab143c065d611caa565b63ab143c065f526004601cfd5b15611d6357565b5f630638288b60e31b815280611d7b60048201610700565b0390fd5b15611d8657565b5f6303cb96db60e21b815280611d9e60048201610700565b0390fd5b611dd7611dde94611dcd606094989795611dc3608086019a5f8701906109e6565b6020850190610404565b6040830190610404565b0190610404565b565b9291925050611e0182611dfb611df55f6119b4565b91610401565b11611d5c565b611e42611e2a611e1b611e16600133906103a5565b611ad1565b611e245f611ad1565b90611af2565b611e3c611e3642610401565b91610401565b10611d7f565b611e4a6148f7565b92909290611e80611e596138d8565b908391611e78611e71611e6a6118f2565b938a611af2565b9187611af2565b915f93614ed1565b92909294611e97611e918592610401565b91610401565b11908115611f1a575b50611efe57611eb0338290615220565b611ebc82853391615295565b338290611ef786937f0f026689e85a8d17644dcfde4a809a89d61d408ce737d1f1e9bdca05fbed20da94611eee610304565b94859485611da2565b0390a19190565b5f63503ae32b60e11b815280611f1660048201610700565b0390fd5b9050611f2f611f298692610401565b91610401565b115f611ea0565b611f5090611f42611738565b611f4a611738565b90611c65565b9091565b611f8490611f60611738565b50611f69611738565b50611f72614573565b611f7a6118f2565b9190915f93614ed1565b91909190565b5f90565b90565b611fa5611fa0611faa92611f8e565b61036e565b6109d3565b90565b611fb5611f8a565b50611fc06012611f91565b90565b611fd490611fcf615024565b611fd6565b565b611fe0905f611a05565b565b611feb90611fc3565b565b5f90565b61200561200061200a92611946565b611971565b610c5d565b90565b90565b60200190565b5190565b612022611fed565b5061202b6152e0565b8061204661204061203b5f611ff1565b610c5d565b91610c5d565b14612098575b60a090612057615336565b604051917f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8352602083015260408201524660608201523060808201522090565b5060a06120ab6120a661184f565b61200d565b6120bd6120b782612016565b91612010565b20905061204c565b906120d892916120d361534a565b6120da565b565b9190916120e68161535d565b60601b60601c3d5f526352d1902d6001527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80602060016004601d865afa510361217f57818391817fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f38a25561215d575b505050565b815f926040519485378338925af415612177578080612158565b3d5f823e3d90fd5b6355299b496001526004601dfd5b9061219892916120c5565b565b6121ab906121a6615368565b6121f9565b90565b90565b6121c56121c06121ca926121ae565b611971565b610c5d565b90565b6121f67f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc6121b1565b90565b506122026121cd565b90565b612215612210611fed565b61219a565b90565b63389a75e1600c52335f525f6020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c925f80a2565b949392919061225e615212565b5f146123165761226c611c31565b954661228161227b6001611c49565b91610401565b145f146122f857865c6122ef5761229d959630905d5b5b61267b565b90916122a7615212565b5f146122de576122b5611c31565b466122c96122c36001611c49565b91610401565b145f146122d7575f905d5b5b565b80556122d4565b5f688000000000ab143c065d6122d5565b865f526004601cfd5b3087541461230d5761229d9596309055612297565b865f526004601cfd5b688000000000ab143c069594955c61233d5761229d9430688000000000ab143c065d612298565b63ab143c065f526004601cfd5b61235390610321565b90565b906123609061234a565b9052565b9061236e906109bd565b9052565b9061237c906109d3565b9052565b9061238a90610321565b9052565b90612398906109f3565b9052565b906123a690610a11565b9052565b6123b56101206117b5565b90565b9061249361248960026123c96123aa565b946123e06123d85f83016107f6565b5f8801612356565b6123f76123ee5f8301610826565b60208801612364565b61240e6124055f8301610853565b60408801612372565b61242561241c5f830161087a565b60608801612372565b61243d612434600183016108a6565b60808801612380565b61245561244c600183016108d8565b60a0880161238e565b61246c6124638383016108a6565b60c08801612380565b61248361247a838301610903565b60e0880161239c565b01610924565b610100840161239c565b565b61249e906123b8565b90565b6124ab9051610321565b90565b6124b8905161234a565b90565b6124c590516109bd565b90565b6124dc6124d76124e1926109bd565b61036e565b610401565b90565b6124f36124f991939293610401565b92610401565b91612505838202610401565b92818404149015171561251457565b611ade565b61252390516109d3565b90565b61252f906109d3565b604d811161253d57600a0a90565b611ade565b634e487b7160e01b5f52601260045260245ffd5b61256261256891610401565b91610401565b908115612573570490565b612542565b5f80fd5b60e01b90565b9050519061258f8261045b565b565b906020828203126125aa576125a7915f01612582565b90565b61030e565b6125b8906119b4565b9052565b6125f16125f8946125e76060949897956125dd608086019a5f870190610a04565b60208501906125af565b60408301906105d6565b01906105d6565b565b612602610304565b3d5f823e3d90fd5b61261490516109f3565b90565b61262b612626612630926109f3565b61036e565b610401565b90565b61264261264891939293610401565b92610401565b820391821161265357565b611ade565b1561265f57565b5f63178dff1560e31b81528061267760048201610700565b0390fd5b949394505061269c816126966126905f6119b4565b91610401565b11611d5c565b6126dd6126c56126b66126b1600133906103a5565b611ad1565b6126bf5f611ad1565b90611af2565b6126d76126d142610401565b91610401565b10611d7f565b6126e76002612495565b936126ff6126f7608087016124a1565b600190615384565b9461271761270f60c083016124a1565b600190615384565b61271f6148f7565b979097956127578961272f6138d8565b91909161274f6127488b946127426118f2565b94611af2565b918c611af2565b915f93614ed1565b9790979961276e6127688a92610401565b91610401565b11908115612cb8575b50612c9c57612787338790615220565b61279d87612797608087016124a1565b90615492565b6127b3896127ad60c087016124a1565b90615492565b6127bb611738565b815f14612c25576127ce608086016124a1565b6127e86127e26127dd5f611965565b610321565b91610321565b145f14612bf75750865b5b815f14612b165760208861281061280b5f89016124ae565b6109a4565b9261287f61286161285c8a612856612851604061284a63532c46db989b989b9961284461283f60a0880161260a565b612617565b906124e4565b9301612519565b612526565b90612556565b6155b8565b925f9561288a5f600190612873610304565b998a988997889661257c565b8652600486016125bc565b03925af18015612b11576129349361291d9261290192612ae5575b505b8380612ab7575b5f14612a39576128e56128c3608089016124a1565b6128d66128d15f8b016124ae565b6109a4565b6128df5f6119b4565b91615523565b5b6128fc6128f5608089016124a1565b5f90615384565b612633565b9361291861291160c088016124a1565b5f90615384565b612633565b948180612a1e575b9182156129e6575b5050612658565b806129476129415f6119b4565b91610401565b116129c9575b508161296161295b5f6119b4565b91610401565b116129ab575b50503382906129a486937f0f026689e85a8d17644dcfde4a809a89d61d408ce737d1f1e9bdca05fbed20da9461299b610304565b94859485611da2565b0390a19190565b6129bb60c06129c29392016124a1565b33916155ea565b5f80612967565b6129e0906129d9608084016124a1565b33916155ea565b5f61294d565b6129f2919250156105d1565b9081612a01575b505f8061292d565b9050612a16612a108492610401565b91610401565b10155f6129f9565b5085612a32612a2c83610401565b91610401565b1015612925565b612a4384156105d1565b80612a89575b612a53575b6128e6565b612a84612a6260c089016124a1565b612a75612a705f8b016124ae565b6109a4565b612a7e5f6119b4565b91615523565b612a4e565b50612a9660c088016124a1565b612ab0612aaa612aa55f611965565b610321565b91610321565b1415612a49565b50612ac4608088016124a1565b612ade612ad8612ad35f611965565b610321565b91610321565b14156128ae565b612b059060203d8111612b0a575b612afd818361178c565b810190612591565b6128a5565b503d612af3565b6125fa565b60208a612b2c612b275f89016124ae565b6109a4565b92612b9a612b7c612b778a612b71612b6c6060612b65637c51d6cf989b989b99612b5f612b5a8d88016124bb565b6124c8565b906124e4565b9301612519565b612526565b90612556565b6155b8565b925f95612ba55f600190612b8e610304565b998a988997889661257c565b8652600486016125bc565b03925af18015612bf2576129349361291d9261290192612bc6575b506128a7565b612be69060203d8111612beb575b612bde818361178c565b810190612591565b612bc0565b503d612bd4565b6125fa565b612c20612c06608087016124a1565b612c19612c145f89016124ae565b6109a4565b8a91615523565b6127f2565b612c2f82156105d1565b612c39575b6127f3565b612c4560c086016124a1565b612c5f612c59612c545f611965565b610321565b91610321565b145f14612c6e5750885b612c34565b612c97612c7d60c087016124a1565b612c90612c8b5f89016124ae565b6109a4565b8c91615523565b612c69565b5f63503ae32b60e11b815280612cb460048201610700565b0390fd5b9050612ccd612cc78b92610401565b91610401565b115f612777565b90612cf09291612ce2611738565b612cea611738565b90612251565b9091565b5090565b5090565b612d069051610a11565b90565b612d1d612d18612d2292611946565b61036e565b610a11565b90565b612d31612d3791610a11565b91610a11565b90039064ffffffffff8211612d4857565b611ade565b612d61612d5c612d6692611c46565b61036e565b610a11565b90565b612d75612d7b91610a11565b91610a11565b019064ffffffffff8211612d8b57565b611ade565b612da4612d9f612da992610a11565b61036e565b610401565b90565b67ffffffffffffffff8111612dc45760208091020190565b611778565b90612ddb612dd683612dac565b6117b5565b918252565b369037565b90612e0a612df283612dc9565b92602080612e008693612dac565b9201910390612de0565b565b612e1590610a11565b64ffffffffff8114612e275760010190565b611ade565b634e487b7160e01b5f52603260045260245ffd5b5190565b90612e4e82612e40565b811015612e5f576020809102010190565b612e2c565b67ffffffffffffffff8111612e7c5760208091020190565b611778565b90612e93612e8e83612e64565b6117b5565b918252565b369037565b90612ec2612eaa83612e81565b92602080612eb88693612e64565b9201910390612e98565b565b67ffffffffffffffff8111612edc5760208091020190565b611778565b90612ef3612eee83612ec4565b6117b5565b918252565b369037565b90612f22612f0a83612ee1565b92602080612f188693612ec4565b9201910390612ef8565b565b5f910312612f2e57565b61030e565b5190565b60209181520190565b60200190565b612f4f906109bd565b9052565b90612f6081602093612f46565b0190565b60200190565b90612f87612f81612f7a84612f33565b8093612f37565b92612f40565b905f5b818110612f975750505090565b909192612fb0612faa6001928651612f53565b94612f64565b9101919091612f8a565b5190565b60209181520190565b60200190565b612fd6906109f3565b9052565b90612fe781602093612fcd565b0190565b60200190565b9061300e61300861300184612fba565b8093612fbe565b92612fc7565b905f5b81811061301e5750505090565b9091926130376130316001928651612fda565b94612feb565b9101919091613011565b60209181520190565b60200190565b61305990610a11565b9052565b9061306a81602093613050565b0190565b60200190565b9061309161308b61308484612e40565b8093613041565b9261304a565b905f5b8181106130a15750505090565b9091926130ba6130b4600192865161305d565b9461306e565b9101919091613094565b96959361311d9061310f60a09561310161312b966130f28d6131339c9860c08201915f818403910152612f6a565b908d6020818403910152612ff1565b908b820360408d0152612f6a565b9089820360608b0152612ff1565b908782036080890152613074565b9401906105d6565b565b60a01b90565b9061314e64ffffffffff60a01b91613135565b9181191691161790565b61316c61316761317192610a11565b61036e565b610a11565b90565b90565b9061318c61318761319392613158565b613174565b825461313b565b9055565b60c81b90565b906131b064ffffffffff60c81b91613197565b9181191691161790565b906131cf6131ca6131d692613158565b613174565b825461319d565b9055565b6131e381610a11565b036131ea57565b5f80fd5b905051906131fb826131da565b565b9060208282031261321657613213915f016131ee565b90565b61030e565b90565b613227816109bd565b0361322e57565b5f80fd5b9050359061323f8261321e565b565b50613250906020810190613232565b90565b60200190565b916132678261326d92612f37565b9261321b565b90815f905b828210613280575050505090565b909192936132a261329c6001926132978886613241565b612f53565b95613253565b920190929192613272565b90565b6132b9816109f3565b036132c057565b5f80fd5b905035906132d1826132b0565b565b506132e29060208101906132c4565b90565b60200190565b916132f9826132ff92612fbe565b926132ad565b90815f905b828210613312575050505090565b9091929361333461332e60019261332988866132d3565b612fda565b956132e5565b920190929192613304565b9a999791946133ab966133808d61339d9760a09b976133726133b39f9b9761338f9860c08601918683035f880152613259565b9260208185039101526132eb565b918d6040818503910152613259565b918a830360608c01526132eb565b908782036080890152613074565b9401906105d6565b565b91969392966133c26156aa565b6133cd838390612cf4565b6133e96133e36133de878a90612cf8565b610401565b91610401565b141580156138a9575b61388d576134006002612495565b9761340d60e08a01612cfc565b61341f6134195f612d09565b91610a11565b036136d0575b613430848490612cf4565b61344261343c5f6119b4565b91610401565b1180156136ac575b5f146136745761347e60206134686134635f8d016124ae565b6109a4565b632bf1360e90613476610304565b93849261257c565b8252815f8161348f60048201610700565b03925af190811561366f575f91613641575b50976134b66134b15f8c016124ae565b6109a4565b96635339c59f9594969893929190916134d66134d15f6119b4565b612de5565b936001958a3b1561363c576134e9610304565b9b8c9a6134f68c9b61257c565b8b5260048b01996135069a61333f565b03815a5f948591f19081613610575b50155f14613559575050600161352a575b5b5b565b61353f6135365f612d09565b60028001613177565b61355461354b5f612d09565b600280016131ba565b613526565b602061357161356c5f61358795016124ae565b6109a4565b632bf1360e9061357f610304565b94859261257c565b8252815f8161359860048201610700565b03925af1801561360b576135c66135cf916135d8945f916135dd575b50926135c06001612d4d565b90612d69565b60028001613177565b600280016131ba565b613527565b6135fe915060203d8111613604575b6135f6818361178c565b8101906131fd565b5f6135b4565b503d6135ec565b6125fa565b61362f905f3d8111613635575b613627818361178c565b810190612f24565b5f613515565b503d61361d565b612578565b613662915060203d8111613668575b61365a818361178c565b8101906131fd565b5f6134a1565b503d613650565b6125fa565b5050505050505050506136926136895f612d09565b60028001613177565b6136a761369e5f612d09565b600280016131ba565b613528565b506136b8828290612cf4565b6136ca6136c45f6119b4565b91610401565b1161344a565b989695949392919061371e6137196137146137048c6136fe60e06136f76101008401612cfc565b9201612cfc565b90612d25565b61370e6001612d4d565b90612d69565b612d90565b612de5565b9961372b60e08b01612cfc565b60a0525b8961375161374b61374661010060a0519401612cfc565b610a11565b91610a11565b116137a15761378e8b6137898c61378361377e60a051949261377860e060a0519201612cfc565b90612d25565b612d90565b90612e44565b61239c565b61379960a051612e0c565b60a05261372f565b9091929394959697996137bd6137b85f8c016124ae565b6109a4565b90635339c59f916137d56137d05f6119b4565b612e9d565b906137e76137e25f6119b4565b612efd565b936137f96137f45f6119b4565b612e9d565b9361380b6138065f6119b4565b612efd565b9091600195843b15613888575f966138379488946138429361382b610304565b9b8c9a8b998a9861257c565b8852600488016130c4565b03925af1801561388357613857575b50613425565b613876905f3d811161387c575b61386e818361178c565b810190612f24565b5f613851565b503d613864565b6125fa565b612578565b5f63251f56a160e21b8152806138a560048201610700565b0390fd5b506138b5818990612cf4565b6138d16138cb6138c68a8990612cf8565b610401565b91610401565b14156133f2565b6138e0611738565b6138e8611738565b906138f560028001610903565b9161390260028001610924565b8361391561390f5f612d09565b91610a11565b1461397b5792905b8161393061392a86610a11565b91610a11565b116139755761393e826157e3565b5f1461395f57613959916139529190611af2565b915b612e0c565b9061391d565b61395991929361396f9190611af2565b92613954565b92505091565b505050505f9061399461398e5f936119b4565b926119b4565b90565b61399f611738565b506387a211a2600c525f526020600c205490565b6139bb615024565b6139c36139c5565b565b6139d66139d15f611965565b615acd565b565b6139e06139b3565b565b95939196949290966139f2615b85565b9687548060038a55613a4d575b50908798613a11979695949392613ba3565b613a19575b50565b6002905560016020527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602080a15f613a16565b9695949392919097600188811c14303b1015613a7857613a119760ff1b1b97909192939495966139ff565b63f92ee8a95f526004601cfd5b15613a8c57565b5f63b4fa3fb360e01b815280613aa460048201610700565b0390fd5b90565b613abf613aba613ac492613aa8565b61036e565b610401565b90565b613ad090610371565b90565b613adc90613ac7565b90565b613ae890613ac7565b90565b90565b90613b03613afe613b0a92613adf565b613aeb565b8254611976565b9055565b613b1790610371565b90565b613b2390613b0e565b90565b613b2f9061038d565b90565b613b3e613b43916107d2565b611626565b90565b613b509054613b32565b90565b90505190613b6082610e93565b565b90602082820312613b7b57613b78915f01613b53565b90565b61030e565b916020613ba1929493613b9a60408201965f8301906109e6565b0190610404565b565b613cd19291613cc3613cd69695613cbe613cca94613cfd9c9b613cdd9b60805260a052613beb85613be4613bde613bd95f611965565b610321565b91610321565b1415613a85565b613c1087613c09613c03613bfe5f611965565b610321565b91610321565b1415613a85565b613c3583613c2e613c28613c235f611965565b610321565b91610321565b1415613a85565b613c5a89613c53613c4d613c485f611965565b610321565b91610321565b1415613a85565b613c78608051613c72613c6c5f6119b4565b91610401565b11613a85565b60a051613c8d613c875f6119b4565b91610401565b1180613ea5575b613c9d90613a85565b613cb98c613cb3613cad5f6119b4565b91610401565b11613a85565b615b99565b615e97565b6005611994565b6006611994565b613ad3565b600a613aee565b613ce96080515f611a05565b613cf660a0516007611a05565b6008611a05565b613d0a60016002016108a6565b613d24613d1e613d195f611965565b610321565b91610321565b03613dfe575b613d36600280016108a6565b613d50613d4a613d455f611965565b610321565b91610321565b03613d58575b565b613d74613d6f613d6a600280016108a6565b613b1a565b613b26565b602063095ea7b391613d8e613d89600a613b46565b611666565b90613dad5f801995613db8613da1610304565b9788968795869461257c565b845260048401613b80565b03925af18015613df957613dcd575b50613d56565b613ded9060203d8111613df2575b613de5818361178c565b810190613b62565b613dc7565b503d613ddb565b6125fa565b613e1b613e16613e1160016002016108a6565b613b1a565b613b26565b602063095ea7b391613e35613e30600a613b46565b611666565b90613e545f801995613e5f613e48610304565b9788968795869461257c565b845260048401613b80565b03925af18015613ea057613e74575b50613d2a565b613e949060203d8111613e99575b613e8c818361178c565b810190613b62565b613e6e565b503d613e82565b6125fa565b50613c9d60a051613ec0613eba612710613aab565b91610401565b11159050613c94565b90613ed9979695949392916139e2565b565b613ee3611738565b506338377508600c525f526020600c205490565b9493929190613f04615212565b5f14613fbb57613f12611c31565b9546613f27613f216001611c49565b91610401565b145f14613f9d57865c613f9457613f43959630905d5b5b61407f565b90613f4c615212565b5f14613f8357613f5a611c31565b46613f6e613f686001611c49565b91610401565b145f14613f7c575f905d5b5b565b8055613f79565b5f688000000000ab143c065d613f7a565b865f526004601cfd5b30875414613fb257613f439596309055613f3d565b865f526004601cfd5b688000000000ab143c069594955c613fe257613f439430688000000000ab143c065d613f3e565b63ab143c065f526004601cfd5b15613ff657565b5f63fd99316160e01b81528061400e60048201610700565b0390fd5b61401b9061038d565b90565b61405361405a9461404960609498979561403f608086019a5f870190610a04565b6020850190610404565b60408301906105d6565b01906105d6565b565b1561406357565b5f63149196c760e21b81528061407b60048201610700565b0390fd5b9390929350816140976140915f6119b4565b91610401565b118061453d575b6140a790613a85565b6140b16002612495565b9160206140cb6140c3608086016124a1565b600190615384565b956140e36140db60c087016124a1565b600190615384565b95845f1461452c576140f7608087016124a1565b5b94614101611738565b918661411d6141176141125f611965565b610321565b91610321565b14155f146145065761413c9087903361413530614012565b9192615fcc565b61415a8661415361414e5f8b016124ae565b6109a4565b8791615523565b5b5f14614435576141e26141776141725f89016124ae565b6109a4565b946141c56141c06141a68a6141a061419b60a063532c46db999c999c97930161260a565b612617565b906124e4565b6141ba6141b560408d01612519565b612526565b90612556565b6155b8565b93956141ed5f6001906141d6610304565b998a988997889661257c565b86526004860161401e565b03925af1801561443057614404575b505b8061421961421361420e5f611965565b610321565b91610321565b036143d8575b50614364614348614284614231614573565b614239611738565b5061425a61425361424c608089016124a1565b5f90615384565b8990612633565b61427a61427361426c60c08a016124a1565b5f90615384565b8990612633565b9092909192614f14565b9691966142a38861429d6142975f6119b4565b91610401565b1161405c565b6142ae33899061602b565b6142c3426142be600133906103a5565b611a05565b6142d9826142d3608089016124a1565b906160d0565b6142ef816142e960c089016124a1565b906160d0565b3391909161432a897ff7ed121cfb40d57714b8349a1791bb3d55e16464fe62844d8ab562e66805272794614321610304565b94859485611da2565b0390a161434361433c608086016124a1565b5f90615384565b612633565b9261435f61435860c085016124a1565b5f90615384565b612633565b91806143786143725f6119b4565b91610401565b116143bb575b508161439261438c5f6119b4565b91610401565b1161439d575b505090565b6143ad60c06143b49392016124a1565b33916155ea565b5f80614398565b6143d2906143cb608084016124a1565b33916155ea565b5f61437e565b6143fe906143ef6143ea5f85016124ae565b6109a4565b6143f85f6119b4565b91615523565b5f61421f565b6144249060203d8111614429575b61441c818361178c565b810190612591565b6141fc565b503d614412565b6125fa565b6144b561444b6144465f89016124ae565b6109a4565b946144986144936144798a61447361446e8a637c51d6cf999c999c9793016124bb565b6124c8565b906124e4565b61448d61448860608d01612519565b612526565b90612556565b6155b8565b93956144c05f6001906144a9610304565b998a988997889661257c565b86526004860161401e565b03925af18015614501576144d5575b506141fe565b6144f59060203d81116144fa575b6144ed818361178c565b810190612591565b6144cf565b503d6144e3565b6125fa565b61452591925061451f6145193492610401565b91610401565b14613fef565b839061415b565b61453860c087016124a1565b6140f8565b506140a78361455461454e85610401565b91610401565b11905061409e565b9061457093929161456b611738565b613ef7565b90565b6145aa9061457f611738565b50614588611738565b506145916148f7565b92906145a461459e6138d8565b92611af2565b93611af2565b90565b5f90565b6145b96145ad565b50638b78c6d8195490565b5f7f4b5552552d5641554c5400000000000000000000000000000000000000000000910152565b6145f5600a6117ed565b90614602602083016145c4565b565b61460c6145eb565b90565b614617611773565b50614620614604565b90565b9061462c611863565b5061465361464461463f600133906103a5565b611ad1565b61464d5f611ad1565b90611af2565b61466561465f42610401565b91610401565b11614676576146739161622d565b90565b5f6303cb96db60e21b81528061468e60048201610700565b0390fd5b959490939192946146a1614f06565b614841575b6146ae6152e0565b91826146ca6146c46146bf5f611ff1565b610c5d565b91610c5d565b14614816575b6146d8615336565b93874211614809576040519860601b60601c9660601b60601c9765383775081901600e52875f526020600c20958654957f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8c5260208c015260408b01524660608b01523060808b015260a08a20602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98a528760208b01528860408b01528660608b01528460808b015260a08a015260c08920604e526042602c205f5260ff1660205260405260605260208060805f60015afa90843d51036147fc5701905582637f5e9f2060a01b176040526034602c20557f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925602060608501a36040525f606052565b63ddafbaef5f526004601cfd5b631a15a3cc5f526004601cfd5b915061482861482361184f565b61200d565b61483a61483482612016565b91612010565b20916146d0565b8319156e22d473030f116ddee9f6b43ac78ba38660601b60601c18176146a657633f68539a5f526004601cfd5b6e22d473030f116ddee9f6b43ac78ba390565b9061488a611738565b50614893614f06565b6148ae575b602052637f5e9f20600c525f526034600c205490565b806148c86148c26148bd61486e565b610321565b91610321565b036148985750505f1990565b9160206148f59294936148ee60408201965f8301906109e6565b01906109e6565b565b6148ff611738565b50614908611738565b5061491b614916600a613b46565b611666565b602063d4fac45d9161492c30614012565b9061495561493d60016002016108a6565b94614960614949610304565b9687958694859461257c565b8452600484016148d4565b03915afa908115614a41575f91614a13575b5090614986614981600a613b46565b611666565b602063d4fac45d9161499730614012565b906149bf6149a7600280016108a6565b946149ca6149b3610304565b9687958694859461257c565b8452600484016148d4565b03915afa908115614a0e575f916149e0575b5090565b614a01915060203d8111614a07575b6149f9818361178c565b810190612591565b5f6149dc565b503d6149ef565b6125fa565b614a34915060203d8111614a3a575b614a2c818361178c565b810190612591565b5f614972565b503d614a22565b6125fa565b929190614a51615212565b5f14614b0857614a5f611c31565b9346614a74614a6e6001611c49565b91610401565b145f14614aea57845c614ae157614a90939430905d5b5b614b5f565b90614a99615212565b5f14614ad057614aa7611c31565b46614abb614ab56001611c49565b91610401565b145f14614ac9575f905d5b5b565b8055614ac6565b5f688000000000ab143c065d614ac7565b845f526004601cfd5b30855414614aff57614a909394309055614a8a565b845f526004601cfd5b688000000000ab143c069392935c614b2f57614a909230688000000000ab143c065d614a8b565b63ab143c065f526004601cfd5b15614b4357565b5f63cd41a9e360e01b815280614b5b60048201610700565b0390fd5b90614bec929150614b7360016002016108a6565b614b8d614b87614b825f611965565b610321565b91610321565b148015614c17575b5f14614bfb57614be734614bac60016002016108a6565b614bc6614bc0614bbb5f611965565b610321565b91610321565b145f14614bef57614be0614bda845b610401565b91610401565b145b614b3c565b6162a2565b90565b614be0614bda85614bd5565b614be734614c11614c0b5f6119b4565b91610401565b14614be2565b50614c24600280016108a6565b614c3e614c38614c335f611965565b610321565b91610321565b14614b95565b90614c5691614c51611738565b614a46565b90565b614c6a90614c65615024565b614c6c565b565b63389a75e1600c52805f526020600c209081544211614c92575f614c909255615acd565b565b636f5e88185f526004601cfd5b614ca890614c59565b565b604090614cd3614cda9496959396614cc960608401985f8501906109e6565b6020830190610404565b0190610404565b565b90614ce5616491565b42614d14614d0e614d09614cf96009611ad1565b614d036008611ad1565b90611af2565b610401565b91610401565b10614e3457614d3f614d72614d61614d50614d2d614573565b9490614d396007611ad1565b906124e4565b614d4a612710613aab565b90612556565b92614d5b6007611ad1565b906124e4565b614d6c612710613aab565b90612556565b90614d86614d808592610401565b91610401565b11908115614e18575b50614dfc57614d9f426009611a05565b614db48282614dae60066108a6565b91615295565b614dbe60066108a6565b919091614df77f57a22e4f573fdde147e5da0d963e82b64839e457916475bb99cc5884b9b338cf93614dee610304565b93849384614caa565b0390a1565b5f6313b2e2c560e11b815280614e1460048201610700565b0390fd5b9050614e2d614e278392610401565b91610401565b115f614d8f565b5f6309766eeb60e41b815280614e4c60048201610700565b0390fd5b614e6190614e5c615024565b614e63565b565b8060601b15614e7757614e7590615acd565b565b637448fbae5f526004601cfd5b614e8d90614e50565b565b90614eb291614e9c611738565b50614ea5614573565b92909291929091926164b8565b90565b614ebd611738565b5063389a75e1600c525f526020600c205490565b9493909192614ef9614f0394614ee5611738565b50614eee611738565b50879085859261652d565b959290919261652d565b90565b614f0e611863565b50600190565b92909391614f20611738565b50614f29611738565b50614f32611738565b50614f3b6118f2565b90614f4a858388905f926165c4565b90614f62614f5c828587905f926165c4565b8361665a565b83614f75614f6f5f6119b4565b91610401565b146150165780614f8d614f8785610401565b91610401565b145f14614fd3575050614fcb9291614fbb614fb0614fc59383869060019261652d565b978790835f926165c4565b9287915f926165c4565b9061665a565b919291929190565b61500e9493919796506150089250614ff3614ffe9183899060019261652d565b968790835f926165c4565b9287915f926165c4565b9061665a565b919291929190565b935095505050919291929190565b638b78c6d81954330361503357565b6382b429005f526004601cfd5b91909161504b611863565b50615054614f06565b5f146151275760601b916e22d473030f116ddee9f6b43ac78ba333036150e4575b6387a211a28317600c526020600c2080548084116150d75783900390555f526020600c20818154019055602052600c5160601c9060601c7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a35b600190565b63f4d678b85f526004601cfd5b33602052637f5e9f208317600c526034600c2080548019615107575b5050615075565b80841161511a5783900390555f80615100565b6313be252b5f526004601cfd5b60601b9133602052637f5e9f208317600c526034600c20805480196151b7575b50506387a211a28317600c526020600c2080548084116151aa5783900390555f526020600c20818154019055602052600c5160601c9060601c7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a36150d2565b63f4d678b85f526004601cfd5b8084116151ca5783900390555f80615147565b6313be252b5f526004601cfd5b5f90565b90565b6151f26151ed6151f7926151db565b61036e565b611b89565b90565b6152026151d7565b5061520f6202a3006151de565b90565b61521a611863565b50600190565b6387a211a2600c52805f526020600c209182549283821161528857815f94039055806805345cdf77eb68f44c54036805345cdf77eb68f44c55825260601b60601c7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602083a3565b63f4d678b85f526004601cfd5b90916152de926152d66152ab60016002016108a6565b6152b7600280016108a6565b946152c3818390615492565b6152ce848790615492565b9084916155ea565b9190916155ea565b565b6152e8611fed565b90565b90565b6153026152fd615307926152eb565b611971565b610c5d565b90565b6153337fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc66152ee565b90565b61533e611fed565b5061534761530a565b90565b6153526166a3565b61535857565b6166f3565b50615366615024565b565b6153796153736166a3565b156105d1565b61537f57565b6166f3565b9061538d611738565b50816153a96153a361539e5f611965565b610321565b91610321565b14615440575060206153c56153c06153f793613b1a565b613b26565b6370a08231906153ec6153d730614012565b926153e0610304565b9586948593849361257c565b835260048301610cec565b03915afa90811561543b575f9161540d575b5090565b61542e915060203d8111615434575b615426818361178c565b810190612591565b5f615409565b503d61541c565b6125fa565b61545e915061544e30614012565b31905f1461546157345b90612633565b90565b61546a5f6119b4565b615458565b91602061549092949361548960408201965f830190610404565b01906109e6565b565b6154a461549f600a613b46565b611666565b9162f714ce919092803b1561551e576154d05f80946154db6154c4610304565b9788968795869461257c565b84526004840161546f565b03925af18015615519576154ed575b50565b61550c905f3d8111615512575b615504818361178c565b810190612f24565b5f6154ea565b503d6154fa565b6125fa565b612578565b919060145260345263095ea7b360601b5f5260205f6044601082855af1908160015f51141615615556575b50505f603452565b3d903b15171015615568575f8061554e565b633e3f8f735f526004601cfd5b5f90565b61558d61558861559292610401565b61036e565b6109f3565b90565b1561559c57565b5f637119f00960e11b8152806155b460048201610700565b0390fd5b906155c1615575565b506155e86155ce83615579565b926155e26155dc8592610401565b91612617565b14615595565b565b919091826156086156026155fd5f611965565b610321565b91610321565b1461561b576156199291909161671e565b565b906156269250616700565b565b5f7f5661756c743a206e6f74206f70657261746f7200000000000000000000000000910152565b61565c6013602092610508565b61566581615628565b0190565b61567e9060208101905f81830391015261564f565b90565b1561568857565b615690610304565b62461bcd60e51b8152806156a660048201615669565b0390fd5b6156cf336156c96156c36156be60056108a6565b610321565b91610321565b14615681565b565b905051906156de8261032d565b565b905051906156ed826132b0565b565b905051906156fc8261321e565b565b91906101008382031261577a57615717815f85016156d1565b9261572582602083016156e0565b9261573383604084016131ee565b9261574181606085016131ee565b9261574f82608083016131ee565b926157776157608460a085016156ef565b9361576e8160c086016156ef565b9360e001613b53565b90565b61030e565b9190615792905f60208501940190610a1b565b565b91906040838203126157bc57806157b06157b9925f86016131ee565b936020016131ee565b90565b61030e565b6157ca906124c8565b9052565b91906157e1905f602085019401906157c1565b565b906157ec611738565b506157f5611863565b5061583a61010061581061580b5f6002016107f6565b6109a4565b631c0d9c229061582f8692615823610304565b9586948593849361257c565b83526004830161577f565b03915afa908115615ac8575f8080808080808097959650509692505050615a90575b50919093845f146159f3576158aa604061588061587b5f6002016107f6565b6109a4565b63e6d29b519061589f8692615893610304565b9586948593849361257c565b8352600483016157ce565b03915afa80156159ee576158d6916158d0915f809290916159bd575b5090505b92610a11565b91610a11565b116159ae576158e3611738565b50835f146159645761592b61591061595f9361590a615904615945956124c8565b91612617565b906124e4565b61592561592060016002016108d8565b612617565b90612556565b61593f61593a5f60020161087a565b612526565b906124e4565b6159596159545f600201610826565b6124c8565b90612556565b5b9190565b5061598e6159746159a992612617565b6159886159835f600201610853565b612526565b906124e4565b6159a361599e60016002016108d8565b612617565b90612556565b615960565b50506159b95f6119b4565b9190565b90506159e0915060403d81116159e7575b6159d8818361178c565b810190615794565b905f6158c6565b503d6159ce565b6125fa565b615a366040615a0c615a075f6002016107f6565b6109a4565b630e2e2ffe90615a2b8692615a1f610304565b9586948593849361257c565b8352600483016157ce565b03915afa8015615a8b576158d6916158d0915f80929091615a5a575b5090506158ca565b9050615a7d915060403d8111615a84575b615a75818361178c565b810190615794565b905f615a52565b503d615a6b565b6125fa565b915050615ab591506101003d8111615ac1575b615aad818361178c565b8101906156fe565b9594505094505061585c565b503d615aa3565b6125fa565b615ad5616770565b5f14615b1a57638b78c6d8199060601b60601c8082547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3801560ff1b1790555b565b638b78c6d8199060601b60601c908181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a355615b18565b90565b615b6c615b67615b7192615b55565b611971565b610c5d565b90565b615b8263409feecd19615b58565b90565b615b8d611fed565b50615b96615b74565b90565b615ba1616770565b5f14615bf957638b78c6d819908154615bec5760601b60601c90811560ff1b821790555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a35b565b630dc149f05f526004601cfd5b60601b60601c80638b78c6d819555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a3615bea565b615c3a90610371565b90565b615c4690615c31565b90565b615c5290615c31565b90565b90565b90615c6d615c68615c7492615c49565b615c55565b8254611976565b9055565b919061016083820312615d2157615c91815f85016156ef565b92615c9f82602083016156e0565b92615cad83604084016156d1565b92615cbb8160608501612582565b92615cc982608083016156d1565b92615cd78360a08401612582565b92615ce58160c085016156ef565b92615cf38260e083016156e0565b92615d1e615d058461010085016156e0565b93615d14816101208601612582565b9361014001612582565b90565b61030e565b90615d3863ffffffff60a01b91613135565b9181191691161790565b615d56615d51615d5b926109bd565b61036e565b6109bd565b90565b90565b90615d76615d71615d7d92615d42565b615d5e565b8254615d26565b9055565b90615d9b6bffffffffffffffffffffffff60a01b91613135565b9181191691161790565b615db9615db4615dbe926109f3565b61036e565b6109f3565b90565b90565b90615dd9615dd4615de092615da5565b615dc1565b8254615d81565b9055565b615df8615df3615dfd92610401565b61036e565b6109d3565b90565b60c01b90565b90615e1560ff60c01b91615e00565b9181191691161790565b615e33615e2e615e38926109d3565b61036e565b6109d3565b90565b90565b90615e53615e4e615e5a92615e1f565b615e3b565b8254615e06565b9055565b90615e6d60ff60c81b91613197565b9181191691161790565b90615e8c615e87615e9392615e1f565b615e3b565b8254615e5e565b9055565b615ea3615eac91615c3d565b5f600201615c58565b615edc610160615ec6615ec15f6002016107f6565b6109a4565b6390c9427c90615ed4610304565b93849261257c565b82528180615eec60048201610700565b03915afa8015615fc757615f7191615f68915f808080808094909395929192615f73575b615f63959650615f5192615f42615f5a9593615f38615f4c949a919395989a5f600201615d61565b6001600201615dc4565b6001600201611994565b615de4565b5f600201615e3e565b60028001611994565b615de4565b5f600201615e77565b565b505050505050615f63615f4c615f5a615f51615f38615fac615f42966101603d8111615fc0575b615fa4818361178c565b810190615c78565b505050505098509650945092509550615f10565b503d615f9a565b6125fa565b916040519360605260405260601b602c526323b872dd60601b600c5260205f6064601c82855af1908160015f5114161561600c575b50505f606052604052565b3d903b1517101561601e575f80616001565b637939f4245f526004601cfd5b6805345cdf77eb68f44c54828101908110616091576805345cdf77eb68f44c556387a211a2600c525f526020600c20818154019055602052600c5160601c5f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a3565b63e5cfe9575f526004601cfd5b6040906160c76160ce94969593966160bd60608401985f8501906109e6565b60208301906109e6565b0190610404565b565b90806160ec6160e66160e15f611965565b610321565b91610321565b1461618e576161036160fe600a613b46565b611666565b90638340f5499161611330614012565b919392813b15616189575f61613b91616146829661612f610304565b9889978896879561257c565b85526004850161609e565b03925af1801561618457616158575b50565b616177905f3d811161617d575b61616f818361178c565b810190612f24565b5f616155565b503d616165565b6125fa565b612578565b6161a061619b600a613b46565b611666565b90638340f549839290926161b330614012565b929490823b15616228575f946161e56161da936161ce610304565b9889978896879561257c565b85526004850161609e565b03925af18015616223576161f7575b50565b616216905f3d811161621c575b61620e818361178c565b810190612f24565b5f6161f4565b503d616204565b6125fa565b612578565b616235611863565b506387a211a2600c52335f526020600c2080548084116162955783900390555f526020600c20818154019055602052600c5160601c337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a3600190565b63f4d678b85f526004601cfd5b906162ce916162af611738565b506162b8614573565b929092916162c4611738565b5092909192614f14565b6162ea836162e46162de5f6119b4565b91610401565b1161405c565b6162f533849061602b565b61630a42616305600133906103a5565b611a05565b616312611738565b61631f60016002016108a6565b61633961633361632e5f611965565b610321565b91610321565b145f146163cd575061634c348390612633565b5b61635883839061677e565b8061636b6163655f6119b4565b91610401565b116163b3575b50339190916163ad847ff7ed121cfb40d57714b8349a1791bb3d55e16464fe62844d8ab562e668052727946163a4610304565b94859485611da2565b0390a190565b6163c7906163c05f611965565b33916155ea565b5f616371565b6163d9600280016108a6565b6163f36163ed6163e85f611965565b610321565b91610321565b146163fe575b61634d565b5061640a348290612633565b6163f9565b5f7f5661756c743a206e6f7420676173206372616e6b000000000000000000000000910152565b6164436014602092610508565b61644c8161640f565b0190565b6164659060208101905f818303910152616436565b90565b1561646f57565b616477610304565b62461bcd60e51b81528061648d60048201616450565b0390fd5b6164b6336164b06164aa6164a560066108a6565b610321565b91610321565b14616468565b565b6164ef936164df6164e9936164cb611738565b506164d46118f2565b9390846001926165c4565b93916001926165c4565b9061665a565b90565b6164fb90610401565b5f1981146165095760010190565b611ade565b90565b61652561652061652a9261650e565b61036e565b610401565b90565b909161654761655b91959495616541611738565b506164f2565b926165556305f5e100616511565b90611af2565b9161657161656a8383906124e4565b8490612556565b949283616593575b505050616583575b565b9061658d906164f2565b90616581565b6165bb9293506165b5916165aa6165af92886124e4565b612556565b92610401565b91610401565b105f8080616579565b90916165de6165f2919594956165d8611738565b506164f2565b926165ec6305f5e100616511565b90611af2565b6166076166008383906124e4565b8490612556565b949283616629575b505050616619575b565b90616623906164f2565b90616617565b61665192935061664b9161664061664592886124e4565b612556565b92610401565b91610401565b105f808061660f565b90616663611738565b50818110908218021890565b6166789061038d565b90565b61668490610371565b90565b61669b6166966166a092610316565b61036e565b610401565b90565b6166ab611863565b507f00000000000000000000000000000000000000000000000000000000000000006166ef6166e96166e46166df3061666f565b61667b565b616687565b91610401565b1490565b639f03a0265f526004601cfd5b905f8092389238915af11561671157565b63b12d13eb5f526004601cfd5b919060145260345263a9059cbb60601b5f5260205f6044601082855af1908160015f51141615616751575b50505f603452565b3d903b15171015616763575f80616749565b6390b8ec185f526004601cfd5b616778611863565b50600190565b6167eb916167e661679260016002016108a6565b61679e600280016108a6565b93816167ba6167b46167af5f611965565b610321565b91610321565b036167fd575b846167db6167d56167d05f611965565b610321565b91610321565b036167ed575b6160d0565b6160d0565b565b6167f885859061680d565b6167e1565b61680882829061680d565b6167c0565b9061682491903361681d30614012565b9192615fcc565b56fea26469706673582212208d8a627d1229f31534f17ea2c31c04dd0ef1a8aa715a9797410bd764d226f69664736f6c634300081e0033
Deployed Bytecode
0x60c06040526004361015610015575b3661173457005b61001f5f356102fe565b806302527753146102f95780630516c55b146102f457806306fdde03146102ef578063095ea7b3146102ea57806318160ddd146102e55780631c26e621146102e057806321729db3146102db57806323b872dd146102d657806325692962146102d1578063277838df146102cc5780632e1a7d4d146102c75780633098f459146102c2578063313ce567146102bd578063322f1b35146102b8578063343054cd146102b3578063362a1f57146102ae5780633644e515146102a957806349476574146102a45780634e7e156e1461029f5780634f1ef2861461029a57806352d1902d1461029557806354d1f13d1461029057806354f9137a1461028b578063570ca735146102865780636463ffd114610281578063699f706e1461027c57806370a0823114610277578063715018a6146102725780637403c6cd1461026d5780637ecebe00146102685780638340582b146102635780638a69f5f21461025e5780638da5cb5b14610259578063905221a41461025457806395d89b411461024f578063a9059cbb1461024a578063d505accf14610245578063dd62ed3e14610240578063e04d89da1461023b578063e2bbb15814610236578063f04e283e14610231578063f0c175a31461022c578063f2fde38b14610227578063f742269d14610222578063fae5df6a1461021d5763fee81cf40361000e576116ff565b6116c9565b611694565b6115fd565b6115c9565b6115a0565b611574565b61153e565b611508565b6114a1565b6113b5565b611380565b61134b565b611307565b6112d1565b6112a2565b611227565b6111ea565b611140565b61110b565b6110d5565b611098565b610f36565b610ef0565b610e6a565b610e35565b610e0b565b610d45565b610d01565b610c82565b610c28565b610be4565b610ba3565b610b6e565b610b23565b610aed565b610aae565b6107a9565b610773565b610705565b610690565b61062e565b6105f8565b61056f565b6104bf565b610426565b60e01c90565b60405190565b5f80fd5b5f80fd5b5f80fd5b60018060a01b031690565b61032a90610316565b90565b61033681610321565b0361033d57565b5f80fd5b9050359061034e8261032d565b565b9060208282031261036957610366915f01610341565b90565b61030e565b90565b61038561038061038a92610316565b61036e565b610316565b90565b61039690610371565b90565b6103a29061038d565b90565b906103af90610399565b5f5260205260405f2090565b1c90565b90565b6103d29060086103d793026103bb565b6103bf565b90565b906103e591546103c2565b90565b6103fe906103f96001915f926103a5565b6103da565b90565b90565b61040d90610401565b9052565b9190610424905f60208501940190610404565b565b346104565761045261044161043c366004610350565b6103e8565b610449610304565b91829182610411565b0390f35b61030a565b61046481610401565b0361046b57565b5f80fd5b9050359061047c8261045b565b565b9060208282031261049757610494915f0161046f565b90565b61030e565b9160206104bd9294936104b660408201965f830190610404565b0190610404565b565b346104f0576104d76104d236600461047e565b61173c565b906104ec6104e3610304565b9283928361049c565b0390f35b61030a565b5f9103126104ff57565b61030e565b5190565b60209181520190565b90825f9392825e0152565b601f801991011690565b61054561054e6020936105539361053c81610504565b93848093610508565b95869101610511565b61051c565b0190565b61056c9160208201915f818403910152610526565b90565b3461059f5761057f3660046104f5565b61059b61058a61184f565b610592610304565b91829182610557565b0390f35b61030a565b91906040838203126105cc57806105c06105c9925f8601610341565b9360200161046f565b90565b61030e565b151590565b6105df906105d1565b9052565b91906105f6905f602085019401906105d6565b565b346106295761062561061461060e3660046105a4565b90611867565b61061c610304565b918291826105e3565b0390f35b61030a565b3461065e5761063e3660046104f5565b61065a6106496118f2565b610651610304565b91829182610411565b0390f35b61030a565b919060408382031261068b578061067f610688925f860161046f565b9360200161046f565b90565b61030e565b346106c1576106bd6106ac6106a6366004610663565b90611909565b6106b4610304565b91829182610411565b0390f35b61030a565b90916060828403126106fb576106f86106e1845f8501610341565b936106ef816020860161046f565b9360400161046f565b90565b61030e565b5f0190565b346107345761071e6107183660046106c6565b91611ab0565b610726610304565b8061073081610700565b0390f35b61030a565b909160608284031261076e5761076b610754845f8501610341565b936107628160208601610341565b9360400161046f565b90565b61030e565b346107a4576107a061078f610789366004610739565b91611b17565b610797610304565b918291826105e3565b0390f35b61030a565b6107b43660046104f5565b6107bc611bc0565b6107c4610304565b806107ce81610700565b0390f35b5f1c90565b60018060a01b031690565b6107ee6107f3916107d2565b6107d7565b90565b61080090546107e2565b90565b60a01c90565b63ffffffff1690565b61081e61082391610803565b610809565b90565b6108309054610812565b90565b60c01c90565b60ff1690565b61084b61085091610833565b610839565b90565b61085d905461083f565b90565b60c81c90565b61087261087791610860565b610839565b90565b6108849054610866565b90565b60018060a01b031690565b61089e6108a3916107d2565b610887565b90565b6108b09054610892565b90565b6bffffffffffffffffffffffff1690565b6108d06108d591610803565b6108b3565b90565b6108e290546108c4565b90565b64ffffffffff1690565b6108fb61090091610803565b6108e5565b90565b61090d90546108ef565b90565b61091c61092191610860565b6108e5565b90565b61092e9054610910565b90565b600261093e5f82016107f6565b9161094a5f8301610826565b916109565f8201610853565b916109625f830161087a565b9161096f600182016108a6565b9161097c600183016108d8565b91610989600282016108a6565b916109a1600261099a818501610903565b9301610924565b90565b6109ad9061038d565b90565b6109b9906109a4565b9052565b63ffffffff1690565b6109cf906109bd565b9052565b60ff1690565b6109e2906109d3565b9052565b6109ef90610321565b9052565b6bffffffffffffffffffffffff1690565b610a0d906109f3565b9052565b64ffffffffff1690565b610a2490610a11565b9052565b9694929099989795939161012088019a5f8901610a44916109b0565b60208801610a51916109c6565b60408701610a5e916109d9565b60608601610a6b916109d9565b60808501610a78916109e6565b60a08401610a8591610a04565b60c08301610a92916109e6565b60e08201610a9f91610a1b565b61010001610aac91610a1b565b565b34610ae857610abe3660046104f5565b610ae4610ac9610931565b95610adb999799959195949294610304565b998a998a610a28565b0390f35b61030a565b34610b1e57610b05610b0036600461047e565b611f36565b90610b1a610b11610304565b9283928361049c565b0390f35b61030a565b34610b5457610b3b610b3636600461047e565b611f54565b90610b50610b47610304565b9283928361049c565b0390f35b61030a565b9190610b6c905f602085019401906109d9565b565b34610b9e57610b7e3660046104f5565b610b9a610b89611fad565b610b91610304565b91829182610b59565b0390f35b61030a565b34610bd157610bbb610bb636600461047e565b611fe2565b610bc3610304565b80610bcd81610700565b0390f35b61030a565b610be15f5f906103da565b90565b34610c1457610bf43660046104f5565b610c10610bff610bd6565b610c07610304565b91829182610411565b0390f35b61030a565b610c2560095f906103da565b90565b34610c5857610c383660046104f5565b610c54610c43610c19565b610c4b610304565b91829182610411565b0390f35b61030a565b90565b610c6990610c5d565b9052565b9190610c80905f60208501940190610c60565b565b34610cb257610c923660046104f5565b610cae610c9d61201a565b610ca5610304565b91829182610c6d565b0390f35b61030a565b610cc7906008610ccc93026103bb565b610887565b90565b90610cda9154610cb7565b90565b610ce960065f90610ccf565b90565b9190610cff905f602085019401906109e6565b565b34610d3157610d113660046104f5565b610d2d610d1c610cdd565b610d24610304565b91829182610cec565b0390f35b61030a565b610d4260085f906103da565b90565b34610d7557610d553660046104f5565b610d71610d60610d36565b610d68610304565b91829182610411565b0390f35b61030a565b5f80fd5b5f80fd5b5f80fd5b909182601f83011215610dc05781359167ffffffffffffffff8311610dbb576020019260018302840111610db657565b610d82565b610d7e565b610d7a565b919091604081840312610e0657610dde835f8301610341565b92602082013567ffffffffffffffff8111610e0157610dfd9201610d86565b9091565b610312565b61030e565b610e1f610e19366004610dc5565b9161218d565b610e27610304565b80610e3181610700565b0390f35b34610e6557610e453660046104f5565b610e61610e50612205565b610e58610304565b91829182610c6d565b0390f35b61030a565b610e753660046104f5565b610e7d612218565b610e85610304565b80610e8f81610700565b0390f35b610e9c816105d1565b03610ea357565b5f80fd5b90503590610eb482610e93565b565b9091606082840312610eeb57610ee8610ed1845f850161046f565b93610edf8160208601610ea7565b9360400161046f565b90565b61030e565b34610f2257610f09610f03366004610eb6565b91612cd4565b90610f1e610f15610304565b9283928361049c565b0390f35b61030a565b610f3360055f90610ccf565b90565b34610f6657610f463660046104f5565b610f62610f51610f27565b610f59610304565b91829182610cec565b0390f35b61030a565b909182601f83011215610fa55781359167ffffffffffffffff8311610fa0576020019260208302840111610f9b57565b610d82565b610d7e565b610d7a565b909182601f83011215610fe45781359167ffffffffffffffff8311610fdf576020019260208302840111610fda57565b610d82565b610d7e565b610d7a565b9091608082840312611093575f82013567ffffffffffffffff811161108e5783611014918401610f6b565b929093602082013567ffffffffffffffff81116110895781611037918401610f6b565b929093604082013567ffffffffffffffff8111611084578361105a918401610faa565b929093606082013567ffffffffffffffff811161107f5761107b9201610faa565b9091565b610312565b610312565b610312565b610312565b61030e565b346110d0576110ba6110ab366004610fe9565b969590959491949392936133b5565b6110c2610304565b806110cc81610700565b0390f35b61030a565b34611106576110e53660046104f5565b6110ed6138d8565b906111026110f9610304565b9283928361049c565b0390f35b61030a565b3461113b57611137611126611121366004610350565b613997565b61112e610304565b91829182610411565b0390f35b61030a565b61114b3660046104f5565b6111536139d8565b61115b610304565b8061116581610700565b0390f35b9190610100838203126111e557611182815f8501610341565b926111908260208301610341565b9261119e8360408401610341565b926111ac8160608501610341565b926111ba8260808301610341565b926111e26111cb8460a0850161046f565b936111d98160c0860161046f565b9360e00161046f565b90565b61030e565b346112225761120c6111fd366004611169565b96959095949194939293613ec9565b611214610304565b8061121e81610700565b0390f35b61030a565b346112575761125361124261123d366004610350565b613edb565b61124a610304565b91829182610411565b0390f35b61030a565b60808183031261129d57611272825f830161046f565b9261129a611283846020850161046f565b93611291816040860161046f565b93606001610ea7565b90565b61030e565b6112cd6112bc6112b336600461125c565b9291909161455c565b6112c4610304565b91829182610411565b0390f35b34611302576112e13660046104f5565b6112e9614573565b906112fe6112f5610304565b9283928361049c565b0390f35b61030a565b34611337576113173660046104f5565b6113336113226145b1565b61132a610304565b91829182610cec565b0390f35b61030a565b61134860075f906103da565b90565b3461137b5761135b3660046104f5565b61137761136661133c565b61136e610304565b91829182610411565b0390f35b61030a565b346113b0576113903660046104f5565b6113ac61139b61460f565b6113a3610304565b91829182610557565b0390f35b61030a565b346113e6576113e26113d16113cb3660046105a4565b90614623565b6113d9610304565b918291826105e3565b0390f35b61030a565b6113f4816109d3565b036113fb57565b5f80fd5b9050359061140c826113eb565b565b61141781610c5d565b0361141e57565b5f80fd5b9050359061142f8261140e565b565b60e08183031261149c57611447825f8301610341565b926114558360208401610341565b92611463816040850161046f565b92611471826060830161046f565b9261149961148284608085016113ff565b936114908160a08601611422565b9360c001611422565b90565b61030e565b346114d6576114c06114b4366004611431565b95949094939193614692565b6114c8610304565b806114d281610700565b0390f35b61030a565b919060408382031261150357806114f7611500925f8601610341565b93602001610341565b90565b61030e565b346115395761153561152461151e3660046114db565b90614881565b61152c610304565b91829182610411565b0390f35b61030a565b3461156f5761154e3660046104f5565b6115566148f7565b9061156b611562610304565b9283928361049c565b0390f35b61030a565b61159c61158b611585366004610663565b90614c44565b611593610304565b91829182610411565b0390f35b6115b36115ae366004610350565b614c9f565b6115bb610304565b806115c581610700565b0390f35b346115f8576115e26115dc366004610663565b90614cdc565b6115ea610304565b806115f481610700565b0390f35b61030a565b61161061160b366004610350565b614e84565b611618610304565b8061162281610700565b0390f35b60018060a01b031690565b61164190600861164693026103bb565b611626565b90565b906116549154611631565b90565b611663600a5f90611649565b90565b61166f9061038d565b90565b61167b90611666565b9052565b9190611692905f60208501940190611672565b565b346116c4576116a43660046104f5565b6116c06116af611657565b6116b7610304565b9182918261167f565b0390f35b61030a565b346116fa576116f66116e56116df366004610663565b90614e8f565b6116ed610304565b91829182610411565b0390f35b61030a565b3461172f5761172b61171a611715366004610350565b614eb5565b611722610304565b91829182610411565b0390f35b61030a565b5f80fd5b5f90565b61176d90611748611738565b50611751611738565b5061175a614573565b6117626118f2565b919091600193614ed1565b91909190565b606090565b634e487b7160e01b5f52604160045260245ffd5b906117969061051c565b810190811067ffffffffffffffff8211176117b057604052565b611778565b906117c86117c1610304565b928361178c565b565b67ffffffffffffffff81116117e8576117e460209161051c565b0190565b611778565b906117ff6117fa836117ca565b6117b5565b918252565b5f7f4b757275205661756c7400000000000000000000000000000000000000000000910152565b611835600a6117ed565b9061184260208301611804565b565b61184c61182b565b90565b611857611773565b50611860611844565b90565b5f90565b61186f611863565b50611878614f06565b6118c5575b602052637f5e9f20600c52335f52806034600c20555f52602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560205fa3600190565b8119156e22d473030f116ddee9f6b43ac78ba38260601b60601c181761187d57633f68539a5f526004601cfd5b6118fa611738565b506805345cdf77eb68f44c5490565b9061192c91611916611738565b5061191f614573565b9290929192909192614f14565b505090565b90611944929161193f615024565b611a25565b565b90565b61195d61195861196292611946565b61036e565b610316565b90565b61196e90611949565b90565b5f1b90565b9061198760018060a01b0391611971565b9181191691161790565b90565b906119a96119a46119b092610399565b611991565b8254611976565b9055565b6119c86119c36119cd92611946565b61036e565b610401565b90565b906119dc5f1991611971565b9181191691161790565b6119fa6119f56119ff92610401565b61036e565b610401565b90565b90565b90611a1a611a15611a21926119e6565b611a02565b82546119d0565b9055565b80611a40611a3a611a355f611965565b610321565b91610321565b03611a9f575b5080611a5a611a545f6119b4565b91610401565b03611a8e575b5080611a74611a6e5f6119b4565b91610401565b03611a7d575b50565b611a88906008611a05565b5f611a7a565b611a99906007611a05565b5f611a60565b611aaa906006611994565b5f611a46565b90611abb9291611931565b565b611ac9611ace916107d2565b6103bf565b90565b611adb9054611abd565b90565b634e487b7160e01b5f52601160045260245ffd5b611b01611b0791939293610401565b92610401565b8201809211611b1257565b611ade565b91611b20611863565b50611b47611b38611b33600186906103a5565b611ad1565b611b415f611ad1565b90611af2565b611b59611b5342610401565b91610401565b11611b6d57611b6a92919091615040565b90565b5f6303cb96db60e21b815280611b8560048201610700565b0390fd5b67ffffffffffffffff1690565b611baa611ba5611baf92611b89565b61036e565b610401565b90565b90611bbd9101610401565b90565b611bda42611bd4611bcf6151fa565b611b96565b90611bb2565b63389a75e1600c52335f526020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d5f80a2565b90565b611c29611c24611c2e92611c12565b61036e565b610401565b90565b611c43688000000000ab143c06611c15565b90565b90565b611c5d611c58611c6292611c46565b61036e565b610401565b90565b929190611c70615212565b5f14611d2857611c7e611c31565b9346611c93611c8d6001611c49565b91610401565b145f14611d0a57845c611d0157611caf939430905d5b5b611de0565b9091611cb9615212565b5f14611cf057611cc7611c31565b46611cdb611cd56001611c49565b91610401565b145f14611ce9575f905d5b5b565b8055611ce6565b5f688000000000ab143c065d611ce7565b845f526004601cfd5b30855414611d1f57611caf9394309055611ca9565b845f526004601cfd5b688000000000ab143c069392935c611d4f57611caf9230688000000000ab143c065d611caa565b63ab143c065f526004601cfd5b15611d6357565b5f630638288b60e31b815280611d7b60048201610700565b0390fd5b15611d8657565b5f6303cb96db60e21b815280611d9e60048201610700565b0390fd5b611dd7611dde94611dcd606094989795611dc3608086019a5f8701906109e6565b6020850190610404565b6040830190610404565b0190610404565b565b9291925050611e0182611dfb611df55f6119b4565b91610401565b11611d5c565b611e42611e2a611e1b611e16600133906103a5565b611ad1565b611e245f611ad1565b90611af2565b611e3c611e3642610401565b91610401565b10611d7f565b611e4a6148f7565b92909290611e80611e596138d8565b908391611e78611e71611e6a6118f2565b938a611af2565b9187611af2565b915f93614ed1565b92909294611e97611e918592610401565b91610401565b11908115611f1a575b50611efe57611eb0338290615220565b611ebc82853391615295565b338290611ef786937f0f026689e85a8d17644dcfde4a809a89d61d408ce737d1f1e9bdca05fbed20da94611eee610304565b94859485611da2565b0390a19190565b5f63503ae32b60e11b815280611f1660048201610700565b0390fd5b9050611f2f611f298692610401565b91610401565b115f611ea0565b611f5090611f42611738565b611f4a611738565b90611c65565b9091565b611f8490611f60611738565b50611f69611738565b50611f72614573565b611f7a6118f2565b9190915f93614ed1565b91909190565b5f90565b90565b611fa5611fa0611faa92611f8e565b61036e565b6109d3565b90565b611fb5611f8a565b50611fc06012611f91565b90565b611fd490611fcf615024565b611fd6565b565b611fe0905f611a05565b565b611feb90611fc3565b565b5f90565b61200561200061200a92611946565b611971565b610c5d565b90565b90565b60200190565b5190565b612022611fed565b5061202b6152e0565b8061204661204061203b5f611ff1565b610c5d565b91610c5d565b14612098575b60a090612057615336565b604051917f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8352602083015260408201524660608201523060808201522090565b5060a06120ab6120a661184f565b61200d565b6120bd6120b782612016565b91612010565b20905061204c565b906120d892916120d361534a565b6120da565b565b9190916120e68161535d565b60601b60601c3d5f526352d1902d6001527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80602060016004601d865afa510361217f57818391817fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b5f38a25561215d575b505050565b815f926040519485378338925af415612177578080612158565b3d5f823e3d90fd5b6355299b496001526004601dfd5b9061219892916120c5565b565b6121ab906121a6615368565b6121f9565b90565b90565b6121c56121c06121ca926121ae565b611971565b610c5d565b90565b6121f67f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc6121b1565b90565b506122026121cd565b90565b612215612210611fed565b61219a565b90565b63389a75e1600c52335f525f6020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c925f80a2565b949392919061225e615212565b5f146123165761226c611c31565b954661228161227b6001611c49565b91610401565b145f146122f857865c6122ef5761229d959630905d5b5b61267b565b90916122a7615212565b5f146122de576122b5611c31565b466122c96122c36001611c49565b91610401565b145f146122d7575f905d5b5b565b80556122d4565b5f688000000000ab143c065d6122d5565b865f526004601cfd5b3087541461230d5761229d9596309055612297565b865f526004601cfd5b688000000000ab143c069594955c61233d5761229d9430688000000000ab143c065d612298565b63ab143c065f526004601cfd5b61235390610321565b90565b906123609061234a565b9052565b9061236e906109bd565b9052565b9061237c906109d3565b9052565b9061238a90610321565b9052565b90612398906109f3565b9052565b906123a690610a11565b9052565b6123b56101206117b5565b90565b9061249361248960026123c96123aa565b946123e06123d85f83016107f6565b5f8801612356565b6123f76123ee5f8301610826565b60208801612364565b61240e6124055f8301610853565b60408801612372565b61242561241c5f830161087a565b60608801612372565b61243d612434600183016108a6565b60808801612380565b61245561244c600183016108d8565b60a0880161238e565b61246c6124638383016108a6565b60c08801612380565b61248361247a838301610903565b60e0880161239c565b01610924565b610100840161239c565b565b61249e906123b8565b90565b6124ab9051610321565b90565b6124b8905161234a565b90565b6124c590516109bd565b90565b6124dc6124d76124e1926109bd565b61036e565b610401565b90565b6124f36124f991939293610401565b92610401565b91612505838202610401565b92818404149015171561251457565b611ade565b61252390516109d3565b90565b61252f906109d3565b604d811161253d57600a0a90565b611ade565b634e487b7160e01b5f52601260045260245ffd5b61256261256891610401565b91610401565b908115612573570490565b612542565b5f80fd5b60e01b90565b9050519061258f8261045b565b565b906020828203126125aa576125a7915f01612582565b90565b61030e565b6125b8906119b4565b9052565b6125f16125f8946125e76060949897956125dd608086019a5f870190610a04565b60208501906125af565b60408301906105d6565b01906105d6565b565b612602610304565b3d5f823e3d90fd5b61261490516109f3565b90565b61262b612626612630926109f3565b61036e565b610401565b90565b61264261264891939293610401565b92610401565b820391821161265357565b611ade565b1561265f57565b5f63178dff1560e31b81528061267760048201610700565b0390fd5b949394505061269c816126966126905f6119b4565b91610401565b11611d5c565b6126dd6126c56126b66126b1600133906103a5565b611ad1565b6126bf5f611ad1565b90611af2565b6126d76126d142610401565b91610401565b10611d7f565b6126e76002612495565b936126ff6126f7608087016124a1565b600190615384565b9461271761270f60c083016124a1565b600190615384565b61271f6148f7565b979097956127578961272f6138d8565b91909161274f6127488b946127426118f2565b94611af2565b918c611af2565b915f93614ed1565b9790979961276e6127688a92610401565b91610401565b11908115612cb8575b50612c9c57612787338790615220565b61279d87612797608087016124a1565b90615492565b6127b3896127ad60c087016124a1565b90615492565b6127bb611738565b815f14612c25576127ce608086016124a1565b6127e86127e26127dd5f611965565b610321565b91610321565b145f14612bf75750865b5b815f14612b165760208861281061280b5f89016124ae565b6109a4565b9261287f61286161285c8a612856612851604061284a63532c46db989b989b9961284461283f60a0880161260a565b612617565b906124e4565b9301612519565b612526565b90612556565b6155b8565b925f9561288a5f600190612873610304565b998a988997889661257c565b8652600486016125bc565b03925af18015612b11576129349361291d9261290192612ae5575b505b8380612ab7575b5f14612a39576128e56128c3608089016124a1565b6128d66128d15f8b016124ae565b6109a4565b6128df5f6119b4565b91615523565b5b6128fc6128f5608089016124a1565b5f90615384565b612633565b9361291861291160c088016124a1565b5f90615384565b612633565b948180612a1e575b9182156129e6575b5050612658565b806129476129415f6119b4565b91610401565b116129c9575b508161296161295b5f6119b4565b91610401565b116129ab575b50503382906129a486937f0f026689e85a8d17644dcfde4a809a89d61d408ce737d1f1e9bdca05fbed20da9461299b610304565b94859485611da2565b0390a19190565b6129bb60c06129c29392016124a1565b33916155ea565b5f80612967565b6129e0906129d9608084016124a1565b33916155ea565b5f61294d565b6129f2919250156105d1565b9081612a01575b505f8061292d565b9050612a16612a108492610401565b91610401565b10155f6129f9565b5085612a32612a2c83610401565b91610401565b1015612925565b612a4384156105d1565b80612a89575b612a53575b6128e6565b612a84612a6260c089016124a1565b612a75612a705f8b016124ae565b6109a4565b612a7e5f6119b4565b91615523565b612a4e565b50612a9660c088016124a1565b612ab0612aaa612aa55f611965565b610321565b91610321565b1415612a49565b50612ac4608088016124a1565b612ade612ad8612ad35f611965565b610321565b91610321565b14156128ae565b612b059060203d8111612b0a575b612afd818361178c565b810190612591565b6128a5565b503d612af3565b6125fa565b60208a612b2c612b275f89016124ae565b6109a4565b92612b9a612b7c612b778a612b71612b6c6060612b65637c51d6cf989b989b99612b5f612b5a8d88016124bb565b6124c8565b906124e4565b9301612519565b612526565b90612556565b6155b8565b925f95612ba55f600190612b8e610304565b998a988997889661257c565b8652600486016125bc565b03925af18015612bf2576129349361291d9261290192612bc6575b506128a7565b612be69060203d8111612beb575b612bde818361178c565b810190612591565b612bc0565b503d612bd4565b6125fa565b612c20612c06608087016124a1565b612c19612c145f89016124ae565b6109a4565b8a91615523565b6127f2565b612c2f82156105d1565b612c39575b6127f3565b612c4560c086016124a1565b612c5f612c59612c545f611965565b610321565b91610321565b145f14612c6e5750885b612c34565b612c97612c7d60c087016124a1565b612c90612c8b5f89016124ae565b6109a4565b8c91615523565b612c69565b5f63503ae32b60e11b815280612cb460048201610700565b0390fd5b9050612ccd612cc78b92610401565b91610401565b115f612777565b90612cf09291612ce2611738565b612cea611738565b90612251565b9091565b5090565b5090565b612d069051610a11565b90565b612d1d612d18612d2292611946565b61036e565b610a11565b90565b612d31612d3791610a11565b91610a11565b90039064ffffffffff8211612d4857565b611ade565b612d61612d5c612d6692611c46565b61036e565b610a11565b90565b612d75612d7b91610a11565b91610a11565b019064ffffffffff8211612d8b57565b611ade565b612da4612d9f612da992610a11565b61036e565b610401565b90565b67ffffffffffffffff8111612dc45760208091020190565b611778565b90612ddb612dd683612dac565b6117b5565b918252565b369037565b90612e0a612df283612dc9565b92602080612e008693612dac565b9201910390612de0565b565b612e1590610a11565b64ffffffffff8114612e275760010190565b611ade565b634e487b7160e01b5f52603260045260245ffd5b5190565b90612e4e82612e40565b811015612e5f576020809102010190565b612e2c565b67ffffffffffffffff8111612e7c5760208091020190565b611778565b90612e93612e8e83612e64565b6117b5565b918252565b369037565b90612ec2612eaa83612e81565b92602080612eb88693612e64565b9201910390612e98565b565b67ffffffffffffffff8111612edc5760208091020190565b611778565b90612ef3612eee83612ec4565b6117b5565b918252565b369037565b90612f22612f0a83612ee1565b92602080612f188693612ec4565b9201910390612ef8565b565b5f910312612f2e57565b61030e565b5190565b60209181520190565b60200190565b612f4f906109bd565b9052565b90612f6081602093612f46565b0190565b60200190565b90612f87612f81612f7a84612f33565b8093612f37565b92612f40565b905f5b818110612f975750505090565b909192612fb0612faa6001928651612f53565b94612f64565b9101919091612f8a565b5190565b60209181520190565b60200190565b612fd6906109f3565b9052565b90612fe781602093612fcd565b0190565b60200190565b9061300e61300861300184612fba565b8093612fbe565b92612fc7565b905f5b81811061301e5750505090565b9091926130376130316001928651612fda565b94612feb565b9101919091613011565b60209181520190565b60200190565b61305990610a11565b9052565b9061306a81602093613050565b0190565b60200190565b9061309161308b61308484612e40565b8093613041565b9261304a565b905f5b8181106130a15750505090565b9091926130ba6130b4600192865161305d565b9461306e565b9101919091613094565b96959361311d9061310f60a09561310161312b966130f28d6131339c9860c08201915f818403910152612f6a565b908d6020818403910152612ff1565b908b820360408d0152612f6a565b9089820360608b0152612ff1565b908782036080890152613074565b9401906105d6565b565b60a01b90565b9061314e64ffffffffff60a01b91613135565b9181191691161790565b61316c61316761317192610a11565b61036e565b610a11565b90565b90565b9061318c61318761319392613158565b613174565b825461313b565b9055565b60c81b90565b906131b064ffffffffff60c81b91613197565b9181191691161790565b906131cf6131ca6131d692613158565b613174565b825461319d565b9055565b6131e381610a11565b036131ea57565b5f80fd5b905051906131fb826131da565b565b9060208282031261321657613213915f016131ee565b90565b61030e565b90565b613227816109bd565b0361322e57565b5f80fd5b9050359061323f8261321e565b565b50613250906020810190613232565b90565b60200190565b916132678261326d92612f37565b9261321b565b90815f905b828210613280575050505090565b909192936132a261329c6001926132978886613241565b612f53565b95613253565b920190929192613272565b90565b6132b9816109f3565b036132c057565b5f80fd5b905035906132d1826132b0565b565b506132e29060208101906132c4565b90565b60200190565b916132f9826132ff92612fbe565b926132ad565b90815f905b828210613312575050505090565b9091929361333461332e60019261332988866132d3565b612fda565b956132e5565b920190929192613304565b9a999791946133ab966133808d61339d9760a09b976133726133b39f9b9761338f9860c08601918683035f880152613259565b9260208185039101526132eb565b918d6040818503910152613259565b918a830360608c01526132eb565b908782036080890152613074565b9401906105d6565b565b91969392966133c26156aa565b6133cd838390612cf4565b6133e96133e36133de878a90612cf8565b610401565b91610401565b141580156138a9575b61388d576134006002612495565b9761340d60e08a01612cfc565b61341f6134195f612d09565b91610a11565b036136d0575b613430848490612cf4565b61344261343c5f6119b4565b91610401565b1180156136ac575b5f146136745761347e60206134686134635f8d016124ae565b6109a4565b632bf1360e90613476610304565b93849261257c565b8252815f8161348f60048201610700565b03925af190811561366f575f91613641575b50976134b66134b15f8c016124ae565b6109a4565b96635339c59f9594969893929190916134d66134d15f6119b4565b612de5565b936001958a3b1561363c576134e9610304565b9b8c9a6134f68c9b61257c565b8b5260048b01996135069a61333f565b03815a5f948591f19081613610575b50155f14613559575050600161352a575b5b5b565b61353f6135365f612d09565b60028001613177565b61355461354b5f612d09565b600280016131ba565b613526565b602061357161356c5f61358795016124ae565b6109a4565b632bf1360e9061357f610304565b94859261257c565b8252815f8161359860048201610700565b03925af1801561360b576135c66135cf916135d8945f916135dd575b50926135c06001612d4d565b90612d69565b60028001613177565b600280016131ba565b613527565b6135fe915060203d8111613604575b6135f6818361178c565b8101906131fd565b5f6135b4565b503d6135ec565b6125fa565b61362f905f3d8111613635575b613627818361178c565b810190612f24565b5f613515565b503d61361d565b612578565b613662915060203d8111613668575b61365a818361178c565b8101906131fd565b5f6134a1565b503d613650565b6125fa565b5050505050505050506136926136895f612d09565b60028001613177565b6136a761369e5f612d09565b600280016131ba565b613528565b506136b8828290612cf4565b6136ca6136c45f6119b4565b91610401565b1161344a565b989695949392919061371e6137196137146137048c6136fe60e06136f76101008401612cfc565b9201612cfc565b90612d25565b61370e6001612d4d565b90612d69565b612d90565b612de5565b9961372b60e08b01612cfc565b60a0525b8961375161374b61374661010060a0519401612cfc565b610a11565b91610a11565b116137a15761378e8b6137898c61378361377e60a051949261377860e060a0519201612cfc565b90612d25565b612d90565b90612e44565b61239c565b61379960a051612e0c565b60a05261372f565b9091929394959697996137bd6137b85f8c016124ae565b6109a4565b90635339c59f916137d56137d05f6119b4565b612e9d565b906137e76137e25f6119b4565b612efd565b936137f96137f45f6119b4565b612e9d565b9361380b6138065f6119b4565b612efd565b9091600195843b15613888575f966138379488946138429361382b610304565b9b8c9a8b998a9861257c565b8852600488016130c4565b03925af1801561388357613857575b50613425565b613876905f3d811161387c575b61386e818361178c565b810190612f24565b5f613851565b503d613864565b6125fa565b612578565b5f63251f56a160e21b8152806138a560048201610700565b0390fd5b506138b5818990612cf4565b6138d16138cb6138c68a8990612cf8565b610401565b91610401565b14156133f2565b6138e0611738565b6138e8611738565b906138f560028001610903565b9161390260028001610924565b8361391561390f5f612d09565b91610a11565b1461397b5792905b8161393061392a86610a11565b91610a11565b116139755761393e826157e3565b5f1461395f57613959916139529190611af2565b915b612e0c565b9061391d565b61395991929361396f9190611af2565b92613954565b92505091565b505050505f9061399461398e5f936119b4565b926119b4565b90565b61399f611738565b506387a211a2600c525f526020600c205490565b6139bb615024565b6139c36139c5565b565b6139d66139d15f611965565b615acd565b565b6139e06139b3565b565b95939196949290966139f2615b85565b9687548060038a55613a4d575b50908798613a11979695949392613ba3565b613a19575b50565b6002905560016020527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602080a15f613a16565b9695949392919097600188811c14303b1015613a7857613a119760ff1b1b97909192939495966139ff565b63f92ee8a95f526004601cfd5b15613a8c57565b5f63b4fa3fb360e01b815280613aa460048201610700565b0390fd5b90565b613abf613aba613ac492613aa8565b61036e565b610401565b90565b613ad090610371565b90565b613adc90613ac7565b90565b613ae890613ac7565b90565b90565b90613b03613afe613b0a92613adf565b613aeb565b8254611976565b9055565b613b1790610371565b90565b613b2390613b0e565b90565b613b2f9061038d565b90565b613b3e613b43916107d2565b611626565b90565b613b509054613b32565b90565b90505190613b6082610e93565b565b90602082820312613b7b57613b78915f01613b53565b90565b61030e565b916020613ba1929493613b9a60408201965f8301906109e6565b0190610404565b565b613cd19291613cc3613cd69695613cbe613cca94613cfd9c9b613cdd9b60805260a052613beb85613be4613bde613bd95f611965565b610321565b91610321565b1415613a85565b613c1087613c09613c03613bfe5f611965565b610321565b91610321565b1415613a85565b613c3583613c2e613c28613c235f611965565b610321565b91610321565b1415613a85565b613c5a89613c53613c4d613c485f611965565b610321565b91610321565b1415613a85565b613c78608051613c72613c6c5f6119b4565b91610401565b11613a85565b60a051613c8d613c875f6119b4565b91610401565b1180613ea5575b613c9d90613a85565b613cb98c613cb3613cad5f6119b4565b91610401565b11613a85565b615b99565b615e97565b6005611994565b6006611994565b613ad3565b600a613aee565b613ce96080515f611a05565b613cf660a0516007611a05565b6008611a05565b613d0a60016002016108a6565b613d24613d1e613d195f611965565b610321565b91610321565b03613dfe575b613d36600280016108a6565b613d50613d4a613d455f611965565b610321565b91610321565b03613d58575b565b613d74613d6f613d6a600280016108a6565b613b1a565b613b26565b602063095ea7b391613d8e613d89600a613b46565b611666565b90613dad5f801995613db8613da1610304565b9788968795869461257c565b845260048401613b80565b03925af18015613df957613dcd575b50613d56565b613ded9060203d8111613df2575b613de5818361178c565b810190613b62565b613dc7565b503d613ddb565b6125fa565b613e1b613e16613e1160016002016108a6565b613b1a565b613b26565b602063095ea7b391613e35613e30600a613b46565b611666565b90613e545f801995613e5f613e48610304565b9788968795869461257c565b845260048401613b80565b03925af18015613ea057613e74575b50613d2a565b613e949060203d8111613e99575b613e8c818361178c565b810190613b62565b613e6e565b503d613e82565b6125fa565b50613c9d60a051613ec0613eba612710613aab565b91610401565b11159050613c94565b90613ed9979695949392916139e2565b565b613ee3611738565b506338377508600c525f526020600c205490565b9493929190613f04615212565b5f14613fbb57613f12611c31565b9546613f27613f216001611c49565b91610401565b145f14613f9d57865c613f9457613f43959630905d5b5b61407f565b90613f4c615212565b5f14613f8357613f5a611c31565b46613f6e613f686001611c49565b91610401565b145f14613f7c575f905d5b5b565b8055613f79565b5f688000000000ab143c065d613f7a565b865f526004601cfd5b30875414613fb257613f439596309055613f3d565b865f526004601cfd5b688000000000ab143c069594955c613fe257613f439430688000000000ab143c065d613f3e565b63ab143c065f526004601cfd5b15613ff657565b5f63fd99316160e01b81528061400e60048201610700565b0390fd5b61401b9061038d565b90565b61405361405a9461404960609498979561403f608086019a5f870190610a04565b6020850190610404565b60408301906105d6565b01906105d6565b565b1561406357565b5f63149196c760e21b81528061407b60048201610700565b0390fd5b9390929350816140976140915f6119b4565b91610401565b118061453d575b6140a790613a85565b6140b16002612495565b9160206140cb6140c3608086016124a1565b600190615384565b956140e36140db60c087016124a1565b600190615384565b95845f1461452c576140f7608087016124a1565b5b94614101611738565b918661411d6141176141125f611965565b610321565b91610321565b14155f146145065761413c9087903361413530614012565b9192615fcc565b61415a8661415361414e5f8b016124ae565b6109a4565b8791615523565b5b5f14614435576141e26141776141725f89016124ae565b6109a4565b946141c56141c06141a68a6141a061419b60a063532c46db999c999c97930161260a565b612617565b906124e4565b6141ba6141b560408d01612519565b612526565b90612556565b6155b8565b93956141ed5f6001906141d6610304565b998a988997889661257c565b86526004860161401e565b03925af1801561443057614404575b505b8061421961421361420e5f611965565b610321565b91610321565b036143d8575b50614364614348614284614231614573565b614239611738565b5061425a61425361424c608089016124a1565b5f90615384565b8990612633565b61427a61427361426c60c08a016124a1565b5f90615384565b8990612633565b9092909192614f14565b9691966142a38861429d6142975f6119b4565b91610401565b1161405c565b6142ae33899061602b565b6142c3426142be600133906103a5565b611a05565b6142d9826142d3608089016124a1565b906160d0565b6142ef816142e960c089016124a1565b906160d0565b3391909161432a897ff7ed121cfb40d57714b8349a1791bb3d55e16464fe62844d8ab562e66805272794614321610304565b94859485611da2565b0390a161434361433c608086016124a1565b5f90615384565b612633565b9261435f61435860c085016124a1565b5f90615384565b612633565b91806143786143725f6119b4565b91610401565b116143bb575b508161439261438c5f6119b4565b91610401565b1161439d575b505090565b6143ad60c06143b49392016124a1565b33916155ea565b5f80614398565b6143d2906143cb608084016124a1565b33916155ea565b5f61437e565b6143fe906143ef6143ea5f85016124ae565b6109a4565b6143f85f6119b4565b91615523565b5f61421f565b6144249060203d8111614429575b61441c818361178c565b810190612591565b6141fc565b503d614412565b6125fa565b6144b561444b6144465f89016124ae565b6109a4565b946144986144936144798a61447361446e8a637c51d6cf999c999c9793016124bb565b6124c8565b906124e4565b61448d61448860608d01612519565b612526565b90612556565b6155b8565b93956144c05f6001906144a9610304565b998a988997889661257c565b86526004860161401e565b03925af18015614501576144d5575b506141fe565b6144f59060203d81116144fa575b6144ed818361178c565b810190612591565b6144cf565b503d6144e3565b6125fa565b61452591925061451f6145193492610401565b91610401565b14613fef565b839061415b565b61453860c087016124a1565b6140f8565b506140a78361455461454e85610401565b91610401565b11905061409e565b9061457093929161456b611738565b613ef7565b90565b6145aa9061457f611738565b50614588611738565b506145916148f7565b92906145a461459e6138d8565b92611af2565b93611af2565b90565b5f90565b6145b96145ad565b50638b78c6d8195490565b5f7f4b5552552d5641554c5400000000000000000000000000000000000000000000910152565b6145f5600a6117ed565b90614602602083016145c4565b565b61460c6145eb565b90565b614617611773565b50614620614604565b90565b9061462c611863565b5061465361464461463f600133906103a5565b611ad1565b61464d5f611ad1565b90611af2565b61466561465f42610401565b91610401565b11614676576146739161622d565b90565b5f6303cb96db60e21b81528061468e60048201610700565b0390fd5b959490939192946146a1614f06565b614841575b6146ae6152e0565b91826146ca6146c46146bf5f611ff1565b610c5d565b91610c5d565b14614816575b6146d8615336565b93874211614809576040519860601b60601c9660601b60601c9765383775081901600e52875f526020600c20958654957f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8c5260208c015260408b01524660608b01523060808b015260a08a20602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98a528760208b01528860408b01528660608b01528460808b015260a08a015260c08920604e526042602c205f5260ff1660205260405260605260208060805f60015afa90843d51036147fc5701905582637f5e9f2060a01b176040526034602c20557f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925602060608501a36040525f606052565b63ddafbaef5f526004601cfd5b631a15a3cc5f526004601cfd5b915061482861482361184f565b61200d565b61483a61483482612016565b91612010565b20916146d0565b8319156e22d473030f116ddee9f6b43ac78ba38660601b60601c18176146a657633f68539a5f526004601cfd5b6e22d473030f116ddee9f6b43ac78ba390565b9061488a611738565b50614893614f06565b6148ae575b602052637f5e9f20600c525f526034600c205490565b806148c86148c26148bd61486e565b610321565b91610321565b036148985750505f1990565b9160206148f59294936148ee60408201965f8301906109e6565b01906109e6565b565b6148ff611738565b50614908611738565b5061491b614916600a613b46565b611666565b602063d4fac45d9161492c30614012565b9061495561493d60016002016108a6565b94614960614949610304565b9687958694859461257c565b8452600484016148d4565b03915afa908115614a41575f91614a13575b5090614986614981600a613b46565b611666565b602063d4fac45d9161499730614012565b906149bf6149a7600280016108a6565b946149ca6149b3610304565b9687958694859461257c565b8452600484016148d4565b03915afa908115614a0e575f916149e0575b5090565b614a01915060203d8111614a07575b6149f9818361178c565b810190612591565b5f6149dc565b503d6149ef565b6125fa565b614a34915060203d8111614a3a575b614a2c818361178c565b810190612591565b5f614972565b503d614a22565b6125fa565b929190614a51615212565b5f14614b0857614a5f611c31565b9346614a74614a6e6001611c49565b91610401565b145f14614aea57845c614ae157614a90939430905d5b5b614b5f565b90614a99615212565b5f14614ad057614aa7611c31565b46614abb614ab56001611c49565b91610401565b145f14614ac9575f905d5b5b565b8055614ac6565b5f688000000000ab143c065d614ac7565b845f526004601cfd5b30855414614aff57614a909394309055614a8a565b845f526004601cfd5b688000000000ab143c069392935c614b2f57614a909230688000000000ab143c065d614a8b565b63ab143c065f526004601cfd5b15614b4357565b5f63cd41a9e360e01b815280614b5b60048201610700565b0390fd5b90614bec929150614b7360016002016108a6565b614b8d614b87614b825f611965565b610321565b91610321565b148015614c17575b5f14614bfb57614be734614bac60016002016108a6565b614bc6614bc0614bbb5f611965565b610321565b91610321565b145f14614bef57614be0614bda845b610401565b91610401565b145b614b3c565b6162a2565b90565b614be0614bda85614bd5565b614be734614c11614c0b5f6119b4565b91610401565b14614be2565b50614c24600280016108a6565b614c3e614c38614c335f611965565b610321565b91610321565b14614b95565b90614c5691614c51611738565b614a46565b90565b614c6a90614c65615024565b614c6c565b565b63389a75e1600c52805f526020600c209081544211614c92575f614c909255615acd565b565b636f5e88185f526004601cfd5b614ca890614c59565b565b604090614cd3614cda9496959396614cc960608401985f8501906109e6565b6020830190610404565b0190610404565b565b90614ce5616491565b42614d14614d0e614d09614cf96009611ad1565b614d036008611ad1565b90611af2565b610401565b91610401565b10614e3457614d3f614d72614d61614d50614d2d614573565b9490614d396007611ad1565b906124e4565b614d4a612710613aab565b90612556565b92614d5b6007611ad1565b906124e4565b614d6c612710613aab565b90612556565b90614d86614d808592610401565b91610401565b11908115614e18575b50614dfc57614d9f426009611a05565b614db48282614dae60066108a6565b91615295565b614dbe60066108a6565b919091614df77f57a22e4f573fdde147e5da0d963e82b64839e457916475bb99cc5884b9b338cf93614dee610304565b93849384614caa565b0390a1565b5f6313b2e2c560e11b815280614e1460048201610700565b0390fd5b9050614e2d614e278392610401565b91610401565b115f614d8f565b5f6309766eeb60e41b815280614e4c60048201610700565b0390fd5b614e6190614e5c615024565b614e63565b565b8060601b15614e7757614e7590615acd565b565b637448fbae5f526004601cfd5b614e8d90614e50565b565b90614eb291614e9c611738565b50614ea5614573565b92909291929091926164b8565b90565b614ebd611738565b5063389a75e1600c525f526020600c205490565b9493909192614ef9614f0394614ee5611738565b50614eee611738565b50879085859261652d565b959290919261652d565b90565b614f0e611863565b50600190565b92909391614f20611738565b50614f29611738565b50614f32611738565b50614f3b6118f2565b90614f4a858388905f926165c4565b90614f62614f5c828587905f926165c4565b8361665a565b83614f75614f6f5f6119b4565b91610401565b146150165780614f8d614f8785610401565b91610401565b145f14614fd3575050614fcb9291614fbb614fb0614fc59383869060019261652d565b978790835f926165c4565b9287915f926165c4565b9061665a565b919291929190565b61500e9493919796506150089250614ff3614ffe9183899060019261652d565b968790835f926165c4565b9287915f926165c4565b9061665a565b919291929190565b935095505050919291929190565b638b78c6d81954330361503357565b6382b429005f526004601cfd5b91909161504b611863565b50615054614f06565b5f146151275760601b916e22d473030f116ddee9f6b43ac78ba333036150e4575b6387a211a28317600c526020600c2080548084116150d75783900390555f526020600c20818154019055602052600c5160601c9060601c7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a35b600190565b63f4d678b85f526004601cfd5b33602052637f5e9f208317600c526034600c2080548019615107575b5050615075565b80841161511a5783900390555f80615100565b6313be252b5f526004601cfd5b60601b9133602052637f5e9f208317600c526034600c20805480196151b7575b50506387a211a28317600c526020600c2080548084116151aa5783900390555f526020600c20818154019055602052600c5160601c9060601c7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a36150d2565b63f4d678b85f526004601cfd5b8084116151ca5783900390555f80615147565b6313be252b5f526004601cfd5b5f90565b90565b6151f26151ed6151f7926151db565b61036e565b611b89565b90565b6152026151d7565b5061520f6202a3006151de565b90565b61521a611863565b50600190565b6387a211a2600c52805f526020600c209182549283821161528857815f94039055806805345cdf77eb68f44c54036805345cdf77eb68f44c55825260601b60601c7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602083a3565b63f4d678b85f526004601cfd5b90916152de926152d66152ab60016002016108a6565b6152b7600280016108a6565b946152c3818390615492565b6152ce848790615492565b9084916155ea565b9190916155ea565b565b6152e8611fed565b90565b90565b6153026152fd615307926152eb565b611971565b610c5d565b90565b6153337fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc66152ee565b90565b61533e611fed565b5061534761530a565b90565b6153526166a3565b61535857565b6166f3565b50615366615024565b565b6153796153736166a3565b156105d1565b61537f57565b6166f3565b9061538d611738565b50816153a96153a361539e5f611965565b610321565b91610321565b14615440575060206153c56153c06153f793613b1a565b613b26565b6370a08231906153ec6153d730614012565b926153e0610304565b9586948593849361257c565b835260048301610cec565b03915afa90811561543b575f9161540d575b5090565b61542e915060203d8111615434575b615426818361178c565b810190612591565b5f615409565b503d61541c565b6125fa565b61545e915061544e30614012565b31905f1461546157345b90612633565b90565b61546a5f6119b4565b615458565b91602061549092949361548960408201965f830190610404565b01906109e6565b565b6154a461549f600a613b46565b611666565b9162f714ce919092803b1561551e576154d05f80946154db6154c4610304565b9788968795869461257c565b84526004840161546f565b03925af18015615519576154ed575b50565b61550c905f3d8111615512575b615504818361178c565b810190612f24565b5f6154ea565b503d6154fa565b6125fa565b612578565b919060145260345263095ea7b360601b5f5260205f6044601082855af1908160015f51141615615556575b50505f603452565b3d903b15171015615568575f8061554e565b633e3f8f735f526004601cfd5b5f90565b61558d61558861559292610401565b61036e565b6109f3565b90565b1561559c57565b5f637119f00960e11b8152806155b460048201610700565b0390fd5b906155c1615575565b506155e86155ce83615579565b926155e26155dc8592610401565b91612617565b14615595565b565b919091826156086156026155fd5f611965565b610321565b91610321565b1461561b576156199291909161671e565b565b906156269250616700565b565b5f7f5661756c743a206e6f74206f70657261746f7200000000000000000000000000910152565b61565c6013602092610508565b61566581615628565b0190565b61567e9060208101905f81830391015261564f565b90565b1561568857565b615690610304565b62461bcd60e51b8152806156a660048201615669565b0390fd5b6156cf336156c96156c36156be60056108a6565b610321565b91610321565b14615681565b565b905051906156de8261032d565b565b905051906156ed826132b0565b565b905051906156fc8261321e565b565b91906101008382031261577a57615717815f85016156d1565b9261572582602083016156e0565b9261573383604084016131ee565b9261574181606085016131ee565b9261574f82608083016131ee565b926157776157608460a085016156ef565b9361576e8160c086016156ef565b9360e001613b53565b90565b61030e565b9190615792905f60208501940190610a1b565b565b91906040838203126157bc57806157b06157b9925f86016131ee565b936020016131ee565b90565b61030e565b6157ca906124c8565b9052565b91906157e1905f602085019401906157c1565b565b906157ec611738565b506157f5611863565b5061583a61010061581061580b5f6002016107f6565b6109a4565b631c0d9c229061582f8692615823610304565b9586948593849361257c565b83526004830161577f565b03915afa908115615ac8575f8080808080808097959650509692505050615a90575b50919093845f146159f3576158aa604061588061587b5f6002016107f6565b6109a4565b63e6d29b519061589f8692615893610304565b9586948593849361257c565b8352600483016157ce565b03915afa80156159ee576158d6916158d0915f809290916159bd575b5090505b92610a11565b91610a11565b116159ae576158e3611738565b50835f146159645761592b61591061595f9361590a615904615945956124c8565b91612617565b906124e4565b61592561592060016002016108d8565b612617565b90612556565b61593f61593a5f60020161087a565b612526565b906124e4565b6159596159545f600201610826565b6124c8565b90612556565b5b9190565b5061598e6159746159a992612617565b6159886159835f600201610853565b612526565b906124e4565b6159a361599e60016002016108d8565b612617565b90612556565b615960565b50506159b95f6119b4565b9190565b90506159e0915060403d81116159e7575b6159d8818361178c565b810190615794565b905f6158c6565b503d6159ce565b6125fa565b615a366040615a0c615a075f6002016107f6565b6109a4565b630e2e2ffe90615a2b8692615a1f610304565b9586948593849361257c565b8352600483016157ce565b03915afa8015615a8b576158d6916158d0915f80929091615a5a575b5090506158ca565b9050615a7d915060403d8111615a84575b615a75818361178c565b810190615794565b905f615a52565b503d615a6b565b6125fa565b915050615ab591506101003d8111615ac1575b615aad818361178c565b8101906156fe565b9594505094505061585c565b503d615aa3565b6125fa565b615ad5616770565b5f14615b1a57638b78c6d8199060601b60601c8082547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3801560ff1b1790555b565b638b78c6d8199060601b60601c908181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a355615b18565b90565b615b6c615b67615b7192615b55565b611971565b610c5d565b90565b615b8263409feecd19615b58565b90565b615b8d611fed565b50615b96615b74565b90565b615ba1616770565b5f14615bf957638b78c6d819908154615bec5760601b60601c90811560ff1b821790555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a35b565b630dc149f05f526004601cfd5b60601b60601c80638b78c6d819555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a3615bea565b615c3a90610371565b90565b615c4690615c31565b90565b615c5290615c31565b90565b90565b90615c6d615c68615c7492615c49565b615c55565b8254611976565b9055565b919061016083820312615d2157615c91815f85016156ef565b92615c9f82602083016156e0565b92615cad83604084016156d1565b92615cbb8160608501612582565b92615cc982608083016156d1565b92615cd78360a08401612582565b92615ce58160c085016156ef565b92615cf38260e083016156e0565b92615d1e615d058461010085016156e0565b93615d14816101208601612582565b9361014001612582565b90565b61030e565b90615d3863ffffffff60a01b91613135565b9181191691161790565b615d56615d51615d5b926109bd565b61036e565b6109bd565b90565b90565b90615d76615d71615d7d92615d42565b615d5e565b8254615d26565b9055565b90615d9b6bffffffffffffffffffffffff60a01b91613135565b9181191691161790565b615db9615db4615dbe926109f3565b61036e565b6109f3565b90565b90565b90615dd9615dd4615de092615da5565b615dc1565b8254615d81565b9055565b615df8615df3615dfd92610401565b61036e565b6109d3565b90565b60c01b90565b90615e1560ff60c01b91615e00565b9181191691161790565b615e33615e2e615e38926109d3565b61036e565b6109d3565b90565b90565b90615e53615e4e615e5a92615e1f565b615e3b565b8254615e06565b9055565b90615e6d60ff60c81b91613197565b9181191691161790565b90615e8c615e87615e9392615e1f565b615e3b565b8254615e5e565b9055565b615ea3615eac91615c3d565b5f600201615c58565b615edc610160615ec6615ec15f6002016107f6565b6109a4565b6390c9427c90615ed4610304565b93849261257c565b82528180615eec60048201610700565b03915afa8015615fc757615f7191615f68915f808080808094909395929192615f73575b615f63959650615f5192615f42615f5a9593615f38615f4c949a919395989a5f600201615d61565b6001600201615dc4565b6001600201611994565b615de4565b5f600201615e3e565b60028001611994565b615de4565b5f600201615e77565b565b505050505050615f63615f4c615f5a615f51615f38615fac615f42966101603d8111615fc0575b615fa4818361178c565b810190615c78565b505050505098509650945092509550615f10565b503d615f9a565b6125fa565b916040519360605260405260601b602c526323b872dd60601b600c5260205f6064601c82855af1908160015f5114161561600c575b50505f606052604052565b3d903b1517101561601e575f80616001565b637939f4245f526004601cfd5b6805345cdf77eb68f44c54828101908110616091576805345cdf77eb68f44c556387a211a2600c525f526020600c20818154019055602052600c5160601c5f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a3565b63e5cfe9575f526004601cfd5b6040906160c76160ce94969593966160bd60608401985f8501906109e6565b60208301906109e6565b0190610404565b565b90806160ec6160e66160e15f611965565b610321565b91610321565b1461618e576161036160fe600a613b46565b611666565b90638340f5499161611330614012565b919392813b15616189575f61613b91616146829661612f610304565b9889978896879561257c565b85526004850161609e565b03925af1801561618457616158575b50565b616177905f3d811161617d575b61616f818361178c565b810190612f24565b5f616155565b503d616165565b6125fa565b612578565b6161a061619b600a613b46565b611666565b90638340f549839290926161b330614012565b929490823b15616228575f946161e56161da936161ce610304565b9889978896879561257c565b85526004850161609e565b03925af18015616223576161f7575b50565b616216905f3d811161621c575b61620e818361178c565b810190612f24565b5f6161f4565b503d616204565b6125fa565b612578565b616235611863565b506387a211a2600c52335f526020600c2080548084116162955783900390555f526020600c20818154019055602052600c5160601c337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a3600190565b63f4d678b85f526004601cfd5b906162ce916162af611738565b506162b8614573565b929092916162c4611738565b5092909192614f14565b6162ea836162e46162de5f6119b4565b91610401565b1161405c565b6162f533849061602b565b61630a42616305600133906103a5565b611a05565b616312611738565b61631f60016002016108a6565b61633961633361632e5f611965565b610321565b91610321565b145f146163cd575061634c348390612633565b5b61635883839061677e565b8061636b6163655f6119b4565b91610401565b116163b3575b50339190916163ad847ff7ed121cfb40d57714b8349a1791bb3d55e16464fe62844d8ab562e668052727946163a4610304565b94859485611da2565b0390a190565b6163c7906163c05f611965565b33916155ea565b5f616371565b6163d9600280016108a6565b6163f36163ed6163e85f611965565b610321565b91610321565b146163fe575b61634d565b5061640a348290612633565b6163f9565b5f7f5661756c743a206e6f7420676173206372616e6b000000000000000000000000910152565b6164436014602092610508565b61644c8161640f565b0190565b6164659060208101905f818303910152616436565b90565b1561646f57565b616477610304565b62461bcd60e51b81528061648d60048201616450565b0390fd5b6164b6336164b06164aa6164a560066108a6565b610321565b91610321565b14616468565b565b6164ef936164df6164e9936164cb611738565b506164d46118f2565b9390846001926165c4565b93916001926165c4565b9061665a565b90565b6164fb90610401565b5f1981146165095760010190565b611ade565b90565b61652561652061652a9261650e565b61036e565b610401565b90565b909161654761655b91959495616541611738565b506164f2565b926165556305f5e100616511565b90611af2565b9161657161656a8383906124e4565b8490612556565b949283616593575b505050616583575b565b9061658d906164f2565b90616581565b6165bb9293506165b5916165aa6165af92886124e4565b612556565b92610401565b91610401565b105f8080616579565b90916165de6165f2919594956165d8611738565b506164f2565b926165ec6305f5e100616511565b90611af2565b6166076166008383906124e4565b8490612556565b949283616629575b505050616619575b565b90616623906164f2565b90616617565b61665192935061664b9161664061664592886124e4565b612556565b92610401565b91610401565b105f808061660f565b90616663611738565b50818110908218021890565b6166789061038d565b90565b61668490610371565b90565b61669b6166966166a092610316565b61036e565b610401565b90565b6166ab611863565b507f000000000000000000000000937485adadda4746d6918a241eac95373d59334d6166ef6166e96166e46166df3061666f565b61667b565b616687565b91610401565b1490565b639f03a0265f526004601cfd5b905f8092389238915af11561671157565b63b12d13eb5f526004601cfd5b919060145260345263a9059cbb60601b5f5260205f6044601082855af1908160015f51141615616751575b50505f603452565b3d903b15171015616763575f80616749565b6390b8ec185f526004601cfd5b616778611863565b50600190565b6167eb916167e661679260016002016108a6565b61679e600280016108a6565b93816167ba6167b46167af5f611965565b610321565b91610321565b036167fd575b846167db6167d56167d05f611965565b610321565b91610321565b036167ed575b6160d0565b6160d0565b565b6167f885859061680d565b6167e1565b61680882829061680d565b6167c0565b9061682491903361681d30614012565b9192615fcc565b56fea26469706673582212208d8a627d1229f31534f17ea2c31c04dd0ef1a8aa715a9797410bd764d226f69664736f6c634300081e0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MON
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.