Overview
ETH Balance
ETH Value
$0.00Latest 6 from a total of 6 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Open Position Va... | 18215426 | 30 hrs ago | IN | 0 ETH | 0.000002 | ||||
| Open Position Va... | 18215361 | 30 hrs ago | IN | 0 ETH | 0.00000315 | ||||
| Adjust Position ... | 18211381 | 31 hrs ago | IN | 0 ETH | 0.00000135 | ||||
| Adjust Position ... | 18211355 | 31 hrs ago | IN | 0 ETH | 0.00000135 | ||||
| Adjust Position ... | 18211347 | 31 hrs ago | IN | 0 ETH | 0.00000135 | ||||
| Open Position Va... | 18211074 | 31 hrs ago | IN | 0 ETH | 0.00000135 |
View more zero value Internal Transactions in Advanced View mode
Cross-Chain Transactions
Contract Source Code Verified (Exact Match)
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {ILSTCollateralVault} from "../interfaces/core/vaults/ILSTCollateralVault.sol";
import {ILiquidStabilityPool} from "../interfaces/core/ILiquidStabilityPool.sol";
import {IBorrowerOperations} from "../interfaces/core/IBorrowerOperations.sol";
import {IWNative} from "../interfaces/utils/tokens/IWNATIVE.sol";
import {IDebtToken} from "../interfaces/core/IDebtToken.sol";
import {IPositionManager} from "../interfaces/core/IPositionManager.sol";
import {ICollVaultRouter} from "../interfaces/periphery/ICollVaultRouter.sol";
import {IMetaCore} from "../interfaces/core/IMetaCore.sol";
import {IPreDepositHook} from "../interfaces/periphery/preDepositHooks/IPreDepositHook.sol";
import {ILSTVault} from "src/interfaces/utils/integrations/ILSTVault.sol";
import {TokenValidationLib} from "../libraries/TokenValidationLib.sol";
import {UtilsLib} from "../libraries/UtilsLib.sol";
import {DynamicArrayLib} from "solady/utils/DynamicArrayLib.sol";
import {FeeLib} from "../libraries/FeeLib.sol";
import {SwappersLib} from "../libraries/SwappersLib.sol";
/// @dev Doesn't have DelegatedOps functionality
/// @dev Periphery whitelisted in Core, delegates BorrowerOperations accounts
contract CollVaultRouter is ICollVaultRouter {
using SwappersLib for SwappersLib.SwapperData;
using SafeERC20 for IERC20;
using Math for uint;
using TokenValidationLib for address[];
using TokenValidationLib for ILSTCollateralVault;
using DynamicArrayLib for DynamicArrayLib.DynamicArray;
using DynamicArrayLib for address[];
using DynamicArrayLib for uint[];
using UtilsLib for bytes;
using FeeLib for uint;
uint16 constant BP = 1e4;
SwappersLib.SwapperData internal swapperData;
ILSTCollateralVault public mainRewardTokenVault;
IBorrowerOperations immutable borrowerOperations;
IWNative immutable wNative;
IDebtToken immutable debtToken;
ILiquidStabilityPool immutable liquidStabilityPool;
IMetaCore immutable metaCore;
modifier onlyOwner() {
require(msg.sender == metaCore.owner(), "CollVaultRouter: Only owner");
_;
}
constructor(
address _borrowerOperations,
address _wNative,
address _debtToken,
address _liquidStabilityPool,
address _metaCore,
address _mainRewardTokenVault,
address[] memory _initialWhitelistedSwappers
) {
if (_borrowerOperations == address(0) || _wNative == address(0) || _debtToken == address(0) || _liquidStabilityPool == address(0) || _metaCore == address(0)) {
revert("CollVaultRouter: 0 address");
}
borrowerOperations = IBorrowerOperations(_borrowerOperations);
wNative = IWNative(_wNative);
debtToken = IDebtToken(_debtToken);
liquidStabilityPool = ILiquidStabilityPool(_liquidStabilityPool);
metaCore = IMetaCore(_metaCore);
mainRewardTokenVault = ILSTCollateralVault(_mainRewardTokenVault);
// add routers on constructor
for (uint i; i < _initialWhitelistedSwappers.length; i++) {
SwappersLib.addWhitelistedSwapper(swapperData, _initialWhitelistedSwappers[i], true);
}
}
/**
* @notice Opens positions by routing the wrapping of the token for the vault share
* @notice Handles WNATIVE to iWNATIVE conversion
* @param params - _preDeposit If it has data, we call `preDepositHook`, `_collAssetToDeposit` will be overridden by the amount returned
*/
function openPositionVault(
ICollVaultRouter.OpenPositionVaultParams memory params
) external payable {
IERC20 vaultAsset = _validateVaultAndManager(params.collVault, params._collIndex, params.positionManager);
if (params._preDeposit.length != 0) {
(bytes memory preDepositParams, IPreDepositHook target) = abi.decode(params._preDeposit, (bytes, IPreDepositHook));
uint prevAssetBalance = vaultAsset.balanceOf(address(this));
target.preDepositHook{value: msg.value}(msg.sender, preDepositParams);
params._collAssetToDeposit = vaultAsset.balanceOf(address(this)) - prevAssetBalance;
} else {
if (msg.value != 0) {
require(address(vaultAsset) == address(wNative), "Passed msg.value with non-WNATIVE vault");
require(msg.value == params._collAssetToDeposit, "msg.value != _collAmount");
wNative.deposit{value: params._collAssetToDeposit}();
} else {
vaultAsset.safeTransferFrom(msg.sender, address(this), params._collAssetToDeposit);
}
}
vaultAsset.safeIncreaseAllowance(address(params.collVault), params._collAssetToDeposit);
uint sharesMinted = params.collVault.deposit(params._collAssetToDeposit, address(this));
require(sharesMinted >= params._minSharesMinted, "sharesMinted < _minSharesMinted");
params.collVault.approve(address(borrowerOperations), sharesMinted);
borrowerOperations.openPosition(
address(params.positionManager),
msg.sender,
params._maxFeePercentage,
sharesMinted,
params._debtAmount,
params._upperHint,
params._lowerHint
);
debtToken.transfer(msg.sender, params._debtAmount);
}
function adjustPositionVault(
ICollVaultRouter.AdjustPositionVaultParams memory params
) external payable {
IERC20 vaultAsset = _validateVaultAndManager(params.collVault, params._collIndex, params.positionManager);
uint sharesMinted;
if (params._collAssetToDeposit != 0) {
if (params._preDeposit.length != 0) {
(bytes memory preDepositParams, IPreDepositHook target) = abi.decode(params._preDeposit, (bytes, IPreDepositHook));
uint256 prevAssetsBalance = vaultAsset.balanceOf(address(this));
target.preDepositHook{value: msg.value}(msg.sender, preDepositParams);
params._collAssetToDeposit = vaultAsset.balanceOf(address(this)) - prevAssetsBalance;
} else {
if (msg.value != 0) {
require(address(vaultAsset) == address(wNative), "Passed msg.value with non-WNATIVE vault");
require(msg.value == params._collAssetToDeposit, "msg.value != _collAmount");
wNative.deposit{value: params._collAssetToDeposit}();
} else {
vaultAsset.safeTransferFrom(msg.sender, address(this), params._collAssetToDeposit);
}
}
vaultAsset.safeIncreaseAllowance(address(params.collVault), params._collAssetToDeposit);
sharesMinted = params.collVault.deposit(params._collAssetToDeposit, address(this));
require(sharesMinted >= params._minSharesMinted, "sharesMinted < minSharesMinted");
params.collVault.approve(address(borrowerOperations), sharesMinted);
}
if (!params._isDebtIncrease && params._debtChange != 0) {
debtToken.sendToPeriphery(msg.sender, params._debtChange);
}
borrowerOperations.adjustPosition(
address(params.positionManager),
msg.sender,
params._maxFeePercentage,
sharesMinted,
params._collWithdrawal,
params._debtChange,
params._isDebtIncrease,
params._upperHint,
params._lowerHint
);
if (params._collWithdrawal != 0) {
if (params.unwrap) {
uint assetsWithdrawn = params.collVault.redeem(params._collWithdrawal, msg.sender, address(this));
require(assetsWithdrawn >= params._minAssetsWithdrawn, "assetsWithdrawn < _minAssetsWithdrawn");
} else {
IERC20(address(params.collVault)).safeTransfer(msg.sender, params._collWithdrawal);
}
}
if (params._isDebtIncrease) {
debtToken.transfer(msg.sender, params._debtChange);
}
}
function closePositionVault(
IPositionManager positionManager,
ILSTCollateralVault collVault,
uint256 minAssetsWithdrawn,
uint256 collIndex,
bool unwrap
) external {
_validateVaultAndManager(collVault, collIndex, positionManager);
uint prevSharesBalance = collVault.balanceOf(address(this));
(, uint debt) = positionManager.getPositionCollAndDebt(msg.sender);
uint debtToBurn = debt - borrowerOperations.DEBT_GAS_COMPENSATION();
debtToken.sendToPeriphery(msg.sender, debtToBurn);
borrowerOperations.closePosition(
address(positionManager),
msg.sender
);
uint sharesWithdrawn = collVault.balanceOf(address(this)) - prevSharesBalance;
if (unwrap) {
uint assetsWithdrawn = collVault.redeem(sharesWithdrawn, msg.sender, address(this));
require(assetsWithdrawn >= minAssetsWithdrawn, "assetsWithdrawn < _minAssetsWithdrawn");
} else {
IERC20(address(collVault)).safeTransfer(msg.sender, sharesWithdrawn);
}
}
function redeemCollateralVault(
ICollVaultRouter.RedeemCollateralVaultParams memory params
) external {
_validateVaultAndManager(params.collVault, params.collIndex, params.positionManager);
uint prevSharesBalance = params.collVault.balanceOf(address(this));
uint prevDebtTokenBalance = debtToken.balanceOf(address(this));
debtToken.sendToPeriphery(msg.sender, params._debtAmount);
params.positionManager.redeemCollateral(
params._debtAmount,
params._firstRedemptionHint,
params._upperPartialRedemptionHint,
params._lowerPartialRedemptionHint,
params._partialRedemptionHintNICR,
params._maxIterations,
params._maxFeePercentage
);
uint sharesWithdrawn = params.collVault.balanceOf(address(this)) - prevSharesBalance;
require(sharesWithdrawn >= params._minSharesWithdrawn , "sharesWithdrawn < _minSharesWithdrawn");
if (params.unwrap) {
uint assetsWithdrawn = params.collVault.redeem(sharesWithdrawn, msg.sender, address(this));
require(assetsWithdrawn >= params.minAssetsWithdrawn, "assetsWithdrawn < _minAssetsWithdrawn");
} else {
IERC20(address(params.collVault)).safeTransfer(msg.sender, sharesWithdrawn);
}
// Dust debtToken could be left if not all expected redemptions were made
uint currentDebtTokenBalance = debtToken.balanceOf(address(this));
if (currentDebtTokenBalance > prevDebtTokenBalance) {
debtToken.transfer(msg.sender, currentDebtTokenBalance - prevDebtTokenBalance);
}
}
function claimCollateralRouter(
IPositionManager positionManager,
ILSTCollateralVault collVault,
address receiver,
uint _collIndex,
uint minAssetsWithdrawn
) external {
_validateVaultAndManager(collVault, _collIndex, positionManager);
uint surplusBalance = positionManager.surplusBalances(msg.sender);
positionManager.claimCollateral(msg.sender, address(this));
uint assetsWithdrawn = collVault.redeem(surplusBalance, receiver, address(this));
require(assetsWithdrawn >= minAssetsWithdrawn, "assetsWithdrawn < _minAssetsWithdrawn");
}
/// @dev Previewed amount withdrawn could be less if between offchain calculation and onchain execution, the earned amount is updated through `getRewardForUser`
function previewRedeemUnderlying(
ILSTCollateralVault collVault,
uint sharesToRedeem
) public view returns (address[] memory tokens, uint[] memory amounts) {
DynamicArrayLib.DynamicArray memory _tokens;
DynamicArrayLib.DynamicArray memory _amounts;
// Simulate the redemption as if calling collVault.redeem()
_simulateVaultRedemption(collVault, sharesToRedeem, _tokens, _amounts, false);
tokens = _tokens.asAddressArray();
amounts = _amounts.asUint256Array();
}
function redeemToOne(
RedeemToOneParams calldata params
) external {
(address[] memory rewardTokens,) = previewRedeemUnderlying(params.collVault, params.shares);
uint length = rewardTokens.length;
uint[] memory prevBalances = new uint[](length);
for (uint i; i < length; i++) {
prevBalances[i] = IERC20(rewardTokens[i]).balanceOf(address(this));
}
params.collVault.redeem(params.shares, address(this), msg.sender);
uint prevTargetTokenBalance = IERC20(params.targetToken).balanceOf(params.receiver);
// Swap reward tokens to target token
for (uint i; i < length; i++) {
address token = rewardTokens[i];
uint amount = IERC20(token).balanceOf(address(this)) - prevBalances[i];
if (token != params.targetToken) {
if (amount > 0 && params.tokensSwapCalldatas[i].length != 0) {
IERC20(token).safeIncreaseAllowance(params.swapRouter, amount);
SwappersLib.executeSwap(swapperData, params.swapRouter, params.tokensSwapCalldatas[i]);
}
} else {
IERC20(token).safeTransfer(params.receiver, amount);
}
}
uint targetTokenBalanceDelta = IERC20(params.targetToken).balanceOf(params.receiver) - prevTargetTokenBalance;
require(targetTokenBalanceDelta >= params.minTargetTokenAmount, "Insufficient token amount");
}
function claimLockedTokens(IERC20[] memory tokens, uint[] memory amounts) external {
require(msg.sender == metaCore.owner(), "Only owner");
for (uint i; i < tokens.length; i++) {
if (address(tokens[i]) == address(0xdead)) {
(bool success,) = metaCore.feeReceiver().call{value: amounts[i]}("");
require(success, "ETH transfer failed");
} else {
tokens[i].safeTransfer(metaCore.feeReceiver(), amounts[i]);
}
}
}
function _isWhitelistedCollateralAt(address positionManagerAtIdx, address collVault) private view returns (bool) {
return IPositionManager(positionManagerAtIdx).collateralToken() == collVault;
}
function _validateVaultAndManager(
ILSTCollateralVault collVault,
uint _collIndex,
IPositionManager positionManager
) internal view returns(IERC20 vaultAsset) {
address positionManagerAtIdx = borrowerOperations.positionManagers(_collIndex);
require(positionManagerAtIdx == address(positionManager), "Incorrect PositionManager");
require(_isWhitelistedCollateralAt(positionManagerAtIdx, address(collVault)), "Incorrect collateral");
require(address(positionManager.collateralToken()) == address(collVault), "Incorrect PositionManager or Vault");
vaultAsset = IERC20(collVault.asset());
}
/**
* @dev Recursively simulates a redemption on a given vault, including fee calculation,
* proportionate distribution of rewarded tokens, and nested vault redemptions.
*/
function _simulateVaultRedemption(
ILSTCollateralVault vault,
uint sharesToRedeem,
DynamicArrayLib.DynamicArray memory tokens,
DynamicArrayLib.DynamicArray memory amounts,
bool isNested
) internal view {
SimRedeemVars memory v;
v.performanceFee = vault.getPerformanceFee();
v.netShares = isNested ? sharesToRedeem : sharesToRedeem - sharesToRedeem.feeOnRaw(vault.getWithdrawFee());
v.totalSupply = vault.totalSupply();
v.asset = vault.asset();
v.mainRewardToken = mainRewardTokenVault != ILSTCollateralVault(address(0)) ? mainRewardTokenVault.asset() : address(0);
(address[] memory rewardTokens, ILSTVault lstVault) = getOrderedRedeemedTokens(vault);
for (uint256 i; i < rewardTokens.length; i++) {
address token = rewardTokens[i];
bool isMainRewardToken = token == v.mainRewardToken;
if (address(lstVault) != address(0)) {
v.earned = lstVault.earned(address(vault), token);
if (isMainRewardToken && vault != mainRewardTokenVault) {
v.earned = mainRewardTokenVault.previewDeposit(v.earned);
token = address(mainRewardTokenVault);
}
v.earned -= v.earned * v.performanceFee / BP;
} else {
v.earned = 0;
}
uint256 tokenBalance = vault.getBalance(token) + v.earned;
if (tokenBalance == 0) continue;
uint256 tokenAmount = v.netShares.mulDiv(tokenBalance, v.totalSupply, Math.Rounding.Down);
if (tokenAmount == 0) continue;
// Recursively simulate if token is a nested vault
// We check if 'isMainRewardToken' instead of mainRewardTokenVault since its replaced by mainRewardToken in tryGetRewardedTokensIncludingMainRewardTokenVault
// And 'MainRewardToken' can only be on rewarded tokens of a vault that it's not mainRewardTokenVault, in the form of mainRewardTokenVault
if (token == address(mainRewardTokenVault)) {
_simulateVaultRedemption(mainRewardTokenVault, tokenAmount, tokens, amounts, true);
} else {
TokenValidationLib.aggregateIfNotExistent(token, tokenAmount, tokens, amounts);
}
}
}
function getOrderedRedeemedTokens(
ILSTCollateralVault vault
) public view returns (address[] memory rewardTokens, ILSTVault lstVault) {
try vault.lstVault() returns (ILSTVault _lstVault) {
lstVault = _lstVault;
} catch {
lstVault = ILSTVault(address(0));
}
// MainRewardTokeVault
rewardTokens = vault.tryGetRewardedTokens();
// Add rewardTokens not still included in the vault
if (address(lstVault) != address(0)) {
/// @dev We assume there's a main reward token vault if there is an lstVault
address mainRewardToken = mainRewardTokenVault.asset();
address[] memory currRewardTokens = lstVault.getAllRewardTokens();
for (uint256 i; i < currRewardTokens.length; i++) {
// Skip if the token is mainRewardToken, since its internally represented by mainRewardTokenVault
if (currRewardTokens[i] == mainRewardToken && vault != mainRewardTokenVault) continue;
(rewardTokens,) = rewardTokens.pushIfNotIncluded(currRewardTokens[i]);
}
}
if (address(vault) != address(mainRewardTokenVault) && address(lstVault) != address(0)) {
// Enforce same order as `redeemToOne`
(rewardTokens,) = rewardTokens.tryGetRewardedTokensIncludingMainRewardTokenVault(vault.asset(), mainRewardTokenVault);
}
}
function addWhitelistedSwapper(address _swapRouter, bool status) external onlyOwner {
SwappersLib.addWhitelistedSwapper(swapperData,_swapRouter, status);
}
function setMainRewardTokenVault(address _mainRewardTokenVault) external onlyOwner {
mainRewardTokenVault = ILSTCollateralVault(_mainRewardTokenVault);
}
receive() external payable {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
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 amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` 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 amount
) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 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 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @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).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return 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 up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
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^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// 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^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice 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) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* 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 + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
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 log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IBaseCollateralVault} from "./IBaseCollateralVault.sol";
import {ILSTWrapper} from "./ILSTWrapper.sol";
import {ILSTVault} from "../../utils/integrations/ILSTVault.sol";
import {EmissionsLib} from "src/libraries/EmissionsLib.sol";
interface ILSTCollateralVault is IBaseCollateralVault {
struct LSTCollVaultStorage {
uint16 minPerformanceFee;
uint16 maxPerformanceFee;
uint16 performanceFee; // over yield, in basis points
/// @dev We currently don't know the lstVault implementation, but if it were to be possible for them to remove tokens from the rewardTokens
/// There would be no need to remove it from here since the amounts should continue being accounted for in the virtual balance
EnumerableSet.AddressSet rewardedTokens;
ILSTVault _lstVault;
address mainRewardTokenVault;
address mainRewardToken;
ILSTWrapper lstWrapper;
uint96 lastUpdate;
mapping(address tokenIn => uint) threshold;
}
struct LSTInitParams {
BaseInitParams _baseParams;
uint16 _minPerformanceFee;
uint16 _maxPerformanceFee;
uint16 _performanceFee; // over yield, in basis points
ILSTVault _lstVault;
address _mainRewardTokenVault;
address _lstWrapper;
}
struct RebalanceParams {
address sentCurrency;
uint sentAmount;
address swapper;
bytes payload;
}
function rebalance(RebalanceParams calldata p) external;
function pullRewards() external;
function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external;
function internalizeDonations(address[] memory tokens, uint128[] memory amounts) external;
function setPairThreshold(address tokenIn, uint thresholdInBP) external;
function setPerformanceFee(uint16 _performanceFee) external;
function setWithdrawFee(uint16 _withdrawFee) external;
function getBalance(address token) external view returns (uint);
function getBalanceOfWithFutureEmissions(address token) external view returns (uint);
function getFullProfitUnlockTimestamp(address token) external view returns (uint);
function unlockRatePerSecond(address token) external view returns (uint);
function getLockedEmissions(address token) external view returns (uint);
function getPerformanceFee() external view returns (uint16);
function rewardedTokens() external view returns (address[] memory);
function lstVault() external view returns (ILSTVault);
function mainRewardToken() external view returns (address);
function mainRewardTokenVault() external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC4626} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IMetaCore} from "./IMetaCore.sol";
import {IDebtToken} from "./IDebtToken.sol";
import {IDebtToken} from "./IDebtToken.sol";
import {EmissionsLib} from "src/libraries/EmissionsLib.sol";
interface ILiquidStabilityPool is IERC4626, IERC1822Proxiable {
struct LSPStorage {
IMetaCore metaCore;
address feeReceiver;
/// @notice Array of tokens that have been emitted to the LiquidStabilityPool
/// @notice Used to track which tokens can be withdrawn to LSP share holders
/// @dev Doesn't include tokens that are already collaterals
EnumerableSet.AddressSet extraAssets;
Queue queue;
address[] collateralTokens;
mapping(uint16 => SunsetIndex) _sunsetIndexes;
mapping(address collateral => uint256 index) indexByCollateral;
mapping(bytes32 => uint) threshold;
EmissionsLib.BalanceData balanceData;
mapping(address => bool) factoryProtocol;
mapping(address => bool) liquidationManagerProtocol;
mapping(address => bool) privilegedDebtRedeemers;
}
struct InitParams {
IERC20 _asset;
string _sharesName;
string _sharesSymbol;
IMetaCore _metaCore;
address _liquidationManager;
address _factory;
address _feeReceiver;
}
struct RebalanceParams {
address sentCurrency;
uint sentAmount;
address receivedCurrency;
address swapper;
bytes payload;
}
struct SunsetIndex {
uint128 idx;
uint128 expiry;
}
struct Queue {
uint16 firstSunsetIndexKey;
uint16 nextSunsetIndexKey;
}
event CollAndEmissionsWithdraw(
address indexed receiver,
uint shares,
uint[] amounts
);
struct Arrays {
uint length;
address[] collaterals;
uint collateralsLength;
uint[] amounts;
}
event EmissionTokenAdded(address token);
event EmissionTokenRemoved(address token);
event StabilityPoolDebtBalanceUpdated(uint256 newBalance);
event UserDepositChanged(address indexed depositor, uint256 newDeposit);
event CollateralOverwritten(address oldCollateral, address newCollateral);
// PROXY
function upgradeToAndCall(address newImplementation, bytes calldata data) external;
function getCurrentImplementation() external view returns (address);
function SUNSET_DURATION() external view returns (uint128);
function totalDebtTokenDeposits() external view returns (uint256);
function enableCollateral(address _collateral, uint64 _unlockRatePerSecond, bool forceThroughBalanceCheck) external;
function startCollateralSunset(address collateral) external;
function getTotalDebtTokenDeposits() external view returns (uint256);
function getCollateralTokens() external view returns (address[] memory);
function offset(address collateral, uint256 _debtToOffset, uint256 _collToAdd) external;
function initialize(InitParams calldata params) external;
function rebalance(RebalanceParams calldata p) external;
function linearVestingExtraAssets(address token, int amount, address recipient) external;
function withdraw(
uint assets,
address[] calldata preferredUnderlyingTokens,
address receiver,
address _owner
) external returns (uint shares);
function redeem(
uint shares,
address[] calldata preferredUnderlyingTokens,
address receiver,
address _owner
) external returns (uint assets);
function updateProtocol(
address _liquidationManager,
address _factory,
bool _register
) external;
function redeem(
uint assets,
address receiver
) external returns (uint shares);
function addNewExtraAsset(address token, uint64 _unlockRatePerSecond) external;
function removeEmitedTokens(address token) external;
function setPairThreshold(address tokenIn, address tokenOut, uint thresholdInBP) external;
function setUnlockRatePerSecond(address token, uint64 _unlockRatePerSecond) external;
function getPrice(address token) external view returns (uint);
function getLockedEmissions(address token) external view returns (uint);
function extSloads(bytes32[] calldata slots) external view returns (bytes32[] memory res);
function unlockRatePerSecond(address token) external view returns (uint);
function removeExtraAsset(address token) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {ICore} from "./ICore.sol";
interface IBorrowerOperations {
struct Balances {
uint256[] collaterals;
uint256[] debts;
uint256[] prices;
}
event BorrowingFeePaid(address indexed borrower, uint256 amount);
event CollateralConfigured(address positionManager, address collateralToken);
event PositionCreated(address indexed _borrower, uint256 arrayIndex);
event PositionManagerRemoved(address positionManager);
event PositionUpdated(address indexed _borrower, uint256 _debt, uint256 _coll, uint256 stake, uint8 operation);
function addColl(
address positionManager,
address account,
uint256 _collateralAmount,
address _upperHint,
address _lowerHint
) external;
function adjustPosition(
address positionManager,
address account,
uint256 _maxFeePercentage,
uint256 _collDeposit,
uint256 _collWithdrawal,
uint256 _debtChange,
bool _isDebtIncrease,
address _upperHint,
address _lowerHint
) external;
function closePosition(address positionManager, address account) external;
function configureCollateral(address positionManager, address collateralToken) external;
function fetchBalances() external view returns (Balances memory balances);
function getGlobalSystemBalances() external view returns (uint256 totalPricedCollateral, uint256 totalDebt);
function getTCR() external view returns (uint256 globalTotalCollateralRatio);
function openPosition(
address positionManager,
address account,
uint256 _maxFeePercentage,
uint256 _collateralAmount,
uint256 _debtAmount,
address _upperHint,
address _lowerHint
) external;
function removePositionManager(address positionManager) external;
function repayDebt(
address positionManager,
address account,
uint256 _debtAmount,
address _upperHint,
address _lowerHint
) external;
function setDelegateApproval(address _delegate, bool _isApproved) external;
function setMinNetDebt(uint256 _minNetDebt) external;
function withdrawColl(
address positionManager,
address account,
uint256 _collWithdrawal,
address _upperHint,
address _lowerHint
) external;
function withdrawDebt(
address positionManager,
address account,
uint256 _maxFeePercentage,
uint256 _debtAmount,
address _upperHint,
address _lowerHint
) external;
function positionManagers(uint256) external view returns (address);
function checkRecoveryMode(uint256 TCR) external view returns (bool);
function DEBT_GAS_COMPENSATION() external view returns (uint256);
function DECIMAL_PRECISION() external view returns (uint256);
function PERCENT_DIVISOR() external view returns (uint256);
function CORE() external view returns (ICore);
function debtToken() external view returns (address);
function factory() external view returns (address);
function getCompositeDebt(uint256 _debt) external view returns (uint256);
function guardian() external view returns (address);
function isApprovedDelegate(address owner, address caller) external view returns (bool isApproved);
function minNetDebt() external view returns (uint256);
function owner() external view returns (address);
function positionManagersData(address) external view returns (address collateralToken, uint16 index);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
interface IWNative {
function deposit() external payable;
function withdraw(uint wad) external;
function transfer(address dst, uint256 wad) external returns (bool);
function approve(address to, uint amount) external returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC3156FlashBorrower } from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol";
import "./ICore.sol";
interface IDebtToken is IERC20 {
// --- Events ---
event FlashLoanFeeUpdated(uint256 newFee);
// --- Public constants ---
function version() external view returns (string memory);
function permitTypeHash() external view returns (bytes32);
// --- Public immutables ---
function gasPool() external view returns (address);
function DEBT_GAS_COMPENSATION() external view returns (uint256);
// --- Public mappings ---
function liquidStabilityPools(address) external view returns (bool);
function borrowerOperations(address) external view returns (bool);
function factories(address) external view returns (bool);
function peripheries(address) external view returns (bool);
function positionManagers(address) external view returns (bool);
// --- External functions ---
function enablePositionManager(address _positionManager) external;
function mintWithGasCompensation(address _account, uint256 _amount) external returns (bool);
function burnWithGasCompensation(address _account, uint256 _amount) external returns (bool);
function mint(address _account, uint256 _amount) external;
function burn(address _account, uint256 _amount) external;
function decimals() external view returns (uint8);
function sendToPeriphery(address _sender, uint256 _amount) external;
function sendToSP(address _sender, uint256 _amount) external;
function returnFromPool(address _poolAddress, address _receiver, uint256 _amount) external;
function transfer(address recipient, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function maxFlashLoan(address token) external view returns (uint256);
function flashFee(address token, uint256 amount) external view returns (uint256);
function flashLoan(
IERC3156FlashBorrower receiver,
address token,
uint256 amount,
bytes calldata data
) external returns (bool);
function whitelistLiquidStabilityPoolAddress(address _liquidStabilityPool, bool active) external;
function whitelistBorrowerOperationsAddress(address _borrowerOperations, bool active) external;
function whitelistFactoryAddress(address _factory, bool active) external;
function whitelistPeripheryAddress(address _periphery, bool active) external;
function whitelistPSM(address, bool) external;
function setDebtGasCompensation(uint256 _gasCompensation, bool _isFinalValue) external;
function setFlashLoanFee(uint256 _fee) external;
function DOMAIN_SEPARATOR() external view returns (bytes32);
function permit(
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC3156FlashBorrower} from "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IFactory} from "./IFactory.sol";
interface IPositionManager {
event BaseRateUpdated(uint256 _baseRate);
event CollateralSent(address _to, uint256 _amount);
event LTermsUpdated(uint256 _L_collateral, uint256 _L_debt);
event LastFeeOpTimeUpdated(uint256 _lastFeeOpTime);
event Redemption(
address indexed _redeemer,
uint256 _attemptedDebtAmount,
uint256 _actualDebtAmount,
uint256 _collateralSent,
uint256 _collateralFee
);
event SystemSnapshotsUpdated(uint256 _totalStakesSnapshot, uint256 _totalCollateralSnapshot);
event TotalStakesUpdated(uint256 _newTotalStakes);
event PositionIndexUpdated(address _borrower, uint256 _newIndex);
event PositionSnapshotsUpdated(uint256 _L_collateral, uint256 _L_debt);
event PositionUpdated(address indexed _borrower, uint256 _debt, uint256 _coll, uint256 _stake, uint8 _operation);
function addCollateralSurplus(address borrower, uint256 collSurplus) external;
function applyPendingRewards(address _borrower) external returns (uint256 coll, uint256 debt);
function claimCollateral(address borrower, address _receiver) external;
function closePosition(address _borrower, address _receiver, uint256 collAmount, uint256 debtAmount) external;
function closePositionByLiquidation(address _borrower) external;
function setCollVaultRouter(address _collVaultRouter) external;
function collectInterests() external;
function decayBaseRateAndGetBorrowingFee(uint256 _debt) external returns (uint256);
function decreaseDebtAndSendCollateral(address account, uint256 debt, uint256 coll) external;
function fetchPrice() external view returns (uint256);
function finalizeLiquidation(
address _liquidator,
uint256 _debt,
uint256 _coll,
uint256 _collSurplus,
uint256 _debtGasComp,
uint256 _collGasComp
) external;
function getEntireSystemBalances() external view returns (uint256, uint256, uint256);
function movePendingPositionRewardsToActiveBalances(uint256 _debt, uint256 _collateral) external;
function openPosition(
address _borrower,
uint256 _collateralAmount,
uint256 _compositeDebt,
uint256 NICR,
address _upperHint,
address _lowerHint
) external returns (uint256 stake, uint256 arrayIndex);
function redeemCollateral(
uint256 _debtAmount,
address _firstRedemptionHint,
address _upperPartialRedemptionHint,
address _lowerPartialRedemptionHint,
uint256 _partialRedemptionHintNICR,
uint256 _maxIterations,
uint256 _maxFeePercentage
) external;
function setAddresses(address _priceFeedAddress, address _sortedPositionsAddress, address _collateralToken) external;
function setParameters(
IFactory.DeploymentParams calldata _params
) external;
function setPaused(bool _paused) external;
function setPriceFeed(address _priceFeedAddress) external;
function startSunset() external;
function updateBalances() external;
function updatePositionFromAdjustment(
bool _isDebtIncrease,
uint256 _debtChange,
uint256 _netDebtChange,
bool _isCollIncrease,
uint256 _collChange,
address _upperHint,
address _lowerHint,
address _borrower,
address _receiver
) external returns (uint256, uint256, uint256);
function DEBT_GAS_COMPENSATION() external view returns (uint256);
function DECIMAL_PRECISION() external view returns (uint256);
function L_collateral() external view returns (uint256);
function L_debt() external view returns (uint256);
function MCR() external view returns (uint256);
function PERCENT_DIVISOR() external view returns (uint256);
function CORE() external view returns (address);
function SUNSETTING_INTEREST_RATE() external view returns (uint256);
function Positions(
address
)
external
view
returns (
uint256 debt,
uint256 coll,
uint256 stake,
uint8 status,
uint128 arrayIndex,
uint256 activeInterestIndex
);
function activeInterestIndex() external view returns (uint256);
function baseRate() external view returns (uint256);
function borrowerOperations() external view returns (address);
function borrowingFeeFloor() external view returns (uint256);
function collateralToken() external view returns (address);
function debtToken() external view returns (address);
function collVaultRouter() external view returns (address);
function defaultedCollateral() external view returns (uint256);
function defaultedDebt() external view returns (uint256);
function getBorrowingFee(uint256 _debt) external view returns (uint256);
function getBorrowingFeeWithDecay(uint256 _debt) external view returns (uint256);
function getBorrowingRate() external view returns (uint256);
function getBorrowingRateWithDecay() external view returns (uint256);
function getCurrentICR(address _borrower, uint256 _price) external view returns (uint256);
function getEntireDebtAndColl(
address _borrower
) external view returns (uint256 debt, uint256 coll, uint256 pendingDebtReward, uint256 pendingCollateralReward);
function getEntireSystemColl() external view returns (uint256);
function getEntireSystemDebt() external view returns (uint256);
function getNominalICR(address _borrower) external view returns (uint256);
function getPendingCollAndDebtRewards(address _borrower) external view returns (uint256, uint256);
function getRedemptionFeeWithDecay(uint256 _collateralDrawn) external view returns (uint256);
function getRedemptionRate() external view returns (uint256);
function getRedemptionRateWithDecay() external view returns (uint256);
function getTotalActiveCollateral() external view returns (uint256);
function getTotalActiveDebt() external view returns (uint256);
function getPositionCollAndDebt(address _borrower) external view returns (uint256 coll, uint256 debt);
function getPositionFromPositionOwnersArray(uint256 _index) external view returns (address);
function getPositionOwnersCount() external view returns (uint256);
function getPositionStake(address _borrower) external view returns (uint256);
function getPositionStatus(address _borrower) external view returns (uint256);
function guardian() external view returns (address);
function hasPendingRewards(address _borrower) external view returns (bool);
function interestPayable() external view returns (uint256);
function interestRate() external view returns (uint256);
function lastActiveIndexUpdate() external view returns (uint256);
function lastCollateralError_Redistribution() external view returns (uint256);
function lastDebtError_Redistribution() external view returns (uint256);
function lastFeeOperationTime() external view returns (uint256);
function liquidationManager() external view returns (address);
function maxBorrowingFee() external view returns (uint256);
function maxRedemptionFee() external view returns (uint256);
function maxSystemDebt() external view returns (uint256);
function minuteDecayFactor() external view returns (uint256);
function owner() external view returns (address);
function paused() external view returns (bool);
function priceFeed() external view returns (address);
function redemptionFeeFloor() external view returns (uint256);
function rewardSnapshots(address) external view returns (uint256 collateral, uint256 debt);
function sortedPositions() external view returns (address);
function sunsetting() external view returns (bool);
function surplusBalances(address) external view returns (uint256);
function systemDeploymentTime() external view returns (uint256);
function totalCollateralSnapshot() external view returns (uint256);
function totalStakes() external view returns (uint256);
function totalStakesSnapshot() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IPositionManager} from "src/interfaces/core/IPositionManager.sol";
import {ILSTCollateralVault} from "src/interfaces/core/vaults/ILSTCollateralVault.sol";
import {ILSTVault} from "src/interfaces/utils/integrations/ILSTVault.sol";
interface ICollVaultRouter {
struct OpenPositionVaultParams {
IPositionManager positionManager;
ILSTCollateralVault collVault;
uint256 _maxFeePercentage;
uint256 _debtAmount;
uint256 _collAssetToDeposit;
address _upperHint;
address _lowerHint;
uint256 _minSharesMinted;
uint256 _collIndex;
bytes _preDeposit;
}
/// @dev Avoid stack too deep
struct AdjustPositionVaultParams {
IPositionManager positionManager;
ILSTCollateralVault collVault;
uint256 _maxFeePercentage;
uint256 _collAssetToDeposit;
uint256 _collWithdrawal;
uint256 _debtChange;
bool _isDebtIncrease;
address _upperHint;
address _lowerHint;
bool unwrap;
uint256 _minSharesMinted;
uint256 _minAssetsWithdrawn;
uint256 _collIndex;
bytes _preDeposit;
}
/// @dev Avoid stack too deep
struct RedeemCollateralVaultParams {
IPositionManager positionManager;
ILSTCollateralVault collVault;
uint256 _debtAmount;
address _firstRedemptionHint;
address _upperPartialRedemptionHint;
address _lowerPartialRedemptionHint;
uint256 _partialRedemptionHintNICR;
uint256 _maxIterations;
uint256 _maxFeePercentage;
uint256 _minSharesWithdrawn;
uint256 minAssetsWithdrawn;
uint256 collIndex;
bool unwrap;
}
struct RedeemToOneParams {
uint shares;
address receiver;
address swapRouter;
ILSTCollateralVault collVault;
address targetToken;
uint minTargetTokenAmount;
bytes[] tokensSwapCalldatas;
}
struct SimRedeemVars {
uint256 netShares;
uint256 totalSupply;
address asset;
address mainRewardToken;
uint256 earned;
uint256 assetAmount;
uint256 performanceFee;
}
function openPositionVault(
OpenPositionVaultParams memory params
) external payable;
function adjustPositionVault(AdjustPositionVaultParams calldata params) external payable;
function closePositionVault(
IPositionManager positionManager,
ILSTCollateralVault collVault,
uint256 minAssetsWithdrawn,
uint256 collIndex,
bool unwrap
) external;
function redeemCollateralVault(
RedeemCollateralVaultParams calldata params
) external;
function claimLockedTokens(IERC20[] memory tokens, uint[] memory amounts) external;
function redeemToOne(
RedeemToOneParams calldata params
) external;
function previewRedeemUnderlying(ILSTCollateralVault collVault, uint shares) external view returns (address[] memory tokens, uint[] memory amounts);
function claimCollateralRouter(
IPositionManager positionManager,
ILSTCollateralVault collVault,
address receiver,
uint _collIndex,
uint minAssetsWithdrawn
) external;
function getOrderedRedeemedTokens(
ILSTCollateralVault vault
) external view returns (address[] memory rewardTokens, ILSTVault lstVault);
function addWhitelistedSwapper(
address swapper,
bool status
) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
interface IMetaCore {
// ---------------------------------
// Structures
// ---------------------------------
struct FeeInfo {
bool existsForDebtToken;
uint16 debtTokenFee;
}
struct RebalancerFeeInfo {
bool exists;
uint16 entryFee;
uint16 exitFee;
}
// ---------------------------------
// Public constants
// ---------------------------------
function OWNERSHIP_TRANSFER_DELAY() external view returns (uint256);
function DEFAULT_FLASH_LOAN_FEE() external view returns (uint16);
// ---------------------------------
// Public state variables
// ---------------------------------
function debtToken() external view returns (address);
function lspEntryFee() external view returns (uint16);
function lspExitFee() external view returns (uint16);
function interestProtocolShare() external view returns (uint16);
/// @dev Default interest receiver for all PositionManagers, unless overriden in the respective PM
function defaultInterestReceiver() external view returns (address);
function feeReceiver() external view returns (address);
function priceFeed() external view returns (address);
function owner() external view returns (address);
function pendingOwner() external view returns (address);
function ownershipTransferDeadline() external view returns (uint256);
function guardian() external view returns (address);
function paused() external view returns (bool);
function lspBootstrapPeriod() external view returns (uint64);
// ---------------------------------
// External functions
// ---------------------------------
function setFeeReceiver(address _feeReceiver) external;
function setPriceFeed(address _priceFeed) external;
function setGuardian(address _guardian) external;
/**
* @notice Global pause/unpause
* Pausing halts new deposits/borrowing across the protocol
*/
function setPaused(bool _paused) external;
/**
* @notice Extend or change the LSP bootstrap period,
* after which certain protocol mechanics change
*/
function setLspBootstrapPeriod(uint64 _bootstrapPeriod) external;
/**
* @notice Set a custom flash-loan fee for a given periphery contract
* @param _periphery Target contract that will get this custom fee
* @param _debtTokenFee Fee in basis points (bp)
* @param _existsForDebtToken Whether this custom fee is used when the caller = `debtToken`
*/
function setPeripheryFlashLoanFee(address _periphery, uint16 _debtTokenFee, bool _existsForDebtToken) external;
/**
* @notice Begin the ownership transfer process
* @param newOwner The address proposed to be the new owner
*/
function commitTransferOwnership(address newOwner) external;
/**
* @notice Finish the ownership transfer, after the mandatory delay
*/
function acceptTransferOwnership() external;
/**
* @notice Revoke a pending ownership transfer
*/
function revokeTransferOwnership() external;
/**
* @notice Look up a custom flash-loan fee for a specific periphery contract
* @param peripheryContract The contract that might have a custom fee
* @return The flash-loan fee in basis points
*/
function getPeripheryFlashLoanFee(address peripheryContract) external view returns (uint16);
/**
* @notice Set / override entry & exit fees for a special rebalancer contract
*/
function setRebalancerFee(address _rebalancer, uint16 _entryFee, uint16 _exitFee) external;
/**
* @notice Set the LSP entry fee globally
* @param _fee Fee in basis points
*/
function setEntryFee(uint16 _fee) external;
/**
* @notice Set the LSP exit fee globally
* @param _fee Fee in basis points
*/
function setExitFee(uint16 _fee) external;
/**
* @notice Set the interest protocol share globally to all PositionManagers
* @param _interestProtocolShare Share in basis points
*/
function setInterestProtocolShare(uint16 _interestProtocolShare) external;
/**
* @notice Look up the LSP entry fee for a rebalancer
* @param rebalancer Possibly has a special fee
* @return The entry fee in basis points
*/
function getLspEntryFee(address rebalancer) external view returns (uint16);
/**
* @notice Look up the LSP exit fee for a rebalancer
* @param rebalancer Possibly has a special fee
* @return The exit fee in basis points
*/
function getLspExitFee(address rebalancer) external view returns (uint16);
// ---------------------------------
// Events
// ---------------------------------
event NewOwnerCommitted(address indexed owner, address indexed pendingOwner, uint256 deadline);
event NewOwnerAccepted(address indexed oldOwner, address indexed newOwner);
event NewOwnerRevoked(address indexed owner, address indexed revokedOwner);
event FeeReceiverSet(address indexed feeReceiver);
event PriceFeedSet(address indexed priceFeed);
event GuardianSet(address indexed guardian);
event PeripheryFlashLoanFee(address indexed periphery, uint16 debtTokenFee);
event LSPBootstrapPeriodSet(uint64 bootstrapPeriod);
event RebalancerFees(address indexed rebalancer, uint16 entryFee, uint16 exitFee);
event EntryFeeSet(uint16 fee);
event ExitFeeSet(uint16 fee);
event InterestProtocolShareSet(uint16 interestProtocolShare);
event DefaultInterestReceiverSet(address indexed defaultInterestReceiver);
event Paused();
event Unpaused();
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
interface IPreDepositHook {
function preDepositHook(address owner, bytes calldata data) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
interface ILSTVault {
function stakingToken() external view returns (address);
function stake(uint256 amount) external;
function withdraw(uint256 amount) external;
function getReward() external;
function getRewardForUser(address account) external;
function rewardTokens(uint) external view returns (address);
function getAllRewardTokens() external view returns (address[] memory);
function earned(address account, address _rewardsToken) external view returns (uint256);
function registerVault(address stakingToken) external returns (address);
function balanceOf(address account) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {DynamicArrayLib} from "solady/utils/DynamicArrayLib.sol";
import {ILSTCollateralVault} from "src/interfaces/core/vaults/ILSTCollateralVault.sol";
library TokenValidationLib {
using DynamicArrayLib for DynamicArrayLib.DynamicArray;
using DynamicArrayLib for address[];
using DynamicArrayLib for uint[];
error DuplicateToken();
error InvalidToken();
function checkForDuplicates(address[] memory tokens, uint length) internal pure {
for (uint i; i < length; i++) {
for (uint j = i + 1; j < length; j++) {
if (tokens[i] == tokens[j]) revert DuplicateToken();
}
}
}
function checkValidToken(address token, address[] memory collaterals, uint collateralsLength, address debtToken, bool isExtraAsset) internal pure {
if (isExtraAsset || token == debtToken) {
return;
}
bool isCollateral;
for (uint j; j < collateralsLength; j++) {
if (collaterals[j] == token) {
isCollateral = true;
break;
}
}
if (!isCollateral) revert InvalidToken();
}
function aggregateIfNotExistent(
address token,
uint amount,
DynamicArrayLib.DynamicArray memory tokens,
DynamicArrayLib.DynamicArray memory amounts
) internal pure {
uint index = tokens.indexOf(token);
if (index != DynamicArrayLib.NOT_FOUND) {
uint existingAmount = amounts.getUint256(index);
amounts.set(index, existingAmount + amount);
} else {
tokens.p(token);
amounts.p(amount);
}
}
function contains(address[] memory tokenArray, address targetToken) internal pure returns (uint256) {
uint256 length = tokenArray.length;
for (uint256 i; i < length; ++i) {
if (tokenArray[i] == targetToken) {
return i + 1;
}
}
return 0;
}
/// @dev If the mainRewardTokenVault is included in the rewardTokens list, it returns a new reward array that includes the rewardToken list from the mainRewardTokenVault.
function tryGetRewardedTokensIncludingMainRewardTokenVault(
address[] memory rewardTokens,
address collVaultAsset,
ILSTCollateralVault mainRewardTokenVault
) internal view returns (address[] memory, uint256) {
// Gets a new rewardToken array that includes collVaultAsset.
(address[] memory newRewardTokens, uint256 length) = pushIfNotIncluded(rewardTokens, collVaultAsset);
uint256 mainRewardTokenVaultIdx = contains(newRewardTokens, address(mainRewardTokenVault));
// returns when mainRewardTokenVault is not included in rewardTokens array
if(mainRewardTokenVaultIdx == 0) {
return (newRewardTokens, length);
}
// replace mainRewardTokenVault with mainRewardToken
newRewardTokens[mainRewardTokenVaultIdx - 1] = mainRewardTokenVault.asset();
address[] memory mainRewardTokenVaultRewardTokens = tryGetRewardedTokens(mainRewardTokenVault);
if(mainRewardTokenVaultRewardTokens.length == 0) {
return (newRewardTokens, length);
}
// finalRewardTokens length shouldn't be bigger than (length + mainRewardTokenVaultLength)
uint256 mainRewardTokenVaultLength = mainRewardTokenVaultRewardTokens.length;
address[] memory finalRewardTokens = new address[](length + mainRewardTokenVaultLength);
uint256 finalLength;
// Merge two arrays using the union set method
for(uint256 i; i < length; ++i) {
if(contains(mainRewardTokenVaultRewardTokens, newRewardTokens[i]) == 0) {
finalRewardTokens[finalLength] = newRewardTokens[i];
++finalLength;
}
}
for(uint256 i; i < mainRewardTokenVaultLength; ++i) {
finalRewardTokens[finalLength] = mainRewardTokenVaultRewardTokens[i];
++finalLength;
}
assembly {
mstore(finalRewardTokens, finalLength)
}
return (finalRewardTokens, finalLength);
}
/// @dev Checks if asset is included in reward tokens array
/// @dev CollVault main asset goes at index (len - 1), if it is not included in reward tokens
/// @dev The ordering is inlined with the `CollVaultRouter::previewRedeemUnderlying()` function
function pushIfNotIncluded(address[] memory rewardTokens, address collVaultAsset)
internal
pure
returns (address[] memory, uint256)
{
uint256 originalLength = rewardTokens.length;
if (contains(rewardTokens, collVaultAsset) > 0) {
return (rewardTokens, originalLength);
}
address[] memory _rewardTokens = new address[](originalLength + 1);
for (uint i; i < originalLength; ++i) {
_rewardTokens[i] = rewardTokens[i];
}
_rewardTokens[originalLength] = collVaultAsset;
return (_rewardTokens, originalLength + 1);
}
/// @dev Vaults in LSP could still not have been upgrade to LSTCollateralVault if there is no LSTVault to earn PoL deployed yet
function tryGetRewardedTokens(ILSTCollateralVault collVault) internal view returns (address[] memory) {
address[] memory rewardedTokens;
try collVault.rewardedTokens() returns (address[] memory _rewardedTokens) {
rewardedTokens = _rewardedTokens;
} catch {}
return rewardedTokens;
}
function underlyingAmounts(address[] memory tokens, address account) internal view returns (uint[] memory amounts) {
amounts = new uint[](tokens.length);
for (uint i; i < tokens.length; i++) {
amounts[i] = IERC20(tokens[i]).balanceOf(account);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
library UtilsLib {
function getSelector(bytes memory data) internal pure returns (bytes4 selector) {
require(data.length >= 4, "Dex calldata too short");
selector = bytes4(data);
}
function bubbleUpRevert(bytes memory reason) internal pure {
assembly {
revert(add(reason, 0x20), mload(reason))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Library for memory arrays with automatic capacity resizing.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/DynamicArrayLib.sol)
library DynamicArrayLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRUCTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Type to represent a dynamic array in memory.
/// You can directly assign to `data`, and the `p` function will
/// take care of the memory allocation.
struct DynamicArray {
uint256[] data;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The constant returned when the element is not found in the array.
uint256 internal constant NOT_FOUND = type(uint256).max;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* UINT256 ARRAY OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// Low level minimalist uint256 array operations.
// If you don't need syntax sugar, it's recommended to use these.
// Some of these functions returns the same array for function chaining.
// `e.g. `array.set(0, 1).set(1, 2)`.
/// @dev Returns a uint256 array with `n` elements. The elements are not zeroized.
function malloc(uint256 n) internal pure returns (uint256[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := or(sub(0, shr(32, n)), mload(0x40))
mstore(result, n)
mstore(0x40, add(add(result, 0x20), shl(5, n)))
}
}
/// @dev Zeroizes all the elements of `a`.
function zeroize(uint256[] memory a) internal pure returns (uint256[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
codecopy(add(result, 0x20), codesize(), shl(5, mload(result)))
}
}
/// @dev Returns the element at `a[i]`, without bounds checking.
function get(uint256[] memory a, uint256 i) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(a, 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a[i]`, without bounds checking.
function getUint256(uint256[] memory a, uint256 i) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(a, 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a[i]`, without bounds checking.
function getAddress(uint256[] memory a, uint256 i) internal pure returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(a, 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a[i]`, without bounds checking.
function getBool(uint256[] memory a, uint256 i) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(a, 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a[i]`, without bounds checking.
function getBytes32(uint256[] memory a, uint256 i) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(a, 0x20), shl(5, i)))
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(uint256[] memory a, uint256 i, uint256 data)
internal
pure
returns (uint256[] memory result)
{
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(result, 0x20), shl(5, i)), data)
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(uint256[] memory a, uint256 i, address data)
internal
pure
returns (uint256[] memory result)
{
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(result, 0x20), shl(5, i)), shr(96, shl(96, data)))
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(uint256[] memory a, uint256 i, bool data)
internal
pure
returns (uint256[] memory result)
{
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(result, 0x20), shl(5, i)), iszero(iszero(data)))
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(uint256[] memory a, uint256 i, bytes32 data)
internal
pure
returns (uint256[] memory result)
{
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(result, 0x20), shl(5, i)), data)
}
}
/// @dev Casts `a` to `address[]`.
function asAddressArray(uint256[] memory a) internal pure returns (address[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
}
}
/// @dev Casts `a` to `bool[]`.
function asBoolArray(uint256[] memory a) internal pure returns (bool[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
}
}
/// @dev Casts `a` to `bytes32[]`.
function asBytes32Array(uint256[] memory a) internal pure returns (bytes32[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
}
}
/// @dev Casts `a` to `uint256[]`.
function toUint256Array(address[] memory a) internal pure returns (uint256[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
}
}
/// @dev Casts `a` to `uint256[]`.
function toUint256Array(bool[] memory a) internal pure returns (uint256[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
}
}
/// @dev Casts `a` to `uint256[]`.
function toUint256Array(bytes32[] memory a) internal pure returns (uint256[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
}
}
/// @dev Reduces the size of `a` to `n`.
/// If `n` is greater than the size of `a`, this will be a no-op.
function truncate(uint256[] memory a, uint256 n)
internal
pure
returns (uint256[] memory result)
{
/// @solidity memory-safe-assembly
assembly {
result := a
mstore(mul(lt(n, mload(result)), result), n)
}
}
/// @dev Clears the array and attempts to free the memory if possible.
function free(uint256[] memory a) internal pure returns (uint256[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := a
let n := mload(result)
mstore(shl(6, lt(iszero(n), eq(add(shl(5, add(1, n)), result), mload(0x40)))), result)
mstore(result, 0)
}
}
/// @dev Equivalent to `keccak256(abi.encodePacked(a))`.
function hash(uint256[] memory a) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := keccak256(add(a, 0x20), shl(5, mload(a)))
}
}
/// @dev Returns a copy of `a` sliced from `start` to `end` (exclusive).
function slice(uint256[] memory a, uint256 start, uint256 end)
internal
pure
returns (uint256[] memory result)
{
/// @solidity memory-safe-assembly
assembly {
let arrayLen := mload(a)
if iszero(gt(arrayLen, end)) { end := arrayLen }
if iszero(gt(arrayLen, start)) { start := arrayLen }
if lt(start, end) {
result := mload(0x40)
let resultLen := sub(end, start)
mstore(result, resultLen)
a := add(a, shl(5, start))
// Copy the `a` one word at a time, backwards.
let o := add(shl(5, resultLen), 0x20)
mstore(0x40, add(result, o)) // Allocate memory.
for {} 1 {} {
mstore(add(result, o), mload(add(a, o)))
o := sub(o, 0x20)
if iszero(o) { break }
}
}
}
}
/// @dev Returns if `needle` is in `a`.
function contains(uint256[] memory a, uint256 needle) internal pure returns (bool) {
return ~indexOf(a, needle, 0) != 0;
}
/// @dev Returns the first index of `needle`, scanning forward from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(uint256[] memory a, uint256 needle, uint256 from)
internal
pure
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
result := not(0)
if lt(from, mload(a)) {
let o := add(a, shl(5, from))
let end := add(shl(5, add(1, mload(a))), a)
let c := mload(end) // Cache the word after the array.
for { mstore(end, needle) } 1 {} {
o := add(o, 0x20)
if eq(mload(o), needle) { break }
}
mstore(end, c) // Restore the word after the array.
if iszero(eq(o, end)) { result := shr(5, sub(o, add(0x20, a))) }
}
}
}
/// @dev Returns the first index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(uint256[] memory a, uint256 needle) internal pure returns (uint256 result) {
result = indexOf(a, needle, 0);
}
/// @dev Returns the last index of `needle`, scanning backwards from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(uint256[] memory a, uint256 needle, uint256 from)
internal
pure
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
result := not(0)
let n := mload(a)
if n {
if iszero(lt(from, n)) { from := sub(n, 1) }
let o := add(shl(5, add(2, from)), a)
for { mstore(a, needle) } 1 {} {
o := sub(o, 0x20)
if eq(mload(o), needle) { break }
}
mstore(a, n) // Restore the length.
if iszero(eq(o, a)) { result := shr(5, sub(o, add(0x20, a))) }
}
}
}
/// @dev Returns the first index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(uint256[] memory a, uint256 needle)
internal
pure
returns (uint256 result)
{
result = lastIndexOf(a, needle, NOT_FOUND);
}
/// @dev Directly returns `a` without copying.
function directReturn(uint256[] memory a) internal pure {
assembly {
let retStart := sub(a, 0x20)
mstore(retStart, 0x20)
return(retStart, add(0x40, shl(5, mload(a))))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* DYNAMIC ARRAY OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// Some of these functions returns the same array for function chaining.
// `e.g. `a.p("1").p("2")`.
/// @dev Shorthand for `a.data.length`.
function length(DynamicArray memory a) internal pure returns (uint256) {
return a.data.length;
}
/// @dev Wraps `a` in a dynamic array struct.
function wrap(uint256[] memory a) internal pure returns (DynamicArray memory result) {
result.data = a;
}
/// @dev Wraps `a` in a dynamic array struct.
function wrap(address[] memory a) internal pure returns (DynamicArray memory result) {
/// @solidity memory-safe-assembly
assembly {
mstore(result, a)
}
}
/// @dev Wraps `a` in a dynamic array struct.
function wrap(bool[] memory a) internal pure returns (DynamicArray memory result) {
/// @solidity memory-safe-assembly
assembly {
mstore(result, a)
}
}
/// @dev Wraps `a` in a dynamic array struct.
function wrap(bytes32[] memory a) internal pure returns (DynamicArray memory result) {
/// @solidity memory-safe-assembly
assembly {
mstore(result, a)
}
}
/// @dev Clears the array without deallocating the memory.
function clear(DynamicArray memory a) internal pure returns (DynamicArray memory result) {
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(mload(result), 0)
}
}
/// @dev Clears the array and attempts to free the memory if possible.
function free(DynamicArray memory a) internal pure returns (DynamicArray memory result) {
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
let arrData := mload(result)
if iszero(eq(arrData, 0x60)) {
let prime := 8188386068317523
let cap := mload(sub(arrData, 0x20))
// Extract `cap`, initializing it to zero if it is not a multiple of `prime`.
cap := mul(div(cap, prime), iszero(mod(cap, prime)))
// If `cap` is non-zero and the memory is contiguous, we can free it.
if lt(iszero(cap), eq(mload(0x40), add(arrData, add(0x20, cap)))) {
mstore(0x40, sub(arrData, 0x20))
}
mstore(result, 0x60)
}
}
}
/// @dev Resizes the array to contain `n` elements. New elements will be zeroized.
function resize(DynamicArray memory a, uint256 n)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
reserve(result, n);
/// @solidity memory-safe-assembly
assembly {
let arrData := mload(result)
let arrLen := mload(arrData)
if iszero(lt(n, arrLen)) {
codecopy(add(arrData, shl(5, add(1, arrLen))), codesize(), shl(5, sub(n, arrLen)))
}
mstore(arrData, n)
}
}
/// @dev Increases the size of `a` to `n`.
/// If `n` is less than the size of `a`, this will be a no-op.
/// This method does not zeroize any newly created elements.
function expand(DynamicArray memory a, uint256 n)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
if (n >= a.data.length) {
reserve(result, n);
/// @solidity memory-safe-assembly
assembly {
mstore(mload(result), n)
}
}
}
/// @dev Reduces the size of `a` to `n`.
/// If `n` is greater than the size of `a`, this will be a no-op.
function truncate(DynamicArray memory a, uint256 n)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(mul(lt(n, mload(mload(result))), mload(result)), n)
}
}
/// @dev Reserves at least `minimum` amount of contiguous memory.
function reserve(DynamicArray memory a, uint256 minimum)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(minimum, 0xffffffff)) { invalid() } // For extra safety.
for { let arrData := mload(a) } 1 {} {
// Some random prime number to multiply `cap`, so that
// we know that the `cap` is for a dynamic array.
// Selected to be larger than any memory pointer realistically.
let prime := 8188386068317523
// Special case for `arrData` pointing to zero pointer.
if eq(arrData, 0x60) {
let newCap := shl(5, add(1, minimum))
let capSlot := mload(0x40)
mstore(capSlot, mul(prime, newCap)) // Store the capacity.
let newArrData := add(0x20, capSlot)
mstore(newArrData, 0) // Store the length.
mstore(0x40, add(newArrData, add(0x20, newCap))) // Allocate memory.
mstore(a, newArrData)
break
}
let w := not(0x1f)
let cap := mload(add(arrData, w)) // `mload(sub(arrData, w))`.
// Extract `cap`, initializing it to zero if it is not a multiple of `prime`.
cap := mul(div(cap, prime), iszero(mod(cap, prime)))
let newCap := shl(5, minimum)
// If we don't need to grow the memory.
if iszero(and(gt(minimum, mload(arrData)), gt(newCap, cap))) { break }
// If the memory is contiguous, we can simply expand it.
if eq(mload(0x40), add(arrData, add(0x20, cap))) {
mstore(add(arrData, w), mul(prime, newCap)) // Store the capacity.
mstore(0x40, add(arrData, add(0x20, newCap))) // Expand the memory allocation.
break
}
let capSlot := mload(0x40)
let newArrData := add(capSlot, 0x20)
mstore(0x40, add(newArrData, add(0x20, newCap))) // Reallocate the memory.
mstore(a, newArrData) // Store the `newArrData`.
// Copy `arrData` one word at a time, backwards.
for { let o := add(0x20, shl(5, mload(arrData))) } 1 {} {
mstore(add(newArrData, o), mload(add(arrData, o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
mstore(capSlot, mul(prime, newCap)) // Store the capacity.
mstore(newArrData, mload(arrData)) // Store the length.
break
}
}
}
/// @dev Appends `data` to `a`.
function p(DynamicArray memory a, uint256 data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
let arrData := mload(a)
let newArrLen := add(mload(arrData), 1)
let newArrBytesLen := shl(5, newArrLen)
// Some random prime number to multiply `cap`, so that
// we know that the `cap` is for a dynamic array.
// Selected to be larger than any memory pointer realistically.
let prime := 8188386068317523
let cap := mload(sub(arrData, 0x20))
// Extract `cap`, initializing it to zero if it is not a multiple of `prime`.
cap := mul(div(cap, prime), iszero(mod(cap, prime)))
// Expand / Reallocate memory if required.
// Note that we need to allocate an extra word for the length.
for {} iszero(lt(newArrBytesLen, cap)) {} {
// Approximately more than double the capacity to ensure more than enough space.
let newCap := add(cap, or(cap, newArrBytesLen))
// If the memory is contiguous, we can simply expand it.
if iszero(or(xor(mload(0x40), add(arrData, add(0x20, cap))), eq(arrData, 0x60))) {
mstore(sub(arrData, 0x20), mul(prime, newCap)) // Store the capacity.
mstore(0x40, add(arrData, add(0x20, newCap))) // Expand the memory allocation.
break
}
// Set the `newArrData` to point to the word after `cap`.
let newArrData := add(mload(0x40), 0x20)
mstore(0x40, add(newArrData, add(0x20, newCap))) // Reallocate the memory.
mstore(a, newArrData) // Store the `newArrData`.
let w := not(0x1f)
// Copy `arrData` one word at a time, backwards.
for { let o := newArrBytesLen } 1 {} {
mstore(add(newArrData, o), mload(add(arrData, o)))
o := add(o, w) // `sub(o, 0x20)`.
if iszero(o) { break }
}
mstore(add(newArrData, w), mul(prime, newCap)) // Store the memory.
arrData := newArrData // Assign `newArrData` to `arrData`.
break
}
mstore(add(arrData, newArrBytesLen), data) // Append `data`.
mstore(arrData, newArrLen) // Store the length.
}
}
/// @dev Appends `data` to `a`.
function p(DynamicArray memory a, address data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = p(a, uint256(uint160(data)));
}
/// @dev Appends `data` to `a`.
function p(DynamicArray memory a, bool data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = p(a, _toUint(data));
}
/// @dev Appends `data` to `a`.
function p(DynamicArray memory a, bytes32 data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = p(a, uint256(data));
}
/// @dev Shorthand for returning an empty array.
function p() internal pure returns (DynamicArray memory result) {}
/// @dev Shorthand for `p(p(), data)`.
function p(uint256 data) internal pure returns (DynamicArray memory result) {
p(result, uint256(data));
}
/// @dev Shorthand for `p(p(), data)`.
function p(address data) internal pure returns (DynamicArray memory result) {
p(result, uint256(uint160(data)));
}
/// @dev Shorthand for `p(p(), data)`.
function p(bool data) internal pure returns (DynamicArray memory result) {
p(result, _toUint(data));
}
/// @dev Shorthand for `p(p(), data)`.
function p(bytes32 data) internal pure returns (DynamicArray memory result) {
p(result, uint256(data));
}
/// @dev Removes and returns the last element of `a`.
/// Returns 0 and does not pop anything if the array is empty.
function pop(DynamicArray memory a) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
let o := mload(a)
let n := mload(o)
result := mload(add(o, shl(5, n)))
mstore(o, sub(n, iszero(iszero(n))))
}
}
/// @dev Removes and returns the last element of `a`.
/// Returns 0 and does not pop anything if the array is empty.
function popUint256(DynamicArray memory a) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
let o := mload(a)
let n := mload(o)
result := mload(add(o, shl(5, n)))
mstore(o, sub(n, iszero(iszero(n))))
}
}
/// @dev Removes and returns the last element of `a`.
/// Returns 0 and does not pop anything if the array is empty.
function popAddress(DynamicArray memory a) internal pure returns (address result) {
/// @solidity memory-safe-assembly
assembly {
let o := mload(a)
let n := mload(o)
result := mload(add(o, shl(5, n)))
mstore(o, sub(n, iszero(iszero(n))))
}
}
/// @dev Removes and returns the last element of `a`.
/// Returns 0 and does not pop anything if the array is empty.
function popBool(DynamicArray memory a) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
let o := mload(a)
let n := mload(o)
result := mload(add(o, shl(5, n)))
mstore(o, sub(n, iszero(iszero(n))))
}
}
/// @dev Removes and returns the last element of `a`.
/// Returns 0 and does not pop anything if the array is empty.
function popBytes32(DynamicArray memory a) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let o := mload(a)
let n := mload(o)
result := mload(add(o, shl(5, n)))
mstore(o, sub(n, iszero(iszero(n))))
}
}
/// @dev Returns the element at `a.data[i]`, without bounds checking.
function get(DynamicArray memory a, uint256 i) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(mload(a), 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a.data[i]`, without bounds checking.
function getUint256(DynamicArray memory a, uint256 i) internal pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(mload(a), 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a.data[i]`, without bounds checking.
function getAddress(DynamicArray memory a, uint256 i) internal pure returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(mload(a), 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a.data[i]`, without bounds checking.
function getBool(DynamicArray memory a, uint256 i) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(mload(a), 0x20), shl(5, i)))
}
}
/// @dev Returns the element at `a.data[i]`, without bounds checking.
function getBytes32(DynamicArray memory a, uint256 i) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(add(add(mload(a), 0x20), shl(5, i)))
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(DynamicArray memory a, uint256 i, uint256 data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(mload(result), 0x20), shl(5, i)), data)
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(DynamicArray memory a, uint256 i, address data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(mload(result), 0x20), shl(5, i)), shr(96, shl(96, data)))
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(DynamicArray memory a, uint256 i, bool data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(mload(result), 0x20), shl(5, i)), iszero(iszero(data)))
}
}
/// @dev Sets `a.data[i]` to `data`, without bounds checking.
function set(DynamicArray memory a, uint256 i, bytes32 data)
internal
pure
returns (DynamicArray memory result)
{
_deallocate(result);
result = a;
/// @solidity memory-safe-assembly
assembly {
mstore(add(add(mload(result), 0x20), shl(5, i)), data)
}
}
/// @dev Returns the underlying array as a `uint256[]`.
function asUint256Array(DynamicArray memory a)
internal
pure
returns (uint256[] memory result)
{
/// @solidity memory-safe-assembly
assembly {
result := mload(a)
}
}
/// @dev Returns the underlying array as a `address[]`.
function asAddressArray(DynamicArray memory a)
internal
pure
returns (address[] memory result)
{
/// @solidity memory-safe-assembly
assembly {
result := mload(a)
}
}
/// @dev Returns the underlying array as a `bool[]`.
function asBoolArray(DynamicArray memory a) internal pure returns (bool[] memory result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(a)
}
}
/// @dev Returns the underlying array as a `bytes32[]`.
function asBytes32Array(DynamicArray memory a)
internal
pure
returns (bytes32[] memory result)
{
/// @solidity memory-safe-assembly
assembly {
result := mload(a)
}
}
/// @dev Returns a copy of `a` sliced from `start` to `end` (exclusive).
function slice(DynamicArray memory a, uint256 start, uint256 end)
internal
pure
returns (DynamicArray memory result)
{
result.data = slice(a.data, start, end);
}
/// @dev Returns a copy of `a` sliced from `start` to the end of the array.
function slice(DynamicArray memory a, uint256 start)
internal
pure
returns (DynamicArray memory result)
{
result.data = slice(a.data, start, type(uint256).max);
}
/// @dev Returns if `needle` is in `a`.
function contains(DynamicArray memory a, uint256 needle) internal pure returns (bool) {
return ~indexOf(a.data, needle, 0) != 0;
}
/// @dev Returns if `needle` is in `a`.
function contains(DynamicArray memory a, address needle) internal pure returns (bool) {
return ~indexOf(a.data, uint160(needle), 0) != 0;
}
/// @dev Returns if `needle` is in `a`.
function contains(DynamicArray memory a, bytes32 needle) internal pure returns (bool) {
return ~indexOf(a.data, uint256(needle), 0) != 0;
}
/// @dev Returns the first index of `needle`, scanning forward from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(DynamicArray memory a, uint256 needle, uint256 from)
internal
pure
returns (uint256)
{
return indexOf(a.data, needle, from);
}
/// @dev Returns the first index of `needle`, scanning forward from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(DynamicArray memory a, address needle, uint256 from)
internal
pure
returns (uint256)
{
return indexOf(a.data, uint160(needle), from);
}
/// @dev Returns the first index of `needle`, scanning forward from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(DynamicArray memory a, bytes32 needle, uint256 from)
internal
pure
returns (uint256)
{
return indexOf(a.data, uint256(needle), from);
}
/// @dev Returns the first index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(DynamicArray memory a, uint256 needle) internal pure returns (uint256) {
return indexOf(a.data, needle, 0);
}
/// @dev Returns the first index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(DynamicArray memory a, address needle) internal pure returns (uint256) {
return indexOf(a.data, uint160(needle), 0);
}
/// @dev Returns the first index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function indexOf(DynamicArray memory a, bytes32 needle) internal pure returns (uint256) {
return indexOf(a.data, uint256(needle), 0);
}
/// @dev Returns the last index of `needle`, scanning backwards from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(DynamicArray memory a, uint256 needle, uint256 from)
internal
pure
returns (uint256)
{
return lastIndexOf(a.data, needle, from);
}
/// @dev Returns the last index of `needle`, scanning backwards from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(DynamicArray memory a, address needle, uint256 from)
internal
pure
returns (uint256)
{
return lastIndexOf(a.data, uint160(needle), from);
}
/// @dev Returns the last index of `needle`, scanning backwards from `from`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(DynamicArray memory a, bytes32 needle, uint256 from)
internal
pure
returns (uint256)
{
return lastIndexOf(a.data, uint256(needle), from);
}
/// @dev Returns the last index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(DynamicArray memory a, uint256 needle) internal pure returns (uint256) {
return lastIndexOf(a.data, needle, NOT_FOUND);
}
/// @dev Returns the last index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(DynamicArray memory a, address needle) internal pure returns (uint256) {
return lastIndexOf(a.data, uint160(needle), NOT_FOUND);
}
/// @dev Returns the last index of `needle`.
/// If `needle` is not in `a`, returns `NOT_FOUND`.
function lastIndexOf(DynamicArray memory a, bytes32 needle) internal pure returns (uint256) {
return lastIndexOf(a.data, uint256(needle), NOT_FOUND);
}
/// @dev Equivalent to `keccak256(abi.encodePacked(a.data))`.
function hash(DynamicArray memory a) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := keccak256(add(mload(a), 0x20), shl(5, mload(mload(a))))
}
}
/// @dev Directly returns `a` without copying.
function directReturn(DynamicArray memory a) internal pure {
assembly {
let arrData := mload(a)
let retStart := sub(arrData, 0x20)
mstore(retStart, 0x20)
return(retStart, add(0x40, shl(5, mload(arrData))))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PRIVATE HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Helper for deallocating a automatically allocated array pointer.
function _deallocate(DynamicArray memory result) private pure {
/// @solidity memory-safe-assembly
assembly {
mstore(0x40, result) // Deallocate, as we have already allocated.
}
}
/// @dev Casts the bool into a uint256.
function _toUint(bool b) private pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
result := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
library FeeLib {
using Math for uint;
uint private constant BP = 1e4;
/// @dev Calculates the fees that should be added to an amount `shares` that does already include fees.
/// Used in {IERC4626-deposit}, {IERC4626-mint}, {IERC4626-withdraw} and {IERC4626-previewRedeem} operations.
function feeOnRaw(
uint shares,
uint feeBP
) internal pure returns (uint) {
return shares.mulDiv(feeBP, BP, Math.Rounding.Up);
}
/// @dev Calculates the fee part of an amount `shares` that deoes not includes fees.
/// Used in {IERC4626-previewDeposit} and {IERC4626-previewRedeem} operations.
function feeOnTotal(
uint shares,
uint feeBP
) internal pure returns (uint) {
return shares.mulDiv(feeBP, feeBP + BP, Math.Rounding.Up);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {UtilsLib} from "src/libraries/UtilsLib.sol";
library SwappersLib {
using UtilsLib for bytes;
event SwapperAdded(address indexed swapRouter, bool status);
struct SwapperData {
mapping(address => bool) whitelistedSwappers;
}
function addWhitelistedSwapper(SwapperData storage self, address _swapRouter, bool status) internal {
self.whitelistedSwappers[_swapRouter] = status;
emit SwapperAdded(_swapRouter, status);
}
function executeSwap(SwapperData storage self, address swapRouter, bytes memory dexCalldata) internal {
require(self.whitelistedSwappers[swapRouter], "SwappersLib: swapper not whitelisted");
(bool success, bytes memory retData) = swapRouter.call(dexCalldata);
if (!success) {
retData.bubbleUpRevert();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC20.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @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.
*
* ```
* 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 of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @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._indexes[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 read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 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 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @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._indexes[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 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;
/// @solidity memory-safe-assembly
assembly {
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 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;
/// @solidity memory-safe-assembly
assembly {
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 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;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC4626, IERC20} from "@openzeppelin/contracts/interfaces/IERC4626.sol";
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {IPositionManager} from "../IPositionManager.sol";
import {IMetaCore} from "../IMetaCore.sol";
import {IPriceFeed} from "../IPriceFeed.sol";
import {EmissionsLib} from "src/libraries/EmissionsLib.sol";
interface IBaseCollateralVault is IERC4626, IERC1822Proxiable {
struct BaseInitParams {
uint16 _minWithdrawFee;
uint16 _maxWithdrawFee;
uint16 _withdrawFee;
IMetaCore _metaCore;
// ERC4626
IERC20 _asset;
// ERC20
string _sharesName;
string _sharesSymbol;
}
struct BaseCollVaultStorage {
uint16 minWithdrawFee;
uint16 maxWithdrawFee;
uint16 withdrawFee; // over rewarded tokens, in basis points
uint8 assetDecimals;
IMetaCore _metaCore;
// Second mapping of this struct is usless, but it's for retrocompatibility with LSTCollateralVault
EmissionsLib.BalanceData balanceData;
}
function totalAssets() external view returns (uint); // todo: maybe remove this
function fetchPrice() external view returns (uint);
function getPrice(address token) external view returns (uint);
function receiveDonations(address[] memory tokens, uint[] memory amounts, address receiver) external;
function setWithdrawFee(uint16 _withdrawFee) external;
function getBalance(address token) external view returns (uint);
function getWithdrawFee() external view returns (uint16);
function getMetaCore() external view returns (IMetaCore);
function getPriceFeed() external view returns (IPriceFeed);
function assetDecimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
interface ILSTWrapper is IERC20 {
function metaCore() external view returns (address);
function lstCollVault() external view returns (address);
function decimals() external view returns (uint8);
function depositFor(address account, uint256 amount) external returns (bool);
function withdrawTo(address account, uint256 amount) external returns (bool);
function recover(address account) external returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
library EmissionsLib {
using SafeCast for uint256;
uint64 constant internal DEFAULT_UNLOCK_RATE = 1e11; // 10% per second
uint64 constant internal MAX_UNLOCK_RATE = 1e12; // 100%
struct BalanceData {
mapping(address token => uint) balance;
mapping(address token => EmissionSchedule) emissionSchedule;
}
struct EmissionSchedule {
uint128 emissions;
uint64 lockTimestamp;
uint64 _unlockRatePerSecond; // rate points
}
error AmountCannotBeZero();
error EmissionRateExceedsMax();
// error UnsupportedEmissionConfig();
event EmissionsAdded(address indexed token, uint128 amount);
event EmissionsSub(address indexed token, uint128 amount);
event NewUnlockRatePerSecond(address indexed token, uint64 unlockRatePerSecond);
/// @dev zero _unlockRatePerSecond parameter resets rate back to DEFAULT_UNLOCK_RATE
function setUnlockRatePerSecond(BalanceData storage $, address token, uint64 _unlockRatePerSecond) internal {
if (_unlockRatePerSecond > MAX_UNLOCK_RATE) revert EmissionRateExceedsMax();
_addEmissions($, token, 0); // update lockTimestamp and emissions
$.emissionSchedule[token]._unlockRatePerSecond = _unlockRatePerSecond;
emit NewUnlockRatePerSecond(token, _unlockRatePerSecond);
}
function addEmissions(BalanceData storage $, address token, uint128 amount) internal {
if (amount == 0) revert AmountCannotBeZero();
_addEmissions($, token, amount);
emit EmissionsAdded(token, amount);
}
function _addEmissions(BalanceData storage $, address token, uint128 amount) private {
EmissionSchedule memory schedule = $.emissionSchedule[token];
uint256 _unlockTimestamp = unlockTimestamp(schedule);
uint128 nextEmissions = (lockedEmissions(schedule, _unlockTimestamp) + amount).toUint128();
schedule.emissions = nextEmissions;
schedule.lockTimestamp = block.timestamp.toUint64();
$.balance[token] += amount;
$.emissionSchedule[token] = schedule;
}
function subEmissions(BalanceData storage $, address token, uint128 amount) internal {
if (amount == 0) revert AmountCannotBeZero();
_subEmissions($, token, amount);
emit EmissionsSub(token, amount);
}
function _subEmissions(BalanceData storage $, address token, uint128 amount) private {
EmissionSchedule memory schedule = $.emissionSchedule[token];
uint256 _unlockTimestamp = unlockTimestamp(schedule);
uint128 nextEmissions = (lockedEmissions(schedule, _unlockTimestamp) - amount).toUint128();
schedule.emissions = nextEmissions;
schedule.lockTimestamp = block.timestamp.toUint64();
$.balance[token] -= amount;
$.emissionSchedule[token] = schedule;
}
/// @dev Doesn't include locked emissions
function unlockedEmissions(EmissionSchedule memory schedule) internal view returns (uint256) {
return schedule.emissions - lockedEmissions(schedule, unlockTimestamp(schedule));
}
function balanceOfWithFutureEmissions(BalanceData storage $, address token) internal view returns (uint256) {
return $.balance[token];
}
/**
* @notice Returns the unlocked token emissions
*/
function balanceOf(BalanceData storage $, address token) internal view returns (uint256) {
EmissionSchedule memory schedule = $.emissionSchedule[token];
return $.balance[token] - lockedEmissions(schedule, unlockTimestamp(schedule));
}
/**
* @notice Returns locked emissions
*/
function lockedEmissions(EmissionSchedule memory schedule, uint256 _unlockTimestamp) internal view returns (uint256) {
if (block.timestamp >= _unlockTimestamp) {
// all emissions were unlocked
return 0;
} else {
// emissions are still unlocking, calculate the amount of already unlocked emissions
uint256 secondsSinceLockup = block.timestamp - schedule.lockTimestamp;
// design decision - use dimensionless 'unlock rate units' to unlock emissions over a fixed time window
uint256 ratePointsUnlocked = unlockRatePerSecond(schedule) * secondsSinceLockup;
// emissions remainder is designed to be added to balance in unlockTimestamp
return schedule.emissions - ratePointsUnlocked * schedule.emissions / MAX_UNLOCK_RATE;
}
}
// timestamp at which all emissions are fully unlocked
function unlockTimestamp(EmissionSchedule memory schedule) internal pure returns (uint256) {
// ceil to account for remainder seconds left after integer division
return divRoundUp(MAX_UNLOCK_RATE, unlockRatePerSecond(schedule)) + schedule.lockTimestamp;
}
function unlockRatePerSecond(EmissionSchedule memory schedule) internal pure returns (uint256) {
return schedule._unlockRatePerSecond == 0 ? DEFAULT_UNLOCK_RATE : schedule._unlockRatePerSecond;
}
function divRoundUp(uint256 dividend, uint256 divisor) internal pure returns (uint256) {
return (dividend + divisor - 1) / divisor;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*
* _Available since v4.7._
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(
uint256 assets,
address receiver,
address owner
) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(
uint256 shares,
address receiver,
address owner
) external returns (uint256 assets);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface 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
pragma solidity 0.8.26;
import {IMetaCore} from "src/interfaces/core/IMetaCore.sol";
interface ICore {
// --- Public variables ---
function metaCore() external view returns (IMetaCore);
function startTime() external view returns (uint256);
function CCR() external view returns (uint256);
function dmBootstrapPeriod() external view returns (uint64);
function isPeriphery(address peripheryContract) external view returns (bool);
// --- External functions ---
function setPeripheryEnabled(address _periphery, bool _enabled) external;
function setPMBootstrapPeriod(address dm, uint64 _bootstrapPeriod) external;
function setNewCCR(uint256 _CCR) external;
function priceFeed() external view returns (address);
function owner() external view returns (address);
function pendingOwner() external view returns (address);
function guardian() external view returns (address);
function feeReceiver() external view returns (address);
function paused() external view returns (bool);
function lspBootstrapPeriod() external view returns (uint64);
function getLspEntryFee(address rebalancer) external view returns (uint16);
function getLspExitFee(address rebalancer) external view returns (uint16);
function interestProtocolShare() external view returns (uint16);
function defaultInterestReceiver() external view returns (address);
// --- Events ---
event CCRSet(uint256 initialCCR);
event PMBootstrapPeriodSet(address dm, uint64 bootstrapPeriod);
event PeripheryEnabled(address indexed periphery, bool enabled);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC3156FlashBorrower.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC3156 FlashBorrower, as defined in
* https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
*
* _Available since v4.1._
*/
interface IERC3156FlashBorrower {
/**
* @dev Receive a flash loan.
* @param initiator The initiator of the loan.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @param fee The additional amount of tokens to repay.
* @param data Arbitrary data structure, intended to contain user-defined parameters.
* @return The keccak256 hash of "IERC3156FlashBorrower.onFlashLoan"
*/
function onFlashLoan(
address initiator,
address token,
uint256 amount,
uint256 fee,
bytes calldata data
) external returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
interface IFactory {
// commented values are suggested default parameters
struct DeploymentParams {
uint256 minuteDecayFactor; // 999037758833783000 (half life of 12 hours)
uint256 redemptionFeeFloor; // 1e18 / 1000 * 5 (0.5%)
uint256 maxRedemptionFee; // 1e18 (100%)
uint256 borrowingFeeFloor; // 1e18 / 1000 * 5 (0.5%)
uint256 maxBorrowingFee; // 1e18 / 100 * 5 (5%)
uint256 interestRateInBps; // 100 (1%)
uint256 maxDebt;
uint256 MCR; // 12 * 1e17 (120%)
address collVaultRouter; // set to address(0) if PositionManager coll is not CollateralVault
}
event NewDeployment(address collateral, address priceFeed, address positionManager, address sortedPositions);
function deployNewInstance(
address collateral,
address priceFeed,
address customPositionManagerImpl,
address customSortedPositionsImpl,
DeploymentParams calldata params,
uint64 unlockRatePerSecond,
bool forceThroughLspBalanceCheck
) external;
function setImplementations(address _positionManagerImpl, address _sortedPositionsImpl) external;
function CORE() external view returns (address);
function borrowerOperations() external view returns (address);
function debtToken() external view returns (address);
function guardian() external view returns (address);
function liquidationManager() external view returns (address);
function owner() external view returns (address);
function sortedPositionsImpl() external view returns (address);
function liquidStabilityPool() external view returns (address);
function positionManagerCount() external view returns (uint256);
function positionManagerImpl() external view returns (address);
function positionManagers(uint256) external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IPriceFeed {
struct FeedType {
address spotOracle;
bool isCollVault;
}
event NewOracleRegistered(address token, address chainlinkAggregator, address underlyingDerivative);
event PriceFeedStatusUpdated(address token, address oracle, bool isWorking);
event PriceRecordUpdated(address indexed token, uint256 _price);
event NewCollVaultRegistered(address collVault, bool enable);
event NewSpotOracleRegistered(address token, address spotOracle);
function fetchPrice(address _token) external view returns (uint256);
function getMultiplePrices(address[] memory _tokens) external view returns (uint256[] memory prices);
function setOracle(
address _token,
address _chainlinkOracle,
uint32 _heartbeat,
uint16 _staleThreshold,
address underlyingDerivative
) external;
function whitelistCollateralVault(address _collateralVaultShareToken, bool enable) external;
function setSpotOracle(address _token, address _spotOracle) external;
function MAX_PRICE_DEVIATION_FROM_PREVIOUS_ROUND() external view returns (uint256);
function CORE() external view returns (address);
function RESPONSE_TIMEOUT() external view returns (uint256);
function TARGET_DIGITS() external view returns (uint256);
function guardian() external view returns (address);
function oracleRecords(
address
)
external
view
returns (
address chainLinkOracle,
uint8 decimals,
uint32 heartbeat,
uint16 staleThreshold,
address underlyingDerivative
);
function isCollVault(address _collateralVaultShareToken) external view returns (bool);
function isStableBPT(address _oracle) external view returns (bool);
function isWeightedBPT(address _oracle) external view returns (bool);
function getSpotOracle(address _token) external view returns (address);
function feedType(address _token) external view returns (FeedType memory);
function owner() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX 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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @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
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
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
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
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
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
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
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
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
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
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
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
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
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
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
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
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
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
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
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
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
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
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
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
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
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
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
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
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
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
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
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
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
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
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
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
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
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
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
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
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
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
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
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
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
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
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
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
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
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
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
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
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
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
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
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
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
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
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
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
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
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
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
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @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
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @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
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
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);
}{
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin-upgradeable/contracts/=lib/openzeppelin-contracts-upgradeable/contracts/",
"solady/=lib/solady/src/",
"@solmate/=lib/solmate/src/",
"@chimera/=lib/chimera/src/",
"forge-std/=lib/forge-std/src/",
"@uniswap/v3-core/=lib/v3-core/",
"@uniswap/v3-periphery/=lib/v3-periphery/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"chimera/=lib/chimera/src/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"rewards/=lib/rewards/",
"solmate/=lib/solmate/src/",
"v3-core/=lib/v3-core/contracts/",
"v3-periphery/=lib/v3-periphery/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 100
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_borrowerOperations","type":"address"},{"internalType":"address","name":"_wNative","type":"address"},{"internalType":"address","name":"_debtToken","type":"address"},{"internalType":"address","name":"_liquidStabilityPool","type":"address"},{"internalType":"address","name":"_metaCore","type":"address"},{"internalType":"address","name":"_mainRewardTokenVault","type":"address"},{"internalType":"address[]","name":"_initialWhitelistedSwappers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"swapRouter","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"SwapperAdded","type":"event"},{"inputs":[{"internalType":"address","name":"_swapRouter","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"addWhitelistedSwapper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IPositionManager","name":"positionManager","type":"address"},{"internalType":"contract ILSTCollateralVault","name":"collVault","type":"address"},{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_collAssetToDeposit","type":"uint256"},{"internalType":"uint256","name":"_collWithdrawal","type":"uint256"},{"internalType":"uint256","name":"_debtChange","type":"uint256"},{"internalType":"bool","name":"_isDebtIncrease","type":"bool"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"uint256","name":"_minSharesMinted","type":"uint256"},{"internalType":"uint256","name":"_minAssetsWithdrawn","type":"uint256"},{"internalType":"uint256","name":"_collIndex","type":"uint256"},{"internalType":"bytes","name":"_preDeposit","type":"bytes"}],"internalType":"struct ICollVaultRouter.AdjustPositionVaultParams","name":"params","type":"tuple"}],"name":"adjustPositionVault","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IPositionManager","name":"positionManager","type":"address"},{"internalType":"contract ILSTCollateralVault","name":"collVault","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"_collIndex","type":"uint256"},{"internalType":"uint256","name":"minAssetsWithdrawn","type":"uint256"}],"name":"claimCollateralRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"claimLockedTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IPositionManager","name":"positionManager","type":"address"},{"internalType":"contract ILSTCollateralVault","name":"collVault","type":"address"},{"internalType":"uint256","name":"minAssetsWithdrawn","type":"uint256"},{"internalType":"uint256","name":"collIndex","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"}],"name":"closePositionVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ILSTCollateralVault","name":"vault","type":"address"}],"name":"getOrderedRedeemedTokens","outputs":[{"internalType":"address[]","name":"rewardTokens","type":"address[]"},{"internalType":"contract ILSTVault","name":"lstVault","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mainRewardTokenVault","outputs":[{"internalType":"contract ILSTCollateralVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IPositionManager","name":"positionManager","type":"address"},{"internalType":"contract ILSTCollateralVault","name":"collVault","type":"address"},{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_debtAmount","type":"uint256"},{"internalType":"uint256","name":"_collAssetToDeposit","type":"uint256"},{"internalType":"address","name":"_upperHint","type":"address"},{"internalType":"address","name":"_lowerHint","type":"address"},{"internalType":"uint256","name":"_minSharesMinted","type":"uint256"},{"internalType":"uint256","name":"_collIndex","type":"uint256"},{"internalType":"bytes","name":"_preDeposit","type":"bytes"}],"internalType":"struct ICollVaultRouter.OpenPositionVaultParams","name":"params","type":"tuple"}],"name":"openPositionVault","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract ILSTCollateralVault","name":"collVault","type":"address"},{"internalType":"uint256","name":"sharesToRedeem","type":"uint256"}],"name":"previewRedeemUnderlying","outputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"contract IPositionManager","name":"positionManager","type":"address"},{"internalType":"contract ILSTCollateralVault","name":"collVault","type":"address"},{"internalType":"uint256","name":"_debtAmount","type":"uint256"},{"internalType":"address","name":"_firstRedemptionHint","type":"address"},{"internalType":"address","name":"_upperPartialRedemptionHint","type":"address"},{"internalType":"address","name":"_lowerPartialRedemptionHint","type":"address"},{"internalType":"uint256","name":"_partialRedemptionHintNICR","type":"uint256"},{"internalType":"uint256","name":"_maxIterations","type":"uint256"},{"internalType":"uint256","name":"_maxFeePercentage","type":"uint256"},{"internalType":"uint256","name":"_minSharesWithdrawn","type":"uint256"},{"internalType":"uint256","name":"minAssetsWithdrawn","type":"uint256"},{"internalType":"uint256","name":"collIndex","type":"uint256"},{"internalType":"bool","name":"unwrap","type":"bool"}],"internalType":"struct ICollVaultRouter.RedeemCollateralVaultParams","name":"params","type":"tuple"}],"name":"redeemCollateralVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"swapRouter","type":"address"},{"internalType":"contract ILSTCollateralVault","name":"collVault","type":"address"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"minTargetTokenAmount","type":"uint256"},{"internalType":"bytes[]","name":"tokensSwapCalldatas","type":"bytes[]"}],"internalType":"struct ICollVaultRouter.RedeemToOneParams","name":"params","type":"tuple"}],"name":"redeemToOne","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_mainRewardTokenVault","type":"address"}],"name":"setMainRewardTokenVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
610120604052348015610010575f80fd5b50604051614a07380380614a0783398101604081905261002f916101e8565b6001600160a01b038716158061004c57506001600160a01b038616155b8061005e57506001600160a01b038516155b8061007057506001600160a01b038416155b8061008257506001600160a01b038316155b156100d35760405162461bcd60e51b815260206004820152601a60248201527f436f6c6c5661756c74526f757465723a20302061646472657373000000000000604482015260640160405180910390fd5b6001600160a01b0387811660805286811660a05285811660c05284811660e05283811661010052600180546001600160a01b0319169184169190911790555f5b815181101561014f576101475f83838151811061013257610132610316565b6020026020010151600161015c60201b60201c565b600101610113565b505050505050505061032a565b6001600160a01b0382165f8181526020858152604091829020805460ff191685151590811790915591519182527f7dc49220c17ba736a5a8f465c46784ed2262884e4ea605ae95e6fd117a77a421910160405180910390a2505050565b80516001600160a01b03811681146101cf575f80fd5b919050565b634e487b7160e01b5f52604160045260245ffd5b5f805f805f805f60e0888a0312156101fe575f80fd5b610207886101b9565b9650610215602089016101b9565b9550610223604089016101b9565b9450610231606089016101b9565b935061023f608089016101b9565b925061024d60a089016101b9565b60c08901519092506001600160401b03811115610268575f80fd5b8801601f81018a13610278575f80fd5b80516001600160401b03811115610291576102916101d4565b604051600582901b90603f8201601f191681016001600160401b03811182821017156102bf576102bf6101d4565b60405291825260208184018101929081018d8411156102dc575f80fd5b6020850194505b83851015610302576102f4856101b9565b8152602094850194016102e3565b508094505050505092959891949750929550565b634e487b7160e01b5f52603260045260245ffd5b60805160a05160c05160e051610100516146176103f05f395f818161052f0152818161177501528181611bd901528181611ce60152611e1b01525f50505f8181610a7201528181610cb401528181611225015281816119c0015281816120ef0152818161217c0152818161245f01526124e701525f81816107b10152818161082501528181610ece0152610f4201525f81816109bd01528181610b51015281816110d9015281816111b80152818161191e01528181611a390152612ed801526146175ff3fe6080604052600436106100a8575f3560e01c80639573ea25116100625780639573ea251461017c5780639b60706a1461019b578063c11f5d5d146101ba578063c71aeca8146101d9578063d986b63b146101f8578063f86a8a5e14610217575f80fd5b80631bea8518146100b357806329fe3a5f146100e95780634b3fccaa146101165780635c82fd25146101375780638b3ad5b31461014a5780638d8078fc1461015d575f80fd5b366100af57005b5f80fd5b3480156100be575f80fd5b506100d26100cd366004613994565b610243565b6040516100e09291906139f2565b60405180910390f35b3480156100f4575f80fd5b50610108610103366004613a1b565b6104e1565b6040516100e0929190613a45565b348015610121575f80fd5b50610135610130366004613994565b61052d565b005b610135610145366004613be0565b610608565b610135610158366004613d00565b610d30565b348015610168575f80fd5b50610135610177366004613de4565b611262565b348015610187575f80fd5b50610135610196366004613e1a565b611773565b3480156101a6575f80fd5b506101356101b5366004613e51565b611832565b3480156101c5575f80fd5b506101356101d4366004613f33565b611bd7565b3480156101e4575f80fd5b506101356101f3366004613ff6565b611eed565b348015610203575f80fd5b5061013561021236600461404d565b612061565b348015610222575f80fd5b50600154610236906001600160a01b031681565b6040516100e0919061411b565b60605f826001600160a01b031663b4e0dc326040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156102a0575060408051601f3d908101601f1916820190925261029d9181019061412f565b60015b6102ab57505f6102ae565b90505b6102c0836001600160a01b031661257b565b91506001600160a01b0381161561043657600154604080516338d52e0f60e01b815290515f926001600160a01b0316916338d52e0f9160048083019260209291908290030181865afa158015610318573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061033c919061412f565b90505f826001600160a01b03166312edb24c6040518163ffffffff1660e01b81526004015f60405180830381865afa15801561037a573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526103a1919081019061414a565b90505f5b815181101561043257826001600160a01b03168282815181106103ca576103ca6141e3565b60200260200101516001600160a01b03161480156103f657506001546001600160a01b03878116911614155b61042a5761042682828151811061040f5761040f6141e3565b6020026020010151866125e990919063ffffffff16565b5094505b6001016103a5565b5050505b6001546001600160a01b0384811691161480159061045c57506001600160a01b03811615155b156104dc576104d8836001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104a0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104c4919061412f565b6001548491906001600160a01b03166126f6565b5091505b915091565b6060806104fa6040518060200160405280606081525090565b604080516020810190915260608152610516868684845f61293a565b81519350610522815190565b925050509250929050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610589573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105ad919061412f565b6001600160a01b0316336001600160a01b0316146105e65760405162461bcd60e51b81526004016105dd906141f7565b60405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b5f6106208260200151836101800151845f0151612eb6565b90505f82606001515f14610a3c576101a083015151156107a9575f80846101a00151806020019051810190610655919061422e565b915091505f846001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610686919061411b565b602060405180830381865afa1580156106a1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106c591906142ac565b9050816001600160a01b031663caaede783433866040518463ffffffff1660e01b81526004016106f69291906142f1565b5f604051808303818588803b15801561070d575f80fd5b505af115801561071f573d5f803e3d5ffd5b50506040516370a0823160e01b81528493506001600160a01b03891692506370a08231915061075290309060040161411b565b602060405180830381865afa15801561076d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061079191906142ac565b61079b9190614328565b6060870152506108b9915050565b341561089c577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316146108005760405162461bcd60e51b81526004016105dd9061433b565b826060015134146108235760405162461bcd60e51b81526004016105dd90614382565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db084606001516040518263ffffffff1660e01b81526004015f604051808303818588803b158015610880575f80fd5b505af1158015610892573d5f803e3d5ffd5b50505050506108b9565b60608301516108b9906001600160a01b0384169033903090613121565b602083015160608401516108d7916001600160a01b0385169161318c565b60208301516060840151604051636e553f6560e01b815260048101919091523060248201526001600160a01b0390911690636e553f65906044016020604051808303815f875af115801561092d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061095191906142ac565b90508261014001518110156109a85760405162461bcd60e51b815260206004820152601e60248201527f7368617265734d696e746564203c206d696e5368617265734d696e746564000060448201526064016105dd565b82602001516001600160a01b031663095ea7b37f0000000000000000000000000000000000000000000000000000000000000000836040518363ffffffff1660e01b81526004016109fa9291906143b4565b6020604051808303815f875af1158015610a16573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a3a91906143cd565b505b8260c00151158015610a51575060a083015115155b15610ad55760a0830151604051630d6a876d60e31b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001691636b543b6891610aa79133916004016143b4565b5f604051808303815f87803b158015610abe575f80fd5b505af1158015610ad0573d5f803e3d5ffd5b505050505b8251604080850151608086015160a087015160c088015160e08901516101008a01519551634f7f575960e11b81526001600160a01b039788166004820152336024820152604481019590955260648501889052608485019390935260a4840191909152151560c4830152831660e48201529082166101048201527f000000000000000000000000000000000000000000000000000000000000000090911690639efeaeb290610124015f604051808303815f87803b158015610b95575f80fd5b505af1158015610ba7573d5f803e3d5ffd5b5050505082608001515f14610c8e5782610120015115610c685760208301516080840151604051635d043b2960e11b81525f926001600160a01b03169163ba08765291610bfb9190339030906004016143e8565b6020604051808303815f875af1158015610c17573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c3b91906142ac565b9050836101600151811015610c625760405162461bcd60e51b81526004016105dd90614407565b50610c8e565b610c8e33846080015185602001516001600160a01b03166132269092919063ffffffff16565b8260c0015115610d2b5760a083015160405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163a9059cbb91610ce99133916004016143b4565b6020604051808303815f875af1158015610d05573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d2991906143cd565b505b505050565b5f610d488260200151836101000151845f0151612eb6565b9050816101200151515f14610ec6575f80836101200151806020019051810190610d72919061422e565b915091505f836001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610da3919061411b565b602060405180830381865afa158015610dbe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610de291906142ac565b9050816001600160a01b031663caaede783433866040518463ffffffff1660e01b8152600401610e139291906142f1565b5f604051808303818588803b158015610e2a575f80fd5b505af1158015610e3c573d5f803e3d5ffd5b50506040516370a0823160e01b81528493506001600160a01b03881692506370a082319150610e6f90309060040161411b565b602060405180830381865afa158015610e8a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eae91906142ac565b610eb89190614328565b608086015250610fd6915050565b3415610fb9577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b031614610f1d5760405162461bcd60e51b81526004016105dd9061433b565b81608001513414610f405760405162461bcd60e51b81526004016105dd90614382565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db083608001516040518263ffffffff1660e01b81526004015f604051808303818588803b158015610f9d575f80fd5b505af1158015610faf573d5f803e3d5ffd5b5050505050610fd6565b6080820151610fd6906001600160a01b0383169033903090613121565b60208201516080830151610ff4916001600160a01b0384169161318c565b60208201516080830151604051636e553f6560e01b815260048101919091523060248201525f916001600160a01b031690636e553f65906044016020604051808303815f875af115801561104a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061106e91906142ac565b90508260e001518110156110c45760405162461bcd60e51b815260206004820152601f60248201527f7368617265734d696e746564203c205f6d696e5368617265734d696e7465640060448201526064016105dd565b82602001516001600160a01b031663095ea7b37f0000000000000000000000000000000000000000000000000000000000000000836040518363ffffffff1660e01b81526004016111169291906143b4565b6020604051808303815f875af1158015611132573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061115691906143cd565b508251604080850151606086015160a087015160c088015193516326caa39d60e01b81526001600160a01b0395861660048201523360248201526044810193909352606483018690526084830191909152831660a482015290821660c48201527f0000000000000000000000000000000000000000000000000000000000000000909116906326caa39d9060e4015f604051808303815f87803b1580156111fb575f80fd5b505af115801561120d573d5f803e3d5ffd5b50505050606083015160405163a9059cbb60e01b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169163a9059cbb91610ce99133916004016143b4565b5f61127d6112766080840160608501613994565b83356104e1565b5080519091505f816001600160401b0381111561129c5761129c613a9d565b6040519080825280602002602001820160405280156112c5578160200160208202803683370190505b5090505f5b8281101561137b578381815181106112e4576112e46141e3565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401611317919061411b565b602060405180830381865afa158015611332573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061135691906142ac565b828281518110611368576113686141e3565b60209081029190910101526001016112ca565b5061138c6080850160608601613994565b604051635d043b2960e11b81526001600160a01b03919091169063ba087652906113bf90873590309033906004016143e8565b6020604051808303815f875af11580156113db573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113ff91906142ac565b505f61141160a0860160808701613994565b6001600160a01b03166370a0823161142f6040880160208901613994565b6040518263ffffffff1660e01b815260040161144b919061411b565b602060405180830381865afa158015611466573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061148a91906142ac565b90505f5b83811015611683575f8582815181106114a9576114a96141e3565b602002602001015190505f8483815181106114c6576114c66141e3565b6020026020010151826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016114fa919061411b565b602060405180830381865afa158015611515573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061153991906142ac565b6115439190614328565b905061155560a0890160808a01613994565b6001600160a01b0316826001600160a01b031614611655575f811180156115ab575061158460c089018961444c565b84818110611594576115946141e3565b90506020028101906115a69190614491565b151590505b15611650576115d46115c360608a0160408b01613994565b6001600160a01b038416908361318c565b6116505f6115e860608b0160408c01613994565b6115f560c08c018c61444c565b87818110611605576116056141e3565b90506020028101906116179190614491565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061324592505050565b611679565b61167961166860408a0160208b01613994565b6001600160a01b0384169083613226565b505060010161148e565b505f8161169660a0880160808901613994565b6001600160a01b03166370a082316116b460408a0160208b01613994565b6040518263ffffffff1660e01b81526004016116d0919061411b565b602060405180830381865afa1580156116eb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061170f91906142ac565b6117199190614328565b90508560a0013581101561176b5760405162461bcd60e51b8152602060048201526019602482015278125b9cdd59999a58da595b9d081d1bdad95b88185b5bdd5b9d603a1b60448201526064016105dd565b505050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117cf573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117f3919061412f565b6001600160a01b0316336001600160a01b0316146118235760405162461bcd60e51b81526004016105dd906141f7565b61182e5f8383613323565b5050565b61183d848387612eb6565b506040516370a0823160e01b81525f906001600160a01b038616906370a082319061186c90309060040161411b565b602060405180830381865afa158015611887573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118ab91906142ac565b90505f866001600160a01b031663eb7a7f7e336040518263ffffffff1660e01b81526004016118da919061411b565b6040805180830381865afa1580156118f4573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061191891906144d3565b9150505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634ba4a28b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611978573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061199c91906142ac565b6119a69083614328565b604051630d6a876d60e31b81529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636b543b68906119f790339085906004016143b4565b5f604051808303815f87803b158015611a0e575f80fd5b505af1158015611a20573d5f803e3d5ffd5b5050604051632fd0a10760e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016925063bf42841c9150611a72908b9033906004016144f5565b5f604051808303815f87803b158015611a89575f80fd5b505af1158015611a9b573d5f803e3d5ffd5b505050505f83886001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401611acd919061411b565b602060405180830381865afa158015611ae8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b0c91906142ac565b611b169190614328565b90508415611bb857604051635d043b2960e11b81525f906001600160a01b038a169063ba08765290611b50908590339030906004016143e8565b6020604051808303815f875af1158015611b6c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b9091906142ac565b905087811015611bb25760405162461bcd60e51b81526004016105dd90614407565b50611bcc565b611bcc6001600160a01b0389163383613226565b505050505050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c33573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c57919061412f565b6001600160a01b0316336001600160a01b031614611ca45760405162461bcd60e51b815260206004820152600a60248201526927b7363c9037bbb732b960b11b60448201526064016105dd565b5f5b8251811015610d2b5761dead6001600160a01b0316838281518110611ccd57611ccd6141e3565b60200260200101516001600160a01b031603611e16575f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d40573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d64919061412f565b6001600160a01b0316838381518110611d7f57611d7f6141e3565b60200260200101516040515f6040518083038185875af1925050503d805f8114611dc4576040519150601f19603f3d011682016040523d82523d5f602084013e611dc9565b606091505b5050905080611e105760405162461bcd60e51b8152602060048201526013602482015272115512081d1c985b9cd9995c8819985a5b1959606a1b60448201526064016105dd565b50611ee5565b611ee57f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e75573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e99919061412f565b838381518110611eab57611eab6141e3565b6020026020010151858481518110611ec557611ec56141e3565b60200260200101516001600160a01b03166132269092919063ffffffff16565b600101611ca6565b611ef8848387612eb6565b5060405163ec38a05d60e01b81525f906001600160a01b0387169063ec38a05d90611f2790339060040161411b565b602060405180830381865afa158015611f42573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f6691906142ac565b604051632b946eed60e11b81529091506001600160a01b03871690635728ddda90611f9790339030906004016144f5565b5f604051808303815f87803b158015611fae575f80fd5b505af1158015611fc0573d5f803e3d5ffd5b5050604051635d043b2960e11b81525f92506001600160a01b038816915063ba08765290611ff6908590899030906004016143e8565b6020604051808303815f875af1158015612012573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061203691906142ac565b9050828110156120585760405162461bcd60e51b81526004016105dd90614407565b50505050505050565b6120788160200151826101600151835f0151612eb6565b5060208101516040516370a0823160e01b81525f916001600160a01b0316906370a08231906120ab90309060040161411b565b602060405180830381865afa1580156120c6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120ea91906142ac565b90505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401612139919061411b565b602060405180830381865afa158015612154573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061217891906142ac565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636b543b683385604001516040518363ffffffff1660e01b81526004016121cc9291906143b4565b5f604051808303815f87803b1580156121e3575f80fd5b505af11580156121f5573d5f803e3d5ffd5b505084516040808701516060880151608089015160a08a015160c08b015160e08c01516101008d01519651635e69ba9360e11b815260048101969096526001600160a01b03948516602487015292841660448601529083166064850152608484015260a483015260c48201929092529116925063bcd37526915060e4015f604051808303815f87803b158015612289575f80fd5b505af115801561229b573d5f803e3d5ffd5b505050505f8284602001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016122d1919061411b565b602060405180830381865afa1580156122ec573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061231091906142ac565b61231a9190614328565b905083610120015181101561237f5760405162461bcd60e51b815260206004820152602560248201527f73686172657357697468647261776e203c205f6d696e53686172657357697468604482015264323930bbb760d91b60648201526084016105dd565b8361018001511561242d576020840151604051635d043b2960e11b81525f916001600160a01b03169063ba087652906123c0908590339030906004016143e8565b6020604051808303815f875af11580156123dc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061240091906142ac565b90508461014001518110156124275760405162461bcd60e51b81526004016105dd90614407565b50612446565b6020840151612446906001600160a01b03163383613226565b6040516370a0823160e01b81525f906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a082319061249490309060040161411b565b602060405180830381865afa1580156124af573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124d391906142ac565b905082811115612574576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663a9059cbb336125178685614328565b6040518363ffffffff1660e01b81526004016125349291906143b4565b6020604051808303815f875af1158015612550573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061176b91906143cd565b5050505050565b606080826001600160a01b031663aaffe0766040518163ffffffff1660e01b81526004015f60405180830381865afa9250505080156125db57506040513d5f823e601f3d908101601f191682016040526125d8919081019061414a565b60015b156125e35790505b92915050565b81516060905f90816125fb8686613380565b111561260b5784925090506126ef565b5f61261782600161450f565b6001600160401b0381111561262e5761262e613a9d565b604051908082528060200260200182016040528015612657578160200160208202803683370190505b5090505f5b828110156126b057868181518110612676576126766141e3565b6020026020010151828281518110612690576126906141e3565b6001600160a01b039092166020928302919091019091015260010161265c565b50848183815181106126c4576126c46141e3565b6001600160a01b0390921660209283029190910190910152806126e883600161450f565b9350935050505b9250929050565b60605f805f61270587876125e9565b915091505f6127148387613380565b9050805f0361272857509092509050612932565b856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612764573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612788919061412f565b83612794600184614328565b815181106127a4576127a46141e3565b60200260200101906001600160a01b031690816001600160a01b0316815250505f6127ce8761257b565b905080515f036127e5575091935091506129329050565b80515f6127f2828661450f565b6001600160401b0381111561280957612809613a9d565b604051908082528060200260200182016040528015612832578160200160208202803683370190505b5090505f805b868110156128c15761286385898381518110612856576128566141e3565b6020026020010151613380565b5f036128b95787818151811061287b5761287b6141e3565b6020026020010151838381518110612895576128956141e3565b6001600160a01b03909216602092830291909101909101526128b682614522565b91505b600101612838565b505f5b83811015612923578481815181106128de576128de6141e3565b60200260200101518383815181106128f8576128f86141e3565b6001600160a01b039092166020928302919091019091015261291982614522565b91506001016128c4565b50808252909750955050505050505b935093915050565b6129856040518060e001604052805f81526020015f81526020015f6001600160a01b031681526020015f6001600160a01b031681526020015f81526020015f81526020015f81525090565b856001600160a01b031663235c36036040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129c1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129e5919061453a565b61ffff1660c082015281612a7057612a61866001600160a01b0316631540aa896040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a32573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a56919061453a565b869061ffff166133e6565b612a6b9086614328565b612a72565b845b815f018181525050856001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ab6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ada91906142ac565b816020018181525050856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b1f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612b43919061412f565b6001600160a01b03908116604083015260015416612b61575f612bd5565b60015f9054906101000a90046001600160a01b03166001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612bb1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612bd5919061412f565b6001600160a01b031660608201525f80612bee88610243565b915091505f5b8251811015611bcc575f838281518110612c1057612c106141e3565b602002602001015190505f85606001516001600160a01b0316826001600160a01b03161490505f6001600160a01b0316846001600160a01b031614612da55760405163211dc32d60e01b81526001600160a01b0385169063211dc32d90612c7d908e9086906004016144f5565b602060405180830381865afa158015612c98573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612cbc91906142ac565b6080870152808015612cdc57506001546001600160a01b038c8116911614155b15612d6b57600154608087015160405163ef8b30f760e01b81526001600160a01b039092169163ef8b30f791612d189160040190815260200190565b602060405180830381865afa158015612d33573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d5791906142ac565b60808701526001546001600160a01b031691505b60c0860151608087015161271091612d829161455b565b612d8c9190614586565b86608001818151612d9d9190614328565b905250612dac565b5f60808701525b5f86608001518c6001600160a01b031663f8b2cb4f856040518263ffffffff1660e01b8152600401612dde919061411b565b602060405180830381865afa158015612df9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612e1d91906142ac565b612e27919061450f565b9050805f03612e3857505050612eae565b602087015187515f91612e4e91908490846133fd565b9050805f03612e605750505050612eae565b6001546001600160a01b0390811690851603612e9d57612e9860015f9054906101000a90046001600160a01b0316828d8d600161293a565b612ea9565b612ea984828d8d61345a565b505050505b600101612bf4565b60405163107233fb60e11b8152600481018390525f9081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906320e467f690602401602060405180830381865afa158015612f1d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f41919061412f565b9050826001600160a01b0316816001600160a01b031614612fa05760405162461bcd60e51b815260206004820152601960248201527824b731b7b93932b1ba102837b9b4ba34b7b726b0b730b3b2b960391b60448201526064016105dd565b612faa81866134c2565b612fed5760405162461bcd60e51b8152602060048201526014602482015273125b98dbdc9c9958dd0818dbdb1b185d195c985b60621b60448201526064016105dd565b846001600160a01b0316836001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015613033573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613057919061412f565b6001600160a01b0316146130b85760405162461bcd60e51b815260206004820152602260248201527f496e636f727265637420506f736974696f6e4d616e61676572206f72205661756044820152611b1d60f21b60648201526084016105dd565b846001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613118919061412f565b95945050505050565b6040516001600160a01b0380851660248301528316604482015260648101829052610d299085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261353e565b5f81846001600160a01b031663dd62ed3e30866040518363ffffffff1660e01b81526004016131bc9291906144f5565b602060405180830381865afa1580156131d7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131fb91906142ac565b613205919061450f565b9050610d298463095ea7b360e01b85846040516024016131559291906143b4565b610d2b8363a9059cbb60e01b84846040516024016131559291906143b4565b6001600160a01b0382165f9081526020849052604090205460ff166132b85760405162461bcd60e51b8152602060048201526024808201527f53776170706572734c69623a2073776170706572206e6f742077686974656c696044820152631cdd195960e21b60648201526084016105dd565b5f80836001600160a01b0316836040516132d291906145a5565b5f604051808303815f865af19150503d805f811461330b576040519150601f19603f3d011682016040523d82523d5f602084013e613310565b606091505b509150915081612574576125748161360f565b6001600160a01b0382165f8181526020858152604091829020805460ff191685151590811790915591519182527f7dc49220c17ba736a5a8f465c46784ed2262884e4ea605ae95e6fd117a77a421910160405180910390a2505050565b81515f90815b818110156133dc57836001600160a01b03168582815181106133aa576133aa6141e3565b60200260200101516001600160a01b0316036133d4576133cb81600161450f565b925050506125e3565b600101613386565b505f949350505050565b5f6133f6838361271060016133fd565b9392505050565b5f8061340a868686613617565b90506001836002811115613420576134206145bb565b14801561343c57505f848061343757613437614572565b868809115b1561344f5761344c60018261450f565b90505b90505b949350505050565b5f61346583866136bf565b90505f1981146134ad578151600582901b01602001516134a682613489878461450f565b60408051606081529052855160059290921b909101602001528390565b5050612574565b6134b783866136d7565b5061176b82856136f2565b5f816001600160a01b0316836001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015613509573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061352d919061412f565b6001600160a01b0316149392505050565b5f613592826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661379d9092919063ffffffff16565b805190915015610d2b57808060200190518101906135b091906143cd565b610d2b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016105dd565b805160208201fd5b5f80805f19858709858702925082811083820303915050805f0361364e5783828161364457613644614572565b04925050506133f6565b808411613659575f80fd5b5f84868809600260036001881981018916988990049182028318808302840302808302840302808302840302808302840302808302840302918202909203025f889003889004909101858311909403939093029303949094049190911702949350505050565b5f6133f6835f0151836001600160a01b03165f6137ab565b6040805160608152908190526133f683836001600160a01b03165b604080516060815290819052829050825160018151018060051b661d174b32e2c55360208403518181061582820402905080831061378c57828117810160608614826020018701604051181761375857828102601f19870152850160200160405261378c565b602060405101816020018101604052808a52601f19855b888101518382015281018061376f57509184029181019190915294505b505082019390935291909152919050565b606061345284845f856137f9565b82515f19908210156133f6578160051b840184855160010160051b0180518582525b602083019250858351036137cd5781528181146137f05785602001820360051c92505b50509392505050565b60608247101561385a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016105dd565b5f80866001600160a01b0316858760405161387591906145a5565b5f6040518083038185875af1925050503d805f81146138af576040519150601f19603f3d011682016040523d82523d5f602084013e6138b4565b606091505b50915091506138c5878383876138d0565b979650505050505050565b6060831561393e5782515f03613937576001600160a01b0385163b6139375760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105dd565b5081613452565b61345283838151156139535781518083602001fd5b8060405162461bcd60e51b81526004016105dd91906145cf565b6001600160a01b0381168114613981575f80fd5b50565b803561398f8161396d565b919050565b5f602082840312156139a4575f80fd5b81356133f68161396d565b5f8151808452602084019350602083015f5b828110156139e85781516001600160a01b03168652602095860195909101906001016139c1565b5093949350505050565b604081525f613a0460408301856139af565b905060018060a01b03831660208301529392505050565b5f8060408385031215613a2c575f80fd5b8235613a378161396d565b946020939093013593505050565b604081525f613a5760408301856139af565b82810360208401528084518083526020830191506020860192505f5b81811015613a91578351835260209384019390920191600101613a73565b50909695505050505050565b634e487b7160e01b5f52604160045260245ffd5b6040516101c081016001600160401b0381118282101715613ad457613ad4613a9d565b60405290565b60405161014081016001600160401b0381118282101715613ad457613ad4613a9d565b6040516101a081016001600160401b0381118282101715613ad457613ad4613a9d565b604051601f8201601f191681016001600160401b0381118282101715613b4857613b48613a9d565b604052919050565b8015158114613981575f80fd5b803561398f81613b50565b5f6001600160401b03821115613b8057613b80613a9d565b50601f01601f191660200190565b5f82601f830112613b9d575f80fd5b8135613bb0613bab82613b68565b613b20565b818152846020838601011115613bc4575f80fd5b816020850160208301375f918101602001919091529392505050565b5f60208284031215613bf0575f80fd5b81356001600160401b03811115613c05575f80fd5b82016101c08185031215613c17575f80fd5b613c1f613ab1565b613c2882613984565b8152613c3660208301613984565b602082015260408281013590820152606080830135908201526080808301359082015260a08083013590820152613c6f60c08301613b5d565b60c0820152613c8060e08301613984565b60e0820152613c926101008301613984565b610100820152613ca56101208301613b5d565b6101208201526101408281013590820152610160808301359082015261018080830135908201526101a08201356001600160401b03811115613ce5575f80fd5b613cf186828501613b8e565b6101a083015250949350505050565b5f60208284031215613d10575f80fd5b81356001600160401b03811115613d25575f80fd5b82016101408185031215613d37575f80fd5b613d3f613ada565b613d4882613984565b8152613d5660208301613984565b6020820152604082810135908201526060808301359082015260808083013590820152613d8560a08301613984565b60a0820152613d9660c08301613984565b60c082015260e0828101359082015261010080830135908201526101208201356001600160401b03811115613dc9575f80fd5b613dd586828501613b8e565b61012083015250949350505050565b5f60208284031215613df4575f80fd5b81356001600160401b03811115613e09575f80fd5b820160e081850312156133f6575f80fd5b5f8060408385031215613e2b575f80fd5b8235613e368161396d565b91506020830135613e4681613b50565b809150509250929050565b5f805f805f60a08688031215613e65575f80fd5b8535613e708161396d565b94506020860135613e808161396d565b935060408601359250606086013591506080860135613e9e81613b50565b809150509295509295909350565b5f6001600160401b03821115613ec457613ec4613a9d565b5060051b60200190565b5f82601f830112613edd575f80fd5b8135613eeb613bab82613eac565b8082825260208201915060208360051b860101925085831115613f0c575f80fd5b602085015b83811015613f29578035835260209283019201613f11565b5095945050505050565b5f8060408385031215613f44575f80fd5b82356001600160401b03811115613f59575f80fd5b8301601f81018513613f69575f80fd5b8035613f77613bab82613eac565b8082825260208201915060208360051b850101925087831115613f98575f80fd5b6020840193505b82841015613fc3578335613fb28161396d565b825260209384019390910190613f9f565b945050505060208301356001600160401b03811115613fe0575f80fd5b613fec85828601613ece565b9150509250929050565b5f805f805f60a0868803121561400a575f80fd5b85356140158161396d565b945060208601356140258161396d565b935060408601356140358161396d565b94979396509394606081013594506080013592915050565b5f6101a082840312801561405f575f80fd5b50614068613afd565b61407183613984565b815261407f60208401613984565b60208201526040838101359082015261409a60608401613984565b60608201526140ab60808401613984565b60808201526140bc60a08401613984565b60a082015260c0838101359082015260e08084013590820152610100808401359082015261012080840135908201526101408084013590820152610160808401359082015261410e6101808401613b5d565b6101808201529392505050565b6001600160a01b0391909116815260200190565b5f6020828403121561413f575f80fd5b81516133f68161396d565b5f6020828403121561415a575f80fd5b81516001600160401b0381111561416f575f80fd5b8201601f8101841361417f575f80fd5b805161418d613bab82613eac565b8082825260208201915060208360051b8501019250868311156141ae575f80fd5b6020840193505b828410156141d95783516141c88161396d565b8252602093840193909101906141b5565b9695505050505050565b634e487b7160e01b5f52603260045260245ffd5b6020808252601b908201527f436f6c6c5661756c74526f757465723a204f6e6c79206f776e65720000000000604082015260600190565b5f806040838503121561423f575f80fd5b82516001600160401b03811115614254575f80fd5b8301601f81018513614264575f80fd5b8051614272613bab82613b68565b818152866020838501011115614286575f80fd5b8160208401602083015e5f602083830101528094505050506020830151613e468161396d565b5f602082840312156142bc575f80fd5b5051919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03831681526040602082018190525f90613452908301846142c3565b634e487b7160e01b5f52601160045260245ffd5b818103818111156125e3576125e3614314565b60208082526027908201527f506173736564206d73672e76616c75652077697468206e6f6e2d574e4154495660408201526611481d985d5b1d60ca1b606082015260800190565b6020808252601890820152771b5cd9cb9d985b1d5948084f4817d8dbdb1b105b5bdd5b9d60421b604082015260600190565b6001600160a01b03929092168252602082015260400190565b5f602082840312156143dd575f80fd5b81516133f681613b50565b9283526001600160a01b03918216602084015216604082015260600190565b60208082526025908201527f61737365747357697468647261776e203c205f6d696e41737365747357697468604082015264323930bbb760d91b606082015260800190565b5f808335601e19843603018112614461575f80fd5b8301803591506001600160401b0382111561447a575f80fd5b6020019150600581901b36038213156126ef575f80fd5b5f808335601e198436030181126144a6575f80fd5b8301803591506001600160401b038211156144bf575f80fd5b6020019150368190038213156126ef575f80fd5b5f80604083850312156144e4575f80fd5b505080516020909101519092909150565b6001600160a01b0392831681529116602082015260400190565b808201808211156125e3576125e3614314565b5f6001820161453357614533614314565b5060010190565b5f6020828403121561454a575f80fd5b815161ffff811681146133f6575f80fd5b80820281158282048414176125e3576125e3614314565b634e487b7160e01b5f52601260045260245ffd5b5f826145a057634e487b7160e01b5f52601260045260245ffd5b500490565b5f82518060208501845e5f920191825250919050565b634e487b7160e01b5f52602160045260245ffd5b602081525f6133f660208301846142c356fea26469706673582212205f463df5512cddea7fdf3de508dfab8679d51214ece0d24663a2762d6ebe00e764736f6c634300081a003300000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd4000000000000000000000000ee7d8bcfb72bc1880d0cf19822eb0a2e6577ab620000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f000000000000000000000000b86ea1873bd4c7dd3525b8ea623516b5cba4eb920000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ac4c6e212a361c968f1725b4d055b47e63f80b75
Deployed Bytecode
0x6080604052600436106100a8575f3560e01c80639573ea25116100625780639573ea251461017c5780639b60706a1461019b578063c11f5d5d146101ba578063c71aeca8146101d9578063d986b63b146101f8578063f86a8a5e14610217575f80fd5b80631bea8518146100b357806329fe3a5f146100e95780634b3fccaa146101165780635c82fd25146101375780638b3ad5b31461014a5780638d8078fc1461015d575f80fd5b366100af57005b5f80fd5b3480156100be575f80fd5b506100d26100cd366004613994565b610243565b6040516100e09291906139f2565b60405180910390f35b3480156100f4575f80fd5b50610108610103366004613a1b565b6104e1565b6040516100e0929190613a45565b348015610121575f80fd5b50610135610130366004613994565b61052d565b005b610135610145366004613be0565b610608565b610135610158366004613d00565b610d30565b348015610168575f80fd5b50610135610177366004613de4565b611262565b348015610187575f80fd5b50610135610196366004613e1a565b611773565b3480156101a6575f80fd5b506101356101b5366004613e51565b611832565b3480156101c5575f80fd5b506101356101d4366004613f33565b611bd7565b3480156101e4575f80fd5b506101356101f3366004613ff6565b611eed565b348015610203575f80fd5b5061013561021236600461404d565b612061565b348015610222575f80fd5b50600154610236906001600160a01b031681565b6040516100e0919061411b565b60605f826001600160a01b031663b4e0dc326040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156102a0575060408051601f3d908101601f1916820190925261029d9181019061412f565b60015b6102ab57505f6102ae565b90505b6102c0836001600160a01b031661257b565b91506001600160a01b0381161561043657600154604080516338d52e0f60e01b815290515f926001600160a01b0316916338d52e0f9160048083019260209291908290030181865afa158015610318573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061033c919061412f565b90505f826001600160a01b03166312edb24c6040518163ffffffff1660e01b81526004015f60405180830381865afa15801561037a573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526103a1919081019061414a565b90505f5b815181101561043257826001600160a01b03168282815181106103ca576103ca6141e3565b60200260200101516001600160a01b03161480156103f657506001546001600160a01b03878116911614155b61042a5761042682828151811061040f5761040f6141e3565b6020026020010151866125e990919063ffffffff16565b5094505b6001016103a5565b5050505b6001546001600160a01b0384811691161480159061045c57506001600160a01b03811615155b156104dc576104d8836001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104a0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104c4919061412f565b6001548491906001600160a01b03166126f6565b5091505b915091565b6060806104fa6040518060200160405280606081525090565b604080516020810190915260608152610516868684845f61293a565b81519350610522815190565b925050509250929050565b7f0000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce86001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610589573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105ad919061412f565b6001600160a01b0316336001600160a01b0316146105e65760405162461bcd60e51b81526004016105dd906141f7565b60405180910390fd5b600180546001600160a01b0319166001600160a01b0392909216919091179055565b5f6106208260200151836101800151845f0151612eb6565b90505f82606001515f14610a3c576101a083015151156107a9575f80846101a00151806020019051810190610655919061422e565b915091505f846001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610686919061411b565b602060405180830381865afa1580156106a1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106c591906142ac565b9050816001600160a01b031663caaede783433866040518463ffffffff1660e01b81526004016106f69291906142f1565b5f604051808303818588803b15801561070d575f80fd5b505af115801561071f573d5f803e3d5ffd5b50506040516370a0823160e01b81528493506001600160a01b03891692506370a08231915061075290309060040161411b565b602060405180830381865afa15801561076d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061079191906142ac565b61079b9190614328565b6060870152506108b9915050565b341561089c577f000000000000000000000000ee7d8bcfb72bc1880d0cf19822eb0a2e6577ab626001600160a01b0316826001600160a01b0316146108005760405162461bcd60e51b81526004016105dd9061433b565b826060015134146108235760405162461bcd60e51b81526004016105dd90614382565b7f000000000000000000000000ee7d8bcfb72bc1880d0cf19822eb0a2e6577ab626001600160a01b031663d0e30db084606001516040518263ffffffff1660e01b81526004015f604051808303818588803b158015610880575f80fd5b505af1158015610892573d5f803e3d5ffd5b50505050506108b9565b60608301516108b9906001600160a01b0384169033903090613121565b602083015160608401516108d7916001600160a01b0385169161318c565b60208301516060840151604051636e553f6560e01b815260048101919091523060248201526001600160a01b0390911690636e553f65906044016020604051808303815f875af115801561092d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061095191906142ac565b90508261014001518110156109a85760405162461bcd60e51b815260206004820152601e60248201527f7368617265734d696e746564203c206d696e5368617265734d696e746564000060448201526064016105dd565b82602001516001600160a01b031663095ea7b37f00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd4836040518363ffffffff1660e01b81526004016109fa9291906143b4565b6020604051808303815f875af1158015610a16573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a3a91906143cd565b505b8260c00151158015610a51575060a083015115155b15610ad55760a0830151604051630d6a876d60e31b81526001600160a01b037f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f1691636b543b6891610aa79133916004016143b4565b5f604051808303815f87803b158015610abe575f80fd5b505af1158015610ad0573d5f803e3d5ffd5b505050505b8251604080850151608086015160a087015160c088015160e08901516101008a01519551634f7f575960e11b81526001600160a01b039788166004820152336024820152604481019590955260648501889052608485019390935260a4840191909152151560c4830152831660e48201529082166101048201527f00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd490911690639efeaeb290610124015f604051808303815f87803b158015610b95575f80fd5b505af1158015610ba7573d5f803e3d5ffd5b5050505082608001515f14610c8e5782610120015115610c685760208301516080840151604051635d043b2960e11b81525f926001600160a01b03169163ba08765291610bfb9190339030906004016143e8565b6020604051808303815f875af1158015610c17573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c3b91906142ac565b9050836101600151811015610c625760405162461bcd60e51b81526004016105dd90614407565b50610c8e565b610c8e33846080015185602001516001600160a01b03166132269092919063ffffffff16565b8260c0015115610d2b5760a083015160405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f169163a9059cbb91610ce99133916004016143b4565b6020604051808303815f875af1158015610d05573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d2991906143cd565b505b505050565b5f610d488260200151836101000151845f0151612eb6565b9050816101200151515f14610ec6575f80836101200151806020019051810190610d72919061422e565b915091505f836001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401610da3919061411b565b602060405180830381865afa158015610dbe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610de291906142ac565b9050816001600160a01b031663caaede783433866040518463ffffffff1660e01b8152600401610e139291906142f1565b5f604051808303818588803b158015610e2a575f80fd5b505af1158015610e3c573d5f803e3d5ffd5b50506040516370a0823160e01b81528493506001600160a01b03881692506370a082319150610e6f90309060040161411b565b602060405180830381865afa158015610e8a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eae91906142ac565b610eb89190614328565b608086015250610fd6915050565b3415610fb9577f000000000000000000000000ee7d8bcfb72bc1880d0cf19822eb0a2e6577ab626001600160a01b0316816001600160a01b031614610f1d5760405162461bcd60e51b81526004016105dd9061433b565b81608001513414610f405760405162461bcd60e51b81526004016105dd90614382565b7f000000000000000000000000ee7d8bcfb72bc1880d0cf19822eb0a2e6577ab626001600160a01b031663d0e30db083608001516040518263ffffffff1660e01b81526004015f604051808303818588803b158015610f9d575f80fd5b505af1158015610faf573d5f803e3d5ffd5b5050505050610fd6565b6080820151610fd6906001600160a01b0383169033903090613121565b60208201516080830151610ff4916001600160a01b0384169161318c565b60208201516080830151604051636e553f6560e01b815260048101919091523060248201525f916001600160a01b031690636e553f65906044016020604051808303815f875af115801561104a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061106e91906142ac565b90508260e001518110156110c45760405162461bcd60e51b815260206004820152601f60248201527f7368617265734d696e746564203c205f6d696e5368617265734d696e7465640060448201526064016105dd565b82602001516001600160a01b031663095ea7b37f00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd4836040518363ffffffff1660e01b81526004016111169291906143b4565b6020604051808303815f875af1158015611132573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061115691906143cd565b508251604080850151606086015160a087015160c088015193516326caa39d60e01b81526001600160a01b0395861660048201523360248201526044810193909352606483018690526084830191909152831660a482015290821660c48201527f00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd4909116906326caa39d9060e4015f604051808303815f87803b1580156111fb575f80fd5b505af115801561120d573d5f803e3d5ffd5b50505050606083015160405163a9059cbb60e01b81527f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f6001600160a01b03169163a9059cbb91610ce99133916004016143b4565b5f61127d6112766080840160608501613994565b83356104e1565b5080519091505f816001600160401b0381111561129c5761129c613a9d565b6040519080825280602002602001820160405280156112c5578160200160208202803683370190505b5090505f5b8281101561137b578381815181106112e4576112e46141e3565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401611317919061411b565b602060405180830381865afa158015611332573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061135691906142ac565b828281518110611368576113686141e3565b60209081029190910101526001016112ca565b5061138c6080850160608601613994565b604051635d043b2960e11b81526001600160a01b03919091169063ba087652906113bf90873590309033906004016143e8565b6020604051808303815f875af11580156113db573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113ff91906142ac565b505f61141160a0860160808701613994565b6001600160a01b03166370a0823161142f6040880160208901613994565b6040518263ffffffff1660e01b815260040161144b919061411b565b602060405180830381865afa158015611466573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061148a91906142ac565b90505f5b83811015611683575f8582815181106114a9576114a96141e3565b602002602001015190505f8483815181106114c6576114c66141e3565b6020026020010151826001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016114fa919061411b565b602060405180830381865afa158015611515573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061153991906142ac565b6115439190614328565b905061155560a0890160808a01613994565b6001600160a01b0316826001600160a01b031614611655575f811180156115ab575061158460c089018961444c565b84818110611594576115946141e3565b90506020028101906115a69190614491565b151590505b15611650576115d46115c360608a0160408b01613994565b6001600160a01b038416908361318c565b6116505f6115e860608b0160408c01613994565b6115f560c08c018c61444c565b87818110611605576116056141e3565b90506020028101906116179190614491565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061324592505050565b611679565b61167961166860408a0160208b01613994565b6001600160a01b0384169083613226565b505060010161148e565b505f8161169660a0880160808901613994565b6001600160a01b03166370a082316116b460408a0160208b01613994565b6040518263ffffffff1660e01b81526004016116d0919061411b565b602060405180830381865afa1580156116eb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061170f91906142ac565b6117199190614328565b90508560a0013581101561176b5760405162461bcd60e51b8152602060048201526019602482015278125b9cdd59999a58da595b9d081d1bdad95b88185b5bdd5b9d603a1b60448201526064016105dd565b505050505050565b7f0000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce86001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117cf573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117f3919061412f565b6001600160a01b0316336001600160a01b0316146118235760405162461bcd60e51b81526004016105dd906141f7565b61182e5f8383613323565b5050565b61183d848387612eb6565b506040516370a0823160e01b81525f906001600160a01b038616906370a082319061186c90309060040161411b565b602060405180830381865afa158015611887573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118ab91906142ac565b90505f866001600160a01b031663eb7a7f7e336040518263ffffffff1660e01b81526004016118da919061411b565b6040805180830381865afa1580156118f4573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061191891906144d3565b9150505f7f00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd46001600160a01b0316634ba4a28b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611978573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061199c91906142ac565b6119a69083614328565b604051630d6a876d60e31b81529091506001600160a01b037f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f1690636b543b68906119f790339085906004016143b4565b5f604051808303815f87803b158015611a0e575f80fd5b505af1158015611a20573d5f803e3d5ffd5b5050604051632fd0a10760e21b81526001600160a01b037f00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd416925063bf42841c9150611a72908b9033906004016144f5565b5f604051808303815f87803b158015611a89575f80fd5b505af1158015611a9b573d5f803e3d5ffd5b505050505f83886001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401611acd919061411b565b602060405180830381865afa158015611ae8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b0c91906142ac565b611b169190614328565b90508415611bb857604051635d043b2960e11b81525f906001600160a01b038a169063ba08765290611b50908590339030906004016143e8565b6020604051808303815f875af1158015611b6c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b9091906142ac565b905087811015611bb25760405162461bcd60e51b81526004016105dd90614407565b50611bcc565b611bcc6001600160a01b0389163383613226565b505050505050505050565b7f0000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce86001600160a01b0316638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c33573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c57919061412f565b6001600160a01b0316336001600160a01b031614611ca45760405162461bcd60e51b815260206004820152600a60248201526927b7363c9037bbb732b960b11b60448201526064016105dd565b5f5b8251811015610d2b5761dead6001600160a01b0316838281518110611ccd57611ccd6141e3565b60200260200101516001600160a01b031603611e16575f7f0000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce86001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d40573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d64919061412f565b6001600160a01b0316838381518110611d7f57611d7f6141e3565b60200260200101516040515f6040518083038185875af1925050503d805f8114611dc4576040519150601f19603f3d011682016040523d82523d5f602084013e611dc9565b606091505b5050905080611e105760405162461bcd60e51b8152602060048201526013602482015272115512081d1c985b9cd9995c8819985a5b1959606a1b60448201526064016105dd565b50611ee5565b611ee57f0000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce86001600160a01b031663b3f006746040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e75573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e99919061412f565b838381518110611eab57611eab6141e3565b6020026020010151858481518110611ec557611ec56141e3565b60200260200101516001600160a01b03166132269092919063ffffffff16565b600101611ca6565b611ef8848387612eb6565b5060405163ec38a05d60e01b81525f906001600160a01b0387169063ec38a05d90611f2790339060040161411b565b602060405180830381865afa158015611f42573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f6691906142ac565b604051632b946eed60e11b81529091506001600160a01b03871690635728ddda90611f9790339030906004016144f5565b5f604051808303815f87803b158015611fae575f80fd5b505af1158015611fc0573d5f803e3d5ffd5b5050604051635d043b2960e11b81525f92506001600160a01b038816915063ba08765290611ff6908590899030906004016143e8565b6020604051808303815f875af1158015612012573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061203691906142ac565b9050828110156120585760405162461bcd60e51b81526004016105dd90614407565b50505050505050565b6120788160200151826101600151835f0151612eb6565b5060208101516040516370a0823160e01b81525f916001600160a01b0316906370a08231906120ab90309060040161411b565b602060405180830381865afa1580156120c6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906120ea91906142ac565b90505f7f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f6001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401612139919061411b565b602060405180830381865afa158015612154573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061217891906142ac565b90507f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f6001600160a01b0316636b543b683385604001516040518363ffffffff1660e01b81526004016121cc9291906143b4565b5f604051808303815f87803b1580156121e3575f80fd5b505af11580156121f5573d5f803e3d5ffd5b505084516040808701516060880151608089015160a08a015160c08b015160e08c01516101008d01519651635e69ba9360e11b815260048101969096526001600160a01b03948516602487015292841660448601529083166064850152608484015260a483015260c48201929092529116925063bcd37526915060e4015f604051808303815f87803b158015612289575f80fd5b505af115801561229b573d5f803e3d5ffd5b505050505f8284602001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016122d1919061411b565b602060405180830381865afa1580156122ec573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061231091906142ac565b61231a9190614328565b905083610120015181101561237f5760405162461bcd60e51b815260206004820152602560248201527f73686172657357697468647261776e203c205f6d696e53686172657357697468604482015264323930bbb760d91b60648201526084016105dd565b8361018001511561242d576020840151604051635d043b2960e11b81525f916001600160a01b03169063ba087652906123c0908590339030906004016143e8565b6020604051808303815f875af11580156123dc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061240091906142ac565b90508461014001518110156124275760405162461bcd60e51b81526004016105dd90614407565b50612446565b6020840151612446906001600160a01b03163383613226565b6040516370a0823160e01b81525f906001600160a01b037f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f16906370a082319061249490309060040161411b565b602060405180830381865afa1580156124af573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906124d391906142ac565b905082811115612574576001600160a01b037f0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f1663a9059cbb336125178685614328565b6040518363ffffffff1660e01b81526004016125349291906143b4565b6020604051808303815f875af1158015612550573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061176b91906143cd565b5050505050565b606080826001600160a01b031663aaffe0766040518163ffffffff1660e01b81526004015f60405180830381865afa9250505080156125db57506040513d5f823e601f3d908101601f191682016040526125d8919081019061414a565b60015b156125e35790505b92915050565b81516060905f90816125fb8686613380565b111561260b5784925090506126ef565b5f61261782600161450f565b6001600160401b0381111561262e5761262e613a9d565b604051908082528060200260200182016040528015612657578160200160208202803683370190505b5090505f5b828110156126b057868181518110612676576126766141e3565b6020026020010151828281518110612690576126906141e3565b6001600160a01b039092166020928302919091019091015260010161265c565b50848183815181106126c4576126c46141e3565b6001600160a01b0390921660209283029190910190910152806126e883600161450f565b9350935050505b9250929050565b60605f805f61270587876125e9565b915091505f6127148387613380565b9050805f0361272857509092509050612932565b856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612764573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612788919061412f565b83612794600184614328565b815181106127a4576127a46141e3565b60200260200101906001600160a01b031690816001600160a01b0316815250505f6127ce8761257b565b905080515f036127e5575091935091506129329050565b80515f6127f2828661450f565b6001600160401b0381111561280957612809613a9d565b604051908082528060200260200182016040528015612832578160200160208202803683370190505b5090505f805b868110156128c15761286385898381518110612856576128566141e3565b6020026020010151613380565b5f036128b95787818151811061287b5761287b6141e3565b6020026020010151838381518110612895576128956141e3565b6001600160a01b03909216602092830291909101909101526128b682614522565b91505b600101612838565b505f5b83811015612923578481815181106128de576128de6141e3565b60200260200101518383815181106128f8576128f86141e3565b6001600160a01b039092166020928302919091019091015261291982614522565b91506001016128c4565b50808252909750955050505050505b935093915050565b6129856040518060e001604052805f81526020015f81526020015f6001600160a01b031681526020015f6001600160a01b031681526020015f81526020015f81526020015f81525090565b856001600160a01b031663235c36036040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129c1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129e5919061453a565b61ffff1660c082015281612a7057612a61866001600160a01b0316631540aa896040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a32573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a56919061453a565b869061ffff166133e6565b612a6b9086614328565b612a72565b845b815f018181525050856001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612ab6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612ada91906142ac565b816020018181525050856001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b1f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612b43919061412f565b6001600160a01b03908116604083015260015416612b61575f612bd5565b60015f9054906101000a90046001600160a01b03166001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612bb1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612bd5919061412f565b6001600160a01b031660608201525f80612bee88610243565b915091505f5b8251811015611bcc575f838281518110612c1057612c106141e3565b602002602001015190505f85606001516001600160a01b0316826001600160a01b03161490505f6001600160a01b0316846001600160a01b031614612da55760405163211dc32d60e01b81526001600160a01b0385169063211dc32d90612c7d908e9086906004016144f5565b602060405180830381865afa158015612c98573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612cbc91906142ac565b6080870152808015612cdc57506001546001600160a01b038c8116911614155b15612d6b57600154608087015160405163ef8b30f760e01b81526001600160a01b039092169163ef8b30f791612d189160040190815260200190565b602060405180830381865afa158015612d33573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612d5791906142ac565b60808701526001546001600160a01b031691505b60c0860151608087015161271091612d829161455b565b612d8c9190614586565b86608001818151612d9d9190614328565b905250612dac565b5f60808701525b5f86608001518c6001600160a01b031663f8b2cb4f856040518263ffffffff1660e01b8152600401612dde919061411b565b602060405180830381865afa158015612df9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612e1d91906142ac565b612e27919061450f565b9050805f03612e3857505050612eae565b602087015187515f91612e4e91908490846133fd565b9050805f03612e605750505050612eae565b6001546001600160a01b0390811690851603612e9d57612e9860015f9054906101000a90046001600160a01b0316828d8d600161293a565b612ea9565b612ea984828d8d61345a565b505050505b600101612bf4565b60405163107233fb60e11b8152600481018390525f9081906001600160a01b037f00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd416906320e467f690602401602060405180830381865afa158015612f1d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f41919061412f565b9050826001600160a01b0316816001600160a01b031614612fa05760405162461bcd60e51b815260206004820152601960248201527824b731b7b93932b1ba102837b9b4ba34b7b726b0b730b3b2b960391b60448201526064016105dd565b612faa81866134c2565b612fed5760405162461bcd60e51b8152602060048201526014602482015273125b98dbdc9c9958dd0818dbdb1b185d195c985b60621b60448201526064016105dd565b846001600160a01b0316836001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015613033573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613057919061412f565b6001600160a01b0316146130b85760405162461bcd60e51b815260206004820152602260248201527f496e636f727265637420506f736974696f6e4d616e61676572206f72205661756044820152611b1d60f21b60648201526084016105dd565b846001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613118919061412f565b95945050505050565b6040516001600160a01b0380851660248301528316604482015260648101829052610d299085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261353e565b5f81846001600160a01b031663dd62ed3e30866040518363ffffffff1660e01b81526004016131bc9291906144f5565b602060405180830381865afa1580156131d7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131fb91906142ac565b613205919061450f565b9050610d298463095ea7b360e01b85846040516024016131559291906143b4565b610d2b8363a9059cbb60e01b84846040516024016131559291906143b4565b6001600160a01b0382165f9081526020849052604090205460ff166132b85760405162461bcd60e51b8152602060048201526024808201527f53776170706572734c69623a2073776170706572206e6f742077686974656c696044820152631cdd195960e21b60648201526084016105dd565b5f80836001600160a01b0316836040516132d291906145a5565b5f604051808303815f865af19150503d805f811461330b576040519150601f19603f3d011682016040523d82523d5f602084013e613310565b606091505b509150915081612574576125748161360f565b6001600160a01b0382165f8181526020858152604091829020805460ff191685151590811790915591519182527f7dc49220c17ba736a5a8f465c46784ed2262884e4ea605ae95e6fd117a77a421910160405180910390a2505050565b81515f90815b818110156133dc57836001600160a01b03168582815181106133aa576133aa6141e3565b60200260200101516001600160a01b0316036133d4576133cb81600161450f565b925050506125e3565b600101613386565b505f949350505050565b5f6133f6838361271060016133fd565b9392505050565b5f8061340a868686613617565b90506001836002811115613420576134206145bb565b14801561343c57505f848061343757613437614572565b868809115b1561344f5761344c60018261450f565b90505b90505b949350505050565b5f61346583866136bf565b90505f1981146134ad578151600582901b01602001516134a682613489878461450f565b60408051606081529052855160059290921b909101602001528390565b5050612574565b6134b783866136d7565b5061176b82856136f2565b5f816001600160a01b0316836001600160a01b031663b2016bd46040518163ffffffff1660e01b8152600401602060405180830381865afa158015613509573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061352d919061412f565b6001600160a01b0316149392505050565b5f613592826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661379d9092919063ffffffff16565b805190915015610d2b57808060200190518101906135b091906143cd565b610d2b5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016105dd565b805160208201fd5b5f80805f19858709858702925082811083820303915050805f0361364e5783828161364457613644614572565b04925050506133f6565b808411613659575f80fd5b5f84868809600260036001881981018916988990049182028318808302840302808302840302808302840302808302840302808302840302918202909203025f889003889004909101858311909403939093029303949094049190911702949350505050565b5f6133f6835f0151836001600160a01b03165f6137ab565b6040805160608152908190526133f683836001600160a01b03165b604080516060815290819052829050825160018151018060051b661d174b32e2c55360208403518181061582820402905080831061378c57828117810160608614826020018701604051181761375857828102601f19870152850160200160405261378c565b602060405101816020018101604052808a52601f19855b888101518382015281018061376f57509184029181019190915294505b505082019390935291909152919050565b606061345284845f856137f9565b82515f19908210156133f6578160051b840184855160010160051b0180518582525b602083019250858351036137cd5781528181146137f05785602001820360051c92505b50509392505050565b60608247101561385a5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016105dd565b5f80866001600160a01b0316858760405161387591906145a5565b5f6040518083038185875af1925050503d805f81146138af576040519150601f19603f3d011682016040523d82523d5f602084013e6138b4565b606091505b50915091506138c5878383876138d0565b979650505050505050565b6060831561393e5782515f03613937576001600160a01b0385163b6139375760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016105dd565b5081613452565b61345283838151156139535781518083602001fd5b8060405162461bcd60e51b81526004016105dd91906145cf565b6001600160a01b0381168114613981575f80fd5b50565b803561398f8161396d565b919050565b5f602082840312156139a4575f80fd5b81356133f68161396d565b5f8151808452602084019350602083015f5b828110156139e85781516001600160a01b03168652602095860195909101906001016139c1565b5093949350505050565b604081525f613a0460408301856139af565b905060018060a01b03831660208301529392505050565b5f8060408385031215613a2c575f80fd5b8235613a378161396d565b946020939093013593505050565b604081525f613a5760408301856139af565b82810360208401528084518083526020830191506020860192505f5b81811015613a91578351835260209384019390920191600101613a73565b50909695505050505050565b634e487b7160e01b5f52604160045260245ffd5b6040516101c081016001600160401b0381118282101715613ad457613ad4613a9d565b60405290565b60405161014081016001600160401b0381118282101715613ad457613ad4613a9d565b6040516101a081016001600160401b0381118282101715613ad457613ad4613a9d565b604051601f8201601f191681016001600160401b0381118282101715613b4857613b48613a9d565b604052919050565b8015158114613981575f80fd5b803561398f81613b50565b5f6001600160401b03821115613b8057613b80613a9d565b50601f01601f191660200190565b5f82601f830112613b9d575f80fd5b8135613bb0613bab82613b68565b613b20565b818152846020838601011115613bc4575f80fd5b816020850160208301375f918101602001919091529392505050565b5f60208284031215613bf0575f80fd5b81356001600160401b03811115613c05575f80fd5b82016101c08185031215613c17575f80fd5b613c1f613ab1565b613c2882613984565b8152613c3660208301613984565b602082015260408281013590820152606080830135908201526080808301359082015260a08083013590820152613c6f60c08301613b5d565b60c0820152613c8060e08301613984565b60e0820152613c926101008301613984565b610100820152613ca56101208301613b5d565b6101208201526101408281013590820152610160808301359082015261018080830135908201526101a08201356001600160401b03811115613ce5575f80fd5b613cf186828501613b8e565b6101a083015250949350505050565b5f60208284031215613d10575f80fd5b81356001600160401b03811115613d25575f80fd5b82016101408185031215613d37575f80fd5b613d3f613ada565b613d4882613984565b8152613d5660208301613984565b6020820152604082810135908201526060808301359082015260808083013590820152613d8560a08301613984565b60a0820152613d9660c08301613984565b60c082015260e0828101359082015261010080830135908201526101208201356001600160401b03811115613dc9575f80fd5b613dd586828501613b8e565b61012083015250949350505050565b5f60208284031215613df4575f80fd5b81356001600160401b03811115613e09575f80fd5b820160e081850312156133f6575f80fd5b5f8060408385031215613e2b575f80fd5b8235613e368161396d565b91506020830135613e4681613b50565b809150509250929050565b5f805f805f60a08688031215613e65575f80fd5b8535613e708161396d565b94506020860135613e808161396d565b935060408601359250606086013591506080860135613e9e81613b50565b809150509295509295909350565b5f6001600160401b03821115613ec457613ec4613a9d565b5060051b60200190565b5f82601f830112613edd575f80fd5b8135613eeb613bab82613eac565b8082825260208201915060208360051b860101925085831115613f0c575f80fd5b602085015b83811015613f29578035835260209283019201613f11565b5095945050505050565b5f8060408385031215613f44575f80fd5b82356001600160401b03811115613f59575f80fd5b8301601f81018513613f69575f80fd5b8035613f77613bab82613eac565b8082825260208201915060208360051b850101925087831115613f98575f80fd5b6020840193505b82841015613fc3578335613fb28161396d565b825260209384019390910190613f9f565b945050505060208301356001600160401b03811115613fe0575f80fd5b613fec85828601613ece565b9150509250929050565b5f805f805f60a0868803121561400a575f80fd5b85356140158161396d565b945060208601356140258161396d565b935060408601356140358161396d565b94979396509394606081013594506080013592915050565b5f6101a082840312801561405f575f80fd5b50614068613afd565b61407183613984565b815261407f60208401613984565b60208201526040838101359082015261409a60608401613984565b60608201526140ab60808401613984565b60808201526140bc60a08401613984565b60a082015260c0838101359082015260e08084013590820152610100808401359082015261012080840135908201526101408084013590820152610160808401359082015261410e6101808401613b5d565b6101808201529392505050565b6001600160a01b0391909116815260200190565b5f6020828403121561413f575f80fd5b81516133f68161396d565b5f6020828403121561415a575f80fd5b81516001600160401b0381111561416f575f80fd5b8201601f8101841361417f575f80fd5b805161418d613bab82613eac565b8082825260208201915060208360051b8501019250868311156141ae575f80fd5b6020840193505b828410156141d95783516141c88161396d565b8252602093840193909101906141b5565b9695505050505050565b634e487b7160e01b5f52603260045260245ffd5b6020808252601b908201527f436f6c6c5661756c74526f757465723a204f6e6c79206f776e65720000000000604082015260600190565b5f806040838503121561423f575f80fd5b82516001600160401b03811115614254575f80fd5b8301601f81018513614264575f80fd5b8051614272613bab82613b68565b818152866020838501011115614286575f80fd5b8160208401602083015e5f602083830101528094505050506020830151613e468161396d565b5f602082840312156142bc575f80fd5b5051919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b6001600160a01b03831681526040602082018190525f90613452908301846142c3565b634e487b7160e01b5f52601160045260245ffd5b818103818111156125e3576125e3614314565b60208082526027908201527f506173736564206d73672e76616c75652077697468206e6f6e2d574e4154495660408201526611481d985d5b1d60ca1b606082015260800190565b6020808252601890820152771b5cd9cb9d985b1d5948084f4817d8dbdb1b105b5bdd5b9d60421b604082015260600190565b6001600160a01b03929092168252602082015260400190565b5f602082840312156143dd575f80fd5b81516133f681613b50565b9283526001600160a01b03918216602084015216604082015260600190565b60208082526025908201527f61737365747357697468647261776e203c205f6d696e41737365747357697468604082015264323930bbb760d91b606082015260800190565b5f808335601e19843603018112614461575f80fd5b8301803591506001600160401b0382111561447a575f80fd5b6020019150600581901b36038213156126ef575f80fd5b5f808335601e198436030181126144a6575f80fd5b8301803591506001600160401b038211156144bf575f80fd5b6020019150368190038213156126ef575f80fd5b5f80604083850312156144e4575f80fd5b505080516020909101519092909150565b6001600160a01b0392831681529116602082015260400190565b808201808211156125e3576125e3614314565b5f6001820161453357614533614314565b5060010190565b5f6020828403121561454a575f80fd5b815161ffff811681146133f6575f80fd5b80820281158282048414176125e3576125e3614314565b634e487b7160e01b5f52601260045260245ffd5b5f826145a057634e487b7160e01b5f52601260045260245ffd5b500490565b5f82518060208501845e5f920191825250919050565b634e487b7160e01b5f52602160045260245ffd5b602081525f6133f660208301846142c356fea26469706673582212205f463df5512cddea7fdf3de508dfab8679d51214ece0d24663a2762d6ebe00e764736f6c634300081a0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd4000000000000000000000000ee7d8bcfb72bc1880d0cf19822eb0a2e6577ab620000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f000000000000000000000000b86ea1873bd4c7dd3525b8ea623516b5cba4eb920000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ac4c6e212a361c968f1725b4d055b47e63f80b75
-----Decoded View---------------
Arg [0] : _borrowerOperations (address): 0x49FD0C4fb5172b20b7636b13c49fb15dA52D5bd4
Arg [1] : _wNative (address): 0xEE7D8BCFb72bC1880D0Cf19822eB0A2e6577aB62
Arg [2] : _debtToken (address): 0x0F26bBb8962d73bC891327F14dB5162D5279899F
Arg [3] : _liquidStabilityPool (address): 0xb86EA1873bd4C7dd3525B8Ea623516B5cBa4eb92
Arg [4] : _metaCore (address): 0x8700AF942BE2A6E5566306D0eE7Bcc5a3A6E0ce8
Arg [5] : _mainRewardTokenVault (address): 0x0000000000000000000000000000000000000000
Arg [6] : _initialWhitelistedSwappers (address[]): 0xAC4c6e212A361c968F1725b4d055b47E63F80b75
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 00000000000000000000000049fd0c4fb5172b20b7636b13c49fb15da52d5bd4
Arg [1] : 000000000000000000000000ee7d8bcfb72bc1880d0cf19822eb0a2e6577ab62
Arg [2] : 0000000000000000000000000f26bbb8962d73bc891327f14db5162d5279899f
Arg [3] : 000000000000000000000000b86ea1873bd4c7dd3525b8ea623516b5cba4eb92
Arg [4] : 0000000000000000000000008700af942be2a6e5566306d0ee7bcc5a3a6e0ce8
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [6] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [8] : 000000000000000000000000ac4c6e212a361c968f1725b4d055b47e63f80b75
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
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.