Source Code
Latest 25 from a total of 150 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Update To Edge | 60675321 | 7 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 60663742 | 7 days ago | IN | 0 S | 0.03363066 | ||||
| Update To Edge | 60657672 | 7 days ago | IN | 0 S | 0.10308841 | ||||
| Update To Edge | 60626081 | 7 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 60608924 | 8 days ago | IN | 0 S | 0.03126988 | ||||
| Update To Edge | 60522403 | 9 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 60463569 | 10 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 60456886 | 10 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 60453337 | 10 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 60437135 | 11 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 60434525 | 11 days ago | IN | 0 S | 0.02899195 | ||||
| Update To Edge | 59716141 | 20 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59712367 | 20 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59709250 | 20 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59706462 | 20 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59699712 | 20 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59693781 | 20 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59583915 | 21 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59579850 | 21 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59572097 | 22 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59568767 | 22 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 59565201 | 22 days ago | IN | 0 S | 0.0304512 | ||||
| Update To Edge | 58759906 | 33 days ago | IN | 0 S | 0.03044154 | ||||
| Update To Edge | 58755108 | 33 days ago | IN | 0 S | 0.03044154 | ||||
| Update To Edge | 58751539 | 33 days ago | IN | 0 S | 0.03044154 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xB7B5d20D...841F5F144 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
UpdatableRateProviderBalV2
Compiler Version
v0.8.24+commit.e11b9ed9
Optimization Enabled:
No with 200 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: LicenseRef-Gyro-1.0
// for information on licensing please see the README in the GitHub repository
// <https://github.com/gyrostable/dynamic-rateprovider>.
pragma solidity ^0.8.24;
import {BaseUpdatableRateProvider} from "./BaseUpdatableRateProvider.sol";
import {IGyroBasePool} from "gyro-concentrated-lps-balv2/IGyroBasePool.sol";
import {IGyroECLPPool} from "gyro-concentrated-lps-balv2/IGyroECLPPool.sol";
import {IGyro2CLPPool} from "gyro-concentrated-lps-balv2/IGyro2CLPPool.sol";
import {IGovernanceRoleManager} from "gyro-concentrated-lps-balv2/IGovernanceRoleManager.sol";
import {IGyroConfig} from "gyro-concentrated-lps-balv2/IGyroConfig.sol";
import {IGyroConfigManager} from "gyro-concentrated-lps-balv2/IGyroConfigManager.sol";
// *sigh* Balancer's version of IERC20 doesn't include `.decimals()`. Foundry's version is actually
// IERC20Metadata.
import {IVault, IERC20 as IERC20Bal, IAsset} from "balancer-v2-interfaces/vault/IVault.sol";
import {IERC20} from "forge-std/interfaces/IERC20.sol";
import {WeightedPoolUserData} from "balancer-v2-interfaces/pool-weighted/WeightedPoolUserData.sol";
import {FixedPoint} from "balancer-v3/pkg/solidity-utils/contracts/math/FixedPoint.sol";
import {LogExpMath} from "balancer-v3/pkg/solidity-utils/contracts/math/LogExpMath.sol";
// The third incarnation of IERC20!
import {SafeERC20, IERC20 as IERC20OZ} from "oz/token/ERC20/utils/SafeERC20.sol";
/// @notice Balancer V2 variant of the updatable rateprovider for volatile asset pairs in Gyroscope
/// ECLPs. Like a `ConstantRateProvider` but can be updated when the pool goes out of range.
contract UpdatableRateProviderBalV2 is BaseUpdatableRateProvider {
using FixedPoint for uint256;
using LogExpMath for uint256;
using SafeERC20 for IERC20OZ;
/// @notice Connected `GyroConfigManager` used to set the protocol fee to 0 during update.
IGyroConfigManager public immutable gyroConfigManager;
/// @notice Connected `GovernanceRoleManager` used to set the protocol fee to 0 during update.
IGovernanceRoleManager public immutable governanceRoleManager;
/// @notice Key used by pools to retrieve their swap fees, see:
/// https://github.com/gyrostable/concentrated-lps/blob/main/libraries/GyroConfigHelpers.sol
bytes32 internal constant PROTOCOL_SWAP_FEE_PERC_KEY = "PROTOCOL_SWAP_FEE_PERC";
/// @notice Internal helper struct to back up and restore protocol fees.
struct ProtocolFeeSetting {
bool isSet;
uint256 value; // valid iff isSet.
}
/// @notice Some collected pool metadata we pass around.
struct PoolMetadata {
IGyroBasePool pool; // Additionally satisifes one of the IGyro*Pool interfaces based on
// `poolType`.
PoolType poolType;
IVault vault;
bytes32 poolId;
IERC20Bal[] tokens;
uint256[] poolBalancesPreJoin;
}
/// @param _feed A RateProvider to use for updates
/// @param _invert If true, use 1/(value returned by the feed) instead of the feed value itself.
/// @param _admin Address to be set for the `DEFAULT_ADMIN_ROLE`, which can set the pool later
/// and
/// manage permissions
/// @param _updater Address to be set for the `UPDATER_ROLE`, which can call `.updateToEdge()`.
/// Pass the zero address if you don't want to set an updater yet; the admin can manage
/// roles
/// later.
/// @param _gyroConfigManager Address of the `GyroConfigManager` that we can use to set swap
/// fees
/// @param _governanceRoleManager Address of the `GovernanceRoleManager` that we can use to set
/// swap fees.
constructor(
address _feed,
bool _invert,
address _admin,
address _updater,
address _gyroConfigManager,
address _governanceRoleManager
) BaseUpdatableRateProvider(_feed, _invert, _admin, _updater) {
gyroConfigManager = IGyroConfigManager(_gyroConfigManager);
governanceRoleManager = IGovernanceRoleManager(_governanceRoleManager);
}
/// @notice Set the pool that this rateprovider should be connected to. Required before
/// `.updateToEdge()` is called. Callable at most once and by admin only.
///
/// @param _pool A Balancer V2 ECLP
function setPool(address _pool, PoolType _poolType) external onlyRole(DEFAULT_ADMIN_ROLE) {
address[] memory rateProviders = _getRateProviders(_pool, _poolType);
_setPool(_pool, _poolType, _calcOurTokenIx(rateProviders));
}
function _getRateProviders(address _pool, PoolType _poolType)
internal
view
returns (address[] memory rateProviders)
{
if (_poolType == PoolType.ECLP) {
IGyroECLPPool pool_ = IGyroECLPPool(_pool);
rateProviders = new address[](2);
rateProviders[0] = pool_.rateProvider0();
rateProviders[1] = pool_.rateProvider1();
} else if (_poolType == PoolType.C2LP) {
IGyro2CLPPool pool_ = IGyro2CLPPool(_pool);
rateProviders = new address[](2);
rateProviders[0] = pool_.rateProvider0();
rateProviders[1] = pool_.rateProvider1();
} else {
assert(false);
}
}
/// @notice If the pool is out of range, update this rateprovider such that the true current
/// price it is just on the edge of its price range after the update. Reverts if the pool is not
/// out of range. Callable by the updater role only. Uses the linked `feed` rateprovider to get
/// the true current price.
function updateToEdge() external onlyRole(UPDATER_ROLE) {
require(pool != ZERO_ADDRESS, "Pool not set");
PoolMetadata memory meta = _getPoolMetadata(pool, poolType);
// Unless protocol fees are known to be 0, we need to set them to 0 so they don't get in
// the way when updating our rate. We do a join+exit combo with a small amount around our
// updating of our rate to update the accounting for protocol fees (`lastInvariant` in the
// ECLP). Note that order matters here. We store the old value to restore it later. We also
// have to store _whether_ protocol fees are set for this pool because they follow a default
// cascade (see _getPoolProtocolFeeSetting()).
ProtocolFeeSetting memory oldProtocolFees = _getPoolProtocolFeeSetting(address(meta.pool));
// If they are already set to explicit 0, we do not need to change them or join/exit, and we
// don't. This saves a bit of unnecessary interaction.
// NB We could expand the condition to skip if they are implicitly 0 (due to defaulting to
// 0), but we avoid modeling the default cascade here to save some code instead.
if (!(oldProtocolFees.isSet && oldProtocolFees.value == 0)) {
_joinPoolAll(meta);
_setPoolProtocolFeeSetting(address(meta.pool), ProtocolFeeSetting(true, 0));
}
(uint256 alpha, uint256 beta) = _getPriceBounds(meta);
_updateToEdge(alpha, beta);
// Update protocol fee accounting and reset their config.
if (!(oldProtocolFees.isSet && oldProtocolFees.value == 0)) {
_exitPoolAll(meta);
_setPoolProtocolFeeSetting(address(meta.pool), oldProtocolFees);
}
}
function _getPoolMetadata(address _pool, PoolType _poolType)
internal
view
returns (PoolMetadata memory meta)
{
IGyroBasePool pool_ = IGyroBasePool(_pool);
IVault vault_ = IVault(pool_.getVault());
bytes32 poolId_ = pool_.getPoolId();
meta.pool = pool_;
meta.poolType = _poolType;
meta.vault = vault_;
meta.poolId = poolId_;
(meta.tokens, meta.poolBalancesPreJoin,) = vault_.getPoolTokens(poolId_);
}
function _getPriceBounds(PoolMetadata memory meta) internal view returns (uint256, uint256) {
if (meta.poolType == PoolType.ECLP) {
(IGyroECLPPool.Params memory params,) =
IGyroECLPPool(address(meta.pool)).getECLPParams();
return (uint256(params.alpha), uint256(params.beta));
} else if (meta.poolType == PoolType.C2LP) {
uint256[2] memory sqrtParams = IGyro2CLPPool(address(meta.pool)).getSqrtParameters();
return (sqrtParams[0].mulDown(sqrtParams[0]), sqrtParams[1].mulDown(sqrtParams[1]));
} else {
assert(false);
return (0, 0); // unreachable, to make the compiler happy.
}
}
// Join the pool with (potentially) all our assets.
function _joinPoolAll(PoolMetadata memory meta) internal {
uint256[] memory balances = _getBalances(meta.tokens);
// NB `.getActualSupply()` is like `.totalSupply()` but accounts for the fact that due
// protocol fees are distributed before the join (so it may be slightly higher than
// totalSupply).
uint256 bptAmount =
_calcBptAmount(balances, meta.poolBalancesPreJoin, meta.pool.getActualSupply());
_makeApprovals(meta);
_joinPoolFor(bptAmount, meta);
}
// Exit all our LP shares from the pool.
function _exitPoolAll(PoolMetadata memory meta) internal {
_exitPoolFor(meta.pool.balanceOf(address(this)), meta);
}
// Get our balances of the pool tokens in their native number of decimals
function _getBalances(IERC20Bal[] memory tokens)
internal
view
returns (uint256[] memory balances)
{
balances = new uint256[](tokens.length);
for (uint256 i = 0; i < tokens.length; ++i) {
IERC20 token = IERC20(address(tokens[i]));
balances[i] = token.balanceOf(address(this));
}
}
// This function does nothing but casting types.
function _tokens2assets(IERC20Bal[] memory tokens)
internal
pure
returns (IAsset[] memory assets)
{
assets = new IAsset[](tokens.length);
for (uint256 i = 0; i < tokens.length; ++i) {
assets[i] = IAsset(address(tokens[i]));
}
}
// Calculate BPT amount that we can get by joining, given our balances. Never returns 0.
function _calcBptAmount(
uint256[] memory balances,
uint256[] memory poolBalances,
uint256 totalSupply
) internal pure returns (uint256 shares) {
shares = type(uint256).max;
for (uint256 i = 0; i < balances.length; ++i) {
// Note that decimal/rate scaling factors cancel out and the result is an 18-decimal
// number
// (i.e., in the same scale as LP shares).
if (poolBalances[i] > 0) {
uint256 assetShares = totalSupply * balances[i] / poolBalances[i];
if (assetShares < shares) {
shares = assetShares;
}
}
// If poolBalances[i] == 0 (a mostly theoretical concern), we don't need to put any of
// those assets in, so they don't constrain the shares we get out.
}
// Just as a conservative safety margin if the pool rounds down slightly more than we do
// here.
// It really doesn't matter with which amount we join.
shares /= 2;
if (shares == 0) {
// In this case, someone has to give this contract a bit more assets.
revert("Not enough assets.");
}
}
function _makeApprovals(PoolMetadata memory meta) internal {
// We just make one blanket approval per token.
for (uint256 i = 0; i < meta.tokens.length; ++i) {
IERC20OZ token = IERC20OZ(address(meta.tokens[i]));
if (token.allowance(address(this), address(meta.vault)) == 0) {
token.forceApprove(address(meta.vault), type(uint256).max);
}
}
}
// Interacts with Balancer to join the pool with specified amounts.
function _joinPoolFor(uint256 bptAmount, PoolMetadata memory meta) internal {
// We don't use limits b/c they don't matter here, and amounts are small anyways.
uint256[] memory maxAmountsIn = new uint256[](meta.tokens.length);
for (uint256 i = 0; i < meta.tokens.length; ++i) {
maxAmountsIn[i] = type(uint256).max;
}
// All CLPs use the same user data encoding as the weighted pool.
bytes memory userData =
abi.encode(WeightedPoolUserData.JoinKind.ALL_TOKENS_IN_FOR_EXACT_BPT_OUT, bptAmount);
meta.vault.joinPool(
meta.poolId,
address(this),
address(this),
IVault.JoinPoolRequest({
assets: _tokens2assets(meta.tokens),
maxAmountsIn: maxAmountsIn,
userData: userData,
fromInternalBalance: false
})
);
}
// Same as _joinPoolFor() but for exiting.
function _exitPoolFor(uint256 bptAmount, PoolMetadata memory meta) internal {
uint256[] memory minAmountsOut = new uint256[](meta.tokens.length);
for (uint256 i = 0; i < meta.tokens.length; ++i) {
minAmountsOut[i] = 0;
}
bytes memory userData =
abi.encode(WeightedPoolUserData.ExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT, bptAmount);
meta.vault.exitPool(
meta.poolId,
address(this),
payable(address(this)),
IVault.ExitPoolRequest({
assets: _tokens2assets(meta.tokens),
minAmountsOut: minAmountsOut,
userData: userData,
toInternalBalance: false
})
);
}
// We only check if a protocol fee is configured *explicitly* for the pool. Note that the actual
// fee follows a default cascade (first per pool, then per pool type, then a global default),
// but we don't need to consider this here. Therefore, if `res.isSet == false`, this just means
// that the pool does not have an explicit fee configured, not that there is no protocol fee.
function _getPoolProtocolFeeSetting(address _pool)
internal
view
returns (ProtocolFeeSetting memory res)
{
IGyroConfig gyroConfig = gyroConfigManager.config();
bytes32 key = _getPoolKey(_pool, PROTOCOL_SWAP_FEE_PERC_KEY);
if (gyroConfig.hasKey(key)) {
res.isSet = true;
res.value = gyroConfig.getUint(key);
} else {
res.isSet = false;
}
}
// See:
// https://github.com/gyrostable/concentrated-lps/blob/main/libraries/GyroConfigHelpers.sol
function _getPoolKey(address pool, bytes32 key) internal pure returns (bytes32) {
return keccak256(abi.encode(key, pool));
}
function _setPoolProtocolFeeSetting(address _pool, ProtocolFeeSetting memory feeSetting)
internal
{
IGovernanceRoleManager.ProposalAction[] memory actions =
new IGovernanceRoleManager.ProposalAction[](1);
actions[0].target = address(gyroConfigManager);
actions[0].value = 0;
if (feeSetting.isSet) {
actions[0].data = abi.encodeWithSelector(
gyroConfigManager.setPoolConfigUint.selector,
_pool,
PROTOCOL_SWAP_FEE_PERC_KEY,
feeSetting.value
);
} else {
actions[0].data = abi.encodeWithSelector(
gyroConfigManager.unsetPoolConfig.selector, _pool, PROTOCOL_SWAP_FEE_PERC_KEY
);
}
governanceRoleManager.executeActions(actions);
}
}// SPDX-License-Identifier: LicenseRef-Gyro-1.0
// for information on licensing please see the README in the GitHub repository
// <https://github.com/gyrostable/dynamic-rateprovider>.
pragma solidity ^0.8.24;
import {AccessControlDefaultAdminRules} from
"oz/access/extensions/AccessControlDefaultAdminRules.sol";
// NB the Bal V2 and V3 interfaces for IRateProvider are the same.
import {IRateProvider} from "balancer-v3-interfaces/solidity-utils/helpers/IRateProvider.sol";
import {FixedPoint} from "balancer-v3/pkg/solidity-utils/contracts/math/FixedPoint.sol";
abstract contract BaseUpdatableRateProvider is AccessControlDefaultAdminRules, IRateProvider {
using FixedPoint for uint256;
/// @notice The side where the pool price was out of range on `updateToEdge()`. Only for
/// logging.
enum OutOfRangeSide {
BELOW,
ABOVE
}
/// @notice Type of Gyro pool.
enum PoolType {
ECLP,
C2LP
}
/// @notice Connected price feed. This is a RateProvider (often a ChainlinkRateProvider or a
/// transformation of one).
IRateProvider public immutable feed;
/// @notice If true, we use 1 / (the feed value) as the true value. This can be useful
/// for pairs like wstETH/USDC where the wstETH side is already "used up" for the live wstETH/
/// WETH rate and the actual range needs to be captured on the USDC side.
bool public immutable invert;
/// @notice Address of the connected pool. Settable once by the owner.
address public pool;
/// @notice Type of the connected pool. Settable once by the owner.
PoolType public poolType;
/// @notice Index of the pool token that this rateprovider is attached to. Settable once,
// together with `pool`.
uint8 public ourTokenIx;
/// @notice Current value. Equal to `.getRate()`.
uint256 public value;
/// @notice The role that can call the update function.
bytes32 public constant UPDATER_ROLE = "UPDATER_ROLE";
/// @notice Emitted at most once during contract lifetime, when the admin has set the connected
/// pool.
event PoolSet(address indexed pool, PoolType poolType, uint8 ourTokenIx);
/// @notice Emitted whenever the stored value (the rate) is updated.
event ValueUpdated(uint256 value, OutOfRangeSide indexed why);
address internal constant ZERO_ADDRESS = address(0);
constructor(address _feed, bool _invert, address _admin, address _updater)
AccessControlDefaultAdminRules(1 days, _admin)
{
if (_updater != ZERO_ADDRESS) {
_grantRole(UPDATER_ROLE, _updater);
}
feed = IRateProvider(_feed);
invert = _invert;
// NB we can do this *once*, here, while the pool is stil uninitialized.
// During normal operation, we need to set the value much more carefully to avoid arbitrage
// loss, and we can't usually set it to the current value.
value = _getFeedValue();
}
function getRate() external view override returns (uint256) {
return value;
}
function _setPool(address _pool, PoolType _poolType, uint8 _ourTokenIx) internal {
require(pool == ZERO_ADDRESS, "Pool already set");
pool = _pool;
poolType = _poolType;
ourTokenIx = _ourTokenIx;
emit PoolSet(_pool, _poolType, _ourTokenIx);
}
function _setValue(uint256 _value, OutOfRangeSide why) internal {
value = _value;
emit ValueUpdated(_value, why);
}
function _getFeedValue() internal view returns (uint256 ret) {
ret = feed.getRate();
if (invert) {
ret = FixedPoint.ONE.divDown(ret);
}
}
// Updater function. alpha and beta are the inner price bounds for the price of token0
// denominated in units of the numeraire token (token1 for 2 assets or token2 for 3 assets).
function _updateToEdge(uint256 alpha, uint256 beta) internal {
uint256 feedValue = _getFeedValue();
bool thisIsNumeraire = ourTokenIx == 1;
if (!thisIsNumeraire) {
uint256 valueBelow = feedValue.divDown(alpha);
uint256 valueAbove = feedValue.divDown(beta);
if (value > valueBelow) {
_setValue(valueBelow, OutOfRangeSide.BELOW);
} else if (value < valueAbove) {
_setValue(valueAbove, OutOfRangeSide.ABOVE);
} else {
revert("Pool not out of range");
}
} else {
uint256 valueBelow = feedValue.mulDown(alpha);
uint256 valueAbove = feedValue.mulDown(beta);
if (value < valueBelow) {
_setValue(valueBelow, OutOfRangeSide.BELOW);
} else if (value > valueAbove) {
_setValue(valueAbove, OutOfRangeSide.ABOVE);
} else {
revert("Pool not out of range");
}
}
}
/// @notice Calculate the `thisIsToken0` flag given the two rateproviders.
function _calcOurTokenIx(address[] memory rateProviders) internal view returns (uint8) {
for (uint8 i = 0; i < rateProviders.length; ++i) {
if (rateProviders[i] == address(this)) {
return i;
}
}
revert("Rateprovider not configured in pool.");
}
}pragma solidity ^0.8;
import {IERC20} from "forge-std/interfaces/IERC20.sol";
/// @notice Interface shared between all Gyro CLPs
interface IGyroBasePool is IERC20 {
function getVault() external view returns (address);
function getPoolId() external view returns (bytes32);
function gyroConfig() external view returns (address);
function getActualSupply() external view returns (uint256);
function getInvariant() external view returns (uint256);
function getInvariantDivActualSupply() external view returns (uint256);
function getLastInvariant() external view returns (uint256);
function getSwapFeePercentage() external view returns (uint256);
}pragma solidity ^0.8;
import {IGyroBasePool} from "./IGyroBasePool.sol";
/// @notice This is an ad-hoc interface for required functions of ECLPs under Balancer v2.
/// See https://github.com/gyrostable/concentrated-lps/blob/main/contracts/eclp/GyroECLPPool.sol
interface IGyroECLPPool is IGyroBasePool {
// See https://github.com/gyrostable/concentrated-lps/blob/main/contracts/eclp/GyroECLPMath.sol
struct Vector2 {
int256 x;
int256 y;
}
struct Params {
// Price bounds (lower and upper). 0 < alpha < beta
int256 alpha;
int256 beta;
// Rotation vector:
// phi in (-90 degrees, 0] is the implicit rotation vector. It's stored as a point:
int256 c; // c = cos(-phi) >= 0. rounded to 18 decimals
int256 s; // s = sin(-phi) >= 0. rounded to 18 decimals
// Invariant: c^2 + s^2 == 1, i.e., the point (c, s) is normalized.
// due to rounding, this may not = 1. The term dSq in DerivedParams corrects for this in extra precision
// Stretching factor:
int256 lambda; // lambda >= 1 where lambda == 1 is the circle.
}
// terms in this struct are stored in extra precision (38 decimals) with final decimal rounded down
struct DerivedParams {
Vector2 tauAlpha;
Vector2 tauBeta;
int256 u; // from (A chi)_y = lambda * u + v
int256 v; // from (A chi)_y = lambda * u + v
int256 w; // from (A chi)_x = w / lambda + z
int256 z; // from (A chi)_x = w / lambda + z
int256 dSq; // error in c^2 + s^2 = dSq, used to correct errors in c, s, tau, u,v,w,z calculations
//int256 dAlpha; // normalization constant for tau(alpha)
//int256 dBeta; // normalization constant for tau(beta)
}
function rateProvider0() external view returns (address);
function rateProvider1() external view returns (address);
function getECLPParams() external view returns (Params memory, DerivedParams memory);
}pragma solidity ^0.8;
import {IGyroBasePool} from "./IGyroBasePool.sol";
/// @notice This is an ad-hoc interface for required functions of 2CLPs under Balancer v2.
/// See https://github.com/gyrostable/concentrated-lps/blob/main/contracts/eclp/GyroECLPPool.sol
interface IGyro2CLPPool is IGyroBasePool {
function calculateCurrentValues(
uint256 balanceTokenIn,
uint256 balanceTokenOut,
bool tokenInIsToken0
)
external
view
returns (
uint256 currentInvariant,
uint256 virtualParamIn,
uint256 virtualParamOut
);
function getActualSupply() external view returns (uint256);
function getPrice() external view returns (uint256 spotPrice);
function getSqrtParameters() external view returns (uint256[2] memory);
function getSwapFeePercentage() external view returns (uint256);
function getTokenRates() external view returns (uint256 rate0, uint256 rate1);
function getVirtualParameters() external view returns (uint256[] memory virtualParams);
function rateProvider0() external view returns (address);
function rateProvider1() external view returns (address);
}pragma solidity ^0.8.24;
/// @notice This is an ad-hoc interface for required functions of the GovernanceRoleManager in the
/// Gyro governance system.
/// See https://github.com/gyrostable/governance-l2/pull/5
interface IGovernanceRoleManager {
/// @notice Proposal action as defined in L1 governance contract
struct ProposalAction {
address target;
bytes data;
uint256 value;
}
struct ParameterRequirement {
uint256 index;
bytes32 value;
}
/// @notice Executes a list of actions
/// @param actions The actions to execute
function executeActions(ProposalAction[] calldata actions) external;
function addPermission(address user, address target, bytes4 selector, ParameterRequirement[] calldata parameters)
external;
function owner() external returns (address);
}// SPDX-License-Identifier: LicenseRef-Gyro-1.0
// for information on licensing please see the README in the GitHub repository <https://github.com/gyrostable/core-protocol>.
pragma solidity ^0.8.4;
import "./IGovernable.sol";
/// @notice IGyroConfig stores the global configuration of the Gyroscope protocol
interface IGyroConfig is IGovernable {
/// @notice Event emitted every time a configuration is changed
event ConfigChanged(bytes32 key, uint256 previousValue, uint256 newValue);
event ConfigChanged(bytes32 key, address previousValue, address newValue);
/// @notice Event emitted when a configuration is unset
event ConfigUnset(bytes32 key);
/// @notice Event emitted when a configuration is frozen
event ConfigFrozen(bytes32 key);
/// @notice Returns a set of known configuration keys
function listKeys() external view returns (bytes32[] memory);
/// @notice Returns true if the configuration has the given key
function hasKey(bytes32 key) external view returns (bool);
/// @notice Returns the metadata associated with a particular config key
function getConfigMeta(bytes32 key) external view returns (uint8, bool);
/// @notice Returns a uint256 value from the config
function getUint(bytes32 key) external view returns (uint256);
/// @notice Returns a uint256 value from the config or `defaultValue` if it does not exist
function getUint(bytes32 key, uint256 defaultValue) external view returns (uint256);
/// @notice Returns an address value from the config
function getAddress(bytes32 key) external view returns (address);
/// @notice Returns an address value from the config or `defaultValue` if it does not exist
function getAddress(bytes32 key, address defaultValue) external view returns (address);
/// @notice Set a uint256 config
/// NOTE: We avoid overloading to avoid complications with some clients
function setUint(bytes32 key, uint256 newValue) external;
/// @notice Set an address config
function setAddress(bytes32 key, address newValue) external;
/// @notice Unset a key in the config
function unset(bytes32 key) external;
/// @notice Freezes a key, making it impossible to update or unset
function freeze(bytes32 key) external;
}pragma solidity ^0.8.24;
import {IGyroConfig} from "./IGyroConfig.sol";
/// @notice Ad-hoc interface for some functions from GyroConfigManager we need
/// See https://github.com/gyrostable/governance-l2/pull/5
interface IGyroConfigManager {
function config() external view returns (IGyroConfig);
function setPoolConfigUint(address pool, bytes32 key, uint256 value) external;
function unsetPoolConfig(address pool, bytes32 key) external;
function owner() external view returns (address);
// GyroConfigManager fallback-delegates to GyroConfig. We add this function from GyroConfig b/c
// we need it in tests.
function acceptGovernance() external;
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma experimental ABIEncoderV2;
import "../solidity-utils/openzeppelin/IERC20.sol";
import "../solidity-utils/helpers/IAuthentication.sol";
import "../solidity-utils/helpers/ISignaturesValidator.sol";
import "../solidity-utils/helpers/ITemporarilyPausable.sol";
import "../solidity-utils/misc/IWETH.sol";
import "./IAsset.sol";
import "./IAuthorizer.sol";
import "./IFlashLoanRecipient.sol";
import "./IProtocolFeesCollector.sol";
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Full external interface for the Vault core contract - no external or public methods exist in the contract that
* don't override one of these declarations.
*/
interface IVault is ISignaturesValidator, ITemporarilyPausable, IAuthentication {
// Generalities about the Vault:
//
// - Whenever documentation refers to 'tokens', it strictly refers to ERC20-compliant token contracts. Tokens are
// transferred out of the Vault by calling the `IERC20.transfer` function, and transferred in by calling
// `IERC20.transferFrom`. In these cases, the sender must have previously allowed the Vault to use their tokens by
// calling `IERC20.approve`. The only deviation from the ERC20 standard that is supported is functions not returning
// a boolean value: in these scenarios, a non-reverting call is assumed to be successful.
//
// - All non-view functions in the Vault are non-reentrant: calling them while another one is mid-execution (e.g.
// while execution control is transferred to a token contract during a swap) will result in a revert. View
// functions can be called in a re-reentrant way, but doing so might cause them to return inconsistent results.
// Contracts calling view functions in the Vault must make sure the Vault has not already been entered.
//
// - View functions revert if referring to either unregistered Pools, or unregistered tokens for registered Pools.
// Authorizer
//
// Some system actions are permissioned, like setting and collecting protocol fees. This permissioning system exists
// outside of the Vault in the Authorizer contract: the Vault simply calls the Authorizer to check if the caller
// can perform a given action.
/**
* @dev Returns the Vault's Authorizer.
*/
function getAuthorizer() external view returns (IAuthorizer);
/**
* @dev Sets a new Authorizer for the Vault. The caller must be allowed by the current Authorizer to do this.
*
* Emits an `AuthorizerChanged` event.
*/
function setAuthorizer(IAuthorizer newAuthorizer) external;
/**
* @dev Emitted when a new authorizer is set by `setAuthorizer`.
*/
event AuthorizerChanged(IAuthorizer indexed newAuthorizer);
// Relayers
//
// Additionally, it is possible for an account to perform certain actions on behalf of another one, using their
// Vault ERC20 allowance and Internal Balance. These accounts are said to be 'relayers' for these Vault functions,
// and are expected to be smart contracts with sound authentication mechanisms. For an account to be able to wield
// this power, two things must occur:
// - The Authorizer must grant the account the permission to be a relayer for the relevant Vault function. This
// means that Balancer governance must approve each individual contract to act as a relayer for the intended
// functions.
// - Each user must approve the relayer to act on their behalf.
// This double protection means users cannot be tricked into approving malicious relayers (because they will not
// have been allowed by the Authorizer via governance), nor can malicious relayers approved by a compromised
// Authorizer or governance drain user funds, since they would also need to be approved by each individual user.
/**
* @dev Returns true if `user` has approved `relayer` to act as a relayer for them.
*/
function hasApprovedRelayer(address user, address relayer) external view returns (bool);
/**
* @dev Allows `relayer` to act as a relayer for `sender` if `approved` is true, and disallows it otherwise.
*
* Emits a `RelayerApprovalChanged` event.
*/
function setRelayerApproval(
address sender,
address relayer,
bool approved
) external;
/**
* @dev Emitted every time a relayer is approved or disapproved by `setRelayerApproval`.
*/
event RelayerApprovalChanged(address indexed relayer, address indexed sender, bool approved);
// Internal Balance
//
// Users can deposit tokens into the Vault, where they are allocated to their Internal Balance, and later
// transferred or withdrawn. It can also be used as a source of tokens when joining Pools, as a destination
// when exiting them, and as either when performing swaps. This usage of Internal Balance results in greatly reduced
// gas costs when compared to relying on plain ERC20 transfers, leading to large savings for frequent users.
//
// Internal Balance management features batching, which means a single contract call can be used to perform multiple
// operations of different kinds, with different senders and recipients, at once.
/**
* @dev Returns `user`'s Internal Balance for a set of tokens.
*/
function getInternalBalance(address user, IERC20[] memory tokens) external view returns (uint256[] memory);
/**
* @dev Performs a set of user balance operations, which involve Internal Balance (deposit, withdraw or transfer)
* and plain ERC20 transfers using the Vault's allowance. This last feature is particularly useful for relayers, as
* it lets integrators reuse a user's Vault allowance.
*
* For each operation, if the caller is not `sender`, it must be an authorized relayer for them.
*/
function manageUserBalance(UserBalanceOp[] memory ops) external payable;
/**
* @dev Data for `manageUserBalance` operations, which include the possibility for ETH to be sent and received
without manual WETH wrapping or unwrapping.
*/
struct UserBalanceOp {
UserBalanceOpKind kind;
IAsset asset;
uint256 amount;
address sender;
address payable recipient;
}
// There are four possible operations in `manageUserBalance`:
//
// - DEPOSIT_INTERNAL
// Increases the Internal Balance of the `recipient` account by transferring tokens from the corresponding
// `sender`. The sender must have allowed the Vault to use their tokens via `IERC20.approve()`.
//
// ETH can be used by passing the ETH sentinel value as the asset and forwarding ETH in the call: it will be wrapped
// and deposited as WETH. Any ETH amount remaining will be sent back to the caller (not the sender, which is
// relevant for relayers).
//
// Emits an `InternalBalanceChanged` event.
//
//
// - WITHDRAW_INTERNAL
// Decreases the Internal Balance of the `sender` account by transferring tokens to the `recipient`.
//
// ETH can be used by passing the ETH sentinel value as the asset. This will deduct WETH instead, unwrap it and send
// it to the recipient as ETH.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_INTERNAL
// Transfers tokens from the Internal Balance of the `sender` account to the Internal Balance of `recipient`.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `InternalBalanceChanged` event.
//
//
// - TRANSFER_EXTERNAL
// Transfers tokens from `sender` to `recipient`, using the Vault's ERC20 allowance. This is typically used by
// relayers, as it lets them reuse a user's Vault allowance.
//
// Reverts if the ETH sentinel value is passed.
//
// Emits an `ExternalBalanceTransfer` event.
enum UserBalanceOpKind { DEPOSIT_INTERNAL, WITHDRAW_INTERNAL, TRANSFER_INTERNAL, TRANSFER_EXTERNAL }
/**
* @dev Emitted when a user's Internal Balance changes, either from calls to `manageUserBalance`, or through
* interacting with Pools using Internal Balance.
*
* Because Internal Balance works exclusively with ERC20 tokens, ETH deposits and withdrawals will use the WETH
* address.
*/
event InternalBalanceChanged(address indexed user, IERC20 indexed token, int256 delta);
/**
* @dev Emitted when a user's Vault ERC20 allowance is used by the Vault to transfer tokens to an external account.
*/
event ExternalBalanceTransfer(IERC20 indexed token, address indexed sender, address recipient, uint256 amount);
// Pools
//
// There are three specialization settings for Pools, which allow for cheaper swaps at the cost of reduced
// functionality:
//
// - General: no specialization, suited for all Pools. IGeneralPool is used for swap request callbacks, passing the
// balance of all tokens in the Pool. These Pools have the largest swap costs (because of the extra storage reads),
// which increase with the number of registered tokens.
//
// - Minimal Swap Info: IMinimalSwapInfoPool is used instead of IGeneralPool, which saves gas by only passing the
// balance of the two tokens involved in the swap. This is suitable for some pricing algorithms, like the weighted
// constant product one popularized by Balancer V1. Swap costs are smaller compared to general Pools, and are
// independent of the number of registered tokens.
//
// - Two Token: only allows two tokens to be registered. This achieves the lowest possible swap gas cost. Like
// minimal swap info Pools, these are called via IMinimalSwapInfoPool.
enum PoolSpecialization { GENERAL, MINIMAL_SWAP_INFO, TWO_TOKEN }
/**
* @dev Registers the caller account as a Pool with a given specialization setting. Returns the Pool's ID, which
* is used in all Pool-related functions. Pools cannot be deregistered, nor can the Pool's specialization be
* changed.
*
* The caller is expected to be a smart contract that implements either `IGeneralPool` or `IMinimalSwapInfoPool`,
* depending on the chosen specialization setting. This contract is known as the Pool's contract.
*
* Note that the same contract may register itself as multiple Pools with unique Pool IDs, or in other words,
* multiple Pools may share the same contract.
*
* Emits a `PoolRegistered` event.
*/
function registerPool(PoolSpecialization specialization) external returns (bytes32);
/**
* @dev Emitted when a Pool is registered by calling `registerPool`.
*/
event PoolRegistered(bytes32 indexed poolId, address indexed poolAddress, PoolSpecialization specialization);
/**
* @dev Returns a Pool's contract address and specialization setting.
*/
function getPool(bytes32 poolId) external view returns (address, PoolSpecialization);
/**
* @dev Registers `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Pools can only interact with tokens they have registered. Users join a Pool by transferring registered tokens,
* exit by receiving registered tokens, and can only swap registered tokens.
*
* Each token can only be registered once. For Pools with the Two Token specialization, `tokens` must have a length
* of two, that is, both tokens must be registered in the same `registerTokens` call, and they must be sorted in
* ascending order.
*
* The `tokens` and `assetManagers` arrays must have the same length, and each entry in these indicates the Asset
* Manager for the corresponding token. Asset Managers can manage a Pool's tokens via `managePoolBalance`,
* depositing and withdrawing them directly, and can even set their balance to arbitrary amounts. They are therefore
* expected to be highly secured smart contracts with sound design principles, and the decision to register an
* Asset Manager should not be made lightly.
*
* Pools can choose not to assign an Asset Manager to a given token by passing in the zero address. Once an Asset
* Manager is set, it cannot be changed except by deregistering the associated token and registering again with a
* different Asset Manager.
*
* Emits a `TokensRegistered` event.
*/
function registerTokens(
bytes32 poolId,
IERC20[] memory tokens,
address[] memory assetManagers
) external;
/**
* @dev Emitted when a Pool registers tokens by calling `registerTokens`.
*/
event TokensRegistered(bytes32 indexed poolId, IERC20[] tokens, address[] assetManagers);
/**
* @dev Deregisters `tokens` for the `poolId` Pool. Must be called by the Pool's contract.
*
* Only registered tokens (via `registerTokens`) can be deregistered. Additionally, they must have zero total
* balance. For Pools with the Two Token specialization, `tokens` must have a length of two, that is, both tokens
* must be deregistered in the same `deregisterTokens` call.
*
* A deregistered token can be re-registered later on, possibly with a different Asset Manager.
*
* Emits a `TokensDeregistered` event.
*/
function deregisterTokens(bytes32 poolId, IERC20[] memory tokens) external;
/**
* @dev Emitted when a Pool deregisters tokens by calling `deregisterTokens`.
*/
event TokensDeregistered(bytes32 indexed poolId, IERC20[] tokens);
/**
* @dev Returns detailed information for a Pool's registered token.
*
* `cash` is the number of tokens the Vault currently holds for the Pool. `managed` is the number of tokens
* withdrawn and held outside the Vault by the Pool's token Asset Manager. The Pool's total balance for `token`
* equals the sum of `cash` and `managed`.
*
* Internally, `cash` and `managed` are stored using 112 bits. No action can ever cause a Pool's token `cash`,
* `managed` or `total` balance to be greater than 2^112 - 1.
*
* `lastChangeBlock` is the number of the block in which `token`'s total balance was last modified (via either a
* join, exit, swap, or Asset Manager update). This value is useful to avoid so-called 'sandwich attacks', for
* example when developing price oracles. A change of zero (e.g. caused by a swap with amount zero) is considered a
* change for this purpose, and will update `lastChangeBlock`.
*
* `assetManager` is the Pool's token Asset Manager.
*/
function getPoolTokenInfo(bytes32 poolId, IERC20 token)
external
view
returns (
uint256 cash,
uint256 managed,
uint256 lastChangeBlock,
address assetManager
);
/**
* @dev Returns a Pool's registered tokens, the total balance for each, and the latest block when *any* of
* the tokens' `balances` changed.
*
* The order of the `tokens` array is the same order that will be used in `joinPool`, `exitPool`, as well as in all
* Pool hooks (where applicable). Calls to `registerTokens` and `deregisterTokens` may change this order.
*
* If a Pool only registers tokens once, and these are sorted in ascending order, they will be stored in the same
* order as passed to `registerTokens`.
*
* Total balances include both tokens held by the Vault and those withdrawn by the Pool's Asset Managers. These are
* the amounts used by joins, exits and swaps. For a detailed breakdown of token balances, use `getPoolTokenInfo`
* instead.
*/
function getPoolTokens(bytes32 poolId)
external
view
returns (
IERC20[] memory tokens,
uint256[] memory balances,
uint256 lastChangeBlock
);
/**
* @dev Called by users to join a Pool, which transfers tokens from `sender` into the Pool's balance. This will
* trigger custom Pool behavior, which will typically grant something in return to `recipient` - often tokenized
* Pool shares.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `assets` and `maxAmountsIn` arrays must have the same length, and each entry indicates the maximum amount
* to send for each asset. The amounts to send are decided by the Pool and not the Vault: it just enforces
* these maximums.
*
* If joining a Pool that holds WETH, it is possible to send ETH directly: the Vault will do the wrapping. To enable
* this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead of the
* WETH address. Note that it is not possible to combine ETH and WETH in the same join. Any excess ETH will be sent
* back to the caller (not the sender, which is important for relayers).
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If sending ETH however, the array must be
* sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the final
* `assets` array might not be sorted. Pools with no registered tokens cannot be joined.
*
* If `fromInternalBalance` is true, the caller's Internal Balance will be preferred: ERC20 transfers will only
* be made for the difference between the requested amount and Internal Balance (if any). Note that ETH cannot be
* withdrawn from Internal Balance: attempting to do so will trigger a revert.
*
* This causes the Vault to call the `IBasePool.onJoinPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares). This can be encoded in the `userData` argument, which is ignored by the Vault and passed
* directly to the Pool's contract, as is `recipient`.
*
* Emits a `PoolBalanceChanged` event.
*/
function joinPool(
bytes32 poolId,
address sender,
address recipient,
JoinPoolRequest memory request
) external payable;
struct JoinPoolRequest {
IAsset[] assets;
uint256[] maxAmountsIn;
bytes userData;
bool fromInternalBalance;
}
/**
* @dev Called by users to exit a Pool, which transfers tokens from the Pool's balance to `recipient`. This will
* trigger custom Pool behavior, which will typically ask for something in return from `sender` - often tokenized
* Pool shares. The amount of tokens that can be withdrawn is limited by the Pool's `cash` balance (see
* `getPoolTokenInfo`).
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* The `tokens` and `minAmountsOut` arrays must have the same length, and each entry in these indicates the minimum
* token amount to receive for each token contract. The amounts to send are decided by the Pool and not the Vault:
* it just enforces these minimums.
*
* If exiting a Pool that holds WETH, it is possible to receive ETH directly: the Vault will do the unwrapping. To
* enable this mechanism, the IAsset sentinel value (the zero address) must be passed in the `assets` array instead
* of the WETH address. Note that it is not possible to combine ETH and WETH in the same exit.
*
* `assets` must have the same length and order as the array returned by `getPoolTokens`. This prevents issues when
* interacting with Pools that register and deregister tokens frequently. If receiving ETH however, the array must
* be sorted *before* replacing the WETH address with the ETH sentinel value (the zero address), which means the
* final `assets` array might not be sorted. Pools with no registered tokens cannot be exited.
*
* If `toInternalBalance` is true, the tokens will be deposited to `recipient`'s Internal Balance. Otherwise,
* an ERC20 transfer will be performed. Note that ETH cannot be deposited to Internal Balance: attempting to
* do so will trigger a revert.
*
* `minAmountsOut` is the minimum amount of tokens the user expects to get out of the Pool, for each token in the
* `tokens` array. This array must match the Pool's registered tokens.
*
* This causes the Vault to call the `IBasePool.onExitPool` hook on the Pool's contract, where Pools implement
* their own custom logic. This typically requires additional information from the user (such as the expected number
* of Pool shares to return). This can be encoded in the `userData` argument, which is ignored by the Vault and
* passed directly to the Pool's contract.
*
* Emits a `PoolBalanceChanged` event.
*/
function exitPool(
bytes32 poolId,
address sender,
address payable recipient,
ExitPoolRequest memory request
) external;
struct ExitPoolRequest {
IAsset[] assets;
uint256[] minAmountsOut;
bytes userData;
bool toInternalBalance;
}
/**
* @dev Emitted when a user joins or exits a Pool by calling `joinPool` or `exitPool`, respectively.
*/
event PoolBalanceChanged(
bytes32 indexed poolId,
address indexed liquidityProvider,
IERC20[] tokens,
int256[] deltas,
uint256[] protocolFeeAmounts
);
enum PoolBalanceChangeKind { JOIN, EXIT }
// Swaps
//
// Users can swap tokens with Pools by calling the `swap` and `batchSwap` functions. To do this,
// they need not trust Pool contracts in any way: all security checks are made by the Vault. They must however be
// aware of the Pools' pricing algorithms in order to estimate the prices Pools will quote.
//
// The `swap` function executes a single swap, while `batchSwap` can perform multiple swaps in sequence.
// In each individual swap, tokens of one kind are sent from the sender to the Pool (this is the 'token in'),
// and tokens of another kind are sent from the Pool to the recipient in exchange (this is the 'token out').
// More complex swaps, such as one token in to multiple tokens out can be achieved by batching together
// individual swaps.
//
// There are two swap kinds:
// - 'given in' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines (via the
// `onSwap` hook) the amount of tokens out (to send to the recipient).
// - 'given out' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines
// (via the `onSwap` hook) the amount of tokens in (to receive from the sender).
//
// Additionally, it is possible to chain swaps using a placeholder input amount, which the Vault replaces with
// the calculated output of the previous swap. If the previous swap was 'given in', this will be the calculated
// tokenOut amount. If the previous swap was 'given out', it will use the calculated tokenIn amount. These extended
// swaps are known as 'multihop' swaps, since they 'hop' through a number of intermediate tokens before arriving at
// the final intended token.
//
// In all cases, tokens are only transferred in and out of the Vault (or withdrawn from and deposited into Internal
// Balance) after all individual swaps have been completed, and the net token balance change computed. This makes
// certain swap patterns, such as multihops, or swaps that interact with the same token pair in multiple Pools, cost
// much less gas than they would otherwise.
//
// It also means that under certain conditions it is possible to perform arbitrage by swapping with multiple
// Pools in a way that results in net token movement out of the Vault (profit), with no tokens being sent in (only
// updating the Pool's internal accounting).
//
// To protect users from front-running or the market changing rapidly, they supply a list of 'limits' for each token
// involved in the swap, where either the maximum number of tokens to send (by passing a positive value) or the
// minimum amount of tokens to receive (by passing a negative value) is specified.
//
// Additionally, a 'deadline' timestamp can also be provided, forcing the swap to fail if it occurs after
// this point in time (e.g. if the transaction failed to be included in a block promptly).
//
// If interacting with Pools that hold WETH, it is possible to both send and receive ETH directly: the Vault will do
// the wrapping and unwrapping. To enable this mechanism, the IAsset sentinel value (the zero address) must be
// passed in the `assets` array instead of the WETH address. Note that it is possible to combine ETH and WETH in the
// same swap. Any excess ETH will be sent back to the caller (not the sender, which is relevant for relayers).
//
// Finally, Internal Balance can be used when either sending or receiving tokens.
enum SwapKind { GIVEN_IN, GIVEN_OUT }
/**
* @dev Performs a swap with a single Pool.
*
* If the swap is 'given in' (the number of tokens to send to the Pool is known), it returns the amount of tokens
* taken from the Pool, which must be greater than or equal to `limit`.
*
* If the swap is 'given out' (the number of tokens to take from the Pool is known), it returns the amount of tokens
* sent to the Pool, which must be less than or equal to `limit`.
*
* Internal Balance usage and the recipient are determined by the `funds` struct.
*
* Emits a `Swap` event.
*/
function swap(
SingleSwap memory singleSwap,
FundManagement memory funds,
uint256 limit,
uint256 deadline
) external payable returns (uint256);
/**
* @dev Data for a single swap executed by `swap`. `amount` is either `amountIn` or `amountOut` depending on
* the `kind` value.
*
* `assetIn` and `assetOut` are either token addresses, or the IAsset sentinel value for ETH (the zero address).
* Note that Pools never interact with ETH directly: it will be wrapped to or unwrapped from WETH by the Vault.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct SingleSwap {
bytes32 poolId;
SwapKind kind;
IAsset assetIn;
IAsset assetOut;
uint256 amount;
bytes userData;
}
/**
* @dev Performs a series of swaps with one or multiple Pools. In each individual swap, the caller determines either
* the amount of tokens sent to or received from the Pool, depending on the `kind` value.
*
* Returns an array with the net Vault asset balance deltas. Positive amounts represent tokens (or ETH) sent to the
* Vault, and negative amounts represent tokens (or ETH) sent by the Vault. Each delta corresponds to the asset at
* the same index in the `assets` array.
*
* Swaps are executed sequentially, in the order specified by the `swaps` array. Each array element describes a
* Pool, the token to be sent to this Pool, the token to receive from it, and an amount that is either `amountIn` or
* `amountOut` depending on the swap kind.
*
* Multihop swaps can be executed by passing an `amount` value of zero for a swap. This will cause the amount in/out
* of the previous swap to be used as the amount in for the current one. In a 'given in' swap, 'tokenIn' must equal
* the previous swap's `tokenOut`. For a 'given out' swap, `tokenOut` must equal the previous swap's `tokenIn`.
*
* The `assets` array contains the addresses of all assets involved in the swaps. These are either token addresses,
* or the IAsset sentinel value for ETH (the zero address). Each entry in the `swaps` array specifies tokens in and
* out by referencing an index in `assets`. Note that Pools never interact with ETH directly: it will be wrapped to
* or unwrapped from WETH by the Vault.
*
* Internal Balance usage, sender, and recipient are determined by the `funds` struct. The `limits` array specifies
* the minimum or maximum amount of each token the vault is allowed to transfer.
*
* `batchSwap` can be used to make a single swap, like `swap` does, but doing so requires more gas than the
* equivalent `swap` call.
*
* Emits `Swap` events.
*/
function batchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds,
int256[] memory limits,
uint256 deadline
) external payable returns (int256[] memory);
/**
* @dev Data for each individual swap executed by `batchSwap`. The asset in and out fields are indexes into the
* `assets` array passed to that function, and ETH assets are converted to WETH.
*
* If `amount` is zero, the multihop mechanism is used to determine the actual amount based on the amount in/out
* from the previous swap, depending on the swap kind.
*
* The `userData` field is ignored by the Vault, but forwarded to the Pool in the `onSwap` hook, and may be
* used to extend swap behavior.
*/
struct BatchSwapStep {
bytes32 poolId;
uint256 assetInIndex;
uint256 assetOutIndex;
uint256 amount;
bytes userData;
}
/**
* @dev Emitted for each individual swap performed by `swap` or `batchSwap`.
*/
event Swap(
bytes32 indexed poolId,
IERC20 indexed tokenIn,
IERC20 indexed tokenOut,
uint256 amountIn,
uint256 amountOut
);
/**
* @dev All tokens in a swap are either sent from the `sender` account to the Vault, or from the Vault to the
* `recipient` account.
*
* If the caller is not `sender`, it must be an authorized relayer for them.
*
* If `fromInternalBalance` is true, the `sender`'s Internal Balance will be preferred, performing an ERC20
* transfer for the difference between the requested amount and the User's Internal Balance (if any). The `sender`
* must have allowed the Vault to use their tokens via `IERC20.approve()`. This matches the behavior of
* `joinPool`.
*
* If `toInternalBalance` is true, tokens will be deposited to `recipient`'s internal balance instead of
* transferred. This matches the behavior of `exitPool`.
*
* Note that ETH cannot be deposited to or withdrawn from Internal Balance: attempting to do so will trigger a
* revert.
*/
struct FundManagement {
address sender;
bool fromInternalBalance;
address payable recipient;
bool toInternalBalance;
}
/**
* @dev Simulates a call to `batchSwap`, returning an array of Vault asset deltas. Calls to `swap` cannot be
* simulated directly, but an equivalent `batchSwap` call can and will yield the exact same result.
*
* Each element in the array corresponds to the asset at the same index, and indicates the number of tokens (or ETH)
* the Vault would take from the sender (if positive) or send to the recipient (if negative). The arguments it
* receives are the same that an equivalent `batchSwap` call would receive.
*
* Unlike `batchSwap`, this function performs no checks on the sender or recipient field in the `funds` struct.
* This makes it suitable to be called by off-chain applications via eth_call without needing to hold tokens,
* approve them for the Vault, or even know a user's address.
*
* Note that this function is not 'view' (due to implementation details): the client code must explicitly execute
* eth_call instead of eth_sendTransaction.
*/
function queryBatchSwap(
SwapKind kind,
BatchSwapStep[] memory swaps,
IAsset[] memory assets,
FundManagement memory funds
) external returns (int256[] memory assetDeltas);
// Flash Loans
/**
* @dev Performs a 'flash loan', sending tokens to `recipient`, executing the `receiveFlashLoan` hook on it,
* and then reverting unless the tokens plus a proportional protocol fee have been returned.
*
* The `tokens` and `amounts` arrays must have the same length, and each entry in these indicates the loan amount
* for each token contract. `tokens` must be sorted in ascending order.
*
* The 'userData' field is ignored by the Vault, and forwarded as-is to `recipient` as part of the
* `receiveFlashLoan` call.
*
* Emits `FlashLoan` events.
*/
function flashLoan(
IFlashLoanRecipient recipient,
IERC20[] memory tokens,
uint256[] memory amounts,
bytes memory userData
) external;
/**
* @dev Emitted for each individual flash loan performed by `flashLoan`.
*/
event FlashLoan(IFlashLoanRecipient indexed recipient, IERC20 indexed token, uint256 amount, uint256 feeAmount);
// Asset Management
//
// Each token registered for a Pool can be assigned an Asset Manager, which is able to freely withdraw the Pool's
// tokens from the Vault, deposit them, or assign arbitrary values to its `managed` balance (see
// `getPoolTokenInfo`). This makes them extremely powerful and dangerous. Even if an Asset Manager only directly
// controls one of the tokens in a Pool, a malicious manager could set that token's balance to manipulate the
// prices of the other tokens, and then drain the Pool with swaps. The risk of using Asset Managers is therefore
// not constrained to the tokens they are managing, but extends to the entire Pool's holdings.
//
// However, a properly designed Asset Manager smart contract can be safely used for the Pool's benefit,
// for example by lending unused tokens out for interest, or using them to participate in voting protocols.
//
// This concept is unrelated to the IAsset interface.
/**
* @dev Performs a set of Pool balance operations, which may be either withdrawals, deposits or updates.
*
* Pool Balance management features batching, which means a single contract call can be used to perform multiple
* operations of different kinds, with different Pools and tokens, at once.
*
* For each operation, the caller must be registered as the Asset Manager for `token` in `poolId`.
*/
function managePoolBalance(PoolBalanceOp[] memory ops) external;
struct PoolBalanceOp {
PoolBalanceOpKind kind;
bytes32 poolId;
IERC20 token;
uint256 amount;
}
/**
* Withdrawals decrease the Pool's cash, but increase its managed balance, leaving the total balance unchanged.
*
* Deposits increase the Pool's cash, but decrease its managed balance, leaving the total balance unchanged.
*
* Updates don't affect the Pool's cash balance, but because the managed balance changes, it does alter the total.
* The external amount can be either increased or decreased by this call (i.e., reporting a gain or a loss).
*/
enum PoolBalanceOpKind { WITHDRAW, DEPOSIT, UPDATE }
/**
* @dev Emitted when a Pool's token Asset Manager alters its balance via `managePoolBalance`.
*/
event PoolBalanceManaged(
bytes32 indexed poolId,
address indexed assetManager,
IERC20 indexed token,
int256 cashDelta,
int256 managedDelta
);
// Protocol Fees
//
// Some operations cause the Vault to collect tokens in the form of protocol fees, which can then be withdrawn by
// permissioned accounts.
//
// There are two kinds of protocol fees:
//
// - flash loan fees: charged on all flash loans, as a percentage of the amounts lent.
//
// - swap fees: a percentage of the fees charged by Pools when performing swaps. For a number of reasons, including
// swap gas costs and interface simplicity, protocol swap fees are not charged on each individual swap. Rather,
// Pools are expected to keep track of how much they have charged in swap fees, and pay any outstanding debts to the
// Vault when they are joined or exited. This prevents users from joining a Pool with unpaid debt, as well as
// exiting a Pool in debt without first paying their share.
/**
* @dev Returns the current protocol fee module.
*/
function getProtocolFeesCollector() external view returns (IProtocolFeesCollector);
/**
* @dev Safety mechanism to pause most Vault operations in the event of an emergency - typically detection of an
* error in some part of the system.
*
* The Vault can only be paused during an initial time period, after which pausing is forever disabled.
*
* While the contract is paused, the following features are disabled:
* - depositing and transferring internal balance
* - transferring external balance (using the Vault's allowance)
* - swaps
* - joining Pools
* - Asset Manager interactions
*
* Internal Balance can still be withdrawn, and Pools exited.
*/
function setPaused(bool paused) external;
/**
* @dev Returns the Vault's WETH instance.
*/
function WETH() external view returns (IWETH);
// solhint-disable-previous-line func-name-mixedcase
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2;
/// @dev Interface of the ERC20 standard as defined in the EIP.
/// @dev This includes the optional name, symbol, and decimals metadata.
interface IERC20 {
/// @dev Emitted when `value` tokens are moved from one account (`from`) to another (`to`).
event Transfer(address indexed from, address indexed to, uint256 value);
/// @dev Emitted when the allowance of a `spender` for an `owner` is set, where `value`
/// is the new allowance.
event Approval(address indexed owner, address indexed spender, uint256 value);
/// @notice Returns the amount of tokens in existence.
function totalSupply() external view returns (uint256);
/// @notice Returns the amount of tokens owned by `account`.
function balanceOf(address account) external view returns (uint256);
/// @notice Moves `amount` tokens from the caller's account to `to`.
function transfer(address to, uint256 amount) external returns (bool);
/// @notice Returns the remaining number of tokens that `spender` is allowed
/// to spend on behalf of `owner`
function allowance(address owner, address spender) external view returns (uint256);
/// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.
/// @dev Be aware of front-running risks: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
function approve(address spender, uint256 amount) external returns (bool);
/// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism.
/// `amount` is then deducted from the caller's allowance.
function transferFrom(address from, address to, uint256 amount) external returns (bool);
/// @notice Returns the name of the token.
function name() external view returns (string memory);
/// @notice Returns the symbol of the token.
function symbol() external view returns (string memory);
/// @notice Returns the decimals places of the token.
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../solidity-utils/openzeppelin/IERC20.sol";
library WeightedPoolUserData {
// In order to preserve backwards compatibility, make sure new join and exit kinds are added at the end of the enum.
enum JoinKind { INIT, EXACT_TOKENS_IN_FOR_BPT_OUT, TOKEN_IN_FOR_EXACT_BPT_OUT, ALL_TOKENS_IN_FOR_EXACT_BPT_OUT }
enum ExitKind { EXACT_BPT_IN_FOR_ONE_TOKEN_OUT, EXACT_BPT_IN_FOR_TOKENS_OUT, BPT_IN_FOR_EXACT_TOKENS_OUT }
function joinKind(bytes memory self) internal pure returns (JoinKind) {
return abi.decode(self, (JoinKind));
}
function exitKind(bytes memory self) internal pure returns (ExitKind) {
return abi.decode(self, (ExitKind));
}
// Joins
function initialAmountsIn(bytes memory self) internal pure returns (uint256[] memory amountsIn) {
(, amountsIn) = abi.decode(self, (JoinKind, uint256[]));
}
function exactTokensInForBptOut(bytes memory self)
internal
pure
returns (uint256[] memory amountsIn, uint256 minBPTAmountOut)
{
(, amountsIn, minBPTAmountOut) = abi.decode(self, (JoinKind, uint256[], uint256));
}
function tokenInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut, uint256 tokenIndex) {
(, bptAmountOut, tokenIndex) = abi.decode(self, (JoinKind, uint256, uint256));
}
function allTokensInForExactBptOut(bytes memory self) internal pure returns (uint256 bptAmountOut) {
(, bptAmountOut) = abi.decode(self, (JoinKind, uint256));
}
// Exits
function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
(, bptAmountIn, tokenIndex) = abi.decode(self, (ExitKind, uint256, uint256));
}
function exactBptInForTokensOut(bytes memory self) internal pure returns (uint256 bptAmountIn) {
(, bptAmountIn) = abi.decode(self, (ExitKind, uint256));
}
function bptInForExactTokensOut(bytes memory self)
internal
pure
returns (uint256[] memory amountsOut, uint256 maxBPTAmountIn)
{
(, amountsOut, maxBPTAmountIn) = abi.decode(self, (ExitKind, uint256[], uint256));
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
import { LogExpMath } from "./LogExpMath.sol";
/// @notice Support 18-decimal fixed point arithmetic. All Vault calculations use this for high and uniform precision.
library FixedPoint {
/// @notice Attempted division by zero.
error ZeroDivision();
// solhint-disable no-inline-assembly
// solhint-disable private-vars-leading-underscore
uint256 internal constant ONE = 1e18; // 18 decimal places
uint256 internal constant TWO = 2 * ONE;
uint256 internal constant FOUR = 4 * ONE;
uint256 internal constant MAX_POW_RELATIVE_ERROR = 10000; // 10^(-14)
function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {
// Multiplication overflow protection is provided by Solidity 0.8.x.
uint256 product = a * b;
return product / ONE;
}
function mulUp(uint256 a, uint256 b) internal pure returns (uint256 result) {
// Multiplication overflow protection is provided by Solidity 0.8.x.
uint256 product = a * b;
// Equivalent to:
// result = product == 0 ? 0 : ((product - 1) / FixedPoint.ONE) + 1
assembly ("memory-safe") {
result := mul(iszero(iszero(product)), add(div(sub(product, 1), ONE), 1))
}
}
function divDown(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity 0.8 reverts with a Panic code (0x11) if the multiplication overflows.
uint256 aInflated = a * ONE;
// Solidity 0.8 reverts with a "Division by Zero" Panic code (0x12) if b is zero
return aInflated / b;
}
function divUp(uint256 a, uint256 b) internal pure returns (uint256 result) {
return mulDivUp(a, ONE, b);
}
/// @dev Return (a * b) / c, rounding up.
function mulDivUp(uint256 a, uint256 b, uint256 c) internal pure returns (uint256 result) {
// This check is required because Yul's `div` doesn't revert on c==0.
if (c == 0) {
revert ZeroDivision();
}
// Multiple overflow protection is done by Solidity 0.8.x.
uint256 product = a * b;
// The traditional divUp formula is:
// divUp(x, y) := (x + y - 1) / y
// To avoid intermediate overflow in the addition, we distribute the division and get:
// divUp(x, y) := (x - 1) / y + 1
// Note that this requires x != 0, if x == 0 then the result is zero
//
// Equivalent to:
// result = a == 0 ? 0 : (a * b - 1) / c + 1
assembly ("memory-safe") {
result := mul(iszero(iszero(product)), add(div(sub(product, 1), c), 1))
}
}
/**
* @dev Version of divUp when the input is raw (i.e., already "inflated"). For instance,
* invariant * invariant (36 decimals) vs. invariant.mulDown(invariant) (18 decimal FP).
* This can occur in calculations with many successive multiplications and divisions, and
* we want to minimize the number of operations by avoiding unnecessary scaling by ONE.
*/
function divUpRaw(uint256 a, uint256 b) internal pure returns (uint256 result) {
// This check is required because Yul's `div` doesn't revert on b==0.
if (b == 0) {
revert ZeroDivision();
}
// Equivalent to:
// result = a == 0 ? 0 : 1 + (a - 1) / b
assembly ("memory-safe") {
result := mul(iszero(iszero(a)), add(1, div(sub(a, 1), b)))
}
}
/**
* @dev Returns x^y, assuming both are fixed point numbers, rounding down. The result is guaranteed to not be above
* the true value (that is, the error function expected - actual is always positive).
*/
function powDown(uint256 x, uint256 y) internal pure returns (uint256) {
// Optimize for when y equals 1.0, 2.0 or 4.0, as those are very simple to implement and occur often in 50/50
// and 80/20 Weighted Pools
if (y == ONE) {
return x;
} else if (y == TWO) {
return mulDown(x, x);
} else if (y == FOUR) {
uint256 square = mulDown(x, x);
return mulDown(square, square);
} else {
uint256 raw = LogExpMath.pow(x, y);
uint256 maxError = mulUp(raw, MAX_POW_RELATIVE_ERROR) + 1;
if (raw < maxError) {
return 0;
} else {
unchecked {
return raw - maxError;
}
}
}
}
/**
* @dev Returns x^y, assuming both are fixed point numbers, rounding up. The result is guaranteed to not be below
* the true value (that is, the error function expected - actual is always negative).
*/
function powUp(uint256 x, uint256 y) internal pure returns (uint256) {
// Optimize for when y equals 1.0, 2.0 or 4.0, as those are very simple to implement and occur often in 50/50
// and 80/20 Weighted Pools
if (y == ONE) {
return x;
} else if (y == TWO) {
return mulUp(x, x);
} else if (y == FOUR) {
uint256 square = mulUp(x, x);
return mulUp(square, square);
} else {
uint256 raw = LogExpMath.pow(x, y);
uint256 maxError = mulUp(raw, MAX_POW_RELATIVE_ERROR) + 1;
return raw + maxError;
}
}
/**
* @dev Returns the complement of a value (1 - x), capped to 0 if x is larger than 1.
*
* Useful when computing the complement for values with some level of relative error, as it strips this error and
* prevents intermediate negative values.
*/
function complement(uint256 x) internal pure returns (uint256 result) {
// Equivalent to:
// result = (x < ONE) ? (ONE - x) : 0
assembly ("memory-safe") {
result := mul(lt(x, ONE), sub(ONE, x))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
// solhint-disable
/**
* @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).
*
* Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural
* exponentiation and logarithm (where the base is Euler's number).
*
* All math operations are unchecked in order to save gas.
*
* @author Fernando Martinelli - @fernandomartinelli
* @author Sergio Yuhjtman - @sergioyuhjtman
* @author Daniel Fernandez - @dmf7z
*/
library LogExpMath {
/// @notice This error is thrown when a base is not within an acceptable range.
error BaseOutOfBounds();
/// @notice This error is thrown when a exponent is not within an acceptable range.
error ExponentOutOfBounds();
/// @notice This error is thrown when the exponent * ln(base) is not within an acceptable range.
error ProductOutOfBounds();
/// @notice This error is thrown when an exponent used in the exp function is not within an acceptable range.
error InvalidExponent();
/// @notice This error is thrown when a variable or result is not within the acceptable bounds defined in the function.
error OutOfBounds();
// All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying
// two numbers, and multiply by ONE when dividing them.
// All arguments and return values are 18 decimal fixed point numbers.
int256 constant ONE_18 = 1e18;
// Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the
// case of ln36, 36 decimals.
int256 constant ONE_20 = 1e20;
int256 constant ONE_36 = 1e36;
// The domain of natural exponentiation is bound by the word size and number of decimals used.
//
// Because internally the result will be stored using 20 decimals, the largest possible result is
// (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.
// The smallest possible result is 10^(-18), which makes largest negative argument
// ln(10^(-18)) = -41.446531673892822312.
// We use 130.0 and -41.0 to have some safety margin.
int256 constant MAX_NATURAL_EXPONENT = 130e18;
int256 constant MIN_NATURAL_EXPONENT = -41e18;
// Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point
// 256 bit integer.
int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;
int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;
uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);
// 18 decimal constants
int256 constant x0 = 128000000000000000000; // 2ˆ7
int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)
int256 constant x1 = 64000000000000000000; // 2ˆ6
int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)
// 20 decimal constants
int256 constant x2 = 3200000000000000000000; // 2ˆ5
int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)
int256 constant x3 = 1600000000000000000000; // 2ˆ4
int256 constant a3 = 888611052050787263676000000; // eˆ(x3)
int256 constant x4 = 800000000000000000000; // 2ˆ3
int256 constant a4 = 298095798704172827474000; // eˆ(x4)
int256 constant x5 = 400000000000000000000; // 2ˆ2
int256 constant a5 = 5459815003314423907810; // eˆ(x5)
int256 constant x6 = 200000000000000000000; // 2ˆ1
int256 constant a6 = 738905609893065022723; // eˆ(x6)
int256 constant x7 = 100000000000000000000; // 2ˆ0
int256 constant a7 = 271828182845904523536; // eˆ(x7)
int256 constant x8 = 50000000000000000000; // 2ˆ-1
int256 constant a8 = 164872127070012814685; // eˆ(x8)
int256 constant x9 = 25000000000000000000; // 2ˆ-2
int256 constant a9 = 128402541668774148407; // eˆ(x9)
int256 constant x10 = 12500000000000000000; // 2ˆ-3
int256 constant a10 = 113314845306682631683; // eˆ(x10)
int256 constant x11 = 6250000000000000000; // 2ˆ-4
int256 constant a11 = 106449445891785942956; // eˆ(x11)
/**
* @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.
*
* Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.
*/
function pow(uint256 x, uint256 y) internal pure returns (uint256) {
if (y == 0) {
// We solve the 0^0 indetermination by making it equal one.
return uint256(ONE_18);
}
if (x == 0) {
return 0;
}
// Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to
// arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means
// x^y = exp(y * ln(x)).
// The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
if (x >> 255 != 0) {
revert BaseOutOfBounds();
}
int256 x_int256 = int256(x);
// We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
// both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.
// This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
if (y >= MILD_EXPONENT_BOUND) {
revert ExponentOutOfBounds();
}
int256 y_int256 = int256(y);
int256 logx_times_y;
unchecked {
if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {
int256 ln_36_x = _ln_36(x_int256);
// ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just
// bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal
// multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the
// (downscaled) last 18 decimals.
logx_times_y = ((ln_36_x / ONE_18) * y_int256 + ((ln_36_x % ONE_18) * y_int256) / ONE_18);
} else {
logx_times_y = _ln(x_int256) * y_int256;
}
logx_times_y /= ONE_18;
}
// Finally, we compute exp(y * ln(x)) to arrive at x^y
if (!(MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT)) {
revert ProductOutOfBounds();
}
return uint256(exp(logx_times_y));
}
/**
* @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.
*
* Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.
*/
function exp(int256 x) internal pure returns (int256) {
if (!(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT)) {
revert InvalidExponent();
}
// We avoid using recursion here because zkSync doesn't support it.
bool negativeExponent = false;
if (x < 0) {
// We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it
// fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT). In the negative
// exponent case, compute e^x, then return 1 / result.
unchecked {
x = -x;
}
negativeExponent = true;
}
// First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,
// where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7
// because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the
// decomposition.
// At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this
// decomposition, which will be lower than the smallest x_n.
// exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.
// We mutate x by subtracting x_n, making it the remainder of the decomposition.
// The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause
// intermediate overflows. Instead we store them as plain integers, with 0 decimals.
// Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the
// decomposition.
// For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct
// it and compute the accumulated product.
int256 firstAN;
unchecked {
if (x >= x0) {
x -= x0;
firstAN = a0;
} else if (x >= x1) {
x -= x1;
firstAN = a1;
} else {
firstAN = 1; // One with no decimal places
}
// We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the
// smaller terms.
x *= 100;
}
// `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point
// one. Recall that fixed point multiplication requires dividing by ONE_20.
int256 product = ONE_20;
unchecked {
if (x >= x2) {
x -= x2;
product = (product * a2) / ONE_20;
}
if (x >= x3) {
x -= x3;
product = (product * a3) / ONE_20;
}
if (x >= x4) {
x -= x4;
product = (product * a4) / ONE_20;
}
if (x >= x5) {
x -= x5;
product = (product * a5) / ONE_20;
}
if (x >= x6) {
x -= x6;
product = (product * a6) / ONE_20;
}
if (x >= x7) {
x -= x7;
product = (product * a7) / ONE_20;
}
if (x >= x8) {
x -= x8;
product = (product * a8) / ONE_20;
}
if (x >= x9) {
x -= x9;
product = (product * a9) / ONE_20;
}
}
// x10 and x11 are unnecessary here since we have high enough precision already.
// Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series
// expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).
int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.
int256 term; // Each term in the sum, where the nth term is (x^n / n!).
// The first term is simply x.
term = x;
unchecked {
seriesSum += term;
// Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,
// multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.
term = ((term * x) / ONE_20) / 2;
seriesSum += term;
term = ((term * x) / ONE_20) / 3;
seriesSum += term;
term = ((term * x) / ONE_20) / 4;
seriesSum += term;
term = ((term * x) / ONE_20) / 5;
seriesSum += term;
term = ((term * x) / ONE_20) / 6;
seriesSum += term;
term = ((term * x) / ONE_20) / 7;
seriesSum += term;
term = ((term * x) / ONE_20) / 8;
seriesSum += term;
term = ((term * x) / ONE_20) / 9;
seriesSum += term;
term = ((term * x) / ONE_20) / 10;
seriesSum += term;
term = ((term * x) / ONE_20) / 11;
seriesSum += term;
term = ((term * x) / ONE_20) / 12;
seriesSum += term;
// 12 Taylor terms are sufficient for 18 decimal precision.
// We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor
// approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply
// all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),
// and then drop two digits to return an 18 decimal value.
int256 result = (((product * seriesSum) / ONE_20) * firstAN) / 100;
// We avoid using recursion here because zkSync doesn't support it.
return negativeExponent ? (ONE_18 * ONE_18) / result : result;
}
}
/// @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument.
function log(int256 arg, int256 base) internal pure returns (int256) {
// This performs a simple base change: log(arg, base) = ln(arg) / ln(base).
// Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by
// upscaling.
int256 logBase;
unchecked {
if (LN_36_LOWER_BOUND < base && base < LN_36_UPPER_BOUND) {
logBase = _ln_36(base);
} else {
logBase = _ln(base) * ONE_18;
}
}
int256 logArg;
unchecked {
if (LN_36_LOWER_BOUND < arg && arg < LN_36_UPPER_BOUND) {
logArg = _ln_36(arg);
} else {
logArg = _ln(arg) * ONE_18;
}
// When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places
return (logArg * ONE_18) / logBase;
}
}
/// @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
function ln(int256 a) internal pure returns (int256) {
// The real natural logarithm is not defined for negative numbers or zero.
if (a <= 0) {
revert OutOfBounds();
}
if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {
unchecked {
return _ln_36(a) / ONE_18;
}
} else {
return _ln(a);
}
}
/// @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
function _ln(int256 a) private pure returns (int256) {
// We avoid using recursion here because zkSync doesn't support it.
bool negativeExponent = false;
if (a < ONE_18) {
// Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less
// than one, 1/a will be greater than one, so in this case we compute ln(1/a) and negate the final result.
unchecked {
a = (ONE_18 * ONE_18) / a;
}
negativeExponent = true;
}
// First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which
// we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,
// ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot
// be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.
// At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this
// decomposition, which will be lower than the smallest a_n.
// ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.
// We mutate a by subtracting a_n, making it the remainder of the decomposition.
// For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point
// numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by
// ONE_18 to convert them to fixed point.
// For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide
// by it and compute the accumulated sum.
int256 sum = 0;
unchecked {
if (a >= a0 * ONE_18) {
a /= a0; // Integer, not fixed point division
sum += x0;
}
if (a >= a1 * ONE_18) {
a /= a1; // Integer, not fixed point division
sum += x1;
}
// All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.
sum *= 100;
a *= 100;
// Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.
if (a >= a2) {
a = (a * ONE_20) / a2;
sum += x2;
}
if (a >= a3) {
a = (a * ONE_20) / a3;
sum += x3;
}
if (a >= a4) {
a = (a * ONE_20) / a4;
sum += x4;
}
if (a >= a5) {
a = (a * ONE_20) / a5;
sum += x5;
}
if (a >= a6) {
a = (a * ONE_20) / a6;
sum += x6;
}
if (a >= a7) {
a = (a * ONE_20) / a7;
sum += x7;
}
if (a >= a8) {
a = (a * ONE_20) / a8;
sum += x8;
}
if (a >= a9) {
a = (a * ONE_20) / a9;
sum += x9;
}
if (a >= a10) {
a = (a * ONE_20) / a10;
sum += x10;
}
if (a >= a11) {
a = (a * ONE_20) / a11;
sum += x11;
}
}
// a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series
// that converges rapidly for values of `a` close to one - the same one used in ln_36.
// Let z = (a - 1) / (a + 1).
// ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires
// division by ONE_20.
unchecked {
int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);
int256 z_squared = (z * z) / ONE_20;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_20;
seriesSum += num / 3;
num = (num * z_squared) / ONE_20;
seriesSum += num / 5;
num = (num * z_squared) / ONE_20;
seriesSum += num / 7;
num = (num * z_squared) / ONE_20;
seriesSum += num / 9;
num = (num * z_squared) / ONE_20;
seriesSum += num / 11;
// 6 Taylor terms are sufficient for 36 decimal precision.
// Finally, we multiply by 2 (non fixed point) to compute ln(remainder)
seriesSum *= 2;
// We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both
// with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal
// value.
int256 result = (sum + seriesSum) / 100;
// We avoid using recursion here because zkSync doesn't support it.
return negativeExponent ? -result : result;
}
}
/**
* @dev Internal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,
* for x close to one.
*
* Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.
*/
function _ln_36(int256 x) private pure returns (int256) {
// Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits
// worthwhile.
// First, we transform x to a 36 digit fixed point value.
unchecked {
x *= ONE_18;
// We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).
// ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
// Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires
// division by ONE_36.
int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);
int256 z_squared = (z * z) / ONE_36;
// num is the numerator of the series: the z^(2 * n + 1) term
int256 num = z;
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
int256 seriesSum = num;
// In each step, the numerator is multiplied by z^2
num = (num * z_squared) / ONE_36;
seriesSum += num / 3;
num = (num * z_squared) / ONE_36;
seriesSum += num / 5;
num = (num * z_squared) / ONE_36;
seriesSum += num / 7;
num = (num * z_squared) / ONE_36;
seriesSum += num / 9;
num = (num * z_squared) / ONE_36;
seriesSum += num / 11;
num = (num * z_squared) / ONE_36;
seriesSum += num / 13;
num = (num * z_squared) / ONE_36;
seriesSum += num / 15;
// 8 Taylor terms are sufficient for 36 decimal precision.
// All that remains is multiplying by 2 (non fixed point).
return seriesSum * 2;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/extensions/AccessControlDefaultAdminRules.sol)
pragma solidity ^0.8.20;
import {IAccessControlDefaultAdminRules} from "./IAccessControlDefaultAdminRules.sol";
import {AccessControl, IAccessControl} from "../AccessControl.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {Math} from "../../utils/math/Math.sol";
import {IERC5313} from "../../interfaces/IERC5313.sol";
/**
* @dev Extension of {AccessControl} that allows specifying special rules to manage
* the `DEFAULT_ADMIN_ROLE` holder, which is a sensitive role with special permissions
* over other roles that may potentially have privileged rights in the system.
*
* If a specific role doesn't have an admin role assigned, the holder of the
* `DEFAULT_ADMIN_ROLE` will have the ability to grant it and revoke it.
*
* This contract implements the following risk mitigations on top of {AccessControl}:
*
* * Only one account holds the `DEFAULT_ADMIN_ROLE` since deployment until it's potentially renounced.
* * Enforces a 2-step process to transfer the `DEFAULT_ADMIN_ROLE` to another account.
* * Enforces a configurable delay between the two steps, with the ability to cancel before the transfer is accepted.
* * The delay can be changed by scheduling, see {changeDefaultAdminDelay}.
* * It is not possible to use another role to manage the `DEFAULT_ADMIN_ROLE`.
*
* Example usage:
*
* ```solidity
* contract MyToken is AccessControlDefaultAdminRules {
* constructor() AccessControlDefaultAdminRules(
* 3 days,
* msg.sender // Explicit initial `DEFAULT_ADMIN_ROLE` holder
* ) {}
* }
* ```
*/
abstract contract AccessControlDefaultAdminRules is IAccessControlDefaultAdminRules, IERC5313, AccessControl {
// pending admin pair read/written together frequently
address private _pendingDefaultAdmin;
uint48 private _pendingDefaultAdminSchedule; // 0 == unset
uint48 private _currentDelay;
address private _currentDefaultAdmin;
// pending delay pair read/written together frequently
uint48 private _pendingDelay;
uint48 private _pendingDelaySchedule; // 0 == unset
/**
* @dev Sets the initial values for {defaultAdminDelay} and {defaultAdmin} address.
*/
constructor(uint48 initialDelay, address initialDefaultAdmin) {
if (initialDefaultAdmin == address(0)) {
revert AccessControlInvalidDefaultAdmin(address(0));
}
_currentDelay = initialDelay;
_grantRole(DEFAULT_ADMIN_ROLE, initialDefaultAdmin);
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlDefaultAdminRules).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC5313-owner}.
*/
function owner() public view virtual returns (address) {
return defaultAdmin();
}
///
/// Override AccessControl role management
///
/**
* @dev See {AccessControl-grantRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
*/
function grantRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
if (role == DEFAULT_ADMIN_ROLE) {
revert AccessControlEnforcedDefaultAdminRules();
}
super.grantRole(role, account);
}
/**
* @dev See {AccessControl-revokeRole}. Reverts for `DEFAULT_ADMIN_ROLE`.
*/
function revokeRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
if (role == DEFAULT_ADMIN_ROLE) {
revert AccessControlEnforcedDefaultAdminRules();
}
super.revokeRole(role, account);
}
/**
* @dev See {AccessControl-renounceRole}.
*
* For the `DEFAULT_ADMIN_ROLE`, it only allows renouncing in two steps by first calling
* {beginDefaultAdminTransfer} to the `address(0)`, so it's required that the {pendingDefaultAdmin} schedule
* has also passed when calling this function.
*
* After its execution, it will not be possible to call `onlyRole(DEFAULT_ADMIN_ROLE)` functions.
*
* NOTE: Renouncing `DEFAULT_ADMIN_ROLE` will leave the contract without a {defaultAdmin},
* thereby disabling any functionality that is only available for it, and the possibility of reassigning a
* non-administrated role.
*/
function renounceRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
(address newDefaultAdmin, uint48 schedule) = pendingDefaultAdmin();
if (newDefaultAdmin != address(0) || !_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) {
revert AccessControlEnforcedDefaultAdminDelay(schedule);
}
delete _pendingDefaultAdminSchedule;
}
super.renounceRole(role, account);
}
/**
* @dev See {AccessControl-_grantRole}.
*
* For `DEFAULT_ADMIN_ROLE`, it only allows granting if there isn't already a {defaultAdmin} or if the
* role has been previously renounced.
*
* NOTE: Exposing this function through another mechanism may make the `DEFAULT_ADMIN_ROLE`
* assignable again. Make sure to guarantee this is the expected behavior in your implementation.
*/
function _grantRole(bytes32 role, address account) internal virtual override returns (bool) {
if (role == DEFAULT_ADMIN_ROLE) {
if (defaultAdmin() != address(0)) {
revert AccessControlEnforcedDefaultAdminRules();
}
_currentDefaultAdmin = account;
}
return super._grantRole(role, account);
}
/**
* @dev See {AccessControl-_revokeRole}.
*/
function _revokeRole(bytes32 role, address account) internal virtual override returns (bool) {
if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
delete _currentDefaultAdmin;
}
return super._revokeRole(role, account);
}
/**
* @dev See {AccessControl-_setRoleAdmin}. Reverts for `DEFAULT_ADMIN_ROLE`.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual override {
if (role == DEFAULT_ADMIN_ROLE) {
revert AccessControlEnforcedDefaultAdminRules();
}
super._setRoleAdmin(role, adminRole);
}
///
/// AccessControlDefaultAdminRules accessors
///
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function defaultAdmin() public view virtual returns (address) {
return _currentDefaultAdmin;
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function pendingDefaultAdmin() public view virtual returns (address newAdmin, uint48 schedule) {
return (_pendingDefaultAdmin, _pendingDefaultAdminSchedule);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function defaultAdminDelay() public view virtual returns (uint48) {
uint48 schedule = _pendingDelaySchedule;
return (_isScheduleSet(schedule) && _hasSchedulePassed(schedule)) ? _pendingDelay : _currentDelay;
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function pendingDefaultAdminDelay() public view virtual returns (uint48 newDelay, uint48 schedule) {
schedule = _pendingDelaySchedule;
return (_isScheduleSet(schedule) && !_hasSchedulePassed(schedule)) ? (_pendingDelay, schedule) : (0, 0);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function defaultAdminDelayIncreaseWait() public view virtual returns (uint48) {
return 5 days;
}
///
/// AccessControlDefaultAdminRules public and internal setters for defaultAdmin/pendingDefaultAdmin
///
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function beginDefaultAdminTransfer(address newAdmin) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_beginDefaultAdminTransfer(newAdmin);
}
/**
* @dev See {beginDefaultAdminTransfer}.
*
* Internal function without access restriction.
*/
function _beginDefaultAdminTransfer(address newAdmin) internal virtual {
uint48 newSchedule = SafeCast.toUint48(block.timestamp) + defaultAdminDelay();
_setPendingDefaultAdmin(newAdmin, newSchedule);
emit DefaultAdminTransferScheduled(newAdmin, newSchedule);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function cancelDefaultAdminTransfer() public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_cancelDefaultAdminTransfer();
}
/**
* @dev See {cancelDefaultAdminTransfer}.
*
* Internal function without access restriction.
*/
function _cancelDefaultAdminTransfer() internal virtual {
_setPendingDefaultAdmin(address(0), 0);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function acceptDefaultAdminTransfer() public virtual {
(address newDefaultAdmin, ) = pendingDefaultAdmin();
if (_msgSender() != newDefaultAdmin) {
// Enforce newDefaultAdmin explicit acceptance.
revert AccessControlInvalidDefaultAdmin(_msgSender());
}
_acceptDefaultAdminTransfer();
}
/**
* @dev See {acceptDefaultAdminTransfer}.
*
* Internal function without access restriction.
*/
function _acceptDefaultAdminTransfer() internal virtual {
(address newAdmin, uint48 schedule) = pendingDefaultAdmin();
if (!_isScheduleSet(schedule) || !_hasSchedulePassed(schedule)) {
revert AccessControlEnforcedDefaultAdminDelay(schedule);
}
_revokeRole(DEFAULT_ADMIN_ROLE, defaultAdmin());
_grantRole(DEFAULT_ADMIN_ROLE, newAdmin);
delete _pendingDefaultAdmin;
delete _pendingDefaultAdminSchedule;
}
///
/// AccessControlDefaultAdminRules public and internal setters for defaultAdminDelay/pendingDefaultAdminDelay
///
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function changeDefaultAdminDelay(uint48 newDelay) public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_changeDefaultAdminDelay(newDelay);
}
/**
* @dev See {changeDefaultAdminDelay}.
*
* Internal function without access restriction.
*/
function _changeDefaultAdminDelay(uint48 newDelay) internal virtual {
uint48 newSchedule = SafeCast.toUint48(block.timestamp) + _delayChangeWait(newDelay);
_setPendingDelay(newDelay, newSchedule);
emit DefaultAdminDelayChangeScheduled(newDelay, newSchedule);
}
/**
* @inheritdoc IAccessControlDefaultAdminRules
*/
function rollbackDefaultAdminDelay() public virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_rollbackDefaultAdminDelay();
}
/**
* @dev See {rollbackDefaultAdminDelay}.
*
* Internal function without access restriction.
*/
function _rollbackDefaultAdminDelay() internal virtual {
_setPendingDelay(0, 0);
}
/**
* @dev Returns the amount of seconds to wait after the `newDelay` will
* become the new {defaultAdminDelay}.
*
* The value returned guarantees that if the delay is reduced, it will go into effect
* after a wait that honors the previously set delay.
*
* See {defaultAdminDelayIncreaseWait}.
*/
function _delayChangeWait(uint48 newDelay) internal view virtual returns (uint48) {
uint48 currentDelay = defaultAdminDelay();
// When increasing the delay, we schedule the delay change to occur after a period of "new delay" has passed, up
// to a maximum given by defaultAdminDelayIncreaseWait, by default 5 days. For example, if increasing from 1 day
// to 3 days, the new delay will come into effect after 3 days. If increasing from 1 day to 10 days, the new
// delay will come into effect after 5 days. The 5 day wait period is intended to be able to fix an error like
// using milliseconds instead of seconds.
//
// When decreasing the delay, we wait the difference between "current delay" and "new delay". This guarantees
// that an admin transfer cannot be made faster than "current delay" at the time the delay change is scheduled.
// For example, if decreasing from 10 days to 3 days, the new delay will come into effect after 7 days.
return
newDelay > currentDelay
? uint48(Math.min(newDelay, defaultAdminDelayIncreaseWait())) // no need to safecast, both inputs are uint48
: currentDelay - newDelay;
}
///
/// Private setters
///
/**
* @dev Setter of the tuple for pending admin and its schedule.
*
* May emit a DefaultAdminTransferCanceled event.
*/
function _setPendingDefaultAdmin(address newAdmin, uint48 newSchedule) private {
(, uint48 oldSchedule) = pendingDefaultAdmin();
_pendingDefaultAdmin = newAdmin;
_pendingDefaultAdminSchedule = newSchedule;
// An `oldSchedule` from `pendingDefaultAdmin()` is only set if it hasn't been accepted.
if (_isScheduleSet(oldSchedule)) {
// Emit for implicit cancellations when another default admin was scheduled.
emit DefaultAdminTransferCanceled();
}
}
/**
* @dev Setter of the tuple for pending delay and its schedule.
*
* May emit a DefaultAdminDelayChangeCanceled event.
*/
function _setPendingDelay(uint48 newDelay, uint48 newSchedule) private {
uint48 oldSchedule = _pendingDelaySchedule;
if (_isScheduleSet(oldSchedule)) {
if (_hasSchedulePassed(oldSchedule)) {
// Materialize a virtual delay
_currentDelay = _pendingDelay;
} else {
// Emit for implicit cancellations when another delay was scheduled.
emit DefaultAdminDelayChangeCanceled();
}
}
_pendingDelay = newDelay;
_pendingDelaySchedule = newSchedule;
}
///
/// Private helpers
///
/**
* @dev Defines if an `schedule` is considered set. For consistency purposes.
*/
function _isScheduleSet(uint48 schedule) private pure returns (bool) {
return schedule != 0;
}
/**
* @dev Defines if an `schedule` is considered passed. For consistency purposes.
*/
function _hasSchedulePassed(uint48 schedule) private view returns (bool) {
return schedule < block.timestamp;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;
/// @notice General interface for token exchange rates.
interface IRateProvider {
/**
* @notice An 18 decimal fixed point number representing the exchange rate of one token to another related token.
* @dev The meaning of this rate depends on the context. Note that there may be an error associated with a token
* rate, and the caller might require a certain rounding direction to ensure correctness. This (legacy) interface
* does not take a rounding direction or return an error, so great care must be taken when interpreting and using
* rates in downstream computations.
*
* @return rate The current token rate
*/
function getRate() external view returns (uint256 rate);
}// SPDX-License-Identifier: LicenseRef-Gyro-1.0
// for information on licensing please see the README in the GitHub repository <https://github.com/gyrostable/core-protocol>.
pragma solidity ^0.8.4;
interface IGovernable {
/// @notice Emmited when the governor is changed
event GovernorChanged(address oldGovernor, address newGovernor);
/// @notice Emmited when the governor is change is requested
event GovernorChangeRequested(address newGovernor);
/// @notice Returns the current governor
function governor() external view returns (address);
/// @notice Returns the pending governor
function pendingGovernor() external view returns (address);
/// @notice Changes the governor
/// can only be called by the current governor
function changeGovernor(address newGovernor) external;
/// @notice Called by the pending governor to approve the change
function acceptGovernance() external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
interface IAuthentication {
/**
* @dev Returns the action identifier associated with the external function described by `selector`.
*/
function getActionId(bytes4 selector) external view returns (bytes32);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Interface for the SignatureValidator helper, used to support meta-transactions.
*/
interface ISignaturesValidator {
/**
* @dev Returns the EIP712 domain separator.
*/
function getDomainSeparator() external view returns (bytes32);
/**
* @dev Returns the next nonce used by an address to sign messages.
*/
function getNextNonce(address user) external view returns (uint256);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev Interface for the TemporarilyPausable helper.
*/
interface ITemporarilyPausable {
/**
* @dev Emitted every time the pause state changes by `_setPaused`.
*/
event PausedStateChanged(bool paused);
/**
* @dev Returns the current paused state.
*/
function getPausedState()
external
view
returns (
bool paused,
uint256 pauseWindowEndTime,
uint256 bufferPeriodEndTime
);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
import "../openzeppelin/IERC20.sol";
/**
* @dev Interface for WETH9.
* See https://github.com/gnosis/canonical-weth/blob/0dd1ea3e295eef916d0c6223ec63141137d22d67/contracts/WETH9.sol
*/
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256 amount) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
/**
* @dev This is an empty interface used to represent either ERC20-conforming token contracts or ETH (using the zero
* address sentinel value). We're just relying on the fact that `interface` can be used to declare new address-like
* types.
*
* This concept is unrelated to a Pool's Asset Managers.
*/
interface IAsset {
// solhint-disable-previous-line no-empty-blocks
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
interface IAuthorizer {
/**
* @dev Returns true if `account` can perform the action described by `actionId` in the contract `where`.
*/
function canPerform(
bytes32 actionId,
address account,
address where
) external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
// Inspired by Aave Protocol's IFlashLoanReceiver.
import "../solidity-utils/openzeppelin/IERC20.sol";
interface IFlashLoanRecipient {
/**
* @dev When `flashLoan` is called on the Vault, it invokes the `receiveFlashLoan` hook on the recipient.
*
* At the time of the call, the Vault will have transferred `amounts` for `tokens` to the recipient. Before this
* call returns, the recipient must have transferred `amounts` plus `feeAmounts` for each token back to the
* Vault, or else the entire flash loan will revert.
*
* `userData` is the same value passed in the `IVault.flashLoan` call.
*/
function receiveFlashLoan(
IERC20[] memory tokens,
uint256[] memory amounts,
uint256[] memory feeAmounts,
bytes memory userData
) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "../solidity-utils/openzeppelin/IERC20.sol";
import "./IVault.sol";
import "./IAuthorizer.sol";
interface IProtocolFeesCollector {
event SwapFeePercentageChanged(uint256 newSwapFeePercentage);
event FlashLoanFeePercentageChanged(uint256 newFlashLoanFeePercentage);
function withdrawCollectedFees(
IERC20[] calldata tokens,
uint256[] calldata amounts,
address recipient
) external;
function setSwapFeePercentage(uint256 newSwapFeePercentage) external;
function setFlashLoanFeePercentage(uint256 newFlashLoanFeePercentage) external;
function getSwapFeePercentage() external view returns (uint256);
function getFlashLoanFeePercentage() external view returns (uint256);
function getCollectedFeeAmounts(IERC20[] memory tokens) external view returns (uint256[] memory feeAmounts);
function getAuthorizer() external view returns (IAuthorizer);
function vault() external view returns (IVault);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/extensions/IAccessControlDefaultAdminRules.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "../IAccessControl.sol";
/**
* @dev External interface of AccessControlDefaultAdminRules declared to support ERC-165 detection.
*/
interface IAccessControlDefaultAdminRules is IAccessControl {
/**
* @dev The new default admin is not a valid default admin.
*/
error AccessControlInvalidDefaultAdmin(address defaultAdmin);
/**
* @dev At least one of the following rules was violated:
*
* - The `DEFAULT_ADMIN_ROLE` must only be managed by itself.
* - The `DEFAULT_ADMIN_ROLE` must only be held by one account at the time.
* - Any `DEFAULT_ADMIN_ROLE` transfer must be in two delayed steps.
*/
error AccessControlEnforcedDefaultAdminRules();
/**
* @dev The delay for transferring the default admin delay is enforced and
* the operation must wait until `schedule`.
*
* NOTE: `schedule` can be 0 indicating there's no transfer scheduled.
*/
error AccessControlEnforcedDefaultAdminDelay(uint48 schedule);
/**
* @dev Emitted when a {defaultAdmin} transfer is started, setting `newAdmin` as the next
* address to become the {defaultAdmin} by calling {acceptDefaultAdminTransfer} only after `acceptSchedule`
* passes.
*/
event DefaultAdminTransferScheduled(address indexed newAdmin, uint48 acceptSchedule);
/**
* @dev Emitted when a {pendingDefaultAdmin} is reset if it was never accepted, regardless of its schedule.
*/
event DefaultAdminTransferCanceled();
/**
* @dev Emitted when a {defaultAdminDelay} change is started, setting `newDelay` as the next
* delay to be applied between default admin transfer after `effectSchedule` has passed.
*/
event DefaultAdminDelayChangeScheduled(uint48 newDelay, uint48 effectSchedule);
/**
* @dev Emitted when a {pendingDefaultAdminDelay} is reset if its schedule didn't pass.
*/
event DefaultAdminDelayChangeCanceled();
/**
* @dev Returns the address of the current `DEFAULT_ADMIN_ROLE` holder.
*/
function defaultAdmin() external view returns (address);
/**
* @dev Returns a tuple of a `newAdmin` and an accept schedule.
*
* After the `schedule` passes, the `newAdmin` will be able to accept the {defaultAdmin} role
* by calling {acceptDefaultAdminTransfer}, completing the role transfer.
*
* A zero value only in `acceptSchedule` indicates no pending admin transfer.
*
* NOTE: A zero address `newAdmin` means that {defaultAdmin} is being renounced.
*/
function pendingDefaultAdmin() external view returns (address newAdmin, uint48 acceptSchedule);
/**
* @dev Returns the delay required to schedule the acceptance of a {defaultAdmin} transfer started.
*
* This delay will be added to the current timestamp when calling {beginDefaultAdminTransfer} to set
* the acceptance schedule.
*
* NOTE: If a delay change has been scheduled, it will take effect as soon as the schedule passes, making this
* function returns the new delay. See {changeDefaultAdminDelay}.
*/
function defaultAdminDelay() external view returns (uint48);
/**
* @dev Returns a tuple of `newDelay` and an effect schedule.
*
* After the `schedule` passes, the `newDelay` will get into effect immediately for every
* new {defaultAdmin} transfer started with {beginDefaultAdminTransfer}.
*
* A zero value only in `effectSchedule` indicates no pending delay change.
*
* NOTE: A zero value only for `newDelay` means that the next {defaultAdminDelay}
* will be zero after the effect schedule.
*/
function pendingDefaultAdminDelay() external view returns (uint48 newDelay, uint48 effectSchedule);
/**
* @dev Starts a {defaultAdmin} transfer by setting a {pendingDefaultAdmin} scheduled for acceptance
* after the current timestamp plus a {defaultAdminDelay}.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* Emits a DefaultAdminRoleChangeStarted event.
*/
function beginDefaultAdminTransfer(address newAdmin) external;
/**
* @dev Cancels a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}.
*
* A {pendingDefaultAdmin} not yet accepted can also be cancelled with this function.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* May emit a DefaultAdminTransferCanceled event.
*/
function cancelDefaultAdminTransfer() external;
/**
* @dev Completes a {defaultAdmin} transfer previously started with {beginDefaultAdminTransfer}.
*
* After calling the function:
*
* - `DEFAULT_ADMIN_ROLE` should be granted to the caller.
* - `DEFAULT_ADMIN_ROLE` should be revoked from the previous holder.
* - {pendingDefaultAdmin} should be reset to zero values.
*
* Requirements:
*
* - Only can be called by the {pendingDefaultAdmin}'s `newAdmin`.
* - The {pendingDefaultAdmin}'s `acceptSchedule` should've passed.
*/
function acceptDefaultAdminTransfer() external;
/**
* @dev Initiates a {defaultAdminDelay} update by setting a {pendingDefaultAdminDelay} scheduled for getting
* into effect after the current timestamp plus a {defaultAdminDelay}.
*
* This function guarantees that any call to {beginDefaultAdminTransfer} done between the timestamp this
* method is called and the {pendingDefaultAdminDelay} effect schedule will use the current {defaultAdminDelay}
* set before calling.
*
* The {pendingDefaultAdminDelay}'s effect schedule is defined in a way that waiting until the schedule and then
* calling {beginDefaultAdminTransfer} with the new delay will take at least the same as another {defaultAdmin}
* complete transfer (including acceptance).
*
* The schedule is designed for two scenarios:
*
* - When the delay is changed for a larger one the schedule is `block.timestamp + newDelay` capped by
* {defaultAdminDelayIncreaseWait}.
* - When the delay is changed for a shorter one, the schedule is `block.timestamp + (current delay - new delay)`.
*
* A {pendingDefaultAdminDelay} that never got into effect will be canceled in favor of a new scheduled change.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* Emits a DefaultAdminDelayChangeScheduled event and may emit a DefaultAdminDelayChangeCanceled event.
*/
function changeDefaultAdminDelay(uint48 newDelay) external;
/**
* @dev Cancels a scheduled {defaultAdminDelay} change.
*
* Requirements:
*
* - Only can be called by the current {defaultAdmin}.
*
* May emit a DefaultAdminDelayChangeCanceled event.
*/
function rollbackDefaultAdminDelay() external;
/**
* @dev Maximum time in seconds for an increase to {defaultAdminDelay} (that is scheduled using {changeDefaultAdminDelay})
* to take effect. Default to 5 days.
*
* When the {defaultAdminDelay} is scheduled to be increased, it goes into effect after the new delay has passed with
* the purpose of giving enough time for reverting any accidental change (i.e. using milliseconds instead of seconds)
* that may lock the contract. However, to avoid excessive schedules, the wait is capped by this function and it can
* be overrode for a custom {defaultAdminDelay} increase scheduling.
*
* IMPORTANT: Make sure to add a reasonable amount of time while overriding this value, otherwise,
* there's a risk of setting a high new delay that goes into effect almost immediately without the
* possibility of human intervention in the case of an input error (eg. set milliseconds instead of seconds).
*/
function defaultAdminDelayIncreaseWait() external view returns (uint48);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
assembly ("memory-safe") {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
assembly ("memory-safe") {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 1);
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 1);
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5313.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface for the Light Contract Ownership Standard.
*
* A standardized minimal interface required to identify an account that controls a contract
*/
interface IERC5313 {
/**
* @dev Gets the address of the owner.
*/
function owner() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*
* _Available since v5.1._
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
assembly ("memory-safe") {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}{
"remappings": [
"src/=src/",
"forge-std/=lib/forge-std/src/",
"oz/=lib/openzeppelin-contracts/contracts/",
"@chainlink/=node_modules/@chainlink/",
"balancer-v3-interfaces/=lib/balancer-v3-monorepo/pkg/interfaces/contracts/",
"balancer-v2-interfaces/=lib/balancer-v2-monorepo/pkg/interfaces/contracts/",
"balancer-v3/=lib/balancer-v3-monorepo/",
"gyro-concentrated-lps-balv2/=lib/gyro-concentrated-lps-balv2/",
"permit2/=lib/permit2/src/",
"@balancer-labs/v2-solidity-utils/=lib/balancer-v2-monorepo/pkg/solidity-utils/",
"@balancer-labs/v2-pool-utils/=lib/balancer-v2-monorepo/pkg/pool-utils/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"balancer-v2-monorepo/=lib/balancer-v2-monorepo/",
"balancer-v3-monorepo/=lib/balancer-v3-monorepo/",
"ds-test/=lib/permit2/lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"solmate/=lib/permit2/lib/solmate/"
],
"optimizer": {
"enabled": false,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_feed","type":"address"},{"internalType":"bool","name":"_invert","type":"bool"},{"internalType":"address","name":"_admin","type":"address"},{"internalType":"address","name":"_updater","type":"address"},{"internalType":"address","name":"_gyroConfigManager","type":"address"},{"internalType":"address","name":"_governanceRoleManager","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"uint48","name":"schedule","type":"uint48"}],"name":"AccessControlEnforcedDefaultAdminDelay","type":"error"},{"inputs":[],"name":"AccessControlEnforcedDefaultAdminRules","type":"error"},{"inputs":[{"internalType":"address","name":"defaultAdmin","type":"address"}],"name":"AccessControlInvalidDefaultAdmin","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[],"name":"DefaultAdminDelayChangeCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint48","name":"newDelay","type":"uint48"},{"indexed":false,"internalType":"uint48","name":"effectSchedule","type":"uint48"}],"name":"DefaultAdminDelayChangeScheduled","type":"event"},{"anonymous":false,"inputs":[],"name":"DefaultAdminTransferCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAdmin","type":"address"},{"indexed":false,"internalType":"uint48","name":"acceptSchedule","type":"uint48"}],"name":"DefaultAdminTransferScheduled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"enum BaseUpdatableRateProvider.PoolType","name":"poolType","type":"uint8"},{"indexed":false,"internalType":"uint8","name":"ourTokenIx","type":"uint8"}],"name":"PoolSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"},{"indexed":true,"internalType":"enum BaseUpdatableRateProvider.OutOfRangeSide","name":"why","type":"uint8"}],"name":"ValueUpdated","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPDATER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"acceptDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"beginDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelDefaultAdminTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"}],"name":"changeDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"defaultAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelay","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"defaultAdminDelayIncreaseWait","outputs":[{"internalType":"uint48","name":"","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feed","outputs":[{"internalType":"contract IRateProvider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governanceRoleManager","outputs":[{"internalType":"contract IGovernanceRoleManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"gyroConfigManager","outputs":[{"internalType":"contract IGyroConfigManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"invert","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ourTokenIx","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdmin","outputs":[{"internalType":"address","name":"newAdmin","type":"address"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDefaultAdminDelay","outputs":[{"internalType":"uint48","name":"newDelay","type":"uint48"},{"internalType":"uint48","name":"schedule","type":"uint48"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolType","outputs":[{"internalType":"enum BaseUpdatableRateProvider.PoolType","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rollbackDefaultAdminDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"enum BaseUpdatableRateProvider.PoolType","name":"_poolType","type":"uint8"}],"name":"setPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"updateToEdge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"value","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]Contract Creation Code
0x61010060405234801562000011575f80fd5b50604051620054aa380380620054aa8339818101604052810190620000379190620005fe565b8585858562015180825f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603620000b3575f6040517fc22c8022000000000000000000000000000000000000000000000000000000008152600401620000aa9190620006a7565b60405180910390fd5b816001601a6101000a81548165ffffffffffff021916908365ffffffffffff160217905550620000ec5f801b826200022560201b60201c565b5050505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146200015757620001557f555044415445525f524f4c450000000000000000000000000000000000000000826200022560201b60201c565b505b8373ffffffffffffffffffffffffffffffffffffffff1660808173ffffffffffffffffffffffffffffffffffffffff168152505082151560a081151581525050620001a76200030060201b60201c565b600481905550505050508173ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff1660e08173ffffffffffffffffffffffffffffffffffffffff168152505050505050505062000805565b5f805f1b8303620002e6575f73ffffffffffffffffffffffffffffffffffffffff1662000257620003a160201b60201c565b73ffffffffffffffffffffffffffffffffffffffff1614620002a5576040517f3fc3c27a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160025f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b620002f88383620003c960201b60201c565b905092915050565b5f60805173ffffffffffffffffffffffffffffffffffffffff1663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200034d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620003739190620006fa565b905060a051156200039e576200039b81670de0b6b3a7640000620004c460201b90919060201c565b90505b90565b5f60025f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b5f620003dc8383620004f560201b60201c565b620004ba5760015f808581526020019081526020015f205f015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff021916908315150217905550620004566200055860201b60201c565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a460019050620004be565b5f90505b92915050565b5f80670de0b6b3a764000084620004dc919062000757565b90508281620004ec9190620007ce565b91505092915050565b5f805f8481526020019081526020015f205f015f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900460ff16905092915050565b5f33905090565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6200058e8262000563565b9050919050565b620005a08162000582565b8114620005ab575f80fd5b50565b5f81519050620005be8162000595565b92915050565b5f8115159050919050565b620005da81620005c4565b8114620005e5575f80fd5b50565b5f81519050620005f881620005cf565b92915050565b5f805f805f8060c087890312156200061b576200061a6200055f565b5b5f6200062a89828a01620005ae565b96505060206200063d89828a01620005e8565b95505060406200065089828a01620005ae565b94505060606200066389828a01620005ae565b93505060806200067689828a01620005ae565b92505060a06200068989828a01620005ae565b9150509295509295509295565b620006a18162000582565b82525050565b5f602082019050620006bc5f83018462000696565b92915050565b5f819050919050565b620006d681620006c2565b8114620006e1575f80fd5b50565b5f81519050620006f481620006cb565b92915050565b5f602082840312156200071257620007116200055f565b5b5f6200072184828501620006e4565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6200076382620006c2565b91506200077083620006c2565b92508282026200078081620006c2565b915082820484148315176200079a57620007996200072a565b5b5092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f620007da82620006c2565b9150620007e783620006c2565b925082620007fa57620007f9620007a1565b5b828204905092915050565b60805160a05160c05160e051614c406200086a5f395f818161089f0152611cdc01525f81816105d80152818161179301528181611a7a01528181611b180152611bff01525f81816106210152612c6801525f81816107ee0152612bd90152614c405ff3fe608060405234801561000f575f80fd5b50600436106101d8575f3560e01c8063679aefce11610102578063b1dd61b6116100a0578063cefc14291161006f578063cefc1429146104ed578063cf6eefb7146104f7578063d547741f14610516578063d602b9fd14610532576101d8565b8063b1dd61b614610489578063b71061d1146104a7578063c724120f146104c5578063cc8463c8146104cf576101d8565b80638da5cb5b116100dc5780638da5cb5b146103fe57806391d148541461041c578063a1eda53c1461044c578063a217fddf1461046b576101d8565b8063679aefce146103a457806384ef8ffc146103c25780638754260c146103e0576101d8565b80632c9dbd351161017a5780633fa4f245116101495780633fa4f2451461033057806347e633801461034e578063634e93da1461036c578063649a5ec714610388576101d8565b80632c9dbd35146102be5780632f2ff15d146102da57806336568abe146102f657806337a7b7d814610312576101d8565b80630f6b1fe1116101b65780630f6b1fe11461023457806316f0115b146102525780631855dc4414610270578063248a9ca31461028e576101d8565b806301ffc9a7146101dc578063022d63fb1461020c5780630aa6220b1461022a575b5f80fd5b6101f660048036038101906101f19190613490565b61053c565b60405161020391906134d5565b60405180910390f35b6102146105b5565b604051610221919061350e565b60405180910390f35b6102326105bf565b005b61023c6105d6565b60405161024991906135a1565b60405180910390f35b61025a6105fa565b60405161026791906135da565b60405180910390f35b61027861061f565b60405161028591906134d5565b60405180910390f35b6102a860048036038101906102a39190613626565b610643565b6040516102b59190613660565b60405180910390f35b6102d860048036038101906102d391906136c6565b61065f565b005b6102f460048036038101906102ef9190613704565b610691565b005b610310600480360381019061030b9190613704565b6106da565b005b61031a6107ec565b6040516103279190613762565b60405180910390f35b610338610810565b6040516103459190613793565b60405180910390f35b610356610816565b6040516103639190613660565b60405180910390f35b610386600480360381019061038191906137ac565b61083a565b005b6103a2600480360381019061039d9190613801565b610853565b005b6103ac61086c565b6040516103b99190613793565b60405180910390f35b6103ca610875565b6040516103d791906135da565b60405180910390f35b6103e861089d565b6040516103f5919061384c565b60405180910390f35b6104066108c1565b60405161041391906135da565b60405180910390f35b61043660048036038101906104319190613704565b6108cf565b60405161044391906134d5565b60405180910390f35b610454610932565b604051610462929190613865565b60405180910390f35b610473610990565b6040516104809190613660565b60405180910390f35b610491610996565b60405161049e91906138ff565b60405180910390f35b6104af6109a9565b6040516104bc9190613933565b60405180910390f35b6104cd6109bc565b005b6104d7610b54565b6040516104e4919061350e565b60405180910390f35b6104f5610bc1565b005b6104ff610c56565b60405161050d92919061394c565b60405180910390f35b610530600480360381019061052b9190613704565b610c97565b005b61053a610ce0565b005b5f7f31498786000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806105ae57506105ad82610cf7565b5b9050919050565b5f62069780905090565b5f801b6105cb81610d70565b6105d3610d84565b50565b7f000000000000000000000000000000000000000000000000000000000000000081565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b7f000000000000000000000000000000000000000000000000000000000000000081565b5f805f8381526020019081526020015f20600101549050919050565b5f801b61066b81610d70565b5f6106768484610d90565b905061068b848461068684611194565b611251565b50505050565b5f801b82036106cc576040517f3fc3c27a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106d682826113ba565b5050565b5f801b8214801561071d57506106ee610875565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b156107de575f8061072c610c56565b915091505f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141580610771575061076f816113dc565b155b806107825750610780816113f0565b155b156107c457806040517f19ca5ebb0000000000000000000000000000000000000000000000000000000081526004016107bb919061350e565b60405180910390fd5b600160146101000a81549065ffffffffffff021916905550505b6107e88282611403565b5050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60045481565b7f555044415445525f524f4c45000000000000000000000000000000000000000081565b5f801b61084681610d70565b61084f8261147e565b5050565b5f801b61085f81610d70565b610868826114f8565b5050565b5f600454905090565b5f60025f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b7f000000000000000000000000000000000000000000000000000000000000000081565b5f6108ca610875565b905090565b5f805f8481526020019081526020015f205f015f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900460ff16905092915050565b5f806002601a9054906101000a900465ffffffffffff169050610954816113dc565b80156109665750610964816113f0565b155b610971575f80610988565b600260149054906101000a900465ffffffffffff16815b915091509091565b5f801b81565b600360149054906101000a900460ff1681565b600360159054906101000a900460ff1681565b7f555044415445525f524f4c4500000000000000000000000000000000000000006109e681610d70565b5f73ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1603610a75576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a6c906139cd565b60405180910390fd5b5f610ab060035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600360149054906101000a900460ff1661155e565b90505f610abf825f0151611788565b9050805f01518015610ad457505f8160200151145b610b0657610ae182611977565b610b05825f015160405180604001604052806001151581526020015f815250611a20565b5b5f80610b1184611d65565b91509150610b1f8282611f67565b825f01518015610b3257505f8360200151145b610b4d57610b3f846120d6565b610b4c845f015184611a20565b5b5050505050565b5f806002601a9054906101000a900465ffffffffffff169050610b76816113dc565b8015610b875750610b86816113f0565b5b610ba5576001601a9054906101000a900465ffffffffffff16610bbb565b600260149054906101000a900465ffffffffffff165b91505090565b5f610bca610c56565b5090508073ffffffffffffffffffffffffffffffffffffffff16610bec61215d565b73ffffffffffffffffffffffffffffffffffffffff1614610c4b57610c0f61215d565b6040517fc22c8022000000000000000000000000000000000000000000000000000000008152600401610c4291906135da565b60405180910390fd5b610c53612164565b50565b5f8060015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160149054906101000a900465ffffffffffff16915091509091565b5f801b8203610cd2576040517f3fc3c27a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610cdc828261222f565b5050565b5f801b610cec81610d70565b610cf4612251565b50565b5f7f7965db0b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161480610d695750610d688261225d565b5b9050919050565b610d8181610d7c61215d565b6122c6565b50565b610d8e5f80612317565b565b60605f6001811115610da557610da461388c565b5b826001811115610db857610db761388c565b5b03610f88575f839050600267ffffffffffffffff811115610ddc57610ddb6139eb565b5b604051908082528060200260200182016040528015610e0a5781602001602082028036833780820191505090505b5091508073ffffffffffffffffffffffffffffffffffffffff1663828a7c346040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e56573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e7a9190613a2c565b825f81518110610e8d57610e8c613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff166362ced0926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f10573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f349190613a2c565b82600181518110610f4857610f47613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505061118e565b600180811115610f9b57610f9a61388c565b5b826001811115610fae57610fad61388c565b5b0361117e575f839050600267ffffffffffffffff811115610fd257610fd16139eb565b5b6040519080825280602002602001820160405280156110005781602001602082028036833780820191505090505b5091508073ffffffffffffffffffffffffffffffffffffffff1663828a7c346040518163ffffffff1660e01b8152600401602060405180830381865afa15801561104c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110709190613a2c565b825f8151811061108357611082613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff166362ced0926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611106573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061112a9190613a2c565b8260018151811061113e5761113d613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505061118d565b5f61118c5761118b613a84565b5b5b5b92915050565b5f805f90505b82518160ff161015611210573073ffffffffffffffffffffffffffffffffffffffff16838260ff16815181106111d3576111d2613a57565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16036111ff578091505061124c565b8061120990613ade565b905061119a565b506040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161124390613b76565b60405180910390fd5b919050565b5f73ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146112e0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112d790613bde565b60405180910390fd5b8260035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600360146101000a81548160ff021916908360018111156113455761134461388c565b5b021790555080600360156101000a81548160ff021916908360ff1602179055508273ffffffffffffffffffffffffffffffffffffffff167fccd74cd713b8e75de035e0197901d2475669bcc87f55e343e3cbfb77cf224b4783836040516113ad929190613bfc565b60405180910390a2505050565b6113c382610643565b6113cc81610d70565b6113d68383612406565b50505050565b5f808265ffffffffffff1614159050919050565b5f428265ffffffffffff16109050919050565b61140b61215d565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161461146f576040517f6697b23200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61147982826124cf565b505050565b5f611487610b54565b6114904261254f565b61149a9190613c23565b90506114a682826125a8565b8173ffffffffffffffffffffffffffffffffffffffff167f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed6826040516114ec919061350e565b60405180910390a25050565b5f61150282612659565b61150b4261254f565b6115159190613c23565b90506115218282612317565b7ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b8282604051611552929190613865565b60405180910390a15050565b611566613368565b5f8390505f8173ffffffffffffffffffffffffffffffffffffffff16638d928af86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115b4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115d89190613a2c565b90505f8273ffffffffffffffffffffffffffffffffffffffff166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015611624573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116489190613c70565b905082845f019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505084846020019060018111156116995761169861388c565b5b908160018111156116ad576116ac61388c565b5b8152505081846040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050808460600181815250508173ffffffffffffffffffffffffffffffffffffffff1663f94d4668826040518263ffffffff1660e01b815260040161172c9190613660565b5f60405180830381865afa158015611746573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061176e9190613ee3565b50856080018660a001829052829052505050505092915050565b6117906133db565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166379502c556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117fa573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061181e9190613fa6565b90505f61184b847f50524f544f434f4c5f535741505f4645455f50455243000000000000000000006126b7565b90508173ffffffffffffffffffffffffffffffffffffffff1663696eb375826040518263ffffffff1660e01b81526004016118869190613660565b602060405180830381865afa1580156118a1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118c59190613ffb565b15611960576001835f0190151590811515815250508173ffffffffffffffffffffffffffffffffffffffff1663bd02d0f5826040518263ffffffff1660e01b81526004016119139190613660565b602060405180830381865afa15801561192e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119529190614026565b836020018181525050611970565b5f835f0190151590811515815250505b5050919050565b5f61198582608001516126e9565b90505f611a06828460a00151855f015173ffffffffffffffffffffffffffffffffffffffff1663876f303b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119dd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a019190614026565b612809565b9050611a118361291a565b611a1b8184612a2f565b505050565b5f600167ffffffffffffffff811115611a3c57611a3b6139eb565b5b604051908082528060200260200182016040528015611a7557816020015b611a626133f5565b815260200190600190039081611a5a5790505b5090507f0000000000000000000000000000000000000000000000000000000000000000815f81518110611aac57611aab613a57565b5b60200260200101515f019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505f815f81518110611afd57611afc613a57565b5b60200260200101516040018181525050815f015115611bfd577f0000000000000000000000000000000000000000000000000000000000000000506360b2cf7160e01b837f50524f544f434f4c5f535741505f4645455f50455243000000000000000000008460200151604051602401611b7993929190614051565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050815f81518110611be957611be8613a57565b5b602002602001015160200181905250611cda565b7f00000000000000000000000000000000000000000000000000000000000000005063ec1bf87560e01b837f50524f544f434f4c5f535741505f4645455f5045524300000000000000000000604051602401611c5a929190614086565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050815f81518110611cca57611cc9613a57565b5b6020026020010151602001819052505b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b4662f14826040518263ffffffff1660e01b8152600401611d33919061424d565b5f604051808303815f87803b158015611d4a575f80fd5b505af1158015611d5c573d5f803e3d5ffd5b50505050505050565b5f805f6001811115611d7a57611d7961388c565b5b83602001516001811115611d9157611d9061388c565b5b03611e1e575f835f015173ffffffffffffffffffffffffffffffffffffffff16637be219a26040518163ffffffff1660e01b81526004016101c060405180830381865afa158015611de4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e08919061442d565b509050805f015181602001519250925050611f62565b600180811115611e3157611e3061388c565b5b83602001516001811115611e4857611e4761388c565b5b03611f4d575f835f015173ffffffffffffffffffffffffffffffffffffffff1663707dcd1e6040518163ffffffff1660e01b81526004016040805180830381865afa158015611e99573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ebd919061451a565b9050611f00815f60028110611ed557611ed4613a57565b5b6020020151825f60028110611eed57611eec613a57565b5b6020020151612ba990919063ffffffff16565b611f4382600160028110611f1757611f16613a57565b5b602002015183600160028110611f3057611f2f613a57565b5b6020020151612ba990919063ffffffff16565b9250925050611f62565b5f611f5b57611f5a613a84565b5b5f80915091505b915091565b5f611f70612bd6565b90505f6001600360159054906101000a900460ff1660ff1614905080612032575f611fa48584612cad90919063ffffffff16565b90505f611fba8585612cad90919063ffffffff16565b9050816004541115611fd557611fd0825f612cda565b61202b565b806004541015611fef57611fea816001612cda565b61202a565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120219061458f565b60405180910390fd5b5b50506120d0565b5f6120468584612ba990919063ffffffff16565b90505f61205c8585612ba990919063ffffffff16565b905081600454101561207757612072825f612cda565b6120cd565b8060045411156120915761208c816001612cda565b6120cc565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120c39061458f565b60405180910390fd5b5b50505b50505050565b61215a815f015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161211591906135da565b602060405180830381865afa158015612130573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121549190614026565b82612d2f565b50565b5f33905090565b5f8061216e610c56565b9150915061217b816113dc565b158061218d575061218b816113f0565b155b156121cf57806040517f19ca5ebb0000000000000000000000000000000000000000000000000000000081526004016121c6919061350e565b60405180910390fd5b6121e25f801b6121dd610875565b6124cf565b506121ef5f801b83612406565b5060015f6101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600160146101000a81549065ffffffffffff02191690555050565b61223882610643565b61224181610d70565b61224b83836124cf565b50505050565b61225b5f806125a8565b565b5f7f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b6122d082826108cf565b6123135780826040517fe2517d3f00000000000000000000000000000000000000000000000000000000815260040161230a929190614086565b60405180910390fd5b5050565b5f6002601a9054906101000a900465ffffffffffff169050612338816113dc565b156123b757612346816113f0565b1561238957600260149054906101000a900465ffffffffffff166001601a6101000a81548165ffffffffffff021916908365ffffffffffff1602179055506123b6565b7f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec560405160405180910390a15b5b82600260146101000a81548165ffffffffffff021916908365ffffffffffff160217905550816002601a6101000a81548165ffffffffffff021916908365ffffffffffff160217905550505050565b5f805f1b83036124bd575f73ffffffffffffffffffffffffffffffffffffffff1661242f610875565b73ffffffffffffffffffffffffffffffffffffffff161461247c576040517f3fc3c27a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160025f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b6124c78383612e89565b905092915050565b5f805f1b8314801561251357506124e4610875565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b1561253d5760025f6101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690555b6125478383612f72565b905092915050565b5f65ffffffffffff80168211156125a0576030826040517f6dfcc6500000000000000000000000000000000000000000000000000000000081526004016125979291906145e6565b60405180910390fd5b819050919050565b5f6125b1610c56565b9150508260015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600160146101000a81548165ffffffffffff021916908365ffffffffffff160217905550612622816113dc565b15612654577f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510960405160405180910390a15b505050565b5f80612663610b54565b90508065ffffffffffff168365ffffffffffff161161268d578281612688919061460d565b6126af565b6126ae8365ffffffffffff166126a16105b5565b65ffffffffffff1661305b565b5b915050919050565b5f81836040516020016126cb929190614646565b60405160208183030381529060405280519060200120905092915050565b6060815167ffffffffffffffff811115612706576127056139eb565b5b6040519080825280602002602001820160405280156127345781602001602082028036833780820191505090505b5090505f5b8251811015612803575f83828151811061275657612755613a57565b5b602002602001015190508073ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161279991906135da565b602060405180830381865afa1580156127b4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127d89190614026565b8383815181106127eb576127ea613a57565b5b60200260200101818152505050806001019050612739565b50919050565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90505f5b84518110156128c1575f84828151811061284c5761284b613a57565b5b602002602001015111156128b6575f84828151811061286e5761286d613a57565b5b602002602001015186838151811061288957612888613a57565b5b60200260200101518561289c919061466d565b6128a691906146db565b9050828110156128b4578092505b505b80600101905061282f565b506002816128cf91906146db565b90505f8103612913576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161290a90614755565b60405180910390fd5b9392505050565b5f5b816080015151811015612a2b575f8260800151828151811061294157612940613a57565b5b602002602001015190505f8173ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e3086604001516040518363ffffffff1660e01b815260040161298b929190614773565b602060405180830381865afa1580156129a6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129ca9190614026565b03612a1f57612a1e83604001517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8373ffffffffffffffffffffffffffffffffffffffff166130719092919063ffffffff16565b5b5080600101905061291c565b5050565b5f81608001515167ffffffffffffffff811115612a4f57612a4e6139eb565b5b604051908082528060200260200182016040528015612a7d5781602001602082028036833780820191505090505b5090505f5b826080015151811015612ada577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff828281518110612ac357612ac2613a57565b5b602002602001018181525050806001019050612a82565b505f600384604051602001612af09291906147e0565b6040516020818303038152906040529050826040015173ffffffffffffffffffffffffffffffffffffffff1663b95cac28846060015130306040518060800160405280612b408a6080015161317e565b81526020018881526020018781526020015f15158152506040518563ffffffff1660e01b8152600401612b7694939291906149f4565b5f604051808303815f87803b158015612b8d575f80fd5b505af1158015612b9f573d5f803e3d5ffd5b5050505050505050565b5f808284612bb7919061466d565b9050670de0b6b3a764000081612bcd91906146db565b91505092915050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c40573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c649190614026565b90507f000000000000000000000000000000000000000000000000000000000000000015612caa57612ca781670de0b6b3a7640000612cad90919063ffffffff16565b90505b90565b5f80670de0b6b3a764000084612cc3919061466d565b90508281612cd191906146db565b91505092915050565b81600481905550806001811115612cf457612cf361388c565b5b7f40ce3c3e059a5994a81170ca3a882c3fb0dd4815695f91d7ccaca797ab97962983604051612d239190613793565b60405180910390a25050565b5f81608001515167ffffffffffffffff811115612d4f57612d4e6139eb565b5b604051908082528060200260200182016040528015612d7d5781602001602082028036833780820191505090505b5090505f5b826080015151811015612dba575f828281518110612da357612da2613a57565b5b602002602001018181525050806001019050612d82565b505f600184604051602001612dd0929190614a84565b6040516020818303038152906040529050826040015173ffffffffffffffffffffffffffffffffffffffff16638bdb3913846060015130306040518060800160405280612e208a6080015161317e565b81526020018881526020018781526020015f15158152506040518563ffffffff1660e01b8152600401612e569493929190614b39565b5f604051808303815f87803b158015612e6d575f80fd5b505af1158015612e7f573d5f803e3d5ffd5b5050505050505050565b5f612e9483836108cf565b612f685760015f808581526020019081526020015f205f015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff021916908315150217905550612f0561215d565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a460019050612f6c565b5f90505b92915050565b5f612f7d83836108cf565b15613051575f805f8581526020019081526020015f205f015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff021916908315150217905550612fee61215d565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16847ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a460019050613055565b5f90505b92915050565b5f6130698284108484613250565b905092915050565b5f8373ffffffffffffffffffffffffffffffffffffffff1663095ea7b384846040516024016130a1929190614b83565b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090506130ef8482613269565b6131785761316d848573ffffffffffffffffffffffffffffffffffffffff1663095ea7b3865f604051602401613126929190614be3565b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506132c2565b61317784826132c2565b5b50505050565b6060815167ffffffffffffffff81111561319b5761319a6139eb565b5b6040519080825280602002602001820160405280156131c95781602001602082028036833780820191505090505b5090505f5b825181101561324a578281815181106131ea576131e9613a57565b5b602002602001015182828151811061320557613204613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508060010190506131ce565b50919050565b5f61325a8461335d565b82841802821890509392505050565b5f805f8060205f8651602088015f8a5af192503d91505f5190508280156132b757505f821461329b57600181146132b6565b5f8673ffffffffffffffffffffffffffffffffffffffff163b115b5b935050505092915050565b5f8060205f8451602086015f885af1806132e1576040513d5f823e3d81fd5b3d92505f519150505f82146132fa576001811415613315565b5f8473ffffffffffffffffffffffffffffffffffffffff163b145b1561335757836040517f5274afe700000000000000000000000000000000000000000000000000000000815260040161334e91906135da565b60405180910390fd5b50505050565b5f8115159050919050565b6040518060c001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f60018111156133a2576133a161388c565b5b81526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f801916815260200160608152602001606081525090565b60405180604001604052805f151581526020015f81525090565b60405180606001604052805f73ffffffffffffffffffffffffffffffffffffffff168152602001606081526020015f81525090565b5f604051905090565b5f80fd5b5f80fd5b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61346f8161343b565b8114613479575f80fd5b50565b5f8135905061348a81613466565b92915050565b5f602082840312156134a5576134a4613433565b5b5f6134b28482850161347c565b91505092915050565b5f8115159050919050565b6134cf816134bb565b82525050565b5f6020820190506134e85f8301846134c6565b92915050565b5f65ffffffffffff82169050919050565b613508816134ee565b82525050565b5f6020820190506135215f8301846134ff565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f819050919050565b5f61356961356461355f84613527565b613546565b613527565b9050919050565b5f61357a8261354f565b9050919050565b5f61358b82613570565b9050919050565b61359b81613581565b82525050565b5f6020820190506135b45f830184613592565b92915050565b5f6135c482613527565b9050919050565b6135d4816135ba565b82525050565b5f6020820190506135ed5f8301846135cb565b92915050565b5f819050919050565b613605816135f3565b811461360f575f80fd5b50565b5f81359050613620816135fc565b92915050565b5f6020828403121561363b5761363a613433565b5b5f61364884828501613612565b91505092915050565b61365a816135f3565b82525050565b5f6020820190506136735f830184613651565b92915050565b613682816135ba565b811461368c575f80fd5b50565b5f8135905061369d81613679565b92915050565b600281106136af575f80fd5b50565b5f813590506136c0816136a3565b92915050565b5f80604083850312156136dc576136db613433565b5b5f6136e98582860161368f565b92505060206136fa858286016136b2565b9150509250929050565b5f806040838503121561371a57613719613433565b5b5f61372785828601613612565b92505060206137388582860161368f565b9150509250929050565b5f61374c82613570565b9050919050565b61375c81613742565b82525050565b5f6020820190506137755f830184613753565b92915050565b5f819050919050565b61378d8161377b565b82525050565b5f6020820190506137a65f830184613784565b92915050565b5f602082840312156137c1576137c0613433565b5b5f6137ce8482850161368f565b91505092915050565b6137e0816134ee565b81146137ea575f80fd5b50565b5f813590506137fb816137d7565b92915050565b5f6020828403121561381657613815613433565b5b5f613823848285016137ed565b91505092915050565b5f61383682613570565b9050919050565b6138468161382c565b82525050565b5f60208201905061385f5f83018461383d565b92915050565b5f6040820190506138785f8301856134ff565b61388560208301846134ff565b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b600281106138ca576138c961388c565b5b50565b5f8190506138da826138b9565b919050565b5f6138e9826138cd565b9050919050565b6138f9816138df565b82525050565b5f6020820190506139125f8301846138f0565b92915050565b5f60ff82169050919050565b61392d81613918565b82525050565b5f6020820190506139465f830184613924565b92915050565b5f60408201905061395f5f8301856135cb565b61396c60208301846134ff565b9392505050565b5f82825260208201905092915050565b7f506f6f6c206e6f742073657400000000000000000000000000000000000000005f82015250565b5f6139b7600c83613973565b91506139c282613983565b602082019050919050565b5f6020820190508181035f8301526139e4816139ab565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f81519050613a2681613679565b92915050565b5f60208284031215613a4157613a40613433565b5b5f613a4e84828501613a18565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f613ae882613918565b915060ff8203613afb57613afa613ab1565b5b600182019050919050565b7f5261746570726f7669646572206e6f7420636f6e6669677572656420696e20705f8201527f6f6f6c2e00000000000000000000000000000000000000000000000000000000602082015250565b5f613b60602483613973565b9150613b6b82613b06565b604082019050919050565b5f6020820190508181035f830152613b8d81613b54565b9050919050565b7f506f6f6c20616c726561647920736574000000000000000000000000000000005f82015250565b5f613bc8601083613973565b9150613bd382613b94565b602082019050919050565b5f6020820190508181035f830152613bf581613bbc565b9050919050565b5f604082019050613c0f5f8301856138f0565b613c1c6020830184613924565b9392505050565b5f613c2d826134ee565b9150613c38836134ee565b9250828201905065ffffffffffff811115613c5657613c55613ab1565b5b92915050565b5f81519050613c6a816135fc565b92915050565b5f60208284031215613c8557613c84613433565b5b5f613c9284828501613c5c565b91505092915050565b5f80fd5b5f601f19601f8301169050919050565b613cb882613c9f565b810181811067ffffffffffffffff82111715613cd757613cd66139eb565b5b80604052505050565b5f613ce961342a565b9050613cf58282613caf565b919050565b5f67ffffffffffffffff821115613d1457613d136139eb565b5b602082029050602081019050919050565b5f80fd5b5f613d33826135ba565b9050919050565b613d4381613d29565b8114613d4d575f80fd5b50565b5f81519050613d5e81613d3a565b92915050565b5f613d76613d7184613cfa565b613ce0565b90508083825260208201905060208402830185811115613d9957613d98613d25565b5b835b81811015613dc25780613dae8882613d50565b845260208401935050602081019050613d9b565b5050509392505050565b5f82601f830112613de057613ddf613c9b565b5b8151613df0848260208601613d64565b91505092915050565b5f67ffffffffffffffff821115613e1357613e126139eb565b5b602082029050602081019050919050565b613e2d8161377b565b8114613e37575f80fd5b50565b5f81519050613e4881613e24565b92915050565b5f613e60613e5b84613df9565b613ce0565b90508083825260208201905060208402830185811115613e8357613e82613d25565b5b835b81811015613eac5780613e988882613e3a565b845260208401935050602081019050613e85565b5050509392505050565b5f82601f830112613eca57613ec9613c9b565b5b8151613eda848260208601613e4e565b91505092915050565b5f805f60608486031215613efa57613ef9613433565b5b5f84015167ffffffffffffffff811115613f1757613f16613437565b5b613f2386828701613dcc565b935050602084015167ffffffffffffffff811115613f4457613f43613437565b5b613f5086828701613eb6565b9250506040613f6186828701613e3a565b9150509250925092565b5f613f75826135ba565b9050919050565b613f8581613f6b565b8114613f8f575f80fd5b50565b5f81519050613fa081613f7c565b92915050565b5f60208284031215613fbb57613fba613433565b5b5f613fc884828501613f92565b91505092915050565b613fda816134bb565b8114613fe4575f80fd5b50565b5f81519050613ff581613fd1565b92915050565b5f602082840312156140105761400f613433565b5b5f61401d84828501613fe7565b91505092915050565b5f6020828403121561403b5761403a613433565b5b5f61404884828501613e3a565b91505092915050565b5f6060820190506140645f8301866135cb565b6140716020830185613651565b61407e6040830184613784565b949350505050565b5f6040820190506140995f8301856135cb565b6140a66020830184613651565b9392505050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6140df816135ba565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561411c578082015181840152602081019050614101565b5f8484015250505050565b5f614131826140e5565b61413b81856140ef565b935061414b8185602086016140ff565b61415481613c9f565b840191505092915050565b6141688161377b565b82525050565b5f606083015f8301516141835f8601826140d6565b506020830151848203602086015261419b8282614127565b91505060408301516141b0604086018261415f565b508091505092915050565b5f6141c6838361416e565b905092915050565b5f602082019050919050565b5f6141e4826140ad565b6141ee81856140b7565b935083602082028501614200856140c7565b805f5b8581101561423b578484038952815161421c85826141bb565b9450614227836141ce565b925060208a01995050600181019050614203565b50829750879550505050505092915050565b5f6020820190508181035f83015261426581846141da565b905092915050565b5f80fd5b5f819050919050565b61428381614271565b811461428d575f80fd5b50565b5f8151905061429e8161427a565b92915050565b5f60a082840312156142b9576142b861426d565b5b6142c360a0613ce0565b90505f6142d284828501614290565b5f8301525060206142e584828501614290565b60208301525060406142f984828501614290565b604083015250606061430d84828501614290565b606083015250608061432184828501614290565b60808301525092915050565b5f604082840312156143425761434161426d565b5b61434c6040613ce0565b90505f61435b84828501614290565b5f83015250602061436e84828501614290565b60208301525092915050565b5f61012082840312156143905761438f61426d565b5b61439a60e0613ce0565b90505f6143a98482850161432d565b5f8301525060406143bc8482850161432d565b60208301525060806143d084828501614290565b60408301525060a06143e484828501614290565b60608301525060c06143f884828501614290565b60808301525060e061440c84828501614290565b60a08301525061010061442184828501614290565b60c08301525092915050565b5f806101c0838503121561444457614443613433565b5b5f614451858286016142a4565b92505060a06144628582860161437a565b9150509250929050565b5f67ffffffffffffffff821115614486576144856139eb565b5b602082029050919050565b5f6144a361449e8461446c565b613ce0565b905080602084028301858111156144bd576144bc613d25565b5b835b818110156144e657806144d28882613e3a565b8452602084019350506020810190506144bf565b5050509392505050565b5f82601f83011261450457614503613c9b565b5b6002614511848285614491565b91505092915050565b5f6040828403121561452f5761452e613433565b5b5f61453c848285016144f0565b91505092915050565b7f506f6f6c206e6f74206f7574206f662072616e676500000000000000000000005f82015250565b5f614579601583613973565b915061458482614545565b602082019050919050565b5f6020820190508181035f8301526145a68161456d565b9050919050565b5f819050919050565b5f6145d06145cb6145c6846145ad565b613546565b613918565b9050919050565b6145e0816145b6565b82525050565b5f6040820190506145f95f8301856145d7565b6146066020830184613784565b9392505050565b5f614617826134ee565b9150614622836134ee565b9250828203905065ffffffffffff8111156146405761463f613ab1565b5b92915050565b5f6040820190506146595f830185613651565b61466660208301846135cb565b9392505050565b5f6146778261377b565b91506146828361377b565b92508282026146908161377b565b915082820484148315176146a7576146a6613ab1565b5b5092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f6146e58261377b565b91506146f08361377b565b925082614700576146ff6146ae565b5b828204905092915050565b7f4e6f7420656e6f756768206173736574732e00000000000000000000000000005f82015250565b5f61473f601283613973565b915061474a8261470b565b602082019050919050565b5f6020820190508181035f83015261476c81614733565b9050919050565b5f6040820190506147865f8301856135cb565b61479360208301846135cb565b9392505050565b600481106147ab576147aa61388c565b5b50565b5f8190506147bb8261479a565b919050565b5f6147ca826147ae565b9050919050565b6147da816147c0565b82525050565b5f6040820190506147f35f8301856147d1565b6148006020830184613784565b9392505050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f61483a82613570565b9050919050565b61484a81614830565b82525050565b5f61485b8383614841565b60208301905092915050565b5f602082019050919050565b5f61487d82614807565b6148878185614811565b935061489283614821565b805f5b838110156148c25781516148a98882614850565b97506148b483614867565b925050600181019050614895565b5085935050505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f614903838361415f565b60208301905092915050565b5f602082019050919050565b5f614925826148cf565b61492f81856148d9565b935061493a836148e9565b805f5b8381101561496a57815161495188826148f8565b975061495c8361490f565b92505060018101905061493d565b5085935050505092915050565b614980816134bb565b82525050565b5f608083015f8301518482035f8601526149a08282614873565b915050602083015184820360208601526149ba828261491b565b915050604083015184820360408601526149d48282614127565b91505060608301516149e96060860182614977565b508091505092915050565b5f608082019050614a075f830187613651565b614a1460208301866135cb565b614a2160408301856135cb565b8181036060830152614a338184614986565b905095945050505050565b60038110614a4f57614a4e61388c565b5b50565b5f819050614a5f82614a3e565b919050565b5f614a6e82614a52565b9050919050565b614a7e81614a64565b82525050565b5f604082019050614a975f830185614a75565b614aa46020830184613784565b9392505050565b5f614ab582613527565b9050919050565b614ac581614aab565b82525050565b5f608083015f8301518482035f860152614ae58282614873565b91505060208301518482036020860152614aff828261491b565b91505060408301518482036040860152614b198282614127565b9150506060830151614b2e6060860182614977565b508091505092915050565b5f608082019050614b4c5f830187613651565b614b5960208301866135cb565b614b666040830185614abc565b8181036060830152614b788184614acb565b905095945050505050565b5f604082019050614b965f8301856135cb565b614ba36020830184613784565b9392505050565b5f819050919050565b5f614bcd614bc8614bc384614baa565b613546565b61377b565b9050919050565b614bdd81614bb3565b82525050565b5f604082019050614bf65f8301856135cb565b614c036020830184614bd4565b939250505056fea2646970667358221220be69c9cf6547f702202424a83b059f19972ecbbfccfa8f54f52557546f6850ae64736f6c6343000818003300000000000000000000000079a88bb30beebc41f2b104a86f5dc96c70c40447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000097079f7e04b535fe7cd3f972ce558412dfb33946000000000000000000000000fac37371dfafbfa0937df84532d1eded08b21718000000000000000000000000ce276785e78796dcbb4fe07fd335c89a1f784ca4000000000000000000000000f47998c67d7ebbba8780b37c5d92cb282eb26905
Deployed Bytecode
0x608060405234801561000f575f80fd5b50600436106101d8575f3560e01c8063679aefce11610102578063b1dd61b6116100a0578063cefc14291161006f578063cefc1429146104ed578063cf6eefb7146104f7578063d547741f14610516578063d602b9fd14610532576101d8565b8063b1dd61b614610489578063b71061d1146104a7578063c724120f146104c5578063cc8463c8146104cf576101d8565b80638da5cb5b116100dc5780638da5cb5b146103fe57806391d148541461041c578063a1eda53c1461044c578063a217fddf1461046b576101d8565b8063679aefce146103a457806384ef8ffc146103c25780638754260c146103e0576101d8565b80632c9dbd351161017a5780633fa4f245116101495780633fa4f2451461033057806347e633801461034e578063634e93da1461036c578063649a5ec714610388576101d8565b80632c9dbd35146102be5780632f2ff15d146102da57806336568abe146102f657806337a7b7d814610312576101d8565b80630f6b1fe1116101b65780630f6b1fe11461023457806316f0115b146102525780631855dc4414610270578063248a9ca31461028e576101d8565b806301ffc9a7146101dc578063022d63fb1461020c5780630aa6220b1461022a575b5f80fd5b6101f660048036038101906101f19190613490565b61053c565b60405161020391906134d5565b60405180910390f35b6102146105b5565b604051610221919061350e565b60405180910390f35b6102326105bf565b005b61023c6105d6565b60405161024991906135a1565b60405180910390f35b61025a6105fa565b60405161026791906135da565b60405180910390f35b61027861061f565b60405161028591906134d5565b60405180910390f35b6102a860048036038101906102a39190613626565b610643565b6040516102b59190613660565b60405180910390f35b6102d860048036038101906102d391906136c6565b61065f565b005b6102f460048036038101906102ef9190613704565b610691565b005b610310600480360381019061030b9190613704565b6106da565b005b61031a6107ec565b6040516103279190613762565b60405180910390f35b610338610810565b6040516103459190613793565b60405180910390f35b610356610816565b6040516103639190613660565b60405180910390f35b610386600480360381019061038191906137ac565b61083a565b005b6103a2600480360381019061039d9190613801565b610853565b005b6103ac61086c565b6040516103b99190613793565b60405180910390f35b6103ca610875565b6040516103d791906135da565b60405180910390f35b6103e861089d565b6040516103f5919061384c565b60405180910390f35b6104066108c1565b60405161041391906135da565b60405180910390f35b61043660048036038101906104319190613704565b6108cf565b60405161044391906134d5565b60405180910390f35b610454610932565b604051610462929190613865565b60405180910390f35b610473610990565b6040516104809190613660565b60405180910390f35b610491610996565b60405161049e91906138ff565b60405180910390f35b6104af6109a9565b6040516104bc9190613933565b60405180910390f35b6104cd6109bc565b005b6104d7610b54565b6040516104e4919061350e565b60405180910390f35b6104f5610bc1565b005b6104ff610c56565b60405161050d92919061394c565b60405180910390f35b610530600480360381019061052b9190613704565b610c97565b005b61053a610ce0565b005b5f7f31498786000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614806105ae57506105ad82610cf7565b5b9050919050565b5f62069780905090565b5f801b6105cb81610d70565b6105d3610d84565b50565b7f000000000000000000000000ce276785e78796dcbb4fe07fd335c89a1f784ca481565b60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b7f000000000000000000000000000000000000000000000000000000000000000081565b5f805f8381526020019081526020015f20600101549050919050565b5f801b61066b81610d70565b5f6106768484610d90565b905061068b848461068684611194565b611251565b50505050565b5f801b82036106cc576040517f3fc3c27a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106d682826113ba565b5050565b5f801b8214801561071d57506106ee610875565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b156107de575f8061072c610c56565b915091505f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141580610771575061076f816113dc565b155b806107825750610780816113f0565b155b156107c457806040517f19ca5ebb0000000000000000000000000000000000000000000000000000000081526004016107bb919061350e565b60405180910390fd5b600160146101000a81549065ffffffffffff021916905550505b6107e88282611403565b5050565b7f00000000000000000000000079a88bb30beebc41f2b104a86f5dc96c70c4044781565b60045481565b7f555044415445525f524f4c45000000000000000000000000000000000000000081565b5f801b61084681610d70565b61084f8261147e565b5050565b5f801b61085f81610d70565b610868826114f8565b5050565b5f600454905090565b5f60025f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b7f000000000000000000000000f47998c67d7ebbba8780b37c5d92cb282eb2690581565b5f6108ca610875565b905090565b5f805f8481526020019081526020015f205f015f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900460ff16905092915050565b5f806002601a9054906101000a900465ffffffffffff169050610954816113dc565b80156109665750610964816113f0565b155b610971575f80610988565b600260149054906101000a900465ffffffffffff16815b915091509091565b5f801b81565b600360149054906101000a900460ff1681565b600360159054906101000a900460ff1681565b7f555044415445525f524f4c4500000000000000000000000000000000000000006109e681610d70565b5f73ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1603610a75576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a6c906139cd565b60405180910390fd5b5f610ab060035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600360149054906101000a900460ff1661155e565b90505f610abf825f0151611788565b9050805f01518015610ad457505f8160200151145b610b0657610ae182611977565b610b05825f015160405180604001604052806001151581526020015f815250611a20565b5b5f80610b1184611d65565b91509150610b1f8282611f67565b825f01518015610b3257505f8360200151145b610b4d57610b3f846120d6565b610b4c845f015184611a20565b5b5050505050565b5f806002601a9054906101000a900465ffffffffffff169050610b76816113dc565b8015610b875750610b86816113f0565b5b610ba5576001601a9054906101000a900465ffffffffffff16610bbb565b600260149054906101000a900465ffffffffffff165b91505090565b5f610bca610c56565b5090508073ffffffffffffffffffffffffffffffffffffffff16610bec61215d565b73ffffffffffffffffffffffffffffffffffffffff1614610c4b57610c0f61215d565b6040517fc22c8022000000000000000000000000000000000000000000000000000000008152600401610c4291906135da565b60405180910390fd5b610c53612164565b50565b5f8060015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160149054906101000a900465ffffffffffff16915091509091565b5f801b8203610cd2576040517f3fc3c27a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610cdc828261222f565b5050565b5f801b610cec81610d70565b610cf4612251565b50565b5f7f7965db0b000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19161480610d695750610d688261225d565b5b9050919050565b610d8181610d7c61215d565b6122c6565b50565b610d8e5f80612317565b565b60605f6001811115610da557610da461388c565b5b826001811115610db857610db761388c565b5b03610f88575f839050600267ffffffffffffffff811115610ddc57610ddb6139eb565b5b604051908082528060200260200182016040528015610e0a5781602001602082028036833780820191505090505b5091508073ffffffffffffffffffffffffffffffffffffffff1663828a7c346040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e56573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e7a9190613a2c565b825f81518110610e8d57610e8c613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff166362ced0926040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f10573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f349190613a2c565b82600181518110610f4857610f47613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505061118e565b600180811115610f9b57610f9a61388c565b5b826001811115610fae57610fad61388c565b5b0361117e575f839050600267ffffffffffffffff811115610fd257610fd16139eb565b5b6040519080825280602002602001820160405280156110005781602001602082028036833780820191505090505b5091508073ffffffffffffffffffffffffffffffffffffffff1663828a7c346040518163ffffffff1660e01b8152600401602060405180830381865afa15801561104c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110709190613a2c565b825f8151811061108357611082613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508073ffffffffffffffffffffffffffffffffffffffff166362ced0926040518163ffffffff1660e01b8152600401602060405180830381865afa158015611106573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061112a9190613a2c565b8260018151811061113e5761113d613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505061118d565b5f61118c5761118b613a84565b5b5b5b92915050565b5f805f90505b82518160ff161015611210573073ffffffffffffffffffffffffffffffffffffffff16838260ff16815181106111d3576111d2613a57565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff16036111ff578091505061124c565b8061120990613ade565b905061119a565b506040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161124390613b76565b60405180910390fd5b919050565b5f73ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146112e0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112d790613bde565b60405180910390fd5b8260035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600360146101000a81548160ff021916908360018111156113455761134461388c565b5b021790555080600360156101000a81548160ff021916908360ff1602179055508273ffffffffffffffffffffffffffffffffffffffff167fccd74cd713b8e75de035e0197901d2475669bcc87f55e343e3cbfb77cf224b4783836040516113ad929190613bfc565b60405180910390a2505050565b6113c382610643565b6113cc81610d70565b6113d68383612406565b50505050565b5f808265ffffffffffff1614159050919050565b5f428265ffffffffffff16109050919050565b61140b61215d565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161461146f576040517f6697b23200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61147982826124cf565b505050565b5f611487610b54565b6114904261254f565b61149a9190613c23565b90506114a682826125a8565b8173ffffffffffffffffffffffffffffffffffffffff167f3377dc44241e779dd06afab5b788a35ca5f3b778836e2990bdb26a2a4b2e5ed6826040516114ec919061350e565b60405180910390a25050565b5f61150282612659565b61150b4261254f565b6115159190613c23565b90506115218282612317565b7ff1038c18cf84a56e432fdbfaf746924b7ea511dfe03a6506a0ceba4888788d9b8282604051611552929190613865565b60405180910390a15050565b611566613368565b5f8390505f8173ffffffffffffffffffffffffffffffffffffffff16638d928af86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115b4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115d89190613a2c565b90505f8273ffffffffffffffffffffffffffffffffffffffff166338fff2d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015611624573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116489190613c70565b905082845f019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505084846020019060018111156116995761169861388c565b5b908160018111156116ad576116ac61388c565b5b8152505081846040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050808460600181815250508173ffffffffffffffffffffffffffffffffffffffff1663f94d4668826040518263ffffffff1660e01b815260040161172c9190613660565b5f60405180830381865afa158015611746573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061176e9190613ee3565b50856080018660a001829052829052505050505092915050565b6117906133db565b5f7f000000000000000000000000ce276785e78796dcbb4fe07fd335c89a1f784ca473ffffffffffffffffffffffffffffffffffffffff166379502c556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117fa573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061181e9190613fa6565b90505f61184b847f50524f544f434f4c5f535741505f4645455f50455243000000000000000000006126b7565b90508173ffffffffffffffffffffffffffffffffffffffff1663696eb375826040518263ffffffff1660e01b81526004016118869190613660565b602060405180830381865afa1580156118a1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118c59190613ffb565b15611960576001835f0190151590811515815250508173ffffffffffffffffffffffffffffffffffffffff1663bd02d0f5826040518263ffffffff1660e01b81526004016119139190613660565b602060405180830381865afa15801561192e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119529190614026565b836020018181525050611970565b5f835f0190151590811515815250505b5050919050565b5f61198582608001516126e9565b90505f611a06828460a00151855f015173ffffffffffffffffffffffffffffffffffffffff1663876f303b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119dd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a019190614026565b612809565b9050611a118361291a565b611a1b8184612a2f565b505050565b5f600167ffffffffffffffff811115611a3c57611a3b6139eb565b5b604051908082528060200260200182016040528015611a7557816020015b611a626133f5565b815260200190600190039081611a5a5790505b5090507f000000000000000000000000ce276785e78796dcbb4fe07fd335c89a1f784ca4815f81518110611aac57611aab613a57565b5b60200260200101515f019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250505f815f81518110611afd57611afc613a57565b5b60200260200101516040018181525050815f015115611bfd577f000000000000000000000000ce276785e78796dcbb4fe07fd335c89a1f784ca4506360b2cf7160e01b837f50524f544f434f4c5f535741505f4645455f50455243000000000000000000008460200151604051602401611b7993929190614051565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050815f81518110611be957611be8613a57565b5b602002602001015160200181905250611cda565b7f000000000000000000000000ce276785e78796dcbb4fe07fd335c89a1f784ca45063ec1bf87560e01b837f50524f544f434f4c5f535741505f4645455f5045524300000000000000000000604051602401611c5a929190614086565b604051602081830303815290604052907bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050815f81518110611cca57611cc9613a57565b5b6020026020010151602001819052505b7f000000000000000000000000f47998c67d7ebbba8780b37c5d92cb282eb2690573ffffffffffffffffffffffffffffffffffffffff1663b4662f14826040518263ffffffff1660e01b8152600401611d33919061424d565b5f604051808303815f87803b158015611d4a575f80fd5b505af1158015611d5c573d5f803e3d5ffd5b50505050505050565b5f805f6001811115611d7a57611d7961388c565b5b83602001516001811115611d9157611d9061388c565b5b03611e1e575f835f015173ffffffffffffffffffffffffffffffffffffffff16637be219a26040518163ffffffff1660e01b81526004016101c060405180830381865afa158015611de4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e08919061442d565b509050805f015181602001519250925050611f62565b600180811115611e3157611e3061388c565b5b83602001516001811115611e4857611e4761388c565b5b03611f4d575f835f015173ffffffffffffffffffffffffffffffffffffffff1663707dcd1e6040518163ffffffff1660e01b81526004016040805180830381865afa158015611e99573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ebd919061451a565b9050611f00815f60028110611ed557611ed4613a57565b5b6020020151825f60028110611eed57611eec613a57565b5b6020020151612ba990919063ffffffff16565b611f4382600160028110611f1757611f16613a57565b5b602002015183600160028110611f3057611f2f613a57565b5b6020020151612ba990919063ffffffff16565b9250925050611f62565b5f611f5b57611f5a613a84565b5b5f80915091505b915091565b5f611f70612bd6565b90505f6001600360159054906101000a900460ff1660ff1614905080612032575f611fa48584612cad90919063ffffffff16565b90505f611fba8585612cad90919063ffffffff16565b9050816004541115611fd557611fd0825f612cda565b61202b565b806004541015611fef57611fea816001612cda565b61202a565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120219061458f565b60405180910390fd5b5b50506120d0565b5f6120468584612ba990919063ffffffff16565b90505f61205c8585612ba990919063ffffffff16565b905081600454101561207757612072825f612cda565b6120cd565b8060045411156120915761208c816001612cda565b6120cc565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016120c39061458f565b60405180910390fd5b5b50505b50505050565b61215a815f015173ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161211591906135da565b602060405180830381865afa158015612130573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121549190614026565b82612d2f565b50565b5f33905090565b5f8061216e610c56565b9150915061217b816113dc565b158061218d575061218b816113f0565b155b156121cf57806040517f19ca5ebb0000000000000000000000000000000000000000000000000000000081526004016121c6919061350e565b60405180910390fd5b6121e25f801b6121dd610875565b6124cf565b506121ef5f801b83612406565b5060015f6101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600160146101000a81549065ffffffffffff02191690555050565b61223882610643565b61224181610d70565b61224b83836124cf565b50505050565b61225b5f806125a8565b565b5f7f01ffc9a7000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916149050919050565b6122d082826108cf565b6123135780826040517fe2517d3f00000000000000000000000000000000000000000000000000000000815260040161230a929190614086565b60405180910390fd5b5050565b5f6002601a9054906101000a900465ffffffffffff169050612338816113dc565b156123b757612346816113f0565b1561238957600260149054906101000a900465ffffffffffff166001601a6101000a81548165ffffffffffff021916908365ffffffffffff1602179055506123b6565b7f2b1fa2edafe6f7b9e97c1a9e0c3660e645beb2dcaa2d45bdbf9beaf5472e1ec560405160405180910390a15b5b82600260146101000a81548165ffffffffffff021916908365ffffffffffff160217905550816002601a6101000a81548165ffffffffffff021916908365ffffffffffff160217905550505050565b5f805f1b83036124bd575f73ffffffffffffffffffffffffffffffffffffffff1661242f610875565b73ffffffffffffffffffffffffffffffffffffffff161461247c576040517f3fc3c27a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8160025f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b6124c78383612e89565b905092915050565b5f805f1b8314801561251357506124e4610875565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b1561253d5760025f6101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690555b6125478383612f72565b905092915050565b5f65ffffffffffff80168211156125a0576030826040517f6dfcc6500000000000000000000000000000000000000000000000000000000081526004016125979291906145e6565b60405180910390fd5b819050919050565b5f6125b1610c56565b9150508260015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600160146101000a81548165ffffffffffff021916908365ffffffffffff160217905550612622816113dc565b15612654577f8886ebfc4259abdbc16601dd8fb5678e54878f47b3c34836cfc51154a960510960405160405180910390a15b505050565b5f80612663610b54565b90508065ffffffffffff168365ffffffffffff161161268d578281612688919061460d565b6126af565b6126ae8365ffffffffffff166126a16105b5565b65ffffffffffff1661305b565b5b915050919050565b5f81836040516020016126cb929190614646565b60405160208183030381529060405280519060200120905092915050565b6060815167ffffffffffffffff811115612706576127056139eb565b5b6040519080825280602002602001820160405280156127345781602001602082028036833780820191505090505b5090505f5b8251811015612803575f83828151811061275657612755613a57565b5b602002602001015190508073ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161279991906135da565b602060405180830381865afa1580156127b4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127d89190614026565b8383815181106127eb576127ea613a57565b5b60200260200101818152505050806001019050612739565b50919050565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90505f5b84518110156128c1575f84828151811061284c5761284b613a57565b5b602002602001015111156128b6575f84828151811061286e5761286d613a57565b5b602002602001015186838151811061288957612888613a57565b5b60200260200101518561289c919061466d565b6128a691906146db565b9050828110156128b4578092505b505b80600101905061282f565b506002816128cf91906146db565b90505f8103612913576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161290a90614755565b60405180910390fd5b9392505050565b5f5b816080015151811015612a2b575f8260800151828151811061294157612940613a57565b5b602002602001015190505f8173ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e3086604001516040518363ffffffff1660e01b815260040161298b929190614773565b602060405180830381865afa1580156129a6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129ca9190614026565b03612a1f57612a1e83604001517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8373ffffffffffffffffffffffffffffffffffffffff166130719092919063ffffffff16565b5b5080600101905061291c565b5050565b5f81608001515167ffffffffffffffff811115612a4f57612a4e6139eb565b5b604051908082528060200260200182016040528015612a7d5781602001602082028036833780820191505090505b5090505f5b826080015151811015612ada577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff828281518110612ac357612ac2613a57565b5b602002602001018181525050806001019050612a82565b505f600384604051602001612af09291906147e0565b6040516020818303038152906040529050826040015173ffffffffffffffffffffffffffffffffffffffff1663b95cac28846060015130306040518060800160405280612b408a6080015161317e565b81526020018881526020018781526020015f15158152506040518563ffffffff1660e01b8152600401612b7694939291906149f4565b5f604051808303815f87803b158015612b8d575f80fd5b505af1158015612b9f573d5f803e3d5ffd5b5050505050505050565b5f808284612bb7919061466d565b9050670de0b6b3a764000081612bcd91906146db565b91505092915050565b5f7f00000000000000000000000079a88bb30beebc41f2b104a86f5dc96c70c4044773ffffffffffffffffffffffffffffffffffffffff1663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612c40573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612c649190614026565b90507f000000000000000000000000000000000000000000000000000000000000000015612caa57612ca781670de0b6b3a7640000612cad90919063ffffffff16565b90505b90565b5f80670de0b6b3a764000084612cc3919061466d565b90508281612cd191906146db565b91505092915050565b81600481905550806001811115612cf457612cf361388c565b5b7f40ce3c3e059a5994a81170ca3a882c3fb0dd4815695f91d7ccaca797ab97962983604051612d239190613793565b60405180910390a25050565b5f81608001515167ffffffffffffffff811115612d4f57612d4e6139eb565b5b604051908082528060200260200182016040528015612d7d5781602001602082028036833780820191505090505b5090505f5b826080015151811015612dba575f828281518110612da357612da2613a57565b5b602002602001018181525050806001019050612d82565b505f600184604051602001612dd0929190614a84565b6040516020818303038152906040529050826040015173ffffffffffffffffffffffffffffffffffffffff16638bdb3913846060015130306040518060800160405280612e208a6080015161317e565b81526020018881526020018781526020015f15158152506040518563ffffffff1660e01b8152600401612e569493929190614b39565b5f604051808303815f87803b158015612e6d575f80fd5b505af1158015612e7f573d5f803e3d5ffd5b5050505050505050565b5f612e9483836108cf565b612f685760015f808581526020019081526020015f205f015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff021916908315150217905550612f0561215d565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a460019050612f6c565b5f90505b92915050565b5f612f7d83836108cf565b15613051575f805f8581526020019081526020015f205f015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff021916908315150217905550612fee61215d565b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16847ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b60405160405180910390a460019050613055565b5f90505b92915050565b5f6130698284108484613250565b905092915050565b5f8373ffffffffffffffffffffffffffffffffffffffff1663095ea7b384846040516024016130a1929190614b83565b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090506130ef8482613269565b6131785761316d848573ffffffffffffffffffffffffffffffffffffffff1663095ea7b3865f604051602401613126929190614be3565b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506132c2565b61317784826132c2565b5b50505050565b6060815167ffffffffffffffff81111561319b5761319a6139eb565b5b6040519080825280602002602001820160405280156131c95781602001602082028036833780820191505090505b5090505f5b825181101561324a578281815181106131ea576131e9613a57565b5b602002602001015182828151811061320557613204613a57565b5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508060010190506131ce565b50919050565b5f61325a8461335d565b82841802821890509392505050565b5f805f8060205f8651602088015f8a5af192503d91505f5190508280156132b757505f821461329b57600181146132b6565b5f8673ffffffffffffffffffffffffffffffffffffffff163b115b5b935050505092915050565b5f8060205f8451602086015f885af1806132e1576040513d5f823e3d81fd5b3d92505f519150505f82146132fa576001811415613315565b5f8473ffffffffffffffffffffffffffffffffffffffff163b145b1561335757836040517f5274afe700000000000000000000000000000000000000000000000000000000815260040161334e91906135da565b60405180910390fd5b50505050565b5f8115159050919050565b6040518060c001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f60018111156133a2576133a161388c565b5b81526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f801916815260200160608152602001606081525090565b60405180604001604052805f151581526020015f81525090565b60405180606001604052805f73ffffffffffffffffffffffffffffffffffffffff168152602001606081526020015f81525090565b5f604051905090565b5f80fd5b5f80fd5b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61346f8161343b565b8114613479575f80fd5b50565b5f8135905061348a81613466565b92915050565b5f602082840312156134a5576134a4613433565b5b5f6134b28482850161347c565b91505092915050565b5f8115159050919050565b6134cf816134bb565b82525050565b5f6020820190506134e85f8301846134c6565b92915050565b5f65ffffffffffff82169050919050565b613508816134ee565b82525050565b5f6020820190506135215f8301846134ff565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f819050919050565b5f61356961356461355f84613527565b613546565b613527565b9050919050565b5f61357a8261354f565b9050919050565b5f61358b82613570565b9050919050565b61359b81613581565b82525050565b5f6020820190506135b45f830184613592565b92915050565b5f6135c482613527565b9050919050565b6135d4816135ba565b82525050565b5f6020820190506135ed5f8301846135cb565b92915050565b5f819050919050565b613605816135f3565b811461360f575f80fd5b50565b5f81359050613620816135fc565b92915050565b5f6020828403121561363b5761363a613433565b5b5f61364884828501613612565b91505092915050565b61365a816135f3565b82525050565b5f6020820190506136735f830184613651565b92915050565b613682816135ba565b811461368c575f80fd5b50565b5f8135905061369d81613679565b92915050565b600281106136af575f80fd5b50565b5f813590506136c0816136a3565b92915050565b5f80604083850312156136dc576136db613433565b5b5f6136e98582860161368f565b92505060206136fa858286016136b2565b9150509250929050565b5f806040838503121561371a57613719613433565b5b5f61372785828601613612565b92505060206137388582860161368f565b9150509250929050565b5f61374c82613570565b9050919050565b61375c81613742565b82525050565b5f6020820190506137755f830184613753565b92915050565b5f819050919050565b61378d8161377b565b82525050565b5f6020820190506137a65f830184613784565b92915050565b5f602082840312156137c1576137c0613433565b5b5f6137ce8482850161368f565b91505092915050565b6137e0816134ee565b81146137ea575f80fd5b50565b5f813590506137fb816137d7565b92915050565b5f6020828403121561381657613815613433565b5b5f613823848285016137ed565b91505092915050565b5f61383682613570565b9050919050565b6138468161382c565b82525050565b5f60208201905061385f5f83018461383d565b92915050565b5f6040820190506138785f8301856134ff565b61388560208301846134ff565b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b600281106138ca576138c961388c565b5b50565b5f8190506138da826138b9565b919050565b5f6138e9826138cd565b9050919050565b6138f9816138df565b82525050565b5f6020820190506139125f8301846138f0565b92915050565b5f60ff82169050919050565b61392d81613918565b82525050565b5f6020820190506139465f830184613924565b92915050565b5f60408201905061395f5f8301856135cb565b61396c60208301846134ff565b9392505050565b5f82825260208201905092915050565b7f506f6f6c206e6f742073657400000000000000000000000000000000000000005f82015250565b5f6139b7600c83613973565b91506139c282613983565b602082019050919050565b5f6020820190508181035f8301526139e4816139ab565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f81519050613a2681613679565b92915050565b5f60208284031215613a4157613a40613433565b5b5f613a4e84828501613a18565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f613ae882613918565b915060ff8203613afb57613afa613ab1565b5b600182019050919050565b7f5261746570726f7669646572206e6f7420636f6e6669677572656420696e20705f8201527f6f6f6c2e00000000000000000000000000000000000000000000000000000000602082015250565b5f613b60602483613973565b9150613b6b82613b06565b604082019050919050565b5f6020820190508181035f830152613b8d81613b54565b9050919050565b7f506f6f6c20616c726561647920736574000000000000000000000000000000005f82015250565b5f613bc8601083613973565b9150613bd382613b94565b602082019050919050565b5f6020820190508181035f830152613bf581613bbc565b9050919050565b5f604082019050613c0f5f8301856138f0565b613c1c6020830184613924565b9392505050565b5f613c2d826134ee565b9150613c38836134ee565b9250828201905065ffffffffffff811115613c5657613c55613ab1565b5b92915050565b5f81519050613c6a816135fc565b92915050565b5f60208284031215613c8557613c84613433565b5b5f613c9284828501613c5c565b91505092915050565b5f80fd5b5f601f19601f8301169050919050565b613cb882613c9f565b810181811067ffffffffffffffff82111715613cd757613cd66139eb565b5b80604052505050565b5f613ce961342a565b9050613cf58282613caf565b919050565b5f67ffffffffffffffff821115613d1457613d136139eb565b5b602082029050602081019050919050565b5f80fd5b5f613d33826135ba565b9050919050565b613d4381613d29565b8114613d4d575f80fd5b50565b5f81519050613d5e81613d3a565b92915050565b5f613d76613d7184613cfa565b613ce0565b90508083825260208201905060208402830185811115613d9957613d98613d25565b5b835b81811015613dc25780613dae8882613d50565b845260208401935050602081019050613d9b565b5050509392505050565b5f82601f830112613de057613ddf613c9b565b5b8151613df0848260208601613d64565b91505092915050565b5f67ffffffffffffffff821115613e1357613e126139eb565b5b602082029050602081019050919050565b613e2d8161377b565b8114613e37575f80fd5b50565b5f81519050613e4881613e24565b92915050565b5f613e60613e5b84613df9565b613ce0565b90508083825260208201905060208402830185811115613e8357613e82613d25565b5b835b81811015613eac5780613e988882613e3a565b845260208401935050602081019050613e85565b5050509392505050565b5f82601f830112613eca57613ec9613c9b565b5b8151613eda848260208601613e4e565b91505092915050565b5f805f60608486031215613efa57613ef9613433565b5b5f84015167ffffffffffffffff811115613f1757613f16613437565b5b613f2386828701613dcc565b935050602084015167ffffffffffffffff811115613f4457613f43613437565b5b613f5086828701613eb6565b9250506040613f6186828701613e3a565b9150509250925092565b5f613f75826135ba565b9050919050565b613f8581613f6b565b8114613f8f575f80fd5b50565b5f81519050613fa081613f7c565b92915050565b5f60208284031215613fbb57613fba613433565b5b5f613fc884828501613f92565b91505092915050565b613fda816134bb565b8114613fe4575f80fd5b50565b5f81519050613ff581613fd1565b92915050565b5f602082840312156140105761400f613433565b5b5f61401d84828501613fe7565b91505092915050565b5f6020828403121561403b5761403a613433565b5b5f61404884828501613e3a565b91505092915050565b5f6060820190506140645f8301866135cb565b6140716020830185613651565b61407e6040830184613784565b949350505050565b5f6040820190506140995f8301856135cb565b6140a66020830184613651565b9392505050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6140df816135ba565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561411c578082015181840152602081019050614101565b5f8484015250505050565b5f614131826140e5565b61413b81856140ef565b935061414b8185602086016140ff565b61415481613c9f565b840191505092915050565b6141688161377b565b82525050565b5f606083015f8301516141835f8601826140d6565b506020830151848203602086015261419b8282614127565b91505060408301516141b0604086018261415f565b508091505092915050565b5f6141c6838361416e565b905092915050565b5f602082019050919050565b5f6141e4826140ad565b6141ee81856140b7565b935083602082028501614200856140c7565b805f5b8581101561423b578484038952815161421c85826141bb565b9450614227836141ce565b925060208a01995050600181019050614203565b50829750879550505050505092915050565b5f6020820190508181035f83015261426581846141da565b905092915050565b5f80fd5b5f819050919050565b61428381614271565b811461428d575f80fd5b50565b5f8151905061429e8161427a565b92915050565b5f60a082840312156142b9576142b861426d565b5b6142c360a0613ce0565b90505f6142d284828501614290565b5f8301525060206142e584828501614290565b60208301525060406142f984828501614290565b604083015250606061430d84828501614290565b606083015250608061432184828501614290565b60808301525092915050565b5f604082840312156143425761434161426d565b5b61434c6040613ce0565b90505f61435b84828501614290565b5f83015250602061436e84828501614290565b60208301525092915050565b5f61012082840312156143905761438f61426d565b5b61439a60e0613ce0565b90505f6143a98482850161432d565b5f8301525060406143bc8482850161432d565b60208301525060806143d084828501614290565b60408301525060a06143e484828501614290565b60608301525060c06143f884828501614290565b60808301525060e061440c84828501614290565b60a08301525061010061442184828501614290565b60c08301525092915050565b5f806101c0838503121561444457614443613433565b5b5f614451858286016142a4565b92505060a06144628582860161437a565b9150509250929050565b5f67ffffffffffffffff821115614486576144856139eb565b5b602082029050919050565b5f6144a361449e8461446c565b613ce0565b905080602084028301858111156144bd576144bc613d25565b5b835b818110156144e657806144d28882613e3a565b8452602084019350506020810190506144bf565b5050509392505050565b5f82601f83011261450457614503613c9b565b5b6002614511848285614491565b91505092915050565b5f6040828403121561452f5761452e613433565b5b5f61453c848285016144f0565b91505092915050565b7f506f6f6c206e6f74206f7574206f662072616e676500000000000000000000005f82015250565b5f614579601583613973565b915061458482614545565b602082019050919050565b5f6020820190508181035f8301526145a68161456d565b9050919050565b5f819050919050565b5f6145d06145cb6145c6846145ad565b613546565b613918565b9050919050565b6145e0816145b6565b82525050565b5f6040820190506145f95f8301856145d7565b6146066020830184613784565b9392505050565b5f614617826134ee565b9150614622836134ee565b9250828203905065ffffffffffff8111156146405761463f613ab1565b5b92915050565b5f6040820190506146595f830185613651565b61466660208301846135cb565b9392505050565b5f6146778261377b565b91506146828361377b565b92508282026146908161377b565b915082820484148315176146a7576146a6613ab1565b5b5092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f6146e58261377b565b91506146f08361377b565b925082614700576146ff6146ae565b5b828204905092915050565b7f4e6f7420656e6f756768206173736574732e00000000000000000000000000005f82015250565b5f61473f601283613973565b915061474a8261470b565b602082019050919050565b5f6020820190508181035f83015261476c81614733565b9050919050565b5f6040820190506147865f8301856135cb565b61479360208301846135cb565b9392505050565b600481106147ab576147aa61388c565b5b50565b5f8190506147bb8261479a565b919050565b5f6147ca826147ae565b9050919050565b6147da816147c0565b82525050565b5f6040820190506147f35f8301856147d1565b6148006020830184613784565b9392505050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f61483a82613570565b9050919050565b61484a81614830565b82525050565b5f61485b8383614841565b60208301905092915050565b5f602082019050919050565b5f61487d82614807565b6148878185614811565b935061489283614821565b805f5b838110156148c25781516148a98882614850565b97506148b483614867565b925050600181019050614895565b5085935050505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b5f614903838361415f565b60208301905092915050565b5f602082019050919050565b5f614925826148cf565b61492f81856148d9565b935061493a836148e9565b805f5b8381101561496a57815161495188826148f8565b975061495c8361490f565b92505060018101905061493d565b5085935050505092915050565b614980816134bb565b82525050565b5f608083015f8301518482035f8601526149a08282614873565b915050602083015184820360208601526149ba828261491b565b915050604083015184820360408601526149d48282614127565b91505060608301516149e96060860182614977565b508091505092915050565b5f608082019050614a075f830187613651565b614a1460208301866135cb565b614a2160408301856135cb565b8181036060830152614a338184614986565b905095945050505050565b60038110614a4f57614a4e61388c565b5b50565b5f819050614a5f82614a3e565b919050565b5f614a6e82614a52565b9050919050565b614a7e81614a64565b82525050565b5f604082019050614a975f830185614a75565b614aa46020830184613784565b9392505050565b5f614ab582613527565b9050919050565b614ac581614aab565b82525050565b5f608083015f8301518482035f860152614ae58282614873565b91505060208301518482036020860152614aff828261491b565b91505060408301518482036040860152614b198282614127565b9150506060830151614b2e6060860182614977565b508091505092915050565b5f608082019050614b4c5f830187613651565b614b5960208301866135cb565b614b666040830185614abc565b8181036060830152614b788184614acb565b905095945050505050565b5f604082019050614b965f8301856135cb565b614ba36020830184613784565b9392505050565b5f819050919050565b5f614bcd614bc8614bc384614baa565b613546565b61377b565b9050919050565b614bdd81614bb3565b82525050565b5f604082019050614bf65f8301856135cb565b614c036020830184614bd4565b939250505056fea2646970667358221220be69c9cf6547f702202424a83b059f19972ecbbfccfa8f54f52557546f6850ae64736f6c63430008180033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.29
Net Worth in S
Token Allocations
WETH
100.00%
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|---|---|---|---|---|
| SONIC | 100.00% | $2,896.3 | 0.0001 | $0.2896 |
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.