Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00Latest 25 from a total of 1,100 transactions
| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Refund Native To... | 24456973 | 26 days ago | IN | 0 ETH | 0.00000102 | ||||
| Swap | 23276297 | 191 days ago | IN | 0 ETH | 0.00009432 | ||||
| Multi Multihop S... | 23136345 | 211 days ago | IN | 0 ETH | 0.00025261 | ||||
| Multi Multihop S... | 23135866 | 211 days ago | IN | 0 ETH | 0.00031407 | ||||
| Multi Multihop S... | 23135838 | 211 days ago | IN | 0 ETH | 0.00048976 | ||||
| Multi Multihop S... | 23124489 | 212 days ago | IN | 0 ETH | 0.00043453 | ||||
| Multi Multihop S... | 23119742 | 213 days ago | IN | 0 ETH | 0.00023466 | ||||
| Multi Multihop S... | 23119737 | 213 days ago | IN | 0 ETH | 0.00026464 | ||||
| Multi Multihop S... | 23119732 | 213 days ago | IN | 0 ETH | 0.00024766 | ||||
| Multi Multihop S... | 23119624 | 213 days ago | IN | 0 ETH | 0.00024113 | ||||
| Multi Multihop S... | 23118598 | 213 days ago | IN | 0 ETH | 0.00051706 | ||||
| Multi Multihop S... | 23118531 | 213 days ago | IN | 0 ETH | 0.00055972 | ||||
| Multi Multihop S... | 23109022 | 215 days ago | IN | 0 ETH | 0.00106182 | ||||
| Multi Multihop S... | 23109013 | 215 days ago | IN | 0 ETH | 0.00012725 | ||||
| Multi Multihop S... | 23108943 | 215 days ago | IN | 0 ETH | 0.00106997 | ||||
| Multi Multihop S... | 23107224 | 215 days ago | IN | 0 ETH | 0.00113872 | ||||
| Multi Multihop S... | 23107202 | 215 days ago | IN | 0 ETH | 0.00067421 | ||||
| Multi Multihop S... | 23107193 | 215 days ago | IN | 0 ETH | 0.00090793 | ||||
| Swap | 23096884 | 216 days ago | IN | 0 ETH | 0.00046107 | ||||
| Swap | 23094905 | 217 days ago | IN | 0 ETH | 0.00002816 | ||||
| Swap | 23089846 | 217 days ago | IN | 0 ETH | 0.00012629 | ||||
| Multi Multihop S... | 23083778 | 218 days ago | IN | 0 ETH | 0.00086233 | ||||
| Multi Multihop S... | 23081816 | 218 days ago | IN | 0 ETH | 0.0007789 | ||||
| Multi Multihop S... | 23079890 | 219 days ago | IN | 0 ETH | 0.00096852 | ||||
| Multi Multihop S... | 23069630 | 220 days ago | IN | 0 ETH | 0.00074409 |
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| Transfer | 24644940 | 7 hrs ago | 0.00016061 ETH | ||||
| Transfer | 24644940 | 7 hrs ago | 0.05306035 ETH | ||||
| Swap | 24644940 | 7 hrs ago | 0.05322096 ETH | ||||
| Transfer | 24590951 | 7 days ago | 0.00001761 ETH | ||||
| Transfer | 24590951 | 7 days ago | 0.01865932 ETH | ||||
| Swap | 24590951 | 7 days ago | 0.01867694 ETH | ||||
| 0x00000000 | 24590674 | 7 days ago | 0.0698613 ETH | ||||
| Swap | 24590674 | 7 days ago | 0.0698613 ETH | ||||
| Transfer | 24590360 | 7 days ago | 0.00003063 ETH | ||||
| Transfer | 24590360 | 7 days ago | 0.02152602 ETH | ||||
| Swap | 24590360 | 7 days ago | 0.02155665 ETH | ||||
| Transfer | 24587802 | 8 days ago | 0.00367757 ETH | ||||
| Multihop Swap | 24587802 | 8 days ago | 0.00367757 ETH | ||||
| Transfer | 24585717 | 8 days ago | 0.01685298 ETH | ||||
| Multihop Swap | 24585717 | 8 days ago | 0.01685298 ETH | ||||
| 0x00000000 | 24585473 | 8 days ago | 0.04493632 ETH | ||||
| Swap | 24585473 | 8 days ago | 0.04493632 ETH | ||||
| 0x00000000 | 24582993 | 8 days ago | 0.0024433 ETH | ||||
| Swap | 24582993 | 8 days ago | 0.0024433 ETH | ||||
| 0x00000000 | 24571084 | 10 days ago | 0.0007219 ETH | ||||
| Swap | 24571084 | 10 days ago | 0.0007219 ETH | ||||
| Transfer | 24566703 | 11 days ago | 0.000019 ETH | ||||
| Transfer | 24566703 | 11 days ago | 0.00256599 ETH | ||||
| Swap | 24566703 | 11 days ago | 0.00258499 ETH | ||||
| 0x00000000 | 24563904 | 11 days ago | 0.00263311 ETH |
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
MEVResistRouter
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 9999999 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {Router} from "./Router.sol";
import {ICore, PoolKey, SqrtRatio} from "./interfaces/ICore.sol";
import {CoreLib} from "./libraries/CoreLib.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
/// @title Ekubo MEV Resist Router
/// @author Moody Salem <[email protected]>
/// @notice Enables swapping and quoting against pools in Ekubo Protocol including the MEV resist extension pools
contract MEVResistRouter is Router {
using CoreLib for *;
address public immutable mevResist;
constructor(ICore core, address _mevResist) Router(core) {
mevResist = _mevResist;
}
function _swap(
uint256 value,
PoolKey memory poolKey,
int128 amount,
bool isToken1,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead
) internal override returns (int128 delta0, int128 delta1) {
if (poolKey.extension() != address(mevResist)) {
(delta0, delta1) = core.swap(value, poolKey, amount, isToken1, sqrtRatioLimit, skipAhead);
} else {
(delta0, delta1) = abi.decode(
forward(address(mevResist), abi.encode(poolKey, amount, isToken1, sqrtRatioLimit, skipAhead)),
(int128, int128)
);
if (value != 0) {
SafeTransferLib.safeTransferETH(address(core), value);
}
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {PayableMulticallable} from "./base/PayableMulticallable.sol";
import {BaseLocker} from "./base/BaseLocker.sol";
import {UsesCore} from "./base/UsesCore.sol";
import {IForwardee} from "./interfaces/IFlashAccountant.sol";
import {ICore} from "./interfaces/ICore.sol";
import {PoolKey} from "./types/poolKey.sol";
import {NATIVE_TOKEN_ADDRESS} from "./math/constants.sol";
import {isPriceIncreasing} from "./math/isPriceIncreasing.sol";
import {Permittable} from "./base/Permittable.sol";
import {SlippageChecker} from "./base/SlippageChecker.sol";
import {SqrtRatio, toSqrtRatio, MIN_SQRT_RATIO_RAW, MAX_SQRT_RATIO_RAW} from "./types/sqrtRatio.sol";
import {MIN_SQRT_RATIO, MAX_SQRT_RATIO} from "./types/sqrtRatio.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {CoreLib} from "./libraries/CoreLib.sol";
struct RouteNode {
PoolKey poolKey;
SqrtRatio sqrtRatioLimit;
uint256 skipAhead;
}
struct TokenAmount {
address token;
int128 amount;
}
struct Swap {
RouteNode[] route;
TokenAmount tokenAmount;
}
struct Delta {
int128 amount0;
int128 amount1;
}
/// Replaces a zero value of sqrtRatioLimit with the minimum or maximum depending on the swap direction without any jumps
function defaultSqrtRatioLimit(SqrtRatio sqrtRatioLimit, bool isToken1, int128 amount)
pure
returns (SqrtRatio result)
{
assembly ("memory-safe") {
let increasing := xor(isToken1, slt(amount, 0))
let defaultValue := add(mul(increasing, MAX_SQRT_RATIO_RAW), mul(iszero(increasing), MIN_SQRT_RATIO_RAW))
result := add(sqrtRatioLimit, mul(iszero(sqrtRatioLimit), defaultValue))
}
}
/// @title Ekubo Router
/// @author Moody Salem <[email protected]>
/// @notice Enables swapping and quoting against pools in Ekubo Protocol
contract Router is UsesCore, PayableMulticallable, SlippageChecker, Permittable, BaseLocker {
using CoreLib for *;
error PartialSwapsDisallowed();
error SlippageCheckFailed(int256 expectedAmount, int256 calculatedAmount);
error TokensMismatch(uint256 index);
constructor(ICore core) BaseLocker(core) UsesCore(core) {}
function _swap(
uint256 value,
PoolKey memory poolKey,
int128 amount,
bool isToken1,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead
) internal virtual returns (int128 delta0, int128 delta1) {
(delta0, delta1) = core.swap(value, poolKey, amount, isToken1, sqrtRatioLimit, skipAhead);
}
function handleLockData(uint256, bytes memory data) internal override returns (bytes memory result) {
bytes1 callType = data[0];
if (callType == bytes1(0x00)) {
// swap
(
,
address swapper,
PoolKey memory poolKey,
bool isToken1,
int128 amount,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead,
int256 calculatedAmountThreshold,
address recipient
) = abi.decode(data, (bytes1, address, PoolKey, bool, int128, SqrtRatio, uint256, int256, address));
unchecked {
uint256 value = FixedPointMathLib.ternary(
!isToken1 && poolKey.token0 == NATIVE_TOKEN_ADDRESS && amount > 0, uint128(amount), 0
);
bool increasing = isPriceIncreasing(amount, isToken1);
sqrtRatioLimit = defaultSqrtRatioLimit(sqrtRatioLimit, isToken1, amount);
(int128 delta0, int128 delta1) = _swap(value, poolKey, amount, isToken1, sqrtRatioLimit, skipAhead);
int128 amountCalculated = isToken1 ? -delta0 : -delta1;
if (amountCalculated < calculatedAmountThreshold) {
revert SlippageCheckFailed(calculatedAmountThreshold, amountCalculated);
}
if (increasing) {
withdraw(poolKey.token0, uint128(-delta0), recipient);
pay(swapper, poolKey.token1, uint128(delta1));
} else {
withdraw(poolKey.token1, uint128(-delta1), recipient);
if (uint128(delta0) <= value) {
withdraw(poolKey.token0, uint128(value) - uint128(delta0), swapper);
} else {
pay(swapper, poolKey.token0, uint128(delta0));
}
}
result = abi.encode(delta0, delta1);
}
} else if (callType == bytes1(0x01) || callType == bytes1(0x02)) {
address swapper;
Swap[] memory swaps;
int256 calculatedAmountThreshold;
if (callType == bytes1(0x01)) {
Swap memory s;
// multihopSwap
(, swapper, s, calculatedAmountThreshold) = abi.decode(data, (bytes1, address, Swap, int256));
swaps = new Swap[](1);
swaps[0] = s;
} else {
// multiMultihopSwap
(, swapper, swaps, calculatedAmountThreshold) = abi.decode(data, (bytes1, address, Swap[], int256));
}
Delta[][] memory results = new Delta[][](swaps.length);
unchecked {
int256 totalCalculated;
int256 totalSpecified;
address specifiedToken;
address calculatedToken;
for (uint256 i = 0; i < swaps.length; i++) {
Swap memory s = swaps[i];
results[i] = new Delta[](s.route.length);
TokenAmount memory tokenAmount = s.tokenAmount;
totalSpecified += tokenAmount.amount;
for (uint256 j = 0; j < s.route.length; j++) {
RouteNode memory node = s.route[j];
bool isToken1 = tokenAmount.token == node.poolKey.token1;
require(isToken1 || tokenAmount.token == node.poolKey.token0);
SqrtRatio sqrtRatioLimit =
defaultSqrtRatioLimit(node.sqrtRatioLimit, isToken1, tokenAmount.amount);
(int128 delta0, int128 delta1) =
_swap(0, node.poolKey, tokenAmount.amount, isToken1, sqrtRatioLimit, node.skipAhead);
results[i][j] = Delta(delta0, delta1);
if (isToken1) {
if (delta1 != tokenAmount.amount) revert PartialSwapsDisallowed();
tokenAmount = TokenAmount({token: node.poolKey.token0, amount: -delta0});
} else {
if (delta0 != tokenAmount.amount) revert PartialSwapsDisallowed();
tokenAmount = TokenAmount({token: node.poolKey.token1, amount: -delta1});
}
}
totalCalculated += tokenAmount.amount;
if (i == 0) {
specifiedToken = s.tokenAmount.token;
calculatedToken = tokenAmount.token;
} else {
if (specifiedToken != s.tokenAmount.token || calculatedToken != tokenAmount.token) {
revert TokensMismatch(i);
}
}
}
if (totalCalculated < calculatedAmountThreshold) {
revert SlippageCheckFailed(calculatedAmountThreshold, totalCalculated);
}
if (totalSpecified < 0) {
withdraw(specifiedToken, uint128(uint256(-totalSpecified)), swapper);
} else {
pay(swapper, specifiedToken, uint128(uint256(totalSpecified)));
}
if (totalCalculated > 0) {
withdraw(calculatedToken, uint128(uint256(totalCalculated)), swapper);
} else {
pay(swapper, calculatedToken, uint128(uint256(-totalCalculated)));
}
}
if (callType == bytes1(0x01)) {
result = abi.encode(results[0]);
} else {
result = abi.encode(results);
}
} else if (callType == bytes1(0x03)) {
(, PoolKey memory poolKey, bool isToken1, int128 amount, SqrtRatio sqrtRatioLimit, uint256 skipAhead) =
abi.decode(data, (bytes1, PoolKey, bool, int128, SqrtRatio, uint256));
(int128 delta0, int128 delta1) = _swap(0, poolKey, amount, isToken1, sqrtRatioLimit, skipAhead);
revert QuoteReturnValue(delta0, delta1);
}
}
function swap(
PoolKey memory poolKey,
bool isToken1,
int128 amount,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead,
int256 calculatedAmountThreshold,
address recipient
) public payable returns (int128 delta0, int128 delta1) {
(delta0, delta1) = abi.decode(
lock(
abi.encode(
bytes1(0x00),
msg.sender,
poolKey,
isToken1,
amount,
sqrtRatioLimit,
skipAhead,
calculatedAmountThreshold,
recipient
)
),
(int128, int128)
);
}
function swap(
PoolKey memory poolKey,
bool isToken1,
int128 amount,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead,
int256 calculatedAmountThreshold
) external payable returns (int128 delta0, int128 delta1) {
(delta0, delta1) =
swap(poolKey, isToken1, amount, sqrtRatioLimit, skipAhead, calculatedAmountThreshold, msg.sender);
}
function swap(PoolKey memory poolKey, bool isToken1, int128 amount, SqrtRatio sqrtRatioLimit, uint256 skipAhead)
external
payable
returns (int128 delta0, int128 delta1)
{
(delta0, delta1) = swap(poolKey, isToken1, amount, sqrtRatioLimit, skipAhead, type(int256).min, msg.sender);
}
function swap(RouteNode memory node, TokenAmount memory tokenAmount, int256 calculatedAmountThreshold)
public
payable
returns (int128 delta0, int128 delta1)
{
(delta0, delta1) = swap(
node.poolKey,
node.poolKey.token1 == tokenAmount.token,
tokenAmount.amount,
node.sqrtRatioLimit,
node.skipAhead,
calculatedAmountThreshold,
msg.sender
);
}
function multihopSwap(Swap memory s, int256 calculatedAmountThreshold)
external
payable
returns (Delta[] memory result)
{
result = abi.decode(lock(abi.encode(bytes1(0x01), msg.sender, s, calculatedAmountThreshold)), (Delta[]));
}
function multiMultihopSwap(Swap[] memory swaps, int256 calculatedAmountThreshold)
external
payable
returns (Delta[][] memory results)
{
results = abi.decode(lock(abi.encode(bytes1(0x02), msg.sender, swaps, calculatedAmountThreshold)), (Delta[][]));
}
error QuoteReturnValue(int128 delta0, int128 delta1);
function quote(PoolKey memory poolKey, bool isToken1, int128 amount, SqrtRatio sqrtRatioLimit, uint256 skipAhead)
external
returns (int128 delta0, int128 delta1)
{
sqrtRatioLimit = defaultSqrtRatioLimit(sqrtRatioLimit, isToken1, amount);
bytes memory revertData =
lockAndExpectRevert(abi.encode(bytes1(0x03), poolKey, isToken1, amount, sqrtRatioLimit, skipAhead));
// check that the sig matches the error data
bytes4 sig;
assembly ("memory-safe") {
sig := mload(add(revertData, 32))
}
if (sig == QuoteReturnValue.selector && revertData.length == 68) {
assembly ("memory-safe") {
delta0 := mload(add(revertData, 36))
delta1 := mload(add(revertData, 68))
}
} else {
assembly ("memory-safe") {
revert(add(revertData, 32), mload(revertData))
}
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {CallPoints} from "../types/callPoints.sol";
import {PoolKey} from "../types/poolKey.sol";
import {PositionKey, Bounds} from "../types/positionKey.sol";
import {FeesPerLiquidity} from "../types/feesPerLiquidity.sol";
import {IExposedStorage} from "../interfaces/IExposedStorage.sol";
import {IFlashAccountant} from "../interfaces/IFlashAccountant.sol";
import {SqrtRatio} from "../types/sqrtRatio.sol";
struct UpdatePositionParameters {
bytes32 salt;
Bounds bounds;
int128 liquidityDelta;
}
interface IExtension {
function beforeInitializePool(address caller, PoolKey calldata key, int32 tick) external;
function afterInitializePool(address caller, PoolKey calldata key, int32 tick, SqrtRatio sqrtRatio) external;
function beforeUpdatePosition(address locker, PoolKey memory poolKey, UpdatePositionParameters memory params)
external;
function afterUpdatePosition(
address locker,
PoolKey memory poolKey,
UpdatePositionParameters memory params,
int128 delta0,
int128 delta1
) external;
function beforeSwap(
address locker,
PoolKey memory poolKey,
int128 amount,
bool isToken1,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead
) external;
function afterSwap(
address locker,
PoolKey memory poolKey,
int128 amount,
bool isToken1,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead,
int128 delta0,
int128 delta1
) external;
function beforeCollectFees(address locker, PoolKey memory poolKey, bytes32 salt, Bounds memory bounds) external;
function afterCollectFees(
address locker,
PoolKey memory poolKey,
bytes32 salt,
Bounds memory bounds,
uint128 amount0,
uint128 amount1
) external;
}
interface ICore is IFlashAccountant, IExposedStorage {
event ProtocolFeesWithdrawn(address recipient, address token, uint256 amount);
event ExtensionRegistered(address extension);
event PoolInitialized(bytes32 poolId, PoolKey poolKey, int32 tick, SqrtRatio sqrtRatio);
event PositionFeesCollected(bytes32 poolId, PositionKey positionKey, uint128 amount0, uint128 amount1);
event FeesAccumulated(bytes32 poolId, uint128 amount0, uint128 amount1);
event PositionUpdated(
address locker, bytes32 poolId, UpdatePositionParameters params, int128 delta0, int128 delta1
);
// This error is thrown by swaps and deposits when this particular deployment of the contract is expired.
error FailedRegisterInvalidCallPoints();
error ExtensionAlreadyRegistered();
error InsufficientSavedBalance();
error PoolAlreadyInitialized();
error ExtensionNotRegistered();
error PoolNotInitialized();
error MustCollectFeesBeforeWithdrawingAllLiquidity();
error SqrtRatioLimitOutOfRange();
error InvalidSqrtRatioLimit();
error SavedBalanceTokensNotSorted();
// Allows the owner of the contract to withdraw the protocol withdrawal fees collected
// To withdraw the native token protocol fees, call with token = NATIVE_TOKEN_ADDRESS
function withdrawProtocolFees(address recipient, address token, uint256 amount) external;
// Extensions must call this function to become registered. The call points are validated against the caller address
function registerExtension(CallPoints memory expectedCallPoints) external;
// Sets the initial price for a new pool in terms of tick.
function initializePool(PoolKey memory poolKey, int32 tick) external returns (SqrtRatio sqrtRatio);
function prevInitializedTick(bytes32 poolId, int32 fromTick, uint32 tickSpacing, uint256 skipAhead)
external
view
returns (int32 tick, bool isInitialized);
function nextInitializedTick(bytes32 poolId, int32 fromTick, uint32 tickSpacing, uint256 skipAhead)
external
view
returns (int32 tick, bool isInitialized);
// Loads 2 tokens from the saved balances of the caller as payment in the current context.
function load(address token0, address token1, bytes32 salt, uint128 amount0, uint128 amount1) external;
// Saves an amount of 2 tokens to be used later, in a single slot.
function save(address owner, address token0, address token1, bytes32 salt, uint128 amount0, uint128 amount1)
external
payable;
// Returns the pool fees per liquidity inside the given bounds.
function getPoolFeesPerLiquidityInside(PoolKey memory poolKey, Bounds memory bounds)
external
view
returns (FeesPerLiquidity memory);
// Accumulates tokens to fees of a pool. Only callable by the extension of the specified pool
// key, i.e. the current locker _must_ be the extension.
// The extension must call this function within a lock callback.
function accumulateAsFees(PoolKey memory poolKey, uint128 amount0, uint128 amount1) external payable;
function updatePosition(PoolKey memory poolKey, UpdatePositionParameters memory params)
external
payable
returns (int128 delta0, int128 delta1);
function collectFees(PoolKey memory poolKey, bytes32 salt, Bounds memory bounds)
external
returns (uint128 amount0, uint128 amount1);
function swap_611415377(
PoolKey memory poolKey,
int128 amount,
bool isToken1,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead
) external payable returns (int128 delta0, int128 delta1);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {ICore} from "../interfaces/ICore.sol";
import {ExposedStorageLib} from "./ExposedStorageLib.sol";
import {FeesPerLiquidity} from "../types/feesPerLiquidity.sol";
import {Position} from "../types/position.sol";
import {SqrtRatio} from "../types/sqrtRatio.sol";
import {PoolKey} from "../types/poolKey.sol";
import {EfficientHashLib} from "solady/utils/EfficientHashLib.sol";
// Common storage getters we need for external contracts are defined here instead of in the core contract
library CoreLib {
using ExposedStorageLib for *;
function isExtensionRegistered(ICore core, address extension) internal view returns (bool registered) {
bytes32 key;
assembly ("memory-safe") {
mstore(0, extension)
mstore(32, 0)
key := keccak256(0, 64)
}
registered = uint256(core.sload(key)) != 0;
}
function protocolFeesCollected(ICore core, address token) internal view returns (uint256 amountCollected) {
bytes32 key;
assembly ("memory-safe") {
mstore(0, token)
mstore(32, 1)
key := keccak256(0, 64)
}
amountCollected = uint256(core.sload(key));
}
function poolState(ICore core, bytes32 poolId)
internal
view
returns (SqrtRatio sqrtRatio, int32 tick, uint128 liquidity)
{
bytes32 key;
assembly ("memory-safe") {
mstore(0, poolId)
mstore(32, 2)
key := keccak256(0, 64)
}
bytes32 p = core.sload(key);
assembly ("memory-safe") {
sqrtRatio := and(p, 0xffffffffffffffffffffffff)
tick := and(shr(96, p), 0xffffffff)
liquidity := shr(128, p)
}
}
function poolPositions(ICore core, bytes32 poolId, bytes32 positionId)
internal
view
returns (Position memory position)
{
bytes32 key;
assembly ("memory-safe") {
mstore(0, poolId)
mstore(32, 4)
let b := keccak256(0, 64)
mstore(0, positionId)
mstore(32, b)
key := keccak256(0, 64)
}
(bytes32 v0, bytes32 v1, bytes32 v2) = core.sload(key, bytes32(uint256(key) + 1), bytes32(uint256(key) + 2));
position.liquidity = uint128(uint256(v0));
position.feesPerLiquidityInsideLast = FeesPerLiquidity(uint256(v1), uint256(v2));
}
function savedBalances(ICore core, address owner, address token, bytes32 salt)
internal
view
returns (uint128 savedBalance)
{
bytes32 key = EfficientHashLib.hash(
bytes32(uint256(uint160(owner))),
bytes32(uint256(uint160(token))),
bytes32(uint256(type(uint160).max)),
salt
);
assembly ("memory-safe") {
mstore(0, key)
mstore(32, 8)
key := keccak256(0, 64)
}
savedBalance = uint128(uint256(core.sload(key)) >> 128);
}
function savedBalances(ICore core, address owner, address token0, address token1, bytes32 salt)
internal
view
returns (uint128 savedBalance0, uint128 savedBalance1)
{
bytes32 key = EfficientHashLib.hash(
bytes32(uint256(uint160(owner))), bytes32(uint256(uint160(token0))), bytes32(uint256(uint160(token1))), salt
);
assembly ("memory-safe") {
mstore(0, key)
mstore(32, 8)
key := keccak256(0, 64)
}
uint256 value = uint256(core.sload(key));
savedBalance0 = uint128(value >> 128);
savedBalance1 = uint128(value);
}
function poolTicks(ICore core, bytes32 poolId, int32 tick)
internal
view
returns (int128 liquidityDelta, uint128 liquidityNet)
{
bytes32 key;
assembly ("memory-safe") {
mstore(0, poolId)
mstore(32, 5)
let b := keccak256(0, 64)
mstore(0, tick)
mstore(32, b)
key := keccak256(0, 64)
}
bytes32 data = core.sload(key);
// takes only least significant 128 bits
liquidityDelta = int128(uint128(uint256(data)));
// takes only most significant 128 bits
liquidityNet = uint128(bytes16(data));
}
function swap(
ICore core,
uint256 value,
PoolKey memory poolKey,
int128 amount,
bool isToken1,
SqrtRatio sqrtRatioLimit,
uint256 skipAhead
) internal returns (int128 delta0, int128 delta1) {
(delta0, delta1) = core.swap_611415377{value: value}(poolKey, amount, isToken1, sqrtRatioLimit, skipAhead);
}
function save(ICore core, address owner, address token, bytes32 salt, uint128 amount) internal {
core.save(owner, token, address(type(uint160).max), salt, amount, 0);
}
function load(ICore core, address token, bytes32 salt, uint128 amount) internal {
core.load(token, address(type(uint160).max), salt, amount, 0);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)
///
/// @dev Note:
/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
library SafeTransferLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ETH transfer has failed.
error ETHTransferFailed();
/// @dev The ERC20 `transferFrom` has failed.
error TransferFromFailed();
/// @dev The ERC20 `transfer` has failed.
error TransferFailed();
/// @dev The ERC20 `approve` has failed.
error ApproveFailed();
/// @dev The ERC20 `totalSupply` query has failed.
error TotalSupplyQueryFailed();
/// @dev The Permit2 operation has failed.
error Permit2Failed();
/// @dev The Permit2 amount must be less than `2**160 - 1`.
error Permit2AmountOverflow();
/// @dev The Permit2 approve operation has failed.
error Permit2ApproveFailed();
/// @dev The Permit2 lockdown operation has failed.
error Permit2LockdownFailed();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;
/// @dev Suggested gas stipend for contract receiving ETH to perform a few
/// storage reads and writes, but low enough to prevent griefing.
uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;
/// @dev The unique EIP-712 domain domain separator for the DAI token contract.
bytes32 internal constant DAI_DOMAIN_SEPARATOR =
0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;
/// @dev The address for the WETH9 contract on Ethereum mainnet.
address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
/// @dev The canonical Permit2 address.
/// [Github](https://github.com/Uniswap/permit2)
/// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ETH OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
//
// The regular variants:
// - Forwards all remaining gas to the target.
// - Reverts if the target reverts.
// - Reverts if the current contract has insufficient balance.
//
// The force variants:
// - Forwards with an optional gas stipend
// (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
// - If the target reverts, or if the gas stipend is exhausted,
// creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
// Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
// - Reverts if the current contract has insufficient balance.
//
// The try variants:
// - Forwards with a mandatory gas stipend.
// - Instead of reverting, returns whether the transfer succeeded.
/// @dev Sends `amount` (in wei) ETH to `to`.
function safeTransferETH(address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Sends all the ETH in the current contract to `to`.
function safeTransferAllETH(address to) internal {
/// @solidity memory-safe-assembly
assembly {
// Transfer all the ETH and check if it succeeded or not.
if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
/// @solidity memory-safe-assembly
assembly {
if lt(selfbalance(), amount) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
/// @solidity memory-safe-assembly
assembly {
if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
function forceSafeTransferETH(address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
if lt(selfbalance(), amount) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
function forceSafeTransferAllETH(address to) internal {
/// @solidity memory-safe-assembly
assembly {
// forgefmt: disable-next-item
if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
}
}
/// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
function trySafeTransferAllETH(address to, uint256 gasStipend)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
/// Reverts upon failure.
///
/// The `from` account must have at least `amount` approved for
/// the current contract to manage.
function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x60, amount) // Store the `amount` argument.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
///
/// The `from` account must have at least `amount` approved for the current contract to manage.
function trySafeTransferFrom(address token, address from, address to, uint256 amount)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x60, amount) // Store the `amount` argument.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
success := lt(or(iszero(extcodesize(token)), returndatasize()), success)
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends all of ERC20 `token` from `from` to `to`.
/// Reverts upon failure.
///
/// The `from` account must have their entire balance approved for the current contract to manage.
function safeTransferAllFrom(address token, address from, address to)
internal
returns (uint256 amount)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
// Read the balance, reverting upon failure.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
)
) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
/// Reverts upon failure.
function safeTransfer(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sends all of ERC20 `token` from the current contract to `to`.
/// Reverts upon failure.
function safeTransferAll(address token, address to) internal returns (uint256 amount) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
mstore(0x20, address()) // Store the address of the current contract.
// Read the balance, reverting upon failure.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
)
) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
mstore(0x14, to) // Store the `to` argument.
amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
/// Reverts upon failure.
function safeApprove(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
/// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
/// then retries the approval again (some tokens, e.g. USDT, requires this).
/// Reverts upon failure.
function safeApproveWithRetry(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
// Perform the approval, retrying upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x34, 0) // Store 0 for the `amount`.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
mstore(0x34, amount) // Store back the original `amount`.
// Retry the approval, reverting upon failure.
success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
// Check the `extcodesize` again just in case the token selfdestructs lol.
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
revert(0x1c, 0x04)
}
}
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Returns the amount of ERC20 `token` owned by `account`.
/// Returns zero if the `token` does not exist.
function balanceOf(address token, address account) internal view returns (uint256 amount) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, account) // Store the `account` argument.
mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
amount :=
mul( // The arguments of `mul` are evaluated from right to left.
mload(0x20),
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
)
)
}
}
/// @dev Returns the total supply of the `token`.
/// Reverts if the token does not exist or does not implement `totalSupply()`.
function totalSupply(address token) internal view returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x18160ddd) // `totalSupply()`.
if iszero(
and(gt(returndatasize(), 0x1f), staticcall(gas(), token, 0x1c, 0x04, 0x00, 0x20))
) {
mstore(0x00, 0x54cd9435) // `TotalSupplyQueryFailed()`.
revert(0x1c, 0x04)
}
result := mload(0x00)
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
/// If the initial attempt fails, try to use Permit2 to transfer the token.
/// Reverts upon failure.
///
/// The `from` account must have at least `amount` approved for the current contract to manage.
function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {
if (!trySafeTransferFrom(token, from, to, amount)) {
permit2TransferFrom(token, from, to, amount);
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.
/// Reverts upon failure.
function permit2TransferFrom(address token, address from, address to, uint256 amount)
internal
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(add(m, 0x74), shr(96, shl(96, token)))
mstore(add(m, 0x54), amount)
mstore(add(m, 0x34), to)
mstore(add(m, 0x20), shl(96, from))
// `transferFrom(address,address,uint160,address)`.
mstore(m, 0x36c78516000000000000000000000000)
let p := PERMIT2
let exists := eq(chainid(), 1)
if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }
if iszero(
and(
call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00),
lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists.
)
) {
mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.
revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)
}
}
}
/// @dev Permit a user to spend a given amount of
/// another user's tokens via native EIP-2612 permit if possible, falling
/// back to Permit2 if native permit fails or is not implemented on the token.
function permit2(
address token,
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
for {} shl(96, xor(token, WETH9)) {} {
mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.
// Gas stipend to limit gas burn for tokens that don't refund gas when
// an non-existing function is called. 5K should be enough for a SLOAD.
staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)
)
) { break }
// After here, we can be sure that token is a contract.
let m := mload(0x40)
mstore(add(m, 0x34), spender)
mstore(add(m, 0x20), shl(96, owner))
mstore(add(m, 0x74), deadline)
if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {
mstore(0x14, owner)
mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.
mstore(
add(m, 0x94),
lt(iszero(amount), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))
)
mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.
// `nonces` is already at `add(m, 0x54)`.
// `amount != 0` is already stored at `add(m, 0x94)`.
mstore(add(m, 0xb4), and(0xff, v))
mstore(add(m, 0xd4), r)
mstore(add(m, 0xf4), s)
success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)
break
}
mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.
mstore(add(m, 0x54), amount)
mstore(add(m, 0x94), and(0xff, v))
mstore(add(m, 0xb4), r)
mstore(add(m, 0xd4), s)
success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)
break
}
}
if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);
}
/// @dev Simple permit on the Permit2 contract.
function simplePermit2(
address token,
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, 0x927da105) // `allowance(address,address,address)`.
{
let addressMask := shr(96, not(0))
mstore(add(m, 0x20), and(addressMask, owner))
mstore(add(m, 0x40), and(addressMask, token))
mstore(add(m, 0x60), and(addressMask, spender))
mstore(add(m, 0xc0), and(addressMask, spender))
}
let p := mul(PERMIT2, iszero(shr(160, amount)))
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.
staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)
)
) {
mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.
revert(add(0x18, shl(2, iszero(p))), 0x04)
}
mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).
// `owner` is already `add(m, 0x20)`.
// `token` is already at `add(m, 0x40)`.
mstore(add(m, 0x60), amount)
mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.
// `nonce` is already at `add(m, 0xa0)`.
// `spender` is already at `add(m, 0xc0)`.
mstore(add(m, 0xe0), deadline)
mstore(add(m, 0x100), 0x100) // `signature` offset.
mstore(add(m, 0x120), 0x41) // `signature` length.
mstore(add(m, 0x140), r)
mstore(add(m, 0x160), s)
mstore(add(m, 0x180), shl(248, v))
if iszero( // Revert if token does not have code, or if the call fails.
mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))) {
mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Approves `spender` to spend `amount` of `token` for `address(this)`.
function permit2Approve(address token, address spender, uint160 amount, uint48 expiration)
internal
{
/// @solidity memory-safe-assembly
assembly {
let addressMask := shr(96, not(0))
let m := mload(0x40)
mstore(m, 0x87517c45) // `approve(address,address,uint160,uint48)`.
mstore(add(m, 0x20), and(addressMask, token))
mstore(add(m, 0x40), and(addressMask, spender))
mstore(add(m, 0x60), and(addressMask, amount))
mstore(add(m, 0x80), and(0xffffffffffff, expiration))
if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) {
mstore(0x00, 0x324f14ae) // `Permit2ApproveFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Revokes an approval for `token` and `spender` for `address(this)`.
function permit2Lockdown(address token, address spender) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, 0xcc53287f) // `Permit2.lockdown`.
mstore(add(m, 0x20), 0x20) // Offset of the `approvals`.
mstore(add(m, 0x40), 1) // `approvals.length`.
mstore(add(m, 0x60), shr(96, shl(96, token)))
mstore(add(m, 0x80), shr(96, shl(96, spender)))
if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) {
mstore(0x00, 0x96b3de23) // `Permit2LockdownFailed()`.
revert(0x1c, 0x04)
}
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {Multicallable} from "solady/utils/Multicallable.sol";
abstract contract PayableMulticallable is Multicallable {
function multicall(bytes[] calldata data) public payable override returns (bytes[] memory) {
_multicallDirectReturn(_multicall(data));
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {ILocker, IPayer, IFlashAccountant} from "../interfaces/IFlashAccountant.sol";
import {NATIVE_TOKEN_ADDRESS} from "../math/constants.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
abstract contract BaseLocker is ILocker, IPayer {
error BaseLockerAccountantOnly();
IFlashAccountant internal immutable accountant;
constructor(IFlashAccountant _accountant) {
accountant = _accountant;
}
/// CALLBACK HANDLERS
function locked(uint256 id) external {
if (msg.sender != address(accountant)) revert BaseLockerAccountantOnly();
bytes memory data = msg.data[36:];
bytes memory result = handleLockData(id, data);
assembly ("memory-safe") {
// raw return whatever the handler sent
return(add(result, 32), mload(result))
}
}
function payCallback(uint256, address token) external {
if (msg.sender != address(accountant)) revert BaseLockerAccountantOnly();
address from;
uint256 amount;
assembly ("memory-safe") {
from := calldataload(68)
amount := calldataload(100)
}
SafeTransferLib.safeTransferFrom2(token, from, address(accountant), amount);
}
/// INTERNAL FUNCTIONS
function lock(bytes memory data) internal returns (bytes memory result) {
address target = address(accountant);
assembly ("memory-safe") {
// We will store result where the free memory pointer is now, ...
result := mload(0x40)
// But first use it to store the calldata
// Selector of lock()
mstore(result, shl(224, 0xf83d08ba))
// We only copy the data, not the length, because the length is read from the calldata size
let len := mload(data)
mcopy(add(result, 4), add(data, 32), len)
// If the call failed, pass through the revert
if iszero(call(gas(), target, 0, result, add(len, 4), 0, 0)) {
returndatacopy(result, 0, returndatasize())
revert(result, returndatasize())
}
// Copy the entire return data into the space where the result is pointing
mstore(result, returndatasize())
returndatacopy(add(result, 32), 0, returndatasize())
// Update the free memory pointer to be after the end of the data, aligned to the next 32 byte word
mstore(0x40, and(add(add(result, add(32, returndatasize())), 31), not(31)))
}
}
error ExpectedRevertWithinLock();
function lockAndExpectRevert(bytes memory data) internal returns (bytes memory result) {
address target = address(accountant);
assembly ("memory-safe") {
// We will store result where the free memory pointer is now, ...
result := mload(0x40)
// But first use it to store the calldata
// Selector of lock()
mstore(result, shl(224, 0xf83d08ba))
// We only copy the data, not the length, because the length is read from the calldata size
let len := mload(data)
mcopy(add(result, 4), add(data, 32), len)
// If the call succeeded, revert with ExpectedRevertWithinLock.selector
if call(gas(), target, 0, result, add(len, 4), 0, 0) {
mstore(0, shl(224, 0x4c816e2b))
revert(0, 4)
}
// Copy the entire revert data into the space where the result is pointing
mstore(result, returndatasize())
returndatacopy(add(result, 32), 0, returndatasize())
// Update the free memory pointer to be after the end of the data, aligned to the next 32 byte word
mstore(0x40, and(add(add(result, add(32, returndatasize())), 31), not(31)))
}
}
function pay(address from, address token, uint256 amount) internal {
if (amount != 0) {
if (token == NATIVE_TOKEN_ADDRESS) {
SafeTransferLib.safeTransferETH(address(accountant), amount);
} else {
address target = address(accountant);
assembly ("memory-safe") {
let free := mload(0x40)
// selector of pay(address)
mstore(free, shl(224, 0x0c11dedd))
mstore(add(free, 4), token)
// additional data is appended to the payCallback
mstore(add(free, 36), from)
mstore(add(free, 68), amount)
// if it failed, pass through revert
if iszero(call(gas(), target, 0, free, 100, 0, 0)) {
returndatacopy(free, 0, returndatasize())
revert(free, returndatasize())
}
}
}
}
}
function forward(address to, bytes memory data) internal returns (bytes memory result) {
address target = address(accountant);
assembly ("memory-safe") {
// We will store result where the free memory pointer is now, ...
result := mload(0x40)
// But first use it to store the calldata
// Selector of forward(address)
mstore(result, shl(224, 0x101e8952))
mstore(add(result, 4), to)
// We only copy the data, not the length, because the length is read from the calldata size
let len := mload(data)
mcopy(add(result, 36), add(data, 32), len)
// If the call failed, pass through the revert
if iszero(call(gas(), target, 0, result, add(36, len), 0, 0)) {
returndatacopy(result, 0, returndatasize())
revert(result, returndatasize())
}
// Copy the entire return data into the space where the result is pointing
mstore(result, returndatasize())
returndatacopy(add(result, 32), 0, returndatasize())
// Update the free memory pointer to be after the end of the data, aligned to the next 32 byte word
mstore(0x40, and(add(add(result, add(32, returndatasize())), 31), not(31)))
}
}
function withdraw(address token, uint128 amount, address recipient) internal {
if (amount > 0) {
accountant.withdraw(token, recipient, amount);
}
}
function handleLockData(uint256 id, bytes memory data) internal virtual returns (bytes memory result);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {ICore} from "../interfaces/ICore.sol";
abstract contract UsesCore {
error CoreOnly();
ICore internal immutable core;
constructor(ICore _core) {
core = _core;
}
modifier onlyCore() {
if (msg.sender != address(core)) revert CoreOnly();
_;
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
interface ILocker {
function locked(uint256 id) external;
}
interface IForwardee {
function forwarded(uint256 id, address originalLocker) external;
}
interface IPayer {
function payCallback(uint256 id, address token) external;
}
interface IFlashAccountant {
error NotLocked();
error LockerOnly();
error NoPaymentMade();
error DebtsNotZeroed(uint256 id);
// Thrown if the contract receives too much payment in the payment callback or from a direct native token transfer
error PaymentOverflow();
error PayReentrance();
// Create a lock context
// Any data passed after the function signature is passed through back to the caller after the locked function signature and data, with no additional encoding
// In addition, any data returned from ILocker#locked is also returned from this function exactly as is, i.e. with no additional encoding or decoding
// Reverts are also bubbled up
function lock() external;
// Forward the lock from the current locker to the given address
// Any additional calldata is also passed through to the forwardee, with no additional encoding
// In addition, any data returned from IForwardee#forwarded is also returned from this function exactly as is, i.e. with no additional encoding or decoding
// Reverts are also bubbled up
function forward(address to) external;
// Pays the given amount of token, by calling the payCallback function on the caller to afford them the opportunity to make the payment.
// This function, unlike lock and forward, does not return any of the returndata from the callback.
// This function also cannot be re-entered like lock and forward.
// Must be locked, as the contract accounts the payment against the current locker's debts.
// Token must not be the NATIVE_TOKEN_ADDRESS, as the `balanceOf` calls will fail.
// If you want to pay in the chain's native token, simply transfer it to this contract using a call.
// The payer must implement payCallback in which they must transfer the token to Core.
function pay(address token) external returns (uint128 payment);
// Withdraws a token amount from the accountant to the given recipient.
// The contract must be locked, as it tracks the withdrawn amount against the current locker's delta.
function withdraw(address token, address recipient, uint128 amount) external;
// This contract can receive ETH as a payment as well
receive() external payable;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {MAX_TICK_SPACING, FULL_RANGE_ONLY_TICK_SPACING} from "../math/constants.sol";
using {toPoolId, validatePoolKey, isFullRange, mustLoadFees, tickSpacing, fee, extension} for PoolKey global;
// address (20 bytes) | fee (8 bytes) | tickSpacing (4 bytes)
type Config is bytes32;
function tickSpacing(PoolKey memory pk) pure returns (uint32 r) {
assembly ("memory-safe") {
r := and(mload(add(64, pk)), 0xffffffff)
}
}
function fee(PoolKey memory pk) pure returns (uint64 r) {
assembly ("memory-safe") {
r := and(mload(add(60, pk)), 0xffffffffffffffff)
}
}
function extension(PoolKey memory pk) pure returns (address r) {
assembly ("memory-safe") {
r := and(mload(add(52, pk)), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
function mustLoadFees(PoolKey memory pk) pure returns (bool r) {
assembly ("memory-safe") {
// only if either of tick spacing and fee are nonzero
// if _both_ are zero, then we know we do not need to load fees for swaps
r := iszero(iszero(and(mload(add(64, pk)), 0xffffffffffffffffffffffff)))
}
}
function isFullRange(PoolKey memory pk) pure returns (bool r) {
r = pk.tickSpacing() == FULL_RANGE_ONLY_TICK_SPACING;
}
function toConfig(uint64 _fee, uint32 _tickSpacing, address _extension) pure returns (Config c) {
assembly ("memory-safe") {
c := add(add(shl(96, _extension), shl(32, _fee)), _tickSpacing)
}
}
// Each pool has its own state associated with this key
struct PoolKey {
address token0;
address token1;
Config config;
}
error TokensMustBeSorted();
error InvalidTickSpacing();
function validatePoolKey(PoolKey memory key) pure {
if (key.token0 >= key.token1) revert TokensMustBeSorted();
if (key.tickSpacing() > MAX_TICK_SPACING) {
revert InvalidTickSpacing();
}
}
function toPoolId(PoolKey memory key) pure returns (bytes32 result) {
assembly ("memory-safe") {
// it's already copied into memory
result := keccak256(key, 96)
}
}// SPDX-License-Identifier: UNLICENSED pragma solidity =0.8.28; int32 constant MIN_TICK = -88722835; int32 constant MAX_TICK = 88722835; uint32 constant MAX_TICK_MAGNITUDE = uint32(MAX_TICK); uint32 constant MAX_TICK_SPACING = 698605; uint32 constant FULL_RANGE_ONLY_TICK_SPACING = 0; // We use this address to represent the native token within the protocol address constant NATIVE_TOKEN_ADDRESS = address(0);
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
function isPriceIncreasing(int128 amount, bool isToken1) pure returns (bool increasing) {
assembly ("memory-safe") {
increasing := xor(isToken1, slt(amount, 0))
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
// Contains a single method which allows a user to approve this contract via permit2
// Combining with Multicallable is highly recommended, so that the permit signature can be used to spend tokens in a single transaction
// Note this only allows the msg.sender to execute a permit. Our contracts are not intended for use with some types of contract based account abstraction.
contract Permittable {
// Method is payable in case it is paired with other payable Multicallable calls
function permit(address token, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable {
SafeTransferLib.permit2(token, msg.sender, address(this), amount, deadline, v, r, s);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {NATIVE_TOKEN_ADDRESS} from "../math/constants.sol";
// Has methods that are multicallable for checking deadlines and balance changes
// Only useful in multicallable context, because these methods are expected to be called as part of another transaction that manipulates balances
// All methods are payable in case they are paired with other payable Multicallable calls
abstract contract SlippageChecker {
error TransactionExpired(uint256 deadline);
error MinimumOutputNotReceived(address token, uint256 minimumOutput);
error MaximumInputExceeded(address token, uint256 maximumInput);
// cast keccak "SlippageChecker#balanceKey"
uint256 private constant _BALANCE_KEY_OFFSET = 0x2ea13d3f0340a613d1765d6e239004eca4cb7efa2e253d1e113c4d333b8db7c8;
function balanceKey(address token, address account) private pure returns (bytes32 key) {
assembly ("memory-safe") {
mstore(0, token)
mstore(32, account)
key := add(keccak256(0, 64), _BALANCE_KEY_OFFSET)
}
}
function getRecordedBalance(address token, address account) private view returns (uint256 prev) {
bytes32 key = balanceKey(token, account);
assembly ("memory-safe") {
prev := tload(key)
}
}
function getBalance(address token, address account) private view returns (uint256 balance) {
if (token == NATIVE_TOKEN_ADDRESS) {
balance = account.balance;
} else {
balance = SafeTransferLib.balanceOf(token, account);
}
}
function recordBalanceForSlippageCheck(address token) external payable {
bytes32 key = balanceKey(token, msg.sender);
uint256 bal = getBalance(token, msg.sender);
assembly ("memory-safe") {
tstore(key, bal)
}
}
function checkDeadline(uint256 deadline) external payable {
if (block.timestamp > deadline) revert TransactionExpired(deadline);
}
function checkMinimumOutputReceived(address token, uint256 minimumOutput) external payable {
uint256 prev = getRecordedBalance(token, msg.sender);
uint256 bal = getBalance(token, msg.sender);
unchecked {
if (bal < prev || (bal - prev) < minimumOutput) {
revert MinimumOutputNotReceived(token, minimumOutput);
}
}
}
function checkMaximumInputNotExceeded(address token, uint256 maximumInput) external payable {
uint256 prev = getRecordedBalance(token, msg.sender);
uint256 bal = getBalance(token, msg.sender);
unchecked {
if (bal < prev && (prev - bal) > maximumInput) {
revert MaximumInputExceeded(token, maximumInput);
}
}
}
// Allows a caller to refund any ETH sent to this contract for purpose of transient payments
function refundNativeToken() external payable {
if (address(this).balance > 0) {
SafeTransferLib.safeTransferETH(msg.sender, address(this).balance);
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
// A dynamic fixed point number (a la floating point) that stores a shifting 94 bit view of the underlying fixed point value,
// based on the most significant bits (mantissa)
// If the most significant 2 bits are 11, it represents a 64.30
// If the most significant 2 bits are 10, it represents a 32.62 number
// If the most significant 2 bits are 01, it represents a 0.94 number
// If the most significant 2 bits are 00, it represents a 0.126 number that is always less than 2**-32
type SqrtRatio is uint96;
uint96 constant MIN_SQRT_RATIO_RAW = 4611797791050542631;
SqrtRatio constant MIN_SQRT_RATIO = SqrtRatio.wrap(MIN_SQRT_RATIO_RAW);
uint96 constant MAX_SQRT_RATIO_RAW = 79227682466138141934206691491;
SqrtRatio constant MAX_SQRT_RATIO = SqrtRatio.wrap(MAX_SQRT_RATIO_RAW);
uint96 constant TWO_POW_95 = 0x800000000000000000000000;
uint96 constant TWO_POW_94 = 0x400000000000000000000000;
uint96 constant TWO_POW_62 = 0x4000000000000000;
uint96 constant TWO_POW_62_MINUS_ONE = 0x3fffffffffffffff;
uint96 constant BIT_MASK = 0xc00000000000000000000000; // TWO_POW_95 | TWO_POW_94
SqrtRatio constant ONE = SqrtRatio.wrap((TWO_POW_95) + (1 << 62));
using {
toFixed,
isValid,
ge as >=,
le as <=,
lt as <,
gt as >,
eq as ==,
neq as !=,
isZero,
min,
max
} for SqrtRatio global;
function isValid(SqrtRatio sqrtRatio) pure returns (bool r) {
assembly ("memory-safe") {
r :=
and(
// greater than or equal to TWO_POW_62, i.e. the whole number portion is nonzero
gt(and(sqrtRatio, not(BIT_MASK)), TWO_POW_62_MINUS_ONE),
// and between min/max sqrt ratio
and(iszero(lt(sqrtRatio, MIN_SQRT_RATIO_RAW)), iszero(gt(sqrtRatio, MAX_SQRT_RATIO_RAW)))
)
}
}
error ValueOverflowsSqrtRatioContainer();
// If passing a value greater than this constant with roundUp = true, toSqrtRatio will overflow
// For roundUp = false, the constant is type(uint192).max
uint256 constant MAX_FIXED_VALUE_ROUND_UP =
0x1000000000000000000000000000000000000000000000000 - 0x4000000000000000000000000;
// Converts a 64.128 value into the compact SqrtRatio representation
function toSqrtRatio(uint256 sqrtRatio, bool roundUp) pure returns (SqrtRatio r) {
assembly ("memory-safe") {
let addend := mul(roundUp, 0x3)
// lt 2**96 after rounding up
switch lt(sqrtRatio, sub(0x1000000000000000000000000, addend))
case 1 { r := shr(2, add(sqrtRatio, addend)) }
default {
// 2**34 - 1
addend := mul(roundUp, 0x3ffffffff)
// lt 2**128 after rounding up
switch lt(sqrtRatio, sub(0x100000000000000000000000000000000, addend))
case 1 { r := or(TWO_POW_94, shr(34, add(sqrtRatio, addend))) }
default {
addend := mul(roundUp, 0x3ffffffffffffffff)
// lt 2**160 after rounding up
switch lt(sqrtRatio, sub(0x10000000000000000000000000000000000000000, addend))
case 1 { r := or(TWO_POW_95, shr(66, add(sqrtRatio, addend))) }
default {
// 2**98 - 1
addend := mul(roundUp, 0x3ffffffffffffffffffffffff)
switch lt(sqrtRatio, sub(0x1000000000000000000000000000000000000000000000000, addend))
case 1 { r := or(BIT_MASK, shr(98, add(sqrtRatio, addend))) }
default {
// cast sig "ValueOverflowsSqrtRatioContainer()"
mstore(0, shl(224, 0xa10459f4))
revert(0, 4)
}
}
}
}
}
}
// Returns the 64.128 representation of the given sqrt ratio
function toFixed(SqrtRatio sqrtRatio) pure returns (uint256 r) {
assembly ("memory-safe") {
r := shl(add(2, shr(89, and(sqrtRatio, BIT_MASK))), and(sqrtRatio, not(BIT_MASK)))
}
}
// The below operators assume that the SqrtRatio is valid, i.e. SqrtRatio#isValid returns true
function lt(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
r = SqrtRatio.unwrap(a) < SqrtRatio.unwrap(b);
}
function gt(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
r = SqrtRatio.unwrap(a) > SqrtRatio.unwrap(b);
}
function le(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
r = SqrtRatio.unwrap(a) <= SqrtRatio.unwrap(b);
}
function ge(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
r = SqrtRatio.unwrap(a) >= SqrtRatio.unwrap(b);
}
function eq(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
r = SqrtRatio.unwrap(a) == SqrtRatio.unwrap(b);
}
function neq(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
r = SqrtRatio.unwrap(a) != SqrtRatio.unwrap(b);
}
function isZero(SqrtRatio a) pure returns (bool r) {
assembly ("memory-safe") {
r := iszero(a)
}
}
function max(SqrtRatio a, SqrtRatio b) pure returns (SqrtRatio r) {
assembly ("memory-safe") {
r := xor(a, mul(xor(a, b), gt(b, a)))
}
}
function min(SqrtRatio a, SqrtRatio b) pure returns (SqrtRatio r) {
assembly ("memory-safe") {
r := xor(a, mul(xor(a, b), lt(b, a)))
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error ExpOverflow();
/// @dev The operation failed, as the output exceeds the maximum value of uint256.
error FactorialOverflow();
/// @dev The operation failed, due to an overflow.
error RPowOverflow();
/// @dev The mantissa is too big to fit.
error MantissaOverflow();
/// @dev The operation failed, due to an multiplication overflow.
error MulWadFailed();
/// @dev The operation failed, due to an multiplication overflow.
error SMulWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error DivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error SDivWadFailed();
/// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
error MulDivFailed();
/// @dev The division failed, as the denominator is zero.
error DivFailed();
/// @dev The full precision multiply-divide operation failed, either due
/// to the result being larger than 256 bits, or a division by a zero.
error FullMulDivFailed();
/// @dev The output is undefined, as the input is less-than-or-equal to zero.
error LnWadUndefined();
/// @dev The input outside the acceptable domain.
error OutOfDomain();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The scalar of ETH and most ERC20s.
uint256 internal constant WAD = 1e18;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* SIMPLIFIED FIXED POINT OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if gt(x, div(not(0), y)) {
if y {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
}
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down.
function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.
if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {
mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(z, WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, y), WAD)
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up.
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if iszero(eq(div(z, y), x)) {
if y {
mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
revert(0x1c, 0x04)
}
}
z := add(iszero(iszero(mod(z, WAD))), div(z, WAD))
}
}
/// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.
function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.
if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down.
function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, WAD)
// Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.
if iszero(mul(y, eq(sdiv(z, WAD), x))) {
mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.
revert(0x1c, 0x04)
}
z := sdiv(z, y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(mul(x, WAD), y)
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up.
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.
if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {
mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.
function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
}
}
/// @dev Equivalent to `x` to the power of `y`.
/// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
/// Note: This function is an approximation.
function powWad(int256 x, int256 y) internal pure returns (int256) {
// Using `ln(x)` means `x` must be greater than 0.
return expWad((lnWad(x) * y) / int256(WAD));
}
/// @dev Returns `exp(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
/// Note: This function is an approximation. Monotonically increasing.
function expWad(int256 x) internal pure returns (int256 r) {
unchecked {
// When the result is less than 0.5 we return zero.
// This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
if (x <= -41446531673892822313) return r;
/// @solidity memory-safe-assembly
assembly {
// When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
// an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
if iszero(slt(x, 135305999368893231589)) {
mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
revert(0x1c, 0x04)
}
}
// `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
// for more intermediate precision and a binary basis. This base conversion
// is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
x = (x << 78) / 5 ** 18;
// Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
// of two such that exp(x) = exp(x') * 2**k, where k is an integer.
// Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
x = x - k * 54916777467707473351141471128;
// `k` is in the range `[-61, 195]`.
// Evaluate using a (6, 7)-term rational approximation.
// `p` is made monic, we'll multiply by a scale factor later.
int256 y = x + 1346386616545796478920950773328;
y = ((y * x) >> 96) + 57155421227552351082224309758442;
int256 p = y + x - 94201549194550492254356042504812;
p = ((p * y) >> 96) + 28719021644029726153956944680412240;
p = p * x + (4385272521454847904659076985693276 << 96);
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
int256 q = x - 2855989394907223263936484059900;
q = ((q * x) >> 96) + 50020603652535783019961831881945;
q = ((q * x) >> 96) - 533845033583426703283633433725380;
q = ((q * x) >> 96) + 3604857256930695427073651918091429;
q = ((q * x) >> 96) - 14423608567350463180887372962807573;
q = ((q * x) >> 96) + 26449188498355588339934803723976023;
/// @solidity memory-safe-assembly
assembly {
// Div in assembly because solidity adds a zero check despite the unchecked.
// The q polynomial won't have zeros in the domain as all its roots are complex.
// No scaling is necessary because p is already `2**96` too large.
r := sdiv(p, q)
}
// r should be in the range `(0.09, 0.25) * 2**96`.
// We now need to multiply r by:
// - The scale factor `s ≈ 6.031367120`.
// - The `2**k` factor from the range reduction.
// - The `1e18 / 2**96` factor for base conversion.
// We do this all at once, with an intermediate result in `2**213`
// basis, so the final right shift is always by a positive amount.
r = int256(
(uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
);
}
}
/// @dev Returns `ln(x)`, denominated in `WAD`.
/// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
/// Note: This function is an approximation. Monotonically increasing.
function lnWad(int256 x) internal pure returns (int256 r) {
/// @solidity memory-safe-assembly
assembly {
// We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
// We do this by multiplying by `2**96 / 10**18`. But since
// `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
// and add `ln(2**96 / 10**18)` at the end.
// Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// We place the check here for more optimal stack operations.
if iszero(sgt(x, 0)) {
mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
revert(0x1c, 0x04)
}
// forgefmt: disable-next-item
r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))
// Reduce range of x to (1, 2) * 2**96
// ln(2^k * x) = k * ln(2) + ln(x)
x := shr(159, shl(r, x))
// Evaluate using a (8, 8)-term rational approximation.
// `p` is made monic, we will multiply by a scale factor later.
// forgefmt: disable-next-item
let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
sar(96, mul(add(43456485725739037958740375743393,
sar(96, mul(add(24828157081833163892658089445524,
sar(96, mul(add(3273285459638523848632254066296,
x), x))), x))), x)), 11111509109440967052023855526967)
p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
// We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
// `q` is monic by convention.
let q := add(5573035233440673466300451813936, x)
q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
q := add(909429971244387300277376558375, sar(96, mul(x, q)))
// `p / q` is in the range `(0, 0.125) * 2**96`.
// Finalization, we need to:
// - Multiply by the scale factor `s = 5.549…`.
// - Add `ln(2**96 / 10**18)`.
// - Add `k * ln(2)`.
// - Multiply by `10**18 / 2**96 = 5**18 >> 78`.
// The q polynomial is known not to have zeros in the domain.
// No scaling required because p is already `2**96` too large.
p := sdiv(p, q)
// Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
p := mul(1677202110996718588342820967067443963516166, p)
// Add `ln(2) * k * 5**18 * 2**192`.
// forgefmt: disable-next-item
p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
// Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
// Base conversion: mul `2**18 / 2**192`.
r := sar(174, p)
}
}
/// @dev Returns `W_0(x)`, denominated in `WAD`.
/// See: https://en.wikipedia.org/wiki/Lambert_W_function
/// a.k.a. Product log function. This is an approximation of the principal branch.
/// Note: This function is an approximation. Monotonically increasing.
function lambertW0Wad(int256 x) internal pure returns (int256 w) {
// forgefmt: disable-next-item
unchecked {
if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.
(int256 wad, int256 p) = (int256(WAD), x);
uint256 c; // Whether we need to avoid catastrophic cancellation.
uint256 i = 4; // Number of iterations.
if (w <= 0x1ffffffffffff) {
if (-0x4000000000000 <= w) {
i = 1; // Inputs near zero only take one step to converge.
} else if (w <= -0x3ffffffffffffff) {
i = 32; // Inputs near `-1/e` take very long to converge.
}
} else if (uint256(w >> 63) == uint256(0)) {
/// @solidity memory-safe-assembly
assembly {
// Inline log2 for more performance, since the range is small.
let v := shr(49, w)
let l := shl(3, lt(0xff, v))
l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000)), 49)
w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))
c := gt(l, 60)
i := add(2, add(gt(l, 53), c))
}
} else {
int256 ll = lnWad(w = lnWad(w));
/// @solidity memory-safe-assembly
assembly {
// `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.
w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))
i := add(3, iszero(shr(68, x)))
c := iszero(shr(143, x))
}
if (c == uint256(0)) {
do { // If `x` is big, use Newton's so that intermediate values won't overflow.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := mul(w, div(e, wad))
w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))
}
if (p <= w) break;
p = w;
} while (--i != uint256(0));
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
return w;
}
}
do { // Otherwise, use Halley's for faster convergence.
int256 e = expWad(w);
/// @solidity memory-safe-assembly
assembly {
let t := add(w, wad)
let s := sub(mul(w, e), mul(x, wad))
w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))
}
if (p <= w) break;
p = w;
} while (--i != c);
/// @solidity memory-safe-assembly
assembly {
w := sub(w, sgt(w, 2))
}
// For certain ranges of `x`, we'll use the quadratic-rate recursive formula of
// R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.
if (c == uint256(0)) return w;
int256 t = w | 1;
/// @solidity memory-safe-assembly
assembly {
x := sdiv(mul(x, wad), t)
}
x = (t * (wad + lnWad(x)));
/// @solidity memory-safe-assembly
assembly {
w := sdiv(x, add(wad, t))
}
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* GENERAL NUMBER UTILITIES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `a * b == x * y`, with full precision.
function fullMulEq(uint256 a, uint256 b, uint256 x, uint256 y)
internal
pure
returns (bool result)
{
/// @solidity memory-safe-assembly
assembly {
result := and(eq(mul(a, b), mul(x, y)), eq(mulmod(x, y, not(0)), mulmod(a, b, not(0))))
}
}
/// @dev Calculates `floor(x * y / d)` with full precision.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// 512-bit multiply `[p1 p0] = x * y`.
// Compute the product mod `2**256` and mod `2**256 - 1`
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that `product = p1 * 2**256 + p0`.
// Temporarily use `z` as `p0` to save gas.
z := mul(x, y) // Lower 256 bits of `x * y`.
for {} 1 {} {
// If overflows.
if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
let mm := mulmod(x, y, not(0))
let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.
/*------------------- 512 by 256 division --------------------*/
// Make division exact by subtracting the remainder from `[p1 p0]`.
let r := mulmod(x, y, d) // Compute remainder using mulmod.
let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`.
// Make sure `z` is less than `2**256`. Also prevents `d == 0`.
// Placing the check here seems to give more optimal stack operations.
if iszero(gt(d, p1)) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
d := div(d, t) // Divide `d` by `t`, which is a power of two.
// Invert `d mod 2**256`
// Now that `d` is an odd number, it has an inverse
// modulo `2**256` such that `d * inv = 1 mod 2**256`.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, `d * inv = 1 mod 2**4`.
let inv := xor(2, mul(3, d))
// Now use 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.
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
z :=
mul(
// Divide [p1 p0] by the factors of two.
// Shift in bits from `p1` into `p0`. For this we need
// to flip `t` such that it is `2**256 / t`.
or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),
mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256
)
break
}
z := div(z, d)
break
}
}
}
/// @dev Calculates `floor(x * y / d)` with full precision.
/// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits.
/// Performs the full 512 bit calculation regardless.
function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d)
internal
pure
returns (uint256 z)
{
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
let mm := mulmod(x, y, not(0))
let p1 := sub(mm, add(z, lt(mm, z)))
let t := and(d, sub(0, d))
let r := mulmod(x, y, d)
d := div(d, t)
let inv := xor(2, mul(3, d))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
inv := mul(inv, sub(2, mul(d, inv)))
z :=
mul(
or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),
mul(sub(2, mul(d, inv)), inv)
)
}
}
/// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
/// Throws if result overflows a uint256 or when `d` is zero.
/// Credit to Uniswap-v3-core under MIT license:
/// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
z = fullMulDiv(x, y, d);
/// @solidity memory-safe-assembly
assembly {
if mulmod(x, y, d) {
z := add(z, 1)
if iszero(z) {
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
}
}
}
/// @dev Calculates `floor(x * y / 2 ** n)` with full precision.
/// Throws if result overflows a uint256.
/// Credit to Philogy under MIT license:
/// https://github.com/SorellaLabs/angstrom/blob/main/contracts/src/libraries/X128MathLib.sol
function fullMulDivN(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Temporarily use `z` as `p0` to save gas.
z := mul(x, y) // Lower 256 bits of `x * y`. We'll call this `z`.
for {} 1 {} {
if iszero(or(iszero(x), eq(div(z, x), y))) {
let k := and(n, 0xff) // `n`, cleaned.
let mm := mulmod(x, y, not(0))
let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.
// | p1 | z |
// Before: | p1_0 ¦ p1_1 | z_0 ¦ z_1 |
// Final: | 0 ¦ p1_0 | p1_1 ¦ z_0 |
// Check that final `z` doesn't overflow by checking that p1_0 = 0.
if iszero(shr(k, p1)) {
z := add(shl(sub(256, k), p1), shr(k, z))
break
}
mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
revert(0x1c, 0x04)
}
z := shr(and(n, 0xff), z)
break
}
}
}
/// @dev Returns `floor(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := div(z, d)
}
}
/// @dev Returns `ceil(x * y / d)`.
/// Reverts if `x * y` overflows, or `d` is zero.
function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(x, y)
// Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
mstore(0x00, 0xad251c27) // `MulDivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(z, d))), div(z, d))
}
}
/// @dev Returns `x`, the modular multiplicative inverse of `a`, such that `(a * x) % n == 1`.
function invMod(uint256 a, uint256 n) internal pure returns (uint256 x) {
/// @solidity memory-safe-assembly
assembly {
let g := n
let r := mod(a, n)
for { let y := 1 } 1 {} {
let q := div(g, r)
let t := g
g := r
r := sub(t, mul(r, q))
let u := x
x := y
y := sub(u, mul(y, q))
if iszero(r) { break }
}
x := mul(eq(g, 1), add(x, mul(slt(x, 0), n)))
}
}
/// @dev Returns `ceil(x / d)`.
/// Reverts if `d` is zero.
function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
if iszero(d) {
mstore(0x00, 0x65244e4e) // `DivFailed()`.
revert(0x1c, 0x04)
}
z := add(iszero(iszero(mod(x, d))), div(x, d))
}
}
/// @dev Returns `max(0, x - y)`. Alias for `saturatingSub`.
function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Returns `max(0, x - y)`.
function saturatingSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(gt(x, y), sub(x, y))
}
}
/// @dev Returns `min(2 ** 256 - 1, x + y)`.
function saturatingAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(sub(0, lt(add(x, y), x)), add(x, y))
}
}
/// @dev Returns `min(2 ** 256 - 1, x * y)`.
function saturatingMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(sub(or(iszero(x), eq(div(mul(x, y), x), y)), 1), mul(x, y))
}
}
/// @dev Returns `condition ? x : y`, without branching.
function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), iszero(condition)))
}
}
/// @dev Returns `condition ? x : y`, without branching.
function ternary(bool condition, bytes32 x, bytes32 y) internal pure returns (bytes32 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), iszero(condition)))
}
}
/// @dev Returns `condition ? x : y`, without branching.
function ternary(bool condition, address x, address y) internal pure returns (address z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), iszero(condition)))
}
}
/// @dev Returns `x != 0 ? x : y`, without branching.
function coalesce(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(x, mul(y, iszero(x)))
}
}
/// @dev Returns `x != bytes32(0) ? x : y`, without branching.
function coalesce(bytes32 x, bytes32 y) internal pure returns (bytes32 z) {
/// @solidity memory-safe-assembly
assembly {
z := or(x, mul(y, iszero(x)))
}
}
/// @dev Returns `x != address(0) ? x : y`, without branching.
function coalesce(address x, address y) internal pure returns (address z) {
/// @solidity memory-safe-assembly
assembly {
z := or(x, mul(y, iszero(shl(96, x))))
}
}
/// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.
/// Reverts if the computation overflows.
function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.
if x {
z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`
let half := shr(1, b) // Divide `b` by 2.
// Divide `y` by 2 every iteration.
for { y := shr(1, y) } y { y := shr(1, y) } {
let xx := mul(x, x) // Store x squared.
let xxRound := add(xx, half) // Round to the nearest number.
// Revert if `xx + half` overflowed, or if `x ** 2` overflows.
if or(lt(xxRound, xx), shr(128, x)) {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
x := div(xxRound, b) // Set `x` to scaled `xxRound`.
// If `y` is odd:
if and(y, 1) {
let zx := mul(z, x) // Compute `z * x`.
let zxRound := add(zx, half) // Round to the nearest number.
// If `z * x` overflowed or `zx + half` overflowed:
if or(xor(div(zx, x), z), lt(zxRound, zx)) {
// Revert if `x` is non-zero.
if x {
mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
revert(0x1c, 0x04)
}
}
z := div(zxRound, b) // Return properly scaled `zxRound`.
}
}
}
}
}
/// @dev Returns the square root of `x`, rounded down.
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
// but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffffff, shr(r, x))))
z := shl(shr(1, r), z)
// Goal was to get `z*z*y` within a small factor of `x`. More iterations could
// get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
// We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
// That's not possible if `x < 256` but we can just verify those cases exhaustively.
// Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
// Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
// Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.
// For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
// is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
// with largest error when `s = 1` and when `s = 256` or `1/256`.
// Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
// Then we can estimate `sqrt(y)` using
// `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.
// There is no overflow risk here since `y < 2**136` after the first branch above.
z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If `x+1` is a perfect square, the Babylonian method cycles between
// `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
z := sub(z, lt(div(x, z), z))
}
}
/// @dev Returns the cube root of `x`, rounded down.
/// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
/// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
/// Formally verified by xuwinnie:
/// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf
function cbrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// Makeshift lookup table to nudge the approximate log2 result.
z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))
// Newton-Raphson's.
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
z := div(add(add(div(x, mul(z, z)), z), z), 3)
// Round down.
z := sub(z, lt(div(x, mul(z, z)), z))
}
}
/// @dev Returns the square root of `x`, denominated in `WAD`, rounded down.
function sqrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18);
z = (1 + sqrt(x)) * 10 ** 9;
z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1;
}
/// @solidity memory-safe-assembly
assembly {
z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1))) // Round down.
}
}
/// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down.
/// Formally verified by xuwinnie:
/// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf
function cbrtWad(uint256 x) internal pure returns (uint256 z) {
unchecked {
if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36);
z = (1 + cbrt(x)) * 10 ** 12;
z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3;
}
/// @solidity memory-safe-assembly
assembly {
let p := x
for {} 1 {} {
if iszero(shr(229, p)) {
if iszero(shr(199, p)) {
p := mul(p, 100000000000000000) // 10 ** 17.
break
}
p := mul(p, 100000000) // 10 ** 8.
break
}
if iszero(shr(249, p)) { p := mul(p, 100) }
break
}
let t := mulmod(mul(z, z), z, p)
z := sub(z, gt(lt(t, shr(1, p)), iszero(t))) // Round down.
}
}
/// @dev Returns the factorial of `x`.
function factorial(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := 1
if iszero(lt(x, 58)) {
mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
revert(0x1c, 0x04)
}
for {} x { x := sub(x, 1) } { z := mul(z, x) }
}
}
/// @dev Returns the log2 of `x`.
/// Equivalent to computing the index of the most significant bit (MSB) of `x`.
/// Returns 0 if `x` is zero.
function log2(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(r, shl(3, lt(0xff, shr(r, x))))
// forgefmt: disable-next-item
r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
0x0706060506020504060203020504030106050205030304010505030400000000))
}
}
/// @dev Returns the log2 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log2Up(uint256 x) internal pure returns (uint256 r) {
r = log2(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(r, 1), x))
}
}
/// @dev Returns the log10 of `x`.
/// Returns 0 if `x` is zero.
function log10(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(x, 100000000000000000000000000000000000000)) {
x := div(x, 100000000000000000000000000000000000000)
r := 38
}
if iszero(lt(x, 100000000000000000000)) {
x := div(x, 100000000000000000000)
r := add(r, 20)
}
if iszero(lt(x, 10000000000)) {
x := div(x, 10000000000)
r := add(r, 10)
}
if iszero(lt(x, 100000)) {
x := div(x, 100000)
r := add(r, 5)
}
r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))
}
}
/// @dev Returns the log10 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log10Up(uint256 x) internal pure returns (uint256 r) {
r = log10(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(exp(10, r), x))
}
}
/// @dev Returns the log256 of `x`.
/// Returns 0 if `x` is zero.
function log256(uint256 x) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
r := or(r, shl(4, lt(0xffff, shr(r, x))))
r := or(shr(3, r), lt(0xff, shr(r, x)))
}
}
/// @dev Returns the log256 of `x`, rounded up.
/// Returns 0 if `x` is zero.
function log256Up(uint256 x) internal pure returns (uint256 r) {
r = log256(x);
/// @solidity memory-safe-assembly
assembly {
r := add(r, lt(shl(shl(3, r), 1), x))
}
}
/// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.
/// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).
function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {
/// @solidity memory-safe-assembly
assembly {
mantissa := x
if mantissa {
if iszero(mod(mantissa, 1000000000000000000000000000000000)) {
mantissa := div(mantissa, 1000000000000000000000000000000000)
exponent := 33
}
if iszero(mod(mantissa, 10000000000000000000)) {
mantissa := div(mantissa, 10000000000000000000)
exponent := add(exponent, 19)
}
if iszero(mod(mantissa, 1000000000000)) {
mantissa := div(mantissa, 1000000000000)
exponent := add(exponent, 12)
}
if iszero(mod(mantissa, 1000000)) {
mantissa := div(mantissa, 1000000)
exponent := add(exponent, 6)
}
if iszero(mod(mantissa, 10000)) {
mantissa := div(mantissa, 10000)
exponent := add(exponent, 4)
}
if iszero(mod(mantissa, 100)) {
mantissa := div(mantissa, 100)
exponent := add(exponent, 2)
}
if iszero(mod(mantissa, 10)) {
mantissa := div(mantissa, 10)
exponent := add(exponent, 1)
}
}
}
}
/// @dev Convenience function for packing `x` into a smaller number using `sci`.
/// The `mantissa` will be in bits [7..255] (the upper 249 bits).
/// The `exponent` will be in bits [0..6] (the lower 7 bits).
/// Use `SafeCastLib` to safely ensure that the `packed` number is small
/// enough to fit in the desired unsigned integer type:
/// ```
/// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));
/// ```
function packSci(uint256 x) internal pure returns (uint256 packed) {
(x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.
/// @solidity memory-safe-assembly
assembly {
if shr(249, x) {
mstore(0x00, 0xce30380c) // `MantissaOverflow()`.
revert(0x1c, 0x04)
}
packed := or(shl(7, x), packed)
}
}
/// @dev Convenience function for unpacking a packed number from `packSci`.
function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {
unchecked {
unpacked = (packed >> 7) * 10 ** (packed & 0x7f);
}
}
/// @dev Returns the average of `x` and `y`. Rounds towards zero.
function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = (x & y) + ((x ^ y) >> 1);
}
}
/// @dev Returns the average of `x` and `y`. Rounds towards negative infinity.
function avg(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = (x >> 1) + (y >> 1) + (x & y & 1);
}
}
/// @dev Returns the absolute value of `x`.
function abs(int256 x) internal pure returns (uint256 z) {
unchecked {
z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255);
}
}
/// @dev Returns the absolute distance between `x` and `y`.
function dist(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(xor(sub(0, gt(x, y)), sub(y, x)), gt(x, y))
}
}
/// @dev Returns the absolute distance between `x` and `y`.
function dist(int256 x, int256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := add(xor(sub(0, sgt(x, y)), sub(y, x)), sgt(x, y))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), lt(y, x)))
}
}
/// @dev Returns the minimum of `x` and `y`.
function min(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), slt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), gt(y, x)))
}
}
/// @dev Returns the maximum of `x` and `y`.
function max(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, y), sgt(y, x)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(uint256 x, uint256 minValue, uint256 maxValue)
internal
pure
returns (uint256 z)
{
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), gt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))
}
}
/// @dev Returns `x`, bounded to `minValue` and `maxValue`.
function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))
z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))
}
}
/// @dev Returns greatest common divisor of `x` and `y`.
function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
for { z := x } y {} {
let t := y
y := mod(z, y)
z := t
}
}
}
/// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`,
/// with `t` clamped between `begin` and `end` (inclusive).
/// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
/// If `begins == end`, returns `t <= begin ? a : b`.
function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end)
internal
pure
returns (uint256)
{
if (begin > end) (t, begin, end) = (~t, ~begin, ~end);
if (t <= begin) return a;
if (t >= end) return b;
unchecked {
if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin);
return a - fullMulDiv(a - b, t - begin, end - begin);
}
}
/// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`.
/// with `t` clamped between `begin` and `end` (inclusive).
/// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
/// If `begins == end`, returns `t <= begin ? a : b`.
function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end)
internal
pure
returns (int256)
{
if (begin > end) (t, begin, end) = (~t, ~begin, ~end);
if (t <= begin) return a;
if (t >= end) return b;
// forgefmt: disable-next-item
unchecked {
if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b - a),
uint256(t - begin), uint256(end - begin)));
return int256(uint256(a) - fullMulDiv(uint256(a - b),
uint256(t - begin), uint256(end - begin)));
}
}
/// @dev Returns if `x` is an even number. Some people may need this.
function isEven(uint256 x) internal pure returns (bool) {
return x & uint256(1) == uint256(0);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* RAW NUMBER OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x + y`, without checking for overflow.
function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x + y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x - y`, without checking for underflow.
function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x - y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x * y`, without checking for overflow.
function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
unchecked {
z = x * y;
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := div(x, y)
}
}
/// @dev Returns `x / y`, returning 0 if `y` is zero.
function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := sdiv(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mod(x, y)
}
}
/// @dev Returns `x % y`, returning 0 if `y` is zero.
function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
/// @solidity memory-safe-assembly
assembly {
z := smod(x, y)
}
}
/// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := addmod(x, y, d)
}
}
/// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
z := mulmod(x, y, d)
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
struct CallPoints {
bool beforeInitializePool;
bool afterInitializePool;
bool beforeSwap;
bool afterSwap;
bool beforeUpdatePosition;
bool afterUpdatePosition;
bool beforeCollectFees;
bool afterCollectFees;
}
using {eq, isValid, toUint8} for CallPoints global;
function eq(CallPoints memory a, CallPoints memory b) pure returns (bool) {
return (
a.beforeInitializePool == b.beforeInitializePool && a.afterInitializePool == b.afterInitializePool
&& a.beforeSwap == b.beforeSwap && a.afterSwap == b.afterSwap
&& a.beforeUpdatePosition == b.beforeUpdatePosition && a.afterUpdatePosition == b.afterUpdatePosition
&& a.beforeCollectFees == b.beforeCollectFees && a.afterCollectFees == b.afterCollectFees
);
}
function isValid(CallPoints memory a) pure returns (bool) {
return (
a.beforeInitializePool || a.afterInitializePool || a.beforeSwap || a.afterSwap || a.beforeUpdatePosition
|| a.afterUpdatePosition || a.beforeCollectFees || a.afterCollectFees
);
}
function toUint8(CallPoints memory callPoints) pure returns (uint8 b) {
assembly ("memory-safe") {
b :=
add(
add(
add(
add(
add(
add(
add(mload(callPoints), mul(128, mload(add(callPoints, 32)))),
mul(64, mload(add(callPoints, 64)))
),
mul(32, mload(add(callPoints, 96)))
),
mul(16, mload(add(callPoints, 128)))
),
mul(8, mload(add(callPoints, 160)))
),
mul(4, mload(add(callPoints, 192)))
),
mul(2, mload(add(callPoints, 224)))
)
}
}
function addressToCallPoints(address a) pure returns (CallPoints memory result) {
result = byteToCallPoints(uint8(uint160(a) >> 152));
}
function byteToCallPoints(uint8 b) pure returns (CallPoints memory result) {
// note the order of bytes does not match the struct order of elements because we are matching the cairo implementation
// which for legacy reasons has the fields in this order
result = CallPoints({
beforeInitializePool: (b & 1) != 0,
afterInitializePool: (b & 128) != 0,
beforeSwap: (b & 64) != 0,
afterSwap: (b & 32) != 0,
beforeUpdatePosition: (b & 16) != 0,
afterUpdatePosition: (b & 8) != 0,
beforeCollectFees: (b & 4) != 0,
afterCollectFees: (b & 2) != 0
});
}
function shouldCallBeforeInitializePool(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(152, a), 1)
}
}
function shouldCallAfterInitializePool(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(159, a), 1)
}
}
function shouldCallBeforeSwap(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(158, a), 1)
}
}
function shouldCallAfterSwap(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(157, a), 1)
}
}
function shouldCallBeforeUpdatePosition(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(156, a), 1)
}
}
function shouldCallAfterUpdatePosition(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(155, a), 1)
}
}
function shouldCallBeforeCollectFees(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(154, a), 1)
}
}
function shouldCallAfterCollectFees(address a) pure returns (bool yes) {
assembly ("memory-safe") {
yes := and(shr(153, a), 1)
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {MIN_TICK, MAX_TICK, FULL_RANGE_ONLY_TICK_SPACING} from "../math/constants.sol";
using {toPositionId} for PositionKey global;
using {validateBounds} for Bounds global;
// Bounds are lower and upper prices for which a position is active
struct Bounds {
int32 lower;
int32 upper;
}
error BoundsOrder();
error MinMaxBounds();
error BoundsTickSpacing();
error FullRangeOnlyPool();
function validateBounds(Bounds memory bounds, uint32 tickSpacing) pure {
if (tickSpacing == FULL_RANGE_ONLY_TICK_SPACING) {
if (bounds.lower != MIN_TICK || bounds.upper != MAX_TICK) revert FullRangeOnlyPool();
} else {
if (bounds.lower >= bounds.upper) revert BoundsOrder();
if (bounds.lower < MIN_TICK || bounds.upper > MAX_TICK) revert MinMaxBounds();
int32 spacing = int32(tickSpacing);
if (bounds.lower % spacing != 0 || bounds.upper % spacing != 0) revert BoundsTickSpacing();
}
}
// A position is keyed by the pool and this position key
struct PositionKey {
bytes32 salt;
address owner;
Bounds bounds;
}
function toPositionId(PositionKey memory key) pure returns (bytes32 result) {
assembly ("memory-safe") {
// salt and owner
mstore(0, keccak256(key, 64))
// bounds
mstore(32, keccak256(mload(add(key, 64)), 64))
result := keccak256(0, 64)
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
// The total fees per liquidity for each token.
// Since these are always read together we put them in a struct, even though they cannot be packed.
struct FeesPerLiquidity {
uint256 value0;
uint256 value1;
}
using {sub} for FeesPerLiquidity global;
function sub(FeesPerLiquidity memory a, FeesPerLiquidity memory b) pure returns (FeesPerLiquidity memory result) {
assembly ("memory-safe") {
mstore(result, sub(mload(a), mload(b)))
mstore(add(result, 32), sub(mload(add(a, 32)), mload(add(b, 32))))
}
}
function feesPerLiquidityFromAmounts(uint128 amount0, uint128 amount1, uint128 liquidity)
pure
returns (FeesPerLiquidity memory result)
{
assembly ("memory-safe") {
mstore(result, div(shl(128, amount0), liquidity))
mstore(add(result, 32), div(shl(128, amount1), liquidity))
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
// Exposes all the storage of a contract via view methods.
// Absent https://eips.ethereum.org/EIPS/eip-2330 this makes it easier to access specific pieces of state in the inheriting contract.
interface IExposedStorage {
// Loads each slot after the function selector from the contract's storage and returns all of them.
function sload() external view;
// Loads each slot after the function selector from the contract's transient storage and returns all of them.
function tload() external view;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {IExposedStorage} from "../interfaces/IExposedStorage.sol";
/// @dev This library includes some helper functions for calling IExposedStorage#sload and IExposedStorage#tload.
library ExposedStorageLib {
function sload(IExposedStorage target, bytes32 slot) internal view returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0, shl(224, 0x380eb4e0))
mstore(4, slot)
if iszero(staticcall(gas(), target, 0, 36, 0, 32)) { revert(0, 0) }
result := mload(0)
}
}
function sload(IExposedStorage target, bytes32 slot0, bytes32 slot1, bytes32 slot2)
internal
view
returns (bytes32 result0, bytes32 result1, bytes32 result2)
{
assembly ("memory-safe") {
let o := mload(0x40)
mstore(o, shl(224, 0x380eb4e0))
mstore(add(o, 4), slot0)
mstore(add(o, 36), slot1)
mstore(add(o, 68), slot2)
if iszero(staticcall(gas(), target, o, 100, o, 96)) { revert(0, 0) }
result0 := mload(o)
result1 := mload(add(o, 32))
result2 := mload(add(o, 64))
}
}
function tload(IExposedStorage target, bytes32 slot) internal view returns (bytes32 result) {
assembly ("memory-safe") {
mstore(0, shl(224, 0xed832830))
mstore(4, slot)
if iszero(staticcall(gas(), target, 0, 36, 0, 32)) { revert(0, 0) }
result := mload(0)
}
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;
import {FeesPerLiquidity} from "./feesPerLiquidity.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
struct Position {
uint128 liquidity;
FeesPerLiquidity feesPerLiquidityInsideLast;
}
using {fees} for Position global;
/// @dev Returns the fee amounts of token0 and token1 owed to a position based on the given fees per liquidity inside snapshot
/// Note if the computed fees overflows the uint128 type, it will return only the lower 128 bits. It is assumed that accumulated
/// fees will never exceed type(uint128).max.
function fees(Position memory position, FeesPerLiquidity memory feesPerLiquidityInside)
pure
returns (uint128, uint128)
{
FeesPerLiquidity memory difference = feesPerLiquidityInside.sub(position.feesPerLiquidityInsideLast);
return (
uint128(FixedPointMathLib.fullMulDivN(difference.value0, position.liquidity, 128)),
uint128(FixedPointMathLib.fullMulDivN(difference.value1, position.liquidity, 128))
);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Library for efficiently performing keccak256 hashes.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/EfficientHashLib.sol)
/// @dev To avoid stack-too-deep, you can use:
/// ```
/// bytes32[] memory buffer = EfficientHashLib.malloc(10);
/// EfficientHashLib.set(buffer, 0, value0);
/// ..
/// EfficientHashLib.set(buffer, 9, value9);
/// bytes32 finalHash = EfficientHashLib.hash(buffer);
/// ```
library EfficientHashLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* MALLOC-LESS HASHING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `keccak256(abi.encode(v0))`.
function hash(bytes32 v0) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, v0)
result := keccak256(0x00, 0x20)
}
}
/// @dev Returns `keccak256(abi.encode(v0))`.
function hash(uint256 v0) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, v0)
result := keccak256(0x00, 0x20)
}
}
/// @dev Returns `keccak256(abi.encode(v0, v1))`.
function hash(bytes32 v0, bytes32 v1) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, v0)
mstore(0x20, v1)
result := keccak256(0x00, 0x40)
}
}
/// @dev Returns `keccak256(abi.encode(v0, v1))`.
function hash(uint256 v0, uint256 v1) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, v0)
mstore(0x20, v1)
result := keccak256(0x00, 0x40)
}
}
/// @dev Returns `keccak256(abi.encode(v0, v1, v2))`.
function hash(bytes32 v0, bytes32 v1, bytes32 v2) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
result := keccak256(m, 0x60)
}
}
/// @dev Returns `keccak256(abi.encode(v0, v1, v2))`.
function hash(uint256 v0, uint256 v1, uint256 v2) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
result := keccak256(m, 0x60)
}
}
/// @dev Returns `keccak256(abi.encode(v0, v1, v2, v3))`.
function hash(bytes32 v0, bytes32 v1, bytes32 v2, bytes32 v3)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
result := keccak256(m, 0x80)
}
}
/// @dev Returns `keccak256(abi.encode(v0, v1, v2, v3))`.
function hash(uint256 v0, uint256 v1, uint256 v2, uint256 v3)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
result := keccak256(m, 0x80)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v4))`.
function hash(bytes32 v0, bytes32 v1, bytes32 v2, bytes32 v3, bytes32 v4)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
result := keccak256(m, 0xa0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v4))`.
function hash(uint256 v0, uint256 v1, uint256 v2, uint256 v3, uint256 v4)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
result := keccak256(m, 0xa0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v5))`.
function hash(bytes32 v0, bytes32 v1, bytes32 v2, bytes32 v3, bytes32 v4, bytes32 v5)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
result := keccak256(m, 0xc0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v5))`.
function hash(uint256 v0, uint256 v1, uint256 v2, uint256 v3, uint256 v4, uint256 v5)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
result := keccak256(m, 0xc0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v6))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
result := keccak256(m, 0xe0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v6))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
result := keccak256(m, 0xe0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v7))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6,
bytes32 v7
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
result := keccak256(m, 0x100)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v7))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6,
uint256 v7
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
result := keccak256(m, 0x100)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v8))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6,
bytes32 v7,
bytes32 v8
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
result := keccak256(m, 0x120)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v8))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6,
uint256 v7,
uint256 v8
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
result := keccak256(m, 0x120)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v9))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6,
bytes32 v7,
bytes32 v8,
bytes32 v9
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
result := keccak256(m, 0x140)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v9))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6,
uint256 v7,
uint256 v8,
uint256 v9
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
result := keccak256(m, 0x140)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v10))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6,
bytes32 v7,
bytes32 v8,
bytes32 v9,
bytes32 v10
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
result := keccak256(m, 0x160)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v10))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6,
uint256 v7,
uint256 v8,
uint256 v9,
uint256 v10
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
result := keccak256(m, 0x160)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v11))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6,
bytes32 v7,
bytes32 v8,
bytes32 v9,
bytes32 v10,
bytes32 v11
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
mstore(add(m, 0x160), v11)
result := keccak256(m, 0x180)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v11))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6,
uint256 v7,
uint256 v8,
uint256 v9,
uint256 v10,
uint256 v11
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
mstore(add(m, 0x160), v11)
result := keccak256(m, 0x180)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v12))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6,
bytes32 v7,
bytes32 v8,
bytes32 v9,
bytes32 v10,
bytes32 v11,
bytes32 v12
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
mstore(add(m, 0x160), v11)
mstore(add(m, 0x180), v12)
result := keccak256(m, 0x1a0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v12))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6,
uint256 v7,
uint256 v8,
uint256 v9,
uint256 v10,
uint256 v11,
uint256 v12
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
mstore(add(m, 0x160), v11)
mstore(add(m, 0x180), v12)
result := keccak256(m, 0x1a0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v13))`.
function hash(
bytes32 v0,
bytes32 v1,
bytes32 v2,
bytes32 v3,
bytes32 v4,
bytes32 v5,
bytes32 v6,
bytes32 v7,
bytes32 v8,
bytes32 v9,
bytes32 v10,
bytes32 v11,
bytes32 v12,
bytes32 v13
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
mstore(add(m, 0x160), v11)
mstore(add(m, 0x180), v12)
mstore(add(m, 0x1a0), v13)
result := keccak256(m, 0x1c0)
}
}
/// @dev Returns `keccak256(abi.encode(v0, .., v13))`.
function hash(
uint256 v0,
uint256 v1,
uint256 v2,
uint256 v3,
uint256 v4,
uint256 v5,
uint256 v6,
uint256 v7,
uint256 v8,
uint256 v9,
uint256 v10,
uint256 v11,
uint256 v12,
uint256 v13
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, v0)
mstore(add(m, 0x20), v1)
mstore(add(m, 0x40), v2)
mstore(add(m, 0x60), v3)
mstore(add(m, 0x80), v4)
mstore(add(m, 0xa0), v5)
mstore(add(m, 0xc0), v6)
mstore(add(m, 0xe0), v7)
mstore(add(m, 0x100), v8)
mstore(add(m, 0x120), v9)
mstore(add(m, 0x140), v10)
mstore(add(m, 0x160), v11)
mstore(add(m, 0x180), v12)
mstore(add(m, 0x1a0), v13)
result := keccak256(m, 0x1c0)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* BYTES32 BUFFER HASHING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `keccak256(abi.encode(buffer[0], .., buffer[buffer.length - 1]))`.
function hash(bytes32[] memory buffer) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := keccak256(add(buffer, 0x20), shl(5, mload(buffer)))
}
}
/// @dev Sets `buffer[i]` to `value`, without a bounds check.
/// Returns the `buffer` for function chaining.
function set(bytes32[] memory buffer, uint256 i, bytes32 value)
internal
pure
returns (bytes32[] memory)
{
/// @solidity memory-safe-assembly
assembly {
mstore(add(buffer, shl(5, add(1, i))), value)
}
return buffer;
}
/// @dev Sets `buffer[i]` to `value`, without a bounds check.
/// Returns the `buffer` for function chaining.
function set(bytes32[] memory buffer, uint256 i, uint256 value)
internal
pure
returns (bytes32[] memory)
{
/// @solidity memory-safe-assembly
assembly {
mstore(add(buffer, shl(5, add(1, i))), value)
}
return buffer;
}
/// @dev Returns `new bytes32[](n)`, without zeroing out the memory.
function malloc(uint256 n) internal pure returns (bytes32[] memory buffer) {
/// @solidity memory-safe-assembly
assembly {
buffer := mload(0x40)
mstore(buffer, n)
mstore(0x40, add(shl(5, add(1, n)), buffer))
}
}
/// @dev Frees memory that has been allocated for `buffer`.
/// No-op if `buffer.length` is zero, or if new memory has been allocated after `buffer`.
function free(bytes32[] memory buffer) internal pure {
/// @solidity memory-safe-assembly
assembly {
let n := mload(buffer)
mstore(shl(6, lt(iszero(n), eq(add(shl(5, add(1, n)), buffer), mload(0x40)))), buffer)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EQUALITY CHECKS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `a == abi.decode(b, (bytes32))`.
function eq(bytes32 a, bytes memory b) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := and(eq(0x20, mload(b)), eq(a, mload(add(b, 0x20))))
}
}
/// @dev Returns `abi.decode(a, (bytes32)) == a`.
function eq(bytes memory a, bytes32 b) internal pure returns (bool result) {
/// @solidity memory-safe-assembly
assembly {
result := and(eq(0x20, mload(a)), eq(b, mload(add(a, 0x20))))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* BYTE SLICE HASHING OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the keccak256 of the slice from `start` to `end` (exclusive).
/// `start` and `end` are byte offsets.
function hash(bytes memory b, uint256 start, uint256 end)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(b)
end := xor(end, mul(xor(end, n), lt(n, end)))
start := xor(start, mul(xor(start, n), lt(n, start)))
result := keccak256(add(add(b, 0x20), start), mul(gt(end, start), sub(end, start)))
}
}
/// @dev Returns the keccak256 of the slice from `start` to the end of the bytes.
function hash(bytes memory b, uint256 start) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(b)
start := xor(start, mul(xor(start, n), lt(n, start)))
result := keccak256(add(add(b, 0x20), start), mul(gt(n, start), sub(n, start)))
}
}
/// @dev Returns the keccak256 of the bytes.
function hash(bytes memory b) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := keccak256(add(b, 0x20), mload(b))
}
}
/// @dev Returns the keccak256 of the slice from `start` to `end` (exclusive).
/// `start` and `end` are byte offsets.
function hashCalldata(bytes calldata b, uint256 start, uint256 end)
internal
pure
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
end := xor(end, mul(xor(end, b.length), lt(b.length, end)))
start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
let n := mul(gt(end, start), sub(end, start))
calldatacopy(mload(0x40), add(b.offset, start), n)
result := keccak256(mload(0x40), n)
}
}
/// @dev Returns the keccak256 of the slice from `start` to the end of the bytes.
function hashCalldata(bytes calldata b, uint256 start) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
let n := mul(gt(b.length, start), sub(b.length, start))
calldatacopy(mload(0x40), add(b.offset, start), n)
result := keccak256(mload(0x40), n)
}
}
/// @dev Returns the keccak256 of the bytes.
function hashCalldata(bytes calldata b) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
calldatacopy(mload(0x40), b.offset, b.length)
result := keccak256(mload(0x40), b.length)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* SHA2-256 HELPERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns `sha256(abi.encode(b))`. Yes, it's more efficient.
function sha2(bytes32 b) internal view returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, b)
result := mload(staticcall(gas(), 2, 0x00, 0x20, 0x01, 0x20))
if iszero(returndatasize()) { invalid() }
}
}
/// @dev Returns the sha256 of the slice from `start` to `end` (exclusive).
/// `start` and `end` are byte offsets.
function sha2(bytes memory b, uint256 start, uint256 end)
internal
view
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
let n := mload(b)
end := xor(end, mul(xor(end, n), lt(n, end)))
start := xor(start, mul(xor(start, n), lt(n, start)))
// forgefmt: disable-next-item
result := mload(staticcall(gas(), 2, add(add(b, 0x20), start),
mul(gt(end, start), sub(end, start)), 0x01, 0x20))
if iszero(returndatasize()) { invalid() }
}
}
/// @dev Returns the sha256 of the slice from `start` to the end of the bytes.
function sha2(bytes memory b, uint256 start) internal view returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
let n := mload(b)
start := xor(start, mul(xor(start, n), lt(n, start)))
// forgefmt: disable-next-item
result := mload(staticcall(gas(), 2, add(add(b, 0x20), start),
mul(gt(n, start), sub(n, start)), 0x01, 0x20))
if iszero(returndatasize()) { invalid() }
}
}
/// @dev Returns the sha256 of the bytes.
function sha2(bytes memory b) internal view returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
result := mload(staticcall(gas(), 2, add(b, 0x20), mload(b), 0x01, 0x20))
if iszero(returndatasize()) { invalid() }
}
}
/// @dev Returns the sha256 of the slice from `start` to `end` (exclusive).
/// `start` and `end` are byte offsets.
function sha2Calldata(bytes calldata b, uint256 start, uint256 end)
internal
view
returns (bytes32 result)
{
/// @solidity memory-safe-assembly
assembly {
end := xor(end, mul(xor(end, b.length), lt(b.length, end)))
start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
let n := mul(gt(end, start), sub(end, start))
calldatacopy(mload(0x40), add(b.offset, start), n)
result := mload(staticcall(gas(), 2, mload(0x40), n, 0x01, 0x20))
if iszero(returndatasize()) { invalid() }
}
}
/// @dev Returns the sha256 of the slice from `start` to the end of the bytes.
function sha2Calldata(bytes calldata b, uint256 start) internal view returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
let n := mul(gt(b.length, start), sub(b.length, start))
calldatacopy(mload(0x40), add(b.offset, start), n)
result := mload(staticcall(gas(), 2, mload(0x40), n, 0x01, 0x20))
if iszero(returndatasize()) { invalid() }
}
}
/// @dev Returns the sha256 of the bytes.
function sha2Calldata(bytes calldata b) internal view returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
calldatacopy(mload(0x40), b.offset, b.length)
result := mload(staticcall(gas(), 2, mload(0x40), b.length, 0x01, 0x20))
if iszero(returndatasize()) { invalid() }
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Contract that enables a single call to call multiple methods on itself.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Multicallable.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/Multicallable.sol)
///
/// WARNING:
/// This implementation is NOT to be used with ERC2771 out-of-the-box.
/// https://blog.openzeppelin.com/arbitrary-address-spoofing-vulnerability-erc2771context-multicall-public-disclosure
/// This also applies to potentially other ERCs / patterns appending to the back of calldata.
///
/// We do NOT have a check for ERC2771, as we do not inherit from OpenZeppelin's context.
/// Moreover, it is infeasible and inefficient for us to add checks and mitigations
/// for all possible ERC / patterns appending to the back of calldata.
///
/// We would highly recommend using an alternative pattern such as
/// https://github.com/Vectorized/multicaller
/// which is more flexible, futureproof, and safer by default.
abstract contract Multicallable {
/// @dev Apply `delegatecall` with the current contract to each calldata in `data`,
/// and store the `abi.encode` formatted results of each `delegatecall` into `results`.
/// If any of the `delegatecall`s reverts, the entire context is reverted,
/// and the error is bubbled up.
///
/// By default, this function directly returns the results and terminates the call context.
/// If you need to add before and after actions to the multicall, please override this function.
function multicall(bytes[] calldata data) public payable virtual returns (bytes[] memory) {
// Revert if `msg.value` is non-zero by default to guard against double-spending.
// (See: https://www.paradigm.xyz/2021/08/two-rights-might-make-a-wrong)
//
// If you really need to pass in a `msg.value`, then you will have to
// override this function and add in any relevant before and after checks.
if (msg.value != 0) revert();
// `_multicallDirectReturn` returns the results directly and terminates the call context.
_multicallDirectReturn(_multicall(data));
}
/// @dev The inner logic of `multicall`.
/// This function is included so that you can override `multicall`
/// to add before and after actions, and use the `_multicallDirectReturn` function.
function _multicall(bytes[] calldata data) internal virtual returns (bytes32 results) {
/// @solidity memory-safe-assembly
assembly {
results := mload(0x40)
mstore(results, 0x20)
mstore(add(0x20, results), data.length)
let c := add(0x40, results)
let s := c
let end := shl(5, data.length)
calldatacopy(c, data.offset, end)
end := add(c, end)
let m := end
if data.length {
for {} 1 {} {
let o := add(data.offset, mload(c))
calldatacopy(m, add(o, 0x20), calldataload(o))
// forgefmt: disable-next-item
if iszero(delegatecall(gas(), address(), m, calldataload(o), codesize(), 0x00)) {
// Bubble up the revert if the delegatecall reverts.
returndatacopy(results, 0x00, returndatasize())
revert(results, returndatasize())
}
mstore(c, sub(m, s))
c := add(0x20, c)
// Append the `returndatasize()`, and the return data.
mstore(m, returndatasize())
let b := add(m, 0x20)
returndatacopy(b, 0x00, returndatasize())
// Advance `m` by `returndatasize() + 0x20`,
// rounded up to the next multiple of 32.
m := and(add(add(b, returndatasize()), 0x1f), 0xffffffffffffffe0)
mstore(add(b, returndatasize()), 0) // Zeroize the slot after the returndata.
if iszero(lt(c, end)) { break }
}
}
mstore(0x40, m) // Allocate memory.
results := or(shl(64, sub(m, results)), results) // Pack the bytes length into `results`.
}
}
/// @dev Decodes the `results` into an array of bytes.
/// This can be useful if you need to access the results or re-encode it.
function _multicallResultsToBytesArray(bytes32 results)
internal
pure
virtual
returns (bytes[] memory decoded)
{
/// @solidity memory-safe-assembly
assembly {
decoded := mload(0x40)
let c := and(0xffffffffffffffff, results) // Extract the offset.
mstore(decoded, mload(add(c, 0x20))) // Store the length.
let o := add(decoded, 0x20) // Start of elements in `decoded`.
let end := add(o, shl(5, mload(decoded)))
mstore(0x40, end) // Allocate memory.
let s := add(c, 0x40) // Start of elements in `results`.
let d := sub(s, o) // Difference between input and output pointers.
for {} iszero(eq(o, end)) { o := add(o, 0x20) } { mstore(o, add(mload(add(d, o)), s)) }
}
}
/// @dev Directly returns the `results` and terminates the current call context.
/// `results` must be from `_multicall`, else behavior is undefined.
function _multicallDirectReturn(bytes32 results) internal pure virtual {
/// @solidity memory-safe-assembly
assembly {
return(and(0xffffffffffffffff, results), shr(64, results))
}
}
}{
"remappings": [
"forge-std/=lib/forge-std/src/",
"solady/=lib/solady/src/"
],
"optimizer": {
"enabled": true,
"runs": 9999999
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": true,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract ICore","name":"core","type":"address"},{"internalType":"address","name":"_mevResist","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BaseLockerAccountantOnly","type":"error"},{"inputs":[],"name":"CoreOnly","type":"error"},{"inputs":[],"name":"ExpectedRevertWithinLock","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"maximumInput","type":"uint256"}],"name":"MaximumInputExceeded","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"minimumOutput","type":"uint256"}],"name":"MinimumOutputNotReceived","type":"error"},{"inputs":[],"name":"PartialSwapsDisallowed","type":"error"},{"inputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"name":"QuoteReturnValue","type":"error"},{"inputs":[{"internalType":"int256","name":"expectedAmount","type":"int256"},{"internalType":"int256","name":"calculatedAmount","type":"int256"}],"name":"SlippageCheckFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"TokensMismatch","type":"error"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"TransactionExpired","type":"error"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"checkDeadline","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"maximumInput","type":"uint256"}],"name":"checkMaximumInputNotExceeded","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"minimumOutput","type":"uint256"}],"name":"checkMinimumOutputReceived","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"locked","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"mevResist","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"internalType":"struct RouteNode[]","name":"route","type":"tuple[]"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"int128","name":"amount","type":"int128"}],"internalType":"struct TokenAmount","name":"tokenAmount","type":"tuple"}],"internalType":"struct Swap[]","name":"swaps","type":"tuple[]"},{"internalType":"int256","name":"calculatedAmountThreshold","type":"int256"}],"name":"multiMultihopSwap","outputs":[{"components":[{"internalType":"int128","name":"amount0","type":"int128"},{"internalType":"int128","name":"amount1","type":"int128"}],"internalType":"struct Delta[][]","name":"results","type":"tuple[][]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"internalType":"struct RouteNode[]","name":"route","type":"tuple[]"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"int128","name":"amount","type":"int128"}],"internalType":"struct TokenAmount","name":"tokenAmount","type":"tuple"}],"internalType":"struct Swap","name":"s","type":"tuple"},{"internalType":"int256","name":"calculatedAmountThreshold","type":"int256"}],"name":"multihopSwap","outputs":[{"components":[{"internalType":"int128","name":"amount0","type":"int128"},{"internalType":"int128","name":"amount1","type":"int128"}],"internalType":"struct Delta[]","name":"result","type":"tuple[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"token","type":"address"}],"name":"payCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"bool","name":"isToken1","type":"bool"},{"internalType":"int128","name":"amount","type":"int128"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"name":"quote","outputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"recordBalanceForSlippageCheck","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"refundNativeToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"bool","name":"isToken1","type":"bool"},{"internalType":"int128","name":"amount","type":"int128"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"name":"swap","outputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"bool","name":"isToken1","type":"bool"},{"internalType":"int128","name":"amount","type":"int128"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"},{"internalType":"int256","name":"calculatedAmountThreshold","type":"int256"}],"name":"swap","outputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"internalType":"struct RouteNode","name":"node","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"int128","name":"amount","type":"int128"}],"internalType":"struct TokenAmount","name":"tokenAmount","type":"tuple"},{"internalType":"int256","name":"calculatedAmountThreshold","type":"int256"}],"name":"swap","outputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"bool","name":"isToken1","type":"bool"},{"internalType":"int128","name":"amount","type":"int128"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"},{"internalType":"int256","name":"calculatedAmountThreshold","type":"int256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"swap","outputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"stateMutability":"payable","type":"function"}]Contract Creation Code
60e0346100e757601f61305238819003918201601f19168301916001600160401b038311848410176100eb5780849260409485528339810103126100e7578051906001600160a01b038216908183036100e75760200151916001600160a01b03831683036100e75760805260a05260c052604051612f52908161010082396080518181816107f201528181610b270152612c3a015260a05181818161055801528181611a4c01528181611d4f0152818161289c01528181612cf901528181612dab01528181612e250152612e83015260c05181818161077901528181611bb00152612bc50152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffdfe60806040526004361015610011575f80fd5b5f5f3560e01c806306b81a1514611ff65780630a52f5f114611f235780631d8a796214611ec457806327c3a09014611e565780633bc5284214611c105780634186527014611bd457806346745c4514611b66578063599d0714146119e55780636d0cb613146118d75780637ac2ff7b1461166f578063a69909461461160e578063ac4563de14611539578063ac9650d8146113f4578063b45a3c0e14610512578063cb787803146103e5578063d4fdd7ea1461017a5763f196187f146100d5575f80fd5b6101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610177576101093661219e565b610111612267565b9061011a612276565b91610123612286565b91610104359273ffffffffffffffffffffffffffffffffffffffff84168403610175576101579460e4359360c43593612717565b60408051600f93840b81529190920b602082015290819081015b0390f35b5f5b80fd5b5060407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101775760043567ffffffffffffffff811161035c573660238201121561035c5780600401356101d081612311565b916101de6040519384612119565b818352602083019160051b8101602401823682116103e15760248301905b8282106103ad57505050506040519160a08301907f02000000000000000000000000000000000000000000000000000000000000006020850152336040850152608060608501525180915260c083019060c08160051b850101929185905b82821061036457866102a48761029f81896024356080830152037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612119565b61284a565b90815182019160208181850194031261035c5760208101519067ffffffffffffffff8211610360570182603f8201121561035c5760208101516102e681612311565b926102f46040519485612119565b8184526020808086019360051b850101019285841161035c5760408101925b848410610328576040518061017188826124b9565b835167ffffffffffffffff81116103585760209161034d898480809588010101612665565b815201930192610313565b8380fd5b5080fd5b8280fd5b9091929360208061039f837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff408a60019603018652885161257f565b96019201920190929161025a565b813567ffffffffffffffff81116103dd576020916103d2839260243691890101612329565b8152019101906101fc565b8780fd5b8580fd5b507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601610100811261035c5760a01361017557604051610425816120fd565b610430366004612227565b81526064356bffffffffffffffffffffffff8116810361017557602082019081526040820190608435825260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5c3601126101755760405190610492826120e1565b60a43573ffffffffffffffffffffffffffffffffffffffff8116810361017557825260c4359283600f0b8403610175576bffffffffffffffffffffffff6101579560208501958652519373ffffffffffffffffffffffffffffffffffffffff80602087015116915116149451600f0b925116905191339460e43594612717565b346101755760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755773ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168033036113cc5736602411610175577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc36019067ffffffffffffffff821161139f5760405161060e60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb3601160182612119565b8281526020810192602484375f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc368301015260608151156113725783517fff00000000000000000000000000000000000000000000000000000000000000169081610b845750508051810192610160828503126101755761068f90612903565b506106ac60206106a160408401612930565b940160608301612951565b6106b860c08301612991565b936106c560e08401612657565b946106d3610100850161299e565b610120850151918773ffffffffffffffffffffffffffffffffffffffff806107046101606101408b01519a01612930565b9616951693821580610b65575b80610b59575b156fffffffffffffffffffffffffffffffff83169081028082189590919080155f86128088186bffff9a5889f795069a41a8a30290881467400065a8177fae27020102019a73ffffffffffffffffffffffffffffffffffffffff8a60340151167f00000000000000000000000000000000000000000000000000000000000000009073ffffffffffffffffffffffffffffffffffffffff821614155f14610a2d57505050506040916107d8849284519b8c9485945f86528c60048701612b28565b03818573ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af18015610a22575f975f916109ed575b5096955b81156109e257865f03600f0b5b600f0b908082126109b45750505f6108f2979812185f146108fa575060208361088e73ffffffffffffffffffffffffffffffffffffffff93846108aa975116885f036fffffffffffffffffffffffffffffffff1690612e4f565b0151166fffffffffffffffffffffffffffffffff861691612d66565b60408051600f92830b60208201529390910b9083015281606081015b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612119565b602081519101f35b906109359073ffffffffffffffffffffffffffffffffffffffff602086015116885f036fffffffffffffffffffffffffffffffff1690612e4f565b6fffffffffffffffffffffffffffffffff841681811161099057506fffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff61098b94511691818681169116031690612e4f565b6108aa565b91905073ffffffffffffffffffffffffffffffffffffffff61098b93511690612d66565b7fd395b706000000000000000000000000000000000000000000000000000000005f5260045260245260445ffd5b875f03600f0b610834565b9050610a1291975060403d604011610a1b575b610a0a8183612119565b8101906126f3565b96909689610823565b503d610a00565b6040513d5f823e3d90fd5b5f8b610a7d82969f9883969f998b99610a51916040519b8c94602086019788612b28565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101895288612119565b6040519687937f101e89520000000000000000000000000000000000000000000000000000000085526004850152518091602485015e602401925af115610b51573d8152610b04906020808201913d5f843e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d8301011660405280510101906126f3565b9890971461082757610b4c8373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001661282e565b610827565b3d5f823e3d90fd5b505f82600f0b13610717565b5073ffffffffffffffffffffffffffffffffffffffff87511615610711565b91937f0100000000000000000000000000000000000000000000000000000000000000821493509190838015611349575b156112855750821561119d57610bc9612adb565b50835184019160808584031261017557610be290612903565b50610bef60408501612930565b918185015167ffffffffffffffff811161017557610c2c60809160208073ffffffffffffffffffffffffffffffffffffffff9501918901016129b7565b950151921692604051610c40604082612119565b6001815260205f5b81811061118657505080610c669196610c6082612b07565b52612b07565b509392915b8351917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610cb1610c9b85612311565b94610ca96040519687612119565b808652612311565b01905f5b828110611176575050505f905f5f5f915f965b885188101561106357610cdb888a612b14565b51988951517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610d23610d0d83612311565b92610d1b6040519485612119565b808452612311565b015f5b818110611040575050610d398a8a612b14565b52610d448989612b14565b5060208a01958651936020850151600f0b01915f945b8c518051871015610f415786610d6f91612b14565b519073ffffffffffffffffffffffffffffffffffffffff8151169082519073ffffffffffffffffffffffffffffffffffffffff602083015116831480938115610f20575b5015610175578d918f610e186bffffffffffffffffffffffff602088015116928680610e0c60208801968751600f0b93845f6bffff9a5889f795069a41a8a3911267400065a8177fae2781841402921802018115020190565b9160408b015193612ba5565b929095610e588d604051610e2b816120e1565b610e468a600f0b9687835288600f0b9a8b6020850152612b14565b5190610e528383612b14565b52612b14565b5015610ed35750505060200151600f0b03610eab5773ffffffffffffffffffffffffffffffffffffffff6001925151169060405191610e96836120e1565b82525f03600f0b6020820152955b0194610d5a565b7fe3648855000000000000000000000000000000000000000000000000000000005f5260045ffd5b92509250925051600f0b03610eab5773ffffffffffffffffffffffffffffffffffffffff6020600193510151169060405191610f0e836120e1565b82525f03600f0b602082015295610ea4565b905073ffffffffffffffffffffffffffffffffffffffff835116145f610db3565b509793945095919b949790999a506020870151600f0b01968a155f14610f9257505073ffffffffffffffffffffffffffffffffffffffff80600192515116955116985b019693919890979297610cc8565b9590999173ffffffffffffffffffffffffffffffffffffffff9051511673ffffffffffffffffffffffffffffffffffffffff87161490811591611008575b50610fdd57600190610f84565b7f658e3c95000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b73ffffffffffffffffffffffffffffffffffffffff9150511673ffffffffffffffffffffffffffffffffffffffff8a1614158b610fd0565b60209060405161104f816120e1565b5f81525f8382015282828601015201610d26565b95989750929091939550808612611146575083905f831215611123576fffffffffffffffffffffffffffffffff61109d935f031690612e4f565b5f831315611100576fffffffffffffffffffffffffffffffff6110c1931690612e4f565b156110ea576110e56110d56108c692612b07565b5160405192839160208301612464565b6108f2565b6110e56108c691604051928391602083016124b9565b6fffffffffffffffffffffffffffffffff61111e935f031691612d66565b6110c1565b611141926fffffffffffffffffffffffffffffffff16915084612d66565b61109d565b85907fd395b706000000000000000000000000000000000000000000000000000000005f5260045260245260445ffd5b6020818601810183905201610cb5565b602090611191612adb565b82828601015201610c48565b835184019160808560208501940312610175576111b990612903565b506111c660408501612930565b938181015167ffffffffffffffff81116101755781019280603f850112156101755760208401516111f681612311565b946112046040519687612119565b8186526020808088019360051b83010101918383116101755760408201905b838210611255575050505050608073ffffffffffffffffffffffffffffffffffffffff91015192941691939293610c6b565b815167ffffffffffffffff81116101755760209161127a8784808095890101016129b7565b815201910190611223565b7f03000000000000000000000000000000000000000000000000000000000000009194929350146112b75750506108f2565b80518101610100828203126101755760206112e3916112d861131495612903565b500160408301612951565b906112f060a08201612991565b6112fc60c08301612657565b61010061130b60e0850161299e565b93015193612ba5565b907fcacd6cb3000000000000000000000000000000000000000000000000000000005f52600f0b600452600f0b60245260445ffd5b507f02000000000000000000000000000000000000000000000000000000000000008114610bb5565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f3ed2a9c0000000000000000000000000000000000000000000000000000000005f5260045ffd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760043567ffffffffffffffff8111610175573660238201121561017557806004013567ffffffffffffffff8111610175578060051b36602482850101116101755760405192839260208452808460200152604084810193806024850186378501019283916114a4575b505050806040520360401b178060401c9067ffffffffffffffff16f35b919350915b80915f6044825187016024810135918291018537389084305af41561153057602067ffffffffffffffe0603f5f937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08a87030181528301943d81523d858583013e3d010116933d01015284838210156115235750906114a9565b9350509050838080611487565b853d5f823e3d90fd5b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755761156b61215a565b60243590805f52336020527f2ea13d3f0340a613d1765d6e239004eca4cb7efa2e253d1e113c4d333b8db7c860405f20015c826115a833846127e0565b91808310928315611602575b5050506115bd57005b73ffffffffffffffffffffffffffffffffffffffff907ff9e94710000000000000000000000000000000000000000000000000000000005f521660045260245260445ffd5b031090508284806115b4565b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760043580421161164457005b7f6634e923000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b60c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610175576116a161215a565b60243560443560643560ff81168103610175576084359060a4355f73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2871860601b153360601b908460ff1690156117d2575b5050156116f057005b6040519263927da10584523360208501528673ffffffffffffffffffffffffffffffffffffffff16604085015260608401943086523060c08601528660a01c156e22d473030f116ddee9f6b43ac78ba30296601c86019660608160648a8c5afa605f3d1116156117bb57632b67b57087525265ffffffffffff608086015260e085015261010080850152604161012085015261014084015261016083015260f81b610180909101525f9138916101849184905af1903b02156117ae57005b636b836e6b5f526004601cfd5b600489676b836e6b8757f0fd5f521560021b601801fd5b633644e5155f5260205f6004601c8c611388fa60203d145f51151016156118d2575f92506040519130603484015260208301528660748301527fdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f783511461186f576fd505accf000000000000000000000000825287605483015260948201528460b48201528260d482015260e46010389201838a5af187806116e7565b336014526f7ecebe000000000000000000000000008352602060548301602460108c5afa88151060948301526f8fcbaf0c000000000000000000000000825260b48201528460d48201528260f48201526101046010389201838a5af187806116e7565b6116e7565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760043567ffffffffffffffff81116101755761196d61029f61192a6119a1933690600401612329565b6040519283917f010000000000000000000000000000000000000000000000000000000000000060208401523360408401526080606084015260a083019061257f565b6024356080830152037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612119565b80518101906020818303126101755760208101519067ffffffffffffffff82116101755760206119d992816101719501920101612665565b60405191829182612464565b346101755760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760243573ffffffffffffffffffffffffffffffffffffffff81168082036101755773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016908133036113cc576064359260405192846060528060405260443560601b9081602c526f23b872dd000000000000000000000000600c5260205f6064601c82875af18060015f51141615611b5b575b5f6060528560405215611aca57005b5f936074860152856054860152603485015260208401526f36c78516000000000000000000000000835260014614908115611b41575b3b15109160846010389201836e22d473030f116ddee9f6b43ac78ba35af11615611b2657005b600490677939f4248757f0fd5f5260a01c151560021b601801fd5b6e22d473030f116ddee9f6b43ac78ba33b15159150611b00565b3d843b151710611abb565b34610175575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b5f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755747611c0457005b611c0e473361282e565b005b3461017557611c615f8060046bffffffffffffffffffffffff611c32366122a1565b939492989089835f6bffff9a5889f795069a41a8a3911267400065a8177fae2781841402921802018115020190565b9060405198611cdb60208b01967f0300000000000000000000000000000000000000000000000000000000000000885260408c01906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b151560a08a0152600f0b60c08901521660e08701526101008601526101008552611d0761012086612119565b604051947ff83d08ba0000000000000000000000000000000000000000000000000000000086525180918387015e01838273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af1611e2e573d815260208101903d5f833e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d8301011691826040527fcacd6cb3000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008251161480611e23575b15611e1e57506024810151604490910151600f91820b8352900b6020820152604090f35b905190fd5b506044825114611dfa565b7f4c816e2b000000000000000000000000000000000000000000000000000000005f5260045ffd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557611e8861215a565b805f5233602052611ec07f2ea13d3f0340a613d1765d6e239004eca4cb7efa2e253d1e113c4d333b8db7c860405f20019133906127e0565b905d005b6101007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557610157611efb3661219e565b611f03612267565b611f0b612276565b91611f14612286565b339360e4359360c43593612717565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557611f5561215a565b60243590805f52336020527f2ea13d3f0340a613d1765d6e239004eca4cb7efa2e253d1e113c4d333b8db7c860405f20015c82611f9233846127e0565b8281109283611fea575b505050611fa557005b73ffffffffffffffffffffffffffffffffffffffff907ffef2c60e000000000000000000000000000000000000000000000000000000005f521660045260245260445ffd5b03119050828480611f9c565b6101576120d26bffffffffffffffffffffffff612012366122a1565b9394925f92919250612077604051965f602089015233604089015260608801906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b151560c0860152600f0b60e0850152166101008301526101208201527f800000000000000000000000000000000000000000000000000000000000000061014082015233610160820152610160815261029f61018082612119565b602080825183010191016126f3565b6040810190811067ffffffffffffffff82111761139f57604052565b6060810190811067ffffffffffffffff82111761139f57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761139f57604052565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361017557565b359073ffffffffffffffffffffffffffffffffffffffff8216820361017557565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc606091011261017557604051906121d5826120fd565b8160043573ffffffffffffffffffffffffffffffffffffffff8116810361017557815260243573ffffffffffffffffffffffffffffffffffffffff811681036101755760208201526040604435910152565b91908260609103126101755760405161223f816120fd565b604080829461224d8161217d565b845261225b6020820161217d565b60208501520135910152565b60643590811515820361017557565b6084359081600f0b820361017557565b60a435906bffffffffffffffffffffffff8216820361017557565b60e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc820112610175576122d6906004612227565b906064358015158103610175579060843580600f0b8103610175579060a4356bffffffffffffffffffffffff81168103610175579060c43590565b67ffffffffffffffff811161139f5760051b60200190565b919091808303606081126101755760405190612344826120e1565b8194833567ffffffffffffffff81116101755784019080601f830112156101755781359161237183612311565b9261237f6040519485612119565b808452602060a081860192028301019183831161017557602001905b82821061240757505050506040917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe091845201126101755760408051926123e1846120e1565b6123ed6020820161217d565b845201359081600f0b820361017557602091828401520152565b60a082850312610175576040519061241e826120fd565b6124288584612227565b82526060830135906bffffffffffffffffffffffff8216820361017557826020928360a09501526080850135604082015281520191019061239b565b60206040818301928281528451809452019201905f5b8181106124875750505090565b90919260206124af60019286519060206040928051600f0b83520151600f0b60208201520190565b940192910161247a565b602081016020825282518091526040820190602060408260051b8501019401915f905b8282106124eb57505050505090565b9091929395947fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0878203018252845190602080835192838152019201905f905b80821061254d57505050602080600192960192019201909291959394956124dc565b909192602061257560019286519060206040928051600f0b83520151600f0b60208201520190565b940192019061252b565b9060608101918051926060835283518091526020608084019401905f5b8181106125d557505050602080604092015173ffffffffffffffffffffffffffffffffffffffff815116828501520151600f0b91015290565b909194602060a06001926040895161262e8382516040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b808501516bffffffffffffffffffffffff1660608401520151608082015201960192910161259c565b519081600f0b820361017557565b81601f820112156101755780519061267c82612311565b9261268a6040519485612119565b82845260208085019360061b8301019181831161017557602001925b8284106126b4575050505090565b60408483031261017557602060409182516126ce816120e1565b6126d787612657565b81526126e4838801612657565b838201528152019301926126a6565b919082604091031261017557612714602061270d84612657565b9301612657565b90565b936bffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff946127dc98946120d298946127a2604051995f60208c01523360408c015260608b01906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b151560c0890152600f0b60e08801521661010086015261012085015261014084015216610160820152610160815261029f61018082612119565b9091565b73ffffffffffffffffffffffffffffffffffffffff811661280057503190565b602460106020939284936014526f70a082310000000000000000000000005f525afa601f3d11166020510290565b5f80809338935af11561283d57565b63b12d13eb5f526004601cfd5b905f8060046020604051957ff83d08ba0000000000000000000000000000000000000000000000000000000087528051918291018388015e01848273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af1156128fa573d82523d5f602084013e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d84010116604052565b503d5f823e3d90fd5b51907fff000000000000000000000000000000000000000000000000000000000000008216820361017557565b519073ffffffffffffffffffffffffffffffffffffffff8216820361017557565b919082606091031261017557604051612969816120fd565b604080829461297781612930565b845261298560208201612930565b60208501520151910152565b5190811515820361017557565b51906bffffffffffffffffffffffff8216820361017557565b9190918083036060811261017557604051906129d2826120e1565b8194835167ffffffffffffffff811161017557840181601f82011215610175578051906129fe82612311565b92612a0c6040519485612119565b828452602060a081860194028301019181831161017557602001925b828410612a8f57505050506040917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0918452011261017557602090612a876040805194612a74866120e1565b612a7f858201612930565b865201612657565b828401520152565b60a08483031261017557602060a091604051612aaa816120fd565b612ab48588612951565b8152612ac26060880161299e565b8382015260808701516040820152815201930192612a28565b60405190612ae8826120e1565b60608252604051602083612afb836120e1565b5f83525f828401520152565b8051156113725760200190565b80518210156113725760209160051b010190565b919360c0936bffffffffffffffffffffffff92979695612b8c8560e081019a6040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b600f0b6060850152151560808401521660a08201520152565b90919273ffffffffffffffffffffffffffffffffffffffff8260340151167f00000000000000000000000000000000000000000000000000000000000000009073ffffffffffffffffffffffffffffffffffffffff821614155f14612c8a575060409394612c2091855196879586955f875260048701612b28565b03815f73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af18015610a22575f915f91612c6f57509091565b90506127dc915060403d604011610a1b57610a0a8183612119565b945f9491936108c6612ca9928796604051958694602086019889612b28565b604051947f101e89520000000000000000000000000000000000000000000000000000000086526004860152518091602486015e602401838273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af115610b51573d81526127dc906020808201913d5f843e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d8301011660405280510101906126f3565b91909181612d7357505050565b73ffffffffffffffffffffffffffffffffffffffff8316612dd25750612dd0915073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001661282e565b565b604051927f0c11dedd0000000000000000000000000000000000000000000000000000000084526004840152602483015260448201525f806064838273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000165af115610b515750565b906fffffffffffffffffffffffffffffffff1680612e6c57505050565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016803b15610175575f928360649273ffffffffffffffffffffffffffffffffffffffff948560405198899788967f03a65ab600000000000000000000000000000000000000000000000000000000885216600487015216602485015260448401525af18015610a2257612f125750565b5f612dd09161211956fea26469706673582212204f52231b1f1b3b25bdaca58c87a5d23c1d751fdef1b1736bdcee7959a9ff17ca64736f6c634300081c0033000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444000000000000000000000000553a2efc570c9e104942cec6ac1c18118e54c091
Deployed Bytecode
0x60806040526004361015610011575f80fd5b5f5f3560e01c806306b81a1514611ff65780630a52f5f114611f235780631d8a796214611ec457806327c3a09014611e565780633bc5284214611c105780634186527014611bd457806346745c4514611b66578063599d0714146119e55780636d0cb613146118d75780637ac2ff7b1461166f578063a69909461461160e578063ac4563de14611539578063ac9650d8146113f4578063b45a3c0e14610512578063cb787803146103e5578063d4fdd7ea1461017a5763f196187f146100d5575f80fd5b6101207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610177576101093661219e565b610111612267565b9061011a612276565b91610123612286565b91610104359273ffffffffffffffffffffffffffffffffffffffff84168403610175576101579460e4359360c43593612717565b60408051600f93840b81529190920b602082015290819081015b0390f35b5f5b80fd5b5060407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101775760043567ffffffffffffffff811161035c573660238201121561035c5780600401356101d081612311565b916101de6040519384612119565b818352602083019160051b8101602401823682116103e15760248301905b8282106103ad57505050506040519160a08301907f02000000000000000000000000000000000000000000000000000000000000006020850152336040850152608060608501525180915260c083019060c08160051b850101929185905b82821061036457866102a48761029f81896024356080830152037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612119565b61284a565b90815182019160208181850194031261035c5760208101519067ffffffffffffffff8211610360570182603f8201121561035c5760208101516102e681612311565b926102f46040519485612119565b8184526020808086019360051b850101019285841161035c5760408101925b848410610328576040518061017188826124b9565b835167ffffffffffffffff81116103585760209161034d898480809588010101612665565b815201930192610313565b8380fd5b5080fd5b8280fd5b9091929360208061039f837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff408a60019603018652885161257f565b96019201920190929161025a565b813567ffffffffffffffff81116103dd576020916103d2839260243691890101612329565b8152019101906101fc565b8780fd5b8580fd5b507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601610100811261035c5760a01361017557604051610425816120fd565b610430366004612227565b81526064356bffffffffffffffffffffffff8116810361017557602082019081526040820190608435825260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5c3601126101755760405190610492826120e1565b60a43573ffffffffffffffffffffffffffffffffffffffff8116810361017557825260c4359283600f0b8403610175576bffffffffffffffffffffffff6101579560208501958652519373ffffffffffffffffffffffffffffffffffffffff80602087015116915116149451600f0b925116905191339460e43594612717565b346101755760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444168033036113cc5736602411610175577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc36019067ffffffffffffffff821161139f5760405161060e60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb3601160182612119565b8281526020810192602484375f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc368301015260608151156113725783517fff00000000000000000000000000000000000000000000000000000000000000169081610b845750508051810192610160828503126101755761068f90612903565b506106ac60206106a160408401612930565b940160608301612951565b6106b860c08301612991565b936106c560e08401612657565b946106d3610100850161299e565b610120850151918773ffffffffffffffffffffffffffffffffffffffff806107046101606101408b01519a01612930565b9616951693821580610b65575b80610b59575b156fffffffffffffffffffffffffffffffff83169081028082189590919080155f86128088186bffff9a5889f795069a41a8a30290881467400065a8177fae27020102019a73ffffffffffffffffffffffffffffffffffffffff8a60340151167f000000000000000000000000553a2efc570c9e104942cec6ac1c18118e54c0919073ffffffffffffffffffffffffffffffffffffffff821614155f14610a2d57505050506040916107d8849284519b8c9485945f86528c60048701612b28565b03818573ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444165af18015610a22575f975f916109ed575b5096955b81156109e257865f03600f0b5b600f0b908082126109b45750505f6108f2979812185f146108fa575060208361088e73ffffffffffffffffffffffffffffffffffffffff93846108aa975116885f036fffffffffffffffffffffffffffffffff1690612e4f565b0151166fffffffffffffffffffffffffffffffff861691612d66565b60408051600f92830b60208201529390910b9083015281606081015b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612119565b602081519101f35b906109359073ffffffffffffffffffffffffffffffffffffffff602086015116885f036fffffffffffffffffffffffffffffffff1690612e4f565b6fffffffffffffffffffffffffffffffff841681811161099057506fffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff61098b94511691818681169116031690612e4f565b6108aa565b91905073ffffffffffffffffffffffffffffffffffffffff61098b93511690612d66565b7fd395b706000000000000000000000000000000000000000000000000000000005f5260045260245260445ffd5b875f03600f0b610834565b9050610a1291975060403d604011610a1b575b610a0a8183612119565b8101906126f3565b96909689610823565b503d610a00565b6040513d5f823e3d90fd5b5f8b610a7d82969f9883969f998b99610a51916040519b8c94602086019788612b28565b037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101895288612119565b6040519687937f101e89520000000000000000000000000000000000000000000000000000000085526004850152518091602485015e602401925af115610b51573d8152610b04906020808201913d5f843e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d8301011660405280510101906126f3565b9890971461082757610b4c8373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d4441661282e565b610827565b3d5f823e3d90fd5b505f82600f0b13610717565b5073ffffffffffffffffffffffffffffffffffffffff87511615610711565b91937f0100000000000000000000000000000000000000000000000000000000000000821493509190838015611349575b156112855750821561119d57610bc9612adb565b50835184019160808584031261017557610be290612903565b50610bef60408501612930565b918185015167ffffffffffffffff811161017557610c2c60809160208073ffffffffffffffffffffffffffffffffffffffff9501918901016129b7565b950151921692604051610c40604082612119565b6001815260205f5b81811061118657505080610c669196610c6082612b07565b52612b07565b509392915b8351917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610cb1610c9b85612311565b94610ca96040519687612119565b808652612311565b01905f5b828110611176575050505f905f5f5f915f965b885188101561106357610cdb888a612b14565b51988951517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610d23610d0d83612311565b92610d1b6040519485612119565b808452612311565b015f5b818110611040575050610d398a8a612b14565b52610d448989612b14565b5060208a01958651936020850151600f0b01915f945b8c518051871015610f415786610d6f91612b14565b519073ffffffffffffffffffffffffffffffffffffffff8151169082519073ffffffffffffffffffffffffffffffffffffffff602083015116831480938115610f20575b5015610175578d918f610e186bffffffffffffffffffffffff602088015116928680610e0c60208801968751600f0b93845f6bffff9a5889f795069a41a8a3911267400065a8177fae2781841402921802018115020190565b9160408b015193612ba5565b929095610e588d604051610e2b816120e1565b610e468a600f0b9687835288600f0b9a8b6020850152612b14565b5190610e528383612b14565b52612b14565b5015610ed35750505060200151600f0b03610eab5773ffffffffffffffffffffffffffffffffffffffff6001925151169060405191610e96836120e1565b82525f03600f0b6020820152955b0194610d5a565b7fe3648855000000000000000000000000000000000000000000000000000000005f5260045ffd5b92509250925051600f0b03610eab5773ffffffffffffffffffffffffffffffffffffffff6020600193510151169060405191610f0e836120e1565b82525f03600f0b602082015295610ea4565b905073ffffffffffffffffffffffffffffffffffffffff835116145f610db3565b509793945095919b949790999a506020870151600f0b01968a155f14610f9257505073ffffffffffffffffffffffffffffffffffffffff80600192515116955116985b019693919890979297610cc8565b9590999173ffffffffffffffffffffffffffffffffffffffff9051511673ffffffffffffffffffffffffffffffffffffffff87161490811591611008575b50610fdd57600190610f84565b7f658e3c95000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b73ffffffffffffffffffffffffffffffffffffffff9150511673ffffffffffffffffffffffffffffffffffffffff8a1614158b610fd0565b60209060405161104f816120e1565b5f81525f8382015282828601015201610d26565b95989750929091939550808612611146575083905f831215611123576fffffffffffffffffffffffffffffffff61109d935f031690612e4f565b5f831315611100576fffffffffffffffffffffffffffffffff6110c1931690612e4f565b156110ea576110e56110d56108c692612b07565b5160405192839160208301612464565b6108f2565b6110e56108c691604051928391602083016124b9565b6fffffffffffffffffffffffffffffffff61111e935f031691612d66565b6110c1565b611141926fffffffffffffffffffffffffffffffff16915084612d66565b61109d565b85907fd395b706000000000000000000000000000000000000000000000000000000005f5260045260245260445ffd5b6020818601810183905201610cb5565b602090611191612adb565b82828601015201610c48565b835184019160808560208501940312610175576111b990612903565b506111c660408501612930565b938181015167ffffffffffffffff81116101755781019280603f850112156101755760208401516111f681612311565b946112046040519687612119565b8186526020808088019360051b83010101918383116101755760408201905b838210611255575050505050608073ffffffffffffffffffffffffffffffffffffffff91015192941691939293610c6b565b815167ffffffffffffffff81116101755760209161127a8784808095890101016129b7565b815201910190611223565b7f03000000000000000000000000000000000000000000000000000000000000009194929350146112b75750506108f2565b80518101610100828203126101755760206112e3916112d861131495612903565b500160408301612951565b906112f060a08201612991565b6112fc60c08301612657565b61010061130b60e0850161299e565b93015193612ba5565b907fcacd6cb3000000000000000000000000000000000000000000000000000000005f52600f0b600452600f0b60245260445ffd5b507f02000000000000000000000000000000000000000000000000000000000000008114610bb5565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f3ed2a9c0000000000000000000000000000000000000000000000000000000005f5260045ffd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760043567ffffffffffffffff8111610175573660238201121561017557806004013567ffffffffffffffff8111610175578060051b36602482850101116101755760405192839260208452808460200152604084810193806024850186378501019283916114a4575b505050806040520360401b178060401c9067ffffffffffffffff16f35b919350915b80915f6044825187016024810135918291018537389084305af41561153057602067ffffffffffffffe0603f5f937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08a87030181528301943d81523d858583013e3d010116933d01015284838210156115235750906114a9565b9350509050838080611487565b853d5f823e3d90fd5b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755761156b61215a565b60243590805f52336020527f2ea13d3f0340a613d1765d6e239004eca4cb7efa2e253d1e113c4d333b8db7c860405f20015c826115a833846127e0565b91808310928315611602575b5050506115bd57005b73ffffffffffffffffffffffffffffffffffffffff907ff9e94710000000000000000000000000000000000000000000000000000000005f521660045260245260445ffd5b031090508284806115b4565b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760043580421161164457005b7f6634e923000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b60c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610175576116a161215a565b60243560443560643560ff81168103610175576084359060a4355f73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2871860601b153360601b908460ff1690156117d2575b5050156116f057005b6040519263927da10584523360208501528673ffffffffffffffffffffffffffffffffffffffff16604085015260608401943086523060c08601528660a01c156e22d473030f116ddee9f6b43ac78ba30296601c86019660608160648a8c5afa605f3d1116156117bb57632b67b57087525265ffffffffffff608086015260e085015261010080850152604161012085015261014084015261016083015260f81b610180909101525f9138916101849184905af1903b02156117ae57005b636b836e6b5f526004601cfd5b600489676b836e6b8757f0fd5f521560021b601801fd5b633644e5155f5260205f6004601c8c611388fa60203d145f51151016156118d2575f92506040519130603484015260208301528660748301527fdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f783511461186f576fd505accf000000000000000000000000825287605483015260948201528460b48201528260d482015260e46010389201838a5af187806116e7565b336014526f7ecebe000000000000000000000000008352602060548301602460108c5afa88151060948301526f8fcbaf0c000000000000000000000000825260b48201528460d48201528260f48201526101046010389201838a5af187806116e7565b6116e7565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760043567ffffffffffffffff81116101755761196d61029f61192a6119a1933690600401612329565b6040519283917f010000000000000000000000000000000000000000000000000000000000000060208401523360408401526080606084015260a083019061257f565b6024356080830152037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08101835282612119565b80518101906020818303126101755760208101519067ffffffffffffffff82116101755760206119d992816101719501920101612665565b60405191829182612464565b346101755760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755760243573ffffffffffffffffffffffffffffffffffffffff81168082036101755773ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d44416908133036113cc576064359260405192846060528060405260443560601b9081602c526f23b872dd000000000000000000000000600c5260205f6064601c82875af18060015f51141615611b5b575b5f6060528560405215611aca57005b5f936074860152856054860152603485015260208401526f36c78516000000000000000000000000835260014614908115611b41575b3b15109160846010389201836e22d473030f116ddee9f6b43ac78ba35af11615611b2657005b600490677939f4248757f0fd5f5260a01c151560021b601801fd5b6e22d473030f116ddee9f6b43ac78ba33b15159150611b00565b3d843b151710611abb565b34610175575f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557602060405173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000553a2efc570c9e104942cec6ac1c18118e54c091168152f35b5f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101755747611c0457005b611c0e473361282e565b005b3461017557611c615f8060046bffffffffffffffffffffffff611c32366122a1565b939492989089835f6bffff9a5889f795069a41a8a3911267400065a8177fae2781841402921802018115020190565b9060405198611cdb60208b01967f0300000000000000000000000000000000000000000000000000000000000000885260408c01906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b151560a08a0152600f0b60c08901521660e08701526101008601526101008552611d0761012086612119565b604051947ff83d08ba0000000000000000000000000000000000000000000000000000000086525180918387015e01838273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444165af1611e2e573d815260208101903d5f833e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d8301011691826040527fcacd6cb3000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008251161480611e23575b15611e1e57506024810151604490910151600f91820b8352900b6020820152604090f35b905190fd5b506044825114611dfa565b7f4c816e2b000000000000000000000000000000000000000000000000000000005f5260045ffd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557611e8861215a565b805f5233602052611ec07f2ea13d3f0340a613d1765d6e239004eca4cb7efa2e253d1e113c4d333b8db7c860405f20019133906127e0565b905d005b6101007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557610157611efb3661219e565b611f03612267565b611f0b612276565b91611f14612286565b339360e4359360c43593612717565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261017557611f5561215a565b60243590805f52336020527f2ea13d3f0340a613d1765d6e239004eca4cb7efa2e253d1e113c4d333b8db7c860405f20015c82611f9233846127e0565b8281109283611fea575b505050611fa557005b73ffffffffffffffffffffffffffffffffffffffff907ffef2c60e000000000000000000000000000000000000000000000000000000005f521660045260245260445ffd5b03119050828480611f9c565b6101576120d26bffffffffffffffffffffffff612012366122a1565b9394925f92919250612077604051965f602089015233604089015260608801906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b151560c0860152600f0b60e0850152166101008301526101208201527f800000000000000000000000000000000000000000000000000000000000000061014082015233610160820152610160815261029f61018082612119565b602080825183010191016126f3565b6040810190811067ffffffffffffffff82111761139f57604052565b6060810190811067ffffffffffffffff82111761139f57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761139f57604052565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361017557565b359073ffffffffffffffffffffffffffffffffffffffff8216820361017557565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc606091011261017557604051906121d5826120fd565b8160043573ffffffffffffffffffffffffffffffffffffffff8116810361017557815260243573ffffffffffffffffffffffffffffffffffffffff811681036101755760208201526040604435910152565b91908260609103126101755760405161223f816120fd565b604080829461224d8161217d565b845261225b6020820161217d565b60208501520135910152565b60643590811515820361017557565b6084359081600f0b820361017557565b60a435906bffffffffffffffffffffffff8216820361017557565b60e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc820112610175576122d6906004612227565b906064358015158103610175579060843580600f0b8103610175579060a4356bffffffffffffffffffffffff81168103610175579060c43590565b67ffffffffffffffff811161139f5760051b60200190565b919091808303606081126101755760405190612344826120e1565b8194833567ffffffffffffffff81116101755784019080601f830112156101755781359161237183612311565b9261237f6040519485612119565b808452602060a081860192028301019183831161017557602001905b82821061240757505050506040917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe091845201126101755760408051926123e1846120e1565b6123ed6020820161217d565b845201359081600f0b820361017557602091828401520152565b60a082850312610175576040519061241e826120fd565b6124288584612227565b82526060830135906bffffffffffffffffffffffff8216820361017557826020928360a09501526080850135604082015281520191019061239b565b60206040818301928281528451809452019201905f5b8181106124875750505090565b90919260206124af60019286519060206040928051600f0b83520151600f0b60208201520190565b940192910161247a565b602081016020825282518091526040820190602060408260051b8501019401915f905b8282106124eb57505050505090565b9091929395947fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0878203018252845190602080835192838152019201905f905b80821061254d57505050602080600192960192019201909291959394956124dc565b909192602061257560019286519060206040928051600f0b83520151600f0b60208201520190565b940192019061252b565b9060608101918051926060835283518091526020608084019401905f5b8181106125d557505050602080604092015173ffffffffffffffffffffffffffffffffffffffff815116828501520151600f0b91015290565b909194602060a06001926040895161262e8382516040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b808501516bffffffffffffffffffffffff1660608401520151608082015201960192910161259c565b519081600f0b820361017557565b81601f820112156101755780519061267c82612311565b9261268a6040519485612119565b82845260208085019360061b8301019181831161017557602001925b8284106126b4575050505090565b60408483031261017557602060409182516126ce816120e1565b6126d787612657565b81526126e4838801612657565b838201528152019301926126a6565b919082604091031261017557612714602061270d84612657565b9301612657565b90565b936bffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff946127dc98946120d298946127a2604051995f60208c01523360408c015260608b01906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b151560c0890152600f0b60e08801521661010086015261012085015261014084015216610160820152610160815261029f61018082612119565b9091565b73ffffffffffffffffffffffffffffffffffffffff811661280057503190565b602460106020939284936014526f70a082310000000000000000000000005f525afa601f3d11166020510290565b5f80809338935af11561283d57565b63b12d13eb5f526004601cfd5b905f8060046020604051957ff83d08ba0000000000000000000000000000000000000000000000000000000087528051918291018388015e01848273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444165af1156128fa573d82523d5f602084013e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d84010116604052565b503d5f823e3d90fd5b51907fff000000000000000000000000000000000000000000000000000000000000008216820361017557565b519073ffffffffffffffffffffffffffffffffffffffff8216820361017557565b919082606091031261017557604051612969816120fd565b604080829461297781612930565b845261298560208201612930565b60208501520151910152565b5190811515820361017557565b51906bffffffffffffffffffffffff8216820361017557565b9190918083036060811261017557604051906129d2826120e1565b8194835167ffffffffffffffff811161017557840181601f82011215610175578051906129fe82612311565b92612a0c6040519485612119565b828452602060a081860194028301019181831161017557602001925b828410612a8f57505050506040917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0918452011261017557602090612a876040805194612a74866120e1565b612a7f858201612930565b865201612657565b828401520152565b60a08483031261017557602060a091604051612aaa816120fd565b612ab48588612951565b8152612ac26060880161299e565b8382015260808701516040820152815201930192612a28565b60405190612ae8826120e1565b60608252604051602083612afb836120e1565b5f83525f828401520152565b8051156113725760200190565b80518210156113725760209160051b010190565b919360c0936bffffffffffffffffffffffff92979695612b8c8560e081019a6040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b600f0b6060850152151560808401521660a08201520152565b90919273ffffffffffffffffffffffffffffffffffffffff8260340151167f000000000000000000000000553a2efc570c9e104942cec6ac1c18118e54c0919073ffffffffffffffffffffffffffffffffffffffff821614155f14612c8a575060409394612c2091855196879586955f875260048701612b28565b03815f73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444165af18015610a22575f915f91612c6f57509091565b90506127dc915060403d604011610a1b57610a0a8183612119565b945f9491936108c6612ca9928796604051958694602086019889612b28565b604051947f101e89520000000000000000000000000000000000000000000000000000000086526004860152518091602486015e602401838273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444165af115610b51573d81526127dc906020808201913d5f843e7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f3d8301011660405280510101906126f3565b91909181612d7357505050565b73ffffffffffffffffffffffffffffffffffffffff8316612dd25750612dd0915073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d4441661282e565b565b604051927f0c11dedd0000000000000000000000000000000000000000000000000000000084526004840152602483015260448201525f806064838273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444165af115610b515750565b906fffffffffffffffffffffffffffffffff1680612e6c57505050565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d44416803b15610175575f928360649273ffffffffffffffffffffffffffffffffffffffff948560405198899788967f03a65ab600000000000000000000000000000000000000000000000000000000885216600487015216602485015260448401525af18015610a2257612f125750565b5f612dd09161211956fea26469706673582212204f52231b1f1b3b25bdaca58c87a5d23c1d751fdef1b1736bdcee7959a9ff17ca64736f6c634300081c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444000000000000000000000000553a2efc570c9e104942cec6ac1c18118e54c091
-----Decoded View---------------
Arg [0] : core (address): 0xe0e0e08A6A4b9Dc7bD67BCB7aadE5cF48157d444
Arg [1] : _mevResist (address): 0x553a2EFc570c9e104942cEC6aC1c18118e54C091
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000e0e0e08a6a4b9dc7bd67bcb7aade5cf48157d444
Arg [1] : 000000000000000000000000553a2efc570c9e104942cec6ac1c18118e54c091
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ 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.