Source Code
Overview
S Balance
S Value
$0.00| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 47925534 | 125 days ago | Contract Creation | 0 S |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
StrategyLib
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {ConstantsLib} from "../../core/libs/ConstantsLib.sol";
import {IPlatform} from "../../interfaces/IPlatform.sol";
import {IFactory} from "../../interfaces/IFactory.sol";
import {IPriceReader} from "../../interfaces/IPriceReader.sol";
import {ISwapper} from "../../interfaces/ISwapper.sol";
import {IStrategy} from "../../interfaces/IStrategy.sol";
import {IFarmingStrategy} from "../../interfaces/IFarmingStrategy.sol";
import {IRevenueRouter} from "../../interfaces/IRevenueRouter.sol";
library StrategyLib {
using SafeERC20 for IERC20;
/// @dev Reward pools may have low liquidity and up to 2% fees
uint internal constant SWAP_REWARDS_PRICE_IMPACT_TOLERANCE = 7_000;
struct ExtractFeesVars {
IPlatform platform;
uint feePlatform;
uint amountPlatform;
}
function FarmingStrategyBase_init(
IFarmingStrategy.FarmingStrategyBaseStorage storage $,
string memory id,
address platform,
uint farmId
) external {
$.farmId = farmId;
IFactory.Farm memory farm = IFactory(IPlatform(platform).factory()).farm(farmId);
if (keccak256(bytes(farm.strategyLogicId)) != keccak256(bytes(id))) {
revert IFarmingStrategy.IncorrectStrategyId();
}
updateFarmingAssets($, platform);
$._rewardsOnBalance = new uint[](farm.rewardAssets.length);
}
function updateFarmingAssets(IFarmingStrategy.FarmingStrategyBaseStorage storage $, address platform) public {
IFactory.Farm memory farm = IFactory(IPlatform(platform).factory()).farm($.farmId);
address swapper = IPlatform(platform).swapper();
$._rewardAssets = farm.rewardAssets;
uint len = farm.rewardAssets.length;
// nosemgrep
for (uint i; i < len; ++i) {
IERC20(farm.rewardAssets[i]).forceApprove(swapper, type(uint).max);
}
$._rewardsOnBalance = new uint[](len);
}
function transferAssets(
IStrategy.StrategyBaseStorage storage $,
uint amount,
uint total_,
address receiver
) external returns (uint[] memory amountsOut) {
address[] memory assets = $._assets;
uint len = assets.length;
amountsOut = new uint[](len);
// nosemgrep
for (uint i; i < len; ++i) {
amountsOut[i] = balance(assets[i]) * amount / total_;
IERC20(assets[i]).transfer(receiver, amountsOut[i]);
}
}
function extractFees(
address platform,
address vault,
address[] memory assets_,
uint[] memory amounts_
) external returns (uint[] memory amountsRemaining) {
ExtractFeesVars memory vars =
ExtractFeesVars({platform: IPlatform(platform), feePlatform: 0, amountPlatform: 0});
(vars.feePlatform,,,) = vars.platform.getFees();
try vars.platform.getCustomVaultFee(vault) returns (uint vaultCustomFee) {
if (vaultCustomFee != 0) {
vars.feePlatform = vaultCustomFee;
}
} catch {}
uint len = assets_.length;
amountsRemaining = new uint[](len);
// nosemgrep
for (uint i; i < len; ++i) {
// revenue fee amount of assets_[i]
vars.amountPlatform = amounts_[i] * vars.feePlatform / ConstantsLib.DENOMINATOR;
vars.amountPlatform = Math.min(vars.amountPlatform, balance(assets_[i]));
if (vars.amountPlatform > 0) {
try vars.platform.revenueRouter() returns (address revenueReceiver) {
IERC20(assets_[i]).forceApprove(revenueReceiver, vars.amountPlatform);
IRevenueRouter(revenueReceiver).processFeeAsset(assets_[i], vars.amountPlatform);
} catch {
// can be only in old strategy upgrade tests
}
amountsRemaining[i] = amounts_[i] - vars.amountPlatform;
amountsRemaining[i] = Math.min(amountsRemaining[i], balance(assets_[i]));
}
}
}
function liquidateRewards(
address platform,
address exchangeAsset,
address[] memory rewardAssets_,
uint[] memory rewardAmounts_,
uint customPriceImpactTolerance
) external returns (uint earnedExchangeAsset) {
ISwapper swapper = ISwapper(IPlatform(platform).swapper());
uint len = rewardAssets_.length;
uint exchangeAssetBalanceBefore = balance(exchangeAsset);
// nosemgrep
for (uint i; i < len; ++i) {
if (rewardAmounts_[i] > swapper.threshold(rewardAssets_[i])) {
if (rewardAssets_[i] != exchangeAsset) {
swapper.swap(
rewardAssets_[i],
exchangeAsset,
Math.min(rewardAmounts_[i], balance(rewardAssets_[i])),
customPriceImpactTolerance != 0
? customPriceImpactTolerance
: SWAP_REWARDS_PRICE_IMPACT_TOLERANCE
);
} else {
exchangeAssetBalanceBefore = 0;
}
}
}
uint exchangeAssetBalanceAfter = balance(exchangeAsset);
earnedExchangeAsset = exchangeAssetBalanceAfter - exchangeAssetBalanceBefore;
}
function emitApr(
IStrategy.StrategyBaseStorage storage $,
address platform,
address[] memory assets,
uint[] memory amounts,
uint tvl,
uint totalBefore
) external {
uint duration = block.timestamp - $.lastHardWork;
IPriceReader priceReader = IPriceReader(IPlatform(platform).priceReader());
//slither-disable-next-line unused-return
(uint earned,, uint[] memory assetPrices,) = priceReader.getAssetsPrice(assets, amounts);
uint apr = computeApr(tvl, earned, duration);
uint aprCompound = totalBefore != 0 ? computeApr(totalBefore, $.total - totalBefore, duration) : apr;
uint sharePrice = tvl * 1e18 / IERC20($.vault).totalSupply();
emit IStrategy.HardWork(apr, aprCompound, earned, tvl, duration, sharePrice, assetPrices);
$.lastApr = apr;
$.lastAprCompound = aprCompound;
$.lastHardWork = block.timestamp;
}
function balance(address token) public view returns (uint) {
return IERC20(token).balanceOf(address(this));
}
/// @dev https://www.investopedia.com/terms/a/apr.asp
/// TVL and rewards should be in the same currency and with the same decimals
function computeApr(uint tvl, uint earned, uint duration) public pure returns (uint) {
if (tvl == 0 || duration == 0) {
return 0;
}
return earned * 1e18 * ConstantsLib.DENOMINATOR * uint(365) / tvl / (duration * 1e18 / 1 days);
}
function computeAprInt(uint tvl, int earned, uint duration) public pure returns (int) {
if (tvl == 0 || duration == 0) {
return 0;
}
return earned * int(1e18) * int(ConstantsLib.DENOMINATOR) * int(365) / int(tvl) / int(duration * 1e18 / 1 days);
}
function assetsAmountsWithBalances(
address[] memory assets_,
uint[] memory amounts_
) external view returns (address[] memory assets, uint[] memory amounts) {
assets = assets_;
amounts = amounts_;
uint len = assets_.length;
// nosemgrep
for (uint i; i < len; ++i) {
amounts[i] += balance(assets_[i]);
}
}
function assetsAreOnBalance(address[] memory assets) external view returns (bool isReady) {
uint rwLen = assets.length;
for (uint i; i < rwLen; ++i) {
if (IERC20(assets[i]).balanceOf(address(this)) > 0) {
isReady = true;
break;
}
}
}
function isPositiveAmountInArray(uint[] memory amounts) external pure returns (bool) {
uint len = amounts.length;
for (uint i; i < len; ++i) {
if (amounts[i] != 0) {
return true;
}
}
return false;
}
function swap(address platform, address tokenIn, address tokenOut, uint amount) external returns (uint amountOut) {
uint outBalanceBefore = balance(tokenOut);
ISwapper swapper = ISwapper(IPlatform(platform).swapper());
swapper.swap(tokenIn, tokenOut, amount, 1000);
amountOut = balance(tokenOut) - outBalanceBefore;
}
function swap(
address platform,
address tokenIn,
address tokenOut,
uint amount,
uint priceImpactTolerance
) external returns (uint amountOut) {
uint outBalanceBefore = balance(tokenOut);
ISwapper swapper = ISwapper(IPlatform(platform).swapper());
swapper.swap(tokenIn, tokenOut, amount, priceImpactTolerance);
amountOut = balance(tokenOut) - outBalanceBefore;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Return the 512-bit addition of two uint256.
*
* The result is stored in two 256 variables such that sum = high * 2²⁵⁶ + low.
*/
function add512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
assembly ("memory-safe") {
low := add(a, b)
high := lt(low, a)
}
}
/**
* @dev Return the 512-bit multiplication of two uint256.
*
* The result is stored in two 256 variables such that product = high * 2²⁵⁶ + low.
*/
function mul512(uint256 a, uint256 b) internal pure returns (uint256 high, uint256 low) {
// 512-bit multiply [high low] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = high * 2²⁵⁶ + low.
assembly ("memory-safe") {
let mm := mulmod(a, b, not(0))
low := mul(a, b)
high := sub(sub(mm, low), lt(mm, low))
}
}
/**
* @dev Returns the addition of two unsigned integers, with a success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
success = c >= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with a success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a - b;
success = c <= a;
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with a success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a * b;
assembly ("memory-safe") {
// Only true when the multiplication doesn't overflow
// (c / a == b) || (a == 0)
success := or(eq(div(c, a), b), iszero(a))
}
// equivalent to: success ? c : 0
result = c * SafeCast.toUint(success);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `DIV` opcode returns zero when the denominator is 0.
result := div(a, b)
}
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
success = b > 0;
assembly ("memory-safe") {
// The `MOD` opcode returns zero when the denominator is 0.
result := mod(a, b)
}
}
}
/**
* @dev Unsigned saturating addition, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingAdd(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryAdd(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Unsigned saturating subtraction, bounds to zero instead of overflowing.
*/
function saturatingSub(uint256 a, uint256 b) internal pure returns (uint256) {
(, uint256 result) = trySub(a, b);
return result;
}
/**
* @dev Unsigned saturating multiplication, bounds to `2²⁵⁶ - 1` instead of overflowing.
*/
function saturatingMul(uint256 a, uint256 b) internal pure returns (uint256) {
(bool success, uint256 result) = tryMul(a, b);
return ternary(success, result, type(uint256).max);
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
// Handle non-overflow cases, 256 by 256 division.
if (high == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return low / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= high) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [high low].
uint256 remainder;
assembly ("memory-safe") {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
high := sub(high, gt(remainder, low))
low := sub(low, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly ("memory-safe") {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [high low] by twos.
low := div(low, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from high into low.
low |= high * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and high
// is no longer required.
result = low * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculates floor(x * y >> n) with full precision. Throws if result overflows a uint256.
*/
function mulShr(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 result) {
unchecked {
(uint256 high, uint256 low) = mul512(x, y);
if (high >= 1 << n) {
Panic.panic(Panic.UNDER_OVERFLOW);
}
return (high << (256 - n)) | (low >> n);
}
}
/**
* @dev Calculates x * y >> n with full precision, following the selected rounding direction.
*/
function mulShr(uint256 x, uint256 y, uint8 n, Rounding rounding) internal pure returns (uint256) {
return mulShr(x, y, n) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, 1 << n) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// If upper 8 bits of 16-bit half set, add 8 to result
r |= SafeCast.toUint((x >> r) > 0xff) << 3;
// If upper 4 bits of 8-bit half set, add 4 to result
r |= SafeCast.toUint((x >> r) > 0xf) << 2;
// Shifts value right by the current result and use it as an index into this lookup table:
//
// | x (4 bits) | index | table[index] = MSB position |
// |------------|---------|-----------------------------|
// | 0000 | 0 | table[0] = 0 |
// | 0001 | 1 | table[1] = 0 |
// | 0010 | 2 | table[2] = 1 |
// | 0011 | 3 | table[3] = 1 |
// | 0100 | 4 | table[4] = 2 |
// | 0101 | 5 | table[5] = 2 |
// | 0110 | 6 | table[6] = 2 |
// | 0111 | 7 | table[7] = 2 |
// | 1000 | 8 | table[8] = 3 |
// | 1001 | 9 | table[9] = 3 |
// | 1010 | 10 | table[10] = 3 |
// | 1011 | 11 | table[11] = 3 |
// | 1100 | 12 | table[12] = 3 |
// | 1101 | 13 | table[13] = 3 |
// | 1110 | 14 | table[14] = 3 |
// | 1111 | 15 | table[15] = 3 |
//
// The lookup table is represented as a 32-byte value with the MSB positions for 0-15 in the last 16 bytes.
assembly ("memory-safe") {
r := or(r, byte(shr(r, x), 0x0000010102020202030303030303030300000000000000000000000000000000))
}
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 x) internal pure returns (uint256 r) {
// If value has upper 128 bits set, log2 result is at least 128
r = SafeCast.toUint(x > 0xffffffffffffffffffffffffffffffff) << 7;
// If upper 64 bits of 128-bit half set, add 64 to result
r |= SafeCast.toUint((x >> r) > 0xffffffffffffffff) << 6;
// If upper 32 bits of 64-bit half set, add 32 to result
r |= SafeCast.toUint((x >> r) > 0xffffffff) << 5;
// If upper 16 bits of 32-bit half set, add 16 to result
r |= SafeCast.toUint((x >> r) > 0xffff) << 4;
// Add 1 if upper 8 bits of 16-bit half set, and divide accumulated result by 8
return (r >> 3) | SafeCast.toUint((x >> r) > 0xff);
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
library ConstantsLib {
uint internal constant DENOMINATOR = 100_000;
address internal constant DEAD_ADDRESS = 0xdEad000000000000000000000000000000000000;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @notice Interface of the main contract and entry point to the platform.
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author ruby (https://github.com/alexandersazonof)
interface IPlatform {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
error AlreadyAnnounced();
error SameVersion();
error NoNewVersion();
error UpgradeTimerIsNotOver(uint TimerTimestamp);
error IncorrectFee(uint minFee, uint maxFee);
error TokenAlreadyExistsInSet(address token);
error AggregatorNotExists(address dexAggRouter);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
event PlatformVersion(string version);
event UpgradeAnnounce(
string oldVersion, string newVersion, address[] proxies, address[] newImplementations, uint timelock
);
event CancelUpgrade(string oldVersion, string newVersion);
event ProxyUpgraded(
address indexed proxy, address implementation, string oldContractVersion, string newContractVersion
);
event Addresses(
address multisig_,
address factory_,
address priceReader_,
address swapper_,
address,
address vaultManager_,
address strategyLogic_,
address,
address hardWorker,
address rebalancer,
address zap,
address bridge
);
event OperatorAdded(address operator);
event OperatorRemoved(address operator);
event FeesChanged(uint fee, uint, uint, uint);
event NewAmmAdapter(string id, address proxy);
event EcosystemRevenueReceiver(address receiver);
event AddDexAggregator(address router);
event RemoveDexAggregator(address router);
event MinTvlForFreeHardWorkChanged(uint oldValue, uint newValue);
event CustomVaultFee(address vault, uint platformFee);
event Rebalancer(address rebalancer_);
event Bridge(address bridge_);
event RevenueRouter(address revenueRouter_);
event MetaVaultFactory(address metaVaultFactory);
event VaultPriceOracle(address vaultPriceOracle_);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* DATA TYPES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
struct PlatformUpgrade {
string newVersion;
address[] proxies;
address[] newImplementations;
}
struct PlatformSettings {
uint fee;
}
struct AmmAdapter {
string id;
address proxy;
}
struct SetupAddresses {
address factory;
address priceReader;
address swapper;
address vaultManager;
address strategyLogic;
address targetExchangeAsset;
address hardWorker;
address zap;
address revenueRouter;
address metaVaultFactory;
address vaultPriceOracle;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* VIEW FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Platform version in CalVer scheme: YY.MM.MINOR-tag. Updates on core contract upgrades.
function platformVersion() external view returns (string memory);
/// @notice Time delay for proxy upgrades of core contracts and changing important platform settings by multisig
//slither-disable-next-line naming-convention
function TIME_LOCK() external view returns (uint);
/// @notice DAO governance
function governance() external view returns (address);
/// @notice Core team multi signature wallet. Development and operations fund
function multisig() external view returns (address);
/// @notice Receiver of ecosystem revenue
function ecosystemRevenueReceiver() external view returns (address);
/// @dev The best asset in a network for swaps between strategy assets and farms rewards assets
/// The target exchange asset is used for finding the best strategy's exchange asset.
/// Rhe fewer routes needed to swap to the target exchange asset, the better.
function targetExchangeAsset() external view returns (address);
/// @notice Platform factory assembling vaults. Stores settings, strategy logic, farms.
/// Provides the opportunity to upgrade vaults and strategies.
/// @return Address of Factory proxy
function factory() external view returns (address);
/// @notice The holders of these NFT receive a share of the vault revenue
/// @return Address of VaultManager proxy
function vaultManager() external view returns (address);
/// @notice The holders of these tokens receive a share of the revenue received in all vaults using this strategy logic.
function strategyLogic() external view returns (address);
/// @notice Combining oracle and DeX spot prices
/// @return Address of PriceReader proxy
function priceReader() external view returns (address);
/// @notice On-chain price quoter and swapper
/// @return Address of Swapper proxy
function swapper() external view returns (address);
/// @notice HardWork resolver and caller
/// @return Address of HardWorker proxy
function hardWorker() external view returns (address);
/// @notice Rebalance resolver
/// @return Address of Rebalancer proxy
function rebalancer() external view returns (address);
/// @notice ZAP feature
/// @return Address of Zap proxy
function zap() external view returns (address);
/// @notice Platform revenue distributor
/// @return Address of the revenue distributor proxy
function revenueRouter() external view returns (address);
/// @notice Factory of MetaVaults
/// @return Address of the MetaVault factory
function metaVaultFactory() external view returns (address);
/// @notice vaultPriceOracle
/// @return Address of the vault price oracle
function vaultPriceOracle() external view returns (address);
/// @notice This function provides the timestamp of the platform upgrade timelock.
/// @dev This function is an external view function, meaning it doesn't modify the state.
/// @return uint representing the timestamp of the platform upgrade timelock.
function platformUpgradeTimelock() external view returns (uint);
/// @notice Pending platform upgrade data
function pendingPlatformUpgrade() external view returns (PlatformUpgrade memory);
/// @notice Get platform revenue fee settings
/// @return fee Revenue fee % (between MIN_FEE - MAX_FEE) with DENOMINATOR precision.
function getFees() external view returns (uint fee, uint, uint, uint);
/// @notice Get custom vault platform fee
/// @return fee revenue fee % with DENOMINATOR precision
function getCustomVaultFee(address vault) external view returns (uint fee);
/// @notice Platform settings
function getPlatformSettings() external view returns (PlatformSettings memory);
/// @notice AMM adapters of the platform
function getAmmAdapters() external view returns (string[] memory id, address[] memory proxy);
/// @notice Get AMM adapter data by hash
/// @param ammAdapterIdHash Keccak256 hash of adapter ID string
/// @return ID string and proxy address of AMM adapter
function ammAdapter(bytes32 ammAdapterIdHash) external view returns (AmmAdapter memory);
/// @notice Check address for existance in operators list
/// @param operator Address
/// @return True if this address is Stability Operator
function isOperator(address operator) external view returns (bool);
/// @notice Allowed DeX aggregators
/// @return Addresses of DeX aggregator rounters
function dexAggregators() external view returns (address[] memory);
/// @notice DeX aggregator router address is allowed to be used in the platform
/// @param dexAggRouter Address of DeX aggreagator router
/// @return Can be used
function isAllowedDexAggregatorRouter(address dexAggRouter) external view returns (bool);
/// @notice Show minimum TVL for compensate if vault has not enough ETH
/// @return Minimum TVL for compensate.
function minTvlForFreeHardWork() external view returns (uint);
/// @notice Front-end platform viewer
/// @return platformAddresses Platform core addresses
/// platformAddresses[0] factory
/// platformAddresses[1] vaultManager
/// platformAddresses[2] strategyLogic
/// platformAddresses[3] deprecated
/// platformAddresses[4] deprecated
/// platformAddresses[5] governance
/// platformAddresses[6] multisig
/// platformAddresses[7] zap
/// platformAddresses[8] bridge
/// @return bcAssets Blue chip token addresses
/// @return dexAggregators_ DeX aggregators allowed to be used entire the platform
/// @return vaultType Vault type ID strings
/// @return vaultExtra Vault color, background color and other extra data. Index of vault same as in previous array.
/// @return vaultBulldingPrice Price of creating new vault in buildingPayPerVaultToken. Index of vault same as in previous array.
/// @return strategyId Strategy logic ID strings
/// @return isFarmingStrategy True if strategy is farming strategy. Index of strategy same as in previous array.
/// @return strategyTokenURI StrategyLogic NFT tokenId metadata and on-chain image. Index of strategy same as in previous array.
/// @return strategyExtra Strategy color, background color and other extra data. Index of strategy same as in previous array.
function getData()
external
view
returns (
address[] memory platformAddresses,
address[] memory bcAssets,
address[] memory dexAggregators_,
string[] memory vaultType,
bytes32[] memory vaultExtra,
uint[] memory vaultBulldingPrice,
string[] memory strategyId,
bool[] memory isFarmingStrategy,
string[] memory strategyTokenURI,
bytes32[] memory strategyExtra
);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* WRITE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Add platform operator.
/// Only governance and multisig can add operator.
/// @param operator Address of new operator
function addOperator(address operator) external;
/// @notice Remove platform operator.
/// Only governance and multisig can remove operator.
/// @param operator Address of operator to remove
function removeOperator(address operator) external;
/// @notice Announce upgrade of platform proxies implementations
/// Only governance and multisig can announce platform upgrades.
/// @param newVersion New platform version. Version must be changed when upgrading.
/// @param proxies Addresses of core contract proxies
/// @param newImplementations New implementation for proxy. Index of proxy same as in previous array.
function announcePlatformUpgrade(
string memory newVersion,
address[] memory proxies,
address[] memory newImplementations
) external;
/// @notice Upgrade platform
/// Only operator (multisig is operator too) can execute pending platform upgrade
function upgrade() external;
/// @notice Cancel pending platform upgrade
/// Only operator (multisig is operator too) can execute pending platform upgrade
function cancelUpgrade() external;
/// @notice Register AMM adapter in platform
/// @param id AMM adapter ID string from AmmAdapterIdLib
/// @param proxy Address of AMM adapter proxy
function addAmmAdapter(string memory id, address proxy) external;
/// @notice Allow DeX aggregator routers to be used in the platform
/// @param dexAggRouter Addresses of DeX aggreagator routers
function addDexAggregators(address[] memory dexAggRouter) external;
/// @notice Remove allowed DeX aggregator router from the platform
/// @param dexAggRouter Address of DeX aggreagator router
function removeDexAggregator(address dexAggRouter) external;
/// @notice Update new minimum TVL for compensate.
/// @param value New minimum TVL for compensate.
function setMinTvlForFreeHardWork(uint value) external;
/// @notice Set custom platform fee for vault
/// @param vault Vault address
/// @param platformFee Custom platform fee
function setCustomVaultFee(address vault, uint platformFee) external;
/// @notice Set vault price oracle
/// @param vaultPriceOracle_ Address of the vault price oracle
function setupVaultPriceOracle(address vaultPriceOracle_) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
/// @notice Creating vaults, upgrading vaults and strategies, vault list, farms and strategy logics management
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author HCrypto7 (https://github.com/hcrypto7)
interface IFactory {
//region ----- Custom Errors -----
error VaultImplementationIsNotAvailable();
error StrategyImplementationIsNotAvailable();
error YouDontHaveEnoughTokens(uint userBalance, uint requireBalance, address payToken);
error SuchVaultAlreadyDeployed(bytes32 key);
error NotActiveVault();
error UpgradeDenied(bytes32 _hash);
error AlreadyLastVersion(bytes32 _hash);
error NotStrategy();
//endregion ----- Custom Errors -----
//region ----- Events -----
event VaultAndStrategy(
address indexed deployer,
string vaultType,
string strategyId,
address vault,
address strategy,
string name,
string symbol,
address[] assets,
bytes32 deploymentKey,
uint vaultManagerTokenId
);
event StrategyProxyUpgraded(address proxy, address oldImplementation, address newImplementation);
event VaultProxyUpgraded(address proxy, address oldImplementation, address newImplementation);
event VaultConfigChanged(
string type_, address implementation, bool deployAllowed, bool upgradeAllowed, bool newVaultType
);
event StrategyLogicConfigChanged(
string id, address implementation, bool deployAllowed, bool upgradeAllowed, bool newStrategy
);
event VaultStatus(address indexed vault, uint newStatus);
event NewFarm(Farm[] farms);
event UpdateFarm(uint id, Farm farm);
event SetStrategyAvailableInitParams(string id, address[] initAddresses, uint[] initNums, int24[] initTicks);
event AliasNameChanged(address indexed operator, address indexed tokenAddress, string newAliasName);
//endregion -- Events -----
//region ----- Data types -----
/// @custom:storage-location erc7201:stability.Factory
struct FactoryStorage {
/// @inheritdoc IFactory
mapping(bytes32 typeHash => VaultConfig) vaultConfig;
/// @inheritdoc IFactory
mapping(bytes32 idHash => StrategyLogicConfig) strategyLogicConfig;
/// @inheritdoc IFactory
mapping(bytes32 deploymentKey => address vaultProxy) deploymentKey;
/// @inheritdoc IFactory
mapping(address vault => uint status) vaultStatus;
/// @inheritdoc IFactory
mapping(address address_ => bool isStrategy_) isStrategy;
EnumerableSet.Bytes32Set vaultTypeHashes;
EnumerableSet.Bytes32Set strategyLogicIdHashes;
mapping(uint => mapping(uint => uint)) __deprecated1;
address[] deployedVaults;
Farm[] farms;
/// @inheritdoc IFactory
mapping(bytes32 idHash => StrategyAvailableInitParams) strategyAvailableInitParams;
mapping(address tokenAddress => string aliasName) aliasNames;
}
struct VaultConfig {
string vaultType;
address implementation;
bool deployAllowed;
bool upgradeAllowed;
uint buildingPrice;
}
struct StrategyLogicConfig {
string id;
address implementation;
bool deployAllowed;
bool upgradeAllowed;
bool farming;
uint tokenId;
}
struct Farm {
uint status;
address pool;
string strategyLogicId;
address[] rewardAssets;
address[] addresses;
uint[] nums;
int24[] ticks;
}
struct StrategyAvailableInitParams {
address[] initAddresses;
uint[] initNums;
int24[] initTicks;
}
//endregion -- Data types -----
//region ----- View functions -----
/// @notice All vaults deployed by the factory
/// @return Vault proxy addresses
function deployedVaults() external view returns (address[] memory);
/// @notice Total vaults deployed
function deployedVaultsLength() external view returns (uint);
/// @notice Get vault by VaultManager tokenId
/// @param id Vault array index. Same as tokenId of VaultManager NFT
/// @return Address of VaultProxy
function deployedVault(uint id) external view returns (address);
/// @notice All farms known by the factory in current network
function farms() external view returns (Farm[] memory);
/// @notice Total farms known by the factory in current network
function farmsLength() external view returns (uint);
/// @notice Farm data by farm index
/// @param id Index of farm
function farm(uint id) external view returns (Farm memory);
/// @notice Strategy logic settings
/// @param idHash keccak256 hash of strategy logic string ID
/// @return config Strategy logic settings
function strategyLogicConfig(bytes32 idHash) external view returns (StrategyLogicConfig memory config);
/// @notice All known strategies
/// @return Array of keccak256 hashes of strategy logic string ID
function strategyLogicIdHashes() external view returns (bytes32[] memory);
// todo remove, use new function without calculating vault symbol on the fly for not initialized vaults
// factory required that special functionally only internally, not for interface
function getStrategyData(
string memory vaultType,
address strategyAddress,
address
)
external
view
returns (
string memory strategyId,
address[] memory assets,
string[] memory assetsSymbols,
string memory specificName,
string memory vaultSymbol
);
/// @dev Get best asset of assets to be strategy exchange asset
function getExchangeAssetIndex(address[] memory assets) external view returns (uint);
/// @notice Deployment key of created vault
/// @param deploymentKey_ Hash of concatenated unique vault and strategy initialization parameters
/// @return Address of deployed vault
function deploymentKey(bytes32 deploymentKey_) external view returns (address);
/// @notice Calculating deployment key based on unique vault and strategy initialization parameters
/// @param vaultType Vault type string
/// @param strategyId Strategy logic Id string
/// @param vaultInitAddresses Vault initialization addresses for deployVaultAndStrategy method
/// @param vaultInitNums Vault initialization uint numbers for deployVaultAndStrategy method
/// @param strategyInitAddresses Strategy initialization addresses for deployVaultAndStrategy method
/// @param strategyInitNums Strategy initialization uint numbers for deployVaultAndStrategy method
/// @param strategyInitTicks Strategy initialization int24 ticks for deployVaultAndStrategy method
function getDeploymentKey(
string memory vaultType,
string memory strategyId,
address[] memory vaultInitAddresses,
uint[] memory vaultInitNums,
address[] memory strategyInitAddresses,
uint[] memory strategyInitNums,
int24[] memory strategyInitTicks
) external view returns (bytes32);
/// @notice Governance and multisig can set a vault status other than Active - the default status.
/// HardWorker only works with active vaults.
/// @return status Constant from VaultStatusLib
function vaultStatus(address vault) external view returns (uint status);
/// @notice Check that strategy proxy deployed by the Factory
/// @param address_ Address of contract
/// @return This address is our strategy proxy
function isStrategy(address address_) external view returns (bool);
/// @notice Data on all factory strategies.
/// The output values are matched by index in the arrays.
/// @return id Strategy logic ID strings
/// @return deployAllowed New vaults can be deployed
/// @return upgradeAllowed Strategy can be upgraded
/// @return farming It is farming strategy (earns farming/gauge rewards)
/// @return tokenId Token ID of StrategyLogic NFT
/// @return tokenURI StrategyLogic NFT tokenId metadata and on-chain image
/// @return extra Strategy color, background color and other extra data
function strategies()
external
view
returns (
string[] memory id,
bool[] memory deployAllowed,
bool[] memory upgradeAllowed,
bool[] memory farming,
uint[] memory tokenId,
string[] memory tokenURI,
bytes32[] memory extra
);
/// @notice Get config of vault type
/// @param typeHash Keccak256 hash of vault type string
/// @return vaultType Vault type string
/// @return implementation Vault implementation address
/// @return deployAllowed New vaults can be deployed
/// @return upgradeAllowed Vaults can be upgraded
/// @return buildingPrice Price of building new vault
function vaultConfig(bytes32 typeHash)
external
view
returns (
string memory vaultType,
address implementation,
bool deployAllowed,
bool upgradeAllowed,
uint buildingPrice
);
/// @notice Data on all factory vault types
/// The output values are matched by index in the arrays.
/// @return vaultType Vault type string
/// @return implementation Address of vault implemented logic
/// @return deployAllowed New vaults can be deployed
/// @return upgradeAllowed Vaults can be upgraded
/// @return buildingPrice Price of building new vault
/// @return extra Vault type color, background color and other extra data
function vaultTypes()
external
view
returns (
string[] memory vaultType,
address[] memory implementation,
bool[] memory deployAllowed,
bool[] memory upgradeAllowed,
uint[] memory buildingPrice,
bytes32[] memory extra
);
/// @notice Initialization strategy params store
function strategyAvailableInitParams(bytes32 idHash) external view returns (StrategyAvailableInitParams memory);
//endregion -- View functions -----
//region ----- Write functions -----
/// @notice Main method of the Factory - new vault creation by user.
/// @param vaultType Vault type ID string
/// @param strategyId Strategy logic ID string
/// Different types of vaults and strategies have different lengths of input arrays.
/// @param vaultInitAddresses Addresses for vault initialization
/// @param vaultInitNums Numbers for vault initialization
/// @param strategyInitAddresses Addresses for strategy initialization
/// @param strategyInitNums Numbers for strategy initialization
/// @param strategyInitTicks Ticks for strategy initialization
/// @return vault Deployed VaultProxy address
/// @return strategy Deployed StrategyProxy address
function deployVaultAndStrategy(
string memory vaultType,
string memory strategyId,
address[] memory vaultInitAddresses,
uint[] memory vaultInitNums,
address[] memory strategyInitAddresses,
uint[] memory strategyInitNums,
int24[] memory strategyInitTicks
) external returns (address vault, address strategy);
/// @notice Upgrade vault proxy. Can be called by any address.
/// @param vault Address of vault proxy for upgrade
function upgradeVaultProxy(address vault) external;
/// @notice Upgrade strategy proxy. Can be called by any address.
/// @param strategy Address of strategy proxy for upgrade
function upgradeStrategyProxy(address strategy) external;
/// @notice Add farm to factory
/// @param farms_ Settings and data required to work with the farm.
function addFarms(Farm[] memory farms_) external;
/// @notice Update farm
/// @param id Farm index
/// @param farm_ Settings and data required to work with the farm.
function updateFarm(uint id, Farm memory farm_) external;
/// @notice Initial addition or change of vault type settings.
/// Operator can add new vault type. Governance or multisig can change existing vault type config.
/// @param vaultConfig_ Vault type settings
function setVaultConfig(VaultConfig memory vaultConfig_) external;
/// @notice Initial addition or change of vault type implementation
/// Operator can add new vault type. Governance or multisig can change existing vault type config.
/// @param vaultType Vault type string ID (Compounding, etc)
/// @param implementation Address of implementation
function setVaultImplementation(string memory vaultType, address implementation) external;
/// @notice Initial addition or change of strategy logic settings.
/// Operator can add new strategy logic. Governance or multisig can change existing logic config.
/// @param config Strategy logic settings
/// @param developer Strategy developer is receiver of minted StrategyLogic NFT on initial addition
function setStrategyLogicConfig(StrategyLogicConfig memory config, address developer) external;
/// @notice Governance and multisig can set a vault status other than Active - the default status.
/// @param vaults Addresses of vault proxy
/// @param statuses New vault statuses. Constant from VaultStatusLib
function setVaultStatus(address[] memory vaults, uint[] memory statuses) external;
/// @notice Initial addition or change of strategy available init params
/// @param id Strategy ID string
/// @param initParams Init params variations that will be parsed by strategy
function setStrategyAvailableInitParams(string memory id, StrategyAvailableInitParams memory initParams) external;
//endregion -- Write functions -----
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/// @dev Combining oracle and DeX spot prices
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
interface IPriceReader {
//region ----- Events -----
event AdapterAdded(address adapter);
event AdapterRemoved(address adapter);
event VaultWithSafeSharePriceAdded(address vault);
event VaultWithSafeSharePriceRemoved(address vault);
//endregion -- Events -----
//region --------------------------- Errors
error NotWhitelistedTransientCache();
//endregion --------------------------- Errors
/// @notice Price of asset
/// @dev Price of 1.0 amount of asset in USD
/// @param asset Address of asset
/// @return price USD price with 18 decimals
/// @return trusted Price from oracle
function getPrice(address asset) external view returns (uint price, bool trusted);
/// @notice Price of vault share
/// @dev Price of 1.0 amount of vault token
/// @param vault Address of vault
/// @return price USD price with 18 decimals
/// @return safe Safe to use this price on-chain
function getVaultPrice(address vault) external view returns (uint price, bool safe);
/// @notice Get USD price of specified assets and amounts
/// @param assets_ Addresses of assets
/// @param amounts_ Amount of asset. Index of asset same as in previous parameter.
/// @return total Total USD value with 18 decimals
/// @return assetAmountPrice USD price of asset amount. Index of assetAmountPrice same as in assets_ parameters.
/// @return assetPrice USD price of asset. Index of assetAmountPrice same as in assets_ parameters.
/// @return trusted True if only oracle prices was used for calculation.
function getAssetsPrice(
address[] memory assets_,
uint[] memory amounts_
) external view returns (uint total, uint[] memory assetAmountPrice, uint[] memory assetPrice, bool trusted);
/// @notice Get vaults that have organic safe share price that can be used on-chain
function vaultsWithSafeSharePrice() external view returns (address[] memory vaults);
/// @notice Add oracle adapter to PriceReader
/// Only operator (multisig is operator too) can add adapter
/// @param adapter_ Address of price oracle proxy
function addAdapter(address adapter_) external;
/// @notice Remove oracle adapter from PriceReader
/// Only operator (multisig is operator too) can add adapter
/// @param adapter_ Address of price oracle proxy
function removeAdapter(address adapter_) external;
/// @notice Add vaults that have organic safe share price that can be used on-chain
/// Only operator (multisig is operator too) can add adapter
/// @param vaults Addresses of vaults
function addSafeSharePrices(address[] memory vaults) external;
/// @notice Remove vaults that have organic safe share price that can be used on-chain
/// Only operator (multisig is operator too) can add adapter
/// @param vaults Addresses of vaults
function removeSafeSharePrices(address[] memory vaults) external;
/// @notice Check if the user is whitelisted for using transient cache
function whitelistTransientCache(address user_) external view returns (bool);
/// @notice Add user to whitelist of users allowed to use the transient cache
function changeWhitelistTransientCache(address user, bool add) external;
/// @notice Save asset price to transient cache
/// @param asset Pass 0 to clear the cache
function preCalculatePriceTx(address asset) external;
/// @notice Save vault price to transient cache
/// Second call with the same vault will be ignored and won't not change the price
/// @param vault Pass 0 to clear the cache
function preCalculateVaultPriceTx(address vault) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/// @notice On-chain price quoter and swapper by predefined routes
/// @author Alien Deployer (https://github.com/a17)
/// @author Jude (https://github.com/iammrjude)
/// @author JodsMigel (https://github.com/JodsMigel)
/// @author 0xhokugava (https://github.com/0xhokugava)
interface ISwapper {
event Swap(address indexed tokenIn, address indexed tokenOut, uint amount);
event PoolAdded(PoolData poolData, bool assetAdded);
event PoolRemoved(address token);
event BlueChipAdded(PoolData poolData);
event ThresholdChanged(address[] tokenIn, uint[] thresholdAmount);
event BlueChipPoolRemoved(address tokenIn, address tokenOut);
//region ----- Custom Errors -----
error UnknownAMMAdapter();
error LessThenThreshold(uint minimumAmount);
error NoRouteFound();
error NoRoutesForAssets();
//endregion -- Custom Errors -----
struct PoolData {
address pool;
address ammAdapter;
address tokenIn;
address tokenOut;
}
struct AddPoolData {
address pool;
string ammAdapterId;
address tokenIn;
address tokenOut;
}
/// @notice All assets in pools added to Swapper
/// @return Addresses of assets
function assets() external view returns (address[] memory);
/// @notice All blue chip assets in blue chip pools added to Swapper
/// @return Addresses of blue chip assets
function bcAssets() external view returns (address[] memory);
/// @notice All assets in Swapper
/// @return Addresses of assets and blue chip assets
function allAssets() external view returns (address[] memory);
/// @notice Add pools with largest TVL
/// @param pools Largest pools with AMM adapter addresses
/// @param rewrite Rewrite pool for tokenIn
function addPools(PoolData[] memory pools, bool rewrite) external;
/// @notice Add pools with largest TVL
/// @param pools Largest pools with AMM adapter ID string
/// @param rewrite Rewrite pool for tokenIn
function addPools(AddPoolData[] memory pools, bool rewrite) external;
/// @notice Add largest pools with the most popular tokens on the current network
/// @param pools_ PoolData array with pool, tokens and AMM adapter address
/// @param rewrite Change exist pool records
function addBlueChipsPools(PoolData[] memory pools_, bool rewrite) external;
/// @notice Add largest pools with the most popular tokens on the current network
/// @param pools_ AddPoolData array with pool, tokens and AMM adapter string ID
/// @param rewrite Change exist pool records
function addBlueChipsPools(AddPoolData[] memory pools_, bool rewrite) external;
/// @notice Retrieves pool data for a specified token swap in Blue Chip Pools.
/// @dev This function provides information about the pool associated with the specified input and output tokens.
/// @param tokenIn The input token address.
/// @param tokenOut The output token address.
/// @return poolData The data structure containing information about the Blue Chip Pool.
/// @custom:opcodes view
function blueChipsPools(address tokenIn, address tokenOut) external view returns (PoolData memory poolData);
/// @notice Set swap threshold for token
/// @dev Prevents dust swap.
/// @param tokenIn Swap input token
/// @param thresholdAmount Minimum amount of token for executing swap
function setThresholds(address[] memory tokenIn, uint[] memory thresholdAmount) external;
/// @notice Swap threshold for token
/// @param token Swap input token
/// @return threshold_ Minimum amount of token for executing swap
function threshold(address token) external view returns (uint threshold_);
/// @notice Price of given tokenIn against tokenOut
/// @param tokenIn Swap input token
/// @param tokenOut Swap output token
/// @param amount Amount of tokenIn. If provide zero then amount is 1.0.
/// @return Amount of tokenOut with decimals of tokenOut
function getPrice(address tokenIn, address tokenOut, uint amount) external view returns (uint);
/// @notice Return price the first poolData.tokenIn against the last poolData.tokenOut in decimals of tokenOut.
/// @param route Array of pool address, swapper address tokenIn, tokenOut
/// @param amount Amount of tokenIn. If provide zero then amount is 1.0.
function getPriceForRoute(PoolData[] memory route, uint amount) external view returns (uint);
/// @notice Check possibility of swap tokenIn for tokenOut
/// @param tokenIn Swap input token
/// @param tokenOut Swap output token
/// @return Swap route exists
function isRouteExist(address tokenIn, address tokenOut) external view returns (bool);
/// @notice Build route for swap. No reverts inside.
/// @param tokenIn Swap input token
/// @param tokenOut Swap output token
/// @return route Array of pools for swap tokenIn to tokenOut. Zero length indicate an error.
/// @return errorMessage Possible reason why the route was not found. Empty for success routes.
function buildRoute(
address tokenIn,
address tokenOut
) external view returns (PoolData[] memory route, string memory errorMessage);
/// @notice Sell tokenIn for tokenOut
/// @dev Assume approve on this contract exist
/// @param tokenIn Swap input token
/// @param tokenOut Swap output token
/// @param amount Amount of tokenIn for swap.
/// @param priceImpactTolerance Price impact tolerance. Must include fees at least. Denominator is 100_000.
function swap(address tokenIn, address tokenOut, uint amount, uint priceImpactTolerance) external;
/// @notice Swap by predefined route
/// @param route Array of pool address, swapper address tokenIn, tokenOut.
/// TokenIn from first item will be swaped to tokenOut of last .
/// @param amount Amount of first item tokenIn.
/// @param priceImpactTolerance Price impact tolerance. Must include fees at least. Denominator is 100_000.
function swapWithRoute(PoolData[] memory route, uint amount, uint priceImpactTolerance) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/// @dev Core interface of strategy logic
interface IStrategy is IERC165 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
event HardWork(
uint apr, uint compoundApr, uint earned, uint tvl, uint duration, uint sharePrice, uint[] assetPrices
);
event StrategyProtocols(string[]);
event SpecificName(string);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
error NotReadyForHardWork();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* DATA TYPES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @custom:storage-location erc7201:stability.StrategyBase
struct StrategyBaseStorage {
/// @inheritdoc IStrategy
address vault;
/// @inheritdoc IStrategy
uint total;
/// @inheritdoc IStrategy
uint lastHardWork;
/// @inheritdoc IStrategy
uint lastApr;
/// @inheritdoc IStrategy
uint lastAprCompound;
/// @inheritdoc IStrategy
address[] _assets;
/// @inheritdoc IStrategy
address _underlying;
string _id;
uint _exchangeAssetIndex;
uint customPriceImpactTolerance;
/// @inheritdoc IStrategy
uint fuseOn;
/// @inheritdoc IStrategy
string[] protocols;
string specific;
}
enum FuseMode {
FUSE_OFF_0,
/// @notice Fuse mode is on (emergency stop was called).
/// All assets were transferred from the underlying pool to the strategy balance, no deposits are allowed.
FUSE_ON_1
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* VIEW FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Strategy logic string ID
function strategyLogicId() external view returns (string memory);
/// @dev Extra data
/// @return 0-2 bytes - strategy color
/// 3-5 bytes - strategy background color
/// 6-31 bytes - free
function extra() external view returns (bytes32);
/// @dev Types of vault that supported by strategy implementation
/// @return types Vault type ID strings
function supportedVaultTypes() external view returns (string[] memory types);
/// @dev Linked vault address
function vault() external view returns (address);
/// @dev Final assets that strategy invests
function assets() external view returns (address[] memory);
/// @notice Final assets and amounts that strategy manages
function assetsAmounts() external view returns (address[] memory assets_, uint[] memory amounts_);
/// @notice Priced invested assets proportions
/// @return proportions Proportions of assets with 18 decimals. Min is 0, max is 1e18.
function getAssetsProportions() external view returns (uint[] memory proportions);
/// @notice Underlying token address
/// @dev Can be used for liquidity farming strategies where AMM has fungible liquidity token (Solidly forks, etc),
/// for concentrated liquidity tokenized vaults (Gamma, G-UNI etc) and for other needs.
/// @return Address of underlying token or zero address if no underlying in strategy
function underlying() external view returns (address);
/// @dev Balance of liquidity token or liquidity value
function total() external view returns (uint);
/// @dev Last HardWork time
/// @return Timestamp
function lastHardWork() external view returns (uint);
/// @dev Last APR of earned USD amount registered by HardWork
/// ONLY FOR OFF-CHAIN USE.
/// Not trusted asset price can be manipulated.
/// @return APR with 5 decimals. 100_000 - 100% APR, 9_955 - 9.96% APR.
function lastApr() external view returns (uint);
/// @dev Last APR of compounded assets registered by HardWork.
/// Can be used on-chain.
/// @return APR with 5 decimals. 100_000 - 100% APR, 9_955 - 9.96% APR.
function lastAprCompound() external view returns (uint);
/// @notice Calculation of consumed amounts and liquidity/underlying value for provided strategy assets and amounts.
/// @param assets_ Strategy assets or part of them, if necessary
/// @param amountsMax Amounts of specified assets available for investing
/// @return amountsConsumed Cosumed amounts of assets when investing
/// @return value Liquidity value or underlying token amount minted when investing
function previewDepositAssets(
address[] memory assets_,
uint[] memory amountsMax
) external view returns (uint[] memory amountsConsumed, uint value);
/// @notice Write version of previewDepositAssets
/// @param assets_ Strategy assets or part of them, if necessary
/// @param amountsMax Amounts of specified assets available for investing
/// @return amountsConsumed Cosumed amounts of assets when investing
/// @return value Liquidity value or underlying token amount minted when investing
function previewDepositAssetsWrite(
address[] memory assets_,
uint[] memory amountsMax
) external returns (uint[] memory amountsConsumed, uint value);
/// @notice All strategy revenue (pool fees, farm rewards etc) that not claimed by strategy yet
/// @return assets_ Revenue assets
/// @return amounts Amounts. Index of asset same as in previous array.
function getRevenue() external view returns (address[] memory assets_, uint[] memory amounts);
/// @notice Optional specific name of investing strategy, underyling type, setup variation etc
/// @return name Empty string or specific name
/// @return showInVaultSymbol Show specific in linked vault symbol
function getSpecificName() external view returns (string memory name, bool showInVaultSymbol);
/// @notice Variants pf strategy initializations with description of money making mechanic.
/// As example, if strategy need farm, then number of variations is number of available farms.
/// If CAMM strategy have set of available widths (tick ranges), then number of variations is number of available farms.
/// If both example conditions are met then total number or variations = total farms * total widths.
/// @param platform_ Need this param because method called when strategy implementation is not initialized
/// @return variants Descriptions of the strategy for making money
/// @return addresses Init strategy addresses. Indexes for each variants depends of copmpared arrays lengths.
/// @return nums Init strategy numbers. Indexes for each variants depends of copmpared arrays lengths.
/// @return ticks Init strategy ticks. Indexes for each variants depends of copmpared arrays lengths.
function initVariants(address platform_)
external
view
returns (string[] memory variants, address[] memory addresses, uint[] memory nums, int24[] memory ticks);
/// @notice How does the strategy make money?
/// @return Description in free form
function description() external view returns (string memory);
/// @notice Is HardWork on vault deposits can be enabled
function isHardWorkOnDepositAllowed() external view returns (bool);
/// @notice Is HardWork can be executed
function isReadyForHardWork() external view returns (bool);
/// @notice Strategy not need to process revenue on HardWorks
function autoCompoundingByUnderlyingProtocol() external view returns (bool);
/// @notice Custom price impact tolerance instead default need for specific cases where liquidity in pools is low
function customPriceImpactTolerance() external view returns (uint);
/// @notice Total amount of assets available in the lending protocol for withdraw
/// It's normal situation when user is not able to withdraw all
/// because there are not enough reserves available in the protocol right now
/// @dev This function is replaced by more flexible maxWithdrawAssets(uint mode) function.
function maxWithdrawAssets() external view returns (uint[] memory amounts);
/// @notice Total amount of assets available in the lending protocol for withdraw
/// It's normal situation when user is not able to withdraw all
/// because there are not enough reserves available in the protocol right now
/// @param mode 0 - Return amount that can be withdrawn in assets
/// 1 - Return amount that can be withdrawn in underlying
/// @return amounts Empty array (zero length) is returned if all available amount can be withdrawn
function maxWithdrawAssets(uint mode) external view returns (uint[] memory amounts);
/// @notice Underlying pool TVL in the terms of USD
function poolTvl() external view returns (uint tvlUsd);
/// @notice return FUSE_ON_1 if emergency was called and all actives were transferred to the vault
function fuseMode() external view returns (uint);
/// @notice Maximum amounts of assets that can be deposited into the strategy
/// @return amounts Empty array (zero length) is returned if there are no limits on deposits
function maxDepositAssets() external view returns (uint[] memory amounts);
/// @notice Show strategy protocols
function protocols() external view returns (string[] memory);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* WRITE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev A single universal initializer for all strategy implementations.
/// @param addresses All addresses that strategy requires for initialization. Min array length is 2.
/// addresses[0]: platform (required)
/// addresses[1]: vault (required)
/// addresses[2]: initStrategyAddresses[0] (optional)
/// addresses[3]: initStrategyAddresses[1] (optional)
/// addresses[n]: initStrategyAddresses[n - 2] (optional)
/// @param nums All uint values that strategy requires for initialization. Min array length is 0.
/// @param ticks All int24 values that strategy requires for initialization. Min array length is 0.
function initialize(address[] memory addresses, uint[] memory nums, int24[] memory ticks) external;
/// @notice Invest strategy assets. Amounts of assets must be already on strategy contract balance.
/// Only vault can call this.
/// @param amounts Amounts of strategy assets
/// @return value Liquidity value or underlying token amount
function depositAssets(uint[] memory amounts) external returns (uint value);
/// @notice Invest underlying asset. Asset must be already on strategy contract balance.
/// Only vault can call this.
/// @param amount Amount of underlying asset to invest
/// @return amountsConsumed Consumed amounts of invested assets
function depositUnderlying(uint amount) external returns (uint[] memory amountsConsumed);
/// @dev For specified amount of shares and assets_, withdraw strategy assets from farm/pool/staking and send to receiver if possible
/// Only vault can call this.
/// @param assets_ Here we give the user a choice of assets to withdraw if strategy support it
/// @param value Part of strategy total value to withdraw
/// @param receiver User address
/// @return amountsOut Amounts of assets sent to user
function withdrawAssets(
address[] memory assets_,
uint value,
address receiver
) external returns (uint[] memory amountsOut);
/// @notice Wothdraw underlying invested and send to receiver
/// Only vault can call this.
/// @param amount Amount of underlying asset to withdraw
/// @param receiver User of vault which withdraw underlying from the vault
function withdrawUnderlying(uint amount, address receiver) external;
/// @dev For specified amount of shares, transfer strategy assets from contract balance and send to receiver if possible
/// This method is called by vault w/o underlying on triggered fuse mode.
/// Only vault can call this.
/// @param amount Amount of liquidity value that user withdraw
/// @param totalAmount Total amount of strategy liquidity
/// @param receiver User of vault which withdraw assets
/// @return amountsOut Amounts of strategy assets sent to user
function transferAssets(
uint amount,
uint totalAmount,
address receiver
) external returns (uint[] memory amountsOut);
/// @notice Execute HardWork
/// During HardWork strategy claiming revenue and processing it.
/// Only vault can call this.
function doHardWork() external;
/// @notice Emergency stop investing by strategy, withdraw liquidity without rewards.
/// This action triggers FUSE mode.
/// Only governance or multisig can call this.
function emergencyStopInvesting() external;
/// @notice Custom price impact tolerance instead default need for specific cases where low liquidity in pools
/// @param priceImpactTolerance Tolerance percent with 100_000 DENOMINATOR. 4_000 == 4%
function setCustomPriceImpactTolerance(uint priceImpactTolerance) external;
/// @notice Set custom strategy protocols
/// @param protocols_ Row format is: defi_organization_id:protocol_id from Stability Library.
function setProtocols(string[] calldata protocols_) external;
/// @notice Set custom specific name
function setSpecificName(string memory specific) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
/// @dev Mostly this interface need for front-end and tests for interacting with farming strategies
/// @author JodsMigel (https://github.com/JodsMigel)
interface IFarmingStrategy {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
event RewardsClaimed(uint[] amounts);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
error BadFarm();
error IncorrectStrategyId();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* DATA TYPES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @custom:storage-location erc7201:stability.FarmingStrategyBase
struct FarmingStrategyBaseStorage {
/// @inheritdoc IFarmingStrategy
uint farmId;
address[] _rewardAssets;
uint[] _rewardsOnBalance;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* VIEW FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Index of the farm used by initialized strategy
function farmId() external view returns (uint);
/// @notice Strategy can earn money on farm now
/// Some strategies can continue work and earn pool fees after ending of farm rewards.
function canFarm() external view returns (bool);
/// @notice Mechanics of receiving farming rewards
function farmMechanics() external view returns (string memory);
/// @notice Farming reward assets for claim and liquidate
/// @return Addresses of farm reward ERC20 tokens
function farmingAssets() external view returns (address[] memory);
/// @notice Address of pool for staking asset/underlying
function stakingPool() external view returns (address);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* WRITE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Update strategy farming reward assets from Factory
/// Only operator can call this
function refreshFarmingAssets() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
interface IRevenueRouter {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
event EpochFlip(uint periodEnded, uint totalStblRevenue);
event AddedUnit(uint unitIndex, UnitType unitType, string name, address feeTreasury);
event UpdatedUnit(uint unitIndex, UnitType unitType, string name, address feeTreasury);
event UnitEpochRevenue(uint periodEnded, string unitName, uint stblRevenue);
event ProcessUnitRevenue(uint unitIndex, uint stblGot);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
error WaitForNewPeriod();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* DATA TYPES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @custom:storage-location erc7201:stability.RevenueRouter
struct RevenueRouterStorage {
address stbl;
address xStbl;
address xStaking;
address feeTreasury;
uint xShare;
uint activePeriod;
uint pendingRevenue;
Unit[] units;
address[] aavePools;
EnumerableSet.AddressSet vaultsAccumulated;
}
enum UnitType {
Core,
AaveMarkets,
Assets
}
struct Unit {
UnitType unitType;
string name;
uint pendingRevenue;
address feeTreasury;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* GOV ACTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Add new Unit
function addUnit(UnitType unitType, string calldata name, address feeTreasury) external;
/// @notice Update Unit
function updateUnit(uint unitIndex, UnitType unitType, string calldata name, address feeTreasury) external;
/// @notice Setup Aave pool list
function setAavePools(address[] calldata pools) external;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* USER ACTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Update the epoch (period) -- callable once a week at >= Thursday 0 UTC
/// @return newPeriod The new period
function updatePeriod() external returns (uint newPeriod);
/// @notice Process platform fee in form of an asset
function processFeeAsset(address asset, uint amount) external;
/// @notice Process platform fee in form of an vault shares
function processFeeVault(address vault, uint amount) external;
/// @notice Claim unit fees and swap to STBL
function processUnitRevenue(uint unitIndex) external;
/// @notice Claim units fees and swap to STBL
function processUnitsRevenue() external;
/// @notice Withdraw assets from accumulated vaults and swap to STBL
function processAccumulatedVaults(uint maxVaultsForWithdraw) external;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* VIEW FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @notice Show all Units
function units() external view returns (Unit[] memory);
/// @notice The period used for rewarding
/// @return The block.timestamp divided by 1 week in seconds
function getPeriod() external view returns (uint);
/// @notice Current active period
function activePeriod() external view returns (uint);
/// @notice Accumulated STBL amount for next distribution by core unit (vault fees)
function pendingRevenue() external view returns (uint);
/// @notice Accumulated STBL amount for next distribution by unit
function pendingRevenue(uint unitIndex) external view returns (uint);
/// @notice Get Aave pool list to mintToTreasury calls
function aavePools() external view returns (address[] memory);
/// @notice Get vault addresses that contract hold on balance, but not withdrew yet
function vaultsAccumulated() external view returns (address[] memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
import {Arrays} from "../Arrays.sol";
import {Math} from "../math/Math.sol";
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
* - Set can be cleared (all elements removed) in O(n).
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* The following types are supported:
*
* - `bytes32` (`Bytes32Set`) since v3.3.0
* - `address` (`AddressSet`) since v3.3.0
* - `uint256` (`UintSet`) since v3.3.0
* - `string` (`StringSet`) since v5.4.0
* - `bytes` (`BytesSet`) since v5.4.0
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: This function has an unbounded cost that scales with set size. Developers should keep in mind that
* using it may render the function uncallable if the set grows to the point where clearing it consumes too much
* gas to fit in a block.
*/
function _clear(Set storage set) private {
uint256 len = _length(set);
for (uint256 i = 0; i < len; ++i) {
delete set._positions[set._values[i]];
}
Arrays.unsafeSetLength(set._values, 0);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
/**
* @dev Return a slice of the 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, uint256 start, uint256 end) private view returns (bytes32[] memory) {
unchecked {
end = Math.min(end, _length(set));
start = Math.min(start, end);
uint256 len = end - start;
bytes32[] memory result = new bytes32[](len);
for (uint256 i = 0; i < len; ++i) {
result[i] = Arrays.unsafeAccess(set._values, start + i).value;
}
return result;
}
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(Bytes32Set storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
/**
* @dev Return a slice of the 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, uint256 start, uint256 end) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner, start, end);
bytes32[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(AddressSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
/**
* @dev Return a slice of the 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, uint256 start, uint256 end) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner, start, end);
address[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(UintSet storage set) internal {
_clear(set._inner);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
/**
* @dev Return a slice of the 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, uint256 start, uint256 end) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner, start, end);
uint256[] memory result;
assembly ("memory-safe") {
result := store
}
return result;
}
struct StringSet {
// Storage of set values
string[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(string value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(StringSet storage set, string memory value) internal returns (bool) {
if (!contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(StringSet storage set, string memory value) internal returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
string memory lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(StringSet storage set) internal {
uint256 len = length(set);
for (uint256 i = 0; i < len; ++i) {
delete set._positions[set._values[i]];
}
Arrays.unsafeSetLength(set._values, 0);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(StringSet storage set, string memory value) internal view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(StringSet storage set) internal 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(StringSet storage set, uint256 index) internal view returns (string memory) {
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(StringSet storage set) internal view returns (string[] memory) {
return set._values;
}
/**
* @dev Return a slice of the 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(StringSet storage set, uint256 start, uint256 end) internal view returns (string[] memory) {
unchecked {
end = Math.min(end, length(set));
start = Math.min(start, end);
uint256 len = end - start;
string[] memory result = new string[](len);
for (uint256 i = 0; i < len; ++i) {
result[i] = Arrays.unsafeAccess(set._values, start + i).value;
}
return result;
}
}
struct BytesSet {
// Storage of set values
bytes[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(BytesSet storage set, bytes memory value) internal returns (bool) {
if (!contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(BytesSet storage set, bytes memory value) internal returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes memory lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Removes all the values from a set. O(n).
*
* WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
* function uncallable if the set grows to the point where clearing it consumes too much gas to fit in a block.
*/
function clear(BytesSet storage set) internal {
uint256 len = length(set);
for (uint256 i = 0; i < len; ++i) {
delete set._positions[set._values[i]];
}
Arrays.unsafeSetLength(set._values, 0);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(BytesSet storage set, bytes memory value) internal view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(BytesSet storage set) internal 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(BytesSet storage set, uint256 index) internal view returns (bytes memory) {
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(BytesSet storage set) internal view returns (bytes[] memory) {
return set._values;
}
/**
* @dev Return a slice of the 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(BytesSet storage set, uint256 start, uint256 end) internal view returns (bytes[] memory) {
unchecked {
end = Math.min(end, length(set));
start = Math.min(start, end);
uint256 len = end - start;
bytes[] memory result = new bytes[](len);
for (uint256 i = 0; i < len; ++i) {
result[i] = Arrays.unsafeAccess(set._values, start + i).value;
}
return result;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/Arrays.sol)
// This file was procedurally generated from scripts/generate/templates/Arrays.js.
pragma solidity ^0.8.20;
import {Comparators} from "./Comparators.sol";
import {SlotDerivation} from "./SlotDerivation.sol";
import {StorageSlot} from "./StorageSlot.sol";
import {Math} from "./math/Math.sol";
/**
* @dev Collection of functions related to array types.
*/
library Arrays {
using SlotDerivation for bytes32;
using StorageSlot for bytes32;
/**
* @dev Sort an array of uint256 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
uint256[] memory array,
function(uint256, uint256) pure returns (bool) comp
) internal pure returns (uint256[] memory) {
_quickSort(_begin(array), _end(array), comp);
return array;
}
/**
* @dev Variant of {sort} that sorts an array of uint256 in increasing order.
*/
function sort(uint256[] memory array) internal pure returns (uint256[] memory) {
sort(array, Comparators.lt);
return array;
}
/**
* @dev Sort an array of address (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
address[] memory array,
function(address, address) pure returns (bool) comp
) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of address in increasing order.
*/
function sort(address[] memory array) internal pure returns (address[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Sort an array of bytes32 (in memory) following the provided comparator function.
*
* This function does the sorting "in place", meaning that it overrides the input. The object is returned for
* convenience, but that returned value can be discarded safely if the caller has a memory pointer to the array.
*
* NOTE: this function's cost is `O(n · log(n))` in average and `O(n²)` in the worst case, with n the length of the
* array. Using it in view functions that are executed through `eth_call` is safe, but one should be very careful
* when executing this as part of a transaction. If the array being sorted is too large, the sort operation may
* consume more gas than is available in a block, leading to potential DoS.
*
* IMPORTANT: Consider memory side-effects when using custom comparator functions that access memory in an unsafe way.
*/
function sort(
bytes32[] memory array,
function(bytes32, bytes32) pure returns (bool) comp
) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), _castToUint256Comp(comp));
return array;
}
/**
* @dev Variant of {sort} that sorts an array of bytes32 in increasing order.
*/
function sort(bytes32[] memory array) internal pure returns (bytes32[] memory) {
sort(_castToUint256Array(array), Comparators.lt);
return array;
}
/**
* @dev Performs a quick sort of a segment of memory. The segment sorted starts at `begin` (inclusive), and stops
* at end (exclusive). Sorting follows the `comp` comparator.
*
* Invariant: `begin <= end`. This is the case when initially called by {sort} and is preserved in subcalls.
*
* IMPORTANT: Memory locations between `begin` and `end` are not validated/zeroed. This function should
* be used only if the limits are within a memory array.
*/
function _quickSort(uint256 begin, uint256 end, function(uint256, uint256) pure returns (bool) comp) private pure {
unchecked {
if (end - begin < 0x40) return;
// Use first element as pivot
uint256 pivot = _mload(begin);
// Position where the pivot should be at the end of the loop
uint256 pos = begin;
for (uint256 it = begin + 0x20; it < end; it += 0x20) {
if (comp(_mload(it), pivot)) {
// If the value stored at the iterator's position comes before the pivot, we increment the
// position of the pivot and move the value there.
pos += 0x20;
_swap(pos, it);
}
}
_swap(begin, pos); // Swap pivot into place
_quickSort(begin, pos, comp); // Sort the left side of the pivot
_quickSort(pos + 0x20, end, comp); // Sort the right side of the pivot
}
}
/**
* @dev Pointer to the memory location of the first element of `array`.
*/
function _begin(uint256[] memory array) private pure returns (uint256 ptr) {
assembly ("memory-safe") {
ptr := add(array, 0x20)
}
}
/**
* @dev Pointer to the memory location of the first memory word (32bytes) after `array`. This is the memory word
* that comes just after the last element of the array.
*/
function _end(uint256[] memory array) private pure returns (uint256 ptr) {
unchecked {
return _begin(array) + array.length * 0x20;
}
}
/**
* @dev Load memory word (as a uint256) at location `ptr`.
*/
function _mload(uint256 ptr) private pure returns (uint256 value) {
assembly {
value := mload(ptr)
}
}
/**
* @dev Swaps the elements memory location `ptr1` and `ptr2`.
*/
function _swap(uint256 ptr1, uint256 ptr2) private pure {
assembly {
let value1 := mload(ptr1)
let value2 := mload(ptr2)
mstore(ptr1, value2)
mstore(ptr2, value1)
}
}
/// @dev Helper: low level cast address memory array to uint256 memory array
function _castToUint256Array(address[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 memory array to uint256 memory array
function _castToUint256Array(bytes32[] memory input) private pure returns (uint256[] memory output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast address comp function to uint256 comp function
function _castToUint256Comp(
function(address, address) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/// @dev Helper: low level cast bytes32 comp function to uint256 comp function
function _castToUint256Comp(
function(bytes32, bytes32) pure returns (bool) input
) private pure returns (function(uint256, uint256) pure returns (bool) output) {
assembly {
output := input
}
}
/**
* @dev Searches a sorted `array` and returns the first index that contains
* a value greater or equal to `element`. If no such index exists (i.e. all
* values in the array are strictly less than `element`), the array length is
* returned. Time complexity O(log n).
*
* NOTE: The `array` is expected to be sorted in ascending order, and to
* contain no repeated elements.
*
* IMPORTANT: Deprecated. This implementation behaves as {lowerBound} but lacks
* support for repeated elements in the array. The {lowerBound} function should
* be used instead.
*/
function findUpperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
low = mid + 1;
}
}
// At this point `low` is the exclusive upper bound. We will return the inclusive upper bound.
if (low > 0 && unsafeAccess(array, low - 1).value == element) {
return low - 1;
} else {
return low;
}
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value greater or equal than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/lower_bound[lower_bound].
*/
function lowerBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Searches an `array` sorted in ascending order and returns the first
* index that contains a value strictly greater than `element`. If no such index
* exists (i.e. all values in the array are strictly less than `element`), the array
* length is returned. Time complexity O(log n).
*
* See C++'s https://en.cppreference.com/w/cpp/algorithm/upper_bound[upper_bound].
*/
function upperBound(uint256[] storage array, uint256 element) internal view returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeAccess(array, mid).value > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Same as {lowerBound}, but with an array in memory.
*/
function lowerBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) < element) {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
} else {
high = mid;
}
}
return low;
}
/**
* @dev Same as {upperBound}, but with an array in memory.
*/
function upperBoundMemory(uint256[] memory array, uint256 element) internal pure returns (uint256) {
uint256 low = 0;
uint256 high = array.length;
if (high == 0) {
return 0;
}
while (low < high) {
uint256 mid = Math.average(low, high);
// Note that mid will always be strictly less than high (i.e. it will be a valid array index)
// because Math.average rounds towards zero (it does integer division with truncation).
if (unsafeMemoryAccess(array, mid) > element) {
high = mid;
} else {
// this cannot overflow because mid < high
unchecked {
low = mid + 1;
}
}
}
return low;
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(address[] storage arr, uint256 pos) internal pure returns (StorageSlot.AddressSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getAddressSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes32[] storage arr, uint256 pos) internal pure returns (StorageSlot.Bytes32Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getBytes32Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(uint256[] storage arr, uint256 pos) internal pure returns (StorageSlot.Uint256Slot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getUint256Slot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(bytes[] storage arr, uint256 pos) internal pure returns (StorageSlot.BytesSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getBytesSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeAccess(string[] storage arr, uint256 pos) internal pure returns (StorageSlot.StringSlot storage) {
bytes32 slot;
assembly ("memory-safe") {
slot := arr.slot
}
return slot.deriveArray().offset(pos).getStringSlot();
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(address[] memory arr, uint256 pos) internal pure returns (address res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(bytes32[] memory arr, uint256 pos) internal pure returns (bytes32 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(uint256[] memory arr, uint256 pos) internal pure returns (uint256 res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(bytes[] memory arr, uint256 pos) internal pure returns (bytes memory res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Access an array in an "unsafe" way. Skips solidity "index-out-of-range" check.
*
* WARNING: Only use if you are certain `pos` is lower than the array length.
*/
function unsafeMemoryAccess(string[] memory arr, uint256 pos) internal pure returns (string memory res) {
assembly {
res := mload(add(add(arr, 0x20), mul(pos, 0x20)))
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(address[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes32[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(uint256[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
/**
* @dev Helper to set the length of a dynamic array. Directly writing to `.length` is forbidden.
*
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(string[] storage array, uint256 len) internal {
assembly ("memory-safe") {
sstore(array.slot, len)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Comparators.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides a set of functions to compare values.
*
* _Available since v5.1._
*/
library Comparators {
function lt(uint256 a, uint256 b) internal pure returns (bool) {
return a < b;
}
function gt(uint256 a, uint256 b) internal pure returns (bool) {
return a > b;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/SlotDerivation.sol)
// This file was procedurally generated from scripts/generate/templates/SlotDerivation.js.
pragma solidity ^0.8.20;
/**
* @dev Library for computing storage (and transient storage) locations from namespaces and deriving slots
* corresponding to standard patterns. The derivation method for array and mapping matches the storage layout used by
* the solidity language / compiler.
*
* See https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html#mappings-and-dynamic-arrays[Solidity docs for mappings and dynamic arrays.].
*
* Example usage:
* ```solidity
* contract Example {
* // Add the library methods
* using StorageSlot for bytes32;
* using SlotDerivation for bytes32;
*
* // Declare a namespace
* string private constant _NAMESPACE = "<namespace>"; // eg. OpenZeppelin.Slot
*
* function setValueInNamespace(uint256 key, address newValue) internal {
* _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value = newValue;
* }
*
* function getValueInNamespace(uint256 key) internal view returns (address) {
* return _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value;
* }
* }
* ```
*
* TIP: Consider using this library along with {StorageSlot}.
*
* NOTE: This library provides a way to manipulate storage locations in a non-standard way. Tooling for checking
* upgrade safety will ignore the slots accessed through this library.
*
* _Available since v5.1._
*/
library SlotDerivation {
/**
* @dev Derive an ERC-7201 slot from a string (namespace).
*/
function erc7201Slot(string memory namespace) internal pure returns (bytes32 slot) {
assembly ("memory-safe") {
mstore(0x00, sub(keccak256(add(namespace, 0x20), mload(namespace)), 1))
slot := and(keccak256(0x00, 0x20), not(0xff))
}
}
/**
* @dev Add an offset to a slot to get the n-th element of a structure or an array.
*/
function offset(bytes32 slot, uint256 pos) internal pure returns (bytes32 result) {
unchecked {
return bytes32(uint256(slot) + pos);
}
}
/**
* @dev Derive the location of the first element in an array from the slot where the length is stored.
*/
function deriveArray(bytes32 slot) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, slot)
result := keccak256(0x00, 0x20)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, address key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, and(key, shr(96, not(0))))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bool key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, iszero(iszero(key)))
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes32 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, uint256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, int256 key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, string memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
/**
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, bytes memory key) internal pure returns (bytes32 result) {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)
let cache := mload(end)
mstore(end, slot)
result := keccak256(begin, add(length, 0x20))
mstore(end, cache)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}{
"remappings": [
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@solady/=lib/solady/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
"solady/=lib/solady/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"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":[],"name":"IncorrectStrategyId","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"apr","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"compoundApr","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"earned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tvl","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"duration","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sharePrice","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"assetPrices","type":"uint256[]"}],"name":"HardWork","type":"event"},{"inputs":[{"internalType":"address[]","name":"assets_","type":"address[]"},{"internalType":"uint256[]","name":"amounts_","type":"uint256[]"}],"name":"assetsAmountsWithBalances","outputs":[{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"assets","type":"address[]"}],"name":"assetsAreOnBalance","outputs":[{"internalType":"bool","name":"isReady","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"balance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tvl","type":"uint256"},{"internalType":"uint256","name":"earned","type":"uint256"},{"internalType":"uint256","name":"duration","type":"uint256"}],"name":"computeApr","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"tvl","type":"uint256"},{"internalType":"int256","name":"earned","type":"int256"},{"internalType":"uint256","name":"duration","type":"uint256"}],"name":"computeAprInt","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"isPositiveAmountInArray","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]Contract Creation Code
61223f610034600b8282823980515f1a607314602857634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100f0575f3560e01c8063b9f637cd11610093578063e3d670d71161006e578063e3d670d71461023c578063efad27021461024f578063fe2d469414610262578063fede401f14610283575f5ffd5b8063b9f637cd146101eb578063e343fe121461020a578063e3d3b66d14610229575f5ffd5b80633da7b76c116100ce5780633da7b76c1461016b5780634ab3b02f1461017e578063640f24451461019f578063a9678a18146101be575f5ffd5b806308dc79a1146100f457806325567aef146101295780633596603f14610148575b5f5ffd5b8180156100ff575f5ffd5b5061011361010e3660046117ec565b6102a2565b60405161012091906118ad565b60405180910390f35b818015610134575f5ffd5b506101136101433660046118bf565b61064f565b61015b6101563660046118fd565b610807565b6040519015158152602001610120565b61015b610179366004611936565b610850565b818015610189575f5ffd5b5061019d61019836600461198d565b610901565b005b8180156101aa575f5ffd5b5061019d6101b9366004611a22565b610a7b565b8180156101c9575f5ffd5b506101dd6101d8366004611ab1565b610c9a565b604051908152602001610120565b8180156101f6575f5ffd5b506101dd610205366004611aef565b610d8b565b818015610215575f5ffd5b506101dd610224366004611b7d565b610fdc565b6101dd610237366004611bd4565b6110cc565b6101dd61024a366004611bfd565b611150565b6101dd61025d366004611bd4565b6111be565b610275610270366004611c18565b611238565b604051610120929190611c7b565b81801561028e575f5ffd5b5061019d61029d366004611cd1565b611297565b60605f6040518060600160405280876001600160a01b031681526020015f81526020015f8152509050805f01516001600160a01b031663db8d55f16040518163ffffffff1660e01b8152600401608060405180830381865afa15801561030a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061032e9190611cff565b50505060208201528051604051630eaada1760e21b81526001600160a01b03878116600483015290911690633aab685c90602401602060405180830381865afa92505050801561039b575060408051601f3d908101601f1916820190925261039891810190611d32565b60015b156103b05780156103ae57602082018190525b505b8351806001600160401b038111156103ca576103ca611690565b6040519080825280602002602001820160405280156103f3578160200160208202803683370190505b5092505f5b8181101561064457620186a0836020015186838151811061041b5761041b611d49565b602002602001015161042d9190611d71565b6104379190611d9c565b60408401819052865161046d91906104689089908590811061045b5761045b611d49565b6020026020010151611150565b611438565b604084018190521561063c57825f01516001600160a01b031663e88558126040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156104d6575060408051601f3d908101601f191682019092526104d391810190611dba565b60015b156105a4576105168185604001518985815181106104f6576104f6611d49565b60200260200101516001600160a01b03166114479092919063ffffffff16565b806001600160a01b031663a2b5044788848151811061053757610537611d49565b602002602001015186604001516040518363ffffffff1660e01b81526004016105759291906001600160a01b03929092168252602082015260400190565b5f604051808303815f87803b15801561058c575f5ffd5b505af115801561059e573d5f5f3e3d5ffd5b50505050505b82604001518582815181106105bb576105bb611d49565b60200260200101516105cd9190611dd5565b8482815181106105df576105df611d49565b60200260200101818152505061061d84828151811061060057610600611d49565b602002602001015161046888848151811061045b5761045b611d49565b84828151811061062f5761062f611d49565b6020026020010181815250505b6001016103f8565b505050949350505050565b60605f856005018054806020026020016040519081016040528092919081815260200182805480156106a857602002820191905f5260205f20905b81546001600160a01b0316815260019091019060200180831161068a575b5050835193945083925050506001600160401b038111156106cb576106cb611690565b6040519080825280602002602001820160405280156106f4578160200160208202803683370190505b5092505f5b8181101561064457858761071885848151811061045b5761045b611d49565b6107229190611d71565b61072c9190611d9c565b84828151811061073e5761073e611d49565b60200260200101818152505082818151811061075c5761075c611d49565b60200260200101516001600160a01b031663a9059cbb8686848151811061078557610785611d49565b60200260200101516040518363ffffffff1660e01b81526004016107be9291906001600160a01b03929092168252602082015260400190565b6020604051808303815f875af11580156107da573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107fe9190611df7565b506001016106f9565b80515f90815b818110156108475783818151811061082757610827611d49565b60200260200101515f1461083f575060019392505050565b60010161080d565b505f9392505050565b80515f90815b818110156108fa575f84828151811061087157610871611d49565b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156108bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108e39190611d32565b11156108f257600192506108fa565b600101610856565b5050919050565b80845f01819055505f826001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015610946573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061096a9190611dba565b6001600160a01b031663538a85a1836040518263ffffffff1660e01b815260040161099791815260200190565b5f60405180830381865afa1580156109b1573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526109d89190810190611f85565b9050838051906020012081604001518051906020012014610a0c576040516352cf57fb60e11b815260040160405180910390fd5b610a168584611297565b8060600151516001600160401b03811115610a3357610a33611690565b604051908082528060200260200182016040528015610a5c578160200160208202803683370190505b508051610a739160028801916020909101906115b9565b505050505050565b5f866002015442610a8c9190611dd5565b90505f866001600160a01b03166349b5fdb46040518163ffffffff1660e01b8152600401602060405180830381865afa158015610acb573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610aef9190611dba565b90505f5f826001600160a01b031663a36fba3289896040518363ffffffff1660e01b8152600401610b21929190611c7b565b5f60405180830381865afa158015610b3b573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610b6291908101906120b2565b5092505091505f610b748784876110cc565b90505f865f03610b845781610b9e565b610b9e87888e60010154610b989190611dd5565b886110cc565b90505f8c5f015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bf2573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c169190611d32565b610c288a670de0b6b3a7640000611d71565b610c329190611d9c565b90507fbaf1e6aa8c7f916f68c03ad59d65f22ed7fb0cdfa8e8ae2322b818d34c64e3a08383878c8b868a604051610c6f979695949392919061212f565b60405180910390a15060038c019190915560048b015550504260029098019790975550505050505050565b5f5f610ca584611150565b90505f866001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ce4573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d089190611dba565b604051637f0148ab60e11b81529091506001600160a01b0382169063fe02915690610d3f908990899089906103e890600401612172565b5f604051808303815f87803b158015610d56575f5ffd5b505af1158015610d68573d5f5f3e3d5ffd5b5050505081610d7686611150565b610d809190611dd5565b979650505050505050565b5f5f866001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc9573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ded9190611dba565b85519091505f610dfc88611150565b90505f5b82811015610fb757836001600160a01b031663c86ec2bf898381518110610e2957610e29611d49565b60200260200101516040518263ffffffff1660e01b8152600401610e5c91906001600160a01b0391909116815260200190565b602060405180830381865afa158015610e77573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e9b9190611d32565b878281518110610ead57610ead611d49565b60200260200101511115610faf57886001600160a01b0316888281518110610ed757610ed7611d49565b60200260200101516001600160a01b031614610fab57836001600160a01b031663fe029156898381518110610f0e57610f0e611d49565b60200260200101518b610f498b8681518110610f2c57610f2c611d49565b60200260200101516104688e888151811061045b5761045b611d49565b8a5f03610f5857611b58610f5a565b8a5b6040518563ffffffff1660e01b8152600401610f799493929190612172565b5f604051808303815f87803b158015610f90575f5ffd5b505af1158015610fa2573d5f5f3e3d5ffd5b50505050610faf565b5f91505b600101610e00565b505f610fc289611150565b9050610fce8282611dd5565b9a9950505050505050505050565b5f5f610fe785611150565b90505f876001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015611026573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061104a9190611dba565b604051637f0148ab60e11b81529091506001600160a01b0382169063fe0291569061107f908a908a908a908a90600401612172565b5f604051808303815f87803b158015611096575f5ffd5b505af11580156110a8573d5f5f3e3d5ffd5b50505050816110b687611150565b6110c09190611dd5565b98975050505050505050565b5f8315806110d8575081155b156110e457505f611149565b620151806110fa83670de0b6b3a7640000611d71565b6111049190611d9c565b8461016d620186a061111e87670de0b6b3a7640000611d71565b6111289190611d71565b6111329190611d71565b61113c9190611d9c565b6111469190611d9c565b90505b9392505050565b6040516370a0823160e01b81523060048201525f906001600160a01b038316906370a0823190602401602060405180830381865afa158015611194573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111b89190611d32565b92915050565b5f8315806111ca575081155b156111d657505f611149565b620151806111ec83670de0b6b3a7640000611d71565b6111f69190611d9c565b8461016d620186a0611210670de0b6b3a76400008861219b565b61121a919061219b565b611224919061219b565b61122e91906121ca565b61114691906121ca565b8151829082905f5b8181101561128e5761125d86828151811061045b5761045b611d49565b83828151811061126f5761126f611d49565b6020026020010181815161128391906121f6565b905250600101611240565b50509250929050565b5f816001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112d4573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112f89190611dba565b835460405163538a85a160e01b81526001600160a01b03929092169163538a85a19161132a9160040190815260200190565b5f60405180830381865afa158015611344573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261136b9190810190611f85565b90505f826001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113aa573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113ce9190611dba565b606083015180519192506113ea91600187019160200190611602565b506060820151515f5b8181101561141f57611417835f19866060015184815181106104f6576104f6611d49565b6001016113f3565b50806001600160401b03811115610a3357610a33611690565b5f828218828410028218611149565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526114988482611500565b6114fa57604080516001600160a01b03851660248201525f6044808301919091528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526114f0908590611549565b6114fa8482611549565b50505050565b5f5f5f5f60205f8651602088015f8a5af192503d91505f51905082801561153f57508115611531578060011461153f565b5f866001600160a01b03163b115b9695505050505050565b5f5f60205f8451602086015f885af180611568576040513d5f823e3d81fd5b50505f513d9150811561157f57806001141561158c565b6001600160a01b0384163b155b156114fa57604051635274afe760e01b81526001600160a01b038516600482015260240160405180910390fd5b828054828255905f5260205f209081019282156115f2579160200282015b828111156115f25782518255916020019190600101906115d7565b506115fe929150611655565b5090565b828054828255905f5260205f209081019282156115f2579160200282015b828111156115f257825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190611620565b5b808211156115fe575f8155600101611656565b6001600160a01b038116811461167d575f5ffd5b50565b803561168b81611669565b919050565b634e487b7160e01b5f52604160045260245ffd5b60405160e081016001600160401b03811182821017156116c6576116c6611690565b60405290565b604051601f8201601f191681016001600160401b03811182821017156116f4576116f4611690565b604052919050565b5f6001600160401b0382111561171457611714611690565b5060051b60200190565b5f82601f83011261172d575f5ffd5b813561174061173b826116fc565b6116cc565b8082825260208201915060208360051b860101925085831115611761575f5ffd5b602085015b8381101561178757803561177981611669565b835260209283019201611766565b5095945050505050565b5f82601f8301126117a0575f5ffd5b81356117ae61173b826116fc565b8082825260208201915060208360051b8601019250858311156117cf575f5ffd5b602085015b838110156117875780358352602092830192016117d4565b5f5f5f5f608085870312156117ff575f5ffd5b843561180a81611669565b9350602085013561181a81611669565b925060408501356001600160401b03811115611834575f5ffd5b6118408782880161171e565b92505060608501356001600160401b0381111561185b575f5ffd5b61186787828801611791565b91505092959194509250565b5f8151808452602084019350602083015f5b828110156118a3578151865260209586019590910190600101611885565b5093949350505050565b602081525f6111496020830184611873565b5f5f5f5f608085870312156118d2575f5ffd5b84359350602085013592506040850135915060608501356118f281611669565b939692955090935050565b5f6020828403121561190d575f5ffd5b81356001600160401b03811115611922575f5ffd5b61192e84828501611791565b949350505050565b5f60208284031215611946575f5ffd5b81356001600160401b0381111561195b575f5ffd5b61192e8482850161171e565b5f6001600160401b0382111561197f5761197f611690565b50601f01601f191660200190565b5f5f5f5f608085870312156119a0575f5ffd5b8435935060208501356001600160401b038111156119bc575f5ffd5b8501601f810187136119cc575f5ffd5b80356119da61173b82611967565b8181528860208385010111156119ee575f5ffd5b816020840160208301375f60208383010152809550505050611a1260408601611680565b9396929550929360600135925050565b5f5f5f5f5f5f60c08789031215611a37575f5ffd5b863595506020870135611a4981611669565b945060408701356001600160401b03811115611a63575f5ffd5b611a6f89828a0161171e565b94505060608701356001600160401b03811115611a8a575f5ffd5b611a9689828a01611791565b9699959850939660808101359560a090910135945092505050565b5f5f5f5f60808587031215611ac4575f5ffd5b8435611acf81611669565b93506020850135611adf81611669565b92506040850135611a1281611669565b5f5f5f5f5f60a08688031215611b03575f5ffd5b8535611b0e81611669565b94506020860135611b1e81611669565b935060408601356001600160401b03811115611b38575f5ffd5b611b448882890161171e565b93505060608601356001600160401b03811115611b5f575f5ffd5b611b6b88828901611791565b95989497509295608001359392505050565b5f5f5f5f5f60a08688031215611b91575f5ffd5b8535611b9c81611669565b94506020860135611bac81611669565b93506040860135611bbc81611669565b94979396509394606081013594506080013592915050565b5f5f5f60608486031215611be6575f5ffd5b505081359360208301359350604090920135919050565b5f60208284031215611c0d575f5ffd5b813561114981611669565b5f5f60408385031215611c29575f5ffd5b82356001600160401b03811115611c3e575f5ffd5b611c4a8582860161171e565b92505060208301356001600160401b03811115611c65575f5ffd5b611c7185828601611791565b9150509250929050565b604080825283519082018190525f9060208501906060840190835b81811015611cbd5783516001600160a01b0316835260209384019390920191600101611c96565b5050838103602085015261153f8186611873565b5f5f60408385031215611ce2575f5ffd5b823591506020830135611cf481611669565b809150509250929050565b5f5f5f5f60808587031215611d12575f5ffd5b505082516020840151604085015160609095015191969095509092509050565b5f60208284031215611d42575f5ffd5b5051919050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176111b8576111b8611d5d565b634e487b7160e01b5f52601260045260245ffd5b5f82611daa57611daa611d88565b500490565b805161168b81611669565b5f60208284031215611dca575f5ffd5b815161114981611669565b818103818111156111b8576111b8611d5d565b8051801515811461168b575f5ffd5b5f60208284031215611e07575f5ffd5b61114982611de8565b5f82601f830112611e1f575f5ffd5b8151611e2d61173b82611967565b818152846020838601011115611e41575f5ffd5b8160208501602083015e5f918101602001919091529392505050565b5f82601f830112611e6c575f5ffd5b8151611e7a61173b826116fc565b8082825260208201915060208360051b860101925085831115611e9b575f5ffd5b602085015b83811015611787578051611eb381611669565b835260209283019201611ea0565b5f82601f830112611ed0575f5ffd5b8151611ede61173b826116fc565b8082825260208201915060208360051b860101925085831115611eff575f5ffd5b602085015b83811015611787578051835260209283019201611f04565b5f82601f830112611f2b575f5ffd5b8151611f3961173b826116fc565b8082825260208201915060208360051b860101925085831115611f5a575f5ffd5b602085015b838110156117875780518060020b8114611f77575f5ffd5b835260209283019201611f5f565b5f60208284031215611f95575f5ffd5b81516001600160401b03811115611faa575f5ffd5b820160e08185031215611fbb575f5ffd5b611fc36116a4565b81518152611fd360208301611daf565b602082015260408201516001600160401b03811115611ff0575f5ffd5b611ffc86828501611e10565b60408301525060608201516001600160401b0381111561201a575f5ffd5b61202686828501611e5d565b60608301525060808201516001600160401b03811115612044575f5ffd5b61205086828501611e5d565b60808301525060a08201516001600160401b0381111561206e575f5ffd5b61207a86828501611ec1565b60a08301525060c08201516001600160401b03811115612098575f5ffd5b6120a486828501611f1c565b60c083015250949350505050565b5f5f5f5f608085870312156120c5575f5ffd5b845160208601519094506001600160401b038111156120e2575f5ffd5b6120ee87828801611ec1565b93505060408501516001600160401b03811115612109575f5ffd5b61211587828801611ec1565b92505061212460608601611de8565b905092959194509250565b8781528660208201528560408201528460608201528360808201528260a082015260e060c08201525f61216560e0830184611873565b9998505050505050505050565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b8082025f8212600160ff1b841416156121b6576121b6611d5d565b81810583148215176111b8576111b8611d5d565b5f826121d8576121d8611d88565b600160ff1b82145f19841416156121f1576121f1611d5d565b500590565b808201808211156111b8576111b8611d5d56fea264697066735822122026d3d4efae185e8cb978a41b19fee5de72eb27ac818bf6582afc1d401c11e42264736f6c634300081c0033
Deployed Bytecode
0x7313d579335a6bf08ff312087486ee63bae79d249630146080604052600436106100f0575f3560e01c8063b9f637cd11610093578063e3d670d71161006e578063e3d670d71461023c578063efad27021461024f578063fe2d469414610262578063fede401f14610283575f5ffd5b8063b9f637cd146101eb578063e343fe121461020a578063e3d3b66d14610229575f5ffd5b80633da7b76c116100ce5780633da7b76c1461016b5780634ab3b02f1461017e578063640f24451461019f578063a9678a18146101be575f5ffd5b806308dc79a1146100f457806325567aef146101295780633596603f14610148575b5f5ffd5b8180156100ff575f5ffd5b5061011361010e3660046117ec565b6102a2565b60405161012091906118ad565b60405180910390f35b818015610134575f5ffd5b506101136101433660046118bf565b61064f565b61015b6101563660046118fd565b610807565b6040519015158152602001610120565b61015b610179366004611936565b610850565b818015610189575f5ffd5b5061019d61019836600461198d565b610901565b005b8180156101aa575f5ffd5b5061019d6101b9366004611a22565b610a7b565b8180156101c9575f5ffd5b506101dd6101d8366004611ab1565b610c9a565b604051908152602001610120565b8180156101f6575f5ffd5b506101dd610205366004611aef565b610d8b565b818015610215575f5ffd5b506101dd610224366004611b7d565b610fdc565b6101dd610237366004611bd4565b6110cc565b6101dd61024a366004611bfd565b611150565b6101dd61025d366004611bd4565b6111be565b610275610270366004611c18565b611238565b604051610120929190611c7b565b81801561028e575f5ffd5b5061019d61029d366004611cd1565b611297565b60605f6040518060600160405280876001600160a01b031681526020015f81526020015f8152509050805f01516001600160a01b031663db8d55f16040518163ffffffff1660e01b8152600401608060405180830381865afa15801561030a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061032e9190611cff565b50505060208201528051604051630eaada1760e21b81526001600160a01b03878116600483015290911690633aab685c90602401602060405180830381865afa92505050801561039b575060408051601f3d908101601f1916820190925261039891810190611d32565b60015b156103b05780156103ae57602082018190525b505b8351806001600160401b038111156103ca576103ca611690565b6040519080825280602002602001820160405280156103f3578160200160208202803683370190505b5092505f5b8181101561064457620186a0836020015186838151811061041b5761041b611d49565b602002602001015161042d9190611d71565b6104379190611d9c565b60408401819052865161046d91906104689089908590811061045b5761045b611d49565b6020026020010151611150565b611438565b604084018190521561063c57825f01516001600160a01b031663e88558126040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156104d6575060408051601f3d908101601f191682019092526104d391810190611dba565b60015b156105a4576105168185604001518985815181106104f6576104f6611d49565b60200260200101516001600160a01b03166114479092919063ffffffff16565b806001600160a01b031663a2b5044788848151811061053757610537611d49565b602002602001015186604001516040518363ffffffff1660e01b81526004016105759291906001600160a01b03929092168252602082015260400190565b5f604051808303815f87803b15801561058c575f5ffd5b505af115801561059e573d5f5f3e3d5ffd5b50505050505b82604001518582815181106105bb576105bb611d49565b60200260200101516105cd9190611dd5565b8482815181106105df576105df611d49565b60200260200101818152505061061d84828151811061060057610600611d49565b602002602001015161046888848151811061045b5761045b611d49565b84828151811061062f5761062f611d49565b6020026020010181815250505b6001016103f8565b505050949350505050565b60605f856005018054806020026020016040519081016040528092919081815260200182805480156106a857602002820191905f5260205f20905b81546001600160a01b0316815260019091019060200180831161068a575b5050835193945083925050506001600160401b038111156106cb576106cb611690565b6040519080825280602002602001820160405280156106f4578160200160208202803683370190505b5092505f5b8181101561064457858761071885848151811061045b5761045b611d49565b6107229190611d71565b61072c9190611d9c565b84828151811061073e5761073e611d49565b60200260200101818152505082818151811061075c5761075c611d49565b60200260200101516001600160a01b031663a9059cbb8686848151811061078557610785611d49565b60200260200101516040518363ffffffff1660e01b81526004016107be9291906001600160a01b03929092168252602082015260400190565b6020604051808303815f875af11580156107da573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107fe9190611df7565b506001016106f9565b80515f90815b818110156108475783818151811061082757610827611d49565b60200260200101515f1461083f575060019392505050565b60010161080d565b505f9392505050565b80515f90815b818110156108fa575f84828151811061087157610871611d49565b60209081029190910101516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa1580156108bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108e39190611d32565b11156108f257600192506108fa565b600101610856565b5050919050565b80845f01819055505f826001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015610946573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061096a9190611dba565b6001600160a01b031663538a85a1836040518263ffffffff1660e01b815260040161099791815260200190565b5f60405180830381865afa1580156109b1573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526109d89190810190611f85565b9050838051906020012081604001518051906020012014610a0c576040516352cf57fb60e11b815260040160405180910390fd5b610a168584611297565b8060600151516001600160401b03811115610a3357610a33611690565b604051908082528060200260200182016040528015610a5c578160200160208202803683370190505b508051610a739160028801916020909101906115b9565b505050505050565b5f866002015442610a8c9190611dd5565b90505f866001600160a01b03166349b5fdb46040518163ffffffff1660e01b8152600401602060405180830381865afa158015610acb573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610aef9190611dba565b90505f5f826001600160a01b031663a36fba3289896040518363ffffffff1660e01b8152600401610b21929190611c7b565b5f60405180830381865afa158015610b3b573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610b6291908101906120b2565b5092505091505f610b748784876110cc565b90505f865f03610b845781610b9e565b610b9e87888e60010154610b989190611dd5565b886110cc565b90505f8c5f015f9054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bf2573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c169190611d32565b610c288a670de0b6b3a7640000611d71565b610c329190611d9c565b90507fbaf1e6aa8c7f916f68c03ad59d65f22ed7fb0cdfa8e8ae2322b818d34c64e3a08383878c8b868a604051610c6f979695949392919061212f565b60405180910390a15060038c019190915560048b015550504260029098019790975550505050505050565b5f5f610ca584611150565b90505f866001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ce4573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d089190611dba565b604051637f0148ab60e11b81529091506001600160a01b0382169063fe02915690610d3f908990899089906103e890600401612172565b5f604051808303815f87803b158015610d56575f5ffd5b505af1158015610d68573d5f5f3e3d5ffd5b5050505081610d7686611150565b610d809190611dd5565b979650505050505050565b5f5f866001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015610dc9573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ded9190611dba565b85519091505f610dfc88611150565b90505f5b82811015610fb757836001600160a01b031663c86ec2bf898381518110610e2957610e29611d49565b60200260200101516040518263ffffffff1660e01b8152600401610e5c91906001600160a01b0391909116815260200190565b602060405180830381865afa158015610e77573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e9b9190611d32565b878281518110610ead57610ead611d49565b60200260200101511115610faf57886001600160a01b0316888281518110610ed757610ed7611d49565b60200260200101516001600160a01b031614610fab57836001600160a01b031663fe029156898381518110610f0e57610f0e611d49565b60200260200101518b610f498b8681518110610f2c57610f2c611d49565b60200260200101516104688e888151811061045b5761045b611d49565b8a5f03610f5857611b58610f5a565b8a5b6040518563ffffffff1660e01b8152600401610f799493929190612172565b5f604051808303815f87803b158015610f90575f5ffd5b505af1158015610fa2573d5f5f3e3d5ffd5b50505050610faf565b5f91505b600101610e00565b505f610fc289611150565b9050610fce8282611dd5565b9a9950505050505050505050565b5f5f610fe785611150565b90505f876001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015611026573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061104a9190611dba565b604051637f0148ab60e11b81529091506001600160a01b0382169063fe0291569061107f908a908a908a908a90600401612172565b5f604051808303815f87803b158015611096575f5ffd5b505af11580156110a8573d5f5f3e3d5ffd5b50505050816110b687611150565b6110c09190611dd5565b98975050505050505050565b5f8315806110d8575081155b156110e457505f611149565b620151806110fa83670de0b6b3a7640000611d71565b6111049190611d9c565b8461016d620186a061111e87670de0b6b3a7640000611d71565b6111289190611d71565b6111329190611d71565b61113c9190611d9c565b6111469190611d9c565b90505b9392505050565b6040516370a0823160e01b81523060048201525f906001600160a01b038316906370a0823190602401602060405180830381865afa158015611194573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906111b89190611d32565b92915050565b5f8315806111ca575081155b156111d657505f611149565b620151806111ec83670de0b6b3a7640000611d71565b6111f69190611d9c565b8461016d620186a0611210670de0b6b3a76400008861219b565b61121a919061219b565b611224919061219b565b61122e91906121ca565b61114691906121ca565b8151829082905f5b8181101561128e5761125d86828151811061045b5761045b611d49565b83828151811061126f5761126f611d49565b6020026020010181815161128391906121f6565b905250600101611240565b50509250929050565b5f816001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156112d4573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112f89190611dba565b835460405163538a85a160e01b81526001600160a01b03929092169163538a85a19161132a9160040190815260200190565b5f60405180830381865afa158015611344573d5f5f3e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261136b9190810190611f85565b90505f826001600160a01b0316632b3297f96040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113aa573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113ce9190611dba565b606083015180519192506113ea91600187019160200190611602565b506060820151515f5b8181101561141f57611417835f19866060015184815181106104f6576104f6611d49565b6001016113f3565b50806001600160401b03811115610a3357610a33611690565b5f828218828410028218611149565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526114988482611500565b6114fa57604080516001600160a01b03851660248201525f6044808301919091528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526114f0908590611549565b6114fa8482611549565b50505050565b5f5f5f5f60205f8651602088015f8a5af192503d91505f51905082801561153f57508115611531578060011461153f565b5f866001600160a01b03163b115b9695505050505050565b5f5f60205f8451602086015f885af180611568576040513d5f823e3d81fd5b50505f513d9150811561157f57806001141561158c565b6001600160a01b0384163b155b156114fa57604051635274afe760e01b81526001600160a01b038516600482015260240160405180910390fd5b828054828255905f5260205f209081019282156115f2579160200282015b828111156115f25782518255916020019190600101906115d7565b506115fe929150611655565b5090565b828054828255905f5260205f209081019282156115f2579160200282015b828111156115f257825182546001600160a01b0319166001600160a01b03909116178255602090920191600190910190611620565b5b808211156115fe575f8155600101611656565b6001600160a01b038116811461167d575f5ffd5b50565b803561168b81611669565b919050565b634e487b7160e01b5f52604160045260245ffd5b60405160e081016001600160401b03811182821017156116c6576116c6611690565b60405290565b604051601f8201601f191681016001600160401b03811182821017156116f4576116f4611690565b604052919050565b5f6001600160401b0382111561171457611714611690565b5060051b60200190565b5f82601f83011261172d575f5ffd5b813561174061173b826116fc565b6116cc565b8082825260208201915060208360051b860101925085831115611761575f5ffd5b602085015b8381101561178757803561177981611669565b835260209283019201611766565b5095945050505050565b5f82601f8301126117a0575f5ffd5b81356117ae61173b826116fc565b8082825260208201915060208360051b8601019250858311156117cf575f5ffd5b602085015b838110156117875780358352602092830192016117d4565b5f5f5f5f608085870312156117ff575f5ffd5b843561180a81611669565b9350602085013561181a81611669565b925060408501356001600160401b03811115611834575f5ffd5b6118408782880161171e565b92505060608501356001600160401b0381111561185b575f5ffd5b61186787828801611791565b91505092959194509250565b5f8151808452602084019350602083015f5b828110156118a3578151865260209586019590910190600101611885565b5093949350505050565b602081525f6111496020830184611873565b5f5f5f5f608085870312156118d2575f5ffd5b84359350602085013592506040850135915060608501356118f281611669565b939692955090935050565b5f6020828403121561190d575f5ffd5b81356001600160401b03811115611922575f5ffd5b61192e84828501611791565b949350505050565b5f60208284031215611946575f5ffd5b81356001600160401b0381111561195b575f5ffd5b61192e8482850161171e565b5f6001600160401b0382111561197f5761197f611690565b50601f01601f191660200190565b5f5f5f5f608085870312156119a0575f5ffd5b8435935060208501356001600160401b038111156119bc575f5ffd5b8501601f810187136119cc575f5ffd5b80356119da61173b82611967565b8181528860208385010111156119ee575f5ffd5b816020840160208301375f60208383010152809550505050611a1260408601611680565b9396929550929360600135925050565b5f5f5f5f5f5f60c08789031215611a37575f5ffd5b863595506020870135611a4981611669565b945060408701356001600160401b03811115611a63575f5ffd5b611a6f89828a0161171e565b94505060608701356001600160401b03811115611a8a575f5ffd5b611a9689828a01611791565b9699959850939660808101359560a090910135945092505050565b5f5f5f5f60808587031215611ac4575f5ffd5b8435611acf81611669565b93506020850135611adf81611669565b92506040850135611a1281611669565b5f5f5f5f5f60a08688031215611b03575f5ffd5b8535611b0e81611669565b94506020860135611b1e81611669565b935060408601356001600160401b03811115611b38575f5ffd5b611b448882890161171e565b93505060608601356001600160401b03811115611b5f575f5ffd5b611b6b88828901611791565b95989497509295608001359392505050565b5f5f5f5f5f60a08688031215611b91575f5ffd5b8535611b9c81611669565b94506020860135611bac81611669565b93506040860135611bbc81611669565b94979396509394606081013594506080013592915050565b5f5f5f60608486031215611be6575f5ffd5b505081359360208301359350604090920135919050565b5f60208284031215611c0d575f5ffd5b813561114981611669565b5f5f60408385031215611c29575f5ffd5b82356001600160401b03811115611c3e575f5ffd5b611c4a8582860161171e565b92505060208301356001600160401b03811115611c65575f5ffd5b611c7185828601611791565b9150509250929050565b604080825283519082018190525f9060208501906060840190835b81811015611cbd5783516001600160a01b0316835260209384019390920191600101611c96565b5050838103602085015261153f8186611873565b5f5f60408385031215611ce2575f5ffd5b823591506020830135611cf481611669565b809150509250929050565b5f5f5f5f60808587031215611d12575f5ffd5b505082516020840151604085015160609095015191969095509092509050565b5f60208284031215611d42575f5ffd5b5051919050565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b80820281158282048414176111b8576111b8611d5d565b634e487b7160e01b5f52601260045260245ffd5b5f82611daa57611daa611d88565b500490565b805161168b81611669565b5f60208284031215611dca575f5ffd5b815161114981611669565b818103818111156111b8576111b8611d5d565b8051801515811461168b575f5ffd5b5f60208284031215611e07575f5ffd5b61114982611de8565b5f82601f830112611e1f575f5ffd5b8151611e2d61173b82611967565b818152846020838601011115611e41575f5ffd5b8160208501602083015e5f918101602001919091529392505050565b5f82601f830112611e6c575f5ffd5b8151611e7a61173b826116fc565b8082825260208201915060208360051b860101925085831115611e9b575f5ffd5b602085015b83811015611787578051611eb381611669565b835260209283019201611ea0565b5f82601f830112611ed0575f5ffd5b8151611ede61173b826116fc565b8082825260208201915060208360051b860101925085831115611eff575f5ffd5b602085015b83811015611787578051835260209283019201611f04565b5f82601f830112611f2b575f5ffd5b8151611f3961173b826116fc565b8082825260208201915060208360051b860101925085831115611f5a575f5ffd5b602085015b838110156117875780518060020b8114611f77575f5ffd5b835260209283019201611f5f565b5f60208284031215611f95575f5ffd5b81516001600160401b03811115611faa575f5ffd5b820160e08185031215611fbb575f5ffd5b611fc36116a4565b81518152611fd360208301611daf565b602082015260408201516001600160401b03811115611ff0575f5ffd5b611ffc86828501611e10565b60408301525060608201516001600160401b0381111561201a575f5ffd5b61202686828501611e5d565b60608301525060808201516001600160401b03811115612044575f5ffd5b61205086828501611e5d565b60808301525060a08201516001600160401b0381111561206e575f5ffd5b61207a86828501611ec1565b60a08301525060c08201516001600160401b03811115612098575f5ffd5b6120a486828501611f1c565b60c083015250949350505050565b5f5f5f5f608085870312156120c5575f5ffd5b845160208601519094506001600160401b038111156120e2575f5ffd5b6120ee87828801611ec1565b93505060408501516001600160401b03811115612109575f5ffd5b61211587828801611ec1565b92505061212460608601611de8565b905092959194509250565b8781528660208201528560408201528460608201528360808201528260a082015260e060c08201525f61216560e0830184611873565b9998505050505050505050565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b8082025f8212600160ff1b841416156121b6576121b6611d5d565b81810583148215176111b8576111b8611d5d565b5f826121d8576121d8611d88565b600160ff1b82145f19841416156121f1576121f1611d5d565b500590565b808201808211156111b8576111b8611d5d56fea264697066735822122026d3d4efae185e8cb978a41b19fee5de72eb27ac818bf6582afc1d401c11e42264736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in S
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
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.