Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
Swapper
Compiler Version
v0.8.28+commit.7893614a
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { ITokenP } from "contracts/interfaces/ITokenP.sol";
import { ISwapper } from "contracts/interfaces/ISwapper.sol";
import { IPermit2, PermitTransferFrom } from "contracts/interfaces/external/permit2/IPermit2.sol";
import { SignatureTransferDetails, TokenPermissions } from "contracts/interfaces/external/permit2/IPermit2.sol";
import { AccessManagedModifiers } from "./AccessManagedModifiers.sol";
import { LibHelpers } from "../libraries/LibHelpers.sol";
import { LibManager } from "../libraries/LibManager.sol";
import { LibOracle } from "../libraries/LibOracle.sol";
import { LibStorage as s } from "../libraries/LibStorage.sol";
import { LibWhitelist } from "../libraries/LibWhitelist.sol";
import "../../utils/Constants.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";
// Struct to help storing local variables to avoid stack too deep issues
struct LocalVariables {
bool isMint;
bool isExact;
uint256 lowerExposure;
uint256 upperExposure;
int256 lowerFees;
int256 upperFees;
uint256 amountToNextBreakPoint;
uint256 stablecoinsIssued;
uint256 otherStablecoinSupply;
}
/// @title Swapper
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev In all the functions of this contract, one of `tokenIn` or `tokenOut` must be the stablecoin, and
/// one of `tokenOut` or `tokenIn` must be an accepted collateral. Depending on the `tokenIn` or `tokenOut` given,
/// the functions will either handle a mint or a burn operation
/// @dev In case of a burn, they will also revert if the system does not have enough of `amountOut` for `tokenOut`.
/// This balance must be available either directly on the contract or, when applicable, through the underlying
/// strategies that manage the collateral
/// @dev Functions here may be paused for some collateral assets (for either mint or burn), in which case they'll
/// revert
/// @dev In case of a burn again, the swap functions will revert if the call concerns a collateral that requires a
/// whitelist but the `to` address does not have it. The quote functions will not revert in this case.
/// @dev Calling one of the swap functions in a burn case does not require any prior token approval
/// @dev This contract is an authorized fork of Angle's `Swapper` contract
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/transmuter/facets/Swapper.sol
contract Swapper is ISwapper, AccessManagedModifiers {
using SafeERC20 for IERC20;
using SafeCast for uint256;
using Address for address;
using Math for uint256;
// The `to` address is not indexed as there cannot be 4 indexed addresses in an event.
event Swap(
address indexed tokenIn,
address indexed tokenOut,
uint256 amountIn,
uint256 amountOut,
address indexed from,
address to
);
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EXTERNAL ACTION FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
// For the four functions below, a value of `0` for the `deadline` parameters means that there will be no timestamp
// check for when the swap is actually executed.
/// @inheritdoc ISwapper
/// @dev `msg.sender` must have approved this contract for at least `amountIn` for `tokenIn` for mint transactions
function swapExactInput(
uint256 amountIn,
uint256 amountOutMin,
address tokenIn,
address tokenOut,
address to,
uint256 deadline
)
external
returns (uint256 amountOut)
{
(bool mint, Collateral storage collatInfo) = _getMintBurn(tokenIn, tokenOut, deadline);
amountOut =
mint ? _quoteMintExactInput(collatInfo, amountIn) : _quoteBurnExactInput(tokenOut, collatInfo, amountIn);
if (amountOut < amountOutMin) revert TooSmallAmountOut();
_swap(amountIn, amountOut, tokenIn, tokenOut, to, mint, collatInfo, "");
}
/// @inheritdoc ISwapper
function swapExactInputWithPermit(
uint256 amountIn,
uint256 amountOutMin,
address tokenIn,
address to,
uint256 deadline,
bytes memory permitData
)
external
returns (uint256 amountOut)
{
(address tokenOut, Collateral storage collatInfo) = _getMint(tokenIn, deadline);
amountOut = _quoteMintExactInput(collatInfo, amountIn);
if (amountOut < amountOutMin) revert TooSmallAmountOut();
permitData = _buildPermitTransferPayload(amountIn, amountIn, tokenIn, deadline, permitData, collatInfo);
_swap(amountIn, amountOut, tokenIn, tokenOut, to, true, collatInfo, permitData);
}
/// @inheritdoc ISwapper
/// @dev `msg.sender` must have approved this contract for an amount bigger than what `amountIn` will
/// be before calling this function for a mint. Approving the contract for `tokenIn` with `amountInMax`
/// will always be enough in this case
function swapExactOutput(
uint256 amountOut,
uint256 amountInMax,
address tokenIn,
address tokenOut,
address to,
uint256 deadline
)
external
returns (uint256 amountIn)
{
(bool mint, Collateral storage collatInfo) = _getMintBurn(tokenIn, tokenOut, deadline);
amountIn =
mint ? _quoteMintExactOutput(collatInfo, amountOut) : _quoteBurnExactOutput(tokenOut, collatInfo, amountOut);
if (amountIn > amountInMax) revert TooBigAmountIn();
_swap(amountIn, amountOut, tokenIn, tokenOut, to, mint, collatInfo, "");
}
/// @inheritdoc ISwapper
function swapExactOutputWithPermit(
uint256 amountOut,
uint256 amountInMax,
address tokenIn,
address to,
uint256 deadline,
bytes memory permitData
)
public
returns (uint256 amountIn)
{
(address tokenOut, Collateral storage collatInfo) = _getMint(tokenIn, deadline);
amountIn = _quoteMintExactOutput(collatInfo, amountOut);
if (amountIn > amountInMax) revert TooBigAmountIn();
permitData = _buildPermitTransferPayload(amountIn, amountInMax, tokenIn, deadline, permitData, collatInfo);
_swap(amountIn, amountOut, tokenIn, tokenOut, to, true, collatInfo, permitData);
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VIEW HELPERS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
// If these functions return a 0 `amountOut` or `amountIn` value, then calling one of the swap functions above
// will not do anything.
/// @inheritdoc ISwapper
function quoteIn(uint256 amountIn, address tokenIn, address tokenOut) external view returns (uint256 amountOut) {
ParallelizerStorage storage ts = s.transmuterStorage();
(bool mint, Collateral storage collatInfo) = _getMintBurn(tokenIn, tokenOut, block.timestamp);
if (mint) {
amountOut = _quoteMintExactInput(collatInfo, amountIn);
_checkHardCaps(collatInfo, amountOut, ts.normalizer);
} else {
amountOut = _quoteBurnExactInput(tokenOut, collatInfo, amountIn);
_checkAmounts(tokenOut, collatInfo, amountOut);
}
}
/// @inheritdoc ISwapper
function quoteOut(uint256 amountOut, address tokenIn, address tokenOut) external view returns (uint256 amountIn) {
ParallelizerStorage storage ts = s.transmuterStorage();
(bool mint, Collateral storage collatInfo) = _getMintBurn(tokenIn, tokenOut, block.timestamp);
if (mint) {
_checkHardCaps(collatInfo, amountOut, ts.normalizer);
return _quoteMintExactOutput(collatInfo, amountOut);
} else {
_checkAmounts(tokenOut, collatInfo, amountOut);
return _quoteBurnExactOutput(tokenOut, collatInfo, amountOut);
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
INTERNAL ACTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Processes the internal metric updates and the transfers following mint or burn operations
function _swap(
uint256 amountIn,
uint256 amountOut,
address tokenIn,
address tokenOut,
address to,
bool mint,
Collateral storage collatInfo,
bytes memory permitData
)
internal
nonReentrant
{
if (amountIn > 0 && amountOut > 0) {
ParallelizerStorage storage ts = s.transmuterStorage();
if (mint) {
uint128 changeAmount = (amountOut.mulDiv(BASE_27, ts.normalizer, Math.Rounding.Ceil)).toUint128();
// The amount of stablecoins issued from a collateral are not stored as absolute variables, but
// as variables normalized by a `normalizer`
collatInfo.normalizedStables = collatInfo.normalizedStables + uint216(changeAmount);
_checkHardCaps(collatInfo, 0, ts.normalizer);
ts.normalizedStables = ts.normalizedStables + changeAmount;
if (permitData.length > 0) {
PERMIT_2.functionCall(permitData);
} else if (collatInfo.isManaged > 0) {
IERC20(tokenIn).safeTransferFrom(
msg.sender, LibManager.transferRecipient(collatInfo.managerData.config), amountIn
);
} else {
IERC20(tokenIn).safeTransferFrom(msg.sender, address(this), amountIn);
}
if (collatInfo.isManaged > 0) {
LibManager.invest(amountIn, collatInfo.managerData.config);
}
ITokenP(tokenOut).mint(to, amountOut);
} else {
if (collatInfo.onlyWhitelisted > 0 && !LibWhitelist.checkWhitelist(collatInfo.whitelistData, to)) {
revert NotWhitelisted();
}
uint128 changeAmount = ((amountIn * BASE_27) / ts.normalizer).toUint128();
// This will underflow when the system is trying to burn more stablecoins than what has been issued
// from this collateral
collatInfo.normalizedStables = collatInfo.normalizedStables - uint216(changeAmount);
ts.normalizedStables = ts.normalizedStables - changeAmount;
ITokenP(tokenIn).burnSelf(amountIn, msg.sender);
if (collatInfo.isManaged > 0) {
LibManager.release(tokenOut, to, amountOut, collatInfo.managerData.config);
} else {
IERC20(tokenOut).safeTransfer(to, amountOut);
}
}
emit Swap(tokenIn, tokenOut, amountIn, amountOut, msg.sender, to);
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
INTERNAL VIEW
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Computes the `amountOut` of stablecoins to mint from `tokenIn` of a collateral with data `collatInfo`
function _quoteMintExactInput(
Collateral storage collatInfo,
uint256 amountIn
)
internal
view
returns (uint256 amountOut)
{
uint256 oracleValue = LibOracle.readMint(collatInfo.oracleConfig);
amountOut = LibHelpers.convertDecimalTo(oracleValue * amountIn, 18 + collatInfo.decimals, 18);
amountOut = _quoteFees(collatInfo, QuoteType.MintExactInput, amountOut);
}
/// @notice Computes the `amountIn` of collateral to get during a mint of `amountOut` of stablecoins
function _quoteMintExactOutput(
Collateral storage collatInfo,
uint256 amountOut
)
internal
view
returns (uint256 amountIn)
{
uint256 oracleValue = LibOracle.readMint(collatInfo.oracleConfig);
amountIn = _quoteFees(collatInfo, QuoteType.MintExactOutput, amountOut);
amountIn = LibHelpers.convertDecimalTo((amountIn * BASE_18) / oracleValue, 18, collatInfo.decimals);
}
/// @notice Computes the `amountIn` of stablecoins to burn to release `amountOut` of `collateral`
function _quoteBurnExactOutput(
address collateral,
Collateral storage collatInfo,
uint256 amountOut
)
internal
view
returns (uint256 amountIn)
{
(uint256 ratio, uint256 oracleValue) = LibOracle.getBurnOracle(collateral, collatInfo.oracleConfig);
amountIn = Math.mulDiv(LibHelpers.convertDecimalTo(amountOut, collatInfo.decimals, 18), oracleValue, ratio);
amountIn = _quoteFees(collatInfo, QuoteType.BurnExactOutput, amountIn);
}
/// @notice Computes the `amountOut` of `collateral` to give during a burn operation of `amountIn` of stablecoins
function _quoteBurnExactInput(
address collateral,
Collateral storage collatInfo,
uint256 amountIn
)
internal
view
returns (uint256 amountOut)
{
(uint256 ratio, uint256 oracleValue) = LibOracle.getBurnOracle(collateral, collatInfo.oracleConfig);
amountOut = _quoteFees(collatInfo, QuoteType.BurnExactInput, amountIn);
amountOut = LibHelpers.convertDecimalTo((amountOut * ratio) / oracleValue, 18, collatInfo.decimals);
}
/// @notice Computes the fees to apply during a mint or burn operation
/// @dev This function leverages the mathematical computations of the appendix of the Parallelizer whitepaper
/// @dev Cost of the function is linear in the length of the `xFeeMint` or `xFeeBurn` array
function _quoteFees(
Collateral storage collatInfo,
QuoteType quoteType,
uint256 amountStable
)
internal
view
returns (uint256)
{
LocalVariables memory v;
v.isMint = _isMint(quoteType);
v.isExact = _isExact(quoteType);
uint256 n = v.isMint ? collatInfo.xFeeMint.length : collatInfo.xFeeBurn.length;
uint256 currentExposure;
{
ParallelizerStorage storage ts = s.transmuterStorage();
uint256 normalizedStablesMem = ts.normalizedStables;
// Handling the initialisation and constant fees
if (normalizedStablesMem == 0 || n == 1) {
return _computeFee(quoteType, amountStable, v.isMint ? collatInfo.yFeeMint[0] : collatInfo.yFeeBurn[0]);
}
// Increasing precision for `currentExposure` because otherwise if there is a factor 1e9 between total
// stablecoin supply and one specific collateral, exposure can be null
currentExposure = uint64((collatInfo.normalizedStables * BASE_18) / normalizedStablesMem);
uint256 normalizerMem = ts.normalizer;
// Store the current amount of stablecoins issued from this collateral
v.stablecoinsIssued = (uint256(collatInfo.normalizedStables) * normalizerMem) / BASE_27;
v.otherStablecoinSupply = (normalizerMem * normalizedStablesMem) / BASE_27 - v.stablecoinsIssued;
}
uint256 amount;
// Finding in which segment the current exposure to the collateral is
uint256 i = LibHelpers.findLowerBound(
v.isMint, v.isMint ? collatInfo.xFeeMint : collatInfo.xFeeBurn, uint64(BASE_9), uint64(currentExposure)
);
while (i < n - 1) {
// We compute a linear by part function on the amount swapped
// The `amountToNextBreakPoint` variable is the `b_{i+1}` value from the whitepaper
if (v.isMint) {
v.lowerExposure = collatInfo.xFeeMint[i];
v.upperExposure = collatInfo.xFeeMint[i + 1];
v.lowerFees = collatInfo.yFeeMint[i];
v.upperFees = collatInfo.yFeeMint[i + 1];
v.amountToNextBreakPoint =
(v.otherStablecoinSupply * v.upperExposure) / (BASE_9 - v.upperExposure) - v.stablecoinsIssued;
} else {
// The exposures in the burn case are decreasing
v.lowerExposure = collatInfo.xFeeBurn[i];
v.upperExposure = collatInfo.xFeeBurn[i + 1];
v.lowerFees = collatInfo.yFeeBurn[i];
v.upperFees = collatInfo.yFeeBurn[i + 1];
// The `b_{i+1}` value in the burn case is the opposite value of the mint case
v.amountToNextBreakPoint =
v.stablecoinsIssued - (v.otherStablecoinSupply * v.upperExposure) / (BASE_9 - v.upperExposure);
}
// Computing the `g_i(0)` value from the whitepaper
int256 currentFees;
// We can only enter the else in the first iteration of the loop as otherwise we will
// always be at the beginning of the new segment
if (v.lowerExposure * BASE_9 == currentExposure) {
currentFees = v.lowerFees;
} else if (v.lowerFees == v.upperFees) {
currentFees = v.lowerFees;
} else {
// This is the opposite of the `b_i` value from the whitepaper.
uint256 amountFromPrevBreakPoint = v.isMint
? v.stablecoinsIssued - (v.otherStablecoinSupply * v.lowerExposure) / (BASE_9 - v.lowerExposure)
: (v.otherStablecoinSupply * v.lowerExposure) / (BASE_9 - v.lowerExposure) - v.stablecoinsIssued;
// slope = (upperFees - lowerFees) / (amountToNextBreakPoint + amountFromPrevBreakPoint)
// `currentFees` is the `g(0)` value from the whitepaper
currentFees = v.lowerFees
+ int256(
(uint256(v.upperFees - v.lowerFees) * amountFromPrevBreakPoint)
/ (v.amountToNextBreakPoint + amountFromPrevBreakPoint)
);
}
{
// In the mint case, when `!v.isExact`: = `b_{i+1} * (1+(g_i(0)+f_{i+1})/2)`
uint256 amountToNextBreakPointNormalizer = v.isExact
? v.amountToNextBreakPoint
: v.isMint
? _invertFeeMint(v.amountToNextBreakPoint, int64(v.upperFees + currentFees) / 2)
: _applyFeeBurn(v.amountToNextBreakPoint, int64(v.upperFees + currentFees) / 2);
if (amountToNextBreakPointNormalizer >= amountStable) {
int64 midFee;
if (v.isExact) {
// `(g_i(0) + g_i(M)) / 2 = g(0) + (f_{i+1} - g(0)) * M / (2 * b_{i+1})`
midFee = int64(
currentFees
+ int256(
amountStable.mulDiv(
uint256((v.upperFees - currentFees)), 2 * amountToNextBreakPointNormalizer, Math.Rounding.Ceil
)
)
);
} else {
// Here instead of computing the closed form expression for `m_t` derived in the whitepaper,
// we are computing: `(g(0)+g_i(m_t))/2 = g(0)+(f_{i+1}-f_i)/(b_{i+1}-b_i)m_t/2
// ac4 is the value of `2M(f_{i+1}-f_i)/(b_{i+1}-b_i) = 2M(f_{i+1}-g(0))/b_{i+1}` used
// in the computation of `m_t` in both the mint and burn case
uint256 ac4 = BASE_9.mulDiv(
2 * amountStable * uint256(v.upperFees - currentFees), v.amountToNextBreakPoint, Math.Rounding.Ceil
);
if (v.isMint) {
// In the mint case:
// `m_t = (-1-g(0)+sqrt[(1+g(0))**2+2M(f_{i+1}-g(0))/b_{i+1}])/((f_{i+1}-g(0))/b_{i+1})`
// And so: g(0)+(f_{i+1}-f_i)/(b_{i+1}-b_i)m_t/2
// = (g(0)-1+sqrt[(1+g(0))**2+2M(f_{i+1}-g(0))/b_{i+1}]) / 2
midFee = int64(
(
int256(Math.sqrt((uint256(int256(BASE_9) + currentFees)) ** 2 + ac4, Math.Rounding.Ceil))
+ currentFees - int256(BASE_9)
) / 2
);
} else {
// In the burn case:
// `m_t = (1-g(0)+sqrt[(1-g(0))**2-2M(f_{i+1}-g(0))/b_{i+1}])/((f_{i+1}-g(0))/b_{i+1})`
// And so: g(0)+(f_{i+1}-f_i)/(b_{i+1}-b_i)m_t/2
// = (g(0)+1-sqrt[(1-g(0))**2-2M(f_{i+1}-g(0))/b_{i+1}]) / 2
uint256 baseMinusCurrentSquared = (uint256(int256(BASE_9) - currentFees)) ** 2;
// Mathematically, this condition is always verified, but rounding errors may make this
// mathematical invariant break, in which case we consider that the square root is null
if (baseMinusCurrentSquared < ac4) {
midFee = int64((currentFees + int256(BASE_9)) / 2);
} else {
midFee = int64(
int256(
Math.mulDiv(
uint256(
currentFees + int256(BASE_9)
- int256(Math.sqrt(baseMinusCurrentSquared - ac4, Math.Rounding.Floor))
),
1,
2,
Math.Rounding.Ceil
)
)
);
}
}
}
return amount + _computeFee(quoteType, amountStable, midFee);
} else {
amountStable -= amountToNextBreakPointNormalizer;
amount += !v.isExact
? v.amountToNextBreakPoint
: v.isMint
? _invertFeeMint(v.amountToNextBreakPoint, int64(v.upperFees + currentFees) / 2)
: _applyFeeBurn(v.amountToNextBreakPoint, int64(v.upperFees + currentFees) / 2);
currentExposure = v.upperExposure * BASE_9;
++i;
// Update for the rest of the swaps the stablecoins issued from the asset
v.stablecoinsIssued =
v.isMint ? v.stablecoinsIssued + v.amountToNextBreakPoint : v.stablecoinsIssued - v.amountToNextBreakPoint;
}
}
}
// If `i == n-1`, we are in an area where fees are constant
return
amount + _computeFee(quoteType, amountStable, v.isMint ? collatInfo.yFeeMint[n - 1] : collatInfo.yFeeBurn[n - 1]);
}
/// @notice Checks whether there is still enough of the collateral to process the transfer
function _checkAmounts(address collateral, Collateral storage collatInfo, uint256 amountOut) internal view {
if (
(collatInfo.isManaged > 0 && LibManager.maxAvailable(collatInfo.managerData.config) < amountOut)
|| (collatInfo.isManaged == 0 && IERC20(collateral).balanceOf(address(this)) < amountOut)
) revert InvalidSwap();
}
/// @notice Checks whether there is enough space left to mint from this collateral
function _checkHardCaps(Collateral storage collatInfo, uint256 amount, uint256 normalizer) internal view {
if (amount + (collatInfo.normalizedStables * normalizer) / BASE_27 > collatInfo.stablecoinCap) {
revert InvalidSwap();
}
}
/// @notice Checks whether a swap from `tokenIn` to `tokenOut` is a mint or a burn, whether the
/// collateral provided is paused or not and in case of whether the swap is not occuring too late
/// @dev The function reverts if the `tokenIn` and `tokenOut` given do not correspond to the stablecoin
/// and to an accepted collateral asset of the system
function _getMintBurn(
address tokenIn,
address tokenOut,
uint256 deadline
)
internal
view
returns (bool mint, Collateral storage collatInfo)
{
if (block.timestamp > deadline) revert TooLate();
ParallelizerStorage storage ts = s.transmuterStorage();
address _tokenP = address(ts.tokenP);
if (tokenIn == _tokenP) {
collatInfo = ts.collaterals[tokenOut];
if (collatInfo.isBurnLive == 0) revert Paused();
mint = false;
} else if (tokenOut == _tokenP) {
collatInfo = ts.collaterals[tokenIn];
if (collatInfo.isMintLive == 0) revert Paused();
mint = true;
} else {
revert InvalidTokens();
}
}
/// @notice Checks whether `tokenIn` is a valid unpaused collateral and the deadline
function _getMint(
address tokenIn,
uint256 deadline
)
internal
view
returns (address tokenOut, Collateral storage collatInfo)
{
if (block.timestamp > deadline) revert TooLate();
ParallelizerStorage storage ts = s.transmuterStorage();
collatInfo = ts.collaterals[tokenIn];
if (collatInfo.isMintLive == 0) revert Paused();
tokenOut = address(ts.tokenP);
}
/// @notice Builds a permit2 `permitTransferFrom` payload for a `tokenIn` transfer
/// @dev The transfer should be from `msg.sender` to this contract or a manager
function _buildPermitTransferPayload(
uint256 amountIn,
uint256 approvedAmount,
address tokenIn,
uint256 deadline,
bytes memory permitData,
Collateral storage collatInfo
)
internal
view
returns (bytes memory payload)
{
Permit2Details memory details;
if (collatInfo.isManaged > 0) details.to = LibManager.transferRecipient(collatInfo.managerData.config);
else details.to = address(this);
(details.nonce, details.signature) = abi.decode(permitData, (uint256, bytes));
payload = abi.encodeWithSelector(
IPermit2.permitTransferFrom.selector,
PermitTransferFrom({
permitted: TokenPermissions({ token: tokenIn, amount: approvedAmount }),
nonce: details.nonce,
deadline: deadline
}),
SignatureTransferDetails({ to: details.to, requestedAmount: amountIn }),
msg.sender,
details.signature
);
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
INTERNAL PURE
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Applies or inverts `fees` to an `amount` based on the type of operation
function _computeFee(QuoteType quoteType, uint256 amount, int64 fees) internal pure returns (uint256) {
return quoteType == QuoteType.MintExactInput
? _applyFeeMint(amount, fees)
: quoteType == QuoteType.MintExactOutput
? _invertFeeMint(amount, fees)
: quoteType == QuoteType.BurnExactInput ? _applyFeeBurn(amount, fees) : _invertFeeBurn(amount, fees);
}
/// @notice Checks whether an operation is a mint operation or not
function _isMint(QuoteType quoteType) internal pure returns (bool) {
return quoteType == QuoteType.MintExactInput || quoteType == QuoteType.MintExactOutput;
}
/// @notice Checks whether a swap involves an amount of stablecoins that is known in exact in advance or not
function _isExact(QuoteType quoteType) internal pure returns (bool) {
return quoteType == QuoteType.MintExactOutput || quoteType == QuoteType.BurnExactInput;
}
/// @notice Applies `fees` to an `amountIn` of assets to get an `amountOut` of stablecoins
function _applyFeeMint(uint256 amountIn, int64 fees) internal pure returns (uint256 amountOut) {
if (fees >= 0) {
uint256 castedFees = uint256(int256(fees));
// Consider that if fees are above `BASE_12` this is equivalent to infinite fees
if (castedFees >= BASE_12) revert InvalidSwap();
amountOut = (amountIn * BASE_9) / (BASE_9 + castedFees);
} else {
amountOut = (amountIn * BASE_9) / (BASE_9 - uint256(int256(-fees)));
}
}
/// @notice Gets from an `amountOut` of stablecoins and with `fees`, the `amountIn` of assets
/// that need to be brought during a mint
function _invertFeeMint(uint256 amountOut, int64 fees) internal pure returns (uint256 amountIn) {
if (fees >= 0) {
uint256 castedFees = uint256(int256(fees));
// Consider that if fees are above `BASE_12` this is equivalent to infinite fees
if (castedFees >= BASE_12) revert InvalidSwap();
amountIn = amountOut.mulDiv(BASE_9 + castedFees, BASE_9, Math.Rounding.Ceil);
} else {
amountIn = amountOut.mulDiv(BASE_9 - uint256(int256(-fees)), BASE_9, Math.Rounding.Ceil);
}
}
/// @notice Applies `fees` to an `amountIn` of stablecoins to get an `amountOut` of assets
function _applyFeeBurn(uint256 amountIn, int64 fees) internal pure returns (uint256 amountOut) {
if (fees >= 0) {
uint256 castedFees = uint256(int256(fees));
if (castedFees >= MAX_BURN_FEE) revert InvalidSwap();
amountOut = ((BASE_9 - castedFees) * amountIn) / BASE_9;
} else {
amountOut = ((BASE_9 + uint256(int256(-fees))) * amountIn) / BASE_9;
}
}
/// @notice Gets from an `amountOut` of assets and with `fees` the `amountIn` of stablecoins that need
/// to be brought during a burn
function _invertFeeBurn(uint256 amountOut, int64 fees) internal pure returns (uint256 amountIn) {
if (fees >= 0) {
uint256 castedFees = uint256(int256(fees));
if (castedFees >= MAX_BURN_FEE) revert InvalidSwap();
amountIn = amountOut.mulDiv(BASE_9, BASE_9 - castedFees, Math.Rounding.Ceil);
} else {
amountIn = amountOut.mulDiv(BASE_9, BASE_9 + uint256(int256(-fees)), Math.Rounding.Ceil);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/AuthorityUtils.sol)
pragma solidity ^0.8.20;
import {IAuthority} from "./IAuthority.sol";
library AuthorityUtils {
/**
* @dev Since `AccessManager` implements an extended IAuthority interface, invoking `canCall` with backwards compatibility
* for the preexisting `IAuthority` interface requires special care to avoid reverting on insufficient return data.
* This helper function takes care of invoking `canCall` in a backwards compatible way without reverting.
*/
function canCallWithDelay(
address authority,
address caller,
address target,
bytes4 selector
) internal view returns (bool immediate, uint32 delay) {
(bool success, bytes memory data) = authority.staticcall(
abi.encodeCall(IAuthority.canCall, (caller, target, selector))
);
if (success) {
if (data.length >= 0x40) {
(immediate, delay) = abi.decode(data, (bool, uint32));
} else if (data.length >= 0x20) {
immediate = abi.decode(data, (bool));
}
}
return (immediate, delay);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/manager/IAccessManager.sol)
pragma solidity ^0.8.20;
import {Time} from "../../utils/types/Time.sol";
interface IAccessManager {
/**
* @dev A delayed operation was scheduled.
*/
event OperationScheduled(
bytes32 indexed operationId,
uint32 indexed nonce,
uint48 schedule,
address caller,
address target,
bytes data
);
/**
* @dev A scheduled operation was executed.
*/
event OperationExecuted(bytes32 indexed operationId, uint32 indexed nonce);
/**
* @dev A scheduled operation was canceled.
*/
event OperationCanceled(bytes32 indexed operationId, uint32 indexed nonce);
/**
* @dev Informational labelling for a roleId.
*/
event RoleLabel(uint64 indexed roleId, string label);
/**
* @dev Emitted when `account` is granted `roleId`.
*
* NOTE: The meaning of the `since` argument depends on the `newMember` argument.
* If the role is granted to a new member, the `since` argument indicates when the account becomes a member of the role,
* otherwise it indicates the execution delay for this account and roleId is updated.
*/
event RoleGranted(uint64 indexed roleId, address indexed account, uint32 delay, uint48 since, bool newMember);
/**
* @dev Emitted when `account` membership or `roleId` is revoked. Unlike granting, revoking is instantaneous.
*/
event RoleRevoked(uint64 indexed roleId, address indexed account);
/**
* @dev Role acting as admin over a given `roleId` is updated.
*/
event RoleAdminChanged(uint64 indexed roleId, uint64 indexed admin);
/**
* @dev Role acting as guardian over a given `roleId` is updated.
*/
event RoleGuardianChanged(uint64 indexed roleId, uint64 indexed guardian);
/**
* @dev Grant delay for a given `roleId` will be updated to `delay` when `since` is reached.
*/
event RoleGrantDelayChanged(uint64 indexed roleId, uint32 delay, uint48 since);
/**
* @dev Target mode is updated (true = closed, false = open).
*/
event TargetClosed(address indexed target, bool closed);
/**
* @dev Role required to invoke `selector` on `target` is updated to `roleId`.
*/
event TargetFunctionRoleUpdated(address indexed target, bytes4 selector, uint64 indexed roleId);
/**
* @dev Admin delay for a given `target` will be updated to `delay` when `since` is reached.
*/
event TargetAdminDelayUpdated(address indexed target, uint32 delay, uint48 since);
error AccessManagerAlreadyScheduled(bytes32 operationId);
error AccessManagerNotScheduled(bytes32 operationId);
error AccessManagerNotReady(bytes32 operationId);
error AccessManagerExpired(bytes32 operationId);
error AccessManagerLockedRole(uint64 roleId);
error AccessManagerBadConfirmation();
error AccessManagerUnauthorizedAccount(address msgsender, uint64 roleId);
error AccessManagerUnauthorizedCall(address caller, address target, bytes4 selector);
error AccessManagerUnauthorizedConsume(address target);
error AccessManagerUnauthorizedCancel(address msgsender, address caller, address target, bytes4 selector);
error AccessManagerInvalidInitialAdmin(address initialAdmin);
/**
* @dev Check if an address (`caller`) is authorised to call a given function on a given contract directly (with
* no restriction). Additionally, it returns the delay needed to perform the call indirectly through the {schedule}
* & {execute} workflow.
*
* This function is usually called by the targeted contract to control immediate execution of restricted functions.
* Therefore we only return true if the call can be performed without any delay. If the call is subject to a
* previously set delay (not zero), then the function should return false and the caller should schedule the operation
* for future execution.
*
* If `immediate` is true, the delay can be disregarded and the operation can be immediately executed, otherwise
* the operation can be executed if and only if delay is greater than 0.
*
* NOTE: The IAuthority interface does not include the `uint32` delay. This is an extension of that interface that
* is backward compatible. Some contracts may thus ignore the second return argument. In that case they will fail
* to identify the indirect workflow, and will consider calls that require a delay to be forbidden.
*
* NOTE: This function does not report the permissions of the admin functions in the manager itself. These are defined by the
* {AccessManager} documentation.
*/
function canCall(
address caller,
address target,
bytes4 selector
) external view returns (bool allowed, uint32 delay);
/**
* @dev Expiration delay for scheduled proposals. Defaults to 1 week.
*
* IMPORTANT: Avoid overriding the expiration with 0. Otherwise every contract proposal will be expired immediately,
* disabling any scheduling usage.
*/
function expiration() external view returns (uint32);
/**
* @dev Minimum setback for all delay updates, with the exception of execution delays. It
* can be increased without setback (and reset via {revokeRole} in the case event of an
* accidental increase). Defaults to 5 days.
*/
function minSetback() external view returns (uint32);
/**
* @dev Get whether the contract is closed disabling any access. Otherwise role permissions are applied.
*
* NOTE: When the manager itself is closed, admin functions are still accessible to avoid locking the contract.
*/
function isTargetClosed(address target) external view returns (bool);
/**
* @dev Get the role required to call a function.
*/
function getTargetFunctionRole(address target, bytes4 selector) external view returns (uint64);
/**
* @dev Get the admin delay for a target contract. Changes to contract configuration are subject to this delay.
*/
function getTargetAdminDelay(address target) external view returns (uint32);
/**
* @dev Get the id of the role that acts as an admin for the given role.
*
* The admin permission is required to grant the role, revoke the role and update the execution delay to execute
* an operation that is restricted to this role.
*/
function getRoleAdmin(uint64 roleId) external view returns (uint64);
/**
* @dev Get the role that acts as a guardian for a given role.
*
* The guardian permission allows canceling operations that have been scheduled under the role.
*/
function getRoleGuardian(uint64 roleId) external view returns (uint64);
/**
* @dev Get the role current grant delay.
*
* Its value may change at any point without an event emitted following a call to {setGrantDelay}.
* Changes to this value, including effect timepoint are notified in advance by the {RoleGrantDelayChanged} event.
*/
function getRoleGrantDelay(uint64 roleId) external view returns (uint32);
/**
* @dev Get the access details for a given account for a given role. These details include the timepoint at which
* membership becomes active, and the delay applied to all operation by this user that requires this permission
* level.
*
* Returns:
* [0] Timestamp at which the account membership becomes valid. 0 means role is not granted.
* [1] Current execution delay for the account.
* [2] Pending execution delay for the account.
* [3] Timestamp at which the pending execution delay will become active. 0 means no delay update is scheduled.
*/
function getAccess(
uint64 roleId,
address account
) external view returns (uint48 since, uint32 currentDelay, uint32 pendingDelay, uint48 effect);
/**
* @dev Check if a given account currently has the permission level corresponding to a given role. Note that this
* permission might be associated with an execution delay. {getAccess} can provide more details.
*/
function hasRole(uint64 roleId, address account) external view returns (bool isMember, uint32 executionDelay);
/**
* @dev Give a label to a role, for improved role discoverability by UIs.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleLabel} event.
*/
function labelRole(uint64 roleId, string calldata label) external;
/**
* @dev Add `account` to `roleId`, or change its execution delay.
*
* This gives the account the authorization to call any function that is restricted to this role. An optional
* execution delay (in seconds) can be set. If that delay is non 0, the user is required to schedule any operation
* that is restricted to members of this role. The user will only be able to execute the operation after the delay has
* passed, before it has expired. During this period, admin and guardians can cancel the operation (see {cancel}).
*
* If the account has already been granted this role, the execution delay will be updated. This update is not
* immediate and follows the delay rules. For example, if a user currently has a delay of 3 hours, and this is
* called to reduce that delay to 1 hour, the new delay will take some time to take effect, enforcing that any
* operation executed in the 3 hours that follows this update was indeed scheduled before this update.
*
* Requirements:
*
* - the caller must be an admin for the role (see {getRoleAdmin})
* - granted role must not be the `PUBLIC_ROLE`
*
* Emits a {RoleGranted} event.
*/
function grantRole(uint64 roleId, address account, uint32 executionDelay) external;
/**
* @dev Remove an account from a role, with immediate effect. If the account does not have the role, this call has
* no effect.
*
* Requirements:
*
* - the caller must be an admin for the role (see {getRoleAdmin})
* - revoked role must not be the `PUBLIC_ROLE`
*
* Emits a {RoleRevoked} event if the account had the role.
*/
function revokeRole(uint64 roleId, address account) external;
/**
* @dev Renounce role permissions for the calling account with immediate effect. If the sender is not in
* the role this call has no effect.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* Emits a {RoleRevoked} event if the account had the role.
*/
function renounceRole(uint64 roleId, address callerConfirmation) external;
/**
* @dev Change admin role for a given role.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleAdminChanged} event
*/
function setRoleAdmin(uint64 roleId, uint64 admin) external;
/**
* @dev Change guardian role for a given role.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleGuardianChanged} event
*/
function setRoleGuardian(uint64 roleId, uint64 guardian) external;
/**
* @dev Update the delay for granting a `roleId`.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {RoleGrantDelayChanged} event.
*/
function setGrantDelay(uint64 roleId, uint32 newDelay) external;
/**
* @dev Set the role required to call functions identified by the `selectors` in the `target` contract.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {TargetFunctionRoleUpdated} event per selector.
*/
function setTargetFunctionRole(address target, bytes4[] calldata selectors, uint64 roleId) external;
/**
* @dev Set the delay for changing the configuration of a given target contract.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {TargetAdminDelayUpdated} event.
*/
function setTargetAdminDelay(address target, uint32 newDelay) external;
/**
* @dev Set the closed flag for a contract.
*
* Closing the manager itself won't disable access to admin methods to avoid locking the contract.
*
* Requirements:
*
* - the caller must be a global admin
*
* Emits a {TargetClosed} event.
*/
function setTargetClosed(address target, bool closed) external;
/**
* @dev Return the timepoint at which a scheduled operation will be ready for execution. This returns 0 if the
* operation is not yet scheduled, has expired, was executed, or was canceled.
*/
function getSchedule(bytes32 id) external view returns (uint48);
/**
* @dev Return the nonce for the latest scheduled operation with a given id. Returns 0 if the operation has never
* been scheduled.
*/
function getNonce(bytes32 id) external view returns (uint32);
/**
* @dev Schedule a delayed operation for future execution, and return the operation identifier. It is possible to
* choose the timestamp at which the operation becomes executable as long as it satisfies the execution delays
* required for the caller. The special value zero will automatically set the earliest possible time.
*
* Returns the `operationId` that was scheduled. Since this value is a hash of the parameters, it can reoccur when
* the same parameters are used; if this is relevant, the returned `nonce` can be used to uniquely identify this
* scheduled operation from other occurrences of the same `operationId` in invocations of {execute} and {cancel}.
*
* Emits a {OperationScheduled} event.
*
* NOTE: It is not possible to concurrently schedule more than one operation with the same `target` and `data`. If
* this is necessary, a random byte can be appended to `data` to act as a salt that will be ignored by the target
* contract if it is using standard Solidity ABI encoding.
*/
function schedule(
address target,
bytes calldata data,
uint48 when
) external returns (bytes32 operationId, uint32 nonce);
/**
* @dev Execute a function that is delay restricted, provided it was properly scheduled beforehand, or the
* execution delay is 0.
*
* Returns the nonce that identifies the previously scheduled operation that is executed, or 0 if the
* operation wasn't previously scheduled (if the caller doesn't have an execution delay).
*
* Emits an {OperationExecuted} event only if the call was scheduled and delayed.
*/
function execute(address target, bytes calldata data) external payable returns (uint32);
/**
* @dev Cancel a scheduled (delayed) operation. Returns the nonce that identifies the previously scheduled
* operation that is cancelled.
*
* Requirements:
*
* - the caller must be the proposer, a guardian of the targeted function, or a global admin
*
* Emits a {OperationCanceled} event.
*/
function cancel(address caller, address target, bytes calldata data) external returns (uint32);
/**
* @dev Consume a scheduled operation targeting the caller. If such an operation exists, mark it as consumed
* (emit an {OperationExecuted} event and clean the state). Otherwise, throw an error.
*
* This is useful for contract that want to enforce that calls targeting them were scheduled on the manager,
* with all the verifications that it implies.
*
* Emit a {OperationExecuted} event.
*/
function consumeScheduledOp(address caller, bytes calldata data) external;
/**
* @dev Hashing function for delayed operations.
*/
function hashOperation(address caller, address target, bytes calldata data) external view returns (bytes32);
/**
* @dev Changes the authority of a target managed by this manager instance.
*
* Requirements:
*
* - the caller must be a global admin
*/
function updateAuthority(address target, address newAuthority) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/manager/IAuthority.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard interface for permissioning originally defined in Dappsys.
*/
interface IAuthority {
/**
* @dev Returns true if the caller can invoke on a target the function identified by a function selector.
*/
function canCall(address caller, address target, bytes4 selector) external view returns (bool allowed);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, bytes memory returndata) = recipient.call{value: amount}("");
if (!success) {
_revert(returndata);
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 1);
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 1);
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/types/Time.sol)
pragma solidity ^0.8.20;
import {Math} from "../math/Math.sol";
import {SafeCast} from "../math/SafeCast.sol";
/**
* @dev This library provides helpers for manipulating time-related objects.
*
* It uses the following types:
* - `uint48` for timepoints
* - `uint32` for durations
*
* While the library doesn't provide specific types for timepoints and duration, it does provide:
* - a `Delay` type to represent duration that can be programmed to change value automatically at a given point
* - additional helper functions
*/
library Time {
using Time for *;
/**
* @dev Get the block timestamp as a Timepoint.
*/
function timestamp() internal view returns (uint48) {
return SafeCast.toUint48(block.timestamp);
}
/**
* @dev Get the block number as a Timepoint.
*/
function blockNumber() internal view returns (uint48) {
return SafeCast.toUint48(block.number);
}
// ==================================================== Delay =====================================================
/**
* @dev A `Delay` is a uint32 duration that can be programmed to change value automatically at a given point in the
* future. The "effect" timepoint describes when the transitions happens from the "old" value to the "new" value.
* This allows updating the delay applied to some operation while keeping some guarantees.
*
* In particular, the {update} function guarantees that if the delay is reduced, the old delay still applies for
* some time. For example if the delay is currently 7 days to do an upgrade, the admin should not be able to set
* the delay to 0 and upgrade immediately. If the admin wants to reduce the delay, the old delay (7 days) should
* still apply for some time.
*
*
* The `Delay` type is 112 bits long, and packs the following:
*
* ```
* | [uint48]: effect date (timepoint)
* | | [uint32]: value before (duration)
* ↓ ↓ ↓ [uint32]: value after (duration)
* 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC
* ```
*
* NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently
* supported.
*/
type Delay is uint112;
/**
* @dev Wrap a duration into a Delay to add the one-step "update in the future" feature
*/
function toDelay(uint32 duration) internal pure returns (Delay) {
return Delay.wrap(duration);
}
/**
* @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled
* change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.
*/
function _getFullAt(
Delay self,
uint48 timepoint
) private pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
(valueBefore, valueAfter, effect) = self.unpack();
return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);
}
/**
* @dev Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the
* effect timepoint is 0, then the pending value should not be considered.
*/
function getFull(Delay self) internal view returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
return _getFullAt(self, timestamp());
}
/**
* @dev Get the current value.
*/
function get(Delay self) internal view returns (uint32) {
(uint32 delay, , ) = self.getFull();
return delay;
}
/**
* @dev Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to
* enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the
* new delay becomes effective.
*/
function withUpdate(
Delay self,
uint32 newValue,
uint32 minSetback
) internal view returns (Delay updatedDelay, uint48 effect) {
uint32 value = self.get();
uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));
effect = timestamp() + setback;
return (pack(value, newValue, effect), effect);
}
/**
* @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).
*/
function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {
uint112 raw = Delay.unwrap(self);
valueAfter = uint32(raw);
valueBefore = uint32(raw >> 32);
effect = uint48(raw >> 64);
return (valueBefore, valueAfter, effect);
}
/**
* @dev pack the components into a Delay object.
*/
function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay) {
return Delay.wrap((uint112(effect) << 64) | (uint112(valueBefore) << 32) | uint112(valueAfter));
}
}// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.28; /// @title IManager /// @author Cooper Labs /// @custom:contact [email protected] /// @dev This interface is an authorized fork of Angle's `IManager` interface /// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IManager.sol interface IManager { /// @notice Returns the amount of collateral managed by the Manager /// @return balances Balances of all the subCollaterals handled by the manager /// @dev MUST NOT revert function totalAssets() external view returns (uint256[] memory balances, uint256 totalValue); /// @notice Hook to invest `amount` of `collateral` /// @dev MUST revert if the manager cannot accept these funds /// @dev MUST have received the funds beforehand function invest(uint256 amount) external; /// @notice Sends `amount` of `collateral` to the `to` address /// @dev Called when `tokenP` are burnt and during redemptions // @dev MUST revert if there are not funds enough available /// @dev MUST be callable only by the parallelizer function release(address asset, address to, uint256 amount) external; /// @notice Gives the maximum amount of collateral immediately available for a transfer /// @dev Useful for integrators using `quoteIn` and `quoteOut` function maxAvailable() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.28; /// @title IParallelizerOracle /// @author Cooper Labs /// @custom:contact [email protected] /// @dev This interface is an authorized fork of Angle's `IParallelizerOracle` interface /// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IParallelizerOracle.sol interface IParallelizerOracle { /// @notice Reads the oracle value for asset to use in a redemption to compute the collateral ratio function readRedemption() external view returns (uint256); /// @notice Reads the oracle value for asset to use in a mint. It should be comprehensive of the /// deviation from the target price function readMint() external view returns (uint256); /// @notice Reads the oracle value for asset to use in a burn transaction as well as the ratio /// between the current price and the target price for the asset function readBurn() external view returns (uint256 oracleValue, uint256 ratio); /// @notice Reads the oracle value for asset function read() external view returns (uint256); }
// SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.28; /// @title ISwapper /// @author Cooper Labs /// @custom:contact [email protected] /// @dev This interface is an authorized fork of Angle's `ISwapper` interface /// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/ISwapper.sol interface ISwapper { /// @notice Swaps (that is to say mints or burns) an exact amount of `tokenIn` for an amount of `tokenOut` /// @param amountIn Amount of `tokenIn` to bring /// @param amountOutMin Minimum amount of `tokenOut` to get: if `amountOut` is inferior to this amount, the /// function will revert /// @param tokenIn Token to bring for the swap /// @param tokenOut Token to get out of the swap /// @param to Address to which `tokenOut` must be sent /// @param deadline Timestamp before which the transaction must be executed /// @return amountOut Amount of `tokenOut` obtained through the swap function swapExactInput( uint256 amountIn, uint256 amountOutMin, address tokenIn, address tokenOut, address to, uint256 deadline ) external returns (uint256 amountOut); /// @notice Same as `swapExactInput`, but using Permit2 signatures for `tokenIn` /// @dev Can only be used to mint, hence `tokenOut` is not needed function swapExactInputWithPermit( uint256 amountIn, uint256 amountOutMin, address tokenIn, address to, uint256 deadline, bytes calldata permitData ) external returns (uint256 amountOut); /// @notice Swaps (that is to say mints or burns) an amount of `tokenIn` for an exact amount of `tokenOut` /// @param amountOut Amount of `tokenOut` to obtain from the swap /// @param amountInMax Maximum amount of `tokenIn` to bring in order to get `amountOut` of `tokenOut` /// @param tokenIn Token to bring for the swap /// @param tokenOut Token to get out of the swap /// @param to Address to which `tokenOut` must be sent /// @param deadline Timestamp before which the transaction must be executed /// @return amountIn Amount of `tokenIn` used to perform the swap function swapExactOutput( uint256 amountOut, uint256 amountInMax, address tokenIn, address tokenOut, address to, uint256 deadline ) external returns (uint256 amountIn); /// @notice Same as `swapExactOutput`, but using Permit2 signatures for `tokenIn` /// @dev Can only be used to mint, hence `tokenOut` is not needed function swapExactOutputWithPermit( uint256 amountOut, uint256 amountInMax, address tokenIn, address to, uint256 deadline, bytes calldata permitData ) external returns (uint256 amountIn); /// @notice Simulates what a call to `swapExactInput` with `amountIn` of `tokenIn` for `tokenOut` would give. /// If called right before and at the same block, the `amountOut` outputted by this function is exactly the /// amount that will be obtained with `swapExactInput` function quoteIn(uint256 amountIn, address tokenIn, address tokenOut) external view returns (uint256 amountOut); /// @notice Simulates what a call to `swapExactOutput` for `amountOut` of `tokenOut` with `tokenIn` would give. /// If called right before and at the same block, the `amountIn` outputted by this function is exactly the /// amount that will be obtained with `swapExactOutput` function quoteOut(uint256 amountOut, address tokenIn, address tokenOut) external view returns (uint256 amountIn); }
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title ITokenP
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @notice Interface for the stablecoins `tokenP` contracts
/// @dev This interface is an authorized fork of Angle's `IAgToken` interface
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/interfaces/IAgToken.sol
interface ITokenP is IERC20 {
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MINTER ROLE ONLY FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Lets a whitelisted contract mint tokenPs
/// @param account Address to mint to
/// @param amount Amount to mint
function mint(address account, uint256 amount) external;
/// @notice Burns `amount` tokens from a `burner` address after being asked to by `sender`
/// @param amount Amount of tokens to burn
/// @param burner Address to burn from
/// @param sender Address which requested the burn from `burner`
/// @dev This method is to be called by a contract with the minter right after being requested
/// to do so by a `sender` address willing to burn tokens from another `burner` address
/// @dev The method checks the allowance between the `sender` and the `burner`
function burnFrom(uint256 amount, address burner, address sender) external;
/// @notice Burns `amount` tokens from a `burner` address
/// @param amount Amount of tokens to burn
/// @param burner Address to burn from
/// @dev This method is to be called by a contract with a minter right on the tokenP after being
/// requested to do so by an address willing to burn tokens from its address
function burnSelf(uint256 amount, address burner) external;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Amount of decimals of the stablecoin
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
// getRoundData and latestRoundData should both raise "No data present"
// if they do not have data to report, instead of returning unset values
// which could be misinterpreted as actual reported values.
function getRoundData(uint80 _roundId)
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title ICbETH
/// @notice Interface for the `cbETH` contract
interface ICbETH {
function exchangeRate() external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title ISfrxETH
/// @notice Interface for the `sfrxETH` contract
interface ISfrxETH {
function pricePerShare() external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IKeyringGuard
/// @notice Interface for the `KeyringGuard` contract
interface IKeyringGuard {
function isAuthorized(address from, address to) external returns (bool passed);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IStETH
/// @notice Interface for the `StETH` contract
interface IStETH {
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);
function submit(address) external payable returns (uint256);
function getSharesByPooledEth(uint256 _ethAmount) external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IMorphoOracle
/// @notice Interface for the oracle contracts used within Morpho
interface IMorphoOracle {
function price() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0;
/// @notice The token and amount details for a transfer signed in the permit transfer signature
struct TokenPermissions {
// ERC20 token address
address token;
// the maximum amount that can be spent
uint256 amount;
}
/// @notice The signed permit message for a single token transfer
struct PermitTransferFrom {
TokenPermissions permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice Specifies the recipient address and amount for batched transfers.
/// @dev Recipients and amounts correspond to the index of the signed token permissions array.
/// @dev Reverts if the requested amount is greater than the permitted signed amount.
struct SignatureTransferDetails {
// recipient address
address to;
// spender requested amount
uint256 requestedAmount;
}
/// @title SignatureTransfer
/// @notice Handles ERC20 token transfers through signature based actions
/// @dev Requires user's token approval on the Permit2 contract
interface IPermit2 {
/// @notice Transfers a token using a signed permit message
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param signature The signature to verify
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
)
external;
}// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0;
/// @title IRETH
/// @notice Interface for the `rETH` contract
interface IRETH {
function getExchangeRate() external view returns (uint256);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IAccessManager } from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
import { ITokenP } from "contracts/interfaces/ITokenP.sol";
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ENUMS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
enum FacetCutAction {
Add,
Replace,
Remove
}
enum ManagerType {
EXTERNAL
}
enum ActionType {
Mint,
Burn,
Redeem
}
enum TrustedType {
Updater,
Seller
}
enum QuoteType {
MintExactInput,
MintExactOutput,
BurnExactInput,
BurnExactOutput
}
enum OracleReadType {
CHAINLINK_FEEDS,
EXTERNAL,
NO_ORACLE,
STABLE,
WSTETH,
CBETH,
RETH,
SFRXETH,
MAX,
MORPHO_ORACLE
}
enum OracleQuoteType {
UNIT,
TARGET
}
enum WhitelistType {
BACKED
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
struct Permit2Details {
address to; // Address that will receive the funds
uint256 nonce; // Nonce of the transaction
bytes signature; // Permit signature of the user
}
struct FacetCut {
address facetAddress; // Facet contract address
FacetCutAction action; // Can be add, remove or replace
bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}
struct Facet {
address facetAddress; // Facet contract address
bytes4[] functionSelectors; // Ex. bytes4(keccak256("transfer(address,uint256)"))
}
struct FacetInfo {
address facetAddress; // Facet contract address
uint16 selectorPosition; // Position in the list of all selectors
}
struct DiamondStorage {
bytes4[] selectors; // List of all available selectors
mapping(bytes4 => FacetInfo) selectorInfo; // Selector to (address, position in list)
IAccessManager accessManager; // Contract handling access management
}
struct ImplementationStorage {
address implementation; // Dummy implementation address for Etherscan usability
}
struct ManagerStorage {
IERC20[] subCollaterals; // Subtokens handled by the manager or strategies
bytes config; // Additional configuration data
}
struct Collateral {
uint8 isManaged; // If the collateral is managed through external strategies
uint8 isMintLive; // If minting from this asset is unpaused
uint8 isBurnLive; // If burning to this asset is unpaused
uint8 decimals; // IERC20Metadata(collateral).decimals()
uint8 onlyWhitelisted; // If only whitelisted addresses can burn or redeem for this token
uint216 normalizedStables; // Normalized amount of stablecoins issued from this collateral
uint64[] xFeeMint; // Increasing exposures in [0,BASE_9[
int64[] yFeeMint; // Mint fees at the exposures specified in `xFeeMint`
uint64[] xFeeBurn; // Decreasing exposures in ]0,BASE_9]
int64[] yFeeBurn; // Burn fees at the exposures specified in `xFeeBurn`
bytes oracleConfig; // Data about the oracle used for the collateral
bytes whitelistData; // For whitelisted collateral, data used to verify whitelists
ManagerStorage managerData; // For managed collateral, data used to handle the strategies
uint256 stablecoinCap; // Cap on the amount of stablecoins that can be issued from this collateral
}
struct ParallelizerStorage {
ITokenP tokenP; // tokenP handled by the system
uint8 isRedemptionLive; // If redemption is unpaused
uint8 statusReentrant; // If call is reentrant or not
bool consumingSchedule; // If the contract is consuming a scheduled operation
uint128 normalizedStables; // Normalized amount of stablecoins issued by the system
uint128 normalizer; // To reconcile `normalizedStables` values with the actual amount
address[] collateralList; // List of collateral assets supported by the system
uint64[] xRedemptionCurve; // Increasing collateral ratios > 0
int64[] yRedemptionCurve; // Value of the redemption fees at `xRedemptionCurve`
mapping(address => Collateral) collaterals; // Maps a collateral asset to its parameters
mapping(address => uint256) isTrusted; // If an address is trusted to update the normalizer value
mapping(address => uint256) isSellerTrusted; // If an address is trusted to sell accruing reward tokens or to run
// keeper jobs on oracles
mapping(WhitelistType => mapping(address => uint256)) isWhitelistedForType;
}
// Whether an address is whitelisted for a specific whitelist type// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { LibDiamond } from "../libraries/LibDiamond.sol";
import { LibStorage as s, ParallelizerStorage } from "../libraries/LibStorage.sol";
import "../../utils/Errors.sol";
import "../../utils/Constants.sol";
/// @title AccessManagedModifiers
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This contract is an authorized fork of Angle's `AccessControlModifiers` contract
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/facets/AccessControlModifiers.sol
/// update access logic to use OpenZeppelin's `AccessManaged` logic
contract AccessManagedModifiers {
/// @notice Checks whether the `msg.sender` can call a function with a given selector
modifier restricted() {
if (!LibDiamond.checkCanCall(msg.sender, msg.data)) revert AccessManagedUnauthorized(msg.sender);
_;
}
/// @notice Prevents a contract from calling itself, directly or indirectly
/// @dev This implementation is an adaptation of the OpenZepellin `ReentrancyGuard` for the purpose of this
/// Diamond Proxy system. The base implementation can be found here
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol
modifier nonReentrant() {
ParallelizerStorage storage ts = s.transmuterStorage();
// Reentrant protection
// On the first call, `ts.statusReentrant` will be `NOT_ENTERED`
if (ts.statusReentrant == ENTERED) revert ReentrantCall();
// Any calls to the `nonReentrant` modifier after this point will fail
ts.statusReentrant = ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
ts.statusReentrant = NOT_ENTERED;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import { LibStorage as s } from "./LibStorage.sol";
import { IAccessManager } from "@openzeppelin/contracts/access/manager/IAccessManager.sol";
import { AuthorityUtils } from "@openzeppelin/contracts/access/manager/AuthorityUtils.sol";
import "../../utils/Errors.sol";
import "../../utils/Constants.sol";
import "../Storage.sol";
/// @title LibDiamond
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @notice Helper library to deal with diamond proxies.
/// @dev Reference: EIP-2535 Diamonds
/// @dev Forked from https://github.com/mudgen/diamond-3/blob/master/contracts/libraries/LibDiamond.sol by mudgen
library LibDiamond {
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
function isGovernor(address caller) internal view returns (bool) {
(bool isMember,) = s.diamondStorage().accessManager.hasRole(GOVERNOR_ROLE, caller);
return isMember;
}
/// @notice Checks whether `caller` can call `data` on `this`
function checkCanCall(address caller, bytes calldata data) internal returns (bool) {
IAccessManager accessManager = s.diamondStorage().accessManager;
(bool immediate, uint32 delay) =
AuthorityUtils.canCallWithDelay(address(accessManager), caller, address(this), bytes4(data[0:4]));
if (!immediate) {
if (delay > 0) {
ParallelizerStorage storage ts = s.transmuterStorage();
ts.consumingSchedule = true;
accessManager.consumeScheduledOp(caller, data);
ts.consumingSchedule = false;
} else {
return false;
}
}
return true;
}
/// @notice Internal function version of `diamondCut`
function diamondCut(FacetCut[] memory _diamondCut, address _init, bytes memory _calldata) internal {
uint256 diamondCutLength = _diamondCut.length;
for (uint256 facetIndex; facetIndex < diamondCutLength; facetIndex++) {
bytes4[] memory functionSelectors = _diamondCut[facetIndex].functionSelectors;
address facetAddress = _diamondCut[facetIndex].facetAddress;
if (functionSelectors.length == 0) {
revert NoSelectorsProvidedForFacetForCut(facetAddress);
}
FacetCutAction action = _diamondCut[facetIndex].action;
if (action == FacetCutAction.Add) {
_addFunctions(facetAddress, functionSelectors);
} else if (action == FacetCutAction.Replace) {
_replaceFunctions(facetAddress, functionSelectors);
} else if (action == FacetCutAction.Remove) {
_removeFunctions(facetAddress, functionSelectors);
}
}
emit DiamondCut(_diamondCut, _init, _calldata);
_initializeDiamondCut(_init, _calldata);
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PRIVATE FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Does a delegate call on `_init` with `_calldata`
function _initializeDiamondCut(address _init, bytes memory _calldata) private {
if (_init == address(0)) {
return;
}
_enforceHasContractCode(_init);
(bool success, bytes memory error) = _init.delegatecall(_calldata);
if (!success) {
if (error.length > 0) {
assembly ("memory-safe") {
let returndata_size := mload(error)
revert(add(32, error), returndata_size)
}
} else {
revert InitializationFunctionReverted(_init, _calldata);
}
}
}
/// @notice Adds a new function to the diamond proxy
/// @dev Reverts if selectors are already existing
function _addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
if (_facetAddress == address(0)) {
revert CannotAddSelectorsToZeroAddress(_functionSelectors);
}
DiamondStorage storage ds = s.diamondStorage();
uint16 selectorCount = uint16(ds.selectors.length);
_enforceHasContractCode(_facetAddress);
uint256 functionSelectorsLength = _functionSelectors.length;
for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds.selectorInfo[selector].facetAddress;
if (oldFacetAddress != address(0)) {
revert CannotAddFunctionToDiamondThatAlreadyExists(selector);
}
ds.selectorInfo[selector] = FacetInfo(_facetAddress, selectorCount);
ds.selectors.push(selector);
selectorCount++;
}
}
/// @notice Upgrades a function in the diamond proxy
/// @dev Reverts if selectors do not already exist
function _replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
DiamondStorage storage ds = s.diamondStorage();
if (_facetAddress == address(0)) {
revert CannotReplaceFunctionsFromFacetWithZeroAddress(_functionSelectors);
}
_enforceHasContractCode(_facetAddress);
uint256 functionSelectorsLength = _functionSelectors.length;
for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds.selectorInfo[selector].facetAddress;
// Can't replace immutable functions -- functions defined directly in the diamond in this case
if (oldFacetAddress == address(this)) {
revert CannotReplaceImmutableFunction(selector);
}
if (oldFacetAddress == _facetAddress) {
revert CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(selector);
}
if (oldFacetAddress == address(0)) {
revert CannotReplaceFunctionThatDoesNotExists(selector);
}
// Replace old facet address
ds.selectorInfo[selector].facetAddress = _facetAddress;
}
}
/// @notice Removes a function in the diamond proxy
/// @dev Reverts if selectors do not already exist
function _removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
DiamondStorage storage ds = s.diamondStorage();
uint256 selectorCount = ds.selectors.length;
if (_facetAddress != address(0)) {
revert RemoveFacetAddressMustBeZeroAddress(_facetAddress);
}
uint256 functionSelectorsLength = _functionSelectors.length;
for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
bytes4 selector = _functionSelectors[selectorIndex];
FacetInfo memory oldFacetAddressAndSelectorPosition = ds.selectorInfo[selector];
if (oldFacetAddressAndSelectorPosition.facetAddress == address(0)) {
revert CannotRemoveFunctionThatDoesNotExist(selector);
}
// Can't remove immutable functions -- functions defined directly in the diamond
if (oldFacetAddressAndSelectorPosition.facetAddress == address(this)) {
revert CannotRemoveImmutableFunction(selector);
}
// Replace selector with last selector
selectorCount--;
if (oldFacetAddressAndSelectorPosition.selectorPosition != selectorCount) {
bytes4 lastSelector = ds.selectors[selectorCount];
ds.selectors[oldFacetAddressAndSelectorPosition.selectorPosition] = lastSelector;
ds.selectorInfo[lastSelector].selectorPosition = oldFacetAddressAndSelectorPosition.selectorPosition;
}
// Delete last selector
ds.selectors.pop();
delete ds.selectorInfo[selector];
}
}
/// @notice Checks that an address has a non void bytecode
function _enforceHasContractCode(address _contract) private view {
uint256 contractSize;
assembly ("memory-safe") {
contractSize := extcodesize(_contract)
}
if (contractSize == 0) {
revert ContractHasNoCode();
}
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import "../Storage.sol";
/// @title LibHelpers
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibHelpers` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibHelpers.sol
library LibHelpers {
/// @notice Rebases the units of `amount` from `fromDecimals` to `toDecimals`
function convertDecimalTo(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256) {
if (fromDecimals > toDecimals) return amount / 10 ** (fromDecimals - toDecimals);
else if (fromDecimals < toDecimals) return amount * 10 ** (toDecimals - fromDecimals);
else return amount;
}
/// @notice Checks whether a `token` is in a list `tokens` and returns the index of the token in the list
/// or -1 in the other case
function checkList(address token, address[] memory tokens) internal pure returns (int256) {
uint256 tokensLength = tokens.length;
for (uint256 i; i < tokensLength; ++i) {
if (token == tokens[i]) return int256(i);
}
return -1;
}
/// @notice Searches a sorted `array` and returns the first index that contains a value strictly greater
/// (or lower if increasingArray is false) to `element` minus 1
/// @dev If no such index exists (i.e. all values in the array are strictly lesser/greater than `element`),
/// either array length minus 1, or 0 are returned
/// @dev The time complexity of the search is O(log n).
/// @dev Inspired from OpenZeppelin Contracts v4.4.1:
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Arrays.sol
/// @dev Modified by Angle Labs to support `uint64`, monotonous arrays and exclusive upper bounds
function findLowerBound(
bool increasingArray,
uint64[] memory array,
uint64 normalizerArray,
uint64 element
)
internal
pure
returns (uint256)
{
if (array.length == 0) {
return 0;
}
uint256 low = 1;
uint256 high = array.length;
if (
(increasingArray && array[high - 1] * normalizerArray <= element)
|| (!increasingArray && array[high - 1] * normalizerArray >= element)
) return high - 1;
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds down (it does integer division with truncation).
if (increasingArray ? array[mid] * normalizerArray > element : array[mid] * normalizerArray < element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound.
// `low - 1` is the inclusive lower bound.
return low - 1;
}
/// @notice Evaluates for `x` a piecewise linear function defined with the breaking points in the arrays
/// `xArray` and `yArray`
/// @dev The values in the `xArray` must be increasing
function piecewiseLinear(uint64 x, uint64[] memory xArray, int64[] memory yArray) internal pure returns (int64) {
uint256 indexLowerBound = findLowerBound(true, xArray, 1, x);
if (indexLowerBound == 0 && x < xArray[0]) return yArray[0];
else if (indexLowerBound == xArray.length - 1) return yArray[xArray.length - 1];
return yArray[indexLowerBound]
+ ((yArray[indexLowerBound + 1] - yArray[indexLowerBound]) * int64(x - xArray[indexLowerBound]))
/ int64(xArray[indexLowerBound + 1] - xArray[indexLowerBound]);
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IManager } from "contracts/interfaces/IManager.sol";
import "../Storage.sol";
/// @title LibManager
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev Managed collateral assets may be handled through external smart contracts or directly through this library
/// @dev There is no implementation at this point for a managed collateral handled through this library, and
/// a new specific `ManagerType` would need to be added in this case
/// @dev This library is an authorized fork of Angle's `LibManager` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibManager.sol
library LibManager {
/// @notice Checks to which address managed funds must be transferred
function transferRecipient(bytes memory config) internal view returns (address recipient) {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
recipient = address(this);
if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (address));
}
/// @notice Performs a transfer of `token` for a collateral that is managed to a `to` address
/// @dev `token` may not be the actual collateral itself, as some collaterals have subcollaterals associated
/// with it
/// @dev Eventually pulls funds from strategies
function release(address token, address to, uint256 amount, bytes memory config) internal {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) abi.decode(data, (IManager)).release(token, to, amount);
}
/// @notice Gets the balances of all the tokens controlled through `managerData`
/// @return balances An array of size `subCollaterals` with current balances of all subCollaterals
/// including the one corresponding to the `managerData` given
/// @return totalValue The value of all the `subCollaterals` in `collateral`
/// @dev `subCollaterals` must always have as first token (index 0) the collateral itself
function totalAssets(bytes memory config) internal view returns (uint256[] memory balances, uint256 totalValue) {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (IManager)).totalAssets();
}
/// @notice Calls a hook if needed after new funds have been transfered to a manager
function invest(uint256 amount, bytes memory config) internal {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) abi.decode(data, (IManager)).invest(amount);
}
/// @notice Returns available underlying tokens, for instance if liquidity is fully used and
/// not withdrawable the function will return 0
function maxAvailable(bytes memory config) internal view returns (uint256 available) {
(ManagerType managerType, bytes memory data) = parseManagerConfig(config);
if (managerType == ManagerType.EXTERNAL) return abi.decode(data, (IManager)).maxAvailable();
}
/// @notice Decodes the `managerData` associated to a collateral
function parseManagerConfig(bytes memory config) internal pure returns (ManagerType managerType, bytes memory data) {
(managerType, data) = abi.decode(config, (ManagerType, bytes));
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IParallelizerOracle } from "contracts/interfaces/IParallelizerOracle.sol";
import { AggregatorV3Interface } from "contracts/interfaces/external/chainlink/AggregatorV3Interface.sol";
import { IMorphoOracle } from "contracts/interfaces/external/morpho/IMorphoOracle.sol";
import { LibStorage as s } from "./LibStorage.sol";
import "../../utils/Constants.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";
/// @title LibOracle
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibOracle` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibOracle.sol
library LibOracle {
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ACTIONS SPECIFIC ORACLES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Reads the oracle value used during a redemption to compute collateral ratio for `oracleConfig`
/// @dev This value is only sensitive to compute the collateral ratio and deduce a penalty factor
function readRedemption(bytes memory oracleConfig) internal view returns (uint256 oracleValue) {
(OracleReadType oracleType, OracleReadType targetType, bytes memory oracleData, bytes memory targetData,) =
_parseOracleConfig(oracleConfig);
if (oracleType == OracleReadType.EXTERNAL) {
IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
return externalOracle.readRedemption();
} else {
(oracleValue,) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, 0);
return oracleValue;
}
}
/// @notice Reads the oracle value used during mint operations for an asset with `oracleConfig`
/// @dev For assets which do not rely on external oracles, this value is the minimum between the processed oracle
/// value for the asset and its target price
function readMint(bytes memory oracleConfig) internal view returns (uint256 oracleValue) {
(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
) = _parseOracleConfig(oracleConfig);
if (oracleType == OracleReadType.EXTERNAL) {
IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
return externalOracle.readMint();
}
(uint128 userDeviation,) = abi.decode(hyperparameters, (uint128, uint128));
uint256 targetPrice;
(oracleValue, targetPrice) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, userDeviation);
if (targetPrice < oracleValue) oracleValue = targetPrice;
}
/// @notice Reads the oracle value used for a burn operation for an asset with `oracleConfig`
/// @return oracleValue The actual oracle value obtained
/// @return ratio If `oracle value < target price`, the ratio between the oracle value and the target
/// price, otherwise `BASE_18`
function readBurn(bytes memory oracleConfig) internal view returns (uint256 oracleValue, uint256 ratio) {
(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
) = _parseOracleConfig(oracleConfig);
if (oracleType == OracleReadType.EXTERNAL) {
IParallelizerOracle externalOracle = abi.decode(oracleData, (IParallelizerOracle));
return externalOracle.readBurn();
}
(uint128 userDeviation, uint128 burnRatioDeviation) = abi.decode(hyperparameters, (uint128, uint128));
uint256 targetPrice;
(oracleValue, targetPrice) = readSpotAndTarget(oracleType, targetType, oracleData, targetData, userDeviation);
// Firewall in case the oracle value reported is low compared to the target
// If the oracle value is slightly below its target, then no deviation is reported for the oracle and
// the price of burning the stablecoin for other assets is not impacted. Also, the oracle value of this asset
// is set to the target price, to not be open to direct arbitrage
ratio = BASE_18;
if (oracleValue * BASE_18 < targetPrice * (BASE_18 - burnRatioDeviation)) {
ratio = (oracleValue * BASE_18) / targetPrice;
} else if (oracleValue < targetPrice) {
oracleValue = targetPrice;
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Internal version of the `getOracle` function
function getOracle(address collateral)
internal
view
returns (OracleReadType, OracleReadType, bytes memory, bytes memory, bytes memory)
{
return _parseOracleConfig(s.transmuterStorage().collaterals[collateral].oracleConfig);
}
/// @notice Gets the oracle value and the ratio with respect to the target price when it comes to
/// burning for `collateral`
function getBurnOracle(
address collateral,
bytes memory oracleConfig
)
internal
view
returns (uint256 minRatio, uint256 oracleValue)
{
ParallelizerStorage storage ts = s.transmuterStorage();
minRatio = BASE_18;
address[] memory collateralList = ts.collateralList;
uint256 length = collateralList.length;
for (uint256 i; i < length; ++i) {
uint256 ratioObserved = BASE_18;
if (collateralList[i] != collateral) {
(, ratioObserved) = readBurn(ts.collaterals[collateralList[i]].oracleConfig);
} else {
(oracleValue, ratioObserved) = readBurn(oracleConfig);
}
if (ratioObserved < minRatio) minRatio = ratioObserved;
}
}
/// @notice Computes the `quoteAmount` (for Chainlink oracles) depending on a `quoteType` and a base value
/// (e.g the target price of the asset)
/// @dev For cases where the Chainlink feed directly looks into the value of the asset, `quoteAmount` is `BASE_18`.
/// For others, like wstETH for which Chainlink only has an oracle for stETH, `quoteAmount` is the target price
function quoteAmount(OracleQuoteType quoteType, uint256 baseValue) internal pure returns (uint256) {
if (quoteType == OracleQuoteType.UNIT) return BASE_18;
else return baseValue;
}
function readSpotAndTarget(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
uint256 deviation
)
internal
view
returns (uint256 oracleValue, uint256 targetPrice)
{
targetPrice = read(targetType, BASE_18, targetData);
oracleValue = read(oracleType, targetPrice, oracleData);
// System may tolerate small deviations from target
// If the oracle value reported is reasonably close to the target
// --> disregard the oracle value and return the target price
if (
targetPrice * (BASE_18 - deviation) < oracleValue * BASE_18
&& oracleValue * BASE_18 < targetPrice * (BASE_18 + deviation)
) oracleValue = targetPrice;
}
/// @notice Reads an oracle value (or a target oracle value) for an asset based on its data parsed `oracleConfig`
function read(OracleReadType readType, uint256 baseValue, bytes memory data) internal view returns (uint256) {
if (readType == OracleReadType.CHAINLINK_FEEDS) {
(
AggregatorV3Interface[] memory circuitChainlink,
uint32[] memory stalePeriods,
uint8[] memory circuitChainIsMultiplied,
uint8[] memory chainlinkDecimals,
OracleQuoteType quoteType
) = abi.decode(data, (AggregatorV3Interface[], uint32[], uint8[], uint8[], OracleQuoteType));
uint256 quotePrice = quoteAmount(quoteType, baseValue);
uint256 listLength = circuitChainlink.length;
for (uint256 i; i < listLength; ++i) {
quotePrice = readChainlinkFeed(
quotePrice, circuitChainlink[i], circuitChainIsMultiplied[i], chainlinkDecimals[i], stalePeriods[i]
);
}
return quotePrice;
} else if (readType == OracleReadType.STABLE) {
return BASE_18;
} else if (readType == OracleReadType.NO_ORACLE) {
return baseValue;
} else if (readType == OracleReadType.WSTETH) {
return STETH.getPooledEthByShares(1 ether);
} else if (readType == OracleReadType.CBETH) {
return CBETH.exchangeRate();
} else if (readType == OracleReadType.RETH) {
return RETH.getExchangeRate();
} else if (readType == OracleReadType.SFRXETH) {
return SFRXETH.pricePerShare();
} else if (readType == OracleReadType.MAX) {
uint256 maxValue = abi.decode(data, (uint256));
return maxValue;
} else if (readType == OracleReadType.MORPHO_ORACLE) {
(address contractAddress, uint256 normalizationFactor) = abi.decode(data, (address, uint256));
return IMorphoOracle(contractAddress).price() / normalizationFactor;
}
// If the `OracleReadType` is `EXTERNAL`, it means that this function is called to compute a
// `targetPrice` in which case the `baseValue` is returned here
else {
return baseValue;
}
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SPECIFIC HELPERS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @notice Reads a Chainlink feed using a quote amount and converts the quote amount to the out-currency
/// @param _quoteAmount The amount for which to compute the price expressed in `BASE_18`
/// @param feed Chainlink feed to query
/// @param multiplied Whether the ratio outputted by Chainlink should be multiplied or divided to the `quoteAmount`
/// @param decimals Number of decimals of the corresponding Chainlink pair
/// @return The `quoteAmount` converted in out-currency
function readChainlinkFeed(
uint256 _quoteAmount,
AggregatorV3Interface feed,
uint8 multiplied,
uint256 decimals,
uint32 stalePeriod
)
internal
view
returns (uint256)
{
(, int256 ratio,, uint256 updatedAt,) = feed.latestRoundData();
if (ratio <= 0 || block.timestamp - updatedAt > stalePeriod) revert InvalidChainlinkRate();
// Checking whether we should multiply or divide by the ratio computed
if (multiplied == 1) return (_quoteAmount * uint256(ratio)) / (10 ** decimals);
else return (_quoteAmount * (10 ** decimals)) / uint256(ratio);
}
/// @notice Parses an `oracleConfig` into several sub fields
function _parseOracleConfig(bytes memory oracleConfig)
private
pure
returns (OracleReadType, OracleReadType, bytes memory, bytes memory, bytes memory)
{
return abi.decode(oracleConfig, (OracleReadType, OracleReadType, bytes, bytes, bytes));
}
function updateOracle(address collateral) internal {
ParallelizerStorage storage ts = s.transmuterStorage();
if (ts.collaterals[collateral].decimals == 0) revert NotCollateral();
(
OracleReadType oracleType,
OracleReadType targetType,
bytes memory oracleData,
bytes memory targetData,
bytes memory hyperparameters
) = _parseOracleConfig(ts.collaterals[collateral].oracleConfig);
if (targetType != OracleReadType.MAX) revert OracleUpdateFailed();
uint256 oracleValue = read(oracleType, BASE_18, oracleData);
uint256 maxValue = abi.decode(targetData, (uint256));
if (oracleValue > maxValue) {
ts.collaterals[collateral].oracleConfig = abi.encode(
oracleType,
targetType,
oracleData,
// There are no checks whether the value increased or not
abi.encode(oracleValue),
hyperparameters
);
} else {
revert OracleUpdateFailed();
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import "../../utils/Constants.sol";
import { DiamondStorage, ImplementationStorage, ParallelizerStorage } from "../Storage.sol";
/// @title LibStorage
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibStorage` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibStorage.sol
library LibStorage {
/// @notice Returns the storage struct stored at the `DIAMOND_STORAGE_POSITION` slot
/// @dev This struct handles the logic of the different facets used in the diamond proxy
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly ("memory-safe") {
ds.slot := position
}
}
/// @notice Returns the storage struct stored at the `TRANSMUTER_STORAGE_POSITION` slot
/// @dev This struct handles the particular logic of the Parallelizer system
function transmuterStorage() internal pure returns (ParallelizerStorage storage ts) {
bytes32 position = TRANSMUTER_STORAGE_POSITION;
assembly ("memory-safe") {
ts.slot := position
}
}
/// @notice Returns the storage struct stored at the `IMPLEMENTATION_STORAGE_POSITION` slot
/// @dev This struct handles the logic for making the contract easily usable on Etherscan
function implementationStorage() internal pure returns (ImplementationStorage storage ims) {
bytes32 position = IMPLEMENTATION_STORAGE_POSITION;
assembly ("memory-safe") {
ims.slot := position
}
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { IKeyringGuard } from "contracts/interfaces/external/keyring/IKeyringGuard.sol";
import { LibStorage as s } from "./LibStorage.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";
/// @title LibWhitelist
/// @author Cooper Labs
/// @custom:contact [email protected]
/// @dev This library is an authorized fork of Angle's `LibWhitelist` library
/// https://github.com/AngleProtocol/angle-transmuter/blob/main/contracts/parallelizer/libraries/LibWhitelist.sol
library LibWhitelist {
/// @notice Checks whether `sender` is whitelisted for a collateral with `whitelistData`
function checkWhitelist(bytes memory whitelistData, address sender) internal returns (bool) {
(WhitelistType whitelistType, bytes memory data) = abi.decode(whitelistData, (WhitelistType, bytes));
if (s.transmuterStorage().isWhitelistedForType[whitelistType][sender] > 0) return true;
if (data.length != 0) {
if (whitelistType == WhitelistType.BACKED) {
address keyringGuard = abi.decode(data, (address));
if (keyringGuard != address(0)) return IKeyringGuard(keyringGuard).isAuthorized(address(this), sender);
}
}
return false;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import { ICbETH } from "contracts/interfaces/external/coinbase/ICbETH.sol";
import { ISfrxETH } from "contracts/interfaces/external/frax/ISfrxETH.sol";
import { IStETH } from "contracts/interfaces/external/lido/IStETH.sol";
import { IRETH } from "contracts/interfaces/external/rocketPool/IRETH.sol";
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
STORAGE SLOTS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/// @dev Storage position of `DiamondStorage` structure
/// @dev Equals `keccak256("diamond.standard.diamond.storage") - 1`
bytes32 constant DIAMOND_STORAGE_POSITION = 0xc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131b;
/// @dev Storage position of `ParallelizerStorage` structure
/// @dev Equals `keccak256("diamond.standard.parallelizer.storage") - 1`
bytes32 constant TRANSMUTER_STORAGE_POSITION = 0x4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c75;
/// @dev Storage position of `ImplementationStorage` structure
/// @dev Equals `keccak256("eip1967.proxy.implementation") - 1`
bytes32 constant IMPLEMENTATION_STORAGE_POSITION = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
MATHS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
uint256 constant BASE_6 = 1e6;
uint256 constant BASE_8 = 1e8;
uint256 constant BASE_9 = 1e9;
uint256 constant BASE_12 = 1e12;
uint256 constant BPS = 1e14;
uint256 constant BASE_18 = 1e18;
uint256 constant HALF_BASE_27 = 1e27 / 2;
uint256 constant BASE_27 = 1e27;
uint256 constant BASE_36 = 1e36;
uint256 constant MAX_BURN_FEE = 999_000_000;
uint256 constant MAX_MINT_FEE = BASE_12 - 1;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
REENTRANT
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint8 constant NOT_ENTERED = 1;
uint8 constant ENTERED = 2;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
REENTRANT
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
// Role IDs for the AccessManager
uint64 constant GOVERNOR_ROLE = 10;
uint64 constant GUARDIAN_ROLE = 20;
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
COMMON ADDRESSES
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
address constant PERMIT_2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
address constant ODOS_ROUTER = 0xCf5540fFFCdC3d510B18bFcA6d2b9987b0772559;
ICbETH constant CBETH = ICbETH(0xBe9895146f7AF43049ca1c1AE358B0541Ea49704);
IRETH constant RETH = IRETH(0xae78736Cd615f374D3085123A210448E74Fc6393);
IStETH constant STETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
ISfrxETH constant SFRXETH = ISfrxETH(0xac3E018457B222d93114458476f3E3416Abbe38F);
address constant XEVT = 0x3Ee320c9F73a84D1717557af00695A34b26d1F1d;
address constant USDM = 0x59D9356E565Ab3A36dD77763Fc0d87fEaf85508C;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant EURC = 0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c;// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.28; error AccessManagedUnauthorized(address caller); error AlreadyAdded(); error CannotAddFunctionToDiamondThatAlreadyExists(bytes4 _selector); error CannotAddSelectorsToZeroAddress(bytes4[] _selectors); error CannotRemoveFunctionThatDoesNotExist(bytes4 _selector); error CannotRemoveImmutableFunction(bytes4 _selector); error CannotReplaceFunctionsFromFacetWithZeroAddress(bytes4[] _selectors); error CannotReplaceFunctionThatDoesNotExists(bytes4 _selector); error CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(bytes4 _selector); error CannotReplaceImmutableFunction(bytes4 _selector); error ContractHasNoCode(); error CollateralBacked(); error FunctionNotFound(bytes4 _functionSelector); error IncorrectFacetCutAction(uint8 _action); error InitializationFunctionReverted(address _initializationContractAddress, bytes _calldata); error InvalidChainlinkRate(); error InvalidLengths(); error InvalidNegativeFees(); error InvalidOracleType(); error InvalidParam(); error InvalidParams(); error InvalidRate(); error InvalidSwap(); error InvalidTokens(); error InvalidAccessManager(); error ManagerHasAssets(); error NoSelectorsProvidedForFacetForCut(address _facetAddress); error NotAllowed(); error NotCollateral(); error NotGovernor(); error NotGuardian(); error NotTrusted(); error NotTrustedOrGuardian(); error NotWhitelisted(); error OdosSwapFailed(); error OracleUpdateFailed(); error Paused(); error ReentrantCall(); error RemoveFacetAddressMustBeZeroAddress(address _facetAddress); error TooBigAmountIn(); error TooLate(); error TooSmallAmountOut(); error ZeroAddress(); error ZeroAmount(); error SwapError(); error SlippageTooHigh(); error InsufficientFunds();
{
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": [],
"viaIR": true,
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[],"name":"FailedCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidChainlinkRate","type":"error"},{"inputs":[],"name":"InvalidSwap","type":"error"},{"inputs":[],"name":"InvalidTokens","type":"error"},{"inputs":[],"name":"NotWhitelisted","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"inputs":[],"name":"ReentrantCall","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"TooBigAmountIn","type":"error"},{"inputs":[],"name":"TooLate","type":"error"},{"inputs":[],"name":"TooSmallAmountOut","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"Swap","type":"event"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"}],"name":"quoteIn","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"}],"name":"quoteOut","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"permitData","type":"bytes"}],"name":"swapExactInputWithPermit","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactOutput","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountInMax","type":"uint256"},{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"permitData","type":"bytes"}],"name":"swapExactOutputWithPermit","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60808060405234601557615802908161001a8239f35b5f80fdfe60806040526004361015610011575f80fd5b5f5f3560e01c80633b6a1fe014610ef15780634583aea614610e865780639525f3ab14610e6c578063b92567fa146107d6578063c10a62871461046a5763d92c6cb21461005c575f80fd5b346103195761006a3661164d565b61007982859697949895611c02565b91909261008685846119cd565b97881061045b5761009b918391888780611cb1565b600260ff5f51602061578d5f395f51905f525460a81c161461044c576100e7600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b83151580610443575b610130575b602087610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b604051908152f35b61015361014e5f5160206157ad5f395f51905f525460801c8961428c565b614242565b6001600160801b03835460281c91168091016001600160d81b03811161042f57835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546101b18160801c86611b26565b16016001600160801b03811161041b57610202906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b80518590156103cd578082602061025694519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d9061023a82611632565b916102486040519384611611565b82523d87602084013e61557e565b505b60ff815416610327575b506001600160a01b031691823b15610319576040516340c10f1960e01b81526001600160a01b038716600482015260248101869052818160448183885af1801561031c57610304575b50506001600160a01b0360209560405192835285878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0333951692a45f80808080806100f5565b61030f828092611611565b61031957806102ab565b80fd5b6040513d84823e3d90fd5b610336600861033b920161188c565b614bda565b90610345816140bf565b61026257610364816020806001600160a01b0394518301019101613f85565b16803b156103c1578380916024604051809481936255f9e960e71b83528860048401525af180156103b65790849161039d575b50610262565b816103a791611611565b6103b257825f610397565b8280fd5b6040513d86823e3d90fd5b8380fd5b60609061557e565b5050805460ff161561040657610401836103f16103ec6008850161188c565b6143da565b336001600160a01b038916614378565b610258565b6104018330336001600160a01b038916614378565b602486634e487b7160e01b81526011600452fd5b602487634e487b7160e01b81526011600452fd5b508615156100f0565b6004856306fda65d60e31b8152fd5b60048663a1aabbe160e01b8152fd5b5034610319576104793661164d565b61048882859697949895611c02565b9190926104958584611bb8565b978089116107c757918391886104ab948b611cb1565b600260ff5f51602061578d5f395f51905f525460a81c161461044c576104f7600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b861515806107be575b61053757602087610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b61055561014e5f5160206157ad5f395f51905f525460801c8661428c565b6001600160801b03835460281c91168091016001600160d81b03811161042f57835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546105b38160801c86611b26565b16016001600160801b03811161041b57610604906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b8051859015610785578082602061063c94519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d9061023a82611632565b505b60ff8154166106ff575b506001600160a01b031691823b15610319576040516340c10f1960e01b81526001600160a01b038716600482015260248101839052818160448183885af1801561031c576106ea575b50506001600160a01b0360209560405192868452878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0333951692a45f80808080806100f5565b6106f5828092611611565b6103195780610691565b610336600861070e920161188c565b90610718816140bf565b61064857610737816020806001600160a01b0394518301019101613f85565b16803b156103c1578380916024604051809481936255f9e960e71b83528b60048401525af180156103b657908491610770575b50610648565b8161077a91611611565b6103b257825f61076a565b5050805460ff16156107a9576107a4866103f16103ec6008850161188c565b61063e565b6107a48630336001600160a01b038916614378565b50831515610500565b6004876328ac195d60e21b8152fd5b5034610319576107f56107e83661151b565b8284959792939694611739565b9096908715610e5b576108088482611bb8565b965b8711610e4c576040516020986108208a83611611565b838252600260ff5f51602061578d5f395f51905f525460a81c1614610e3d5761086f600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b881590811580610e34575b6108b1575b8a8a610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b15610b8d57506108d561014e5f5160206157ad5f395f51905f525460801c8761428c565b6001600160801b03835460281c91168091016001600160d81b038111610b7957835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546109338160801c86611b26565b16016001600160801b038111610b6557610984906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b8051839015610b2c5780828b6109d694519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d906109bb82611632565b916109c96040519384611611565b82523d858c84013e61557e565b505b60ff815416610aa7575b506001600160a01b038516803b15610aa3576040516340c10f1960e01b81526001600160a01b0384166004820152602481018590529082908290604490829084905af1801561031c57610a8e575b50506001600160a01b03905b60405192868452878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0380339616941692a45f808080808080808061087f565b610a99828092611611565b6103195780610a30565b5080fd5b6103366008610ab6920161188c565b90610ac0816140bf565b6109e257610ade8189806001600160a01b0394518301019101613f85565b16803b15610aa3578180916024604051809481936255f9e960e71b83528c60048401525af1801561031c57908291610b17575b506109e2565b81610b2191611611565b61031957805f610b11565b5050805460ff1615610b5057610b4b876103f16103ec6008850161188c565b6109d8565b610b4b8730336001600160a01b038916614378565b602484634e487b7160e01b81526011600452fd5b602485634e487b7160e01b81526011600452fd5b905060ff82548a1c16151580610e18575b610e09576b033b2e3c9fd0803ce80000008802908882046b033b2e3c9fd0803ce8000000141715610df55761014e610be8915f5160206157ad5f395f51905f525460801c9061196b565b6001600160801b03825460281c91168091036001600160d81b038111610b6557825464ffffffffff1660289190911b64ffffffffff19161782556001600160801b035f5160206157ad5f395f51905f525416036001600160801b038111610df557610c8a906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b6001600160a01b038516803b156103b2578280916044604051809481936315a38ec760e11b83528d60048401523360248401525af18015610dea57908391610dd5575b5050805460ff1615610d83576103366008610ce8920161188c565b90610cf2816140bf565b15610d08575b50506001600160a01b0390610a3c565b610d228189806001600160a01b0394518301019101613f85565b16803b15610aa357604051638bfb07c960e01b81526001600160a01b03878116600483015284166024820152604481018590529082908290606490829084905af1801561031c5715610cf857610d79828092611611565b6103195780610cf8565b505060405163a9059cbb60e01b878201526001600160a01b038281166024830152604482018490529190610dd090610dc881606481015b03601f198101835282611611565b838716614b6d565b610a3c565b81610ddf91611611565b610aa357815f610ccd565b6040513d85823e3d90fd5b602483634e487b7160e01b81526011600452fd5b600483630b094f2760e31b8152fd5b50610e2e84610e296006850161188c565b6140dd565b15610b9e565b5086151561087a565b6004846306fda65d60e31b8152fd5b6004826328ac195d60e21b8152fd5b610e66848288611b82565b9661080a565b5034610319576020610128610e8036611571565b916116e9565b503461031957610ea7602091610e9b36611571565b93919250834291611739565b929015610ed65750610ebc61012891836119cd565b91825f5160206157ad5f395f51905f525460801c91611b4f565b610ee4610eec928483611989565b928391611a0e565b610128565b50346114a557610f036107e83661151b565b909690871561150a57610f1684826119cd565b965b87106114fb57604051602098610f2e8a83611611565b5f8252600260ff5f51602061578d5f395f51905f525460a81c16146114ec57610f7d600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b8515908115806114e3575b610fbe578a8a610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b156112535750610fe261014e5f5160206157ad5f395f51905f525460801c8a61428c565b6001600160801b03835460281c91168091016001600160d81b038111610b7957835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546110408160801c86611b26565b16016001600160801b038111610b6557611091906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b805183901561121a5780828b6110c894519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d906109bb82611632565b505b60ff815416611195575b506001600160a01b038516803b15610aa3576040516340c10f1960e01b81526001600160a01b0384166004820152602481018890529082908290604490829084905af1801561031c57611180575b50506001600160a01b03905b60405192835285878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0380339616941692a45f808080808080808061087f565b61118b828092611611565b6103195780611122565b61033660086111a4920161188c565b906111ae816140bf565b6110d4576111cc8189806001600160a01b0394518301019101613f85565b16803b15610aa3578180916024604051809481936255f9e960e71b83528960048401525af1801561031c57908291611205575b506110d4565b8161120f91611611565b61031957805f6111ff565b5050805460ff161561123e57611239846103f16103ec6008850161188c565b6110ca565b6112398430336001600160a01b038916614378565b905060ff82548a1c161515806114cc575b6114bd576b033b2e3c9fd0803ce80000008502908582046b033b2e3c9fd0803ce80000001417156114a95761014e6112ae915f5160206157ad5f395f51905f525460801c9061196b565b6001600160801b03825460281c91168091036001600160d81b0381116114a957825464ffffffffff1660289190911b64ffffffffff19161782556001600160801b035f5160206157ad5f395f51905f525416036001600160801b0381116114a957611350906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b6001600160a01b038516803b156114a5575f80916044604051809481936315a38ec760e11b83528a60048401523360248401525af1801561149a57611485575b50805460ff16156114455761033660086113aa920161188c565b906113b4816140bf565b156113ca575b50506001600160a01b039061112e565b6113e48189806001600160a01b0394518301019101613f85565b16803b15610aa357604051638bfb07c960e01b81526001600160a01b03878116600483015284166024820152604481018890529082908290606490829084905af1801561031c57156113ba5761143b828092611611565b61031957806113ba565b505060405163a9059cbb60e01b878201526001600160a01b03828116602483015260448201879052919061148090610dc88160648101610dba565b61112e565b6114929192505f90611611565b5f905f611390565b6040513d5f823e3d90fd5b5f80fd5b634e487b7160e01b5f52601160045260245ffd5b630b094f2760e31b5f5260045ffd5b506114dd84610e296006850161188c565b15611264565b50891515610f88565b6306fda65d60e31b5f5260045ffd5b63a1aabbe160e01b5f5260045ffd5b611515848288611989565b96610f18565b60c09060031901126114a55760043590602435906044356001600160a01b03811681036114a557906064356001600160a01b03811681036114a557906084356001600160a01b03811681036114a5579060a43590565b60609060031901126114a557600435906024356001600160a01b03811681036114a557906044356001600160a01b03811681036114a55790565b606081019081106001600160401b038211176115c657604052565b634e487b7160e01b5f52604160045260245ffd5b604081019081106001600160401b038211176115c657604052565b61012081019081106001600160401b038211176115c657604052565b90601f801991011681019081106001600160401b038211176115c657604052565b6001600160401b0381116115c657601f01601f191660200190565b9060c06003198301126114a55760043591602435916044356001600160a01b03811681036114a557916064356001600160a01b03811681036114a557916084359160a4356001600160401b0381116114a557816023820112156114a5578060040135906116b982611632565b926116c76040519485611611565b828452602483830101116114a557815f92602460209301838601378301015290565b906116f690834291611739565b901561172557611722925061171d5f5160206157ad5f395f51905f525460801c8383611b4f565b611bb8565b90565b82611734838361172296611a0e565b611b82565b914211611864576001600160a01b035f51602061578d5f395f51905f525416806001600160a01b038416145f146117df57506117a691506001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815460101c16156117b7575f91565b7f9e87fac8000000000000000000000000000000000000000000000000000000005f5260045ffd5b906001600160a01b0316145f1461183c5761182a906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815460081c16156117b757600191565b7f672215de000000000000000000000000000000000000000000000000000000005f5260045ffd5b7fecdd1c29000000000000000000000000000000000000000000000000000000005f5260045ffd5b90604051915f8154908160011c926001831692831561194e575b60208510841461193a57848752869390811561191857506001146118d4575b506118d292500383611611565b565b90505f9291925260205f20905f915b8183106118fc5750509060206118d2928201015f6118c5565b60209193508060019154838589010152019101909184926118e3565b9050602092506118d294915060ff191682840152151560051b8201015f6118c5565b634e487b7160e01b5f52602260045260245ffd5b93607f16936118a6565b818102929181159184041417156114a957565b8115611975570490565b634e487b7160e01b5f52601260045260245ffd5b6119c16119b76119bc611722956119ae60ff956119a86005890161188c565b90611e80565b93909187612186565b611958565b61196b565b915460181c1690613eff565b906119e6906119b76119e16005850161188c565b613fd9565b9060ff815460181c166012019160ff83116114a95761172292611a0891613f4a565b906129d5565b909160ff835416159182159384611af9575b508315611a59575b505050611a3157565b7f11157667000000000000000000000000000000000000000000000000000000005f5260045ffd5b9192509082611a6d575b50505f8080611a28565b6001600160a01b039192506020906024604051809481937f70a08231000000000000000000000000000000000000000000000000000000008352306004840152165afa90811561149a575f91611ac7575b50105f80611a63565b90506020813d602011611af1575b81611ae260209383611611565b810103126114a557515f611abe565b3d9150611ad5565b82919450611b0c6008611b11920161188c565b61441f565b10925f611a20565b919082018092116114a957565b906b033b2e3c9fd0803ce8000000611b44600992845460281c611958565b0491015410611a3157565b916009916b033b2e3c9fd0803ce8000000611b71611b7893865460281c611958565b0490611b19565b91015410611a3157565b61172292611bad611b9c611bb2936119a86005870161188c565b91909260ff865460181c1690613f4a565b61449b565b90613186565b611bd1611bca6119e16005840161188c565b92826137dd565b91670de0b6b3a7640000830292808404670de0b6b3a764000014901517156114a9576119c160ff916117229461196b565b90421161186457611c43906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815460081c16156117b7576001600160a01b035f51602061578d5f395f51905f52541691565b81601f820112156114a557805190611c8282611632565b92611c906040519485611611565b828452602083830101116114a557815f9260208093018386015e8301015290565b9492909360405190611cc2826115ab565b5f825260208201965f885260408301956060875260ff81541615155f14611e4f57611cfa6103ec60086001600160a01b03930161188c565b1683525b81518201936040838603126114a5576020830151966040840151956001600160401b0387116114a557611de99a6117229a6101449a611d51611e10986020809c816001600160a01b039801920101611c6b565b85528252826040519a611d638c6115da565b168a52888a0152519560405198611d798a6115ab565b89528789019687526040890193845251169260405193611d98856115da565b8452868401525193604051998a977f30f28b7a00000000000000000000000000000000000000000000000000000000888a0152602489019051602080916001600160a01b0381511684520151910152565b51606487015251608486015280516001600160a01b031660a48601526020015160c4850152565b3360e4840152610100610104840152805191829182610124860152018484015e5f838284010152601f801991011681010301601f198101835282611611565b50308352611cfe565b8051821015611e6c5760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b90915f91670de0b6b3a76400009360405190818260207f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775492838152017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775f5260205f20925f5b818110611fc2575050611efc92500383611611565b8151925f5b848110611f0f575050505050565b6001600160a01b03611f218286611e58565b51166001600160a01b03831614611faf57611f92611f8d6005611f876001600160a01b03611f4f868a611e58565b51166001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b0161188c565b614538565b90505b888110611fa6575b50600101611f01565b97506001611f9d565b9550611fba82614538565b969096611f95565b84546001600160a01b0316835260019485019487945060209093019201611ee7565b805415611e6c575f5260205f20905f90565b9190918054831015611e6c575f52601860205f208360021c019260031b1690565b919082039182116114a957565b905f82633b9aca00039212633b9aca008312811690633b9aca008413901516176114a957565b90633b9ac9ff1982019182136001166114a957565b81810392915f1380158285131691841216176114a957565b90633b9aca008201915f633b9aca00841291129080158216911516176114a957565b9081633b9aca00019182126001166114a957565b9190915f83820193841291129080158216911516176114a957565b5f908015612180578080600114612178576002146121715760016101338210166001600b83101617612163579060019060025b600181116121275750825f1904821161211357500290565b80634e487b7160e01b602492526011600452fd5b92805f1904811161214f5760018416612146575b80029260011c6120fb565b8092029161213b565b602482634e487b7160e01b81526011600452fd5b6002900a9190806121135750565b5050600490565b505050600190565b50505f90565b9060405190612194826115f5565b5f82525f60208301525f60408301525f60608301525f60808301525f60a08301525f60c08301525f60e08301525f6101008301526004600210156125a2575f80835260016020840181905290929091906129ca565b5f5160206157ad5f395f51905f5254946001600160801b0386161580156129c1575b6129985750855460281c80670de0b6b3a7640000810204670de0b6b3a764000014811517156114a9576b033b2e3c9fd0803ce800000061228c612298926001600160801b036001600160401b0361226e828c16670de0b6b3a7640000850261196b565b16998461227f8260801c8095611958565b0460e08901521690611958565b0460e084015190612017565b6101008301525f9482511515805f1461298c578288018392915b6040519182602082549182815201915f5260205f20905f915b8160038401106129485794809387959361230d936123129854918b82821061292f575b828210612912575b8282106128f5575b50106128e7575b500383611611565b6147e4565b915b612389575b5050905115905061235b575f1982019182116114a9576123426123559260026117229601611ff6565b90549060031b1c60070b905b6002614690565b90611b19565b5f1982019182116114a9576123796123559260046117229601611ff6565b90549060031b1c60070b9061234e565b91969094915f1983018381116114a9578610156128dc57835115612828578782016001600160401b036123bc8883611ff6565b90549060031b1c1660408601528887018088116114a9576001600160401b036123e88261241794611ff6565b90549060031b1c166060870152600284016124038982611ff6565b90549060031b1c60070b6080880152611ff6565b90549060031b1c60070b60a085015261243a610100850151606086015190611958565b6060850151633b9aca000390633b9aca0082116114a9576124699161245e9161196b565b60e086015190612017565b60c08501525b6040840151633b9aca00810290808204633b9aca0014901517156114a9570361274c576080830151945b60208401511561270a5760c0840151925b8584106126205750505060208201518490156125075760a06124ce9293015161205f565b926001600160ff1b03821682036114a9576124f6612355946124fc93611722981b908561430c565b906120ad565b60070b906002614690565b50506001600160ff1b03821682036114a95761254061253561252d8560a085015161205f565b84881b611958565b60c0830151906142c5565b9051156125b6576125619061255c61255785612099565b6120c8565b611b19565b61256a81614c20565b9060048610156125a2576125936123559460029361259893896117229a505081800210016120ad565b61204a565b0560070b9061234e565b634e487b7160e01b5f52602160045260245ffd5b9093506125c561255783612024565b90808210156125e257505061172292600261259861235593612077565b6125f9906125f36125fe9394612077565b93612017565b614c20565b92612617612612611722956123559461205f565b6142ee565b60070b9061234e565b959461264d92989361263491989298612017565b946020850151155f146126b8575060c084015190611b19565b946060830151633b9aca00810290808204633b9aca0014901517156114a957905f1981146114a957835190830191901561269f578261269560e086015160c087015190611b19565b60e0860152612314565b826126b360e086015160c087015190612017565b612695565b8451156126e2576123559060026126d860c08801519260a08901516120ad565b60070b05906149cf565b6127059060026126fb60c08801519260a08901516120ad565b60070b0590614963565b612355565b83511561272f5761272960c085015160026126d88960a08901516120ad565b926124aa565b61274760c085015160026126fb8960a08901516120ad565b612729565b608083015160a08401510361276657608083015194612499565b8251156127e95760e0830151612786610100850151604086015190611958565b906040850151633b9aca000390633b9aca0082116114a9576127ae6127b4926127e39461196b565b90612017565b6124f66080860151916127dd6127d2826119b78660a08c015161205f565b9160c0890151611b19565b9061196b565b94612499565b6127fd610100840151604085015190611958565b6040840151633b9aca0003633b9aca0081116114a95761245e612823916127e39361196b565b6127b4565b600382016001600160401b0361283e8883611ff6565b90549060031b1c1660408601528887018088116114a9576001600160401b0361286a8261288594611ff6565b90549060031b1c166060870152600484016124038982611ff6565b90549060031b1c60070b60a085015260e08401516128ad610100860151606087015190611958565b906060860151633b9aca000391633b9aca0083116114a9576128d2926127ae9161196b565b60c085015261246f565b819750829550612319565b60c01c81526020015f612305565b90936020906001600160401b038560801c1681520193018b6122fe565b90936020906001600160401b038560401c1681520193018b6122f6565b6001600160401b0384168552602090940193018b6122ee565b80546001600160401b038082168652604082811c82166020880152608083811c9092169087015260c09190911c6060860152899894019360049390930192016122cb565b600388018392916122b2565b92945050506117229391505f146129b55760026123429101611fe4565b60046123799101611fe4565b5081851461220b565b6003850154926121e9565b604051916129e2836115f5565b5f83525f60208401525f60408401525f60608401525f60808401525f60a08401525f60c08401525f60e08401525f61010084015260045f10156125a25760018084525f6020850152906001830154915f5160206157ad5f395f51905f5254906001600160801b038216908115801561317c575b6131535750845460281c670de0b6b3a76400008102818104670de0b6b3a764000014821517156114a957826b033b2e3c9fd0803ce80000009283612ab66001600160401b03612aaa612acd98612ac19761196b565b169760801c8093611958565b0460e08b0152611958565b0460e087015190612017565b6101008601525f9385511515805f146131495782600183015b604051928391602081549586815201905f5260205f20945f955b8160038801106130f35791612b4196859261230d9454918181106130d9575b8181106130bc575b81811061309f575b10613091575b509b97999b0383611611565b935b5f1987018781116114a95785101561302857825115612f7357600182016001600160401b03612b728783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612b9f82612bce94611ff6565b90549060031b1c16606086015260028401612bba8882611ff6565b90549060031b1c60070b6080870152611ff6565b90549060031b1c60070b60a0840152612bf1610100840151606085015190611958565b6060840151633b9aca000390633b9aca0082116114a957612c2091612c159161196b565b60e085015190612017565b60c08401525b604083015180633b9aca00810204633b9aca0014811517156114a957633b9aca000203612ea3576080820151955b602083015115612e615760c0830151945b848610612d8f57505050602081015185919015612cbe579060a0612c8a92015161205f565b6001600160ff1b03831683036114a957611722946124f6612cb3926123559560011b908561430c565b60070b905b5f614690565b919250506001600160ff1b03821682036114a957612cef612535612ce68660a085015161205f565b8460011b611958565b905115612d3657612d069061255c61255786612099565b90612d1082614c20565b93612d2c612593600292611722976123559681800210016120ad565b0560070b90612cb8565b612d44612557859395612024565b9080821015612d61575050611722926002612d2c61235593612077565b6125f9906125f3612d729394612077565b92612d86612612611722956123559461205f565b60070b90612cb8565b929693612dbb92969195612da291612017565b936020880151155f14612e28575060c087015190611b19565b936060860151633b9aca00810290808204633b9aca0014901517156114a957915f1981146114a95760010193865115155f14612e1057612e0460e088015160c089015190611b19565b60e08801529591612b43565b612e2360e088015160c089015190612017565b612e04565b875115612e48576123559060026126d860c08b01519260a08c01516120ad565b6127059060026126fb60c08b01519260a08c01516120ad565b825115612e8657612e8060c084015160026126d88a60a08801516120ad565b94612c65565b612e9e60c084015160026126fb8a60a08801516120ad565b612e80565b608082015160a083015103612ebd57608082015195612c54565b815115612f345760e0820151612edd610100840151604085015190611958565b906040840151633b9aca000390633b9aca0082116114a9576127ae612f0592612f2e9461196b565b6124f66080850151916127dd612f23826119b78660a08b015161205f565b9160c0880151611b19565b95612c54565b612f48610100830151604084015190611958565b6040830151633b9aca0003633b9aca0081116114a957612c15612f6e91612f2e9361196b565b612f05565b600382016001600160401b03612f898783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612fb682612fd194611ff6565b90549060031b1c16606086015260048401612bba8882611ff6565b90549060031b1c60070b60a084015260e0830151612ff9610100850151606086015190611958565b906060850151633b9aca000391633b9aca0083116114a95761301e926127ae9161196b565b60c0840152612c26565b5090519094925015613063575f1982019182116114a9576130526123559260026117229601611ff6565b90549060031b1c60070b905f614690565b5f1982019182116114a9576130816123559260046117229601611ff6565b90549060031b1c60070b90612cb8565b60c01c81526020015f612b35565b9260206001916001600160401b038560801c168152019301612b2f565b9260206001916001600160401b038560401c168152019301612b27565b9260206001916001600160401b0385168152019301612b1f565b9395929450906001608060049286546001600160401b03811682526001600160401b038160401c1660208301526001600160401b0381841c16604083015260c01c60608201520194019201949290879492612b00565b8260038301612ae6565b92949350505061172293505f146131705760026130529101611fe4565b60046130819101611fe4565b5060018514612a55565b60405191613193836115f5565b5f83525f60208401525f60408401525f60608401525f60808401525f60a08401525f60c08401525f60e08401525f6101008401526004600310156125a2575f80845260208401819052906137d2565b5f5160206157ad5f395f51905f5254906001600160801b03821690811580156137c8575b61379f5750845460281c670de0b6b3a76400008102818104670de0b6b3a764000014821517156114a957826b033b2e3c9fd0803ce80000009283612ab66001600160401b03612aaa61325b98612ac19761196b565b6101008601525f9385511515805f146137955782600183015b604051928391602081549586815201905f5260205f20945f955b81600388011061373f57916132cb96859261230d9454918181106130d9578181106130bc5781811061309f571061309157509b97999b0383611611565b935b5f1987018781116114a9578510156136d55782511561363b57600182016001600160401b036132fc8783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612b9f8261332994611ff6565b90549060031b1c60070b60a084015261334c610100840151606085015190611958565b6060840151633b9aca000390633b9aca0082116114a95761337091612c159161196b565b60c08401525b604083015180633b9aca00810204633b9aca0014811517156114a957633b9aca000203613599576080820151955b6020830151156135575760c0830151945b8486106134d75750505060208101518591901561340f579060a06133da92015161205f565b6001600160ff1b03831683036114a957611722946124f6613403926123559560011b908561430c565b60070b905b6003614690565b919250506001600160ff1b03821682036114a957613437612535612ce68660a085015161205f565b90511561347e5761344e9061255c61255786612099565b9061345882614c20565b93613474612593600292611722976123559681800210016120ad565b0560070b90613408565b61348c612557859395612024565b90808210156134a957505061172292600261347461235593612077565b6125f9906125f36134ba9394612077565b926134ce612612611722956123559461205f565b60070b90613408565b9296936134ea92969195612da291612017565b936060860151633b9aca00810290808204633b9aca0014901517156114a957915f1981146114a95760010193865115155f1461353f5761353360e088015160c089015190611b19565b60e088015295916132cd565b61355260e088015160c089015190612017565b613533565b82511561357c5761357660c084015160026126d88a60a08801516120ad565b946133b5565b61359460c084015160026126fb8a60a08801516120ad565b613576565b608082015160a0830151036135b3576080820151956133a4565b8151156136015760e08201516135d3610100840151604085015190611958565b906040840151633b9aca000390633b9aca0082116114a9576127ae612f05926135fb9461196b565b956133a4565b613615610100830151604084015190611958565b6040830151633b9aca0003633b9aca0081116114a957612c15612f6e916135fb9361196b565b600382016001600160401b036136518783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612fb68261367e94611ff6565b90549060031b1c60070b60a084015260e08301516136a6610100850151606086015190611958565b906060850151633b9aca000391633b9aca0083116114a9576136cb926127ae9161196b565b60c0840152613376565b5090519094925015613711575f1982019182116114a9576136ff6123559260026117229601611ff6565b90549060031b1c60070b906003614690565b5f1982019182116114a95761372f6123559260046117229601611ff6565b90549060031b1c60070b90613408565b9395929450906001608060049286546001600160401b03811682526001600160401b038160401c1660208301526001600160401b0381841c16604083015260c01c6060820152019401920194929087949261328e565b8260038301613274565b92949350505061172293505f146137bc5760026136ff9101611fe4565b600461372f9101611fe4565b5060018514613206565b6003830154916131e2565b906040516137ea816115f5565b5f81525f60208201525f60408201525f60608201525f60808201525f60a08201525f60c08201525f60e08201525f6101008201526004600110156125a257600180825260208201819052838101545f5160206157ad5f395f51905f5254939092826001600160801b038616158015613ed1575b613ea95750855460281c80670de0b6b3a7640000810204670de0b6b3a764000014811517156114a9576b033b2e3c9fd0803ce80000006138de6138ea926001600160801b036001600160401b036138c0828c16670de0b6b3a7640000850261196b565b1699846138d18260801c8095611958565b0460e08801521690611958565b0460e083015190612017565b6101008201525f9481511515805f14613e9d578488018592915b6040519182602082549182815201915f5260205f20905f915b816003840110613e595794809387959361230d9361395b9854918b82821061292f57828210612912578282106128f55750106128e757500383611611565b915b6139b6575b50505115613998575f1983019283116114a9576139886123559360026117229701611ff6565b90549060031b1c60070b91614690565b5f1983019283116114a9576139886123559360046117229701611ff6565b9096905f1986018681116114a957881015613e5157825115613d9d578482016001600160401b036139e78a83611ff6565b90549060031b1c166040850152858901808a116114a9576001600160401b03613a1382613a2e94611ff6565b90549060031b1c16606086015260028401612bba8b82611ff6565b90549060031b1c60070b60a0840152613a51610100840151606085015190611958565b6060840151633b9aca000390633b9aca0082116114a957613a7591612c159161196b565b60c08401525b604083015180633b9aca00810204633b9aca0014811517156114a957633b9aca000203613cfb576080820151965b602083015115613cb95760c0830151955b848710613be957505050602081015186919015613b10579060a0613adf92015161205f565b6001600160ff1b03841684036114a957611722956124f6613b079261235596861b908561430c565b60070b91614690565b919350506001600160ff1b03831683036114a957613b40612535613b388760a085015161205f565b85851b611958565b905115613b9057613b579061255c61255787612099565b91613b6183614c20565b9460048310156125a257613b86612593600292611722986123559781800210016120ad565b0560070b91614690565b613b9f61255786939496612024565b9080821015613bbd57505090611722936002613b8661235594612077565b6125f990613bcf613bd5939594612077565b94612017565b93613b07612612611722966123559561205f565b95613bfc90613c15939995989298612017565b936020840151155f14613c80575060c083015190611b19565b946060820151633b9aca00810290808204633b9aca0014901517156114a957905f1981146114a9578251908501919015613c675784613c5d60e085015160c086015190611b19565b60e085015261395d565b84613c7b60e085015160c086015190612017565b613c5d565b835115613ca0576123559060026126d860c08701519260a08801516120ad565b6127059060026126fb60c08701519260a08801516120ad565b825115613cde57613cd860c084015160026126d88b60a08801516120ad565b95613aba565b613cf660c084015160026126fb8b60a08801516120ad565b613cd8565b608082015160a083015103613d1557608082015196613aa9565b815115613d635760e0820151613d35610100840151604085015190611958565b906040840151633b9aca000390633b9aca0082116114a9576127ae612f0592613d5d9461196b565b96613aa9565b613d77610100830151604084015190611958565b6040830151633b9aca0003633b9aca0081116114a957612c15612f6e91613d5d9361196b565b600382016001600160401b03613db38a83611ff6565b90549060031b1c166040850152858901808a116114a9576001600160401b03613ddf82613dfa94611ff6565b90549060031b1c16606086015260048401612bba8b82611ff6565b90549060031b1c60070b60a084015260e0830151613e22610100850151606086015190611958565b906060850151633b9aca000391633b9aca0083116114a957613e47926127ae9161196b565b60c0840152613a7b565b819750613962565b80546001600160401b038082168652604082811c82166020880152608083811c9092169087015260c09190911c60608601528b98940193600493909301920161391d565b60038801859291613904565b611722969395509193505015613ec55760026139889101611fe4565b60046139889101611fe4565b5083851461385d565b9060ff8091169116039060ff82116114a957565b60ff16604d81116114a957600a0a90565b9060ff8116806012115f14613f265750906127dd613f21611722936012613eda565b613eee565b60121015613f465790613f40613f21601261172294613eda565b90611958565b5090565b9060ff81166012811115613f6b5750906127dd613f21601261172294613eda565b60121115613f465790613f40613f21611722936012613eda565b908160209103126114a557516001600160a01b03811681036114a55790565b51906001600160801b03821682036114a557565b91908260409103126114a5576117226020613fd284613fa4565b9301613fa4565b613fe290614a2c565b600a859492939510156125a2576001841461403057906001600160801b036140178360208061401f9996518301019101613fb8565b501693614aca565b81929192811061402c5750565b9150565b5050505060206001600160a01b03614052838380600496518301019101613f85565b16604051928380927f5ade93550000000000000000000000000000000000000000000000000000000082525afa90811561149a575f91614090575090565b90506020813d6020116140b7575b816140ab60209383611611565b810103126114a5575190565b3d915061409e565b600111156125a257565b51906001600160a01b03821682036114a557565b805181016040828203126114a55760208201519160018310156114a5576040810151916001600160401b0383116114a55761411f926020809201920101611c6b565b90614129816140bf565b805f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7d6020526001600160a01b0360405f20931692835f5260205260405f205461217857815161417c575b5050505f90565b614185816140bf565b15614191575b80614175565b6020818051810103126114a5576141b260206001600160a01b0392016140c9565b1690811561418b575f91604460209260405194859384927f65e4ad9e00000000000000000000000000000000000000000000000000000000845230600485015260248401525af190811561149a575f9161420a575090565b90506020813d60201161423a575b8161422560209383611611565b810103126114a5575180151581036114a55790565b3d9150614218565b6001600160801b03811161425c576001600160801b031690565b7f6dfcc650000000000000000000000000000000000000000000000000000000005f52608060045260245260445ffd5b906142a4816b033b2e3c9fd0803ce80000008461449b565b908015611975576b033b2e3c9fd0803ce80000006117229309151590611b19565b906142d58183633b9aca0061449b565b9080156119755761172292633b9aca0009151590611b19565b6142fb600260018361449b565b600260016117229309151590611b19565b9161431881838561449b565b918115611975576117229309151590611b19565b9061433c81633b9aca008461449b565b90801561197557633b9aca006117229309151590611b19565b614364633b9aca00838361449b565b9061172292633b9aca009109151590611b19565b6040517f23b872dd0000000000000000000000000000000000000000000000000000000060208201526001600160a01b0392831660248201529290911660448301526064808301939093529181526118d2916143d5608483611611565b614b6d565b6143e390614bda565b3092916143ef816140bf565b156143f75750565b9091506020818051810103126114a55761441b60206001600160a01b0392016140c9565b1690565b9061442a5f92614bda565b90614434816140bf565b1561443c5750565b60049192506001600160a01b0361445d826020808095518301019101613f85565b16604051928380927fe8c9bee50000000000000000000000000000000000000000000000000000000082525afa90811561149a575f91614090575090565b91818302915f198185099383808610950394808603951461452b57848311156145135790829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b82634e487b715f52156003026011186020526024601cfd5b505090611722925061196b565b61454190614a2c565b600a85949293969510156125a257600184146145ed5794614581939291614579876020806001600160801b039a518301019101613fb8565b971693614aca565b81939193670de0b6b3a764000092838202908282048514831517156114a9576001600160801b031684038481116114a9576145bc9084611958565b11156145dc57508184029184830414841517156114a9576117229161196b565b8190939293106145e95750565b9250565b5050505060406001600160a01b0361461084602080600497518301019101613f85565b168151938480927f4cb44a760000000000000000000000000000000000000000000000000000000082525afa91821561149a575f905f9361465057509190565b9250506040823d60401161467e575b8161466c60409383611611565b810103126114a5576020825192015190565b3d915061465f565b600411156125a257565b91909161469c81614686565b806147315750600781900b905f82126146f0575064e8d4a51000811015611a3157633b9aca00820291808304633b9aca0014901517156114a957633b9aca000180633b9aca00116114a9576117229161196b565b9050633b9aca00820291808304633b9aca0014901517156114a9576147149061494b565b60070b633b9aca0003633b9aca0081116114a9576117229161196b565b61473a81614686565b6001810361474c5750611722916149cf565b60029061475881614686565b036147665761172291614963565b600781900b905f821261479a5750633b8b87c0811015611a3157633b9aca0003633b9aca0081116114a9576117229161432c565b6147a4915061494b565b60070b633b9aca000180633b9aca00116114a9576117229161432c565b906001600160401b03809116911602906001600160401b0382169182036114a957565b91815192831561494357600193808280614909575b80156148c6575b6148b257505b80851061481f57505050505f1981019081116114a95790565b61483081861860011c828716611b19565b90821561488557614858633b9aca006001600160401b036148518589611e58565b51166147c1565b6001600160401b038086169116115b156148725750614806565b9450600181018091116114a95793614806565b61489f633b9aca006001600160401b036148518589611e58565b6001600160401b03808616911610614867565b9450505050505f1981019081116114a95790565b508215801561480057505f1981018181116114a957633b9aca006001600160401b036148516148f59389611e58565b6001600160401b0380861691161015614800565b505f1981018181116114a957633b9aca006001600160401b0361485161492f9389611e58565b6001600160401b03808616911611156147f9565b505050505f90565b60070b677fffffffffffffff1981146114a9575f0390565b90600781900b905f82126149a25750633b8b87c0811015611a3157633b9aca0003633b9aca0081116114a957633b9aca009161499e91611958565b0490565b6149ac915061494b565b60070b633b9aca000180633b9aca00116114a957633b9aca009161499e91611958565b90600781900b905f8212614a05575064e8d4a51000811015611a3157633b9aca000180633b9aca00116114a95761172291614355565b614a0f915061494b565b60070b633b9aca0003633b9aca0081116114a95761172291614355565b8051810160a082602083019203126114a5576020820151600a8110156114a557604083015193600a8510156114a55760608401516001600160401b0381116114a557836020614a7d92870101611c6b565b9360808101516001600160401b0381116114a557846020614aa092840101611c6b565b9360a0820151916001600160401b0383116114a557614ac29201602001611c6b565b919493929190565b939492614adb90614ae29392614dd8565b809461520a565b9280670de0b6b3a764000003670de0b6b3a764000081116114a957614b079084611958565b670de0b6b3a7640000850290858204670de0b6b3a764000014861517156114a95781119182614b3f575b5050614b3957565b91508091565b909150670de0b6b3a76400000180670de0b6b3a7640000116114a957614b659084611958565b115f80614b31565b905f602091828151910182855af11561149a575f513d614bd157506001600160a01b0381163b155b614b9c5750565b6001600160a01b03907f5274afe7000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b60011415614b95565b805181016040828203126114a55760208201519160018310156114a5576040810151916001600160401b0383116114a557614c1c926020809201920101611c6b565b9091565b600181111561172257806001700100000000000000000000000000000000831015614d43575b60048268010000000000000000614cf5941015614d36575b640100000000811015614d29575b62010000811015614d1c575b610100811015614d10575b6010811015614d04575b1015614cfc575b60030260011c614ca4818461196b565b0160011c614cb2818461196b565b0160011c614cc0818461196b565b0160011c614cce818461196b565b0160011c614cdc818461196b565b0160011c614cea818461196b565b0160011c809261196b565b8111900390565b60011b614c94565b811c9160021b91614c8d565b60081c91811b91614c83565b60101c9160081b91614c78565b60201c9160101b91614c6c565b60401c9160201b91614c5e565b5050608081901c68010000000000000000614c46565b6001600160401b0381116115c65760051b60200190565b9080601f830112156114a557815190614d8882614d59565b92614d966040519485611611565b82845260208085019360051b8201019182116114a557602001915b818310614dbe5750505090565b825160ff811681036114a557815260209283019201614db1565b600a8110156125a25780614fe4575090815182019160a081602085019403126114a55760208101516001600160401b0381116114a55781019280603f850112156114a5576020840151614e2a81614d59565b94614e386040519687611611565b8186526020808088019360051b83010101908382116114a557604001915b818310614fc45750505060408201516001600160401b0381116114a557820181603f820112156114a5576020810151614e8e81614d59565b91614e9c6040519384611611565b8183526020808085019360051b83010101908482116114a557604001915b818310614fa75750505060608301516001600160401b0381116114a557826020614ee692860101614d70565b9160808401516001600160401b0381116114a55760a0916020614f0b92870101614d70565b93015160028110156114a557670de0b6b3a7640000614f2e919694929596615621565b938351915f935b838510614f455750505050505090565b90919293949695614f9a6001916001600160a01b03614f64898c611e58565b511660ff614f728a87611e58565b511660ff614f808b89611e58565b51169163ffffffff614f928c8b611e58565b511693615660565b9697950193929190614f35565b825163ffffffff811681036114a557815260209283019201614eba565b82516001600160a01b03811681036114a557815260209283019201614e56565b60038103614ffa575050670de0b6b3a764000090565b60028103615010575050670de0b6b3a764000090565b60048103615063575050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561149a575f91614090575090565b600581036150a8575050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561149a575f91614090575090565b600681036150ed5750506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561149a575f91614090575090565b60078103615132575050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561149a575f91614090575090565b600881036151535750602081519181808201938492010103126114a5575190565b6009036151fd576040818051810103126114a557806020604061517f826001600160a01b0395016140c9565b920151916004604051809581937fa035b1fe000000000000000000000000000000000000000000000000000000008352165afa801561149a575f906151c9575b611722925061196b565b506020823d6020116151f5575b816151e360209383611611565b810103126114a55761172291516151bf565b3d91506151d6565b50670de0b6b3a764000090565b92919092600a8110156125a257806153db57508051810160a082602083019203126114a55760208201516001600160401b0381116114a55782019381603f860112156114a557602085015161525e81614d59565b9561526c6040519788611611565b8187526020808089019360051b83010101908482116114a557604001915b8183106153bb5750505060408301516001600160401b0381116114a55783019082603f830112156114a55760208201516152c381614d59565b926152d16040519485611611565b8184526020808086019360051b83010101908582116114a557604001915b81831061539e5750505060608401516001600160401b0381116114a55783602061531b92870101614d70565b9260808501516001600160401b0381116114a55760a091602061534092880101614d70565b9401519060028210156114a55761535b919694929596615621565b938351915f935b8385106153725750505050505090565b909192939496956153916001916001600160a01b03614f64898c611e58565b9697950193929190615362565b825163ffffffff811681036114a5578152602092830192016152ef565b82516001600160a01b03811681036114a55781526020928301920161528a565b91929091600381036153f657505050670de0b6b3a764000090565b600281036154045750905090565b6004810361545857505050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561149a575f91614090575090565b6005810361549e57505050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561149a575f91614090575090565b600681036154e4575050506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561149a575f91614090575090565b6007810361552a57505050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561149a575f91614090575090565b6008810361554c575050602081519181808201938492010103126114a5575190565b60090361557957506040818051810103126114a557806020604061517f826001600160a01b0395016140c9565b905090565b9091906155bd575080511561559557805190602001fd5b7fd6bda275000000000000000000000000000000000000000000000000000000005f5260045ffd5b9080511580615609575b6155ce5790565b7f9996b315000000000000000000000000000000000000000000000000000000005f526e22d473030f116ddee9f6b43ac78ba360045260245ffd5b506e22d473030f116ddee9f6b43ac78ba33b156155c7565b60028110156125a2576117225750670de0b6b3a764000090565b519069ffffffffffffffffffff821682036114a557565b604d81116114a957600a0a90565b91909360a06001600160a01b0394956004604051809781937ffeaf968c000000000000000000000000000000000000000000000000000000008352165afa90811561149a575f945f92615736575b505f85139182159261571a575b50506156f25760ff166001036156e2576156dc61172293926127dd92611958565b91615652565b6119bc90613f4061172294615652565b7fae193563000000000000000000000000000000000000000000000000000000005f5260045ffd5b63ffffffff91925061572c9042612017565b9116105f806156bb565b9450905060a0843d60a011615784575b8161575360a09383611611565b810103126114a5576157648461563b565b50602084015161577b60806060870151960161563b565b5093905f6156ae565b3d915061574656fe4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c754b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c76a26469706673582212202315e764380b3f787ebd2e6dfeae85dc491a663af4dc752be68c0442007445dc64736f6c634300081c0033
Deployed Bytecode
0x60806040526004361015610011575f80fd5b5f5f3560e01c80633b6a1fe014610ef15780634583aea614610e865780639525f3ab14610e6c578063b92567fa146107d6578063c10a62871461046a5763d92c6cb21461005c575f80fd5b346103195761006a3661164d565b61007982859697949895611c02565b91909261008685846119cd565b97881061045b5761009b918391888780611cb1565b600260ff5f51602061578d5f395f51905f525460a81c161461044c576100e7600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b83151580610443575b610130575b602087610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b604051908152f35b61015361014e5f5160206157ad5f395f51905f525460801c8961428c565b614242565b6001600160801b03835460281c91168091016001600160d81b03811161042f57835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546101b18160801c86611b26565b16016001600160801b03811161041b57610202906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b80518590156103cd578082602061025694519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d9061023a82611632565b916102486040519384611611565b82523d87602084013e61557e565b505b60ff815416610327575b506001600160a01b031691823b15610319576040516340c10f1960e01b81526001600160a01b038716600482015260248101869052818160448183885af1801561031c57610304575b50506001600160a01b0360209560405192835285878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0333951692a45f80808080806100f5565b61030f828092611611565b61031957806102ab565b80fd5b6040513d84823e3d90fd5b610336600861033b920161188c565b614bda565b90610345816140bf565b61026257610364816020806001600160a01b0394518301019101613f85565b16803b156103c1578380916024604051809481936255f9e960e71b83528860048401525af180156103b65790849161039d575b50610262565b816103a791611611565b6103b257825f610397565b8280fd5b6040513d86823e3d90fd5b8380fd5b60609061557e565b5050805460ff161561040657610401836103f16103ec6008850161188c565b6143da565b336001600160a01b038916614378565b610258565b6104018330336001600160a01b038916614378565b602486634e487b7160e01b81526011600452fd5b602487634e487b7160e01b81526011600452fd5b508615156100f0565b6004856306fda65d60e31b8152fd5b60048663a1aabbe160e01b8152fd5b5034610319576104793661164d565b61048882859697949895611c02565b9190926104958584611bb8565b978089116107c757918391886104ab948b611cb1565b600260ff5f51602061578d5f395f51905f525460a81c161461044c576104f7600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b861515806107be575b61053757602087610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b61055561014e5f5160206157ad5f395f51905f525460801c8661428c565b6001600160801b03835460281c91168091016001600160d81b03811161042f57835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546105b38160801c86611b26565b16016001600160801b03811161041b57610604906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b8051859015610785578082602061063c94519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d9061023a82611632565b505b60ff8154166106ff575b506001600160a01b031691823b15610319576040516340c10f1960e01b81526001600160a01b038716600482015260248101839052818160448183885af1801561031c576106ea575b50506001600160a01b0360209560405192868452878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0333951692a45f80808080806100f5565b6106f5828092611611565b6103195780610691565b610336600861070e920161188c565b90610718816140bf565b61064857610737816020806001600160a01b0394518301019101613f85565b16803b156103c1578380916024604051809481936255f9e960e71b83528b60048401525af180156103b657908491610770575b50610648565b8161077a91611611565b6103b257825f61076a565b5050805460ff16156107a9576107a4866103f16103ec6008850161188c565b61063e565b6107a48630336001600160a01b038916614378565b50831515610500565b6004876328ac195d60e21b8152fd5b5034610319576107f56107e83661151b565b8284959792939694611739565b9096908715610e5b576108088482611bb8565b965b8711610e4c576040516020986108208a83611611565b838252600260ff5f51602061578d5f395f51905f525460a81c1614610e3d5761086f600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b881590811580610e34575b6108b1575b8a8a610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b15610b8d57506108d561014e5f5160206157ad5f395f51905f525460801c8761428c565b6001600160801b03835460281c91168091016001600160d81b038111610b7957835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546109338160801c86611b26565b16016001600160801b038111610b6557610984906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b8051839015610b2c5780828b6109d694519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d906109bb82611632565b916109c96040519384611611565b82523d858c84013e61557e565b505b60ff815416610aa7575b506001600160a01b038516803b15610aa3576040516340c10f1960e01b81526001600160a01b0384166004820152602481018590529082908290604490829084905af1801561031c57610a8e575b50506001600160a01b03905b60405192868452878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0380339616941692a45f808080808080808061087f565b610a99828092611611565b6103195780610a30565b5080fd5b6103366008610ab6920161188c565b90610ac0816140bf565b6109e257610ade8189806001600160a01b0394518301019101613f85565b16803b15610aa3578180916024604051809481936255f9e960e71b83528c60048401525af1801561031c57908291610b17575b506109e2565b81610b2191611611565b61031957805f610b11565b5050805460ff1615610b5057610b4b876103f16103ec6008850161188c565b6109d8565b610b4b8730336001600160a01b038916614378565b602484634e487b7160e01b81526011600452fd5b602485634e487b7160e01b81526011600452fd5b905060ff82548a1c16151580610e18575b610e09576b033b2e3c9fd0803ce80000008802908882046b033b2e3c9fd0803ce8000000141715610df55761014e610be8915f5160206157ad5f395f51905f525460801c9061196b565b6001600160801b03825460281c91168091036001600160d81b038111610b6557825464ffffffffff1660289190911b64ffffffffff19161782556001600160801b035f5160206157ad5f395f51905f525416036001600160801b038111610df557610c8a906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b6001600160a01b038516803b156103b2578280916044604051809481936315a38ec760e11b83528d60048401523360248401525af18015610dea57908391610dd5575b5050805460ff1615610d83576103366008610ce8920161188c565b90610cf2816140bf565b15610d08575b50506001600160a01b0390610a3c565b610d228189806001600160a01b0394518301019101613f85565b16803b15610aa357604051638bfb07c960e01b81526001600160a01b03878116600483015284166024820152604481018590529082908290606490829084905af1801561031c5715610cf857610d79828092611611565b6103195780610cf8565b505060405163a9059cbb60e01b878201526001600160a01b038281166024830152604482018490529190610dd090610dc881606481015b03601f198101835282611611565b838716614b6d565b610a3c565b81610ddf91611611565b610aa357815f610ccd565b6040513d85823e3d90fd5b602483634e487b7160e01b81526011600452fd5b600483630b094f2760e31b8152fd5b50610e2e84610e296006850161188c565b6140dd565b15610b9e565b5086151561087a565b6004846306fda65d60e31b8152fd5b6004826328ac195d60e21b8152fd5b610e66848288611b82565b9661080a565b5034610319576020610128610e8036611571565b916116e9565b503461031957610ea7602091610e9b36611571565b93919250834291611739565b929015610ed65750610ebc61012891836119cd565b91825f5160206157ad5f395f51905f525460801c91611b4f565b610ee4610eec928483611989565b928391611a0e565b610128565b50346114a557610f036107e83661151b565b909690871561150a57610f1684826119cd565b965b87106114fb57604051602098610f2e8a83611611565b5f8252600260ff5f51602061578d5f395f51905f525460a81c16146114ec57610f7d600160a91b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b8515908115806114e3575b610fbe578a8a610128600160a81b60ff60a81b195f51602061578d5f395f51905f525416175f51602061578d5f395f51905f5255565b156112535750610fe261014e5f5160206157ad5f395f51905f525460801c8a61428c565b6001600160801b03835460281c91168091016001600160d81b038111610b7957835464ffffffffff1660289190911b64ffffffffff19161783556001600160801b035f5160206157ad5f395f51905f52546110408160801c86611b26565b16016001600160801b038111610b6557611091906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b805183901561121a5780828b6110c894519101826e22d473030f116ddee9f6b43ac78ba35af13d156103c5573d906109bb82611632565b505b60ff815416611195575b506001600160a01b038516803b15610aa3576040516340c10f1960e01b81526001600160a01b0384166004820152602481018890529082908290604490829084905af1801561031c57611180575b50506001600160a01b03905b60405192835285878401521660408201527f73adcdbf2d8fee0c1221daefef436a92c3c640e97ff2941e744bf5eef1ab346f60606001600160a01b0380339616941692a45f808080808080808061087f565b61118b828092611611565b6103195780611122565b61033660086111a4920161188c565b906111ae816140bf565b6110d4576111cc8189806001600160a01b0394518301019101613f85565b16803b15610aa3578180916024604051809481936255f9e960e71b83528960048401525af1801561031c57908291611205575b506110d4565b8161120f91611611565b61031957805f6111ff565b5050805460ff161561123e57611239846103f16103ec6008850161188c565b6110ca565b6112398430336001600160a01b038916614378565b905060ff82548a1c161515806114cc575b6114bd576b033b2e3c9fd0803ce80000008502908582046b033b2e3c9fd0803ce80000001417156114a95761014e6112ae915f5160206157ad5f395f51905f525460801c9061196b565b6001600160801b03825460281c91168091036001600160d81b0381116114a957825464ffffffffff1660289190911b64ffffffffff19161782556001600160801b035f5160206157ad5f395f51905f525416036001600160801b0381116114a957611350906001600160801b03166fffffffffffffffffffffffffffffffff195f5160206157ad5f395f51905f525416175f5160206157ad5f395f51905f5255565b6001600160a01b038516803b156114a5575f80916044604051809481936315a38ec760e11b83528a60048401523360248401525af1801561149a57611485575b50805460ff16156114455761033660086113aa920161188c565b906113b4816140bf565b156113ca575b50506001600160a01b039061112e565b6113e48189806001600160a01b0394518301019101613f85565b16803b15610aa357604051638bfb07c960e01b81526001600160a01b03878116600483015284166024820152604481018890529082908290606490829084905af1801561031c57156113ba5761143b828092611611565b61031957806113ba565b505060405163a9059cbb60e01b878201526001600160a01b03828116602483015260448201879052919061148090610dc88160648101610dba565b61112e565b6114929192505f90611611565b5f905f611390565b6040513d5f823e3d90fd5b5f80fd5b634e487b7160e01b5f52601160045260245ffd5b630b094f2760e31b5f5260045ffd5b506114dd84610e296006850161188c565b15611264565b50891515610f88565b6306fda65d60e31b5f5260045ffd5b63a1aabbe160e01b5f5260045ffd5b611515848288611989565b96610f18565b60c09060031901126114a55760043590602435906044356001600160a01b03811681036114a557906064356001600160a01b03811681036114a557906084356001600160a01b03811681036114a5579060a43590565b60609060031901126114a557600435906024356001600160a01b03811681036114a557906044356001600160a01b03811681036114a55790565b606081019081106001600160401b038211176115c657604052565b634e487b7160e01b5f52604160045260245ffd5b604081019081106001600160401b038211176115c657604052565b61012081019081106001600160401b038211176115c657604052565b90601f801991011681019081106001600160401b038211176115c657604052565b6001600160401b0381116115c657601f01601f191660200190565b9060c06003198301126114a55760043591602435916044356001600160a01b03811681036114a557916064356001600160a01b03811681036114a557916084359160a4356001600160401b0381116114a557816023820112156114a5578060040135906116b982611632565b926116c76040519485611611565b828452602483830101116114a557815f92602460209301838601378301015290565b906116f690834291611739565b901561172557611722925061171d5f5160206157ad5f395f51905f525460801c8383611b4f565b611bb8565b90565b82611734838361172296611a0e565b611b82565b914211611864576001600160a01b035f51602061578d5f395f51905f525416806001600160a01b038416145f146117df57506117a691506001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815460101c16156117b7575f91565b7f9e87fac8000000000000000000000000000000000000000000000000000000005f5260045ffd5b906001600160a01b0316145f1461183c5761182a906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815460081c16156117b757600191565b7f672215de000000000000000000000000000000000000000000000000000000005f5260045ffd5b7fecdd1c29000000000000000000000000000000000000000000000000000000005f5260045ffd5b90604051915f8154908160011c926001831692831561194e575b60208510841461193a57848752869390811561191857506001146118d4575b506118d292500383611611565b565b90505f9291925260205f20905f915b8183106118fc5750509060206118d2928201015f6118c5565b60209193508060019154838589010152019101909184926118e3565b9050602092506118d294915060ff191682840152151560051b8201015f6118c5565b634e487b7160e01b5f52602260045260245ffd5b93607f16936118a6565b818102929181159184041417156114a957565b8115611975570490565b634e487b7160e01b5f52601260045260245ffd5b6119c16119b76119bc611722956119ae60ff956119a86005890161188c565b90611e80565b93909187612186565b611958565b61196b565b915460181c1690613eff565b906119e6906119b76119e16005850161188c565b613fd9565b9060ff815460181c166012019160ff83116114a95761172292611a0891613f4a565b906129d5565b909160ff835416159182159384611af9575b508315611a59575b505050611a3157565b7f11157667000000000000000000000000000000000000000000000000000000005f5260045ffd5b9192509082611a6d575b50505f8080611a28565b6001600160a01b039192506020906024604051809481937f70a08231000000000000000000000000000000000000000000000000000000008352306004840152165afa90811561149a575f91611ac7575b50105f80611a63565b90506020813d602011611af1575b81611ae260209383611611565b810103126114a557515f611abe565b3d9150611ad5565b82919450611b0c6008611b11920161188c565b61441f565b10925f611a20565b919082018092116114a957565b906b033b2e3c9fd0803ce8000000611b44600992845460281c611958565b0491015410611a3157565b916009916b033b2e3c9fd0803ce8000000611b71611b7893865460281c611958565b0490611b19565b91015410611a3157565b61172292611bad611b9c611bb2936119a86005870161188c565b91909260ff865460181c1690613f4a565b61449b565b90613186565b611bd1611bca6119e16005840161188c565b92826137dd565b91670de0b6b3a7640000830292808404670de0b6b3a764000014901517156114a9576119c160ff916117229461196b565b90421161186457611c43906001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b60ff815460081c16156117b7576001600160a01b035f51602061578d5f395f51905f52541691565b81601f820112156114a557805190611c8282611632565b92611c906040519485611611565b828452602083830101116114a557815f9260208093018386015e8301015290565b9492909360405190611cc2826115ab565b5f825260208201965f885260408301956060875260ff81541615155f14611e4f57611cfa6103ec60086001600160a01b03930161188c565b1683525b81518201936040838603126114a5576020830151966040840151956001600160401b0387116114a557611de99a6117229a6101449a611d51611e10986020809c816001600160a01b039801920101611c6b565b85528252826040519a611d638c6115da565b168a52888a0152519560405198611d798a6115ab565b89528789019687526040890193845251169260405193611d98856115da565b8452868401525193604051998a977f30f28b7a00000000000000000000000000000000000000000000000000000000888a0152602489019051602080916001600160a01b0381511684520151910152565b51606487015251608486015280516001600160a01b031660a48601526020015160c4850152565b3360e4840152610100610104840152805191829182610124860152018484015e5f838284010152601f801991011681010301601f198101835282611611565b50308352611cfe565b8051821015611e6c5760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b90915f91670de0b6b3a76400009360405190818260207f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775492838152017f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c775f5260205f20925f5b818110611fc2575050611efc92500383611611565b8151925f5b848110611f0f575050505050565b6001600160a01b03611f218286611e58565b51166001600160a01b03831614611faf57611f92611f8d6005611f876001600160a01b03611f4f868a611e58565b51166001600160a01b03165f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7a60205260405f2090565b0161188c565b614538565b90505b888110611fa6575b50600101611f01565b97506001611f9d565b9550611fba82614538565b969096611f95565b84546001600160a01b0316835260019485019487945060209093019201611ee7565b805415611e6c575f5260205f20905f90565b9190918054831015611e6c575f52601860205f208360021c019260031b1690565b919082039182116114a957565b905f82633b9aca00039212633b9aca008312811690633b9aca008413901516176114a957565b90633b9ac9ff1982019182136001166114a957565b81810392915f1380158285131691841216176114a957565b90633b9aca008201915f633b9aca00841291129080158216911516176114a957565b9081633b9aca00019182126001166114a957565b9190915f83820193841291129080158216911516176114a957565b5f908015612180578080600114612178576002146121715760016101338210166001600b83101617612163579060019060025b600181116121275750825f1904821161211357500290565b80634e487b7160e01b602492526011600452fd5b92805f1904811161214f5760018416612146575b80029260011c6120fb565b8092029161213b565b602482634e487b7160e01b81526011600452fd5b6002900a9190806121135750565b5050600490565b505050600190565b50505f90565b9060405190612194826115f5565b5f82525f60208301525f60408301525f60608301525f60808301525f60a08301525f60c08301525f60e08301525f6101008301526004600210156125a2575f80835260016020840181905290929091906129ca565b5f5160206157ad5f395f51905f5254946001600160801b0386161580156129c1575b6129985750855460281c80670de0b6b3a7640000810204670de0b6b3a764000014811517156114a9576b033b2e3c9fd0803ce800000061228c612298926001600160801b036001600160401b0361226e828c16670de0b6b3a7640000850261196b565b16998461227f8260801c8095611958565b0460e08901521690611958565b0460e084015190612017565b6101008301525f9482511515805f1461298c578288018392915b6040519182602082549182815201915f5260205f20905f915b8160038401106129485794809387959361230d936123129854918b82821061292f575b828210612912575b8282106128f5575b50106128e7575b500383611611565b6147e4565b915b612389575b5050905115905061235b575f1982019182116114a9576123426123559260026117229601611ff6565b90549060031b1c60070b905b6002614690565b90611b19565b5f1982019182116114a9576123796123559260046117229601611ff6565b90549060031b1c60070b9061234e565b91969094915f1983018381116114a9578610156128dc57835115612828578782016001600160401b036123bc8883611ff6565b90549060031b1c1660408601528887018088116114a9576001600160401b036123e88261241794611ff6565b90549060031b1c166060870152600284016124038982611ff6565b90549060031b1c60070b6080880152611ff6565b90549060031b1c60070b60a085015261243a610100850151606086015190611958565b6060850151633b9aca000390633b9aca0082116114a9576124699161245e9161196b565b60e086015190612017565b60c08501525b6040840151633b9aca00810290808204633b9aca0014901517156114a9570361274c576080830151945b60208401511561270a5760c0840151925b8584106126205750505060208201518490156125075760a06124ce9293015161205f565b926001600160ff1b03821682036114a9576124f6612355946124fc93611722981b908561430c565b906120ad565b60070b906002614690565b50506001600160ff1b03821682036114a95761254061253561252d8560a085015161205f565b84881b611958565b60c0830151906142c5565b9051156125b6576125619061255c61255785612099565b6120c8565b611b19565b61256a81614c20565b9060048610156125a2576125936123559460029361259893896117229a505081800210016120ad565b61204a565b0560070b9061234e565b634e487b7160e01b5f52602160045260245ffd5b9093506125c561255783612024565b90808210156125e257505061172292600261259861235593612077565b6125f9906125f36125fe9394612077565b93612017565b614c20565b92612617612612611722956123559461205f565b6142ee565b60070b9061234e565b959461264d92989361263491989298612017565b946020850151155f146126b8575060c084015190611b19565b946060830151633b9aca00810290808204633b9aca0014901517156114a957905f1981146114a957835190830191901561269f578261269560e086015160c087015190611b19565b60e0860152612314565b826126b360e086015160c087015190612017565b612695565b8451156126e2576123559060026126d860c08801519260a08901516120ad565b60070b05906149cf565b6127059060026126fb60c08801519260a08901516120ad565b60070b0590614963565b612355565b83511561272f5761272960c085015160026126d88960a08901516120ad565b926124aa565b61274760c085015160026126fb8960a08901516120ad565b612729565b608083015160a08401510361276657608083015194612499565b8251156127e95760e0830151612786610100850151604086015190611958565b906040850151633b9aca000390633b9aca0082116114a9576127ae6127b4926127e39461196b565b90612017565b6124f66080860151916127dd6127d2826119b78660a08c015161205f565b9160c0890151611b19565b9061196b565b94612499565b6127fd610100840151604085015190611958565b6040840151633b9aca0003633b9aca0081116114a95761245e612823916127e39361196b565b6127b4565b600382016001600160401b0361283e8883611ff6565b90549060031b1c1660408601528887018088116114a9576001600160401b0361286a8261288594611ff6565b90549060031b1c166060870152600484016124038982611ff6565b90549060031b1c60070b60a085015260e08401516128ad610100860151606087015190611958565b906060860151633b9aca000391633b9aca0083116114a9576128d2926127ae9161196b565b60c085015261246f565b819750829550612319565b60c01c81526020015f612305565b90936020906001600160401b038560801c1681520193018b6122fe565b90936020906001600160401b038560401c1681520193018b6122f6565b6001600160401b0384168552602090940193018b6122ee565b80546001600160401b038082168652604082811c82166020880152608083811c9092169087015260c09190911c6060860152899894019360049390930192016122cb565b600388018392916122b2565b92945050506117229391505f146129b55760026123429101611fe4565b60046123799101611fe4565b5081851461220b565b6003850154926121e9565b604051916129e2836115f5565b5f83525f60208401525f60408401525f60608401525f60808401525f60a08401525f60c08401525f60e08401525f61010084015260045f10156125a25760018084525f6020850152906001830154915f5160206157ad5f395f51905f5254906001600160801b038216908115801561317c575b6131535750845460281c670de0b6b3a76400008102818104670de0b6b3a764000014821517156114a957826b033b2e3c9fd0803ce80000009283612ab66001600160401b03612aaa612acd98612ac19761196b565b169760801c8093611958565b0460e08b0152611958565b0460e087015190612017565b6101008601525f9385511515805f146131495782600183015b604051928391602081549586815201905f5260205f20945f955b8160038801106130f35791612b4196859261230d9454918181106130d9575b8181106130bc575b81811061309f575b10613091575b509b97999b0383611611565b935b5f1987018781116114a95785101561302857825115612f7357600182016001600160401b03612b728783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612b9f82612bce94611ff6565b90549060031b1c16606086015260028401612bba8882611ff6565b90549060031b1c60070b6080870152611ff6565b90549060031b1c60070b60a0840152612bf1610100840151606085015190611958565b6060840151633b9aca000390633b9aca0082116114a957612c2091612c159161196b565b60e085015190612017565b60c08401525b604083015180633b9aca00810204633b9aca0014811517156114a957633b9aca000203612ea3576080820151955b602083015115612e615760c0830151945b848610612d8f57505050602081015185919015612cbe579060a0612c8a92015161205f565b6001600160ff1b03831683036114a957611722946124f6612cb3926123559560011b908561430c565b60070b905b5f614690565b919250506001600160ff1b03821682036114a957612cef612535612ce68660a085015161205f565b8460011b611958565b905115612d3657612d069061255c61255786612099565b90612d1082614c20565b93612d2c612593600292611722976123559681800210016120ad565b0560070b90612cb8565b612d44612557859395612024565b9080821015612d61575050611722926002612d2c61235593612077565b6125f9906125f3612d729394612077565b92612d86612612611722956123559461205f565b60070b90612cb8565b929693612dbb92969195612da291612017565b936020880151155f14612e28575060c087015190611b19565b936060860151633b9aca00810290808204633b9aca0014901517156114a957915f1981146114a95760010193865115155f14612e1057612e0460e088015160c089015190611b19565b60e08801529591612b43565b612e2360e088015160c089015190612017565b612e04565b875115612e48576123559060026126d860c08b01519260a08c01516120ad565b6127059060026126fb60c08b01519260a08c01516120ad565b825115612e8657612e8060c084015160026126d88a60a08801516120ad565b94612c65565b612e9e60c084015160026126fb8a60a08801516120ad565b612e80565b608082015160a083015103612ebd57608082015195612c54565b815115612f345760e0820151612edd610100840151604085015190611958565b906040840151633b9aca000390633b9aca0082116114a9576127ae612f0592612f2e9461196b565b6124f66080850151916127dd612f23826119b78660a08b015161205f565b9160c0880151611b19565b95612c54565b612f48610100830151604084015190611958565b6040830151633b9aca0003633b9aca0081116114a957612c15612f6e91612f2e9361196b565b612f05565b600382016001600160401b03612f898783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612fb682612fd194611ff6565b90549060031b1c16606086015260048401612bba8882611ff6565b90549060031b1c60070b60a084015260e0830151612ff9610100850151606086015190611958565b906060850151633b9aca000391633b9aca0083116114a95761301e926127ae9161196b565b60c0840152612c26565b5090519094925015613063575f1982019182116114a9576130526123559260026117229601611ff6565b90549060031b1c60070b905f614690565b5f1982019182116114a9576130816123559260046117229601611ff6565b90549060031b1c60070b90612cb8565b60c01c81526020015f612b35565b9260206001916001600160401b038560801c168152019301612b2f565b9260206001916001600160401b038560401c168152019301612b27565b9260206001916001600160401b0385168152019301612b1f565b9395929450906001608060049286546001600160401b03811682526001600160401b038160401c1660208301526001600160401b0381841c16604083015260c01c60608201520194019201949290879492612b00565b8260038301612ae6565b92949350505061172293505f146131705760026130529101611fe4565b60046130819101611fe4565b5060018514612a55565b60405191613193836115f5565b5f83525f60208401525f60408401525f60608401525f60808401525f60a08401525f60c08401525f60e08401525f6101008401526004600310156125a2575f80845260208401819052906137d2565b5f5160206157ad5f395f51905f5254906001600160801b03821690811580156137c8575b61379f5750845460281c670de0b6b3a76400008102818104670de0b6b3a764000014821517156114a957826b033b2e3c9fd0803ce80000009283612ab66001600160401b03612aaa61325b98612ac19761196b565b6101008601525f9385511515805f146137955782600183015b604051928391602081549586815201905f5260205f20945f955b81600388011061373f57916132cb96859261230d9454918181106130d9578181106130bc5781811061309f571061309157509b97999b0383611611565b935b5f1987018781116114a9578510156136d55782511561363b57600182016001600160401b036132fc8783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612b9f8261332994611ff6565b90549060031b1c60070b60a084015261334c610100840151606085015190611958565b6060840151633b9aca000390633b9aca0082116114a95761337091612c159161196b565b60c08401525b604083015180633b9aca00810204633b9aca0014811517156114a957633b9aca000203613599576080820151955b6020830151156135575760c0830151945b8486106134d75750505060208101518591901561340f579060a06133da92015161205f565b6001600160ff1b03831683036114a957611722946124f6613403926123559560011b908561430c565b60070b905b6003614690565b919250506001600160ff1b03821682036114a957613437612535612ce68660a085015161205f565b90511561347e5761344e9061255c61255786612099565b9061345882614c20565b93613474612593600292611722976123559681800210016120ad565b0560070b90613408565b61348c612557859395612024565b90808210156134a957505061172292600261347461235593612077565b6125f9906125f36134ba9394612077565b926134ce612612611722956123559461205f565b60070b90613408565b9296936134ea92969195612da291612017565b936060860151633b9aca00810290808204633b9aca0014901517156114a957915f1981146114a95760010193865115155f1461353f5761353360e088015160c089015190611b19565b60e088015295916132cd565b61355260e088015160c089015190612017565b613533565b82511561357c5761357660c084015160026126d88a60a08801516120ad565b946133b5565b61359460c084015160026126fb8a60a08801516120ad565b613576565b608082015160a0830151036135b3576080820151956133a4565b8151156136015760e08201516135d3610100840151604085015190611958565b906040840151633b9aca000390633b9aca0082116114a9576127ae612f05926135fb9461196b565b956133a4565b613615610100830151604084015190611958565b6040830151633b9aca0003633b9aca0081116114a957612c15612f6e916135fb9361196b565b600382016001600160401b036136518783611ff6565b90549060031b1c166040850152600186018087116114a9576001600160401b03612fb68261367e94611ff6565b90549060031b1c60070b60a084015260e08301516136a6610100850151606086015190611958565b906060850151633b9aca000391633b9aca0083116114a9576136cb926127ae9161196b565b60c0840152613376565b5090519094925015613711575f1982019182116114a9576136ff6123559260026117229601611ff6565b90549060031b1c60070b906003614690565b5f1982019182116114a95761372f6123559260046117229601611ff6565b90549060031b1c60070b90613408565b9395929450906001608060049286546001600160401b03811682526001600160401b038160401c1660208301526001600160401b0381841c16604083015260c01c6060820152019401920194929087949261328e565b8260038301613274565b92949350505061172293505f146137bc5760026136ff9101611fe4565b600461372f9101611fe4565b5060018514613206565b6003830154916131e2565b906040516137ea816115f5565b5f81525f60208201525f60408201525f60608201525f60808201525f60a08201525f60c08201525f60e08201525f6101008201526004600110156125a257600180825260208201819052838101545f5160206157ad5f395f51905f5254939092826001600160801b038616158015613ed1575b613ea95750855460281c80670de0b6b3a7640000810204670de0b6b3a764000014811517156114a9576b033b2e3c9fd0803ce80000006138de6138ea926001600160801b036001600160401b036138c0828c16670de0b6b3a7640000850261196b565b1699846138d18260801c8095611958565b0460e08801521690611958565b0460e083015190612017565b6101008201525f9481511515805f14613e9d578488018592915b6040519182602082549182815201915f5260205f20905f915b816003840110613e595794809387959361230d9361395b9854918b82821061292f57828210612912578282106128f55750106128e757500383611611565b915b6139b6575b50505115613998575f1983019283116114a9576139886123559360026117229701611ff6565b90549060031b1c60070b91614690565b5f1983019283116114a9576139886123559360046117229701611ff6565b9096905f1986018681116114a957881015613e5157825115613d9d578482016001600160401b036139e78a83611ff6565b90549060031b1c166040850152858901808a116114a9576001600160401b03613a1382613a2e94611ff6565b90549060031b1c16606086015260028401612bba8b82611ff6565b90549060031b1c60070b60a0840152613a51610100840151606085015190611958565b6060840151633b9aca000390633b9aca0082116114a957613a7591612c159161196b565b60c08401525b604083015180633b9aca00810204633b9aca0014811517156114a957633b9aca000203613cfb576080820151965b602083015115613cb95760c0830151955b848710613be957505050602081015186919015613b10579060a0613adf92015161205f565b6001600160ff1b03841684036114a957611722956124f6613b079261235596861b908561430c565b60070b91614690565b919350506001600160ff1b03831683036114a957613b40612535613b388760a085015161205f565b85851b611958565b905115613b9057613b579061255c61255787612099565b91613b6183614c20565b9460048310156125a257613b86612593600292611722986123559781800210016120ad565b0560070b91614690565b613b9f61255786939496612024565b9080821015613bbd57505090611722936002613b8661235594612077565b6125f990613bcf613bd5939594612077565b94612017565b93613b07612612611722966123559561205f565b95613bfc90613c15939995989298612017565b936020840151155f14613c80575060c083015190611b19565b946060820151633b9aca00810290808204633b9aca0014901517156114a957905f1981146114a9578251908501919015613c675784613c5d60e085015160c086015190611b19565b60e085015261395d565b84613c7b60e085015160c086015190612017565b613c5d565b835115613ca0576123559060026126d860c08701519260a08801516120ad565b6127059060026126fb60c08701519260a08801516120ad565b825115613cde57613cd860c084015160026126d88b60a08801516120ad565b95613aba565b613cf660c084015160026126fb8b60a08801516120ad565b613cd8565b608082015160a083015103613d1557608082015196613aa9565b815115613d635760e0820151613d35610100840151604085015190611958565b906040840151633b9aca000390633b9aca0082116114a9576127ae612f0592613d5d9461196b565b96613aa9565b613d77610100830151604084015190611958565b6040830151633b9aca0003633b9aca0081116114a957612c15612f6e91613d5d9361196b565b600382016001600160401b03613db38a83611ff6565b90549060031b1c166040850152858901808a116114a9576001600160401b03613ddf82613dfa94611ff6565b90549060031b1c16606086015260048401612bba8b82611ff6565b90549060031b1c60070b60a084015260e0830151613e22610100850151606086015190611958565b906060850151633b9aca000391633b9aca0083116114a957613e47926127ae9161196b565b60c0840152613a7b565b819750613962565b80546001600160401b038082168652604082811c82166020880152608083811c9092169087015260c09190911c60608601528b98940193600493909301920161391d565b60038801859291613904565b611722969395509193505015613ec55760026139889101611fe4565b60046139889101611fe4565b5083851461385d565b9060ff8091169116039060ff82116114a957565b60ff16604d81116114a957600a0a90565b9060ff8116806012115f14613f265750906127dd613f21611722936012613eda565b613eee565b60121015613f465790613f40613f21601261172294613eda565b90611958565b5090565b9060ff81166012811115613f6b5750906127dd613f21601261172294613eda565b60121115613f465790613f40613f21611722936012613eda565b908160209103126114a557516001600160a01b03811681036114a55790565b51906001600160801b03821682036114a557565b91908260409103126114a5576117226020613fd284613fa4565b9301613fa4565b613fe290614a2c565b600a859492939510156125a2576001841461403057906001600160801b036140178360208061401f9996518301019101613fb8565b501693614aca565b81929192811061402c5750565b9150565b5050505060206001600160a01b03614052838380600496518301019101613f85565b16604051928380927f5ade93550000000000000000000000000000000000000000000000000000000082525afa90811561149a575f91614090575090565b90506020813d6020116140b7575b816140ab60209383611611565b810103126114a5575190565b3d915061409e565b600111156125a257565b51906001600160a01b03821682036114a557565b805181016040828203126114a55760208201519160018310156114a5576040810151916001600160401b0383116114a55761411f926020809201920101611c6b565b90614129816140bf565b805f527f4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c7d6020526001600160a01b0360405f20931692835f5260205260405f205461217857815161417c575b5050505f90565b614185816140bf565b15614191575b80614175565b6020818051810103126114a5576141b260206001600160a01b0392016140c9565b1690811561418b575f91604460209260405194859384927f65e4ad9e00000000000000000000000000000000000000000000000000000000845230600485015260248401525af190811561149a575f9161420a575090565b90506020813d60201161423a575b8161422560209383611611565b810103126114a5575180151581036114a55790565b3d9150614218565b6001600160801b03811161425c576001600160801b031690565b7f6dfcc650000000000000000000000000000000000000000000000000000000005f52608060045260245260445ffd5b906142a4816b033b2e3c9fd0803ce80000008461449b565b908015611975576b033b2e3c9fd0803ce80000006117229309151590611b19565b906142d58183633b9aca0061449b565b9080156119755761172292633b9aca0009151590611b19565b6142fb600260018361449b565b600260016117229309151590611b19565b9161431881838561449b565b918115611975576117229309151590611b19565b9061433c81633b9aca008461449b565b90801561197557633b9aca006117229309151590611b19565b614364633b9aca00838361449b565b9061172292633b9aca009109151590611b19565b6040517f23b872dd0000000000000000000000000000000000000000000000000000000060208201526001600160a01b0392831660248201529290911660448301526064808301939093529181526118d2916143d5608483611611565b614b6d565b6143e390614bda565b3092916143ef816140bf565b156143f75750565b9091506020818051810103126114a55761441b60206001600160a01b0392016140c9565b1690565b9061442a5f92614bda565b90614434816140bf565b1561443c5750565b60049192506001600160a01b0361445d826020808095518301019101613f85565b16604051928380927fe8c9bee50000000000000000000000000000000000000000000000000000000082525afa90811561149a575f91614090575090565b91818302915f198185099383808610950394808603951461452b57848311156145135790829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b82634e487b715f52156003026011186020526024601cfd5b505090611722925061196b565b61454190614a2c565b600a85949293969510156125a257600184146145ed5794614581939291614579876020806001600160801b039a518301019101613fb8565b971693614aca565b81939193670de0b6b3a764000092838202908282048514831517156114a9576001600160801b031684038481116114a9576145bc9084611958565b11156145dc57508184029184830414841517156114a9576117229161196b565b8190939293106145e95750565b9250565b5050505060406001600160a01b0361461084602080600497518301019101613f85565b168151938480927f4cb44a760000000000000000000000000000000000000000000000000000000082525afa91821561149a575f905f9361465057509190565b9250506040823d60401161467e575b8161466c60409383611611565b810103126114a5576020825192015190565b3d915061465f565b600411156125a257565b91909161469c81614686565b806147315750600781900b905f82126146f0575064e8d4a51000811015611a3157633b9aca00820291808304633b9aca0014901517156114a957633b9aca000180633b9aca00116114a9576117229161196b565b9050633b9aca00820291808304633b9aca0014901517156114a9576147149061494b565b60070b633b9aca0003633b9aca0081116114a9576117229161196b565b61473a81614686565b6001810361474c5750611722916149cf565b60029061475881614686565b036147665761172291614963565b600781900b905f821261479a5750633b8b87c0811015611a3157633b9aca0003633b9aca0081116114a9576117229161432c565b6147a4915061494b565b60070b633b9aca000180633b9aca00116114a9576117229161432c565b906001600160401b03809116911602906001600160401b0382169182036114a957565b91815192831561494357600193808280614909575b80156148c6575b6148b257505b80851061481f57505050505f1981019081116114a95790565b61483081861860011c828716611b19565b90821561488557614858633b9aca006001600160401b036148518589611e58565b51166147c1565b6001600160401b038086169116115b156148725750614806565b9450600181018091116114a95793614806565b61489f633b9aca006001600160401b036148518589611e58565b6001600160401b03808616911610614867565b9450505050505f1981019081116114a95790565b508215801561480057505f1981018181116114a957633b9aca006001600160401b036148516148f59389611e58565b6001600160401b0380861691161015614800565b505f1981018181116114a957633b9aca006001600160401b0361485161492f9389611e58565b6001600160401b03808616911611156147f9565b505050505f90565b60070b677fffffffffffffff1981146114a9575f0390565b90600781900b905f82126149a25750633b8b87c0811015611a3157633b9aca0003633b9aca0081116114a957633b9aca009161499e91611958565b0490565b6149ac915061494b565b60070b633b9aca000180633b9aca00116114a957633b9aca009161499e91611958565b90600781900b905f8212614a05575064e8d4a51000811015611a3157633b9aca000180633b9aca00116114a95761172291614355565b614a0f915061494b565b60070b633b9aca0003633b9aca0081116114a95761172291614355565b8051810160a082602083019203126114a5576020820151600a8110156114a557604083015193600a8510156114a55760608401516001600160401b0381116114a557836020614a7d92870101611c6b565b9360808101516001600160401b0381116114a557846020614aa092840101611c6b565b9360a0820151916001600160401b0383116114a557614ac29201602001611c6b565b919493929190565b939492614adb90614ae29392614dd8565b809461520a565b9280670de0b6b3a764000003670de0b6b3a764000081116114a957614b079084611958565b670de0b6b3a7640000850290858204670de0b6b3a764000014861517156114a95781119182614b3f575b5050614b3957565b91508091565b909150670de0b6b3a76400000180670de0b6b3a7640000116114a957614b659084611958565b115f80614b31565b905f602091828151910182855af11561149a575f513d614bd157506001600160a01b0381163b155b614b9c5750565b6001600160a01b03907f5274afe7000000000000000000000000000000000000000000000000000000005f521660045260245ffd5b60011415614b95565b805181016040828203126114a55760208201519160018310156114a5576040810151916001600160401b0383116114a557614c1c926020809201920101611c6b565b9091565b600181111561172257806001700100000000000000000000000000000000831015614d43575b60048268010000000000000000614cf5941015614d36575b640100000000811015614d29575b62010000811015614d1c575b610100811015614d10575b6010811015614d04575b1015614cfc575b60030260011c614ca4818461196b565b0160011c614cb2818461196b565b0160011c614cc0818461196b565b0160011c614cce818461196b565b0160011c614cdc818461196b565b0160011c614cea818461196b565b0160011c809261196b565b8111900390565b60011b614c94565b811c9160021b91614c8d565b60081c91811b91614c83565b60101c9160081b91614c78565b60201c9160101b91614c6c565b60401c9160201b91614c5e565b5050608081901c68010000000000000000614c46565b6001600160401b0381116115c65760051b60200190565b9080601f830112156114a557815190614d8882614d59565b92614d966040519485611611565b82845260208085019360051b8201019182116114a557602001915b818310614dbe5750505090565b825160ff811681036114a557815260209283019201614db1565b600a8110156125a25780614fe4575090815182019160a081602085019403126114a55760208101516001600160401b0381116114a55781019280603f850112156114a5576020840151614e2a81614d59565b94614e386040519687611611565b8186526020808088019360051b83010101908382116114a557604001915b818310614fc45750505060408201516001600160401b0381116114a557820181603f820112156114a5576020810151614e8e81614d59565b91614e9c6040519384611611565b8183526020808085019360051b83010101908482116114a557604001915b818310614fa75750505060608301516001600160401b0381116114a557826020614ee692860101614d70565b9160808401516001600160401b0381116114a55760a0916020614f0b92870101614d70565b93015160028110156114a557670de0b6b3a7640000614f2e919694929596615621565b938351915f935b838510614f455750505050505090565b90919293949695614f9a6001916001600160a01b03614f64898c611e58565b511660ff614f728a87611e58565b511660ff614f808b89611e58565b51169163ffffffff614f928c8b611e58565b511693615660565b9697950193929190614f35565b825163ffffffff811681036114a557815260209283019201614eba565b82516001600160a01b03811681036114a557815260209283019201614e56565b60038103614ffa575050670de0b6b3a764000090565b60028103615010575050670de0b6b3a764000090565b60048103615063575050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561149a575f91614090575090565b600581036150a8575050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561149a575f91614090575090565b600681036150ed5750506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561149a575f91614090575090565b60078103615132575050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561149a575f91614090575090565b600881036151535750602081519181808201938492010103126114a5575190565b6009036151fd576040818051810103126114a557806020604061517f826001600160a01b0395016140c9565b920151916004604051809581937fa035b1fe000000000000000000000000000000000000000000000000000000008352165afa801561149a575f906151c9575b611722925061196b565b506020823d6020116151f5575b816151e360209383611611565b810103126114a55761172291516151bf565b3d91506151d6565b50670de0b6b3a764000090565b92919092600a8110156125a257806153db57508051810160a082602083019203126114a55760208201516001600160401b0381116114a55782019381603f860112156114a557602085015161525e81614d59565b9561526c6040519788611611565b8187526020808089019360051b83010101908482116114a557604001915b8183106153bb5750505060408301516001600160401b0381116114a55783019082603f830112156114a55760208201516152c381614d59565b926152d16040519485611611565b8184526020808086019360051b83010101908582116114a557604001915b81831061539e5750505060608401516001600160401b0381116114a55783602061531b92870101614d70565b9260808501516001600160401b0381116114a55760a091602061534092880101614d70565b9401519060028210156114a55761535b919694929596615621565b938351915f935b8385106153725750505050505090565b909192939496956153916001916001600160a01b03614f64898c611e58565b9697950193929190615362565b825163ffffffff811681036114a5578152602092830192016152ef565b82516001600160a01b03811681036114a55781526020928301920161528a565b91929091600381036153f657505050670de0b6b3a764000090565b600281036154045750905090565b6004810361545857505050604051630f451f7160e31b8152670de0b6b3a7640000600482015260208160248173ae7ab96520de3a18e5e111b5eaab095312d7fe845afa90811561149a575f91614090575090565b6005810361549e57505050604051633ba0b9a960e01b815260208160048173be9895146f7af43049ca1c1ae358b0541ea497045afa90811561149a575f91614090575090565b600681036154e4575050506040516339aa885b60e21b815260208160048173ae78736cd615f374d3085123a210448e74fc63935afa90811561149a575f91614090575090565b6007810361552a57505050604051634ca9858360e11b815260208160048173ac3e018457b222d93114458476f3e3416abbe38f5afa90811561149a575f91614090575090565b6008810361554c575050602081519181808201938492010103126114a5575190565b60090361557957506040818051810103126114a557806020604061517f826001600160a01b0395016140c9565b905090565b9091906155bd575080511561559557805190602001fd5b7fd6bda275000000000000000000000000000000000000000000000000000000005f5260045ffd5b9080511580615609575b6155ce5790565b7f9996b315000000000000000000000000000000000000000000000000000000005f526e22d473030f116ddee9f6b43ac78ba360045260245ffd5b506e22d473030f116ddee9f6b43ac78ba33b156155c7565b60028110156125a2576117225750670de0b6b3a764000090565b519069ffffffffffffffffffff821682036114a557565b604d81116114a957600a0a90565b91909360a06001600160a01b0394956004604051809781937ffeaf968c000000000000000000000000000000000000000000000000000000008352165afa90811561149a575f945f92615736575b505f85139182159261571a575b50506156f25760ff166001036156e2576156dc61172293926127dd92611958565b91615652565b6119bc90613f4061172294615652565b7fae193563000000000000000000000000000000000000000000000000000000005f5260045ffd5b63ffffffff91925061572c9042612017565b9116105f806156bb565b9450905060a0843d60a011615784575b8161575360a09383611611565b810103126114a5576157648461563b565b50602084015161577b60806060870151960161563b565b5093905f6156ae565b3d915061574656fe4b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c754b2dd303f68b99d244b702089c802b6e9ea1b5d4ef61fd436d6c41abb1178c76a26469706673582212202315e764380b3f787ebd2e6dfeae85dc491a663af4dc752be68c0442007445dc64736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.