Source Code
Overview
HYPE Balance
HYPE Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
TokenizedVaultUpgradeable
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { AccessControlEnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/extensions/AccessControlEnumerableUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import { ERC4626Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol";
import { DoubleEndedQueue } from "@openzeppelin/contracts/utils/structs/DoubleEndedQueue.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { IERC7540Operator, IERC7540Redeem, IERC7540ClaimRedeem } from "@ambitlabs/hyperdrive-periphery-contracts/interfaces/IERC7540.sol";
import { IERC165 } from "@ambitlabs/hyperdrive-periphery-contracts/interfaces/IERC165.sol";
import { ReentrancyGuardLib } from "@ambitlabs/hyperdrive-periphery-contracts/contracts/ReentrancyGuardLib.sol";
import { ERC7540OperatorUpgradeable } from "@ambitlabs/hyperdrive-periphery-contracts/contracts/ERC7540OperatorUpgradeable.sol";
import { BlockReentrancyGuardUpgradeable } from "@ambitlabs/hyperdrive-periphery-contracts/contracts/BlockReentrancyGuardUpgradeable.sol";
import { ITokenizedVault } from "../interfaces/ITokenizedVault.sol";
import { DoubleEndedQueueLib } from "./DoubleEndedQueueLib.sol";
import { USD, USDMath } from "./USDMath.sol";
import { CoreControllerLib } from "./CoreControllerLib.sol";
import { MathLib } from "./MathLib.sol";
uint8 constant SPOT_DECIMALS = 8;
uint8 constant PERP_DECIMALS = 6;
contract TokenizedVaultUpgradeable is
ERC4626Upgradeable,
ERC7540OperatorUpgradeable,
UUPSUpgradeable,
AccessControlEnumerableUpgradeable,
PausableUpgradeable,
BlockReentrancyGuardUpgradeable,
ITokenizedVault
{
using Math for uint256;
using SafeERC20 for IERC20;
using SafeCast for uint256;
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableSet for EnumerableSet.UintSet;
using USDMath for USD;
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
using DoubleEndedQueueLib for DoubleEndedQueue.Bytes32Deque;
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
/// @dev batch status
uint8 private constant STATUS_PENDING = 1;
uint8 private constant STATUS_PROCESSING = 2;
uint8 private constant STATUS_FINALIZED = 3;
uint256 public constant MAX_REDEMPTION_REQUESTS_PER_ACCOUNT = 5;
uint256 private constant DUST = 1e2;
uint256 private constant SLIPPAGE = 1e4; // $0.01 USD
struct BatchRedemption {
uint256 requestId;
uint40 createdAt;
uint40 withdrawEquityAt;
uint8 status;
uint256 shares;
uint256 assets;
}
struct UserRedemption {
DoubleEndedQueue.Bytes32Deque requests;
mapping(uint256 requestId => uint256) shares;
}
struct RedemptionFee {
uint16 fee;
uint256 maxAmount;
address receiver;
}
struct DepositTracking {
uint256 blockNumber;
uint256 crediting;
}
/// @custom:storage-location erc7201:hyperdrive.storage.TokenizedVault
struct TokenizedVaultStorage {
uint256 totalClaimableAssets;
EnumerableSet.AddressSet proxies;
address asset;
address vaultAddress;
uint64 tokenIndex;
uint256 lockupDuration;
uint256 lastRequestId;
EnumerableSet.UintSet batchRedemptionsRequests;
mapping(uint256 requestId => BatchRedemption) batchRedemptions;
mapping(address account => UserRedemption) userRedemptions;
DoubleEndedQueue.Bytes32Deque batchRedemptionQueue;
uint256 minimumRedemptionAmount;
RedemptionFee redemptionFee;
uint256 batchDuration;
uint256 maximumSupply;
USD minimumWithdrawableEquity;
mapping(address => DepositTracking) deposits;
uint256 minimumVaultDepositAmount;
address usdcCoreDepositWallet;
}
// keccak256(abi.encode(uint256(keccak256("hyperdrive.storage.TokenizedVault")) - 1)) & ~bytes32(uint256(0xff))
bytes32 public constant STORAGE_LOCATION = 0x6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb00;
function getTokenizedVaultStorage() internal pure returns (TokenizedVaultStorage storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := STORAGE_LOCATION
}
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(
string memory name,
string memory symbol,
IERC20Metadata asset_,
address vaultAddress,
uint64 tokenIndex,
uint256 lockupDuration,
address usdcCoreDepositWallet
) public initializer {
__ERC20_init_unchained(name, symbol);
__ERC4626_init_unchained(asset_);
__UUPSUpgradeable_init_unchained();
__Pausable_init_unchained();
__ERC7540OperatorUpgradeable_init_unchained();
__AccessControlEnumerable_init_unchained();
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_grantRole(ADMIN_ROLE, msg.sender);
_setRoleAdmin(ADMIN_ROLE, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(OPERATOR_ROLE, DEFAULT_ADMIN_ROLE);
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
$.batchDuration = 30 seconds;
$.maximumSupply = type(uint256).max;
$.asset = address(asset_);
$.tokenIndex = tokenIndex;
$.vaultAddress = vaultAddress;
$.lockupDuration = lockupDuration;
$.minimumVaultDepositAmount = 10 * 10 ** asset_.decimals(); // default to 10.0
$.usdcCoreDepositWallet = usdcCoreDepositWallet;
}
modifier onlyAdmin() {
require(hasRole(ADMIN_ROLE, msg.sender), Unauthorized());
_;
}
// solhint-disable-next-line no-empty-blocks
function _authorizeUpgrade(address) internal view override {
require(hasRole(ADMIN_ROLE, msg.sender), Unauthorized());
}
function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
return
super.supportsInterface(interfaceId) ||
interfaceId == type(IERC7540Redeem).interfaceId ||
interfaceId == type(IERC7540ClaimRedeem).interfaceId ||
interfaceId == type(IERC7540Operator).interfaceId ||
interfaceId == type(IERC165).interfaceId;
}
modifier nonReentrant() {
ReentrancyGuardLib.enable();
_;
ReentrancyGuardLib.disable();
}
/// @inheritdoc ITokenizedVault
function createProxy() external onlyAdmin returns (address proxy) {
return CoreControllerLib.createProxy(getTokenizedVaultStorage());
}
/// @inheritdoc ITokenizedVault
function setRedemptionFee(uint16 fee, uint256 maxAmount, address receiver) external onlyAdmin {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
require(fee < 5000, FeeTooHigh()); // 50%
$.redemptionFee.fee = fee;
$.redemptionFee.maxAmount = maxAmount;
$.redemptionFee.receiver = receiver;
emit SetRedemptionFee(fee, maxAmount, receiver, msg.sender);
}
/// @inheritdoc ITokenizedVault
function getRedemptionFee() external view returns (uint16, uint256, address) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return ($.redemptionFee.fee, $.redemptionFee.maxAmount, $.redemptionFee.receiver);
}
/// @inheritdoc ITokenizedVault
function setMaximumSupply(uint256 maximumSupply) external onlyAdmin {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if ($.maximumSupply != maximumSupply) {
$.maximumSupply = maximumSupply;
emit SetMaximumSupply(maximumSupply, msg.sender);
}
}
/// @inheritdoc ITokenizedVault
function getMaximumSupply() external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.maximumSupply;
}
/// @inheritdoc ITokenizedVault
function setMinimumRedemptionAmount(uint256 minimumRedemptionAmount) external onlyAdmin {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if ($.minimumRedemptionAmount != minimumRedemptionAmount) {
$.minimumRedemptionAmount = minimumRedemptionAmount;
emit SetMinimumRedemptionAmount(minimumRedemptionAmount, msg.sender);
}
}
/// @inheritdoc ITokenizedVault
function getMinimumRedemptionAmount() external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.minimumRedemptionAmount;
}
/// @inheritdoc ITokenizedVault
function setMinimumVaultDepositAmount(uint256 minimumVaultDepositAmount) external onlyAdmin {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if ($.minimumVaultDepositAmount != minimumVaultDepositAmount) {
$.minimumVaultDepositAmount = minimumVaultDepositAmount;
emit SetMinimumVaultDepositAmount(minimumVaultDepositAmount, msg.sender);
}
}
/// @inheritdoc ITokenizedVault
function getMinimumVaultDepositAmount() external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.minimumVaultDepositAmount;
}
/// @inheritdoc ITokenizedVault
function setBatchDuration(uint256 duration) external onlyAdmin {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if ($.batchDuration != duration) {
$.batchDuration = duration;
emit SetBatchDuration(duration, msg.sender);
}
}
/// @inheritdoc ITokenizedVault
function getBatchDuration() external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.batchDuration;
}
/// @inheritdoc ITokenizedVault
function getProxies() external view returns (address[] memory addresses) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.proxies.values();
}
/// @inheritdoc ITokenizedVault
function getVaultAddress() public view returns (address) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.vaultAddress;
}
/// @inheritdoc ITokenizedVault
function getTokenIndex() external view returns (uint64) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.tokenIndex;
}
/// @inheritdoc ITokenizedVault
function setLockupDuration(uint256 duration) external onlyAdmin {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if ($.lockupDuration != duration) {
$.lockupDuration = duration;
emit SetLockupDuration(duration, msg.sender);
}
}
/// @inheritdoc ITokenizedVault
function getLockupDuration() external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.lockupDuration;
}
/// @inheritdoc ITokenizedVault
function setMinimumWithdrawableEquity(USD equity) external onlyAdmin {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if (USD.unwrap($.minimumWithdrawableEquity) != USD.unwrap(equity)) {
$.minimumWithdrawableEquity = equity;
emit SetMinimumWithdrawableEquity(equity, msg.sender);
}
}
/// @inheritdoc ITokenizedVault
function getMinimumWithdrawableEquity() external view returns (USD) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.minimumWithdrawableEquity;
}
/// @inheritdoc ITokenizedVault
function getActiveProxy() public view returns (uint256) {
return CoreControllerLib.getActiveProxy(getTokenizedVaultStorage());
}
function pause() external onlyAdmin {
super._pause();
}
function resume() external onlyAdmin {
super._unpause();
}
/// @inheritdoc IERC4626
function totalAssets() public view override(ERC4626Upgradeable, IERC4626) returns (uint256 total) {
return CoreControllerLib.getTotalAssets(getTokenizedVaultStorage());
}
/// @inheritdoc ITokenizedVault
function exchangeRate() public view returns (uint256) {
return convertToAssets(10 ** decimals());
}
/** @dev See {IERC4626-maxDeposit}. */
function maxDeposit(address) public view override(ERC4626Upgradeable, IERC4626) returns (uint256) {
if (paused()) {
return 0;
}
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if ($.maximumSupply == type(uint256).max) {
return type(uint256).max;
}
uint256 assets = totalAssets();
return assets >= $.maximumSupply ? 0 : $.maximumSupply - assets;
}
/// @inheritdoc IERC4626
function deposit(
uint256 assets,
address receiver
) public override(ERC4626Upgradeable, IERC4626) whenNotPaused returns (uint256 shares) {
shares = super.deposit(assets, receiver);
emit Deposit(msg.sender, receiver, assets, shares, block.timestamp);
afterMint();
}
/** @dev See {IERC4626-maxMint}. */
function maxMint(address account) public view override(ERC4626Upgradeable, IERC4626) returns (uint256) {
return convertToShares(maxDeposit(account));
}
/// @inheritdoc IERC4626
function mint(
uint256 shares,
address receiver
) public override(ERC4626Upgradeable, IERC4626) whenNotPaused returns (uint256 assets) {
assets = super.mint(shares, receiver);
emit Deposit(msg.sender, receiver, assets, shares, block.timestamp);
afterMint();
}
/// @dev force the assets to be deposited to the vault
function afterMint() private {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
IERC20 token = IERC20(asset());
uint256 balance = token.balanceOf(address(this)) - $.totalClaimableAssets;
if (balance >= $.minimumVaultDepositAmount) {
balance = MathLib.scale(balance, decimals(), PERP_DECIMALS);
CoreControllerLib.depositEquity($, USD.wrap(balance.toUint64()));
}
}
/// @inheritdoc IERC4626
function previewWithdraw(uint256) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256) {
revert(); // solhint-disable-line reason-string
}
/// @inheritdoc IERC4626
function maxWithdraw(address) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256 assets) {
// we dont allow withdrawing, only redeeming due to the nature of the share based redemptions
return 0;
}
/** @dev See {IERC4626-withdraw}. */
function withdraw(
uint256 assets,
address,
address controller
) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256 shares) {
// we dont allow withdrawing, only redeeming due to the nature of the share based redemptions
shares = 0;
require(assets == 0, ERC4626ExceededMaxWithdraw(controller, assets, 0));
}
// @inheritdoc IERC4626
function previewRedeem(uint256) public pure override(ERC4626Upgradeable, IERC4626) returns (uint256) {
revert(); // solhint-disable-line reason-string
}
// @inheritdoc IERC7540ClaimRedeem
function previewClaimRedeem(uint256 requestId, uint256 shares) external view returns (uint256 assets) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
BatchRedemption storage batchRedemption = $.batchRedemptions[requestId];
assets = batchRedemption.status != STATUS_FINALIZED || batchRedemption.shares == 0
? 0
: toAssets(batchRedemption, shares);
}
/// @inheritdoc IERC4626
function maxRedeem(address controller) public view override(ERC4626Upgradeable, IERC4626) returns (uint256 shares) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
UserRedemption storage userRedemption = $.userRedemptions[controller];
uint256 length = userRedemption.requests.length();
for (uint256 i; i < length; i++) {
uint256 requestId = userRedemption.requests.id(i);
BatchRedemption storage batchRedemption = $.batchRedemptions[requestId];
if (batchRedemption.status == STATUS_FINALIZED) {
shares += userRedemption.shares[requestId];
}
}
}
/// @inheritdoc IERC4626
function redeem(
uint256 shares,
address receiver,
address controller
)
public
override(ERC4626Upgradeable, IERC4626)
nonReentrant
whenNotPaused
onlyOwnerOrOperator(controller)
returns (uint256 assets)
{
require(receiver != address(0), ZeroAddressNotAllowed());
require(controller != address(0), ZeroAddressNotAllowed());
uint256 max = maxRedeem(controller);
require(shares <= max, ERC4626ExceededMaxRedeem(controller, shares, max));
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
UserRedemption storage userRedemption = $.userRedemptions[controller];
uint256 remaining = shares;
while (userRedemption.requests.empty() == false && remaining > 0) {
uint256 requestId = userRedemption.requests.firstOrDefault();
BatchRedemption storage batchRedemption = $.batchRedemptions[requestId];
uint256 shares_ = Math.min(remaining, userRedemption.shares[requestId]);
uint256 assets_ = redeem(batchRedemption, userRedemption, shares_);
emit ClaimRedeem(controller, receiver, requestId, msg.sender, shares_, assets_);
remaining -= shares_;
assets += assets_;
}
IERC20(asset()).safeTransfer(receiver, assets);
emit Withdraw(msg.sender, receiver, controller, assets, shares);
emit Withdraw(msg.sender, receiver, controller, assets, shares, block.timestamp);
}
/// @inheritdoc IERC7540ClaimRedeem
function claimRedeem(
uint256 requestId,
uint256 shares,
address receiver,
address controller
) public nonReentrant whenNotPaused onlyOwnerOrOperator(controller) returns (uint256 assets) {
require(controller != address(0), ZeroAddressNotAllowed());
require(receiver != address(0), ZeroAddressNotAllowed());
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
BatchRedemption storage batchRedemption = $.batchRedemptions[requestId];
UserRedemption storage userRedemption = $.userRedemptions[controller];
uint256 max = batchRedemption.status != STATUS_FINALIZED ? 0 : userRedemption.shares[requestId];
require(shares <= max, ERC4626ExceededMaxRedeem(controller, shares, max));
assets = redeem(batchRedemption, userRedemption, shares);
emit ClaimRedeem(controller, receiver, requestId, msg.sender, assets, shares);
IERC20(asset()).safeTransfer(receiver, assets);
emit Withdraw(msg.sender, receiver, controller, assets, shares);
emit Withdraw(msg.sender, receiver, controller, assets, shares, block.timestamp);
}
function redeem(
BatchRedemption storage batchRedemption,
UserRedemption storage userRedemption,
uint256 shares
) private returns (uint256 assets) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
require(batchRedemption.status == STATUS_FINALIZED, OperationFailed());
shares = Math.min(userRedemption.shares[batchRedemption.requestId], shares);
assets = toAssets(batchRedemption, shares);
$.totalClaimableAssets -= assets;
updateUserRedemption(userRedemption, batchRedemption.requestId, shares);
updateBatchRedemption(batchRedemption, shares, assets);
}
function updateBatchRedemption(BatchRedemption storage batchRedemption, uint256 shares, uint256 assets) private {
require(shares <= batchRedemption.shares, OperationFailed());
if (shares < batchRedemption.shares) {
batchRedemption.shares -= shares;
batchRedemption.assets -= assets;
return;
}
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
$.batchRedemptionsRequests.remove(batchRedemption.requestId);
delete $.batchRedemptions[batchRedemption.requestId];
}
function updateUserRedemption(UserRedemption storage userRedemption, uint256 requestId, uint256 shares) private {
require(shares <= userRedemption.shares[requestId], OperationFailed());
if (shares < userRedemption.shares[requestId]) {
userRedemption.shares[requestId] -= shares;
return;
}
delete userRedemption.shares[requestId];
userRedemption.requests.remove(requestId);
}
function toAssets(BatchRedemption storage batchRedemption, uint256 shares) private view returns (uint256 assets) {
assets = batchRedemption.shares == 0
? shares
: shares.mulDiv(batchRedemption.assets, batchRedemption.shares, Math.Rounding.Floor);
assets = Math.min(assets, batchRedemption.assets);
}
/// @inheritdoc IERC7540Redeem
function requestRedeem(
uint256 shares,
address controller,
address owner
) public whenNotPaused onlyOwnerOrOperator(owner) nonReentrant returns (uint256 requestId) {
require(controller != address(0), ZeroAddressNotAllowed());
require(shares > 0, ZeroAmountNotAllowed());
require(controller == msg.sender, ERC7540NotAuthorizedController());
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
uint256 assets = convertToAssets(shares);
require(assets >= $.minimumRedemptionAmount, BelowMinimumRedemptionAmount(assets, $.minimumRedemptionAmount));
// limit the number of active redemption requests per account
require(
$.userRedemptions[controller].requests.length() < MAX_REDEMPTION_REQUESTS_PER_ACCOUNT,
TooManyRedemptionRequests()
);
requestId = enqueue(controller, shares);
IERC20(address(this)).safeTransferFrom(owner, address(this), shares);
emit RedeemRequest(controller, owner, requestId, msg.sender, shares);
}
/// @inheritdoc IERC7540Redeem
function pendingRedeemRequest(uint256 requestId, address controller) external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return
$.batchRedemptions[requestId].status == STATUS_FINALIZED ? 0 : $.userRedemptions[controller].shares[requestId];
}
/// @inheritdoc IERC7540Redeem
function claimableRedeemRequest(uint256 requestId, address controller) external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
BatchRedemption storage batchRedemption = $.batchRedemptions[requestId];
if (batchRedemption.status != STATUS_FINALIZED) {
return 0;
}
UserRedemption storage userRedemption = $.userRedemptions[controller];
return userRedemption.shares[requestId];
}
/// @inheritdoc ITokenizedVault
function totalClaimableAssets() external view returns (uint256) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return $.totalClaimableAssets;
}
/// @inheritdoc ITokenizedVault
function execute() external nonReentrant whenNotPaused oncePerBlock returns (bool takenAction) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
if ($.batchRedemptionQueue.empty() == true) {
emit Execute(msg.sender, block.timestamp);
return false;
}
BatchRedemption storage batch = $.batchRedemptions[$.batchRedemptionQueue.firstOrDefault()];
if (expired(batch) == false) {
emit Execute(msg.sender, block.timestamp);
return false;
}
if (batch.status == STATUS_PENDING) {
batch.status = STATUS_PROCESSING;
}
// the maximum redemption amount is locked in when the batch is first processed
// so that if the exchange rate drops before the batch is redeemed then the
// batch will take on that additional loss
batch.assets = batch.assets == 0
? convertToAssets(batch.shares)
: Math.min(batch.assets, convertToAssets(batch.shares));
if (tryFinalize(batch) == false) {
withdraw(batch);
}
emit Execute(msg.sender, block.timestamp);
return true;
}
/// @dev attempts to finalize the batch from the assets that are avalable for withdrawl
function tryFinalize(BatchRedemption storage batch) private returns (bool) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
// we can use anything sitting in the contract balance
uint256 balance = IERC20(asset()).balanceOf(address(this)) - $.totalClaimableAssets;
uint256 withdrawable = CoreControllerLib.getWithdrawable($) + balance;
uint256 difference = batch.assets <= withdrawable ? 0 : batch.assets - withdrawable;
if (difference > SLIPPAGE) {
return false;
}
finalizeBatchRedemption(batch.requestId, batch.shares, Math.min(batch.assets, withdrawable));
$.batchRedemptionQueue.dequeue();
return true;
}
function calculateFee(
RedemptionFee memory fee,
uint256 assets
) private view returns (uint256 feeAmount, address feeReceiver) {
feeAmount = Math.min((assets * fee.fee) / 10000, fee.maxAmount);
feeReceiver = fee.receiver == address(0) ? msg.sender : fee.receiver;
}
/// @dev withdraw whatever assets are required from the equity
function withdraw(TokenizedVaultUpgradeable.BatchRedemption storage batch) private {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
uint8 decimals = IERC20Metadata(asset()).decimals();
// withdraw anything sitting in the spot and perps, we can include this amount
// as though it wont be available in the current block it should be in the next
uint256 withdrawableL1 = CoreControllerLib.withdrawL1($);
// when we withdraw equity there is a 4 second delay before the action will take
// place so we need to ensure that the next time we run it is after the delay
if (batch.withdrawEquityAt > 0 && block.timestamp < batch.withdrawEquityAt + 5 seconds) {
return;
}
uint256 balance = IERC20(asset()).balanceOf(address(this)) - $.totalClaimableAssets;
uint256 withdrawable = CoreControllerLib.getWithdrawable($) +
balance +
MathLib.scale(withdrawableL1, SPOT_DECIMALS, decimals);
uint256 remaining = withdrawable >= batch.assets ? 0 : batch.assets - withdrawable;
// check if there is more that needs to be withdrawn so it must come from the equity
if (remaining > SLIPPAGE) {
USD equity = CoreControllerLib.getWithdrawableEquity($);
// scale the remaining amount to match the perps
remaining = MathLib.scale(remaining, IERC20Metadata(asset()).decimals(), PERP_DECIMALS);
equity = USDMath.min(equity, USD.wrap(remaining.toUint64()));
// when we withdraw equity there is a 4 second delay before the action will take
// place so we need to ensure that the next time we run it is after the delay
batch.withdrawEquityAt = uint40(block.timestamp);
CoreControllerLib.withdrawEquity($, equity);
}
emit Withdraw(batch.requestId, msg.sender, block.timestamp);
}
/**
* @dev Returns true if a new batch should be enqueued.
*
* Rules:
* - If no batches exist in the queue, a new batch is always allowed.
* - If exactly one batch exists and it is currently processing, a second batch may be enqueued.
*
* This ensures the queue never grows beyond two active batches.
*/
function shouldEnqueueNewBatch(TokenizedVaultStorage storage $) private view returns (bool) {
uint256 length = $.batchRedemptionQueue.length();
// if we dont currently have any batches then create a new one
if (length == 0) {
return true;
}
BatchRedemption storage batch = $.batchRedemptions[$.batchRedemptionQueue.firstOrDefault()];
// if we only have one batch and its processing then create a new one
if (length == 1 && batch.status == STATUS_PROCESSING) {
return true;
}
return false;
}
function enqueue(address controller, uint256 shares) private returns (uint256 requestId) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
requestId = $.lastRequestId;
// check to see if a new batch needs to be created
if (shouldEnqueueNewBatch($)) {
requestId = ++$.lastRequestId;
// track the list of request id's so the active batches can be queried off-chain
$.batchRedemptionsRequests.add(requestId);
// the queue is for processing the requests until they have completed
$.batchRedemptionQueue.enqueue(requestId);
$.batchRedemptions[requestId] = BatchRedemption({
requestId: requestId,
createdAt: uint40(block.timestamp),
withdrawEquityAt: 0,
status: STATUS_PENDING,
shares: 0,
assets: 0
});
}
// increase the shares for the current batch to track this new request
$.batchRedemptions[requestId].shares += shares;
// the user might have already redeemed in the same batch
if ($.userRedemptions[controller].shares[requestId] == 0) {
$.userRedemptions[controller].requests.enqueue(requestId);
}
$.userRedemptions[controller].shares[requestId] += shares;
emit Enqueue(requestId, controller, shares, msg.sender, block.timestamp);
}
function expired(BatchRedemption storage batch) private view returns (bool) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
return block.timestamp >= batch.createdAt + $.batchDuration;
}
function finalizeBatchRedemption(uint256 requestId, uint256 shares, uint256 assets) internal {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
require($.batchRedemptions[requestId].status != STATUS_FINALIZED, RequestAlreadyFinalized());
require(finalizeWithdraw(assets) >= assets, FinalizedAmountNotEnough());
(uint256 feeAmount, address feeReceiver) = calculateFee($.redemptionFee, assets);
$.totalClaimableAssets += assets - feeAmount;
$.batchRedemptions[requestId].status = STATUS_FINALIZED;
$.batchRedemptions[requestId].shares = shares;
$.batchRedemptions[requestId].assets = assets - feeAmount;
_burn(address(this), shares);
emit FinalizeBatchRedemption(requestId, shares, assets, feeAmount, block.timestamp);
if (feeAmount > 0) {
IERC20(asset()).safeTransfer(feeReceiver, feeAmount);
}
}
/// @dev complete the withdrawal from the proxies and reserve the amount.
function finalizeWithdraw(uint256 assets) internal returns (uint256 finalized) {
TokenizedVaultStorage storage $ = getTokenizedVaultStorage();
IERC20 token = IERC20(asset());
// track the current balance before we transfer from the proxies
uint256 balance = token.balanceOf(address(this)) - $.totalClaimableAssets;
finalized += CoreControllerLib.withdraw($, address(this), assets);
// take any remaining amount from the vault contract
finalized += Math.min(assets - finalized, balance);
}
/// @inheritdoc ITokenizedVault
function getStorageSlots(bytes32[] calldata slots) external view returns (bytes32[] memory output) {
output = new bytes32[](slots.length);
for (uint256 i; i < slots.length; ) {
bytes32 slot = slots[i++];
assembly ("memory-safe") {
mstore(add(output, mul(i, 32)), sload(slot))
}
}
}
function forceDepositEquity(address proxy, USD equity) public onlyRole(OPERATOR_ROLE) {
return CoreControllerLib.forceDepositEquity(getTokenizedVaultStorage(), proxy, equity);
}
function forceWithdrawEquity(address proxy, USD equity) public onlyRole(OPERATOR_ROLE) {
return CoreControllerLib.forceWithdrawEquity(getTokenizedVaultStorage(), proxy, equity);
}
function forceWithdrawPerp(address proxy, USD amount) public onlyRole(OPERATOR_ROLE) {
return CoreControllerLib.forceWithdrawPerp(getTokenizedVaultStorage(), proxy, amount);
}
function forceWithdrawSpot(address proxy, uint64 _wei) public onlyRole(OPERATOR_ROLE) {
return CoreControllerLib.forceWithdrawSpot(getTokenizedVaultStorage(), proxy, _wei);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
library CoreReaderLib {
address public constant PRECOMPILE_ADDRESS_POSITION = 0x0000000000000000000000000000000000000800;
address public constant PRECOMPILE_ADDRESS_SPOT_BALANCE = 0x0000000000000000000000000000000000000801;
address public constant PRECOMPILE_ADDRESS_VAULT_EQUITY = 0x0000000000000000000000000000000000000802;
address public constant PRECOMPILE_ADDRESS_WITHDRAWABLE = 0x0000000000000000000000000000000000000803;
address public constant PRECOMPILE_ADDRESS_DELEGATIONS = 0x0000000000000000000000000000000000000804;
address public constant PRECOMPILE_ADDRESS_DELEGATOR_SUMMARY = 0x0000000000000000000000000000000000000805;
address public constant PRECOMPILE_ADDRESS_MARK_PX = 0x0000000000000000000000000000000000000806;
address public constant PRECOMPILE_ADDRESS_ORACLE_PX = 0x0000000000000000000000000000000000000807;
address public constant PRECOMPILE_ADDRESS_SPOT_PX = 0x0000000000000000000000000000000000000808;
address public constant PRECOMPILE_ADDRESS_L1_BLOCK_NUMBER = 0x0000000000000000000000000000000000000809;
address public constant PRECOMPILE_ADDRESS_PERP_ASSET_INFO = 0x000000000000000000000000000000000000080a;
address public constant PRECOMPILE_ADDRESS_SPOT_INFO = 0x000000000000000000000000000000000000080b;
address public constant PRECOMPILE_ADDRESS_TOKEN_INFO = 0x000000000000000000000000000000000000080C;
address public constant PRECOMPILE_ADDRESS_CORE_USER_EXISTS = 0x0000000000000000000000000000000000000810;
error ReadFailure(address precompile);
struct Position {
int64 szi;
uint64 entryNtl;
int64 isolatedRawUsd;
uint32 leverage;
bool isIsolated;
}
struct SpotBalance {
uint64 total;
uint64 hold;
uint64 entryNtl;
}
struct UserVaultEquity {
uint64 equity;
uint64 lockedUntilTimestamp;
}
struct Withdrawable {
uint64 withdrawable;
}
struct Delegation {
address validator;
uint64 amount;
uint64 lockedUntilTimestamp;
}
struct DelegatorSummary {
uint64 delegated;
uint64 undelegated;
uint64 totalPendingWithdrawal;
uint64 nPendingWithdrawals;
}
struct PerpAssetInfo {
string coin;
uint32 marginTableId;
uint8 szDecimals;
uint8 maxLeverage;
bool onlyIsolated;
}
struct SpotInfo {
string name;
uint64[2] tokens;
}
struct TokenInfo {
string name;
uint64[] spots;
uint64 deployerTradingFeeShare;
address deployer;
address evmContract;
uint8 szDecimals;
uint8 weiDecimals;
int8 evmExtraWeiDecimals;
}
struct CoreUserExists {
bool exists;
}
function readPosition(address user, uint16 perp) internal view returns (Position memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_POSITION.staticcall(abi.encode(user, perp));
require(success, ReadFailure(PRECOMPILE_ADDRESS_POSITION));
return abi.decode(result, (Position));
}
function readSpotBalance(address user, uint64 token) internal view returns (SpotBalance memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_SPOT_BALANCE.staticcall(abi.encode(user, token));
require(success, ReadFailure(PRECOMPILE_ADDRESS_SPOT_BALANCE));
return abi.decode(result, (SpotBalance));
}
function readUserVaultEquity(address user, address vault) internal view returns (UserVaultEquity memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_VAULT_EQUITY.staticcall(abi.encode(user, vault));
require(success, ReadFailure(PRECOMPILE_ADDRESS_VAULT_EQUITY));
return abi.decode(result, (UserVaultEquity));
}
function readWithdrawable(address user) internal view returns (Withdrawable memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_WITHDRAWABLE.staticcall(abi.encode(user));
require(success, ReadFailure(PRECOMPILE_ADDRESS_WITHDRAWABLE));
return abi.decode(result, (Withdrawable));
}
function readDelegations(address user) internal view returns (Delegation[] memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_DELEGATIONS.staticcall(abi.encode(user));
require(success, ReadFailure(PRECOMPILE_ADDRESS_DELEGATIONS));
return abi.decode(result, (Delegation[]));
}
function readDelegatorSummary(address user) internal view returns (DelegatorSummary memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_DELEGATOR_SUMMARY.staticcall(abi.encode(user));
require(success, ReadFailure(PRECOMPILE_ADDRESS_DELEGATOR_SUMMARY));
return abi.decode(result, (DelegatorSummary));
}
function readMarkPx(uint32 index) internal view returns (uint64) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_MARK_PX.staticcall(abi.encode(index));
require(success, ReadFailure(PRECOMPILE_ADDRESS_MARK_PX));
return abi.decode(result, (uint64));
}
function readOraclePx(uint32 index) internal view returns (uint64) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_ORACLE_PX.staticcall(abi.encode(index));
require(success, ReadFailure(PRECOMPILE_ADDRESS_ORACLE_PX));
return abi.decode(result, (uint64));
}
function readSpotPx(uint32 index) internal view returns (uint64) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_SPOT_PX.staticcall(abi.encode(index));
require(success, ReadFailure(PRECOMPILE_ADDRESS_SPOT_PX));
return abi.decode(result, (uint64));
}
function readL1BlockNumber() internal view returns (uint64) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_L1_BLOCK_NUMBER.staticcall(abi.encode());
require(success, ReadFailure(PRECOMPILE_ADDRESS_L1_BLOCK_NUMBER));
return abi.decode(result, (uint64));
}
function readPerpAssetInfo(uint32 perp) internal view returns (PerpAssetInfo memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_PERP_ASSET_INFO.staticcall(abi.encode(perp));
require(success, ReadFailure(PRECOMPILE_ADDRESS_PERP_ASSET_INFO));
return abi.decode(result, (PerpAssetInfo));
}
function readSpotInfo(uint32 spot) internal view returns (SpotInfo memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_SPOT_INFO.staticcall(abi.encode(spot));
require(success, ReadFailure(PRECOMPILE_ADDRESS_SPOT_INFO));
return abi.decode(result, (SpotInfo));
}
function readTokenInfo(uint32 token) internal view returns (TokenInfo memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_TOKEN_INFO.staticcall(abi.encode(token));
require(success, ReadFailure(PRECOMPILE_ADDRESS_TOKEN_INFO));
return abi.decode(result, (TokenInfo));
}
function readCoreUserExists(address user) internal view returns (CoreUserExists memory) {
(bool success, bytes memory result) = PRECOMPILE_ADDRESS_CORE_USER_EXISTS.staticcall(abi.encode(user));
require(success, ReadFailure(PRECOMPILE_ADDRESS_CORE_USER_EXISTS));
return abi.decode(result, (CoreUserExists));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface CoreWriter {
event RawAction(address indexed user, bytes data);
function sendRawAction(bytes calldata data) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { CoreWriter } from "./CoreWriter.sol";
library CoreWriterLib {
using SafeCast for uint256;
address public constant CORE_WRITER = 0x3333333333333333333333333333333333333333;
uint8 public constant CORE_WRITER_VERSION_1 = 1;
uint24 public constant CORE_WRITER_ACTION_LIMIT_ORDER = 1;
uint24 public constant CORE_WRITER_ACTION_VAULT_TRANSFER = 2;
uint24 public constant CORE_WRITER_ACTION_TOKEN_DELEGATE = 3;
uint24 public constant CORE_WRITER_ACTION_STAKING_DEPOSIT = 4;
uint24 public constant CORE_WRITER_ACTION_STAKING_WITHDRAW = 5;
uint24 public constant CORE_WRITER_ACTION_SPOT_SEND = 6;
uint24 public constant CORE_WRITER_ACTION_USD_CLASS_TRANSFER = 7;
// ...
uint24 public constant CORE_WRITER_ACTION_SEND_ASSET = 13;
uint8 public constant LIMIT_ORDER_TIF_ALO = 1;
uint8 public constant LIMIT_ORDER_TIF_GTC = 2;
uint8 public constant LIMIT_ORDER_TIF_IOC = 3;
struct LimitOrderAction {
uint32 asset;
bool isBuy;
uint64 limitPx;
uint64 sz;
bool reduceOnly;
uint8 encodedTif;
uint128 cloid;
}
struct VaultTransferAction {
address vault;
bool isDeposit;
uint64 usd;
}
struct TokenDelegateAction {
address validator;
uint64 _wei;
bool isUndelegate;
}
struct StakingDepositAction {
uint64 _wei;
}
struct StakingWithdrawAction {
uint64 _wei;
}
struct SpotSendAction {
address destination;
uint64 token;
uint64 _wei;
}
struct UsdClassTransferAction {
uint64 ntl;
bool toPerp;
}
struct SendAssetAction {
address destination;
address subAccount;
uint32 source_dex;
uint32 destination_dex;
uint64 token;
uint64 _wei;
}
function encodeLimitOrderAction(LimitOrderAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_LIMIT_ORDER, abi.encode(action));
}
function sendLimitOrderAction(LimitOrderAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeLimitOrderAction(action));
}
function encodeVaultTransfer(VaultTransferAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_VAULT_TRANSFER, abi.encode(action));
}
function sendVaultTransfer(VaultTransferAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeVaultTransfer(action));
}
function encodeTokenDelegate(TokenDelegateAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_TOKEN_DELEGATE, abi.encode(action));
}
function sendTokenDelegate(TokenDelegateAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeTokenDelegate(action));
}
function encodeStakingDeposit(StakingDepositAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_STAKING_DEPOSIT, abi.encode(action));
}
function sendStakingDeposit(StakingDepositAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeStakingDeposit(action));
}
function encodeStakingWithdraw(StakingWithdrawAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_STAKING_WITHDRAW, abi.encode(action));
}
function sendStakingWithdraw(StakingWithdrawAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeStakingWithdraw(action));
}
function encodeSpotSend(SpotSendAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_SPOT_SEND, abi.encode(action));
}
function sendSpotSend(SpotSendAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeSpotSend(action));
}
function encodeUsdClassTransfer(UsdClassTransferAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_USD_CLASS_TRANSFER, abi.encode(action));
}
function sendUsdClassTransfer(UsdClassTransferAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeUsdClassTransfer(action));
}
function encodeSendAsset(SendAssetAction memory action) internal pure returns (bytes memory) {
return abi.encodePacked(CORE_WRITER_VERSION_1, CORE_WRITER_ACTION_SEND_ASSET, abi.encode(action));
}
function sendSendAsset(SendAssetAction memory action) internal {
CoreWriter(CORE_WRITER).sendRawAction(encodeSendAsset(action));
}
}// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.28;
contract BlockReentrancyGuardUpgradeable {
/// @custom:storage-location erc7201:ambit.storage.BlockReentrancyGuard
struct BlockReentrancyGuardStorage {
uint256 lastBlockNumber;
}
// keccak256(abi.encode(uint256(keccak256("ambit.storage.BlockReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant BLOCK_REENTERANCY_GUARD_STORAGE_LOCATION =
0x7a2690543f05b94273f26531201d3f783a1582ff4e1fd0b5224e0f07a0278f00;
function getBlockReentrancyGuardStorage() private pure returns (BlockReentrancyGuardStorage storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := BLOCK_REENTERANCY_GUARD_STORAGE_LOCATION
}
}
error BlockReentrancyFailed();
modifier oncePerBlock() {
checkOncePerBlock();
_;
}
function checkOncePerBlock() private {
BlockReentrancyGuardStorage storage $ = getBlockReentrancyGuardStorage();
require(block.number > $.lastBlockNumber, BlockReentrancyFailed());
$.lastBlockNumber = block.number;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import { IERC7540Operator } from "../interfaces/IERC7540.sol";
abstract contract ERC7540OperatorUpgradeable is Initializable, IERC7540Operator {
error ERC7540NotAuthorizedOperator();
error ERC7540NotAuthorizedController();
/// @custom:storage-location erc7201:hyperdrive.storage.ERC7540OperatorUpgradeable
struct ERC7540OperatorStorage {
mapping(address controller => mapping(address operator => bool)) operators;
}
// keccak256(abi.encode(uint256(keccak256("hyperdrive.storage.ERC7540OperatorUpgradeable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant STORAGE_LOCATION = 0x58b5cdfd1ca129592c69bde289fd6324080dd2d81a29959004bd7c0735b6e300;
function getERC7540OperatorStorage() internal pure returns (ERC7540OperatorStorage storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := STORAGE_LOCATION
}
}
// solhint-disable-next-line func-name-mixedcase
function __ERC7540OperatorUpgradeable_init() internal onlyInitializing {
__ERC7540OperatorUpgradeable_init_unchained();
}
// solhint-disable-next-line func-name-mixedcase
function __ERC7540OperatorUpgradeable_init_unchained() internal onlyInitializing {}
/// @inheritdoc IERC7540Operator
function setOperator(address operator, bool approved) external returns (bool) {
ERC7540OperatorStorage storage $ = getERC7540OperatorStorage();
if ($.operators[msg.sender][operator] != approved) {
$.operators[msg.sender][operator] = approved;
emit OperatorSet(msg.sender, operator, approved);
}
return true;
}
/// @inheritdoc IERC7540Operator
function isOperator(address controller, address operator) public view returns (bool) {
ERC7540OperatorStorage storage $ = getERC7540OperatorStorage();
return $.operators[controller][operator];
}
modifier onlyOwnerOrOperator(address owner) {
checkOwnerOrOperator(owner);
_;
}
function checkOwnerOrOperator(address owner) private view {
require(msg.sender == owner || isOperator(owner, msg.sender), ERC7540NotAuthorizedOperator());
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { AccessControlEnumerable } from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
contract Proxy is AccessControlEnumerable {
using Address for address;
using Address for address payable;
bytes32 public constant EXECUTION_ROLE = keccak256("EXECUTION_ROLE");
constructor() {
_grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setRoleAdmin(EXECUTION_ROLE, DEFAULT_ADMIN_ROLE);
_grantRole(EXECUTION_ROLE, msg.sender);
}
receive() external payable {}
function execute(address target, bytes memory data) external onlyRole(EXECUTION_ROLE) {
target.functionCallWithValue(data, 0);
}
function execute(address target, bytes memory data, uint256 value) external payable onlyRole(EXECUTION_ROLE) {
target.functionCallWithValue(data, value);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.26;
import { TransientSlot } from "@openzeppelin/contracts/utils/TransientSlot.sol";
library ReentrancyGuardLib {
using TransientSlot for *;
error ReentrancyGuardFailed();
// keccak256(abi.encode(uint256(keccak256("hyperdrive.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD = 0xe26c696bf0e34aaf444e67b257b0ce1f00d161ab27c76bcd8c8582bed8ddd000;
function enabled() internal view returns (bool) {
return REENTRANCY_GUARD.asBoolean().tload();
}
/// @dev enable the reenterancy protection
function enable() internal {
require(enabled() == false, ReentrancyGuardFailed());
REENTRANCY_GUARD.asBoolean().tstore(true);
}
/// @dev disables the reenterancy protection
function disable() internal {
require(enabled(), ReentrancyGuardFailed());
REENTRANCY_GUARD.asBoolean().tstore(false);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
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[EIP 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 pure returns (bool);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { IERC7540Operator } from "./IERC7540Operator.sol";
import { IERC7540Redeem } from "./IERC7540Redeem.sol";
import { IERC7540CancelRedeem } from "./IERC7540CancelRedeem.sol";
import { IERC7540ClaimRedeem } from "./IERC7540ClaimRedeem.sol";// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
interface IERC7540CancelRedeem {
event CancelRedeemRequest(address indexed controller, uint256 indexed requestId, address sender);
event CancelRedeemClaim(
address indexed receiver,
address indexed controller,
uint256 indexed requestId,
address sender,
uint256 shares
);
/**
* @dev Submits a Request for cancelling the pending redeem Request
*
* - controller MUST be msg.sender unless some unspecified explicit approval is given by the caller,
* approval of ERC-20 tokens from controller to sender is NOT enough.
* - MUST set pendingCancelRedeemRequest to `true` for the returned requestId after request
* - MUST increase claimableCancelRedeemRequest for the returned requestId after fulfillment
* - SHOULD be claimable using `claimCancelRedeemRequest`
* Note: while `pendingCancelRedeemRequest` is `true`, `requestRedeem` cannot be called
*/
function cancelRedeemRequest(uint256 requestId, address controller) external;
/**
* @dev Returns whether the redeem Request is pending cancelation
*
* - MUST NOT show any variations depending on the caller.
*/
function pendingCancelRedeemRequest(uint256 requestId, address controller) external view returns (bool isPending);
/**
* @dev Returns the amount of shares that were canceled from a redeem Request, and can now be claimed.
*
* - MUST NOT show any variations depending on the caller.
*/
function claimableCancelRedeemRequest(
uint256 requestId,
address controller
) external view returns (uint256 claimableShares);
/**
* @dev Claims the canceled redeem shares, and removes the pending cancelation Request
*
* - controller MUST be msg.sender unless some unspecified explicit approval is given by the caller,
* approval of ERC-20 tokens from controller to sender is NOT enough.
* - MUST set pendingCancelRedeemRequest to `false` for the returned requestId after request
* - MUST set claimableCancelRedeemRequest to 0 for the returned requestId after fulfillment
*/
function claimCancelRedeemRequest(
uint256 requestId,
address receiver,
address controller
) external returns (uint256 shares);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
/**
* @title IERC7540ClaimRedeem
*
* @notice Extension interface for ERC-7540 that adds explicit claim functionality with granular events.
*
* @dev This interface extends ERC-7540 async redemption vaults by providing:
* - A dedicated event for tracking when redemption requests are claimed
* - Preview functionality to estimate assets before claiming
* - Partial claim support (claim a portion of a fulfilled request)
*
* This addresses the lack of claim-specific events in the base ERC-7540 standard,
* enabling indexers and UIs to track the complete lifecycle of redemption requests.
*/
interface IERC7540ClaimRedeem {
/**
* @notice Emitted when a redemption request is claimed.
*
* @param controller The address that controls the redemption request.
* @param receiver The address receiving the redeemed assets.
* @param requestId The unique identifier of the redemption request.
* @param sender The address that initiated the claim transaction.
* @param shares The number of vault shares being claimed.
* @param assets The amount of underlying assets received.
*/
event ClaimRedeem(
address indexed controller,
address indexed receiver,
uint256 indexed requestId,
address sender,
uint256 shares,
uint256 assets
);
/**
* @notice Previews the amount of assets that would be received for claiming shares from a request.
*
* @dev MUST NOT revert unless due to integer overflow caused by an unreasonably large input.
* MUST return 0 if the request has no claimable shares.
*
* @param requestId The unique identifier of the redemption request.
* @param shares The number of shares to preview claiming.
*
* @return assets The estimated amount of underlying assets that would be received.
*/
function previewClaimRedeem(uint256 requestId, uint256 shares) external view returns (uint256 assets);
/**
* @notice Claims assets from a fulfilled redemption request.
*
* @dev MUST revert if the request has insufficient claimable shares.
* MUST emit the ClaimRedeem event.
* MUST support partial claims where shares is less than the total claimable amount.
*
* @param requestId The unique identifier of the redemption request.
* @param shares The number of shares to claim from the request.
* @param receiver The address that will receive the underlying assets.
* @param controller The address that controls the redemption request.
*
* @return assets The amount of underlying assets transferred to the receiver.
*/
function claimRedeem(
uint256 requestId,
uint256 shares,
address receiver,
address controller
) external returns (uint256 assets);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
interface IERC7540Operator {
/**
* @dev The event emitted when an operator is set.
*
* @param controller The address of the controller.
* @param operator The address of the operator.
* @param approved The approval status.
*/
event OperatorSet(address indexed controller, address indexed operator, bool approved);
/**
* @dev Sets or removes an operator for the caller.
*
* @param operator The address of the operator.
* @param approved The approval status.
* @return Whether the call was executed successfully or not
*/
function setOperator(address operator, bool approved) external returns (bool);
/**
* @dev Returns `true` if the `operator` is approved as an operator for an `controller`.
*
* @param controller The address of the controller.
* @param operator The address of the operator.
* @return status The approval status
*/
function isOperator(address controller, address operator) external view returns (bool status);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { IERC7540Operator } from "./IERC7540Operator.sol";
interface IERC7540Redeem is IERC7540Operator {
event RedeemRequest(
address indexed controller,
address indexed owner,
uint256 indexed requestId,
address sender,
uint256 shares
);
/**
* @dev Assumes control of shares from sender into the Vault and submits a Request for asynchronous redeem.
*
* - MUST support a redeem Request flow where the control of shares is taken from sender directly
* where msg.sender has ERC-20 approval over the shares of owner.
* - MUST revert if all of shares cannot be requested for redeem.
*
* @param shares the amount of shares to be redeemed to transfer from owner
* @param controller the controller of the request who will be able to operate the request
* @param owner the source of the shares to be redeemed
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault's share token.
*/
function requestRedeem(uint256 shares, address controller, address owner) external returns (uint256 requestId);
/**
* @dev Returns the amount of requested shares in Pending state.
*
* - MUST NOT include any shares in Claimable state for redeem or withdraw.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT revert unless due to integer overflow caused by an unreasonably large input.
*/
function pendingRedeemRequest(uint256 requestId, address controller) external view returns (uint256 pendingShares);
/**
* @dev Returns the amount of requested shares in Claimable state for the controller to redeem or withdraw.
*
* - MUST NOT include any shares in Pending state for redeem or withdraw.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT revert unless due to integer overflow caused by an unreasonably large input.
*/
function claimableRedeemRequest(
uint256 requestId,
address controller
) external view returns (uint256 claimableShares);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
struct AccessControlStorage {
mapping(bytes32 role => RoleData) _roles;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;
function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
assembly {
$.slot := AccessControlStorageLocation
}
}
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
AccessControlStorage storage $ = _getAccessControlStorage();
bytes32 previousAdminRole = getRoleAdmin(role);
$._roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (!hasRole(role, account)) {
$._roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (hasRole(role, account)) {
$._roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/extensions/AccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControlEnumerable} from "@openzeppelin/contracts/access/extensions/IAccessControlEnumerable.sol";
import {AccessControlUpgradeable} from "../AccessControlUpgradeable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerable, AccessControlUpgradeable {
using EnumerableSet for EnumerableSet.AddressSet;
/// @custom:storage-location erc7201:openzeppelin.storage.AccessControlEnumerable
struct AccessControlEnumerableStorage {
mapping(bytes32 role => EnumerableSet.AddressSet) _roleMembers;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControlEnumerable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant AccessControlEnumerableStorageLocation = 0xc1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e82371705932000;
function _getAccessControlEnumerableStorage() private pure returns (AccessControlEnumerableStorage storage $) {
assembly {
$.slot := AccessControlEnumerableStorageLocation
}
}
function __AccessControlEnumerable_init() internal onlyInitializing {
}
function __AccessControlEnumerable_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view virtual returns (address) {
AccessControlEnumerableStorage storage $ = _getAccessControlEnumerableStorage();
return $._roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view virtual returns (uint256) {
AccessControlEnumerableStorage storage $ = _getAccessControlEnumerableStorage();
return $._roleMembers[role].length();
}
/**
* @dev Return all accounts that have `role`
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function getRoleMembers(bytes32 role) public view virtual returns (address[] memory) {
AccessControlEnumerableStorage storage $ = _getAccessControlEnumerableStorage();
return $._roleMembers[role].values();
}
/**
* @dev Overload {AccessControl-_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
AccessControlEnumerableStorage storage $ = _getAccessControlEnumerableStorage();
bool granted = super._grantRole(role, account);
if (granted) {
$._roleMembers[role].add(account);
}
return granted;
}
/**
* @dev Overload {AccessControl-_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
AccessControlEnumerableStorage storage $ = _getAccessControlEnumerableStorage();
bool revoked = super._revokeRole(role, account);
if (revoked) {
$._roleMembers[role].remove(account);
}
return revoked;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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 reinitialization) 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 Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.22;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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}.
*
* Both 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.3.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:ROOT: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) {
return IERC20(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 {
// 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(IERC20(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 {
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(IERC20(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.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.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165Upgradeable is Initializable, IERC165 {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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 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();
_;
}
function __Pausable_init() internal onlyInitializing {
}
function __Pausable_init_unchained() internal onlyInitializing {
}
/**
* @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: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` from `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/extensions/AccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControlEnumerable} from "./IAccessControlEnumerable.sol";
import {AccessControl} from "../AccessControl.sol";
import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";
/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
*/
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
using EnumerableSet for EnumerableSet.AddressSet;
mapping(bytes32 role => EnumerableSet.AddressSet) private _roleMembers;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) public view virtual returns (address) {
return _roleMembers[role].at(index);
}
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) public view virtual returns (uint256) {
return _roleMembers[role].length();
}
/**
* @dev Return all accounts that have `role`
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function getRoleMembers(bytes32 role) public view virtual returns (address[] memory) {
return _roleMembers[role].values();
}
/**
* @dev Overload {AccessControl-_grantRole} to track enumerable memberships
*/
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
bool granted = super._grantRole(role, account);
if (granted) {
_roleMembers[role].add(account);
}
return granted;
}
/**
* @dev Overload {AccessControl-_revokeRole} to track enumerable memberships
*/
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
bool revoked = super._revokeRole(role, account);
if (revoked) {
_roleMembers[role].remove(account);
}
return revoked;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/extensions/IAccessControlEnumerable.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "../IAccessControl.sol";
/**
* @dev External interface of AccessControlEnumerable declared to support ERC-165 detection.
*/
interface IAccessControlEnumerable is IAccessControl {
/**
* @dev Returns one of the accounts that have `role`. `index` must be a
* value between 0 and {getRoleMemberCount}, non-inclusive.
*
* Role bearers are not sorted in any particular way, and their ordering may
* change at any point.
*
* WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
* you perform all queries on the same block. See the following
* https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
* for more information.
*/
function getRoleMember(bytes32 role, uint256 index) external view returns (address);
/**
* @dev Returns the number of accounts that have `role`. Can be used
* together with {getRoleMember} to enumerate all bearers of a role.
*/
function getRoleMemberCount(bytes32 role) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted to signal this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated 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.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated 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.3.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 redemption 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.0) (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.20;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.22;
import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This library provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit IERC1967.Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the ERC-1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit IERC1967.BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}// 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.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.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, bytes memory returndata) = recipient.call{value: amount}("");
if (!success) {
_revert(returndata);
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Arrays.sol)
// This file was procedurally generated from scripts/generate/templates/Arrays.js.
pragma solidity ^0.8.20;
import {Comparators} from "./Comparators.sol";
import {SlotDerivation} from "./SlotDerivation.sol";
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using SlotDerivation for bytes32;
using StorageSlot for bytes32;
/**
* @dev Sort an array of uint256 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
uint256[] memory array,
function(uint256, uint256) pure returns (bool) comp
) internal pure returns (uint256[] memory) {
_quickSort(_begin(array), _end(array), comp);
return array;
}
/**
* @dev Variant of {sort} that sorts an array of uint256 in increasing order.
*/
function sort(uint256[] memory array) internal pure returns (uint256[] memory) {
sort(array, Comparators.lt);
return array;
}
/**
* @dev Sort an array of address (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
address[] memory array,
function(address, address) pure returns (bool) comp
) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of address in increasing order.
*/
function sort(address[] memory array) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Sort an array of bytes32 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
bytes32[] memory array,
function(bytes32, bytes32) pure returns (bool) comp
) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of bytes32 in increasing order.
*/
function sort(bytes32[] memory array) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Performs a quick sort of a segment of memory. The segment sorted starts at `begin` (inclusive), and stops
* at end (exclusive). Sorting follows the `comp` comparator.
*
* Invariant: `begin <= end`. This is the case when initially called by {sort} and is preserved in subcalls.
*
* IMPORTANT: Memory locations between `begin` and `end` are not validated/zeroed. This function should
* be used only if the limits are within a memory array.
*/
function _quickSort(uint256 begin, uint256 end, function(uint256, uint256) pure returns (bool) comp) private pure {
unchecked {
if (end - begin < 0x40) return;
// Use first element as pivot
uint256 pivot = _mload(begin);
// Position where the pivot should be at the end of the loop
uint256 pos = begin;
for (uint256 it = begin + 0x20; it < end; it += 0x20) {
if (comp(_mload(it), pivot)) {
// If the value stored at the iterator's position comes before the pivot, we increment the
// position of the pivot and move the value there.
pos += 0x20;
_swap(pos, it);
}
}
_swap(begin, pos); // Swap pivot into place
_quickSort(begin, pos, comp); // Sort the left side of the pivot
_quickSort(pos + 0x20, end, comp); // Sort the right side of the pivot
}
}
/**
* @dev Pointer to the memory location of the first element of `array`.
*/
function _begin(uint256[] memory array) private pure returns (uint256 ptr) {
assembly ("memory-safe") {
ptr := add(array, 0x20)
}
}
/**
* @dev Pointer to the memory location of the first memory word (32bytes) after `array`. This is the memory word
* that comes just after the last element of the array.
*/
function _end(uint256[] memory array) private pure returns (uint256 ptr) {
unchecked {
return _begin(array) + array.length * 0x20;
}
}
/**
* @dev Load memory word (as a uint256) at location `ptr`.
*/
function _mload(uint256 ptr) private pure returns (uint256 value) {
assembly {
value := mload(ptr)
}
}
/**
* @dev Swaps the elements memory location `ptr1` and `ptr2`.
*/
function _swap(uint256 ptr1, uint256 ptr2) private pure {
assembly {
let value1 := mload(ptr1)
let value2 := mload(ptr2)
mstore(ptr1, value2)
mstore(ptr2, value1)
}
}
/// @dev Helper: low level cast address memory array to uint256 memory array
function _castToUint256Array(address[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 memory array to uint256 memory array
function _castToUint256Array(bytes32[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast address comp function to uint256 comp function
function _castToUint256Comp(
function(address, address) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 comp function to uint256 comp function
function _castToUint256Comp(
function(bytes32, bytes32) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* NOTE: The `array` is expected to be sorted in ascending order, and to
* contain no repeated elements.
*
* IMPORTANT: Deprecated. This implementation behaves as {lowerBound} but lacks
* support for repeated elements in the array. The {lowerBound} function should
* be used instead.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value greater or equal than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/lower_bound[lower_bound].
*/
function lowerBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value strictly greater than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/upper_bound[upper_bound].
*/
function upperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Same as {lowerBound}, but with an array in memory.
*/
function lowerBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Same as {upperBound}, but with an array in memory.
*/
function upperBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(bytes32[] memory arr, uint256 pos) internal pure returns (bytes32 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(address[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes32[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(uint256[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Comparators.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to compare values.
*
* _Available since v5.1._
*/
library Comparators {
function lt(uint256 a, uint256 b) internal pure returns (bool) {
return a < b;
}
function gt(uint256 a, uint256 b) internal pure returns (bool) {
return a > b;
}
}// 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) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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 Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = 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 = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @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 {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(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 {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @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 {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 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 low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, 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 ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, 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 high into low.
low |= high * 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 high
// is no longer required.
result = low * 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 Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 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 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @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 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/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.3.0) (utils/SlotDerivation.sol)
// This file was procedurally generated from scripts/generate/templates/SlotDerivation.js.
pragma solidity ^0.8.20;
/**
* @dev Library for computing storage (and transient storage) locations from namespaces and deriving slots
* corresponding to standard patterns. The derivation method for array and mapping matches the storage layout used by
* the solidity language / compiler.
*
* See https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays[Solidity docs for mappings and dynamic arrays.].
*
* Example usage:
* ```solidity
* contract Example {
* // Add the library methods
* using StorageSlot for bytes32;
* using SlotDerivation for bytes32;
*
* // Declare a namespace
* string private constant _NAMESPACE = "<namespace>"; // eg. OpenZeppelin.Slot
*
* function setValueInNamespace(uint256 key, address newValue) internal {
* _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value = newValue;
* }
*
* function getValueInNamespace(uint256 key) internal view returns (address) {
* return _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value;
* }
* }
* ```
*
* TIP: Consider using this library along with {StorageSlot}.
*
* NOTE: This library provides a way to manipulate storage locations in a non-standard way. Tooling for checking
* upgrade safety will ignore the slots accessed through this library.
*
* _Available since v5.1._
*/
library SlotDerivation {
/**
* @dev Derive an ERC-7201 slot from a string (namespace).
*/
function erc7201Slot(string memory namespace) internal pure returns (bytes32 slot) {
assembly ("memory-safe") {
mstore(0x00, sub(keccak256(add(namespace, 0x20), mload(namespace)), 1))
slot := and(keccak256(0x00, 0x20), not(0xff))
}
}
/**
* @dev Add an offset to a slot to get the n-th element of a structure or an array.
*/
function offset(bytes32 slot, uint256 pos) internal pure returns (bytes32 result) {
unchecked {
return bytes32(uint256(slot) + pos);
}
}
/**
* @dev Derive the location of the first element in an array from the slot where the length is stored.
*/
function deriveArray(bytes32 slot) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, slot)
result := keccak256(0x00, 0x20)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, address key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, and(key, shr(96, not(0))))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bool key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, iszero(iszero(key)))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes32 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, uint256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, int256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, string memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/structs/DoubleEndedQueue.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
/**
* @dev A sequence of items with the ability to efficiently push and pop items (i.e. insert and remove) on both ends of
* the sequence (called front and back). Among other access patterns, it can be used to implement efficient LIFO and
* FIFO queues. Storage use is optimized, and all operations are O(1) constant time. This includes {clear}, given that
* the existing queue contents are left in storage.
*
* The struct is called `Bytes32Deque`. Other types can be cast to and from `bytes32`. This data structure can only be
* used in storage, and not in memory.
* ```solidity
* DoubleEndedQueue.Bytes32Deque queue;
* ```
*/
library DoubleEndedQueue {
/**
* @dev Indices are 128 bits so begin and end are packed in a single storage slot for efficient access.
*
* Struct members have an underscore prefix indicating that they are "private" and should not be read or written to
* directly. Use the functions provided below instead. Modifying the struct manually may violate assumptions and
* lead to unexpected behavior.
*
* The first item is at data[begin] and the last item is at data[end - 1]. This range can wrap around.
*/
struct Bytes32Deque {
uint128 _begin;
uint128 _end;
mapping(uint128 index => bytes32) _data;
}
/**
* @dev Inserts an item at the end of the queue.
*
* Reverts with {Panic-RESOURCE_ERROR} if the queue is full.
*/
function pushBack(Bytes32Deque storage deque, bytes32 value) internal {
unchecked {
uint128 backIndex = deque._end;
if (backIndex + 1 == deque._begin) Panic.panic(Panic.RESOURCE_ERROR);
deque._data[backIndex] = value;
deque._end = backIndex + 1;
}
}
/**
* @dev Removes the item at the end of the queue and returns it.
*
* Reverts with {Panic-EMPTY_ARRAY_POP} if the queue is empty.
*/
function popBack(Bytes32Deque storage deque) internal returns (bytes32 value) {
unchecked {
uint128 backIndex = deque._end;
if (backIndex == deque._begin) Panic.panic(Panic.EMPTY_ARRAY_POP);
--backIndex;
value = deque._data[backIndex];
delete deque._data[backIndex];
deque._end = backIndex;
}
}
/**
* @dev Inserts an item at the beginning of the queue.
*
* Reverts with {Panic-RESOURCE_ERROR} if the queue is full.
*/
function pushFront(Bytes32Deque storage deque, bytes32 value) internal {
unchecked {
uint128 frontIndex = deque._begin - 1;
if (frontIndex == deque._end) Panic.panic(Panic.RESOURCE_ERROR);
deque._data[frontIndex] = value;
deque._begin = frontIndex;
}
}
/**
* @dev Removes the item at the beginning of the queue and returns it.
*
* Reverts with {Panic-EMPTY_ARRAY_POP} if the queue is empty.
*/
function popFront(Bytes32Deque storage deque) internal returns (bytes32 value) {
unchecked {
uint128 frontIndex = deque._begin;
if (frontIndex == deque._end) Panic.panic(Panic.EMPTY_ARRAY_POP);
value = deque._data[frontIndex];
delete deque._data[frontIndex];
deque._begin = frontIndex + 1;
}
}
/**
* @dev Returns the item at the beginning of the queue.
*
* Reverts with {Panic-ARRAY_OUT_OF_BOUNDS} if the queue is empty.
*/
function front(Bytes32Deque storage deque) internal view returns (bytes32 value) {
if (empty(deque)) Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
return deque._data[deque._begin];
}
/**
* @dev Returns the item at the end of the queue.
*
* Reverts with {Panic-ARRAY_OUT_OF_BOUNDS} if the queue is empty.
*/
function back(Bytes32Deque storage deque) internal view returns (bytes32 value) {
if (empty(deque)) Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
unchecked {
return deque._data[deque._end - 1];
}
}
/**
* @dev Return the item at a position in the queue given by `index`, with the first item at 0 and last item at
* `length(deque) - 1`.
*
* Reverts with {Panic-ARRAY_OUT_OF_BOUNDS} if the index is out of bounds.
*/
function at(Bytes32Deque storage deque, uint256 index) internal view returns (bytes32 value) {
if (index >= length(deque)) Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
// By construction, length is a uint128, so the check above ensures that index can be safely downcast to uint128
unchecked {
return deque._data[deque._begin + uint128(index)];
}
}
/**
* @dev Resets the queue back to being empty.
*
* NOTE: The current items are left behind in storage. This does not affect the functioning of the queue, but misses
* out on potential gas refunds.
*/
function clear(Bytes32Deque storage deque) internal {
deque._begin = 0;
deque._end = 0;
}
/**
* @dev Returns the number of items in the queue.
*/
function length(Bytes32Deque storage deque) internal view returns (uint256) {
unchecked {
return uint256(deque._end - deque._begin);
}
}
/**
* @dev Returns true if the queue is empty.
*/
function empty(Bytes32Deque storage deque) internal view returns (bool) {
return deque._end == deque._begin;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
import {Arrays} from "../Arrays.sol";
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
* - Set can be cleared (all elements removed) in O(n).
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function _clear(Set storage set) private {
uint256 len = _length(set);
for (uint256 i = 0; i < len; ++i) {
delete set._positions[set._values[i]];
}
Arrays.unsafeSetLength(set._values, 0);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(Bytes32Set storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(AddressSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/TransientSlot.sol)
// This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
pragma solidity ^0.8.24;
/**
* @dev Library for reading and writing value-types to specific transient storage slots.
*
* Transient slots are often used to store temporary values that are removed after the current transaction.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* * Example reading and writing values using transient storage:
* ```solidity
* contract Lock {
* using TransientSlot for *;
*
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier locked() {
* require(!_LOCK_SLOT.asBoolean().tload());
*
* _LOCK_SLOT.asBoolean().tstore(true);
* _;
* _LOCK_SLOT.asBoolean().tstore(false);
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library TransientSlot {
/**
* @dev UDVT that represents a slot holding an address.
*/
type AddressSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a AddressSlot.
*/
function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
return AddressSlot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a bool.
*/
type BooleanSlot is bytes32;
/**
* @dev Cast an arbitrary slot to a BooleanSlot.
*/
function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
return BooleanSlot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a bytes32.
*/
type Bytes32Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Bytes32Slot.
*/
function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
return Bytes32Slot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a uint256.
*/
type Uint256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Uint256Slot.
*/
function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
return Uint256Slot.wrap(slot);
}
/**
* @dev UDVT that represents a slot holding a int256.
*/
type Int256Slot is bytes32;
/**
* @dev Cast an arbitrary slot to a Int256Slot.
*/
function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
return Int256Slot.wrap(slot);
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(AddressSlot slot) internal view returns (address value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(AddressSlot slot, address value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(BooleanSlot slot) internal view returns (bool value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(BooleanSlot slot, bool value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Bytes32Slot slot, bytes32 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Uint256Slot slot) internal view returns (uint256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Uint256Slot slot, uint256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Int256Slot slot) internal view returns (int256 value) {
assembly ("memory-safe") {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Int256Slot slot, int256 value) internal {
assembly ("memory-safe") {
tstore(slot, value)
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
interface ICoreDepositWallet {
/**
* @notice Deposit tokens from the HyperEVM msg.sender to a the sender address perps balance on Hypercore.
* @dev Requires the caller to call IERC20(token).approve(CoreDepositWallet, amount) before calling this function.
* @param amount The amount of tokens being deposited.
* @param destinationDex The destination dex for the deposit (0 for default perps account, or uint32.max for spot balance).
*/
function deposit(uint256 amount, uint32 destinationDex) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { IERC4626 } from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import { IERC7540Redeem } from "@ambitlabs/hyperdrive-periphery-contracts/interfaces/IERC7540Redeem.sol";
import { IERC7540ClaimRedeem } from "@ambitlabs/hyperdrive-periphery-contracts/interfaces/IERC7540ClaimRedeem.sol";
import { USD } from "../protocol/USDMath.sol";
interface ITokenizedVault is IERC4626, IERC7540Redeem, IERC7540ClaimRedeem {
/// @dev this is in addition to the standard IERC4626.Deposit event as this is friendly to off-chain indexing
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares, uint256 timestamp);
/// @dev this is in addition to the standard IERC4626.Withdraw event as this is friendly to off-chain indexing
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares,
uint256 timestamp
);
event Execute(address caller, uint256 timestamp);
event Enqueue(uint256 indexed requestId, address controller, uint256 shares, address caller, uint256 timestamp);
event Withdraw(uint256 indexed requestId, address caller, uint256 timestamp);
event FinalizeBatchRedemption(
uint256 indexed requestId,
uint256 shares,
uint256 assets,
uint256 fee,
uint256 timestamp
);
event CreateProxy(address indexed proxy, address caller);
event SetLockupDuration(uint256 duration, address indexed caller);
event SetMinimumWithdrawableEquity(USD equity, address indexed caller);
event DepositEquity(address indexed proxy, USD equity, uint256 timestamp);
event Withdraw(address target, uint256 assets, uint256 expected, uint256 timestamp);
event Withdraw(address indexed proxy, address target, uint256 assets, uint256 expected, uint256 timestamp);
event WithdrawL1(uint256 expected, uint256 timestamp);
event WithdrawL1(address indexed proxy, uint256 amount, uint256 timestamp);
event WithdrawEquity(USD amount, USD expected, uint256 timestamp);
event WithdrawEquity(address indexed proxy, USD amount, uint256 timestamp);
event SetMaximumSupply(uint256 maxSupply, address caller);
event SetRedemptionFee(uint16 fee, uint256 maxAmount, address receiver, address caller);
event SetMinimumRedemptionAmount(uint256 minAmount, address caller);
event SetMinimumVaultDepositAmount(uint256 minAmount, address caller);
event SetBatchDuration(uint256 duration, address caller);
error RequestNotAllowed();
error RequestNotCancellable();
error RequestNotFound();
error FinalizedAmountNotEnough();
error ZeroAddressNotAllowed();
error ZeroAmountNotAllowed();
error InvalidAssetMetadata();
error RequestAlreadyFinalized();
error BelowMinimumRedemptionAmount(uint256 amount, uint256 minimumAmount);
error FeeTooHigh();
error Unauthorized();
error ProxyNotFound(address);
error OperationFailed(); // a generic error
error TooManyRedemptionRequests();
struct RedemptionRequest {
uint256 requestId;
uint8 status;
uint40 createdAt;
uint256 shares;
uint256 assets;
}
/**
* @notice Sets the maximum amount of assets that can be supplied.
*/
function setMaximumSupply(uint256 maxSupply) external;
/**
* @notice Returns the maximum amount that can be supplied.
*/
function getMaximumSupply() external view returns (uint256);
/**
* @notice Sets the redemption fee.
*
* @param fee The fee in bps to place on the redemption.
* @param maxAmount The maximum amount that the fee cant exceed.
* @param receiver The fee receiver.
*/
function setRedemptionFee(uint16 fee, uint256 maxAmount, address receiver) external;
/**
* @notice Returns the redemption fee.
*/
function getRedemptionFee() external view returns (uint16, uint256, address);
/**
* @notice Sets the minimum redemption amount.
*/
function setMinimumRedemptionAmount(uint256 minimumRedemptionAmount) external;
/**
* @notice Returns the minimum redemption amount.
*/
function getMinimumRedemptionAmount() external view returns (uint256);
/**
* @notice Sets the minimum vault deposit amount. This is the threshold before the amount is deposited
* into the vault as opposed to a minimum amount that can be deposited by a user.
*/
function setMinimumVaultDepositAmount(uint256 minimumVaultDepositAmount) external;
/**
* @notice Returns the minimum vault deposit amount.
*/
function getMinimumVaultDepositAmount() external view returns (uint256);
/**
* @notice Sets the time a redemption batch should be active before it can be executed.
*/
function setBatchDuration(uint256 duration) external;
/**
* @notice Gets the batch duration.
*/
function getBatchDuration() external view returns (uint256);
/**
* @notice Creates and registers a new proxy account.
*/
function createProxy() external returns (address);
/**
* @notice Returns the list of registered proxy accounts.
*/
function getProxies() external view returns (address[] memory addresses);
/**
* @notice The spot token index on the Hyperliquid L1.
*/
function getTokenIndex() external view returns (uint64);
/**
* @notice the address of the vault that the controller is interacting with.
*/
function getVaultAddress() external view returns (address);
/**
* @notice Sets the lockup duration.
*/
function setLockupDuration(uint256 duration) external;
/**
* @notice Returns the lockup duration.
*/
function getLockupDuration() external view returns (uint256);
/**
* @notice Sets the minimum withdrawable equity.
*/
function setMinimumWithdrawableEquity(USD equity) external;
/**
* @notice Returns the minimum withdrawable equity.
*/
function getMinimumWithdrawableEquity() external view returns (USD);
/**
* @notice Returns the active proxy that is being used for deposits.
*/
function getActiveProxy() external view returns (uint256);
/**
* @notice Executes an operation on the queue.
*/
function execute() external returns (bool takenAction);
/**
* @notice The total of assets that are currently claimable for all controllers.
*/
function totalClaimableAssets() external view returns (uint256);
/**
* @notice Returns the exchange rate between the underlying asset and the vault token.
*/
function exchangeRate() external view returns (uint256);
/**
* @notice Returns the storage location of the vault contract.
*/
function STORAGE_LOCATION() external pure returns (bytes32);
/**
* @notice Allows external view contracts to read arbitrary storage slots.
*/
function getStorageSlots(bytes32[] calldata slots) external view returns (bytes32[] memory output);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { Proxy } from "@ambitlabs/hyperdrive-periphery-contracts/contracts/Proxy.sol";
import { CoreReaderLib } from "@ambitlabs/hypercore/contracts/CoreReaderLib.sol";
import { ITokenizedVault } from "../interfaces/ITokenizedVault.sol";
import { ICoreDepositWallet } from "../interfaces/ICoreDepositWallet.sol";
import { CoreWriter } from "@ambitlabs/hypercore/contracts/CoreWriter.sol";
import { CoreWriterLib } from "@ambitlabs/hypercore/contracts/CoreWriterLib.sol";
import { CoreReaderLib } from "@ambitlabs/hypercore/contracts/CoreReaderLib.sol";
import { USD, USDMath } from "./USDMath.sol";
import { MathLib } from "./MathLib.sol";
import { TokenizedVaultUpgradeable } from "./TokenizedVaultUpgradeable.sol";
library CoreControllerLib {
using EnumerableSet for EnumerableSet.AddressSet;
using USDMath for USD;
using SafeERC20 for IERC20Metadata;
using SafeCast for uint256;
function createProxy(TokenizedVaultUpgradeable.TokenizedVaultStorage storage $) public returns (address proxy) {
proxy = address(new Proxy());
$.proxies.add(proxy);
emit ITokenizedVault.CreateProxy(proxy, msg.sender);
}
function getTotalAssets(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $
) public view returns (uint256 total) {
address[] memory proxies = $.proxies.values();
uint256 blockNumber = compositeBlockNumber();
for (uint256 i = 0; i < proxies.length; i++) {
total += getTotalAssets($, proxies[i], blockNumber);
}
total += IERC20Metadata($.asset).balanceOf(address(this)) - $.totalClaimableAssets;
}
function getActiveProxy(TokenizedVaultUpgradeable.TokenizedVaultStorage storage $) public view returns (uint256) {
return (block.timestamp / $.lockupDuration) % $.proxies.length();
}
function getTotalAssets(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
uint256 blockNumber
) private view returns (uint256 total) {
uint8 decimals = IERC20Metadata($.asset).decimals();
total += IERC20Metadata($.asset).balanceOf(proxy);
total += $.deposits[proxy].blockNumber != blockNumber ? 0 : $.deposits[proxy].crediting;
total += MathLib.scale(CoreReaderLib.readSpotBalance(proxy, $.tokenIndex).total, 8, decimals);
total += MathLib.scale(CoreReaderLib.readWithdrawable(proxy).withdrawable, USDMath.DECIMALS, decimals);
total += MathLib.scale(CoreReaderLib.readUserVaultEquity(proxy, $.vaultAddress).equity, USDMath.DECIMALS, decimals);
}
function depositEquity(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
USD equity
) public returns (address proxy) {
proxy = $.proxies.at(getActiveProxy($));
IERC20Metadata($.asset).safeTransfer(proxy, USDMath.scale(equity, IERC20Metadata($.asset).decimals()));
depositEquity($, proxy, equity);
}
function depositEquity(TokenizedVaultUpgradeable.TokenizedVaultStorage storage $, address proxy, USD equity) private {
require(CoreReaderLib.readCoreUserExists(proxy).exists);
transferToCore($, proxy, equity);
// transfer from the spot balance to the perp balance
Proxy(payable(proxy)).execute(
address(CoreWriterLib.CORE_WRITER),
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeUsdClassTransfer(CoreWriterLib.UsdClassTransferAction(USD.unwrap(equity), true))
)
);
// deposit from the perp balance into the vault
Proxy(payable(proxy)).execute(
address(CoreWriterLib.CORE_WRITER),
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeVaultTransfer(CoreWriterLib.VaultTransferAction($.vaultAddress, true, USD.unwrap(equity)))
)
);
emit ITokenizedVault.DepositEquity(proxy, equity, block.timestamp);
}
function transferToCore(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
USD equity
) private {
uint256 assets = USDMath.scale(equity, IERC20Metadata($.asset).decimals());
// track the balance that is inflight
track($, proxy, assets);
// when we transfer via the USDC CoreDepositWallet we transfer to the
// spot balance instead of directly into perps
Proxy(payable(proxy)).execute(
$.asset,
abi.encodeWithSelector(IERC20.approve.selector, $.usdcCoreDepositWallet, assets)
);
Proxy(payable(proxy)).execute(
$.usdcCoreDepositWallet,
abi.encodeWithSelector(ICoreDepositWallet.deposit.selector, assets, type(uint32).max)
);
Proxy(payable(proxy)).execute($.asset, abi.encodeWithSelector(IERC20.approve.selector, $.usdcCoreDepositWallet, 0));
}
function getWithdrawableEquity(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $
) public view returns (USD equity) {
uint256 index = getActiveProxy($);
uint256 length = $.proxies.length();
for (uint256 i = 1; i <= length - 1; i++) {
uint256 j = (index + i) % length;
address proxy = $.proxies.at(j);
if (isLocked($, proxy) == false) {
CoreReaderLib.UserVaultEquity memory userVaultEquity = CoreReaderLib.readUserVaultEquity(proxy, $.vaultAddress);
equity = equity + USD.wrap(userVaultEquity.equity);
}
}
}
function withdrawEquity(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
USD equity
) public returns (USD total) {
USD remaining = equity;
uint256 index = getActiveProxy($);
uint256 length = $.proxies.length();
for (uint256 i = 1; i <= length - 1 && remaining > USDMath.ZERO; i++) {
uint256 j = (index + i) % length;
// if the index is locked then we ignore it
if (isLocked($, $.proxies.at(j))) {
continue;
}
USD withdrawn = withdrawEquity($, $.proxies.at(j), remaining);
// we could actually end up withdrawing more than we need because of the minimum threshold
remaining = remaining - USDMath.min(remaining, withdrawn);
total = total + withdrawn;
}
emit ITokenizedVault.WithdrawEquity(equity, total, block.timestamp);
}
function withdrawEquity(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
USD equity
) private returns (USD) {
CoreReaderLib.UserVaultEquity memory userVaultEquity = CoreReaderLib.readUserVaultEquity(proxy, $.vaultAddress);
// the minimum withdraw from equity is 1/100000000 of the total vault TVL
// and we cant read the total tvl on chain at the moment so we need to
// have a configurable amount
if (USD.wrap(userVaultEquity.equity) < $.minimumWithdrawableEquity) {
return USDMath.ZERO;
}
// the minimum withdraw from equity is 1/100000000 of the total vault TVL
// and we cant read the total tvl on chain at the moment so we need to
// have a configurable amount
equity = USDMath.min(USDMath.max(equity, $.minimumWithdrawableEquity), USD.wrap(userVaultEquity.equity));
Proxy(payable(proxy)).execute(
address(CoreWriterLib.CORE_WRITER),
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeVaultTransfer(CoreWriterLib.VaultTransferAction($.vaultAddress, false, USD.unwrap(equity)))
)
);
emit ITokenizedVault.WithdrawEquity(proxy, equity, block.timestamp);
return equity;
}
function isLocked(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy
) private view returns (bool) {
CoreReaderLib.UserVaultEquity memory userVaultEquity = CoreReaderLib.readUserVaultEquity(
address(proxy),
$.vaultAddress
);
return (block.timestamp * 1000) < userVaultEquity.lockedUntilTimestamp;
}
function getWithdrawableL1(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $
) public view returns (uint256 total) {
uint256 index = getActiveProxy($);
uint256 length = $.proxies.length();
for (uint256 i = 1; i <= length - 1; i++) {
uint256 j = (index + i) % length;
address proxy = $.proxies.at(j);
total += CoreReaderLib.readSpotBalance(proxy, $.tokenIndex).total;
total += USD.wrap(CoreReaderLib.readWithdrawable(address(proxy)).withdrawable).toWei();
}
}
function withdrawL1(TokenizedVaultUpgradeable.TokenizedVaultStorage storage $) public returns (uint256 expected) {
uint256 index = getActiveProxy($);
uint256 length = $.proxies.length();
for (uint256 i = 1; i <= length - 1; i++) {
uint256 j = (index + i) % length;
expected += withdrawL1($, $.proxies.at(j));
}
emit ITokenizedVault.WithdrawL1(expected, block.timestamp);
}
function withdrawL1(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy
) private returns (uint256 expected) {
USD perp = USD.wrap(CoreReaderLib.readWithdrawable(address(proxy)).withdrawable);
if (USD.unwrap(perp) > 0) {
Proxy(payable(proxy)).execute(
CoreWriterLib.CORE_WRITER,
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeUsdClassTransfer(CoreWriterLib.UsdClassTransferAction(USD.unwrap(perp), false))
)
);
expected += perp.toWei();
}
uint256 spot = CoreReaderLib.readSpotBalance(proxy, $.tokenIndex).total;
// note that for the spot amount we also include any perp amount that we just transferred
// as it will exist at the time when the spotSend action is executed
if (spot + perp.toWei() > 0) {
address systemAddress = address(uint160(0x2000000000000000000000000000000000000000) + $.tokenIndex);
Proxy(payable(proxy)).execute(
CoreWriterLib.CORE_WRITER,
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeSpotSend(
CoreWriterLib.SpotSendAction(systemAddress, $.tokenIndex, (spot + perp.toWei()).toUint64())
)
)
);
expected += spot;
}
emit ITokenizedVault.WithdrawL1(proxy, expected, block.timestamp);
}
function getWithdrawable(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $
) public view returns (uint256 total) {
for (uint256 i = 0; i < $.proxies.length(); i++) {
total += IERC20Metadata($.asset).balanceOf($.proxies.at(i));
}
}
function withdraw(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address target,
uint256 assets
) public returns (uint256 expected) {
uint256 remaining = assets;
for (uint256 i = 0; i < $.proxies.length() && remaining > 0; i++) {
remaining -= withdraw($, $.proxies.at(i), target, remaining);
}
expected = assets - remaining;
emit ITokenizedVault.Withdraw(target, assets, expected, block.timestamp);
}
function withdraw(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
address target,
uint256 assets
) private returns (uint256 expected) {
expected = Math.min(assets, IERC20Metadata($.asset).balanceOf(proxy));
if (expected > 0) {
Proxy(payable(proxy)).execute($.asset, abi.encodeCall(IERC20.transfer, (target, expected)));
emit ITokenizedVault.Withdraw(proxy, target, assets, expected, block.timestamp);
}
}
function track(TokenizedVaultUpgradeable.TokenizedVaultStorage storage $, address proxy, uint256 amount) private {
uint256 blockNumber = compositeBlockNumber();
if ($.deposits[proxy].blockNumber != blockNumber) {
$.deposits[proxy].blockNumber = blockNumber;
$.deposits[proxy].crediting = 0;
}
$.deposits[proxy].crediting += amount;
}
function compositeBlockNumber() private view returns (uint256) {
return (uint256(CoreReaderLib.readL1BlockNumber()) << 128) | uint128(block.number);
}
function forceDepositEquity(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
USD equity
) public {
require($.proxies.contains(proxy), ITokenizedVault.ProxyNotFound(proxy));
depositEquity($, proxy, equity);
}
function forceWithdrawEquity(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
USD equity
) public {
require($.proxies.contains(proxy), ITokenizedVault.ProxyNotFound(proxy));
Proxy(payable(proxy)).execute(
address(CoreWriterLib.CORE_WRITER),
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeVaultTransfer(CoreWriterLib.VaultTransferAction($.vaultAddress, false, USD.unwrap(equity)))
)
);
emit ITokenizedVault.WithdrawEquity(proxy, equity, block.timestamp);
}
function forceWithdrawPerp(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
USD amount
) public {
require($.proxies.contains(proxy), ITokenizedVault.ProxyNotFound(proxy));
Proxy(payable(proxy)).execute(
CoreWriterLib.CORE_WRITER,
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeUsdClassTransfer(CoreWriterLib.UsdClassTransferAction(USD.unwrap(amount), false))
)
);
emit ITokenizedVault.WithdrawL1(proxy, USD.unwrap(amount), block.timestamp);
}
function forceWithdrawSpot(
TokenizedVaultUpgradeable.TokenizedVaultStorage storage $,
address proxy,
uint64 _wei
) public {
require($.proxies.contains(proxy), ITokenizedVault.ProxyNotFound(proxy));
address systemAddress = address(uint160(0x2000000000000000000000000000000000000000) + $.tokenIndex);
Proxy(payable(proxy)).execute(
CoreWriterLib.CORE_WRITER,
abi.encodeCall(
CoreWriter.sendRawAction,
CoreWriterLib.encodeSpotSend(CoreWriterLib.SpotSendAction(systemAddress, $.tokenIndex, _wei))
)
);
emit ITokenizedVault.WithdrawL1(proxy, _wei, block.timestamp);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { DoubleEndedQueue } from "@openzeppelin/contracts/utils/structs/DoubleEndedQueue.sol";
library DoubleEndedQueueLib {
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;
function firstOrDefault(DoubleEndedQueue.Bytes32Deque storage queue) internal view returns (uint256) {
return queue.empty() ? 0 : uint256(queue.front());
}
function id(DoubleEndedQueue.Bytes32Deque storage queue, uint256 i) internal view returns (uint256) {
return uint256(queue.at(i));
}
function enqueue(DoubleEndedQueue.Bytes32Deque storage queue, uint256 requestId) internal {
queue.pushBack(bytes32(requestId));
}
function dequeue(DoubleEndedQueue.Bytes32Deque storage queue) internal {
queue.popFront();
}
function remove(DoubleEndedQueue.Bytes32Deque storage queue, uint256 value) internal {
uint256[] memory v = values(queue);
queue.clear();
for (uint256 i; i < v.length; i++) {
if (v[i] != value) {
queue.pushBack(bytes32(v[i]));
}
}
}
function values(DoubleEndedQueue.Bytes32Deque storage queue) internal view returns (uint256[] memory v) {
v = new uint256[](queue.length());
for (uint256 i; i < v.length; i++) {
v[i] = uint256(queue.at(i));
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
library MathLib {
function scale(uint256 amount, uint8 from, uint8 to) internal pure returns (uint256) {
if (from < to) {
return amount * 10 ** uint256(to - from);
}
if (from > to) {
return amount / 10 ** uint256(from - to);
}
return amount;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { MathLib } from "./MathLib.sol";
type USD is uint64;
function add(USD a, USD b) pure returns (USD) {
return USD.wrap(USD.unwrap(a) + USD.unwrap(b));
}
function sub(USD a, USD b) pure returns (USD) {
return USD.wrap(USD.unwrap(a) - USD.unwrap(b));
}
function gt(USD a, USD b) pure returns (bool) {
return USD.unwrap(a) > USD.unwrap(b);
}
function lt(USD a, USD b) pure returns (bool) {
return USD.unwrap(a) < USD.unwrap(b);
}
using { add as + } for USD global;
using { sub as - } for USD global;
using { gt as > } for USD global;
using { lt as < } for USD global;
library USDMath {
using SafeCast for uint256;
uint8 public constant DECIMALS = 6;
USD public constant ZERO = USD.wrap(0);
function scale(USD usd, uint8 decimals) internal pure returns (uint256) {
return MathLib.scale(USD.unwrap(usd), DECIMALS, decimals);
}
/// @dev convert a USD amount used in perps and vaults which is 6 decimals to a wei amount which is 8 decimals
function toWei(USD usd) internal pure returns (uint64) {
return (USD.unwrap(usd) * 1e2);
}
/// @dev converts a wei amounts which is 8 decimals to a USD amount used in perps and vaults which is 6 decimals.
function fromWei(uint256 _wei) internal pure returns (USD) {
return USD.wrap(_wei.toUint64() / 1e2);
}
function min(USD a, USD b) internal pure returns (USD) {
return USD.unwrap(a) < USD.unwrap(b) ? a : b;
}
function max(USD a, USD b) internal pure returns (USD) {
return USD.unwrap(a) > USD.unwrap(b) ? a : b;
}
}{
"evmVersion": "cancun",
"viaIR": true,
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {
"contracts/protocol/TokenizedVaultUpgradeable.sol": {
"CoreControllerLib": "0x749cadd76eb31dc37af2bebeb3663d04eca613dd"
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minimumAmount","type":"uint256"}],"name":"BelowMinimumRedemptionAmount","type":"error"},{"inputs":[],"name":"BlockReentrancyFailed","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","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":"ERC7540NotAuthorizedController","type":"error"},{"inputs":[],"name":"ERC7540NotAuthorizedOperator","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"FailedCall","type":"error"},{"inputs":[],"name":"FeeTooHigh","type":"error"},{"inputs":[],"name":"FinalizedAmountNotEnough","type":"error"},{"inputs":[],"name":"InvalidAssetMetadata","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"OperationFailed","type":"error"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"ProxyNotFound","type":"error"},{"inputs":[],"name":"ReentrancyGuardFailed","type":"error"},{"inputs":[],"name":"RequestAlreadyFinalized","type":"error"},{"inputs":[],"name":"RequestNotAllowed","type":"error"},{"inputs":[],"name":"RequestNotCancellable","type":"error"},{"inputs":[],"name":"RequestNotFound","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"TooManyRedemptionRequests","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"ZeroAddressNotAllowed","type":"error"},{"inputs":[],"name":"ZeroAmountNotAllowed","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":"controller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"ClaimRedeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"proxy","type":"address"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"CreateProxy","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":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"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"proxy","type":"address"},{"indexed":false,"internalType":"USD","name":"equity","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"DepositEquity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"address","name":"controller","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Enqueue","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Execute","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"FinalizeBatchRedemption","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"controller","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"OperatorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"controller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"RedeemRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"SetBatchDuration","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"SetLockupDuration","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxSupply","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"SetMaximumSupply","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"SetMinimumRedemptionAmount","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"SetMinimumVaultDepositAmount","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"USD","name":"equity","type":"uint64"},{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"SetMinimumWithdrawableEquity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"fee","type":"uint16"},{"indexed":false,"internalType":"uint256","name":"maxAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"address","name":"caller","type":"address"}],"name":"SetRedemptionFee","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":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"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":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"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"expected","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"proxy","type":"address"},{"indexed":false,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"expected","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"USD","name":"amount","type":"uint64"},{"indexed":false,"internalType":"USD","name":"expected","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"WithdrawEquity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"proxy","type":"address"},{"indexed":false,"internalType":"USD","name":"amount","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"WithdrawEquity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"expected","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"WithdrawL1","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"proxy","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"WithdrawL1","type":"event"},{"inputs":[],"name":"ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_REDEMPTION_REQUESTS_PER_ACCOUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STORAGE_LOCATION","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"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":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"controller","type":"address"}],"name":"claimRedeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"address","name":"controller","type":"address"}],"name":"claimableRedeemRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":"createProxy","outputs":[{"internalType":"address","name":"proxy","type":"address"}],"stateMutability":"nonpayable","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":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"exchangeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"execute","outputs":[{"internalType":"bool","name":"takenAction","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"proxy","type":"address"},{"internalType":"USD","name":"equity","type":"uint64"}],"name":"forceDepositEquity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"proxy","type":"address"},{"internalType":"USD","name":"equity","type":"uint64"}],"name":"forceWithdrawEquity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"proxy","type":"address"},{"internalType":"USD","name":"amount","type":"uint64"}],"name":"forceWithdrawPerp","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"proxy","type":"address"},{"internalType":"uint64","name":"_wei","type":"uint64"}],"name":"forceWithdrawSpot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getActiveProxy","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBatchDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLockupDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaximumSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinimumRedemptionAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinimumVaultDepositAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinimumWithdrawableEquity","outputs":[{"internalType":"USD","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProxies","outputs":[{"internalType":"address[]","name":"addresses","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRedemptionFee","outputs":[{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMembers","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"slots","type":"bytes32[]"}],"name":"getStorageSlots","outputs":[{"internalType":"bytes32[]","name":"output","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTokenIndex","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVaultAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"contract IERC20Metadata","name":"asset_","type":"address"},{"internalType":"address","name":"vaultAddress","type":"address"},{"internalType":"uint64","name":"tokenIndex","type":"uint64"},{"internalType":"uint256","name":"lockupDuration","type":"uint256"},{"internalType":"address","name":"usdcCoreDepositWallet","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"controller","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"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":"uint256","name":"requestId","type":"uint256"},{"internalType":"address","name":"controller","type":"address"}],"name":"pendingRedeemRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"requestId","type":"uint256"},{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewClaimRedeem","outputs":[{"internalType":"uint256","name":"assets","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":"","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"controller","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"controller","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"requestRedeem","outputs":[{"internalType":"uint256","name":"requestId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"resume","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"duration","type":"uint256"}],"name":"setBatchDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"duration","type":"uint256"}],"name":"setLockupDuration","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"maximumSupply","type":"uint256"}],"name":"setMaximumSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minimumRedemptionAmount","type":"uint256"}],"name":"setMinimumRedemptionAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minimumVaultDepositAmount","type":"uint256"}],"name":"setMinimumVaultDepositAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"USD","name":"equity","type":"uint64"}],"name":"setMinimumWithdrawableEquity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"fee","type":"uint16"},{"internalType":"uint256","name":"maxAmount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"setRedemptionFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"total","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalClaimableAssets","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":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"controller","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"pure","type":"function"}]Contract Creation Code
60a080604052346100c257306080525f516020615d365f395f51905f525460ff8160401c166100b3576002600160401b03196001600160401b03821601610060575b604051615c6f90816100c78239608051818181611e0d01526127120152f35b6001600160401b0319166001600160401b039081175f516020615d365f395f51905f525581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a15f80610041565b63f92ee8a960e01b5f5260045ffd5b5f80fdfe60806040526004361015610011575f80fd5b5f5f3560e01c806301e1d114146133ce57806301ffc9a714613300578063046f7da21461324657806306fdde031461316457806307a2d13a14613146578063095ea7b3146130a15780630a28a477146129a1578063114154541461302f57806312ef03a214612f7657806318160ddd14612f4c5780631a473aec14612dfd57806323b872dd14612d20578063248a9ca314612ce857806327de8b5e14612c48578063295d3ee814612bff5780632f2ff15d14612bb45780632f6b013214612b8a578063313ce56714612b6457806336568abe14612b1f57806338d52e0f14612aea578063390a37c114612a4a5780633ba0b9a914612a1f578063402d267d146129fa57806349801605146129d05780634bedc548146129a65780634cdad506146129a15780634ef1ccd1146128ee5780634f1ef286146126c257806352821caf14611e6157806352d1902d14611dfa578063558a729714611d1d5780635603d62b14611c675780635c975abb14611c385780636146195414611ba057806365cacaa414611b58578063684649a614611a7557806368c2294914611a425780636e553f651461198557806370a0823114611940578063729a60c0146118ac57806375b238fc146118845780637acf0167146117da5780637d41c86e146113c35780638456cb59146113105780638cb2c5d11461125d5780639010d07c1461120b57806391d14854146111b5578063939dbd941461118d57806394bf804d146110c557806395d89b4114610fd257806398d0040814610e835780639cd6f00914610e11578063a20d176414610d02578063a217fddf14610ce6578063a3246ad314610c6b578063a9059cbb14610c39578063ac8b243614610c0f578063ad3cb1cc14610bca578063b3d7f6b914610bab578063b460af9414610b67578063b58bccc414610ab4578063b6363cf214610a50578063ba08765214610855578063bc87783f1461082b578063c63d75b6146107fe578063c6e6f59214610450578063ca15c873146107c8578063ccfd43a8146107ac578063ce96cb7714610786578063d547741f14610732578063d905777e1461070e578063dbdb35c81461062f578063dd62ed3e146105e7578063e7a1107f1461053f578063ea9a8c7e1461047c578063eaed1d0714610455578063ef8b30f714610450578063f5a23d8d146103de578063f5b541a6146103b65763f9c5fa4a1461038a575f80fd5b346103b357806003193601126103b35760205f51602061597a5f395f51905f5254604051908152f35b80fd5b50346103b357806003193601126103b35760206040515f516020615aba5f395f51905f528152f35b50346103b35760403660031901126103b357602090600435906103ff61343e565b918082525f516020615a1a5f395f51905f528452600360ff600160408520015460501c16145f14610436575090505b604051908152f35b6002610443604094613795565b019082528352205461042e565b6135a9565b50346103b35760403660031901126103b357602061042e61047461343e565b600435613afc565b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f51602061595a5f395f51905f5254036104e5575080f35b5f51602061595a5f395f51905f52819055604080519182523360208301527f0cda53608b4427d683228e7a8a9960664e60a2ab99f516961f478377cbcd9e129190819081015b0390a180f35b6282b42960e81b8252600482fd5b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f516020615bda5f395f51905f5254036105a8575080f35b805f516020615bda5f395f51905f52556040519081527fe06216b0feab92fdedd96ceff6052818c4dc1e3c707ef8b72c59a4e146566ef760203392a280f35b50346103b35760403660031901126103b357610601613412565b61061261060c61343e565b9161375d565b9060018060a01b03165f52602052602060405f2054604051908152f35b50346103b35760203660031901126103b3576004356001600160401b03811680910361070a575f516020615b5a5f395f51905f5282525f516020615afa5f395f51905f5260209081526040808420335f908152925290205460ff161561053157806001600160401b035f5160206159ba5f395f51905f525416036106b1575080f35b806001600160401b03195f5160206159ba5f395f51905f525416175f5160206159ba5f395f51905f52556040519081527ffcf7f5e2e842e5109f36c4bbb233a0aa0cfe86a4799aebe3932942c9c033051a60203392a280f35b5080fd5b50346103b35760203660031901126103b357602061042e61072d613412565b613a68565b50346103b35760403660031901126103b35761078260043561075261343e565b9061077d610778825f525f516020615afa5f395f51905f52602052600160405f20015490565b613c4e565b613dbe565b5080f35b50346103b35760203660031901126103b3576020906107a3613412565b50604051908152f35b50346103b357806003193601126103b357602060405160058152f35b50346103b35760203660031901126103b357604060209160043581525f5160206158da5f395f51905f5283522054604051908152f35b50346103b35760203660031901126103b357610818613412565b50602061042e6108266136ce565b614baf565b50346103b357806003193601126103b35760205f516020615bda5f395f51905f5254604051908152f35b50346103b3576108643661356f565b91909261086f613e00565b610877613e5b565b61088083614a49565b906001600160a01b03841690828215610a41576001600160a01b038516948515610a3257806108c26108b76108c793979597613a68565b878382821115613a0c565b613795565b9260028401855b85546001600160801b0381169060801c141580610a29575b15610986576109809061097a876108fc81613e82565b928388525f516020615a1a5f395f51905f5260205261093460408920858a528760205260408a20548084108185180218938491614aed565b604080513381526020810185905290810182905290949088908e907f340822ce1f8159b2fd086cac55fcd928317dfd1a511fbb448d32104292670b0890606090a46136c1565b95613a5b565b936108ce565b60208589858a6109ad848f60018060a01b035f516020615b1a5f395f51905f525416614b73565b828260405186815283888201527ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db60403392a4604080518581526020810192909252429082015233907fbbbdee62287b5bf3bee13cab60a29ad729cf38109bccbd2a986a11c99b8ca7049080606081015b0390a461042e613e35565b508015156108e6565b6342bcdf7f60e11b8252600482fd5b6342bcdf7f60e11b8152600490fd5b50346103b35760403660031901126103b3576040610a6c613412565b91610a7561343e565b9260018060a01b031681525f516020615c1a5f395f51905f52602052209060018060a01b03165f52602052602060ff60405f2054166040519015158152f35b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f516020615b7a5f395f51905f525403610b1d575080f35b5f516020615b7a5f395f51905f52819055604080519182523360208301527fb1391a645f865d677928062aee966e2889c8840475aabc8622abe3de58b7c0f791908190810161052b565b50346103b357610b763661356f565b9291809150610b8a57602082604051908152f35b606492633fa733bb60e21b835260018060a01b031660045260245280604452fd5b50346103b35760203660031901126103b357602061042e600435613b7f565b50346103b357806003193601126103b35750610c0b604051610bed604082613489565b60058152640352e302e360dc1b6020820152604051918291826133e8565b0390f35b50346103b357806003193601126103b35760205f516020615b7a5f395f51905f5254604051908152f35b50346103b35760403660031901126103b357610c60610c56613412565b6024359033613c94565b602060405160018152f35b50346103b35760203660031901126103b35760043581525f5160206158da5f395f51905f52602052604081206040519181548084526020840192825260208220915b818110610cd057610c0b85610cc481870382613489565b6040519182918261352d565b8254845260209093019260019283019201610cad565b50346103b357806003193601126103b357602090604051908152f35b50346103b35760203660031901126103b3576004356001600160401b03811161070a573660238201121561070a5780600401356001600160401b038111610e0d573660248260051b84010111610e0d57610d5b81613a36565b90610d696040519283613489565b808252610d7581613a36565b602083019390601f1901368537845b828110610dd05750505090604051928392602084019060208552518091526040840192915b818110610db7575050500390f35b8251845285945060209384019390920191600101610da9565b610dd981613a4d565b9083811015610df95760249060051b83010135548160051b850152610d84565b634e487b7160e01b87526032600452602487fd5b8280fd5b50346103b357806003193601126103b357606061ffff5f516020615ada5f395f51905f5254167f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0f5460018060a01b035f5160206159fa5f395f51905f5254169060405192835260208301526040820152f35b50346103b35760803660031901126103b357602435600435610ea3613428565b91610eac613454565b90610eb5613e00565b610ebd613e5b565b610ec682614a49565b6001600160a01b038216928315610fc3576001600160a01b038516928315610fb45790610f3e83886109ad948460209b525f516020615a1a5f395f51905f528b52610f39604083209184610f1982613795565b600185015490959060501c60ff16600314610f9f57915b82821115613a0c565b614aed565b6040805133815260208101839052908101859052909687929091869088907f340822ce1f8159b2fd086cac55fcd928317dfd1a511fbb448d32104292670b0890606090a45f516020615b1a5f395f51905f52546001600160a01b0316614b73565b80896040925260028701602052205491610f30565b6342bcdf7f60e11b8752600487fd5b6342bcdf7f60e11b8652600486fd5b50346103b357806003193601126103b35760405190805f51602061593a5f395f51905f52549061100182613644565b808552916001811690811561109e5750600114611035575b610c0b8461102981860382613489565b604051918291826133e8565b5f51602061593a5f395f51905f5281527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa939250905b8082106110845750909150810160200161102982611019565b91926001816020925483858801015201910190929161106b565b60ff191660208087019190915292151560051b850190920192506110299150839050611019565b50346103b35760403660031901126103b3576004356110e261343e565b916110eb613e5b565b6110f66108266136ce565b80831161116c576020838561110a82613b7f565b91611117818484336150c2565b60408051848152602081019290925242908201526001600160a01b039091169033907f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f69080606081015b0390a361042e614914565b6064928463284ff66760e01b845260018060a01b0316600452602452604452fd5b50346103b357806003193601126103b35760206040515f51602061597a5f395f51905f528152f35b50346103b35760403660031901126103b35760406111d161343e565b9160043581525f516020615afa5f395f51905f52602052209060018060a01b03165f52602052602060ff60405f2054166040519015158152f35b50346103b35760403660031901126103b35761124460209160043581525f5160206158da5f395f51905f52835260406024359120615280565b905460405160039290921b1c6001600160a01b03168152f35b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f5160206159da5f395f51905f5254036112c6575080f35b5f5160206159da5f395f51905f52819055604080519182523360208301527f0a9361015864308f0d61d8a231789df1fa0aaa41d558ba2156692c7463893a8091908190810161052b565b50346103b357806003193601126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f908152925290205460ff16156113b557611363613e5b565b600160ff195f516020615b3a5f395f51905f525416175f516020615b3a5f395f51905f52557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a180f35b6282b42960e81b8152600490fd5b50346103b3576113d23661356f565b6113dd929192613e5b565b6113e681614a49565b6113ee613e00565b6001600160a01b0383169081156117cb5782156117bc573382036117aa5761141583613b46565b5f516020615a3a5f395f51905f525490818110611795575050600561145261143c86613795565b6001600160801b0390548181169060801c031690565b1015611786577f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0654936114836151a1565b61158f575b610a1e8594939260408860026114fe7f1fdc681a13d8c5da54e301c7ce6542dcde4581e4725043fdab2db12ddc574506968a60209d525f516020615a1a5f395f51905f528d5282858520016114de8b8254613a5b565b9055826114ea82613795565b018b85528d52848420541561157d57613795565b018882528a5220611510868254613a5b565b9055857fbe66b23ecac9efd53a4f20600f0f77edabd7e9a3a2d001df4d175a3874bbb5296080604051878152888c820152336040820152426060820152a261155a85308330614aa2565b6040805133815260208101969096526001600160a01b0390911694918291820190565b6108c28b61158a83613795565b6157e7565b9361159990613a4d565b93847f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0655846115c781615511565b505f5160206158ba5f395f51905f52548060801c6001600160801b036001820192166001600160801b038316146117745788525f516020615bfa5f395f51905f526020528160408920556001600160801b035f5160206158ba5f395f51905f52549181199082199060801b16169116175f5160206158ba5f395f51905f52556040519060c082018281106001600160401b038211176117605760209860026114fe7f1fdc681a13d8c5da54e301c7ce6542dcde4581e4725043fdab2db12ddc57450696610a1e9660038d9c9b9a9760409788528083528f830164ffffffffff4216815288840190888252606085016001815261172664ffffffffff60808801948c865260a08901968d88528d5260205f516020615a1a5f395f51905f5290528d8d20985189558160018a0195511682198654161785555116839069ffffffffff000000000082549160281b169069ffffffffff00000000001916179055565b5181549060ff60501b9060ff60501b9060501b16169060ff60501b1916179055518684015551910155965050509850509293945050611488565b634e487b7160e01b89526041600452602489fd5b634e487b71895260416020526024601cfd5b631b3ac1a760e01b8552600485fd5b630a082f2f60e21b8752600452602452604485fd5b60016214074360e21b03198552600485fd5b6307a1cab560e11b8552600485fd5b6342bcdf7f60e11b8552600485fd5b50346103b357806003193601126103b35760405163193b3ccf60e21b81525f51602061597a5f395f51905f5260048201529060208260248173749cadd76eb31dc37af2bebeb3663d04eca613dd5af49081156118785790611841575b602090604051908152f35b506020813d602011611870575b8161185b60209383613489565b8101031261186c5760209051611836565b5f80fd5b3d915061184e565b604051903d90823e3d90fd5b50346103b357806003193601126103b35760206040515f516020615b5a5f395f51905f528152f35b50346103b357806003193601126103b3576040517f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb018054808352908352909160208301917f3081df4eec3e863c7b62fdb6eb14585dd1c2538f6ff3d9ff145a5642157bb2a1915b81811061192a57610c0b85610cc481870382613489565b8254845260209093019260019283019201611913565b50346103b35760203660031901126103b3576020906040906001600160a01b03611968613412565b1681525f51602061591a5f395f51905f5283522054604051908152f35b50346103b35760403660031901126103b3576004356119a261343e565b916119ab613e5b565b6119b36136ce565b808311611a2157602083856119c782614baf565b916119d4838284336150c2565b604080519182526020820184905242908201526001600160a01b039091169033907f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f6908060608101611161565b60649284633c8097d960e11b845260018060a01b0316600452602452604452fd5b50346103b357806003193601126103b35760206001600160401b035f5160206159ba5f395f51905f525416604051908152f35b50346103b357806003193601126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f908152925290205460ff16156113b557604051635e26fa4d60e01b81525f51602061597a5f395f51905f52600482015260208160248173749cadd76eb31dc37af2bebeb3663d04eca613dd5af4908115611b4d5760209291611b20575b506040516001600160a01b039091168152f35b611b409150823d8411611b46575b611b388183613489565b8101906139ed565b5f611b0d565b503d611b2e565b6040513d84823e3d90fd5b50346103b357806003193601126103b3577f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb04546040516001600160a01b039091168152602090f35b50346103b357806003193601126103b357611bb9613e00565b611bc1613e5b565b7f7a2690543f05b94273f26531201d3f783a1582ff4e1fd0b5224e0f07a0278f0054431115611c2957437f7a2690543f05b94273f26531201d3f783a1582ff4e1fd0b5224e0f07a0278f00556020611c176137cd565b611c1f613e35565b6040519015158152f35b6396ee3fd160e01b8152600490fd5b50346103b357806003193601126103b357602060ff5f516020615b3a5f395f51905f5254166040519015158152f35b50346103b35760403660031901126103b35780611c82613412565b611c8a613473565b90611c93613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b15611d1857604051637c794bdb60e01b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152908290829060649082905af48015611b4d57611d075750f35b81611d1191613489565b6103b35780f35b505050fd5b50346103b35760403660031901126103b357611d37613412565b602435918215158093036103b3573381525f516020615c1a5f395f51905f526020526040812060018060a01b0383165f526020528260ff60405f205416151503611d8657602060405160018152f35b6040903381525f516020615c1a5f395f51905f526020522060018060a01b0382165f5260205260405f2060ff1981541660ff841617905560405191825260018060a01b0316907fceb576d9f15e4e200fdb5096d64d5dfd667e16def20c1eefd14256d8e3faa26760203392a35f8080610c60565b50346103b357806003193601126103b3577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163003611e525760206040515f516020615a5a5f395f51905f528152f35b63703e46dd60e11b8152600490fd5b50346103b35760e03660031901126103b3576004356001600160401b03811161070a57611e9290369060040161350f565b6024356001600160401b038111610e0d57611eb190369060040161350f565b6044356001600160a01b038116908190036126be57611ece613454565b6084356001600160401b03811681036126ba5760c4356001600160a01b03811694908590036126b6575f516020615b9a5f395f51905f5254956001600160401b0360ff8860401c16159716801590816126ae575b60011490816126a4575b15908161269b575b5061268c578660016001600160401b03195f516020615b9a5f395f51905f525416175f516020615b9a5f395f51905f525561265c575b611f72614ef8565b8051906001600160401b038211611760578190611f9c5f5160206158fa5f395f51905f5254613644565b601f81116125e2575b50602090601f8311600114612566578a9261255b575b50508160011b915f199060031b1c1916175f5160206158fa5f395f51905f52555b8051906001600160401b038211612547576120045f51602061593a5f395f51905f5254613644565b601f81116124d8575b50602090601f83116001146124555791806004969492602096948b9261244a575b50508160011b915f199060031b1c1916175f51602061593a5f395f51905f52555b612057614ef8565b8261206181614f52565b9015612442575b5f516020615b1a5f395f51905f52549060ff60a01b9060a01b16906affffffffffffffffffffff60a81b1617175f516020615b1a5f395f51905f52556120ac614ef8565b6120b4614ef8565b6120bc614ef8565b6120c4614ef8565b6120cd33614c56565b61241c575b6120db33614d05565b6123e9575b5f516020615b5a5f395f51905f5288525f516020615afa5f395f51905f5284528760016040822001545f516020615b5a5f395f51905f5282525f516020615afa5f395f51905f5286528160016040822001555f516020615b5a5f395f51905f527fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff8380a45f516020615aba5f395f51905f5288525f516020615afa5f395f51905f5284528760016040822001545f516020615aba5f395f51905f5282525f516020615afa5f395f51905f5286528160016040822001555f516020615aba5f395f51905f527fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff8380a4601e5f516020615b7a5f395f51905f52555f195f5160206159da5f395f51905f52557f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0380546001600160a01b031916841790557f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0480546001600160e01b03191660a09290921b67ffffffffffffffff60a01b16919091176001600160a01b039290921691909117905560a4355f516020615bda5f395f51905f525560405163313ce56760e01b815292839182905afa80156123de576122ce9185916123af575b506136b0565b80600a0290600a82040361239b575f51602061595a5f395f51905f52556bffffffffffffffffffffffff60a01b7f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb165416177f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb16556123485780f35b60ff60401b195f516020615b9a5f395f51905f5254165f516020615b9a5f395f51905f52557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a180f35b634e487b7160e01b84526011600452602484fd5b6123d1915060203d6020116123d7575b6123c98183613489565b810190613731565b5f6122c8565b503d6123bf565b6040513d86823e3d90fd5b5f516020615b5a5f395f51905f5288525f5160206158da5f395f51905f5284526124163360408a206155bf565b506120e0565b8780525f5160206158da5f395f51905f52845261243c3360408a206155bf565b506120d2565b506012612068565b015190505f8061202e565b5f51602061593a5f395f51905f5289528189209190601f1984168a5b8181106124c057509260019285926020989660049a9896106124a8575b505050811b015f51602061593a5f395f51905f525561204f565b01515f1960f88460031b161c191690555f808061248e565b92936020600181928786015181550195019301612471565b5f51602061593a5f395f51905f5289527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa601f840160051c8101916020851061253d575b601f0160051c01905b818110612532575061200d565b898155600101612525565b909150819061251c565b634e487b7160e01b88526041600452602488fd5b015190505f80611fbb565b5f5160206158fa5f395f51905f528b52818b209250601f1984168b5b8181106125ca57509084600195949392106125b2575b505050811b015f5160206158fa5f395f51905f5255611fdc565b01515f1960f88460031b161c191690555f8080612598565b92936020600181928786015181550195019301612582565b5f5160206158fa5f395f51905f528b529091507f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0601f840160051c81019160208510612652575b90601f859493920160051c01905b8181106126445750611fa5565b8b8155849350600101612637565b9091508190612629565b600160401b60ff60401b195f516020615b9a5f395f51905f525416175f516020615b9a5f395f51905f5255611f6a565b63f92ee8a960e01b8852600488fd5b9050155f611f34565b303b159150611f2c565b889150611f22565b8680fd5b8580fd5b8380fd5b5060403660031901126103b3576126d7613412565b906024356001600160401b03811161070a573660238201121561070a576127089036906024816004013591016134d9565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163081149081156128cc575b506128bd575f516020615b5a5f395f51905f5282525f516020615afa5f395f51905f5260209081526040808420335f908152925290205460ff1615610531576040516352d1902d60e01b8152926001600160a01b0381169190602085600481865afa80958596612885575b506127c157634c9c8ce360e01b84526004839052602484fd5b9091845f516020615a5a5f395f51905f5281036128735750813b15612861575f516020615a5a5f395f51905f5280546001600160a01b031916821790557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28151839015612847578083602061078295519101845af4612841614f23565b9161585b565b505050346128525780f35b63b398979f60e01b8152600490fd5b634c9c8ce360e01b8452600452602483fd5b632a87526960e21b8552600452602484fd5b9095506020813d6020116128b5575b816128a160209383613489565b810103126128b15751945f6127a8565b8480fd5b3d9150612894565b63703e46dd60e11b8252600482fd5b5f516020615a5a5f395f51905f52546001600160a01b0316141590505f61273d565b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f516020615a3a5f395f51905f525403612957575080f35b5f516020615a3a5f395f51905f52819055604080519182523360208301527f0d34d0b9c521e222c3f85829e41c0a339601b044b087fca5d66ebd837ae7124391908190810161052b565b61346a565b50346103b357806003193601126103b35760205f5160206159da5f395f51905f5254604051908152f35b50346103b357806003193601126103b35760205f516020615a3a5f395f51905f5254604051908152f35b50346103b35760203660031901126103b357612a14613412565b50602061042e6136ce565b50346103b357806003193601126103b357602061042e612a45612a4061367c565b6136b0565b613b46565b50346103b35760403660031901126103b35780612a65613412565b612a6d613473565b90612a76613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b15611d185760405163d1870dc960e01b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152908290829060649082905af48015611b4d57611d075750f35b50346103b357806003193601126103b3575f516020615b1a5f395f51905f52546040516001600160a01b039091168152602090f35b50346103b35760403660031901126103b357612b3961343e565b336001600160a01b03821603612b555761078290600435613dbe565b63334bd91960e11b8252600482fd5b50346103b357806003193601126103b3576020612b7f61367c565b60ff60405191168152f35b50346103b357806003193601126103b35760205f51602061595a5f395f51905f5254604051908152f35b50346103b35760403660031901126103b357610782600435612bd461343e565b90612bfa610778825f525f516020615afa5f395f51905f52602052600160405f20015490565b613d78565b50346103b357806003193601126103b35760206001600160401b037f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb045460a01c16604051908152f35b50346103b35760403660031901126103b35780612c63613412565b612c6b613473565b90612c74613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b15611d185760405163cd3a810b60e01b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152908290829060649082905af48015611b4d57611d075750f35b50346103b35760203660031901126103b357602061042e6004355f525f516020615afa5f395f51905f52602052600160405f20015490565b50346103b35760603660031901126103b357612d3a613412565b612d4261343e565b60443591612d4f8161375d565b335f90815260209190915260409020545f198110612d73575b50610c609350613c94565b838110612de2576001600160a01b03821615612dce573315612dba57610c609450612d9d8261375d565b60018060a01b0333165f526020528360405f20910390555f612d68565b634a1406b160e11b85526004859052602485fd5b63e602df0560e01b85526004859052602485fd5b637dc7a0d960e11b8552336004526024526044839052606484fd5b50346103b35760603660031901126103b35760043561ffff811680910361070a57602435612e29613428565b5f516020615b5a5f395f51905f5284525f516020615afa5f395f51905f5260209081526040808620335f908152925290205460ff1615612f3e57611388831015612f2f57916080917f3418e749c0fc000a135389d4c2de15d697e75059a04711ac1a37b2a0080a98a1938261ffff195f516020615ada5f395f51905f525416175f516020615ada5f395f51905f5255817f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0f5560018060a01b031690816bffffffffffffffffffffffff60a01b5f5160206159fa5f395f51905f525416175f5160206159fa5f395f51905f525560405192835260208301526040820152336060820152a180f35b63cd4e616760e01b8452600484fd5b6282b42960e81b8452600484fd5b50346103b357806003193601126103b35760205f51602061599a5f395f51905f5254604051908152f35b503461186c57604036600319011261186c57612f90613412565b612f98613473565b90612fa1613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b1561186c5760405163014c6f1160e41b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152905f90829060649082905af4801561302457613016575080f35b61302291505f90613489565b005b6040513d5f823e3d90fd5b3461186c57604036600319011261186c576004355f525f516020615a1a5f395f51905f5260205260405f20600360ff600183015460501c1614801590613095575b15613081575060205f604051908152f35b61309060209160243590613bb9565b61042e565b50600281015415613070565b3461186c57604036600319011261186c576130ba613412565b602435903315613133576001600160a01b0316908115613120576130dd3361375d565b825f526020528060405f20556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b3461186c57602036600319011261186c57602061042e600435613b46565b3461186c575f36600319011261186c576040515f5f5160206158fa5f395f51905f525461319081613644565b808452906001811690811561322257506001146131b8575b610c0b8361102981850382613489565b5f5160206158fa5f395f51905f525f9081527f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0939250905b808210613208575090915081016020016110296131a8565b9192600181602092548385880101520191019092916131f0565b60ff191660208086019190915291151560051b8401909101915061102990506131a8565b3461186c575f36600319011261186c57335f9081527fb16e88c42fd4e48df2dd6a2eabd6bc9aec654ec170056b470819f8892cc6431c602052604090205460ff16156132f2575f516020615b3a5f395f51905f525460ff8116156132e35760ff19165f516020615b3a5f395f51905f52557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b638dfc202b60e01b5f5260045ffd5b6282b42960e81b5f5260045ffd5b3461186c57602036600319011261186c5760043563ffffffff60e01b811680910361186c57602090635a05180f60e01b81149081156133a5575b8115613394575b8115613383575b8115613372575b8115613361575b506040519015158152f35b6301ffc9a760e01b14905082613356565b63e3bc4e6560e01b8114915061334f565b632264541760e21b81149150613348565b631883ba3960e21b81149150613341565b9050637965db0b60e01b811480156133be575b9061333a565b506301ffc9a760e01b81146133b8565b3461186c575f36600319011261186c57602061042e6135c7565b602060409281835280519182918282860152018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b038216820361186c57565b604435906001600160a01b038216820361186c57565b602435906001600160a01b038216820361186c57565b606435906001600160a01b038216820361186c57565b3461186c575f80fd5b602435906001600160401b038216820361186c57565b90601f801991011681019081106001600160401b038211176134aa57604052565b634e487b7160e01b5f52604160045260245ffd5b6001600160401b0381116134aa57601f01601f191660200190565b9291926134e5826134be565b916134f36040519384613489565b82948184528183011161186c578281602093845f960137010152565b9080601f8301121561186c5781602061352a933591016134d9565b90565b60206040818301928281528451809452019201905f5b8181106135505750505090565b82516001600160a01b0316845260209384019390920191600101613543565b606090600319011261186c57600435906024356001600160a01b038116810361186c57906044356001600160a01b038116810361186c5790565b3461186c57602036600319011261186c57602061042e600435614baf565b60405163fd7b363f60e01b81525f51602061597a5f395f51905f52600482015260208160248173749cadd76eb31dc37af2bebeb3663d04eca613dd5af4908115613024575f91613615575090565b90506020813d60201161363c575b8161363060209383613489565b8101031261186c575190565b3d9150613623565b90600182811c92168015613672575b602083101461365e57565b634e487b7160e01b5f52602260045260245ffd5b91607f1691613653565b60ff5f516020615b1a5f395f51905f525460a01c1660ff811161369c5790565b634e487b7160e01b5f52601160045260245ffd5b60ff16604d811161369c57600a0a90565b9190820391821161369c57565b60ff5f516020615b3a5f395f51905f52541661372d575f5160206159da5f395f51905f52545f1914613728576137026135c7565b5f5160206159da5f395f51905f52549081811061371f5750505f90565b61352a916136c1565b5f1990565b5f90565b9081602091031261186c575160ff8116810361186c5790565b8181029291811591840414171561369c57565b6001600160a01b03165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020526040902090565b6001600160a01b03165f9081527f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0a6020526040902090565b60015f5160206158ba5f395f51905f52546001600160801b0381169060801c14146139b5575f5160206158ba5f395f51905f52546001600160801b0381169060801c145f1461394c575f5b5f525f516020615a1a5f395f51905f5260205260405f206001810180546138545f516020615b7a5f395f51905f525464ffffffffff8316613a5b565b421061390d5760501c60ff166001146138f6575b50600381018054806138da57506138826002830154613b46565b905b5561388e81613ed1565b156138cb575b50604080513381524260208201527f892cd8f5b436bd5fb7dac1f11aafb73345d892ba3e9fe09cd94d95ba84928e739190a1600190565b6138d4906144e2565b5f613894565b6138e76002840154613b46565b90818082109118021890613884565b805460ff60501b1916600160511b1790555f613868565b5050604080513381524260208201527f892cd8f5b436bd5fb7dac1f11aafb73345d892ba3e9fe09cd94d95ba84928e73925090819081015b0390a15f90565b5f5160206158ba5f395f51905f52546001600160801b0381169060801c146139a3576001600160801b035f5160206158ba5f395f51905f5254165f525f516020615bfa5f395f51905f5260205260405f2054613818565b634e487b715f5260326020526024601cfd5b604080513381524260208201527f892cd8f5b436bd5fb7dac1f11aafb73345d892ba3e9fe09cd94d95ba84928e739181908101613945565b9081602091031261186c57516001600160a01b038116810361186c5790565b15613a1657505050565b632e52afbb60e21b5f5260018060a01b031660045260245260445260645ffd5b6001600160401b0381116134aa5760051b60200190565b5f19811461369c5760010190565b9190820180921161369c57565b90613a735f92613795565b613a8d816001600160801b0390548181169060801c031690565b905f5b828110613a9c57505050565b613aa6818361542e565b805f525f516020615a1a5f395f51905f52602052600360ff600160405f20015460501c1614613ad9575b50600101613a90565b60019195613af5915f526002840160205260405f205490613a5b565b9490613ad0565b90815f525f516020615a1a5f395f51905f52602052600360ff600160405f20015460501c1603613b4057613b31600291613795565b01905f5260205260405f205490565b50505f90565b613b4e6135c7565b906001820180921161369c575f51602061599a5f395f51905f52546001810180911161369c5761352a925f92614be4565b613b876135c7565b906001820180921161369c575f51602061599a5f395f51905f52546001810180911161369c5761352a92600192614be4565b90600282015480155f14613bdb5750600390915b015490818082109118021890565b6003830154613be992615473565b90600390613bcd565b335f9081527f448256db8f8fb95ee3eaaf89c1051414494e85cebb6057fcf996cc3d0ccfb456602052604090205460ff1615613c2a57565b63e2517d3f60e01b5f52336004525f516020615aba5f395f51905f5260245260445ffd5b5f8181525f516020615afa5f395f51905f526020908152604080832033845290915290205460ff1615613c7e5750565b63e2517d3f60e01b5f523360045260245260445ffd5b6001600160a01b0316908115613d65576001600160a01b0316918215613d5257815f525f51602061591a5f395f51905f5260205260405f2054818110613d3957817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f51602061591a5f395f51905f5284520360405f2055845f525f51602061591a5f395f51905f52825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b63ec442f0560e01b5f525f60045260245ffd5b634b637e8f60e11b5f525f60045260245ffd5b613d828282614dbe565b9182613d8d57505090565b5f9182525f5160206158da5f395f51905f526020526040909120613dba916001600160a01b0316906155bf565b5090565b613dc88282614e5c565b9182613dd357505090565b5f9182525f5160206158da5f395f51905f526020526040909120613dba916001600160a01b03169061573e565b5f516020615bba5f395f51905f525c613e265760015f516020615bba5f395f51905f525d565b630800025b60e31b5f5260045ffd5b5f516020615bba5f395f51905f525c15613e26575f5f516020615bba5f395f51905f525d565b60ff5f516020615b3a5f395f51905f525416613e7357565b63d93c066560e01b5f5260045ffd5b80546001600160801b0381169060801c145f14613e9e57505f90565b80546001600160801b0381169060801c146139a357806001600160801b03806001935416165f520160205260405f205490565b5f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015613024575f9061448f575b613f3091505f51602061597a5f395f51905f5254906136c1565b60405163fe6ba89360e01b81525f51602061597a5f395f51905f52600482015273749cadd76eb31dc37af2bebeb3663d04eca613dd9291602082602481875af48015613024575f9061445b575b613f879250613a5b565b600382015490808211614449576127105f5b11614441576002835493015491818082109118021892825f525f516020615a1a5f395f51905f52602052600360ff600160405f20015460501c1614614432575f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115613024575f916143ff575b50602061403c6064925f51602061597a5f395f51905f5254906136c1565b9260405192838092630b7477a160e31b82525f51602061597a5f395f51905f5260048301523060248301528960448301525af480156130245785915f916143c8575b50819261408e8261409c946136c1565b818082109118021890613a5b565b106143b95760405191606083018381106001600160401b038211176134aa5760405261ffff5f516020615ada5f395f51905f525416908184526127106141297f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0f549360208701948552604060018060a01b035f5160206159fa5f395f51905f52541697019687528761374a565b9251945192048481189085110280851894909390926001600160a01b0316806143b3575033955b61417161415d87836136c1565b5f51602061597a5f395f51905f5254613a5b565b5f51602061597a5f395f51905f52555f8381525f516020615a1a5f395f51905f526020526040902060018101805460ff60501b1916600360501b1790556002018290556141be86826136c1565b835f525f516020615a1a5f395f51905f52602052600360405f2001553015613d6557305f525f51602061591a5f395f51905f5260205260405f20548281106143985791608091817f9aa101ee82db17aad9b30847940ac950a2518b6898926bc51bd2b06e4edb8b3f94305f525f51602061591a5f395f51905f526020520360405f2055815f51602061599a5f395f51905f5254035f51602061599a5f395f51905f52555f6040518381527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60203092a36040519182526020820152866040820152426060820152a20361436f575b50505f5160206158ba5f395f51905f52546001600160801b0381169060801c811461435d576001816143036001600160801b03936001600160801b03165f525f516020615bfa5f395f51905f5260205260405f2090565b505f61432c826001600160801b03165f525f516020615bfa5f395f51905f5260205260405f2090565b5501166001600160801b03195f5160206158ba5f395f51905f525416175f5160206158ba5f395f51905f5255600190565b634e487b715f5260316020526024601cfd5b5f516020615b1a5f395f51905f525461439192906001600160a01b0316614b73565b5f806142ac565b905063391434e360e21b5f523060045260245260445260645ffd5b95614150565b63c7dbbd7b60e01b5f5260045ffd5b9150506020813d6020116143f7575b816143e460209383613489565b8101031261186c5751849061409c61407e565b3d91506143d7565b90506020813d60201161442a575b8161441a60209383613489565b8101031261186c5751602061401e565b3d915061440d565b63f1a6019360e01b5f5260045ffd5b505050505f90565b61271061445682846136c1565b613f99565b506020823d602011614487575b8161447560209383613489565b8101031261186c57613f879151613f7d565b3d9150614468565b506020813d6020116144bb575b816144a960209383613489565b8101031261186c57613f309051613f16565b3d915061449c565b9081602091031261186c57516001600160401b038116810361186c5790565b5f516020615b1a5f395f51905f525460405163313ce56760e01b815290602090829060049082906001600160a01b03165afa908115613024575f916148f5575b506040516322298c0160e01b81525f51602061597a5f395f51905f52600482015273749cadd76eb31dc37af2bebeb3663d04eca613dd91602082602481865af4918215613024575f926148c1575b50600184019164ffffffffff835460281c1680151590816148a1575b5061489a575f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015613024575f90614866575b6145f091505f51602061597a5f395f51905f5254906136c1565b60405163fe6ba89360e01b81525f51602061597a5f395f51905f526004820152602081602481895af4908115613024575f91614830575b509261463961463f9261464595613a5b565b92614ffd565b90613a5b565b6003840154908181106148225750505f5b6127108111614699575b50509054604080513381524260208201529192507f9da6493a92039daf47d1f2d7a782299c5994c6323eb1e972f69c432089ec52bf91a2565b60405162c32e5560e31b81525f51602061597a5f395f51905f52600482015290602082602481875af4918215613024575f92614800575b505f516020615b1a5f395f51905f525460405163313ce56760e01b8152929390602090849060049082906001600160a01b03165afa928315613024576020946001600160401b03614738614733829760449761476b965f926147e1575b50615050565b615091565b1680868316105f146147d95750915b805469ffffffffff000000000019164260281b69ffffffffff000000000016179055565b60405194859384926306d4739f60e41b84525f51602061597a5f395f51905f5260048501521660248301525af48015613024576147aa575b8080614660565b6147cb9060203d6020116147d2575b6147c38183613489565b8101906144c3565b505f6147a3565b503d6147b9565b905091614747565b6147f99192508b3d8d116123d7576123c98183613489565b905f61472d565b6004925061481c9060203d6020116147d2576147c38183613489565b916146d0565b61482b916136c1565b614656565b9390506020843d60201161485e575b8161484c60209383613489565b8101031261186c579251614639614627565b3d915061483f565b506020813d602011614892575b8161488060209383613489565b8101031261186c576145f090516145d6565b3d9150614873565b5050505050565b600591500164ffffffffff811161369c5764ffffffffff1642105f61458c565b9091506020813d6020116148ed575b816148dd60209383613489565b8101031261186c5751905f614570565b3d91506148d0565b61490e915060203d6020116123d7576123c98183613489565b5f614522565b5f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015613024575f90614a15575b61497391505f51602061597a5f395f51905f5254906136c1565b5f51602061595a5f395f51905f525481101561498c5750565b6149a96147336001600160401b03926149a361367c565b90615050565b60405163049d734b60e51b81525f51602061597a5f395f51905f5260048201529116602482015260208160448173749cadd76eb31dc37af2bebeb3663d04eca613dd5af48015613024576149fa5750565b614a129060203d602011611b4657611b388183613489565b50565b506020813d602011614a41575b81614a2f60209383613489565b8101031261186c576149739051614959565b3d9150614a22565b60018060a01b0316803314908115614a73575b5015614a6457565b630da8d92160e21b5f5260045ffd5b5f9081525f516020615c1a5f395f51905f526020908152604080832033845290915281205460ff169150614a5c565b6040516323b872dd60e01b60208201526001600160a01b039283166024820152929091166044830152606480830193909352918152614aeb91614ae6608483613489565b615228565b565b929190600360ff600186015460501c1603614b6457614aeb9184545f526002820160205260405f2054818082109118021884614b5f614b2d838098613bb9565b968794614b48865f51602061597a5f395f51905f52546136c1565b5f51602061597a5f395f51905f52558354906152a9565b6153bd565b6301b2776960e11b5f5260045ffd5b60405163a9059cbb60e01b60208201526001600160a01b03929092166024830152604480830193909352918152614aeb91614ae6606483613489565b5f51602061599a5f395f51905f5254906001820180921161369c57614bd26135c7565b6001810180911161369c5761352a925f925b9291614bf1818386615473565b926004811015614c42576001809116149182614c17575b505061352a9250151590613a5b565b9080925015614c2e5761352a930915155f80614c08565b634e487b7160e01b5f52601260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b6001600160a01b0381165f9081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff16614d00576001600160a01b03165f8181527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d60205260408120805460ff191660011790553391907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4600190565b505f90565b6001600160a01b0381165f9081527fb16e88c42fd4e48df2dd6a2eabd6bc9aec654ec170056b470819f8892cc6431c602052604090205460ff16614d00576001600160a01b03165f8181527fb16e88c42fd4e48df2dd6a2eabd6bc9aec654ec170056b470819f8892cc6431c60205260408120805460ff191660011790553391905f516020615b5a5f395f51905f52907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b038616845290915290205460ff16613b40575f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b038616845290915290205460ff1615613b40575f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b60ff5f516020615b9a5f395f51905f525460401c1615614f1457565b631afcd79f60e31b5f5260045ffd5b3d15614f4d573d90614f34826134be565b91614f426040519384613489565b82523d5f602084013e565b606090565b5f8091604051602081019063313ce56760e01b825260048152614f76602482613489565b51916001600160a01b03165afa614f8b614f23565b9080614fc5575b614f9e575b505f905f90565b6020815191818082019384920101031261186c575160ff8111614f97579060ff6001921690565b50602081511015614f92565b9060ff8091169116039060ff821161369c57565b604d811161369c57600a0a90565b8115614c2e570490565b9060ff81168060081061503557600811615015575090565b9061502f60ff61502961352a946008614fd1565b16614fe5565b90614ff3565b509061504a60ff615029600861352a95614fd1565b9061374a565b9060ff81166006811061507c57600610615068575090565b9061502f60ff615029600661352a95614fd1565b509061504a60ff61502961352a946006614fd1565b6001600160401b0381116150ab576001600160401b031690565b6306dfcc6560e41b5f52604060045260245260445ffd5b906150e68360018060a01b035f516020615b1a5f395f51905f525416843091614aa2565b6001600160a01b0316928315613d52577fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791816151336040935f51602061599a5f395f51905f5254613a5b565b5f51602061599a5f395f51905f5255855f525f51602061591a5f395f51905f52602052825f20818154019055855f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208651858152a3825194855260208501526001600160a01b031692a3565b6001600160801b035f5160206158ba5f395f51905f52548181169060801c03168015615222576151dd5f5160206158ba5f395f51905f52613e82565b5f525f516020615a1a5f395f51905f52602052600160405f209114908161520d575b50615208575f90565b600190565b6001015460501c60ff1660021490505f6151ff565b50600190565b905f602091828151910182855af115613024575f513d61527757506001600160a01b0381163b155b6152575750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b60011415615250565b8054821015615295575f5260205f2001905f90565b634e487b7160e01b5f52603260045260245ffd5b9290916002840190835f528160205260405f20548111614b6457835f528160205260405f205481106153a05750825f526020525f60408120556152fc836001600160801b0390548181169060801c031690565b9061530682613a36565b916153146040519384613489565b808352615323601f1991613a36565b013660208401375f5b825181101561535357806153426001928761542e565b61534c8286615847565b520161532c565b505f8085559092905b825181101561539957808261537360019386615847565b5103615380575b0161535c565b61539461538d8286615847565b51876157e7565b61537a565b5050509050565b92909193505f526020526153b960405f209182546136c1565b9055565b919060028301908154808211614b645780821061541157505050506153e28154615613565b50545f525f516020615a1a5f395f51905f526020525f6003604082208281558260018201558260028201550155565b916154236153b99495926003946136c1565b9055019182546136c1565b615448816001600160801b0390548181169060801c031690565b8210156139a3576001600160801b0380600193818085541691160116165f520160205260405f205490565b90915f19838309928083029283808610950394808603951461550457848311156154ec5790829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b82634e487b715f52156003026011186020526024601cfd5b50509061352a9250614ff3565b805f525f516020615a7a5f395f51905f5260205260405f2054155f14614d00575f516020615a9a5f395f51905f5254600160401b8110156134aa5761559061557a8260018594015f516020615a9a5f395f51905f52555f516020615a9a5f395f51905f52615280565b819391549060031b91821b915f19901b19161790565b90555f516020615a9a5f395f51905f5254905f525f516020615a7a5f395f51905f5260205260405f2055600190565b6001810190825f528160205260405f2054155f1461560c578054600160401b8110156134aa576155f961557a826001879401855584615280565b905554915f5260205260405f2055600190565b5050505f90565b5f8181525f516020615a7a5f395f51905f5260205260409020548015613b40575f19810181811161369c575f516020615a9a5f395f51905f52545f1981019190821161369c578181036156e2575b5050505f516020615a9a5f395f51905f525480156156ce575f1901615693815f516020615a9a5f395f51905f52615280565b8154905f199060031b1b191690555f516020615a9a5f395f51905f52555f525f516020615a7a5f395f51905f526020525f6040812055600190565b634e487b7160e01b5f52603160045260245ffd5b61571c6156ff61557a935f516020615a9a5f395f51905f52615280565b90549060031b1c9283925f516020615a9a5f395f51905f52615280565b90555f525f516020615a7a5f395f51905f5260205260405f20555f8080615661565b906001820191815f528260205260405f20548015155f14614441575f19810181811161369c5782545f1981019190821161369c578181036157b2575b505050805480156156ce575f1901906157938282615280565b8154905f199060031b1b19169055555f526020525f6040812055600190565b6157d26157c261557a9386615280565b90549060031b1c92839286615280565b90555f528360205260405f20555f808061577a565b908154908160801c6001600160801b0380600183011693168314615835576001600160801b03165f526001830160205260405f20556001600160801b0382549181199060801b169116179055565b634e487b715f5260416020526024601cfd5b80518210156152955760209160051b010190565b9061587f575080511561587057805190602001fd5b63d6bda27560e01b5f5260045ffd5b815115806158b0575b615890575090565b639996b31560e01b5f9081526001600160a01b0391909116600452602490fd5b50803b1561588856fe6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0bc1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e8237170593200052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace046af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb156af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace026af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb136af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb126af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb106af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb096af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0d360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb086af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0797667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b9296af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0e02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b6268000773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300a49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb11f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00e26c696bf0e34aaf444e67b257b0ce1f00d161ab27c76bcd8c8582bed8ddd0006af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb056af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0c58b5cdfd1ca129592c69bde289fd6324080dd2d81a29959004bd7c0735b6e300a2646970667358221220a646d9e17d1766daed6e435df22cc7d75b4a6be909005dedfe45b18c4760d62964736f6c634300081c0033f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00
Deployed Bytecode
0x60806040526004361015610011575f80fd5b5f5f3560e01c806301e1d114146133ce57806301ffc9a714613300578063046f7da21461324657806306fdde031461316457806307a2d13a14613146578063095ea7b3146130a15780630a28a477146129a1578063114154541461302f57806312ef03a214612f7657806318160ddd14612f4c5780631a473aec14612dfd57806323b872dd14612d20578063248a9ca314612ce857806327de8b5e14612c48578063295d3ee814612bff5780632f2ff15d14612bb45780632f6b013214612b8a578063313ce56714612b6457806336568abe14612b1f57806338d52e0f14612aea578063390a37c114612a4a5780633ba0b9a914612a1f578063402d267d146129fa57806349801605146129d05780634bedc548146129a65780634cdad506146129a15780634ef1ccd1146128ee5780634f1ef286146126c257806352821caf14611e6157806352d1902d14611dfa578063558a729714611d1d5780635603d62b14611c675780635c975abb14611c385780636146195414611ba057806365cacaa414611b58578063684649a614611a7557806368c2294914611a425780636e553f651461198557806370a0823114611940578063729a60c0146118ac57806375b238fc146118845780637acf0167146117da5780637d41c86e146113c35780638456cb59146113105780638cb2c5d11461125d5780639010d07c1461120b57806391d14854146111b5578063939dbd941461118d57806394bf804d146110c557806395d89b4114610fd257806398d0040814610e835780639cd6f00914610e11578063a20d176414610d02578063a217fddf14610ce6578063a3246ad314610c6b578063a9059cbb14610c39578063ac8b243614610c0f578063ad3cb1cc14610bca578063b3d7f6b914610bab578063b460af9414610b67578063b58bccc414610ab4578063b6363cf214610a50578063ba08765214610855578063bc87783f1461082b578063c63d75b6146107fe578063c6e6f59214610450578063ca15c873146107c8578063ccfd43a8146107ac578063ce96cb7714610786578063d547741f14610732578063d905777e1461070e578063dbdb35c81461062f578063dd62ed3e146105e7578063e7a1107f1461053f578063ea9a8c7e1461047c578063eaed1d0714610455578063ef8b30f714610450578063f5a23d8d146103de578063f5b541a6146103b65763f9c5fa4a1461038a575f80fd5b346103b357806003193601126103b35760205f51602061597a5f395f51905f5254604051908152f35b80fd5b50346103b357806003193601126103b35760206040515f516020615aba5f395f51905f528152f35b50346103b35760403660031901126103b357602090600435906103ff61343e565b918082525f516020615a1a5f395f51905f528452600360ff600160408520015460501c16145f14610436575090505b604051908152f35b6002610443604094613795565b019082528352205461042e565b6135a9565b50346103b35760403660031901126103b357602061042e61047461343e565b600435613afc565b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f51602061595a5f395f51905f5254036104e5575080f35b5f51602061595a5f395f51905f52819055604080519182523360208301527f0cda53608b4427d683228e7a8a9960664e60a2ab99f516961f478377cbcd9e129190819081015b0390a180f35b6282b42960e81b8252600482fd5b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f516020615bda5f395f51905f5254036105a8575080f35b805f516020615bda5f395f51905f52556040519081527fe06216b0feab92fdedd96ceff6052818c4dc1e3c707ef8b72c59a4e146566ef760203392a280f35b50346103b35760403660031901126103b357610601613412565b61061261060c61343e565b9161375d565b9060018060a01b03165f52602052602060405f2054604051908152f35b50346103b35760203660031901126103b3576004356001600160401b03811680910361070a575f516020615b5a5f395f51905f5282525f516020615afa5f395f51905f5260209081526040808420335f908152925290205460ff161561053157806001600160401b035f5160206159ba5f395f51905f525416036106b1575080f35b806001600160401b03195f5160206159ba5f395f51905f525416175f5160206159ba5f395f51905f52556040519081527ffcf7f5e2e842e5109f36c4bbb233a0aa0cfe86a4799aebe3932942c9c033051a60203392a280f35b5080fd5b50346103b35760203660031901126103b357602061042e61072d613412565b613a68565b50346103b35760403660031901126103b35761078260043561075261343e565b9061077d610778825f525f516020615afa5f395f51905f52602052600160405f20015490565b613c4e565b613dbe565b5080f35b50346103b35760203660031901126103b3576020906107a3613412565b50604051908152f35b50346103b357806003193601126103b357602060405160058152f35b50346103b35760203660031901126103b357604060209160043581525f5160206158da5f395f51905f5283522054604051908152f35b50346103b35760203660031901126103b357610818613412565b50602061042e6108266136ce565b614baf565b50346103b357806003193601126103b35760205f516020615bda5f395f51905f5254604051908152f35b50346103b3576108643661356f565b91909261086f613e00565b610877613e5b565b61088083614a49565b906001600160a01b03841690828215610a41576001600160a01b038516948515610a3257806108c26108b76108c793979597613a68565b878382821115613a0c565b613795565b9260028401855b85546001600160801b0381169060801c141580610a29575b15610986576109809061097a876108fc81613e82565b928388525f516020615a1a5f395f51905f5260205261093460408920858a528760205260408a20548084108185180218938491614aed565b604080513381526020810185905290810182905290949088908e907f340822ce1f8159b2fd086cac55fcd928317dfd1a511fbb448d32104292670b0890606090a46136c1565b95613a5b565b936108ce565b60208589858a6109ad848f60018060a01b035f516020615b1a5f395f51905f525416614b73565b828260405186815283888201527ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db60403392a4604080518581526020810192909252429082015233907fbbbdee62287b5bf3bee13cab60a29ad729cf38109bccbd2a986a11c99b8ca7049080606081015b0390a461042e613e35565b508015156108e6565b6342bcdf7f60e11b8252600482fd5b6342bcdf7f60e11b8152600490fd5b50346103b35760403660031901126103b3576040610a6c613412565b91610a7561343e565b9260018060a01b031681525f516020615c1a5f395f51905f52602052209060018060a01b03165f52602052602060ff60405f2054166040519015158152f35b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f516020615b7a5f395f51905f525403610b1d575080f35b5f516020615b7a5f395f51905f52819055604080519182523360208301527fb1391a645f865d677928062aee966e2889c8840475aabc8622abe3de58b7c0f791908190810161052b565b50346103b357610b763661356f565b9291809150610b8a57602082604051908152f35b606492633fa733bb60e21b835260018060a01b031660045260245280604452fd5b50346103b35760203660031901126103b357602061042e600435613b7f565b50346103b357806003193601126103b35750610c0b604051610bed604082613489565b60058152640352e302e360dc1b6020820152604051918291826133e8565b0390f35b50346103b357806003193601126103b35760205f516020615b7a5f395f51905f5254604051908152f35b50346103b35760403660031901126103b357610c60610c56613412565b6024359033613c94565b602060405160018152f35b50346103b35760203660031901126103b35760043581525f5160206158da5f395f51905f52602052604081206040519181548084526020840192825260208220915b818110610cd057610c0b85610cc481870382613489565b6040519182918261352d565b8254845260209093019260019283019201610cad565b50346103b357806003193601126103b357602090604051908152f35b50346103b35760203660031901126103b3576004356001600160401b03811161070a573660238201121561070a5780600401356001600160401b038111610e0d573660248260051b84010111610e0d57610d5b81613a36565b90610d696040519283613489565b808252610d7581613a36565b602083019390601f1901368537845b828110610dd05750505090604051928392602084019060208552518091526040840192915b818110610db7575050500390f35b8251845285945060209384019390920191600101610da9565b610dd981613a4d565b9083811015610df95760249060051b83010135548160051b850152610d84565b634e487b7160e01b87526032600452602487fd5b8280fd5b50346103b357806003193601126103b357606061ffff5f516020615ada5f395f51905f5254167f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0f5460018060a01b035f5160206159fa5f395f51905f5254169060405192835260208301526040820152f35b50346103b35760803660031901126103b357602435600435610ea3613428565b91610eac613454565b90610eb5613e00565b610ebd613e5b565b610ec682614a49565b6001600160a01b038216928315610fc3576001600160a01b038516928315610fb45790610f3e83886109ad948460209b525f516020615a1a5f395f51905f528b52610f39604083209184610f1982613795565b600185015490959060501c60ff16600314610f9f57915b82821115613a0c565b614aed565b6040805133815260208101839052908101859052909687929091869088907f340822ce1f8159b2fd086cac55fcd928317dfd1a511fbb448d32104292670b0890606090a45f516020615b1a5f395f51905f52546001600160a01b0316614b73565b80896040925260028701602052205491610f30565b6342bcdf7f60e11b8752600487fd5b6342bcdf7f60e11b8652600486fd5b50346103b357806003193601126103b35760405190805f51602061593a5f395f51905f52549061100182613644565b808552916001811690811561109e5750600114611035575b610c0b8461102981860382613489565b604051918291826133e8565b5f51602061593a5f395f51905f5281527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa939250905b8082106110845750909150810160200161102982611019565b91926001816020925483858801015201910190929161106b565b60ff191660208087019190915292151560051b850190920192506110299150839050611019565b50346103b35760403660031901126103b3576004356110e261343e565b916110eb613e5b565b6110f66108266136ce565b80831161116c576020838561110a82613b7f565b91611117818484336150c2565b60408051848152602081019290925242908201526001600160a01b039091169033907f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f69080606081015b0390a361042e614914565b6064928463284ff66760e01b845260018060a01b0316600452602452604452fd5b50346103b357806003193601126103b35760206040515f51602061597a5f395f51905f528152f35b50346103b35760403660031901126103b35760406111d161343e565b9160043581525f516020615afa5f395f51905f52602052209060018060a01b03165f52602052602060ff60405f2054166040519015158152f35b50346103b35760403660031901126103b35761124460209160043581525f5160206158da5f395f51905f52835260406024359120615280565b905460405160039290921b1c6001600160a01b03168152f35b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f5160206159da5f395f51905f5254036112c6575080f35b5f5160206159da5f395f51905f52819055604080519182523360208301527f0a9361015864308f0d61d8a231789df1fa0aaa41d558ba2156692c7463893a8091908190810161052b565b50346103b357806003193601126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f908152925290205460ff16156113b557611363613e5b565b600160ff195f516020615b3a5f395f51905f525416175f516020615b3a5f395f51905f52557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a180f35b6282b42960e81b8152600490fd5b50346103b3576113d23661356f565b6113dd929192613e5b565b6113e681614a49565b6113ee613e00565b6001600160a01b0383169081156117cb5782156117bc573382036117aa5761141583613b46565b5f516020615a3a5f395f51905f525490818110611795575050600561145261143c86613795565b6001600160801b0390548181169060801c031690565b1015611786577f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0654936114836151a1565b61158f575b610a1e8594939260408860026114fe7f1fdc681a13d8c5da54e301c7ce6542dcde4581e4725043fdab2db12ddc574506968a60209d525f516020615a1a5f395f51905f528d5282858520016114de8b8254613a5b565b9055826114ea82613795565b018b85528d52848420541561157d57613795565b018882528a5220611510868254613a5b565b9055857fbe66b23ecac9efd53a4f20600f0f77edabd7e9a3a2d001df4d175a3874bbb5296080604051878152888c820152336040820152426060820152a261155a85308330614aa2565b6040805133815260208101969096526001600160a01b0390911694918291820190565b6108c28b61158a83613795565b6157e7565b9361159990613a4d565b93847f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0655846115c781615511565b505f5160206158ba5f395f51905f52548060801c6001600160801b036001820192166001600160801b038316146117745788525f516020615bfa5f395f51905f526020528160408920556001600160801b035f5160206158ba5f395f51905f52549181199082199060801b16169116175f5160206158ba5f395f51905f52556040519060c082018281106001600160401b038211176117605760209860026114fe7f1fdc681a13d8c5da54e301c7ce6542dcde4581e4725043fdab2db12ddc57450696610a1e9660038d9c9b9a9760409788528083528f830164ffffffffff4216815288840190888252606085016001815261172664ffffffffff60808801948c865260a08901968d88528d5260205f516020615a1a5f395f51905f5290528d8d20985189558160018a0195511682198654161785555116839069ffffffffff000000000082549160281b169069ffffffffff00000000001916179055565b5181549060ff60501b9060ff60501b9060501b16169060ff60501b1916179055518684015551910155965050509850509293945050611488565b634e487b7160e01b89526041600452602489fd5b634e487b71895260416020526024601cfd5b631b3ac1a760e01b8552600485fd5b630a082f2f60e21b8752600452602452604485fd5b60016214074360e21b03198552600485fd5b6307a1cab560e11b8552600485fd5b6342bcdf7f60e11b8552600485fd5b50346103b357806003193601126103b35760405163193b3ccf60e21b81525f51602061597a5f395f51905f5260048201529060208260248173749cadd76eb31dc37af2bebeb3663d04eca613dd5af49081156118785790611841575b602090604051908152f35b506020813d602011611870575b8161185b60209383613489565b8101031261186c5760209051611836565b5f80fd5b3d915061184e565b604051903d90823e3d90fd5b50346103b357806003193601126103b35760206040515f516020615b5a5f395f51905f528152f35b50346103b357806003193601126103b3576040517f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb018054808352908352909160208301917f3081df4eec3e863c7b62fdb6eb14585dd1c2538f6ff3d9ff145a5642157bb2a1915b81811061192a57610c0b85610cc481870382613489565b8254845260209093019260019283019201611913565b50346103b35760203660031901126103b3576020906040906001600160a01b03611968613412565b1681525f51602061591a5f395f51905f5283522054604051908152f35b50346103b35760403660031901126103b3576004356119a261343e565b916119ab613e5b565b6119b36136ce565b808311611a2157602083856119c782614baf565b916119d4838284336150c2565b604080519182526020820184905242908201526001600160a01b039091169033907f4e2ca0515ed1aef1395f66b5303bb5d6f1bf9d61a353fa53f73f8ac9973fa9f6908060608101611161565b60649284633c8097d960e11b845260018060a01b0316600452602452604452fd5b50346103b357806003193601126103b35760206001600160401b035f5160206159ba5f395f51905f525416604051908152f35b50346103b357806003193601126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f908152925290205460ff16156113b557604051635e26fa4d60e01b81525f51602061597a5f395f51905f52600482015260208160248173749cadd76eb31dc37af2bebeb3663d04eca613dd5af4908115611b4d5760209291611b20575b506040516001600160a01b039091168152f35b611b409150823d8411611b46575b611b388183613489565b8101906139ed565b5f611b0d565b503d611b2e565b6040513d84823e3d90fd5b50346103b357806003193601126103b3577f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb04546040516001600160a01b039091168152602090f35b50346103b357806003193601126103b357611bb9613e00565b611bc1613e5b565b7f7a2690543f05b94273f26531201d3f783a1582ff4e1fd0b5224e0f07a0278f0054431115611c2957437f7a2690543f05b94273f26531201d3f783a1582ff4e1fd0b5224e0f07a0278f00556020611c176137cd565b611c1f613e35565b6040519015158152f35b6396ee3fd160e01b8152600490fd5b50346103b357806003193601126103b357602060ff5f516020615b3a5f395f51905f5254166040519015158152f35b50346103b35760403660031901126103b35780611c82613412565b611c8a613473565b90611c93613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b15611d1857604051637c794bdb60e01b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152908290829060649082905af48015611b4d57611d075750f35b81611d1191613489565b6103b35780f35b505050fd5b50346103b35760403660031901126103b357611d37613412565b602435918215158093036103b3573381525f516020615c1a5f395f51905f526020526040812060018060a01b0383165f526020528260ff60405f205416151503611d8657602060405160018152f35b6040903381525f516020615c1a5f395f51905f526020522060018060a01b0382165f5260205260405f2060ff1981541660ff841617905560405191825260018060a01b0316907fceb576d9f15e4e200fdb5096d64d5dfd667e16def20c1eefd14256d8e3faa26760203392a35f8080610c60565b50346103b357806003193601126103b3577f00000000000000000000000014a68bacb0440b5568f30c8a0e4d1c76396f68b66001600160a01b03163003611e525760206040515f516020615a5a5f395f51905f528152f35b63703e46dd60e11b8152600490fd5b50346103b35760e03660031901126103b3576004356001600160401b03811161070a57611e9290369060040161350f565b6024356001600160401b038111610e0d57611eb190369060040161350f565b6044356001600160a01b038116908190036126be57611ece613454565b6084356001600160401b03811681036126ba5760c4356001600160a01b03811694908590036126b6575f516020615b9a5f395f51905f5254956001600160401b0360ff8860401c16159716801590816126ae575b60011490816126a4575b15908161269b575b5061268c578660016001600160401b03195f516020615b9a5f395f51905f525416175f516020615b9a5f395f51905f525561265c575b611f72614ef8565b8051906001600160401b038211611760578190611f9c5f5160206158fa5f395f51905f5254613644565b601f81116125e2575b50602090601f8311600114612566578a9261255b575b50508160011b915f199060031b1c1916175f5160206158fa5f395f51905f52555b8051906001600160401b038211612547576120045f51602061593a5f395f51905f5254613644565b601f81116124d8575b50602090601f83116001146124555791806004969492602096948b9261244a575b50508160011b915f199060031b1c1916175f51602061593a5f395f51905f52555b612057614ef8565b8261206181614f52565b9015612442575b5f516020615b1a5f395f51905f52549060ff60a01b9060a01b16906affffffffffffffffffffff60a81b1617175f516020615b1a5f395f51905f52556120ac614ef8565b6120b4614ef8565b6120bc614ef8565b6120c4614ef8565b6120cd33614c56565b61241c575b6120db33614d05565b6123e9575b5f516020615b5a5f395f51905f5288525f516020615afa5f395f51905f5284528760016040822001545f516020615b5a5f395f51905f5282525f516020615afa5f395f51905f5286528160016040822001555f516020615b5a5f395f51905f527fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff8380a45f516020615aba5f395f51905f5288525f516020615afa5f395f51905f5284528760016040822001545f516020615aba5f395f51905f5282525f516020615afa5f395f51905f5286528160016040822001555f516020615aba5f395f51905f527fbd79b86ffe0ab8e8776151514217cd7cacd52c909f66475c3af44e129f0b00ff8380a4601e5f516020615b7a5f395f51905f52555f195f5160206159da5f395f51905f52557f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0380546001600160a01b031916841790557f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0480546001600160e01b03191660a09290921b67ffffffffffffffff60a01b16919091176001600160a01b039290921691909117905560a4355f516020615bda5f395f51905f525560405163313ce56760e01b815292839182905afa80156123de576122ce9185916123af575b506136b0565b80600a0290600a82040361239b575f51602061595a5f395f51905f52556bffffffffffffffffffffffff60a01b7f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb165416177f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb16556123485780f35b60ff60401b195f516020615b9a5f395f51905f5254165f516020615b9a5f395f51905f52557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a180f35b634e487b7160e01b84526011600452602484fd5b6123d1915060203d6020116123d7575b6123c98183613489565b810190613731565b5f6122c8565b503d6123bf565b6040513d86823e3d90fd5b5f516020615b5a5f395f51905f5288525f5160206158da5f395f51905f5284526124163360408a206155bf565b506120e0565b8780525f5160206158da5f395f51905f52845261243c3360408a206155bf565b506120d2565b506012612068565b015190505f8061202e565b5f51602061593a5f395f51905f5289528189209190601f1984168a5b8181106124c057509260019285926020989660049a9896106124a8575b505050811b015f51602061593a5f395f51905f525561204f565b01515f1960f88460031b161c191690555f808061248e565b92936020600181928786015181550195019301612471565b5f51602061593a5f395f51905f5289527f46a2803e59a4de4e7a4c574b1243f25977ac4c77d5a1a4a609b5394cebb4a2aa601f840160051c8101916020851061253d575b601f0160051c01905b818110612532575061200d565b898155600101612525565b909150819061251c565b634e487b7160e01b88526041600452602488fd5b015190505f80611fbb565b5f5160206158fa5f395f51905f528b52818b209250601f1984168b5b8181106125ca57509084600195949392106125b2575b505050811b015f5160206158fa5f395f51905f5255611fdc565b01515f1960f88460031b161c191690555f8080612598565b92936020600181928786015181550195019301612582565b5f5160206158fa5f395f51905f528b529091507f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0601f840160051c81019160208510612652575b90601f859493920160051c01905b8181106126445750611fa5565b8b8155849350600101612637565b9091508190612629565b600160401b60ff60401b195f516020615b9a5f395f51905f525416175f516020615b9a5f395f51905f5255611f6a565b63f92ee8a960e01b8852600488fd5b9050155f611f34565b303b159150611f2c565b889150611f22565b8680fd5b8580fd5b8380fd5b5060403660031901126103b3576126d7613412565b906024356001600160401b03811161070a573660238201121561070a576127089036906024816004013591016134d9565b6001600160a01b037f00000000000000000000000014a68bacb0440b5568f30c8a0e4d1c76396f68b6163081149081156128cc575b506128bd575f516020615b5a5f395f51905f5282525f516020615afa5f395f51905f5260209081526040808420335f908152925290205460ff1615610531576040516352d1902d60e01b8152926001600160a01b0381169190602085600481865afa80958596612885575b506127c157634c9c8ce360e01b84526004839052602484fd5b9091845f516020615a5a5f395f51905f5281036128735750813b15612861575f516020615a5a5f395f51905f5280546001600160a01b031916821790557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28151839015612847578083602061078295519101845af4612841614f23565b9161585b565b505050346128525780f35b63b398979f60e01b8152600490fd5b634c9c8ce360e01b8452600452602483fd5b632a87526960e21b8552600452602484fd5b9095506020813d6020116128b5575b816128a160209383613489565b810103126128b15751945f6127a8565b8480fd5b3d9150612894565b63703e46dd60e11b8252600482fd5b5f516020615a5a5f395f51905f52546001600160a01b0316141590505f61273d565b50346103b35760203660031901126103b3575f516020615b5a5f395f51905f5281525f516020615afa5f395f51905f5260209081526040808320335f90815292529020546004359060ff161561053157805f516020615a3a5f395f51905f525403612957575080f35b5f516020615a3a5f395f51905f52819055604080519182523360208301527f0d34d0b9c521e222c3f85829e41c0a339601b044b087fca5d66ebd837ae7124391908190810161052b565b61346a565b50346103b357806003193601126103b35760205f5160206159da5f395f51905f5254604051908152f35b50346103b357806003193601126103b35760205f516020615a3a5f395f51905f5254604051908152f35b50346103b35760203660031901126103b357612a14613412565b50602061042e6136ce565b50346103b357806003193601126103b357602061042e612a45612a4061367c565b6136b0565b613b46565b50346103b35760403660031901126103b35780612a65613412565b612a6d613473565b90612a76613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b15611d185760405163d1870dc960e01b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152908290829060649082905af48015611b4d57611d075750f35b50346103b357806003193601126103b3575f516020615b1a5f395f51905f52546040516001600160a01b039091168152602090f35b50346103b35760403660031901126103b357612b3961343e565b336001600160a01b03821603612b555761078290600435613dbe565b63334bd91960e11b8252600482fd5b50346103b357806003193601126103b3576020612b7f61367c565b60ff60405191168152f35b50346103b357806003193601126103b35760205f51602061595a5f395f51905f5254604051908152f35b50346103b35760403660031901126103b357610782600435612bd461343e565b90612bfa610778825f525f516020615afa5f395f51905f52602052600160405f20015490565b613d78565b50346103b357806003193601126103b35760206001600160401b037f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb045460a01c16604051908152f35b50346103b35760403660031901126103b35780612c63613412565b612c6b613473565b90612c74613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b15611d185760405163cd3a810b60e01b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152908290829060649082905af48015611b4d57611d075750f35b50346103b35760203660031901126103b357602061042e6004355f525f516020615afa5f395f51905f52602052600160405f20015490565b50346103b35760603660031901126103b357612d3a613412565b612d4261343e565b60443591612d4f8161375d565b335f90815260209190915260409020545f198110612d73575b50610c609350613c94565b838110612de2576001600160a01b03821615612dce573315612dba57610c609450612d9d8261375d565b60018060a01b0333165f526020528360405f20910390555f612d68565b634a1406b160e11b85526004859052602485fd5b63e602df0560e01b85526004859052602485fd5b637dc7a0d960e11b8552336004526024526044839052606484fd5b50346103b35760603660031901126103b35760043561ffff811680910361070a57602435612e29613428565b5f516020615b5a5f395f51905f5284525f516020615afa5f395f51905f5260209081526040808620335f908152925290205460ff1615612f3e57611388831015612f2f57916080917f3418e749c0fc000a135389d4c2de15d697e75059a04711ac1a37b2a0080a98a1938261ffff195f516020615ada5f395f51905f525416175f516020615ada5f395f51905f5255817f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0f5560018060a01b031690816bffffffffffffffffffffffff60a01b5f5160206159fa5f395f51905f525416175f5160206159fa5f395f51905f525560405192835260208301526040820152336060820152a180f35b63cd4e616760e01b8452600484fd5b6282b42960e81b8452600484fd5b50346103b357806003193601126103b35760205f51602061599a5f395f51905f5254604051908152f35b503461186c57604036600319011261186c57612f90613412565b612f98613473565b90612fa1613bf2565b73749cadd76eb31dc37af2bebeb3663d04eca613dd91823b1561186c5760405163014c6f1160e41b81525f51602061597a5f395f51905f5260048201526001600160a01b0390921660248301526001600160401b03166044820152905f90829060649082905af4801561302457613016575080f35b61302291505f90613489565b005b6040513d5f823e3d90fd5b3461186c57604036600319011261186c576004355f525f516020615a1a5f395f51905f5260205260405f20600360ff600183015460501c1614801590613095575b15613081575060205f604051908152f35b61309060209160243590613bb9565b61042e565b50600281015415613070565b3461186c57604036600319011261186c576130ba613412565b602435903315613133576001600160a01b0316908115613120576130dd3361375d565b825f526020528060405f20556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b3461186c57602036600319011261186c57602061042e600435613b46565b3461186c575f36600319011261186c576040515f5f5160206158fa5f395f51905f525461319081613644565b808452906001811690811561322257506001146131b8575b610c0b8361102981850382613489565b5f5160206158fa5f395f51905f525f9081527f2ae08a8e29253f69ac5d979a101956ab8f8d9d7ded63fa7a83b16fc47648eab0939250905b808210613208575090915081016020016110296131a8565b9192600181602092548385880101520191019092916131f0565b60ff191660208086019190915291151560051b8401909101915061102990506131a8565b3461186c575f36600319011261186c57335f9081527fb16e88c42fd4e48df2dd6a2eabd6bc9aec654ec170056b470819f8892cc6431c602052604090205460ff16156132f2575f516020615b3a5f395f51905f525460ff8116156132e35760ff19165f516020615b3a5f395f51905f52557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b638dfc202b60e01b5f5260045ffd5b6282b42960e81b5f5260045ffd5b3461186c57602036600319011261186c5760043563ffffffff60e01b811680910361186c57602090635a05180f60e01b81149081156133a5575b8115613394575b8115613383575b8115613372575b8115613361575b506040519015158152f35b6301ffc9a760e01b14905082613356565b63e3bc4e6560e01b8114915061334f565b632264541760e21b81149150613348565b631883ba3960e21b81149150613341565b9050637965db0b60e01b811480156133be575b9061333a565b506301ffc9a760e01b81146133b8565b3461186c575f36600319011261186c57602061042e6135c7565b602060409281835280519182918282860152018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b038216820361186c57565b604435906001600160a01b038216820361186c57565b602435906001600160a01b038216820361186c57565b606435906001600160a01b038216820361186c57565b3461186c575f80fd5b602435906001600160401b038216820361186c57565b90601f801991011681019081106001600160401b038211176134aa57604052565b634e487b7160e01b5f52604160045260245ffd5b6001600160401b0381116134aa57601f01601f191660200190565b9291926134e5826134be565b916134f36040519384613489565b82948184528183011161186c578281602093845f960137010152565b9080601f8301121561186c5781602061352a933591016134d9565b90565b60206040818301928281528451809452019201905f5b8181106135505750505090565b82516001600160a01b0316845260209384019390920191600101613543565b606090600319011261186c57600435906024356001600160a01b038116810361186c57906044356001600160a01b038116810361186c5790565b3461186c57602036600319011261186c57602061042e600435614baf565b60405163fd7b363f60e01b81525f51602061597a5f395f51905f52600482015260208160248173749cadd76eb31dc37af2bebeb3663d04eca613dd5af4908115613024575f91613615575090565b90506020813d60201161363c575b8161363060209383613489565b8101031261186c575190565b3d9150613623565b90600182811c92168015613672575b602083101461365e57565b634e487b7160e01b5f52602260045260245ffd5b91607f1691613653565b60ff5f516020615b1a5f395f51905f525460a01c1660ff811161369c5790565b634e487b7160e01b5f52601160045260245ffd5b60ff16604d811161369c57600a0a90565b9190820391821161369c57565b60ff5f516020615b3a5f395f51905f52541661372d575f5160206159da5f395f51905f52545f1914613728576137026135c7565b5f5160206159da5f395f51905f52549081811061371f5750505f90565b61352a916136c1565b5f1990565b5f90565b9081602091031261186c575160ff8116810361186c5790565b8181029291811591840414171561369c57565b6001600160a01b03165f9081527f52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace016020526040902090565b6001600160a01b03165f9081527f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0a6020526040902090565b60015f5160206158ba5f395f51905f52546001600160801b0381169060801c14146139b5575f5160206158ba5f395f51905f52546001600160801b0381169060801c145f1461394c575f5b5f525f516020615a1a5f395f51905f5260205260405f206001810180546138545f516020615b7a5f395f51905f525464ffffffffff8316613a5b565b421061390d5760501c60ff166001146138f6575b50600381018054806138da57506138826002830154613b46565b905b5561388e81613ed1565b156138cb575b50604080513381524260208201527f892cd8f5b436bd5fb7dac1f11aafb73345d892ba3e9fe09cd94d95ba84928e739190a1600190565b6138d4906144e2565b5f613894565b6138e76002840154613b46565b90818082109118021890613884565b805460ff60501b1916600160511b1790555f613868565b5050604080513381524260208201527f892cd8f5b436bd5fb7dac1f11aafb73345d892ba3e9fe09cd94d95ba84928e73925090819081015b0390a15f90565b5f5160206158ba5f395f51905f52546001600160801b0381169060801c146139a3576001600160801b035f5160206158ba5f395f51905f5254165f525f516020615bfa5f395f51905f5260205260405f2054613818565b634e487b715f5260326020526024601cfd5b604080513381524260208201527f892cd8f5b436bd5fb7dac1f11aafb73345d892ba3e9fe09cd94d95ba84928e739181908101613945565b9081602091031261186c57516001600160a01b038116810361186c5790565b15613a1657505050565b632e52afbb60e21b5f5260018060a01b031660045260245260445260645ffd5b6001600160401b0381116134aa5760051b60200190565b5f19811461369c5760010190565b9190820180921161369c57565b90613a735f92613795565b613a8d816001600160801b0390548181169060801c031690565b905f5b828110613a9c57505050565b613aa6818361542e565b805f525f516020615a1a5f395f51905f52602052600360ff600160405f20015460501c1614613ad9575b50600101613a90565b60019195613af5915f526002840160205260405f205490613a5b565b9490613ad0565b90815f525f516020615a1a5f395f51905f52602052600360ff600160405f20015460501c1603613b4057613b31600291613795565b01905f5260205260405f205490565b50505f90565b613b4e6135c7565b906001820180921161369c575f51602061599a5f395f51905f52546001810180911161369c5761352a925f92614be4565b613b876135c7565b906001820180921161369c575f51602061599a5f395f51905f52546001810180911161369c5761352a92600192614be4565b90600282015480155f14613bdb5750600390915b015490818082109118021890565b6003830154613be992615473565b90600390613bcd565b335f9081527f448256db8f8fb95ee3eaaf89c1051414494e85cebb6057fcf996cc3d0ccfb456602052604090205460ff1615613c2a57565b63e2517d3f60e01b5f52336004525f516020615aba5f395f51905f5260245260445ffd5b5f8181525f516020615afa5f395f51905f526020908152604080832033845290915290205460ff1615613c7e5750565b63e2517d3f60e01b5f523360045260245260445ffd5b6001600160a01b0316908115613d65576001600160a01b0316918215613d5257815f525f51602061591a5f395f51905f5260205260405f2054818110613d3957817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f51602061591a5f395f51905f5284520360405f2055845f525f51602061591a5f395f51905f52825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b63ec442f0560e01b5f525f60045260245ffd5b634b637e8f60e11b5f525f60045260245ffd5b613d828282614dbe565b9182613d8d57505090565b5f9182525f5160206158da5f395f51905f526020526040909120613dba916001600160a01b0316906155bf565b5090565b613dc88282614e5c565b9182613dd357505090565b5f9182525f5160206158da5f395f51905f526020526040909120613dba916001600160a01b03169061573e565b5f516020615bba5f395f51905f525c613e265760015f516020615bba5f395f51905f525d565b630800025b60e31b5f5260045ffd5b5f516020615bba5f395f51905f525c15613e26575f5f516020615bba5f395f51905f525d565b60ff5f516020615b3a5f395f51905f525416613e7357565b63d93c066560e01b5f5260045ffd5b80546001600160801b0381169060801c145f14613e9e57505f90565b80546001600160801b0381169060801c146139a357806001600160801b03806001935416165f520160205260405f205490565b5f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015613024575f9061448f575b613f3091505f51602061597a5f395f51905f5254906136c1565b60405163fe6ba89360e01b81525f51602061597a5f395f51905f52600482015273749cadd76eb31dc37af2bebeb3663d04eca613dd9291602082602481875af48015613024575f9061445b575b613f879250613a5b565b600382015490808211614449576127105f5b11614441576002835493015491818082109118021892825f525f516020615a1a5f395f51905f52602052600360ff600160405f20015460501c1614614432575f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa908115613024575f916143ff575b50602061403c6064925f51602061597a5f395f51905f5254906136c1565b9260405192838092630b7477a160e31b82525f51602061597a5f395f51905f5260048301523060248301528960448301525af480156130245785915f916143c8575b50819261408e8261409c946136c1565b818082109118021890613a5b565b106143b95760405191606083018381106001600160401b038211176134aa5760405261ffff5f516020615ada5f395f51905f525416908184526127106141297f6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0f549360208701948552604060018060a01b035f5160206159fa5f395f51905f52541697019687528761374a565b9251945192048481189085110280851894909390926001600160a01b0316806143b3575033955b61417161415d87836136c1565b5f51602061597a5f395f51905f5254613a5b565b5f51602061597a5f395f51905f52555f8381525f516020615a1a5f395f51905f526020526040902060018101805460ff60501b1916600360501b1790556002018290556141be86826136c1565b835f525f516020615a1a5f395f51905f52602052600360405f2001553015613d6557305f525f51602061591a5f395f51905f5260205260405f20548281106143985791608091817f9aa101ee82db17aad9b30847940ac950a2518b6898926bc51bd2b06e4edb8b3f94305f525f51602061591a5f395f51905f526020520360405f2055815f51602061599a5f395f51905f5254035f51602061599a5f395f51905f52555f6040518381527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60203092a36040519182526020820152866040820152426060820152a20361436f575b50505f5160206158ba5f395f51905f52546001600160801b0381169060801c811461435d576001816143036001600160801b03936001600160801b03165f525f516020615bfa5f395f51905f5260205260405f2090565b505f61432c826001600160801b03165f525f516020615bfa5f395f51905f5260205260405f2090565b5501166001600160801b03195f5160206158ba5f395f51905f525416175f5160206158ba5f395f51905f5255600190565b634e487b715f5260316020526024601cfd5b5f516020615b1a5f395f51905f525461439192906001600160a01b0316614b73565b5f806142ac565b905063391434e360e21b5f523060045260245260445260645ffd5b95614150565b63c7dbbd7b60e01b5f5260045ffd5b9150506020813d6020116143f7575b816143e460209383613489565b8101031261186c5751849061409c61407e565b3d91506143d7565b90506020813d60201161442a575b8161441a60209383613489565b8101031261186c5751602061401e565b3d915061440d565b63f1a6019360e01b5f5260045ffd5b505050505f90565b61271061445682846136c1565b613f99565b506020823d602011614487575b8161447560209383613489565b8101031261186c57613f879151613f7d565b3d9150614468565b506020813d6020116144bb575b816144a960209383613489565b8101031261186c57613f309051613f16565b3d915061449c565b9081602091031261186c57516001600160401b038116810361186c5790565b5f516020615b1a5f395f51905f525460405163313ce56760e01b815290602090829060049082906001600160a01b03165afa908115613024575f916148f5575b506040516322298c0160e01b81525f51602061597a5f395f51905f52600482015273749cadd76eb31dc37af2bebeb3663d04eca613dd91602082602481865af4918215613024575f926148c1575b50600184019164ffffffffff835460281c1680151590816148a1575b5061489a575f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015613024575f90614866575b6145f091505f51602061597a5f395f51905f5254906136c1565b60405163fe6ba89360e01b81525f51602061597a5f395f51905f526004820152602081602481895af4908115613024575f91614830575b509261463961463f9261464595613a5b565b92614ffd565b90613a5b565b6003840154908181106148225750505f5b6127108111614699575b50509054604080513381524260208201529192507f9da6493a92039daf47d1f2d7a782299c5994c6323eb1e972f69c432089ec52bf91a2565b60405162c32e5560e31b81525f51602061597a5f395f51905f52600482015290602082602481875af4918215613024575f92614800575b505f516020615b1a5f395f51905f525460405163313ce56760e01b8152929390602090849060049082906001600160a01b03165afa928315613024576020946001600160401b03614738614733829760449761476b965f926147e1575b50615050565b615091565b1680868316105f146147d95750915b805469ffffffffff000000000019164260281b69ffffffffff000000000016179055565b60405194859384926306d4739f60e41b84525f51602061597a5f395f51905f5260048501521660248301525af48015613024576147aa575b8080614660565b6147cb9060203d6020116147d2575b6147c38183613489565b8101906144c3565b505f6147a3565b503d6147b9565b905091614747565b6147f99192508b3d8d116123d7576123c98183613489565b905f61472d565b6004925061481c9060203d6020116147d2576147c38183613489565b916146d0565b61482b916136c1565b614656565b9390506020843d60201161485e575b8161484c60209383613489565b8101031261186c579251614639614627565b3d915061483f565b506020813d602011614892575b8161488060209383613489565b8101031261186c576145f090516145d6565b3d9150614873565b5050505050565b600591500164ffffffffff811161369c5764ffffffffff1642105f61458c565b9091506020813d6020116148ed575b816148dd60209383613489565b8101031261186c5751905f614570565b3d91506148d0565b61490e915060203d6020116123d7576123c98183613489565b5f614522565b5f516020615b1a5f395f51905f52546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015613024575f90614a15575b61497391505f51602061597a5f395f51905f5254906136c1565b5f51602061595a5f395f51905f525481101561498c5750565b6149a96147336001600160401b03926149a361367c565b90615050565b60405163049d734b60e51b81525f51602061597a5f395f51905f5260048201529116602482015260208160448173749cadd76eb31dc37af2bebeb3663d04eca613dd5af48015613024576149fa5750565b614a129060203d602011611b4657611b388183613489565b50565b506020813d602011614a41575b81614a2f60209383613489565b8101031261186c576149739051614959565b3d9150614a22565b60018060a01b0316803314908115614a73575b5015614a6457565b630da8d92160e21b5f5260045ffd5b5f9081525f516020615c1a5f395f51905f526020908152604080832033845290915281205460ff169150614a5c565b6040516323b872dd60e01b60208201526001600160a01b039283166024820152929091166044830152606480830193909352918152614aeb91614ae6608483613489565b615228565b565b929190600360ff600186015460501c1603614b6457614aeb9184545f526002820160205260405f2054818082109118021884614b5f614b2d838098613bb9565b968794614b48865f51602061597a5f395f51905f52546136c1565b5f51602061597a5f395f51905f52558354906152a9565b6153bd565b6301b2776960e11b5f5260045ffd5b60405163a9059cbb60e01b60208201526001600160a01b03929092166024830152604480830193909352918152614aeb91614ae6606483613489565b5f51602061599a5f395f51905f5254906001820180921161369c57614bd26135c7565b6001810180911161369c5761352a925f925b9291614bf1818386615473565b926004811015614c42576001809116149182614c17575b505061352a9250151590613a5b565b9080925015614c2e5761352a930915155f80614c08565b634e487b7160e01b5f52601260045260245ffd5b634e487b7160e01b5f52602160045260245ffd5b6001600160a01b0381165f9081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff16614d00576001600160a01b03165f8181527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d60205260408120805460ff191660011790553391907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4600190565b505f90565b6001600160a01b0381165f9081527fb16e88c42fd4e48df2dd6a2eabd6bc9aec654ec170056b470819f8892cc6431c602052604090205460ff16614d00576001600160a01b03165f8181527fb16e88c42fd4e48df2dd6a2eabd6bc9aec654ec170056b470819f8892cc6431c60205260408120805460ff191660011790553391905f516020615b5a5f395f51905f52907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b038616845290915290205460ff16613b40575f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b5f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b038616845290915290205460ff1615613b40575f8181525f516020615afa5f395f51905f52602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b60ff5f516020615b9a5f395f51905f525460401c1615614f1457565b631afcd79f60e31b5f5260045ffd5b3d15614f4d573d90614f34826134be565b91614f426040519384613489565b82523d5f602084013e565b606090565b5f8091604051602081019063313ce56760e01b825260048152614f76602482613489565b51916001600160a01b03165afa614f8b614f23565b9080614fc5575b614f9e575b505f905f90565b6020815191818082019384920101031261186c575160ff8111614f97579060ff6001921690565b50602081511015614f92565b9060ff8091169116039060ff821161369c57565b604d811161369c57600a0a90565b8115614c2e570490565b9060ff81168060081061503557600811615015575090565b9061502f60ff61502961352a946008614fd1565b16614fe5565b90614ff3565b509061504a60ff615029600861352a95614fd1565b9061374a565b9060ff81166006811061507c57600610615068575090565b9061502f60ff615029600661352a95614fd1565b509061504a60ff61502961352a946006614fd1565b6001600160401b0381116150ab576001600160401b031690565b6306dfcc6560e41b5f52604060045260245260445ffd5b906150e68360018060a01b035f516020615b1a5f395f51905f525416843091614aa2565b6001600160a01b0316928315613d52577fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d791816151336040935f51602061599a5f395f51905f5254613a5b565b5f51602061599a5f395f51905f5255855f525f51602061591a5f395f51905f52602052825f20818154019055855f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60208651858152a3825194855260208501526001600160a01b031692a3565b6001600160801b035f5160206158ba5f395f51905f52548181169060801c03168015615222576151dd5f5160206158ba5f395f51905f52613e82565b5f525f516020615a1a5f395f51905f52602052600160405f209114908161520d575b50615208575f90565b600190565b6001015460501c60ff1660021490505f6151ff565b50600190565b905f602091828151910182855af115613024575f513d61527757506001600160a01b0381163b155b6152575750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b60011415615250565b8054821015615295575f5260205f2001905f90565b634e487b7160e01b5f52603260045260245ffd5b9290916002840190835f528160205260405f20548111614b6457835f528160205260405f205481106153a05750825f526020525f60408120556152fc836001600160801b0390548181169060801c031690565b9061530682613a36565b916153146040519384613489565b808352615323601f1991613a36565b013660208401375f5b825181101561535357806153426001928761542e565b61534c8286615847565b520161532c565b505f8085559092905b825181101561539957808261537360019386615847565b5103615380575b0161535c565b61539461538d8286615847565b51876157e7565b61537a565b5050509050565b92909193505f526020526153b960405f209182546136c1565b9055565b919060028301908154808211614b645780821061541157505050506153e28154615613565b50545f525f516020615a1a5f395f51905f526020525f6003604082208281558260018201558260028201550155565b916154236153b99495926003946136c1565b9055019182546136c1565b615448816001600160801b0390548181169060801c031690565b8210156139a3576001600160801b0380600193818085541691160116165f520160205260405f205490565b90915f19838309928083029283808610950394808603951461550457848311156154ec5790829109815f0382168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b82634e487b715f52156003026011186020526024601cfd5b50509061352a9250614ff3565b805f525f516020615a7a5f395f51905f5260205260405f2054155f14614d00575f516020615a9a5f395f51905f5254600160401b8110156134aa5761559061557a8260018594015f516020615a9a5f395f51905f52555f516020615a9a5f395f51905f52615280565b819391549060031b91821b915f19901b19161790565b90555f516020615a9a5f395f51905f5254905f525f516020615a7a5f395f51905f5260205260405f2055600190565b6001810190825f528160205260405f2054155f1461560c578054600160401b8110156134aa576155f961557a826001879401855584615280565b905554915f5260205260405f2055600190565b5050505f90565b5f8181525f516020615a7a5f395f51905f5260205260409020548015613b40575f19810181811161369c575f516020615a9a5f395f51905f52545f1981019190821161369c578181036156e2575b5050505f516020615a9a5f395f51905f525480156156ce575f1901615693815f516020615a9a5f395f51905f52615280565b8154905f199060031b1b191690555f516020615a9a5f395f51905f52555f525f516020615a7a5f395f51905f526020525f6040812055600190565b634e487b7160e01b5f52603160045260245ffd5b61571c6156ff61557a935f516020615a9a5f395f51905f52615280565b90549060031b1c9283925f516020615a9a5f395f51905f52615280565b90555f525f516020615a7a5f395f51905f5260205260405f20555f8080615661565b906001820191815f528260205260405f20548015155f14614441575f19810181811161369c5782545f1981019190821161369c578181036157b2575b505050805480156156ce575f1901906157938282615280565b8154905f199060031b1b19169055555f526020525f6040812055600190565b6157d26157c261557a9386615280565b90549060031b1c92839286615280565b90555f528360205260405f20555f808061577a565b908154908160801c6001600160801b0380600183011693168314615835576001600160801b03165f526001830160205260405f20556001600160801b0382549181199060801b169116179055565b634e487b715f5260416020526024601cfd5b80518210156152955760209160051b010190565b9061587f575080511561587057805190602001fd5b63d6bda27560e01b5f5260045ffd5b815115806158b0575b615890575090565b639996b31560e01b5f9081526001600160a01b0391909116600452602490fd5b50803b1561588856fe6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0bc1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e8237170593200052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0352c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace046af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb156af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0052c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace026af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb136af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb126af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb106af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb096af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0d360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc6af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb086af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0797667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b9296af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0e02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b6268000773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300a49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb11f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00e26c696bf0e34aaf444e67b257b0ce1f00d161ab27c76bcd8c8582bed8ddd0006af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb056af5eb732c63a16ddd99ed9086e0dae5c2af489fbdd4532892e38c9d7dedbb0c58b5cdfd1ca129592c69bde289fd6324080dd2d81a29959004bd7c0735b6e300a2646970667358221220a646d9e17d1766daed6e435df22cc7d75b4a6be909005dedfe45b18c4760d62964736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in HYPE
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.