Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00
Cross-Chain Transactions
Loading...
Loading
Contract Name:
YoVault_V2
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 1000 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {Errors} from "./libraries/Errors.sol";
import {IYoVault} from "./interfaces/IYoVault.sol";
import {IYoOracle} from "./interfaces/IYoOracle.sol";
import {Compatible} from "./base/Compatible.sol";
import {AuthUpgradeable, Authority} from "./base/AuthUpgradeable.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ERC4626Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
// __ __ ____ _ _
// \ \ / /__ | _ \ _ __ ___ | |_ ___ ___ ___ | |
// \ V / _ \| |_) | '__/ _ \| __/ _ \ / __/ _ \| |
// | | (_) | __/| | | (_) | || (_) | (_| (_) | |
// |_|\___/|_| |_| \___/ \__\___/ \___\___/|_|
/// @title yoVault_V2 - A simple vault contract that allows for an operator to manage the vault.
/// @dev This contract is based on the ERC4626 standard and uses the Auth contract for access control.
/// It provides an asynchronous redeem mechanism that allows users to request a redeem and the operator to fulfill it.
/// This would allow the operator to move funds to a different chain or strategy before the user can claim the assets.
/// If the vault has enough assets to fulfill the request, the assets are withdrawn and returned to the owner
/// immediately. Otherwise, the assets are transferred to the vault and the request is stored until the operator
/// fulfills it.
contract YoVault_V2 is ERC4626Upgradeable, Compatible, IYoVault, AuthUpgradeable, PausableUpgradeable {
using Math for uint256;
using Address for address;
using SafeERC20 for IERC20;
/// @dev Assume requests are non-fungible and all have ID = 0, so we can differentiate between a request ID and the
/// assets amount.
uint256 internal constant REQUEST_ID = 0;
/// @dev The denominator used for precision calculations.
uint256 internal constant DENOMINATOR = 1e18;
/// @dev The maximum fee that can be set for the vault operations. 1e17 = 10%.
uint256 internal constant MAX_FEE = 1e17;
/// @dev the address of the oracle contract
address public constant ORACLE_ADDRESS = 0x6E879d0CcC85085A709eBf5539224f53d0D396B0;
/// @dev the aggregated underlying balances across all strategies/chains, reported by an oracle
uint256 private deprecated_aggregatedUnderlyingBalances;
/// @dev the last block number when the aggregated underlying balances were updated
uint256 private deprecated_lastBlockUpdated;
/// @dev the last price per share calculated after the aggregated underlying balances are reported
uint256 private deprecated_lastPricePerShare;
/// @dev the total amount of assets that are pending redemption
uint256 public totalPendingAssets;
/// @dev the maximum percentage change allowed before the vault is paused. It can be updated by the owner.
/// 1e18 = 100%. It's value depends on the frequency of the oracle updates.
uint256 private deprecated_maxPercentageChange;
/// @dev the fee charged for the withdraws, it's a percentage of the assets redeemed
uint256 public feeOnWithdraw;
/// @dev the fee charged for the deposits, it's a percentage of the assets deposited
uint256 public feeOnDeposit;
/// @dev the address that receives the fees for the vault operations, if it's zero, no fees are charged
address public feeRecipient;
/// @dev used to store the amount of shares that are pending redemption, it must be fulfilled by the vault operator
mapping(address user => PendingRedeem redeem) internal _pendingRedeem;
//============================== CONSTRUCTOR ===============================
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
//============================== INITIALIZER ===============================
function initialize(IERC20 _asset, address _owner, string memory _name, string memory _symbol) public initializer {
__Context_init();
__ERC20_init(_name, _symbol);
__ERC4626_init(_asset);
__Auth_init(_owner, Authority(address(0)));
__Pausable_init();
}
// ========================================= PUBLIC FUNCTIONS =========================================
/// @notice Allows the vault operator to manage the vault.
/// @param target The target contract to make a call to.
/// @param data The data to send to the target contract.
/// @param value The amount of native assets to send with the call.
function manage(
address target,
bytes calldata data,
uint256 value
) external requiresAuth returns (bytes memory result) {
bytes4 functionSig = bytes4(data);
require(
authority().canCall(msg.sender, target, functionSig),
Errors.TargetMethodNotAuthorized(target, functionSig)
);
result = target.functionCallWithValue(data, value);
}
/// @notice Same as `manage` but allows for multiple calls in a single transaction.
/// @param targets The target contracts to make calls to.
/// @param data The data to send to the target contracts.
/// @param values The amounts of native assets to send with the calls.
function manage(
address[] calldata targets,
bytes[] calldata data,
uint256[] calldata values
) external requiresAuth returns (bytes[] memory results) {
uint256 targetsLength = targets.length;
results = new bytes[](targetsLength);
for (uint256 i; i < targetsLength; ++i) {
bytes4 functionSig = bytes4(data[i]);
require(
authority().canCall(msg.sender, targets[i], functionSig),
Errors.TargetMethodNotAuthorized(targets[i], functionSig)
);
results[i] = targets[i].functionCallWithValue(data[i], values[i]);
}
}
/// @notice Pause the contract to prevent any further deposits, withdrawals, or transfers.
function pause() public requiresAuth {
_pause();
}
/// @notice Unpause the contract to allow deposits, withdrawals, and transfers.
function unpause() public requiresAuth {
_unpause();
}
/// @notice If the vault has enough assets to fulfill the request,
/// withdraw the assets and return them to the owner.
/// Otherwise, transfer the shares to the vault and store the request.
/// The shares are burned when the request is fulfilled and the assets are transferred to the owner.
/// @param shares The amount of shares to redeem.
/// @param receiver The address of the receiver of the assets.
/// @param owner The address of the owner.
/// @return The ID of the request which is always 0 or the assets amount if the request is immediately
/// processed.
function requestRedeem(uint256 shares, address receiver, address owner) public whenNotPaused returns (uint256) {
require(receiver != address(0), Errors.ZeroReceiver());
require(shares > 0, Errors.SharesAmountZero());
require(owner == msg.sender, Errors.NotSharesOwner());
require(balanceOf(owner) >= shares, Errors.InsufficientShares());
uint256 assetsWithFee = super.previewRedeem(shares);
// instant redeem if the vault has enough assets
if (_getAvailableBalance() >= assetsWithFee) {
_withdraw(owner, receiver, owner, assetsWithFee, shares);
emit RedeemRequest(receiver, owner, assetsWithFee, shares, true);
return assetsWithFee;
}
emit RedeemRequest(receiver, owner, assetsWithFee, shares, false);
// transfer the shares to the vault and store the request
_transfer(owner, address(this), shares);
totalPendingAssets += assetsWithFee;
PendingRedeem storage pending = _pendingRedeem[receiver];
pending.shares += shares;
pending.assets += assetsWithFee;
return REQUEST_ID;
}
/// @notice The operator can fulfill a redeem request. Requires authorization.
/// @param receiver The address of the receiver of the assets.
/// @param shares The amount of shares to fulfil.
/// @param assetsWithFee The amount of assets to fulfil including the fee.
function fulfillRedeem(address receiver, uint256 shares, uint256 assetsWithFee) external requiresAuth {
PendingRedeem storage pending = _pendingRedeem[receiver];
require(pending.shares != 0 && shares <= pending.shares, Errors.InvalidSharesAmount());
require(pending.assets != 0 && assetsWithFee <= pending.assets, Errors.InvalidAssetsAmount());
pending.shares -= shares;
pending.assets -= assetsWithFee;
totalPendingAssets -= assetsWithFee;
emit RequestFulfilled(receiver, shares, assetsWithFee);
// burn the shares from the vault and transfer the assets to the receiver
_withdraw(address(this), receiver, address(this), assetsWithFee, shares);
}
/// @notice The operator can cancel a redeem request in case of an black swan event.
/// @param receiver The address of the receiver of the assets.
/// @param shares The amount of shares to cancel.
/// @param assetsWithFee The amount of assets to cancel including the fee.
function cancelRedeem(address receiver, uint256 shares, uint256 assetsWithFee) external requiresAuth {
PendingRedeem storage pending = _pendingRedeem[receiver];
require(pending.shares != 0 && shares <= pending.shares, Errors.InvalidSharesAmount());
require(pending.assets != 0 && assetsWithFee <= pending.assets, Errors.InvalidAssetsAmount());
pending.shares -= shares;
pending.assets -= assetsWithFee;
totalPendingAssets -= assetsWithFee;
emit RequestCancelled(receiver, shares, assetsWithFee);
// transfer the shares back to the owner
_transfer(address(this), receiver, shares);
}
/// @notice Update the fee charged for the vault operations.
/// @param newFee The new fee charged for the vault operations.
function updateWithdrawFee(uint256 newFee) external requiresAuth {
require(newFee < MAX_FEE, Errors.InvalidFee());
emit WithdrawFeeUpdated(feeOnWithdraw, newFee);
feeOnWithdraw = newFee;
}
/// @notice Update the fee charged for the vault operations.
/// @param newFee The new fee charged for the vault operations.
function updateDepositFee(uint256 newFee) external requiresAuth {
require(newFee < MAX_FEE, Errors.InvalidFee());
emit DepositFeeUpdated(feeOnDeposit, newFee);
feeOnDeposit = newFee;
}
/// @notice Update the address that receives the fees for the vault operations.
/// @param newFeeRecipient The new address that receives the fees for the vault operations.
function updateFeeRecipient(address newFeeRecipient) external requiresAuth {
emit FeeRecipientUpdated(feeRecipient, newFeeRecipient);
feeRecipient = newFeeRecipient;
}
//============================== VIEW FUNCTIONS ===============================
function totalAssets() public view override returns (uint256) {
(uint256 price, ) = IYoOracle(ORACLE_ADDRESS).getLatestPrice(address(this));
return price.mulDiv(super.totalSupply(), 10 ** decimals(), Math.Rounding.Floor);
}
/// @notice Get the last price per share from the oracle.
function lastPricePerShare() public view returns (uint256 price) {
(price, ) = IYoOracle(ORACLE_ADDRESS).getLatestPrice(address(this));
return price * (10 ** (18 - decimals()));
}
/// @notice Get the amount of assets and shares that are pending redemption.
/// @param user The address of the user.
function pendingRedeemRequest(address user) public view returns (uint256 assets, uint256 pendingShares) {
return (_pendingRedeem[user].assets, _pendingRedeem[user].shares);
}
//============================== OVERRIDES ===============================
/// @dev Override the default `deposit` function to add the `whenNotPaused` modifier.
function deposit(uint256 assets, address receiver) public override whenNotPaused returns (uint256) {
return super.deposit(assets, receiver);
}
/// @dev Override the default `mint` function to add the `whenNotPaused` modifier.
function mint(uint256 shares, address receiver) public override whenNotPaused returns (uint256) {
return super.mint(shares, receiver);
}
/// @notice This method is disabled. Use `requestRedeem` or `redeem`instead.
function withdraw(uint256, address, address) public override whenNotPaused returns (uint256) {
revert Errors.UseRequestRedeem();
}
function redeem(uint256 shares, address receiver, address owner) public override whenNotPaused returns (uint256) {
return requestRedeem(shares, receiver, owner);
}
/// @dev Override the default `_update` function to add the `whenNotPaused` modifier.
/// The _update function is called on all transfers, mints and burns.
function _update(address from, address to, uint256 value) internal override whenNotPaused {
super._update(from, to, value);
}
/// @dev Converts assets to shares using the last price per share read from the oracle, ignoring the total assets and total
/// supply (shares)
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view override returns (uint256) {
(uint256 pricePerShare, ) = IYoOracle(ORACLE_ADDRESS).getLatestPrice(address(this));
require(pricePerShare > 0, Errors.InvalidPrice());
return assets.mulDiv(10 ** decimals(), pricePerShare, rounding);
}
/// @dev Converts shares to assets using the last price per share read from the oracle, ignoring the total assets and total
/// supply (shares)
function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view override returns (uint256) {
(uint256 pricePerShare, ) = IYoOracle(ORACLE_ADDRESS).getLatestPrice(address(this));
require(pricePerShare > 0, Errors.InvalidPrice());
return shares.mulDiv(pricePerShare, 10 ** decimals(), rounding);
}
/// @dev Preview taking an entry fee on deposit. See {IERC4626-previewDeposit}.
function previewDeposit(uint256 assets) public view virtual override returns (uint256) {
uint256 fee = _feeOnTotal(assets, feeOnDeposit);
return super.previewDeposit(assets - fee);
}
/// @dev Preview adding an entry fee on mint. See {IERC4626-previewMint}.
function previewMint(uint256 shares) public view virtual override returns (uint256) {
uint256 assets = super.previewMint(shares);
return assets + _feeOnRaw(assets, feeOnDeposit);
}
/// @dev Preview adding an exit fee on withdraw. See {IERC4626-previewWithdraw}.
function previewWithdraw(uint256 assets) public view virtual override returns (uint256) {
uint256 fee = _feeOnRaw(assets, feeOnWithdraw);
return super.previewWithdraw(assets + fee);
}
/// @dev Preview taking an exit fee on redeem. See {IERC4626-previewRedeem}.
function previewRedeem(uint256 shares) public view virtual override returns (uint256) {
uint256 assets = super.previewRedeem(shares);
return assets - _feeOnTotal(assets, feeOnWithdraw);
}
function maxDeposit(address receiver) public view virtual override returns (uint256) {
if (paused()) {
return 0;
}
return super.maxDeposit(receiver);
}
function maxMint(address receiver) public view virtual override returns (uint256) {
if (paused()) {
return 0;
}
return super.maxMint(receiver);
}
function maxWithdraw(address owner) public view virtual override returns (uint256) {
if (paused()) {
return 0;
}
return super.maxWithdraw(owner);
}
function maxRedeem(address owner) public view virtual override returns (uint256) {
if (paused()) {
return 0;
}
return super.maxRedeem(owner);
}
/// @dev Account for the fee charged for the vault operations if the fee recipient and fee are set.
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assetsWithFee,
uint256 shares
) internal override {
uint256 feeAmount = _feeOnTotal(assetsWithFee, feeOnWithdraw);
uint256 assets = assetsWithFee - feeAmount;
address recipient = feeRecipient;
super._withdraw(caller, receiver, owner, assets, shares);
if (feeAmount > 0 && recipient != address(0)) {
IERC20(asset()).safeTransfer(recipient, feeAmount);
}
}
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal override {
uint256 feeAmount = _feeOnTotal(assets, feeOnDeposit);
address recipient = feeRecipient;
super._deposit(caller, receiver, assets, shares);
if (feeAmount > 0 && recipient != address(0)) {
IERC20(asset()).safeTransfer(recipient, feeAmount);
}
}
//============================== PRIVATE FUNCTIONS ===============================
/// @dev Calculates the fees that should be added to an amount `assets` that does not already include fees.
/// Used in {IERC4626-mint} and {IERC4626-withdraw} operations.
function _feeOnRaw(uint256 assets, uint256 feeBasisPoints) private pure returns (uint256) {
return assets.mulDiv(feeBasisPoints, DENOMINATOR, Math.Rounding.Ceil);
}
/// @dev Calculates the fee part of an amount `assets` that already includes fees.
/// Used in {IERC4626-deposit} and {IERC4626-redeem} operations.
function _feeOnTotal(uint256 assets, uint256 feeBasisPoints) private pure returns (uint256) {
return assets.mulDiv(feeBasisPoints, feeBasisPoints + DENOMINATOR, Math.Rounding.Ceil);
}
/// @dev The available balance is the balance of the vault minus the total pending assets.
/// @return The available balance.
function _getAvailableBalance() internal view returns (uint256) {
uint256 balance = IERC20(asset()).balanceOf(address(this));
return balance > totalPendingAssets ? balance - totalPendingAssets : 0;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
library Errors {
//============================== GENERICS ===============================
/// @notice Thrown when an unauthorized method to a target is called.
/// @dev The method must be authorized by setUserRole and setRoleCapability from RolesAuthority
error TargetMethodNotAuthorized(address target, bytes4 functionSig);
/// @notice Thrown when insufficient shares balance is available to complete the operation.
error InsufficientShares();
/// @notice Thrown when the operation is called by a user that is not the owner of the shares.
error NotSharesOwner();
/// @notice Thrown when the input shares amount is zero.
error SharesAmountZero();
/// @notice Thrown when a claim request is fulfilled with an invalid shares amount.
error InvalidSharesAmount();
/// @notice Thrown when a withdraw is attempted with an amount different than the claimable assets.
error InvalidAssetsAmount();
/// @notice Thrown when the new max percentage is greater than the current max percentage.
error InvalidMaxPercentage();
/// @notice Thrown when the new fee is greater than the max allowed fee.
error InvalidFee();
/// @notice Thrown when the underlying balance has already been updated in the current block.
error UpdateAlreadyCompletedInThisBlock();
/// @notice Thrown when redeem() or withdraw() is called
error UseRequestRedeem();
error UseOnSharePriceUpdate();
/// @notice Thrown when the price is zero
error InvalidPrice();
/// @notice Thrown when the receiver is zero
error ZeroReceiver();
/// @notice Thrown when msg.sender is not the vault
error Escrow__OnlyVault();
/// @notice Thrown when the requested amount of assets is zero
error Escrow__AmountZero();
/// @notice Thrown when the vault address is zero
error Registry__VaultAddressZero();
/// @notice Thrown when the vault already exists
error Registry__VaultAlreadyExists(address vaultAddress);
/// @notice Thrown when the vault does not exist
error Registry__VaultNotExists(address vaultAddress);
/// @notice Thrown when the vault is not allowed
error Gateway__VaultNotAllowed();
/// @notice Thrown when the amount is zero
error Gateway__ZeroAmount();
/// @notice Thrown when the receiver is zero
error Gateway__ZeroReceiver();
/// @notice Thrown when the shares out is less than the minimum shares out
error Gateway__InsufficientSharesOut(uint256 sharesOut, uint256 minSharesOut);
/// @notice Thrown when the owner of the shares is zero
error Gateway__ZeroOwner();
/// @notice Thrown when the assets out is less than the minimum assets out
error Gateway__InsufficientAssetsOut(uint256 assetsOut, uint256 minAssetsOut);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @title IyoVault
/// @notice Interface for the YO vault part of the YO protocol
interface IYoVault {
struct PendingRedeem {
uint256 assets;
uint256 shares;
}
/// @notice Emitted when the fee is updated
/// @param lastFee The last fee
/// @param newFee The new fee
event WithdrawFeeUpdated(uint256 lastFee, uint256 newFee);
/// @notice Emitted when the fee is updated
/// @param lastFee The last fee
/// @param newFee The new fee
event DepositFeeUpdated(uint256 lastFee, uint256 newFee);
/// @notice Emitted when the fee recipient is updated
/// @param lastFeeRecipient The last fee recipient
/// @param newFeeRecipient The new fee recipient
event FeeRecipientUpdated(address lastFeeRecipient, address newFeeRecipient);
/// @notice Emitted when the max percentage is updated
/// @param lastMaxPercentage The last max percentage
/// @param newMaxPercentage The new max percentage
event MaxPercentageUpdated(uint256 lastMaxPercentage, uint256 newMaxPercentage);
/// @notice Emitted when the underlying balance is updated by the oracle
/// @param lastUnderlyingBalance The last underlying balance
/// @param newUnderlyingBalance The new underlying balance
event UnderlyingBalanceUpdated(uint256 lastUnderlyingBalance, uint256 newUnderlyingBalance);
/// @notice Emitted when a new redeem request is created
/// @param receiver The receiving address
/// @param owner The owner address
/// @param assets The assets amount
/// @param shares The shares amount
/// @param instant The instant status
event RedeemRequest(
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares,
bool indexed instant
);
/// @notice Emitted when a redeem request is fulfilled
/// @param receiver The receiving address
/// @param shares The shares amount
/// @param assets The assets amount
event RequestFulfilled(address indexed receiver, uint256 shares, uint256 assets);
/// @notice Emitted when a redeem request is cancelled
/// @param receiver The receiving address
/// @param shares The shares amount
/// @param assets The assets amount
event RequestCancelled(address indexed receiver, uint256 shares, uint256 assets);
function requestRedeem(uint256 shares, address receiver, address owner) external returns (uint256 requestId);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IYoOracle {
struct AssetOracleData {
uint256 latestPrice;
uint256 anchorPrice;
uint64 anchorTimestamp;
uint64 latestTimestamp;
uint64 windowSeconds;
uint64 maxChangeBps;
}
error NotUpdater();
error InvalidConfig();
error PriceChangeTooBig(
address vault,
uint256 newPrice,
uint256 anchorPrice,
uint256 diffBps,
uint256 maxChangeBps
);
event UpdaterChanged(address indexed oldUpdater, address indexed newUpdater);
event SharePriceUpdated(address indexed vault, uint256 price, uint64 timestamp);
event AssetConfigUpdated(address indexed vault, uint32 windowSeconds, uint32 maxChangeBps);
function getLatestPrice(address _vault) external view returns (uint256 sharePrice, uint64 timestamp);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @title Compatible
/// @notice Abstract contract that allows the contract to receive ether and ERC721/1155 tokens
abstract contract Compatible {
/// @notice Emitted when the contract receives ether
/// @param sender The address that sent the ether
/// @param amount The amount of ether received
event Received(address sender, uint256 amount);
receive() external payable {
emit Received(msg.sender, msg.value);
}
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC721Received.selector;
}
function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] calldata,
uint256[] calldata,
bytes calldata
)
external
pure
returns (bytes4)
{
return this.onERC1155BatchReceived.selector;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import { Authority } from "@solmate/auth/Auth.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
/// @notice Upgradable fork of (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
abstract contract AuthUpgradeable is Initializable {
event OwnershipTransferred(address indexed user, address indexed newOwner);
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
/// @custom:storage-location erc7201:auth.storage
struct AuthStorage {
address owner;
Authority authority;
}
// keccak256(abi.encode(uint256(keccak256("auth.storage")) - 1)) & ~bytes32(uint256(0xff))
// solhint-disable-next-line const-name-snakecase
bytes32 private constant AuthStorageLocation = 0xdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea00;
function _getAuthStorage() private pure returns (AuthStorage storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := AuthStorageLocation
}
}
function __Auth_init(address _owner, Authority _authority) internal onlyInitializing {
AuthStorage storage $ = _getAuthStorage();
$.owner = _owner;
$.authority = _authority;
emit OwnershipTransferred(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}
modifier requiresAuth() virtual {
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
_;
}
function isAuthorized(address user, bytes4 functionSig) public view virtual returns (bool) {
AuthStorage storage $ = _getAuthStorage();
Authority auth = $.authority;
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == $.owner;
}
function owner() public view virtual returns (address) {
return _getAuthStorage().owner;
}
function authority() public view virtual returns (Authority) {
return _getAuthStorage().authority;
}
function setAuthority(Authority newAuthority) public virtual {
AuthStorage storage $ = _getAuthStorage();
// We check if the caller is the owner first because we want to ensure they can
// always swap out the authority even if it's reverting or using up a lot of gas.
// solhint-disable-next-line reason-string
require(msg.sender == $.owner || $.authority.canCall(msg.sender, address(this), msg.sig));
$.authority = newAuthority;
emit AuthorityUpdated(msg.sender, newAuthority);
}
function transferOwnership(address newOwner) public virtual requiresAuth {
AuthStorage storage $ = _getAuthStorage();
$.owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}// 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/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, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @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) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.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.1.0) (token/ERC20/extensions/ERC4626.sol)
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ERC20Upgradeable} from "../ERC20Upgradeable.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Initializable} from "../../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the ERC-4626 "Tokenized Vault Standard" as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*
* This extension allows the minting and burning of "shares" (represented using the ERC-20 inheritance) in exchange for
* underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends
* the ERC-20 standard. Any additional extensions included along it would affect the "shares" token represented by this
* contract and not the "assets" token which is an independent contract.
*
* [CAUTION]
* ====
* In empty (or nearly empty) ERC-4626 vaults, deposits are at high risk of being stolen through frontrunning
* with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation
* attack and is essentially a problem of slippage. Vault deployers can protect against this attack by making an initial
* deposit of a non-trivial amount of the asset, such that price manipulation becomes infeasible. Withdrawals may
* similarly be affected by slippage. Users can protect against this attack as well as unexpected slippage in general by
* verifying the amount received is as expected, using a wrapper that performs these checks such as
* https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router].
*
* Since v4.9, this implementation introduces configurable virtual assets and shares to help developers mitigate that risk.
* The `_decimalsOffset()` corresponds to an offset in the decimal representation between the underlying asset's decimals
* and the vault decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which
* itself determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default
* offset (0) makes it non-profitable even if an attacker is able to capture value from multiple user deposits, as a result
* of the value being captured by the virtual shares (out of the attacker's donation) matching the attacker's expected gains.
* With a larger offset, the attack becomes orders of magnitude more expensive than it is profitable. More details about the
* underlying math can be found xref:erc4626.adoc#inflation-attack[here].
*
* The drawback of this approach is that the virtual shares do capture (a very small) part of the value being accrued
* to the vault. Also, if the vault experiences losses, the users try to exit the vault, the virtual shares and assets
* will cause the first user to exit to experience reduced losses in detriment to the last users that will experience
* bigger losses. Developers willing to revert back to the pre-v4.9 behavior just need to override the
* `_convertToShares` and `_convertToAssets` functions.
*
* To learn more, check out our xref:ROOT:erc4626.adoc[ERC-4626 guide].
* ====
*/
abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626 {
using Math for uint256;
/// @custom:storage-location erc7201:openzeppelin.storage.ERC4626
struct ERC4626Storage {
IERC20 _asset;
uint8 _underlyingDecimals;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC4626")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC4626StorageLocation = 0x0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00;
function _getERC4626Storage() private pure returns (ERC4626Storage storage $) {
assembly {
$.slot := ERC4626StorageLocation
}
}
/**
* @dev Attempted to deposit more assets than the max amount for `receiver`.
*/
error ERC4626ExceededMaxDeposit(address receiver, uint256 assets, uint256 max);
/**
* @dev Attempted to mint more shares than the max amount for `receiver`.
*/
error ERC4626ExceededMaxMint(address receiver, uint256 shares, uint256 max);
/**
* @dev Attempted to withdraw more assets than the max amount for `receiver`.
*/
error ERC4626ExceededMaxWithdraw(address owner, uint256 assets, uint256 max);
/**
* @dev Attempted to redeem more shares than the max amount for `receiver`.
*/
error ERC4626ExceededMaxRedeem(address owner, uint256 shares, uint256 max);
/**
* @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC-20 or ERC-777).
*/
function __ERC4626_init(IERC20 asset_) internal onlyInitializing {
__ERC4626_init_unchained(asset_);
}
function __ERC4626_init_unchained(IERC20 asset_) internal onlyInitializing {
ERC4626Storage storage $ = _getERC4626Storage();
(bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
$._underlyingDecimals = success ? assetDecimals : 18;
$._asset = asset_;
}
/**
* @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
*/
function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool ok, uint8 assetDecimals) {
(bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
abi.encodeCall(IERC20Metadata.decimals, ())
);
if (success && encodedDecimals.length >= 32) {
uint256 returnedDecimals = abi.decode(encodedDecimals, (uint256));
if (returnedDecimals <= type(uint8).max) {
return (true, uint8(returnedDecimals));
}
}
return (false, 0);
}
/**
* @dev Decimals are computed by adding the decimal offset on top of the underlying asset's decimals. This
* "original" value is cached during construction of the vault contract. If this read operation fails (e.g., the
* asset has not been created yet), a default of 18 is used to represent the underlying asset's decimals.
*
* See {IERC20Metadata-decimals}.
*/
function decimals() public view virtual override(IERC20Metadata, ERC20Upgradeable) returns (uint8) {
ERC4626Storage storage $ = _getERC4626Storage();
return $._underlyingDecimals + _decimalsOffset();
}
/** @dev See {IERC4626-asset}. */
function asset() public view virtual returns (address) {
ERC4626Storage storage $ = _getERC4626Storage();
return address($._asset);
}
/** @dev See {IERC4626-totalAssets}. */
function totalAssets() public view virtual returns (uint256) {
ERC4626Storage storage $ = _getERC4626Storage();
return $._asset.balanceOf(address(this));
}
/** @dev See {IERC4626-convertToShares}. */
function convertToShares(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Floor);
}
/** @dev See {IERC4626-convertToAssets}. */
function convertToAssets(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Floor);
}
/** @dev See {IERC4626-maxDeposit}. */
function maxDeposit(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/** @dev See {IERC4626-maxMint}. */
function maxMint(address) public view virtual returns (uint256) {
return type(uint256).max;
}
/** @dev See {IERC4626-maxWithdraw}. */
function maxWithdraw(address owner) public view virtual returns (uint256) {
return _convertToAssets(balanceOf(owner), Math.Rounding.Floor);
}
/** @dev See {IERC4626-maxRedeem}. */
function maxRedeem(address owner) public view virtual returns (uint256) {
return balanceOf(owner);
}
/** @dev See {IERC4626-previewDeposit}. */
function previewDeposit(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Floor);
}
/** @dev See {IERC4626-previewMint}. */
function previewMint(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Ceil);
}
/** @dev See {IERC4626-previewWithdraw}. */
function previewWithdraw(uint256 assets) public view virtual returns (uint256) {
return _convertToShares(assets, Math.Rounding.Ceil);
}
/** @dev See {IERC4626-previewRedeem}. */
function previewRedeem(uint256 shares) public view virtual returns (uint256) {
return _convertToAssets(shares, Math.Rounding.Floor);
}
/** @dev See {IERC4626-deposit}. */
function deposit(uint256 assets, address receiver) public virtual returns (uint256) {
uint256 maxAssets = maxDeposit(receiver);
if (assets > maxAssets) {
revert ERC4626ExceededMaxDeposit(receiver, assets, maxAssets);
}
uint256 shares = previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);
return shares;
}
/** @dev See {IERC4626-mint}. */
function mint(uint256 shares, address receiver) public virtual returns (uint256) {
uint256 maxShares = maxMint(receiver);
if (shares > maxShares) {
revert ERC4626ExceededMaxMint(receiver, shares, maxShares);
}
uint256 assets = previewMint(shares);
_deposit(_msgSender(), receiver, assets, shares);
return assets;
}
/** @dev See {IERC4626-withdraw}. */
function withdraw(uint256 assets, address receiver, address owner) public virtual returns (uint256) {
uint256 maxAssets = maxWithdraw(owner);
if (assets > maxAssets) {
revert ERC4626ExceededMaxWithdraw(owner, assets, maxAssets);
}
uint256 shares = previewWithdraw(assets);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return shares;
}
/** @dev See {IERC4626-redeem}. */
function redeem(uint256 shares, address receiver, address owner) public virtual returns (uint256) {
uint256 maxShares = maxRedeem(owner);
if (shares > maxShares) {
revert ERC4626ExceededMaxRedeem(owner, shares, maxShares);
}
uint256 assets = previewRedeem(shares);
_withdraw(_msgSender(), receiver, owner, assets, shares);
return assets;
}
/**
* @dev Internal conversion function (from assets to shares) with support for rounding direction.
*/
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
}
/**
* @dev Internal conversion function (from shares to assets) with support for rounding direction.
*/
function _convertToAssets(uint256 shares, Math.Rounding rounding) internal view virtual returns (uint256) {
return shares.mulDiv(totalAssets() + 1, totalSupply() + 10 ** _decimalsOffset(), rounding);
}
/**
* @dev Deposit/mint common workflow.
*/
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual {
ERC4626Storage storage $ = _getERC4626Storage();
// If _asset is ERC-777, `transferFrom` can trigger a reentrancy BEFORE the transfer happens through the
// `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer,
// calls the vault, which is assumed not malicious.
//
// Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the
// assets are transferred and before the shares are minted, which is a valid state.
// slither-disable-next-line reentrancy-no-eth
SafeERC20.safeTransferFrom($._asset, caller, address(this), assets);
_mint(receiver, shares);
emit Deposit(caller, receiver, assets, shares);
}
/**
* @dev Withdraw/redeem common workflow.
*/
function _withdraw(
address caller,
address receiver,
address owner,
uint256 assets,
uint256 shares
) internal virtual {
ERC4626Storage storage $ = _getERC4626Storage();
if (caller != owner) {
_spendAllowance(owner, caller, shares);
}
// If _asset is ERC-777, `transfer` can trigger a reentrancy AFTER the transfer happens through the
// `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer,
// calls the vault, which is assumed not malicious.
//
// Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the
// shares are burned and after the assets are transferred, which is a valid state.
_burn(owner, shares);
SafeERC20.safeTransfer($._asset, receiver, assets);
emit Withdraw(caller, receiver, owner, assets, shares);
}
function _decimalsOffset() internal view virtual returns (uint8) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Pausable
struct PausableStorage {
bool _paused;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;
function _getPausableStorage() private pure returns (PausableStorage storage $) {
assembly {
$.slot := PausableStorageLocation
}
}
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal onlyInitializing {
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
PausableStorage storage $ = _getPausableStorage();
return $._paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
PausableStorage storage $ = _getPausableStorage();
$._paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
abstract contract Auth {
event OwnershipTransferred(address indexed user, address indexed newOwner);
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
address public owner;
Authority public authority;
constructor(address _owner, Authority _authority) {
owner = _owner;
authority = _authority;
emit OwnershipTransferred(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}
modifier requiresAuth() virtual {
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
_;
}
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner;
}
function setAuthority(Authority newAuthority) public virtual {
// We check if the caller is the owner first because we want to ensure they can
// always swap out the authority even if it's reverting or using up a lot of gas.
require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig));
authority = newAuthority;
emit AuthorityUpdated(msg.sender, newAuthority);
}
function transferOwnership(address newOwner) public virtual requiresAuth {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
function canCall(
address user,
address target,
bytes4 functionSig
) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}// 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/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/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) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC-20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC-721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC-1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// 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.2.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {ContextUpgradeable} from "../../utils/ContextUpgradeable.sol";
import {IERC20Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC-20
* applications.
*/
abstract contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20, IERC20Metadata, IERC20Errors {
/// @custom:storage-location erc7201:openzeppelin.storage.ERC20
struct ERC20Storage {
mapping(address account => uint256) _balances;
mapping(address account => mapping(address spender => uint256)) _allowances;
uint256 _totalSupply;
string _name;
string _symbol;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ERC20")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ERC20StorageLocation = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00;
function _getERC20Storage() private pure returns (ERC20Storage storage $) {
assembly {
$.slot := ERC20StorageLocation
}
}
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing {
__ERC20_init_unchained(name_, symbol_);
}
function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing {
ERC20Storage storage $ = _getERC20Storage();
$._name = name_;
$._symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
ERC20Storage storage $ = _getERC20Storage();
return $._symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
ERC20Storage storage $ = _getERC20Storage();
return $._allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Skips emitting an {Approval} event indicating an allowance update. This is not
* required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
$._totalSupply += value;
} else {
uint256 fromBalance = $._balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
$._balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
$._totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
$._balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
*
* ```solidity
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
ERC20Storage storage $ = _getERC20Storage();
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
$._allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance < type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// 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.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.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);
}{
"remappings": [
"@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"@openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"@solmate/=node_modules/solmate/src/",
"forge-std/=node_modules/forge-std/src/",
"solmate/=node_modules/solmate/"
],
"optimizer": {
"enabled": true,
"runs": 1000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "shanghai",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxDeposit","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxMint","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxRedeem","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"ERC4626ExceededMaxWithdraw","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","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":"InsufficientShares","type":"error"},{"inputs":[],"name":"InvalidAssetsAmount","type":"error"},{"inputs":[],"name":"InvalidFee","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidPrice","type":"error"},{"inputs":[],"name":"InvalidSharesAmount","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"NotSharesOwner","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"SharesAmountZero","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes4","name":"functionSig","type":"bytes4"}],"name":"TargetMethodNotAuthorized","type":"error"},{"inputs":[],"name":"UseRequestRedeem","type":"error"},{"inputs":[],"name":"ZeroReceiver","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"AuthorityUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"lastFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"DepositFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"lastFeeRecipient","type":"address"},{"indexed":false,"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"FeeRecipientUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"lastMaxPercentage","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newMaxPercentage","type":"uint256"}],"name":"MaxPercentageUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Received","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":true,"internalType":"bool","name":"instant","type":"bool"}],"name":"RedeemRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"RequestCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"RequestFulfilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"lastUnderlyingBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newUnderlyingBalance","type":"uint256"}],"name":"UnderlyingBalanceUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"lastFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"WithdrawFeeUpdated","type":"event"},{"inputs":[],"name":"ORACLE_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"authority","outputs":[{"internalType":"contract Authority","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"assetsWithFee","type":"uint256"}],"name":"cancelRedeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeOnDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeOnWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"uint256","name":"assetsWithFee","type":"uint256"}],"name":"fulfillRedeem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_asset","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"bytes4","name":"functionSig","type":"bytes4"}],"name":"isAuthorized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastPricePerShare","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"targets","type":"address[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"},{"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"manage","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"manage","outputs":[{"internalType":"bytes","name":"result","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"pendingRedeemRequest","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"pendingShares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"requestRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"setAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalPendingAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"updateDepositFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newFeeRecipient","type":"address"}],"name":"updateFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"updateWithdrawFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
6080604052348015600e575f5ffd5b5060156019565b60c9565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff161560685760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b039081161460c65780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b613f95806100d65f395ff3fe608060405260043610610332575f3560e01c80637d41c86e116101a7578063c63d75b6116100e7578063dd62ed3e11610092578063f23a6e611161006d578063f23a6e6114610ab2578063f2fde38b14610af7578063f6e715d014610b16578063fcfc430c14610b35575f5ffd5b8063dd62ed3e14610a11578063ef8b30f714610a74578063f160d36914610a93575f5ffd5b8063d905777e116100c2578063d905777e146109b4578063d9972b96146109d3578063daf635de146109f2575f5ffd5b8063c63d75b614610603578063c6e6f59214610976578063ce96cb7714610995575f5ffd5b8063ab4f0f0111610152578063b460af941161012d578063b460af94146108b5578063ba087652146108d4578063bc197c81146108f3578063bf7e214f1461093a575f5ffd5b8063ab4f0f011461086d578063ac9dc9e814610882578063b3d7f6b914610896575f5ffd5b806394bf804d1161018257806394bf804d1461081b57806395d89b411461083a578063a9059cbb1461084e575f5ffd5b80637d41c86e146107ac5780638456cb59146107cb5780638da5cb5b146107df575f5ffd5b8063313ce5671161027257806353dc1dd31161021d5780636442b2ba116101f85780636442b2ba146106fc5780636e553f651461071b57806370a082311461073a5780637a9e5e4b1461078d575f5ffd5b806353dc1dd314610660578063543610c6146106b15780635c975abb146106c6575f5ffd5b8063402d267d1161024d578063402d267d1461060357806346904840146106225780634cdad50614610641575f5ffd5b8063313ce5671461057957806338d52e0f1461059f5780633f4ba83a146105ef575f5ffd5b8063150b7a02116102dd5780631cd1c8c3116102b85780631cd1c8c3146104f05780632016a0d21461050f578063224d87031461052e57806323b872dd1461055a575f5ffd5b8063150b7a021461044b57806318160ddd146104a85780631a4a6ad6146104db575f5ffd5b806307a2d13a1161030d57806307a2d13a146103de578063095ea7b3146103fd5780630a28a4771461042c575f5ffd5b8063017def571461037557806301e1d1141461039657806306fdde03146103bd575f5ffd5b3661037157604080513381523460208201527f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f88525874910160405180910390a1005b5f5ffd5b348015610380575f5ffd5b5061039461038f3660046134cc565b610b5c565b005b3480156103a1575f5ffd5b506103aa610c1a565b6040519081526020015b60405180910390f35b3480156103c8575f5ffd5b506103d1610cde565b6040516103b49190613530565b3480156103e9575f5ffd5b506103aa6103f83660046134cc565b610db1565b348015610408575f5ffd5b5061041c610417366004613556565b610dc2565b60405190151581526020016103b4565b348015610437575f5ffd5b506103aa6104463660046134cc565b610dd9565b348015610456575f5ffd5b5061048f6104653660046135c5565b7f150b7a020000000000000000000000000000000000000000000000000000000095945050505050565b6040516001600160e01b031990911681526020016103b4565b3480156104b3575f5ffd5b507f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02546103aa565b3480156104e6575f5ffd5b506103aa60055481565b3480156104fb575f5ffd5b5061039461050a366004613633565b610e02565b34801561051a575f5ffd5b50610394610529366004613704565b610f67565b348015610539575f5ffd5b5061054d6105483660046137ce565b6110c9565b6040516103b4919061386d565b348015610565575f5ffd5b5061041c6105743660046138d0565b6113c7565b348015610584575f5ffd5b5061058d6113ea565b60405160ff90911681526020016103b4565b3480156105aa575f5ffd5b507f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b03165b6040516001600160a01b0390911681526020016103b4565b3480156105fa575f5ffd5b50610394611426565b34801561060e575f5ffd5b506103aa61061d36600461390e565b611480565b34801561062d575f5ffd5b506007546105d7906001600160a01b031681565b34801561064c575f5ffd5b506103aa61065b3660046134cc565b6114bf565b34801561066b575f5ffd5b5061069c61067a36600461390e565b6001600160a01b03165f90815260086020526040902080546001909101549091565b604080519283526020830191909152016103b4565b3480156106bc575f5ffd5b506103aa60065481565b3480156106d1575f5ffd5b507fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1661041c565b348015610707575f5ffd5b50610394610716366004613633565b6114e2565b348015610726575f5ffd5b506103aa610735366004613929565b611643565b348015610745575f5ffd5b506103aa61075436600461390e565b6001600160a01b03165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00602052604090205490565b348015610798575f5ffd5b506103946107a736600461390e565b611656565b3480156107b7575f5ffd5b506103aa6107c6366004613957565b611763565b3480156107d6575f5ffd5b506103946119d7565b3480156107ea575f5ffd5b507fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea00546001600160a01b03166105d7565b348015610826575f5ffd5b506103aa610835366004613929565b611a2f565b348015610845575f5ffd5b506103d1611a42565b348015610859575f5ffd5b5061041c610868366004613556565b611a93565b348015610878575f5ffd5b506103aa60035481565b34801561088d575f5ffd5b506103aa611aa0565b3480156108a1575f5ffd5b506103aa6108b03660046134cc565b611b42565b3480156108c0575f5ffd5b506103aa6108cf366004613957565b611b65565b3480156108df575f5ffd5b506103aa6108ee366004613957565b611ba0565b3480156108fe575f5ffd5b5061048f61090d366004613996565b7fbc197c810000000000000000000000000000000000000000000000000000000098975050505050505050565b348015610945575f5ffd5b507fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01546001600160a01b03166105d7565b348015610981575f5ffd5b506103aa6109903660046134cc565b611bbc565b3480156109a0575f5ffd5b506103aa6109af36600461390e565b611bc7565b3480156109bf575f5ffd5b506103aa6109ce36600461390e565b611c08565b3480156109de575f5ffd5b5061041c6109ed366004613a59565b611c49565b3480156109fd575f5ffd5b50610394610a0c3660046134cc565b611d40565b348015610a1c575f5ffd5b506103aa610a2b366004613a91565b6001600160a01b039182165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020908152604080832093909416825291909152205490565b348015610a7f575f5ffd5b506103aa610a8e3660046134cc565b611df9565b348015610a9e575f5ffd5b50610394610aad36600461390e565b611e16565b348015610abd575f5ffd5b5061048f610acc366004613abd565b7ff23a6e61000000000000000000000000000000000000000000000000000000009695505050505050565b348015610b02575f5ffd5b50610394610b1136600461390e565b611ecf565b348015610b21575f5ffd5b506103d1610b30366004613b22565b611f89565b348015610b40575f5ffd5b506105d7736e879d0ccc85085a709ebf5539224f53d0d396b081565b610b71335f356001600160e01b031916611c49565b610bb15760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b67016345785d8a00008110610bd9576040516358d620b360e01b815260040160405180910390fd5b60065460408051918252602082018390527f828cf983933545af35b9ba46eec951db1cb4c5433c3ec403aeced2963c264790910160405180910390a1600655565b6040516302c68be360e31b81523060048201525f908190736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa158015610c6a573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c8e9190613b7a565b509050610cd8610cbc7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace025490565b610cc46113ea565b610ccf90600a613ca1565b8391905f61212b565b91505090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0380546060917f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0091610d2f90613caf565b80601f0160208091040260200160405190810160405280929190818152602001828054610d5b90613caf565b8015610da65780601f10610d7d57610100808354040283529160200191610da6565b820191905f5260205f20905b815481529060010190602001808311610d8957829003601f168201915b505050505091505090565b5f610dbc825f61216d565b92915050565b5f33610dcf818585612223565b5060019392505050565b5f5f610de783600554612235565b9050610dfb610df68285613ce7565b61224b565b9392505050565b610e17335f356001600160e01b031916611c49565b610e525760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b6001600160a01b0383165f908152600860205260409020600181015415801590610e80575080600101548311155b610e9c5760405162f1a34760e11b815260040160405180910390fd5b805415801590610ead575080548211155b610eca57604051633b83271360e01b815260040160405180910390fd5b82816001015f828254610edd9190613cfa565b90915550508054829082905f90610ef5908490613cfa565b925050819055508160035f828254610f0d9190613cfa565b909155505060408051848152602081018490526001600160a01b038616917f55ec94ca0f01023d07c5752a75f44048cfbdb0e4cfedf5e7eacecf21fcde3587910160405180910390a2610f61308585612257565b50505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000810460ff16159067ffffffffffffffff165f81158015610fb15750825b90505f8267ffffffffffffffff166001148015610fcd5750303b155b905081158015610fdb575080155b15611012576040517ff92ee8a900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561104657845468ff00000000000000001916680100000000000000001785555b61104e6122b4565b61105887876122bc565b611061896122d2565b61106b885f6122e6565b6110736123be565b83156110be57845468ff000000000000000019168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050505050565b60606110e0335f356001600160e01b031916611c49565b61111b5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b858067ffffffffffffffff81111561113557611135613665565b60405190808252806020026020018201604052801561116857816020015b60608152602001906001900390816111535790505b5091505f5b818110156113bb575f87878381811061118857611188613d0d565b905060200281019061119a9190613d21565b6111a391613d64565b90506111d67fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01546001600160a01b031690565b6001600160a01b031663b7009613338c8c868181106111f7576111f7613d0d565b905060200201602081019061120c919061390e565b6040516001600160e01b031960e085901b811682526001600160a01b0393841660048301529290911660248201529084166044820152606401602060405180830381865afa158015611260573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112849190613d9a565b8a8a8481811061129657611296613d0d565b90506020020160208101906112ab919061390e565b8290916112e657604051637dab181360e11b81526001600160a01b0390921660048301526001600160e01b0319166024820152604401610ba8565b50506113958888848181106112fd576112fd613d0d565b905060200281019061130f9190613d21565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152508a925089915086905081811061135757611357613d0d565b905060200201358c8c8681811061137057611370613d0d565b9050602002016020810190611385919061390e565b6001600160a01b031691906123ce565b8483815181106113a7576113a7613d0d565b60209081029190910101525060010161116d565b50509695505050505050565b5f336113d485828561247d565b6113df858585612257565b506001949350505050565b5f807f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0090505f8154610cd89190600160a01b900460ff16613db9565b61143b335f356001600160e01b031916611c49565b6114765760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b61147e61252b565b565b5f6114ac7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1690565b156114b857505f919050565b5f19610dbc565b5f5f6114ca83610db1565b90506114d88160055461259d565b610dfb9082613cfa565b6114f7335f356001600160e01b031916611c49565b6115325760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b6001600160a01b0383165f908152600860205260409020600181015415801590611560575080600101548311155b61157c5760405162f1a34760e11b815260040160405180910390fd5b80541580159061158d575080548211155b6115aa57604051633b83271360e01b815260040160405180910390fd5b82816001015f8282546115bd9190613cfa565b90915550508054829082905f906115d5908490613cfa565b925050819055508160035f8282546115ed9190613cfa565b909155505060408051848152602081018490526001600160a01b038616917f1165aa98d42fbaef9bacc273d7b5cca8edc94909519f8f949ec33562963c87e4910160405180910390a2610f6130853085876125be565b5f61164c612660565b610dfb83836126bc565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0080546001600160a01b031633148061170d5750600181015460405163b700961360e01b81523360048201523060248201525f356001600160e01b03191660448201526001600160a01b039091169063b700961390606401602060405180830381865afa1580156116e9573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061170d9190613d9a565b611715575f5ffd5b6001810180546001600160a01b0319166001600160a01b03841690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a35050565b5f61176c612660565b6001600160a01b0383166117ac576040517f6ba9ecd800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f84116117e5576040517f840c364a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0382163314611827576040517fe7fe5cf400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b83611865836001600160a01b03165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00602052604090205490565b101561189d576040517f3999656700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6118a785610db1565b9050806118b2612734565b10611917576118c483858584896125be565b60408051828152602081018790526001916001600160a01b0380871692908816917f9a626d8a4952950c7f8b9f5c92a2804e44e147ce4dd0add2f5928f1faea72590910160405180910390a49050610dfb565b60408051828152602081018790525f916001600160a01b0380871692908816917f9a626d8a4952950c7f8b9f5c92a2804e44e147ce4dd0add2f5928f1faea72590910160405180910390a461196d833087612257565b8060035f82825461197e9190613ce7565b90915550506001600160a01b0384165f908152600860205260408120600181018054919288926119af908490613ce7565b90915550508054829082905f906119c7908490613ce7565b909155505f979650505050505050565b6119ec335f356001600160e01b031916611c49565b611a275760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b61147e612806565b5f611a38612660565b610dfb8383612861565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0480546060917f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0091610d2f90613caf565b5f33610dcf818585612257565b6040516302c68be360e31b81523060048201525f90736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa158015611aee573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b129190613b7a565b509050611b1d6113ea565b611b28906012613dd2565b611b3390600a613ca1565b611b3d9082613deb565b905090565b5f5f611b4d836128d9565b9050611b5b81600654612235565b610dfb9082613ce7565b5f611b6e612660565b6040517f797f246a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611ba9612660565b611bb4848484611763565b949350505050565b5f610dbc825f6128e5565b5f611bf37fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1690565b15611bff57505f919050565b610dbc8261299a565b5f611c347fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1690565b15611c4057505f919050565b610dbc826129db565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01545f907fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea00906001600160a01b03168015801590611d20575060405163b700961360e01b81526001600160a01b0386811660048301523060248301526001600160e01b03198616604483015282169063b700961390606401602060405180830381865afa158015611cfc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d209190613d9a565b80611d37575081546001600160a01b038681169116145b95945050505050565b611d55335f356001600160e01b031916611c49565b611d905760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b67016345785d8a00008110611db8576040516358d620b360e01b815260040160405180910390fd5b60055460408051918252602082018390527f733071ab8253b372ed26a6d1b04aec71c4bfcd209c93397df32bb77478cdd2c8910160405180910390a1600555565b5f5f611e078360065461259d565b9050610dfb6109908285613cfa565b611e2b335f356001600160e01b031916611c49565b611e665760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b600754604080516001600160a01b03928316815291831660208301527faaebcf1bfa00580e41d966056b48521fa9f202645c86d4ddf28113e617c1b1d3910160405180910390a1600780546001600160a01b0319166001600160a01b0392909216919091179055565b611ee4335f356001600160e01b031916611c49565b611f1f5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0080546001600160a01b0319166001600160a01b038316908117825560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b6060611fa0335f356001600160e01b031916611c49565b611fdb5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b5f611fe68486613d64565b90506120197fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01546001600160a01b031690565b60405163b700961360e01b81523360048201526001600160a01b0388811660248301526001600160e01b031984166044830152919091169063b700961390606401602060405180830381865afa158015612075573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120999190613d9a565b868290916120d557604051637dab181360e11b81526001600160a01b0390921660048301526001600160e01b0319166024820152604401610ba8565b505061212185858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525050506001600160a01b038916919050856123ce565b9695505050505050565b5f61215861213883612a17565b801561215357505f848061214e5761214e613e02565b868809115b151590565b612163868686612a43565b611d379190613ce7565b6040516302c68be360e31b81523060048201525f908190736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa1580156121bd573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121e19190613b7a565b5090505f81116122035760405162bfc92160e01b815260040160405180910390fd5b611bb48161220f6113ea565b61221a90600a613ca1565b8691908661212b565b6122308383836001612af9565b505050565b5f610dfb8383670de0b6b3a7640000600161212b565b5f610dbc8260016128e5565b6001600160a01b03831661228057604051634b637e8f60e11b81525f6004820152602401610ba8565b6001600160a01b0382166122a95760405163ec442f0560e01b81525f6004820152602401610ba8565b612230838383612c22565b61147e612c35565b6122c4612c35565b6122ce8282612c9c565b5050565b6122da612c35565b6122e381612cff565b50565b6122ee612c35565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0080546001600160a01b03199081166001600160a01b0385811691821784557fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0180549093169085161790915560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a36040516001600160a01b0383169033907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a3505050565b6123c6612c35565b61147e612d9a565b606081471015612413576040517fcf47918100000000000000000000000000000000000000000000000000000000815247600482015260248101839052604401610ba8565b5f5f856001600160a01b0316848660405161242e9190613e16565b5f6040518083038185875af1925050503d805f8114612468576040519150601f19603f3d011682016040523d82523d5f602084013e61246d565b606091505b5091509150612121868383612dcd565b6001600160a01b038381165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160209081526040808320938616835292905220545f19811015610f61578181101561251d576040517ffb8f41b20000000000000000000000000000000000000000000000000000000081526001600160a01b03841660048201526024810182905260448101839052606401610ba8565b610f6184848484035f612af9565b612533612e42565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a150565b5f610dfb826125b4670de0b6b3a764000082613ce7565b859190600161212b565b5f6125cb8360055461259d565b90505f6125d88285613cfa565b6007549091506001600160a01b03166125f48888888588612e9d565b5f8311801561260b57506001600160a01b03811615155b156126565761265681846126467f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b6001600160a01b03169190612f64565b5050505050505050565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff161561147e576040517fd93c066500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5f6126c783611480565b90508084111561271c576040517f79012fb20000000000000000000000000000000000000000000000000000000081526001600160a01b03841660048201526024810185905260448101829052606401610ba8565b5f61272685611df9565b9050611bb433858784612fd8565b5f5f6127677f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156127c4573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127e89190613e31565b905060035481116127f9575f610cd8565b600354610cd89082613cfa565b61280e612660565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2583361257f565b5f5f61286c83611480565b9050808411156128c1576040517f284ff6670000000000000000000000000000000000000000000000000000000081526001600160a01b03841660048201526024810185905260448101829052606401610ba8565b5f6128cb85611b42565b9050611bb433858388612fd8565b5f610dbc82600161216d565b6040516302c68be360e31b81523060048201525f908190736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa158015612935573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129599190613b7a565b5090505f811161297b5760405162bfc92160e01b815260040160405180910390fd5b611bb46129866113ea565b61299190600a613ca1565b8590838661212b565b6001600160a01b0381165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006020526040812054610dbc905f61216d565b6001600160a01b0381165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006020526040812054610dbc565b5f6002826003811115612a2c57612a2c613e48565b612a369190613e5c565b60ff166001149050919050565b5f838302815f1985870982811083820303915050805f03612a7757838281612a6d57612a6d613e02565b0492505050610dfb565b808411612a8e57612a8e600385150260111861305a565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006001600160a01b038516612b5c576040517fe602df050000000000000000000000000000000000000000000000000000000081525f6004820152602401610ba8565b6001600160a01b038416612b9e576040517f94280d620000000000000000000000000000000000000000000000000000000081525f6004820152602401610ba8565b6001600160a01b038086165f90815260018301602090815260408083209388168352929052208390558115612c1b57836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92585604051612c1291815260200190565b60405180910390a35b5050505050565b612c2a612660565b61223083838361306b565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005468010000000000000000900460ff1661147e576040517fd7e6bcf800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612ca4612c35565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace007f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace03612cf08482613ecd565b5060048101610f618382613ecd565b612d07612c35565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e005f80612d33846131d0565b9150915081612d43576012612d45565b805b83547fffffffffffffffffffffff00000000000000000000000000000000000000000016600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b612da2612c35565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300805460ff19169055565b606082612de257612ddd826132d4565b610dfb565b8151158015612df957506001600160a01b0384163b155b15612e3b576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610ba8565b5080610dfb565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1661147e576040517f8dfc202b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e006001600160a01b0386811690851614612edc57612edc84878461247d565b612ee68483613316565b8054612efc906001600160a01b03168685612f64565b836001600160a01b0316856001600160a01b0316876001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8686604051612f54929190918252602082015260400190565b60405180910390a4505050505050565b6040516001600160a01b0383811660248301526044820183905261223091859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061334a565b5f612fe58360065461259d565b6007549091506001600160a01b0316613000868686866133cf565b5f8211801561301757506001600160a01b03811615155b156130525761305281836126467f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b505050505050565b634e487b715f52806020526024601cfd5b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006001600160a01b0384166130b85781816002015f8282546130ad9190613ce7565b909155506131419050565b6001600160a01b0384165f9081526020829052604090205482811015613123576040517fe450d38c0000000000000000000000000000000000000000000000000000000081526001600160a01b03861660048201526024810182905260448101849052606401610ba8565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b03831661315f57600281018054839003905561317d565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516131c291815260200190565b60405180910390a350505050565b60408051600481526024810182526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f313ce5670000000000000000000000000000000000000000000000000000000017905290515f918291829182916001600160a01b0387169161324491613e16565b5f60405180830381855afa9150503d805f811461327c576040519150601f19603f3d011682016040523d82523d5f602084013e613281565b606091505b509150915081801561329557506020815110155b156132c8575f818060200190518101906132af9190613e31565b905060ff81116132c6576001969095509350505050565b505b505f9485945092505050565b8051156132e45780518082602001fd5b6040517fd6bda27500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03821661333f57604051634b637e8f60e11b81525f6004820152602401610ba8565b6122ce825f83612c22565b5f5f60205f8451602086015f885af180613369576040513d5f823e3d81fd5b50505f513d9150811561338057806001141561338d565b6001600160a01b0384163b155b15610f61576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610ba8565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e008054613407906001600160a01b031686308661345f565b6134118483613498565b836001600160a01b0316856001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78585604051612c12929190918252602082015260400190565b6040516001600160a01b038481166024830152838116604483015260648201839052610f619186918216906323b872dd90608401612f91565b6001600160a01b0382166134c15760405163ec442f0560e01b81525f6004820152602401610ba8565b6122ce5f8383612c22565b5f602082840312156134dc575f5ffd5b5035919050565b5f5b838110156134fd5781810151838201526020016134e5565b50505f910152565b5f815180845261351c8160208601602086016134e3565b601f01601f19169290920160200192915050565b602081525f610dfb6020830184613505565b6001600160a01b03811681146122e3575f5ffd5b5f5f60408385031215613567575f5ffd5b823561357281613542565b946020939093013593505050565b5f5f83601f840112613590575f5ffd5b50813567ffffffffffffffff8111156135a7575f5ffd5b6020830191508360208285010111156135be575f5ffd5b9250929050565b5f5f5f5f5f608086880312156135d9575f5ffd5b85356135e481613542565b945060208601356135f481613542565b935060408601359250606086013567ffffffffffffffff811115613616575f5ffd5b61362288828901613580565b969995985093965092949392505050565b5f5f5f60608486031215613645575f5ffd5b833561365081613542565b95602085013595506040909401359392505050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f830112613688575f5ffd5b813567ffffffffffffffff8111156136a2576136a2613665565b604051601f8201601f19908116603f0116810167ffffffffffffffff811182821017156136d1576136d1613665565b6040528181528382016020018510156136e8575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f5f5f5f60808587031215613717575f5ffd5b843561372281613542565b9350602085013561373281613542565b9250604085013567ffffffffffffffff81111561374d575f5ffd5b61375987828801613679565b925050606085013567ffffffffffffffff811115613775575f5ffd5b61378187828801613679565b91505092959194509250565b5f5f83601f84011261379d575f5ffd5b50813567ffffffffffffffff8111156137b4575f5ffd5b6020830191508360208260051b85010111156135be575f5ffd5b5f5f5f5f5f5f606087890312156137e3575f5ffd5b863567ffffffffffffffff8111156137f9575f5ffd5b61380589828a0161378d565b909750955050602087013567ffffffffffffffff811115613824575f5ffd5b61383089828a0161378d565b909550935050604087013567ffffffffffffffff81111561384f575f5ffd5b61385b89828a0161378d565b979a9699509497509295939492505050565b5f602082016020835280845180835260408501915060408160051b8601019250602086015f5b828110156138c457603f198786030184526138af858351613505565b94506020938401939190910190600101613893565b50929695505050505050565b5f5f5f606084860312156138e2575f5ffd5b83356138ed81613542565b925060208401356138fd81613542565b929592945050506040919091013590565b5f6020828403121561391e575f5ffd5b8135610dfb81613542565b5f5f6040838503121561393a575f5ffd5b82359150602083013561394c81613542565b809150509250929050565b5f5f5f60608486031215613969575f5ffd5b83359250602084013561397b81613542565b9150604084013561398b81613542565b809150509250925092565b5f5f5f5f5f5f5f5f60a0898b0312156139ad575f5ffd5b88356139b881613542565b975060208901356139c881613542565b9650604089013567ffffffffffffffff8111156139e3575f5ffd5b6139ef8b828c0161378d565b909750955050606089013567ffffffffffffffff811115613a0e575f5ffd5b613a1a8b828c0161378d565b909550935050608089013567ffffffffffffffff811115613a39575f5ffd5b613a458b828c01613580565b999c989b5096995094979396929594505050565b5f5f60408385031215613a6a575f5ffd5b8235613a7581613542565b915060208301356001600160e01b03198116811461394c575f5ffd5b5f5f60408385031215613aa2575f5ffd5b8235613aad81613542565b9150602083013561394c81613542565b5f5f5f5f5f5f60a08789031215613ad2575f5ffd5b8635613add81613542565b95506020870135613aed81613542565b94506040870135935060608701359250608087013567ffffffffffffffff811115613b16575f5ffd5b61385b89828a01613580565b5f5f5f5f60608587031215613b35575f5ffd5b8435613b4081613542565b9350602085013567ffffffffffffffff811115613b5b575f5ffd5b613b6787828801613580565b9598909750949560400135949350505050565b5f5f60408385031215613b8b575f5ffd5b8251602084015190925067ffffffffffffffff8116811461394c575f5ffd5b634e487b7160e01b5f52601160045260245ffd5b6001815b6001841115613bf957808504811115613bdd57613bdd613baa565b6001841615613beb57908102905b60019390931c928002613bc2565b935093915050565b5f82613c0f57506001610dbc565b81613c1b57505f610dbc565b8160018114613c315760028114613c3b57613c57565b6001915050610dbc565b60ff841115613c4c57613c4c613baa565b50506001821b610dbc565b5060208310610133831016604e8410600b8410161715613c7a575081810a610dbc565b613c865f198484613bbe565b805f1904821115613c9957613c99613baa565b029392505050565b5f610dfb60ff841683613c01565b600181811c90821680613cc357607f821691505b602082108103613ce157634e487b7160e01b5f52602260045260245ffd5b50919050565b80820180821115610dbc57610dbc613baa565b81810381811115610dbc57610dbc613baa565b634e487b7160e01b5f52603260045260245ffd5b5f5f8335601e19843603018112613d36575f5ffd5b83018035915067ffffffffffffffff821115613d50575f5ffd5b6020019150368190038213156135be575f5ffd5b80356001600160e01b03198116906004841015613d93576001600160e01b0319808560040360031b1b82161691505b5092915050565b5f60208284031215613daa575f5ffd5b81518015158114610dfb575f5ffd5b60ff8181168382160190811115610dbc57610dbc613baa565b60ff8281168282160390811115610dbc57610dbc613baa565b8082028115828204841417610dbc57610dbc613baa565b634e487b7160e01b5f52601260045260245ffd5b5f8251613e278184602087016134e3565b9190910192915050565b5f60208284031215613e41575f5ffd5b5051919050565b634e487b7160e01b5f52602160045260245ffd5b5f60ff831680613e7a57634e487b7160e01b5f52601260045260245ffd5b8060ff84160691505092915050565b601f82111561223057805f5260205f20601f840160051c81016020851015613eae5750805b601f840160051c820191505b81811015612c1b575f8155600101613eba565b815167ffffffffffffffff811115613ee757613ee7613665565b613efb81613ef58454613caf565b84613e89565b6020601f821160018114613f2d575f8315613f165750848201515b5f19600385901b1c1916600184901b178455612c1b565b5f84815260208120601f198516915b82811015613f5c5787850151825560209485019460019092019101613f3c565b5084821015613f7957868401515f19600387901b60f8161c191681555b50505050600190811b0190555056fea164736f6c634300081c000a
Deployed Bytecode
0x608060405260043610610332575f3560e01c80637d41c86e116101a7578063c63d75b6116100e7578063dd62ed3e11610092578063f23a6e611161006d578063f23a6e6114610ab2578063f2fde38b14610af7578063f6e715d014610b16578063fcfc430c14610b35575f5ffd5b8063dd62ed3e14610a11578063ef8b30f714610a74578063f160d36914610a93575f5ffd5b8063d905777e116100c2578063d905777e146109b4578063d9972b96146109d3578063daf635de146109f2575f5ffd5b8063c63d75b614610603578063c6e6f59214610976578063ce96cb7714610995575f5ffd5b8063ab4f0f0111610152578063b460af941161012d578063b460af94146108b5578063ba087652146108d4578063bc197c81146108f3578063bf7e214f1461093a575f5ffd5b8063ab4f0f011461086d578063ac9dc9e814610882578063b3d7f6b914610896575f5ffd5b806394bf804d1161018257806394bf804d1461081b57806395d89b411461083a578063a9059cbb1461084e575f5ffd5b80637d41c86e146107ac5780638456cb59146107cb5780638da5cb5b146107df575f5ffd5b8063313ce5671161027257806353dc1dd31161021d5780636442b2ba116101f85780636442b2ba146106fc5780636e553f651461071b57806370a082311461073a5780637a9e5e4b1461078d575f5ffd5b806353dc1dd314610660578063543610c6146106b15780635c975abb146106c6575f5ffd5b8063402d267d1161024d578063402d267d1461060357806346904840146106225780634cdad50614610641575f5ffd5b8063313ce5671461057957806338d52e0f1461059f5780633f4ba83a146105ef575f5ffd5b8063150b7a02116102dd5780631cd1c8c3116102b85780631cd1c8c3146104f05780632016a0d21461050f578063224d87031461052e57806323b872dd1461055a575f5ffd5b8063150b7a021461044b57806318160ddd146104a85780631a4a6ad6146104db575f5ffd5b806307a2d13a1161030d57806307a2d13a146103de578063095ea7b3146103fd5780630a28a4771461042c575f5ffd5b8063017def571461037557806301e1d1141461039657806306fdde03146103bd575f5ffd5b3661037157604080513381523460208201527f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f88525874910160405180910390a1005b5f5ffd5b348015610380575f5ffd5b5061039461038f3660046134cc565b610b5c565b005b3480156103a1575f5ffd5b506103aa610c1a565b6040519081526020015b60405180910390f35b3480156103c8575f5ffd5b506103d1610cde565b6040516103b49190613530565b3480156103e9575f5ffd5b506103aa6103f83660046134cc565b610db1565b348015610408575f5ffd5b5061041c610417366004613556565b610dc2565b60405190151581526020016103b4565b348015610437575f5ffd5b506103aa6104463660046134cc565b610dd9565b348015610456575f5ffd5b5061048f6104653660046135c5565b7f150b7a020000000000000000000000000000000000000000000000000000000095945050505050565b6040516001600160e01b031990911681526020016103b4565b3480156104b3575f5ffd5b507f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace02546103aa565b3480156104e6575f5ffd5b506103aa60055481565b3480156104fb575f5ffd5b5061039461050a366004613633565b610e02565b34801561051a575f5ffd5b50610394610529366004613704565b610f67565b348015610539575f5ffd5b5061054d6105483660046137ce565b6110c9565b6040516103b4919061386d565b348015610565575f5ffd5b5061041c6105743660046138d0565b6113c7565b348015610584575f5ffd5b5061058d6113ea565b60405160ff90911681526020016103b4565b3480156105aa575f5ffd5b507f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b03165b6040516001600160a01b0390911681526020016103b4565b3480156105fa575f5ffd5b50610394611426565b34801561060e575f5ffd5b506103aa61061d36600461390e565b611480565b34801561062d575f5ffd5b506007546105d7906001600160a01b031681565b34801561064c575f5ffd5b506103aa61065b3660046134cc565b6114bf565b34801561066b575f5ffd5b5061069c61067a36600461390e565b6001600160a01b03165f90815260086020526040902080546001909101549091565b604080519283526020830191909152016103b4565b3480156106bc575f5ffd5b506103aa60065481565b3480156106d1575f5ffd5b507fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1661041c565b348015610707575f5ffd5b50610394610716366004613633565b6114e2565b348015610726575f5ffd5b506103aa610735366004613929565b611643565b348015610745575f5ffd5b506103aa61075436600461390e565b6001600160a01b03165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00602052604090205490565b348015610798575f5ffd5b506103946107a736600461390e565b611656565b3480156107b7575f5ffd5b506103aa6107c6366004613957565b611763565b3480156107d6575f5ffd5b506103946119d7565b3480156107ea575f5ffd5b507fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea00546001600160a01b03166105d7565b348015610826575f5ffd5b506103aa610835366004613929565b611a2f565b348015610845575f5ffd5b506103d1611a42565b348015610859575f5ffd5b5061041c610868366004613556565b611a93565b348015610878575f5ffd5b506103aa60035481565b34801561088d575f5ffd5b506103aa611aa0565b3480156108a1575f5ffd5b506103aa6108b03660046134cc565b611b42565b3480156108c0575f5ffd5b506103aa6108cf366004613957565b611b65565b3480156108df575f5ffd5b506103aa6108ee366004613957565b611ba0565b3480156108fe575f5ffd5b5061048f61090d366004613996565b7fbc197c810000000000000000000000000000000000000000000000000000000098975050505050505050565b348015610945575f5ffd5b507fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01546001600160a01b03166105d7565b348015610981575f5ffd5b506103aa6109903660046134cc565b611bbc565b3480156109a0575f5ffd5b506103aa6109af36600461390e565b611bc7565b3480156109bf575f5ffd5b506103aa6109ce36600461390e565b611c08565b3480156109de575f5ffd5b5061041c6109ed366004613a59565b611c49565b3480156109fd575f5ffd5b50610394610a0c3660046134cc565b611d40565b348015610a1c575f5ffd5b506103aa610a2b366004613a91565b6001600160a01b039182165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020908152604080832093909416825291909152205490565b348015610a7f575f5ffd5b506103aa610a8e3660046134cc565b611df9565b348015610a9e575f5ffd5b50610394610aad36600461390e565b611e16565b348015610abd575f5ffd5b5061048f610acc366004613abd565b7ff23a6e61000000000000000000000000000000000000000000000000000000009695505050505050565b348015610b02575f5ffd5b50610394610b1136600461390e565b611ecf565b348015610b21575f5ffd5b506103d1610b30366004613b22565b611f89565b348015610b40575f5ffd5b506105d7736e879d0ccc85085a709ebf5539224f53d0d396b081565b610b71335f356001600160e01b031916611c49565b610bb15760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b67016345785d8a00008110610bd9576040516358d620b360e01b815260040160405180910390fd5b60065460408051918252602082018390527f828cf983933545af35b9ba46eec951db1cb4c5433c3ec403aeced2963c264790910160405180910390a1600655565b6040516302c68be360e31b81523060048201525f908190736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa158015610c6a573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c8e9190613b7a565b509050610cd8610cbc7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace025490565b610cc46113ea565b610ccf90600a613ca1565b8391905f61212b565b91505090565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0380546060917f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0091610d2f90613caf565b80601f0160208091040260200160405190810160405280929190818152602001828054610d5b90613caf565b8015610da65780601f10610d7d57610100808354040283529160200191610da6565b820191905f5260205f20905b815481529060010190602001808311610d8957829003601f168201915b505050505091505090565b5f610dbc825f61216d565b92915050565b5f33610dcf818585612223565b5060019392505050565b5f5f610de783600554612235565b9050610dfb610df68285613ce7565b61224b565b9392505050565b610e17335f356001600160e01b031916611c49565b610e525760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b6001600160a01b0383165f908152600860205260409020600181015415801590610e80575080600101548311155b610e9c5760405162f1a34760e11b815260040160405180910390fd5b805415801590610ead575080548211155b610eca57604051633b83271360e01b815260040160405180910390fd5b82816001015f828254610edd9190613cfa565b90915550508054829082905f90610ef5908490613cfa565b925050819055508160035f828254610f0d9190613cfa565b909155505060408051848152602081018490526001600160a01b038616917f55ec94ca0f01023d07c5752a75f44048cfbdb0e4cfedf5e7eacecf21fcde3587910160405180910390a2610f61308585612257565b50505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000810460ff16159067ffffffffffffffff165f81158015610fb15750825b90505f8267ffffffffffffffff166001148015610fcd5750303b155b905081158015610fdb575080155b15611012576040517ff92ee8a900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561104657845468ff00000000000000001916680100000000000000001785555b61104e6122b4565b61105887876122bc565b611061896122d2565b61106b885f6122e6565b6110736123be565b83156110be57845468ff000000000000000019168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b505050505050505050565b60606110e0335f356001600160e01b031916611c49565b61111b5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b858067ffffffffffffffff81111561113557611135613665565b60405190808252806020026020018201604052801561116857816020015b60608152602001906001900390816111535790505b5091505f5b818110156113bb575f87878381811061118857611188613d0d565b905060200281019061119a9190613d21565b6111a391613d64565b90506111d67fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01546001600160a01b031690565b6001600160a01b031663b7009613338c8c868181106111f7576111f7613d0d565b905060200201602081019061120c919061390e565b6040516001600160e01b031960e085901b811682526001600160a01b0393841660048301529290911660248201529084166044820152606401602060405180830381865afa158015611260573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112849190613d9a565b8a8a8481811061129657611296613d0d565b90506020020160208101906112ab919061390e565b8290916112e657604051637dab181360e11b81526001600160a01b0390921660048301526001600160e01b0319166024820152604401610ba8565b50506113958888848181106112fd576112fd613d0d565b905060200281019061130f9190613d21565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f920191909152508a925089915086905081811061135757611357613d0d565b905060200201358c8c8681811061137057611370613d0d565b9050602002016020810190611385919061390e565b6001600160a01b031691906123ce565b8483815181106113a7576113a7613d0d565b60209081029190910101525060010161116d565b50509695505050505050565b5f336113d485828561247d565b6113df858585612257565b506001949350505050565b5f807f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e0090505f8154610cd89190600160a01b900460ff16613db9565b61143b335f356001600160e01b031916611c49565b6114765760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b61147e61252b565b565b5f6114ac7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1690565b156114b857505f919050565b5f19610dbc565b5f5f6114ca83610db1565b90506114d88160055461259d565b610dfb9082613cfa565b6114f7335f356001600160e01b031916611c49565b6115325760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b6001600160a01b0383165f908152600860205260409020600181015415801590611560575080600101548311155b61157c5760405162f1a34760e11b815260040160405180910390fd5b80541580159061158d575080548211155b6115aa57604051633b83271360e01b815260040160405180910390fd5b82816001015f8282546115bd9190613cfa565b90915550508054829082905f906115d5908490613cfa565b925050819055508160035f8282546115ed9190613cfa565b909155505060408051848152602081018490526001600160a01b038616917f1165aa98d42fbaef9bacc273d7b5cca8edc94909519f8f949ec33562963c87e4910160405180910390a2610f6130853085876125be565b5f61164c612660565b610dfb83836126bc565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0080546001600160a01b031633148061170d5750600181015460405163b700961360e01b81523360048201523060248201525f356001600160e01b03191660448201526001600160a01b039091169063b700961390606401602060405180830381865afa1580156116e9573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061170d9190613d9a565b611715575f5ffd5b6001810180546001600160a01b0319166001600160a01b03841690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a35050565b5f61176c612660565b6001600160a01b0383166117ac576040517f6ba9ecd800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f84116117e5576040517f840c364a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b0382163314611827576040517fe7fe5cf400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b83611865836001600160a01b03165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00602052604090205490565b101561189d576040517f3999656700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6118a785610db1565b9050806118b2612734565b10611917576118c483858584896125be565b60408051828152602081018790526001916001600160a01b0380871692908816917f9a626d8a4952950c7f8b9f5c92a2804e44e147ce4dd0add2f5928f1faea72590910160405180910390a49050610dfb565b60408051828152602081018790525f916001600160a01b0380871692908816917f9a626d8a4952950c7f8b9f5c92a2804e44e147ce4dd0add2f5928f1faea72590910160405180910390a461196d833087612257565b8060035f82825461197e9190613ce7565b90915550506001600160a01b0384165f908152600860205260408120600181018054919288926119af908490613ce7565b90915550508054829082905f906119c7908490613ce7565b909155505f979650505050505050565b6119ec335f356001600160e01b031916611c49565b611a275760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b61147e612806565b5f611a38612660565b610dfb8383612861565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0480546060917f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0091610d2f90613caf565b5f33610dcf818585612257565b6040516302c68be360e31b81523060048201525f90736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa158015611aee573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b129190613b7a565b509050611b1d6113ea565b611b28906012613dd2565b611b3390600a613ca1565b611b3d9082613deb565b905090565b5f5f611b4d836128d9565b9050611b5b81600654612235565b610dfb9082613ce7565b5f611b6e612660565b6040517f797f246a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f611ba9612660565b611bb4848484611763565b949350505050565b5f610dbc825f6128e5565b5f611bf37fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1690565b15611bff57505f919050565b610dbc8261299a565b5f611c347fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1690565b15611c4057505f919050565b610dbc826129db565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01545f907fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea00906001600160a01b03168015801590611d20575060405163b700961360e01b81526001600160a01b0386811660048301523060248301526001600160e01b03198616604483015282169063b700961390606401602060405180830381865afa158015611cfc573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d209190613d9a565b80611d37575081546001600160a01b038681169116145b95945050505050565b611d55335f356001600160e01b031916611c49565b611d905760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b67016345785d8a00008110611db8576040516358d620b360e01b815260040160405180910390fd5b60055460408051918252602082018390527f733071ab8253b372ed26a6d1b04aec71c4bfcd209c93397df32bb77478cdd2c8910160405180910390a1600555565b5f5f611e078360065461259d565b9050610dfb6109908285613cfa565b611e2b335f356001600160e01b031916611c49565b611e665760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b600754604080516001600160a01b03928316815291831660208301527faaebcf1bfa00580e41d966056b48521fa9f202645c86d4ddf28113e617c1b1d3910160405180910390a1600780546001600160a01b0319166001600160a01b0392909216919091179055565b611ee4335f356001600160e01b031916611c49565b611f1f5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0080546001600160a01b0319166001600160a01b038316908117825560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b6060611fa0335f356001600160e01b031916611c49565b611fdb5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401610ba8565b5f611fe68486613d64565b90506120197fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea01546001600160a01b031690565b60405163b700961360e01b81523360048201526001600160a01b0388811660248301526001600160e01b031984166044830152919091169063b700961390606401602060405180830381865afa158015612075573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120999190613d9a565b868290916120d557604051637dab181360e11b81526001600160a01b0390921660048301526001600160e01b0319166024820152604401610ba8565b505061212185858080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525050506001600160a01b038916919050856123ce565b9695505050505050565b5f61215861213883612a17565b801561215357505f848061214e5761214e613e02565b868809115b151590565b612163868686612a43565b611d379190613ce7565b6040516302c68be360e31b81523060048201525f908190736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa1580156121bd573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121e19190613b7a565b5090505f81116122035760405162bfc92160e01b815260040160405180910390fd5b611bb48161220f6113ea565b61221a90600a613ca1565b8691908661212b565b6122308383836001612af9565b505050565b5f610dfb8383670de0b6b3a7640000600161212b565b5f610dbc8260016128e5565b6001600160a01b03831661228057604051634b637e8f60e11b81525f6004820152602401610ba8565b6001600160a01b0382166122a95760405163ec442f0560e01b81525f6004820152602401610ba8565b612230838383612c22565b61147e612c35565b6122c4612c35565b6122ce8282612c9c565b5050565b6122da612c35565b6122e381612cff565b50565b6122ee612c35565b7fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0080546001600160a01b03199081166001600160a01b0385811691821784557fdd3fd67aef415aded9493b31ad20a02d2991d4bb2760431cc729821271eaea0180549093169085161790915560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a36040516001600160a01b0383169033907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a3505050565b6123c6612c35565b61147e612d9a565b606081471015612413576040517fcf47918100000000000000000000000000000000000000000000000000000000815247600482015260248101839052604401610ba8565b5f5f856001600160a01b0316848660405161242e9190613e16565b5f6040518083038185875af1925050503d805f8114612468576040519150601f19603f3d011682016040523d82523d5f602084013e61246d565b606091505b5091509150612121868383612dcd565b6001600160a01b038381165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0160209081526040808320938616835292905220545f19811015610f61578181101561251d576040517ffb8f41b20000000000000000000000000000000000000000000000000000000081526001600160a01b03841660048201526024810182905260448101839052606401610ba8565b610f6184848484035f612af9565b612533612e42565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a150565b5f610dfb826125b4670de0b6b3a764000082613ce7565b859190600161212b565b5f6125cb8360055461259d565b90505f6125d88285613cfa565b6007549091506001600160a01b03166125f48888888588612e9d565b5f8311801561260b57506001600160a01b03811615155b156126565761265681846126467f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b6001600160a01b03169190612f64565b5050505050505050565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff161561147e576040517fd93c066500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f5f6126c783611480565b90508084111561271c576040517f79012fb20000000000000000000000000000000000000000000000000000000081526001600160a01b03841660048201526024810185905260448101829052606401610ba8565b5f61272685611df9565b9050611bb433858784612fd8565b5f5f6127677f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa1580156127c4573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127e89190613e31565b905060035481116127f9575f610cd8565b600354610cd89082613cfa565b61280e612660565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2583361257f565b5f5f61286c83611480565b9050808411156128c1576040517f284ff6670000000000000000000000000000000000000000000000000000000081526001600160a01b03841660048201526024810185905260448101829052606401610ba8565b5f6128cb85611b42565b9050611bb433858388612fd8565b5f610dbc82600161216d565b6040516302c68be360e31b81523060048201525f908190736e879d0ccc85085a709ebf5539224f53d0d396b0906316345f18906024016040805180830381865afa158015612935573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129599190613b7a565b5090505f811161297b5760405162bfc92160e01b815260040160405180910390fd5b611bb46129866113ea565b61299190600a613ca1565b8590838661212b565b6001600160a01b0381165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006020526040812054610dbc905f61216d565b6001600160a01b0381165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006020526040812054610dbc565b5f6002826003811115612a2c57612a2c613e48565b612a369190613e5c565b60ff166001149050919050565b5f838302815f1985870982811083820303915050805f03612a7757838281612a6d57612a6d613e02565b0492505050610dfb565b808411612a8e57612a8e600385150260111861305a565b5f848688095f868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006001600160a01b038516612b5c576040517fe602df050000000000000000000000000000000000000000000000000000000081525f6004820152602401610ba8565b6001600160a01b038416612b9e576040517f94280d620000000000000000000000000000000000000000000000000000000081525f6004820152602401610ba8565b6001600160a01b038086165f90815260018301602090815260408083209388168352929052208390558115612c1b57836001600160a01b0316856001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92585604051612c1291815260200190565b60405180910390a35b5050505050565b612c2a612660565b61223083838361306b565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005468010000000000000000900460ff1661147e576040517fd7e6bcf800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612ca4612c35565b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace007f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace03612cf08482613ecd565b5060048101610f618382613ecd565b612d07612c35565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e005f80612d33846131d0565b9150915081612d43576012612d45565b805b83547fffffffffffffffffffffff00000000000000000000000000000000000000000016600160a01b60ff92909216919091026001600160a01b031916176001600160a01b0394909416939093179091555050565b612da2612c35565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300805460ff19169055565b606082612de257612ddd826132d4565b610dfb565b8151158015612df957506001600160a01b0384163b155b15612e3b576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610ba8565b5080610dfb565b7fcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033005460ff1661147e576040517f8dfc202b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e006001600160a01b0386811690851614612edc57612edc84878461247d565b612ee68483613316565b8054612efc906001600160a01b03168685612f64565b836001600160a01b0316856001600160a01b0316876001600160a01b03167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8686604051612f54929190918252602082015260400190565b60405180910390a4505050505050565b6040516001600160a01b0383811660248301526044820183905261223091859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505061334a565b5f612fe58360065461259d565b6007549091506001600160a01b0316613000868686866133cf565b5f8211801561301757506001600160a01b03811615155b156130525761305281836126467f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00546001600160a01b031690565b505050505050565b634e487b715f52806020526024601cfd5b7f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace006001600160a01b0384166130b85781816002015f8282546130ad9190613ce7565b909155506131419050565b6001600160a01b0384165f9081526020829052604090205482811015613123576040517fe450d38c0000000000000000000000000000000000000000000000000000000081526001600160a01b03861660048201526024810182905260448101849052606401610ba8565b6001600160a01b0385165f9081526020839052604090209083900390555b6001600160a01b03831661315f57600281018054839003905561317d565b6001600160a01b0383165f9081526020829052604090208054830190555b826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516131c291815260200190565b60405180910390a350505050565b60408051600481526024810182526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f313ce5670000000000000000000000000000000000000000000000000000000017905290515f918291829182916001600160a01b0387169161324491613e16565b5f60405180830381855afa9150503d805f811461327c576040519150601f19603f3d011682016040523d82523d5f602084013e613281565b606091505b509150915081801561329557506020815110155b156132c8575f818060200190518101906132af9190613e31565b905060ff81116132c6576001969095509350505050565b505b505f9485945092505050565b8051156132e45780518082602001fd5b6040517fd6bda27500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b03821661333f57604051634b637e8f60e11b81525f6004820152602401610ba8565b6122ce825f83612c22565b5f5f60205f8451602086015f885af180613369576040513d5f823e3d81fd5b50505f513d9150811561338057806001141561338d565b6001600160a01b0384163b155b15610f61576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610ba8565b7f0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e008054613407906001600160a01b031686308661345f565b6134118483613498565b836001600160a01b0316856001600160a01b03167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78585604051612c12929190918252602082015260400190565b6040516001600160a01b038481166024830152838116604483015260648201839052610f619186918216906323b872dd90608401612f91565b6001600160a01b0382166134c15760405163ec442f0560e01b81525f6004820152602401610ba8565b6122ce5f8383612c22565b5f602082840312156134dc575f5ffd5b5035919050565b5f5b838110156134fd5781810151838201526020016134e5565b50505f910152565b5f815180845261351c8160208601602086016134e3565b601f01601f19169290920160200192915050565b602081525f610dfb6020830184613505565b6001600160a01b03811681146122e3575f5ffd5b5f5f60408385031215613567575f5ffd5b823561357281613542565b946020939093013593505050565b5f5f83601f840112613590575f5ffd5b50813567ffffffffffffffff8111156135a7575f5ffd5b6020830191508360208285010111156135be575f5ffd5b9250929050565b5f5f5f5f5f608086880312156135d9575f5ffd5b85356135e481613542565b945060208601356135f481613542565b935060408601359250606086013567ffffffffffffffff811115613616575f5ffd5b61362288828901613580565b969995985093965092949392505050565b5f5f5f60608486031215613645575f5ffd5b833561365081613542565b95602085013595506040909401359392505050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f830112613688575f5ffd5b813567ffffffffffffffff8111156136a2576136a2613665565b604051601f8201601f19908116603f0116810167ffffffffffffffff811182821017156136d1576136d1613665565b6040528181528382016020018510156136e8575f5ffd5b816020850160208301375f918101602001919091529392505050565b5f5f5f5f60808587031215613717575f5ffd5b843561372281613542565b9350602085013561373281613542565b9250604085013567ffffffffffffffff81111561374d575f5ffd5b61375987828801613679565b925050606085013567ffffffffffffffff811115613775575f5ffd5b61378187828801613679565b91505092959194509250565b5f5f83601f84011261379d575f5ffd5b50813567ffffffffffffffff8111156137b4575f5ffd5b6020830191508360208260051b85010111156135be575f5ffd5b5f5f5f5f5f5f606087890312156137e3575f5ffd5b863567ffffffffffffffff8111156137f9575f5ffd5b61380589828a0161378d565b909750955050602087013567ffffffffffffffff811115613824575f5ffd5b61383089828a0161378d565b909550935050604087013567ffffffffffffffff81111561384f575f5ffd5b61385b89828a0161378d565b979a9699509497509295939492505050565b5f602082016020835280845180835260408501915060408160051b8601019250602086015f5b828110156138c457603f198786030184526138af858351613505565b94506020938401939190910190600101613893565b50929695505050505050565b5f5f5f606084860312156138e2575f5ffd5b83356138ed81613542565b925060208401356138fd81613542565b929592945050506040919091013590565b5f6020828403121561391e575f5ffd5b8135610dfb81613542565b5f5f6040838503121561393a575f5ffd5b82359150602083013561394c81613542565b809150509250929050565b5f5f5f60608486031215613969575f5ffd5b83359250602084013561397b81613542565b9150604084013561398b81613542565b809150509250925092565b5f5f5f5f5f5f5f5f60a0898b0312156139ad575f5ffd5b88356139b881613542565b975060208901356139c881613542565b9650604089013567ffffffffffffffff8111156139e3575f5ffd5b6139ef8b828c0161378d565b909750955050606089013567ffffffffffffffff811115613a0e575f5ffd5b613a1a8b828c0161378d565b909550935050608089013567ffffffffffffffff811115613a39575f5ffd5b613a458b828c01613580565b999c989b5096995094979396929594505050565b5f5f60408385031215613a6a575f5ffd5b8235613a7581613542565b915060208301356001600160e01b03198116811461394c575f5ffd5b5f5f60408385031215613aa2575f5ffd5b8235613aad81613542565b9150602083013561394c81613542565b5f5f5f5f5f5f60a08789031215613ad2575f5ffd5b8635613add81613542565b95506020870135613aed81613542565b94506040870135935060608701359250608087013567ffffffffffffffff811115613b16575f5ffd5b61385b89828a01613580565b5f5f5f5f60608587031215613b35575f5ffd5b8435613b4081613542565b9350602085013567ffffffffffffffff811115613b5b575f5ffd5b613b6787828801613580565b9598909750949560400135949350505050565b5f5f60408385031215613b8b575f5ffd5b8251602084015190925067ffffffffffffffff8116811461394c575f5ffd5b634e487b7160e01b5f52601160045260245ffd5b6001815b6001841115613bf957808504811115613bdd57613bdd613baa565b6001841615613beb57908102905b60019390931c928002613bc2565b935093915050565b5f82613c0f57506001610dbc565b81613c1b57505f610dbc565b8160018114613c315760028114613c3b57613c57565b6001915050610dbc565b60ff841115613c4c57613c4c613baa565b50506001821b610dbc565b5060208310610133831016604e8410600b8410161715613c7a575081810a610dbc565b613c865f198484613bbe565b805f1904821115613c9957613c99613baa565b029392505050565b5f610dfb60ff841683613c01565b600181811c90821680613cc357607f821691505b602082108103613ce157634e487b7160e01b5f52602260045260245ffd5b50919050565b80820180821115610dbc57610dbc613baa565b81810381811115610dbc57610dbc613baa565b634e487b7160e01b5f52603260045260245ffd5b5f5f8335601e19843603018112613d36575f5ffd5b83018035915067ffffffffffffffff821115613d50575f5ffd5b6020019150368190038213156135be575f5ffd5b80356001600160e01b03198116906004841015613d93576001600160e01b0319808560040360031b1b82161691505b5092915050565b5f60208284031215613daa575f5ffd5b81518015158114610dfb575f5ffd5b60ff8181168382160190811115610dbc57610dbc613baa565b60ff8281168282160390811115610dbc57610dbc613baa565b8082028115828204841417610dbc57610dbc613baa565b634e487b7160e01b5f52601260045260245ffd5b5f8251613e278184602087016134e3565b9190910192915050565b5f60208284031215613e41575f5ffd5b5051919050565b634e487b7160e01b5f52602160045260245ffd5b5f60ff831680613e7a57634e487b7160e01b5f52601260045260245ffd5b8060ff84160691505092915050565b601f82111561223057805f5260205f20601f840160051c81016020851015613eae5750805b601f840160051c820191505b81811015612c1b575f8155600101613eba565b815167ffffffffffffffff811115613ee757613ee7613665565b613efb81613ef58454613caf565b84613e89565b6020601f821160018114613f2d575f8315613f165750848201515b5f19600385901b1c1916600184901b178455612c1b565b5f84815260208120601f198516915b82811015613f5c5787850151825560209485019460019092019101613f3c565b5084821015613f7957868401515f19600387901b60f8161c191681555b50505050600190811b0190555056fea164736f6c634300081c000a
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 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.