Overview
ETH Balance
ETH Value
$0.00Latest 23 from a total of 23 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Mint Position | 33702625 | 57 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 33308201 | 62 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 33169412 | 64 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32967253 | 66 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32872952 | 67 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32738750 | 69 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32697740 | 69 days ago | IN | 0 ETH | 0.00000028 | ||||
| Mint Position | 32637825 | 70 days ago | IN | 0 ETH | 0.00000007 | ||||
| Mint Position | 32560453 | 71 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32532524 | 71 days ago | IN | 0 ETH | 0.00000007 | ||||
| Mint Position | 32481647 | 72 days ago | IN | 0 ETH | 0.00000007 | ||||
| Mint Position | 32370158 | 73 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32301422 | 74 days ago | IN | 0 ETH | 0.00000009 | ||||
| Mint Position | 32267461 | 74 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32110537 | 76 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32043328 | 77 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 32009716 | 77 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 31674958 | 81 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 31618205 | 82 days ago | IN | 0 ETH | 0.00000009 | ||||
| Mint Position | 31587601 | 82 days ago | IN | 0 ETH | 0.00000008 | ||||
| Mint Position | 31493471 | 83 days ago | IN | 0 ETH | 0.00000009 | ||||
| Mint Position | 31433940 | 84 days ago | IN | 0 ETH | 0.00000009 | ||||
| Mint Position | 31417786 | 84 days ago | IN | 0 ETH | 0.00000008 |
View more zero value Internal Transactions in Advanced View mode
Cross-Chain Transactions
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.26;
import {IERC4626} from "lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IERC721} from "lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol";
import {SafeCast} from "lib/openzeppelin-contracts/contracts/utils/math/SafeCast.sol";
import {BaseAssetToVaultWrapperHelper} from "src/periphery/base/BaseAssetToVaultWrapperHelper.sol";
import {EVCUtil} from "ethereum-vault-connector/utils/EVCUtil.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {IPositionManager} from "lib/v4-periphery/src/interfaces/IPositionManager.sol";
import {Actions} from "lib/v4-periphery/src/libraries/Actions.sol";
import {ActionConstants} from "lib/v4-periphery/src/libraries/ActionConstants.sol";
import {IWETH9} from "lib/v4-periphery/src/interfaces/external/IWETH9.sol";
interface IPositionManagerExtended is IPositionManager {
function WETH9() external view returns (address);
}
///@dev This doesn't support aave vaults. Only vault wrappers that have underlying vaults that support ERC4626 interface are supported
contract LiquidityHelper is EVCUtil, BaseAssetToVaultWrapperHelper {
using SafeERC20 for IERC20;
using SafeCast for uint256;
using SafeCast for int256;
using SafeCast for int128;
IPositionManager public immutable positionManager;
/// @notice The hooks contract for vault wrapper pools
IHooks public immutable yieldHarvestingHook;
IWETH9 public immutable weth;
error NotOwner();
constructor(address _evc, IPositionManager _positionManager, IHooks _yieldHarvestingHook) EVCUtil(_evc) {
yieldHarvestingHook = _yieldHarvestingHook;
positionManager = _positionManager;
weth = IWETH9(IPositionManagerExtended(address(_positionManager)).WETH9());
}
modifier onlyOwnerOf(uint256 tokenId) {
if (IERC721(address(positionManager)).ownerOf(tokenId) != _msgSender()) {
revert NotOwner();
}
_;
}
function _pullAndConvertAssets(
PoolKey memory poolKey,
uint128 amount0Max,
uint128 amount1Max,
bytes calldata hookData
) internal returns (PoolKey memory, uint128, uint128) {
(IERC4626 vaultWrapper0, IERC4626 vaultWrapper1) = hookData.length == 0
? (IERC4626(address(0)), IERC4626(address(0)))
: abi.decode(hookData, (IERC4626, IERC4626));
if (amount0Max != 0) {
if (!poolKey.currency0.isAddressZero()) {
IERC20(Currency.unwrap(poolKey.currency0)).safeTransferFrom(_msgSender(), address(this), amount0Max);
} else if (msg.value == 0) {
weth.transferFrom(_msgSender(), address(this), amount0Max);
}
}
if (amount1Max != 0) {
IERC20(Currency.unwrap(poolKey.currency1)).safeTransferFrom(_msgSender(), address(this), amount1Max);
}
uint256 currentWETHBalance = weth.balanceOf(address(this));
if (currentWETHBalance > 0) {
weth.withdraw(currentWETHBalance);
}
amount0Max = SafeCast.toUint128(poolKey.currency0.balanceOf(address(this)));
amount1Max = SafeCast.toUint128(poolKey.currency1.balanceOf(address(this)));
if (address(vaultWrapper0) != address(0)) {
IERC4626 underlyingVault0 = _getUnderlyingVault(vaultWrapper0);
_deposit(
vaultWrapper0,
address(underlyingVault0),
IERC20(Currency.unwrap(poolKey.currency0)),
address(this),
amount0Max,
address(positionManager)
);
poolKey.currency0 = Currency.wrap(address(vaultWrapper0));
poolKey.hooks = yieldHarvestingHook;
} else {
if (!poolKey.currency0.isAddressZero()) {
poolKey.currency0.transfer(address(positionManager), amount0Max);
}
}
if (address(vaultWrapper1) != address(0)) {
IERC4626 underlyingVault1 = _getUnderlyingVault(vaultWrapper1);
_deposit(
vaultWrapper1,
address(underlyingVault1),
IERC20(Currency.unwrap(poolKey.currency1)),
address(this),
amount1Max,
address(positionManager)
);
poolKey.currency1 = Currency.wrap(address(vaultWrapper1));
poolKey.hooks = yieldHarvestingHook;
} else {
poolKey.currency1.transfer(address(positionManager), amount1Max);
}
//currencies might be out of order at this point, so we need to sort them
if (Currency.unwrap(poolKey.currency0) > Currency.unwrap(poolKey.currency1)) {
(poolKey.currency0, poolKey.currency1) = (poolKey.currency1, poolKey.currency0);
(amount0Max, amount1Max) = (amount1Max, amount0Max);
}
return (poolKey, amount0Max, amount1Max);
}
function _callModifyLiquidity(
uint8 actionType, // either Actions.MINT_POSITION or Actions.INCREASE_LIQUIDITY
bytes memory actionData, // encoded params for first action,
PoolKey memory poolKey
) internal {
bytes memory actions = new bytes(5);
actions[0] = bytes1(actionType);
actions[1] = bytes1(uint8(Actions.SETTLE));
actions[2] = bytes1(uint8(Actions.SETTLE));
actions[3] = bytes1(uint8(Actions.SWEEP));
actions[4] = bytes1(uint8(Actions.SWEEP));
bytes[] memory params = new bytes[](5);
params[0] = actionData;
params[1] = abi.encode(poolKey.currency0, ActionConstants.OPEN_DELTA, false);
params[2] = abi.encode(poolKey.currency1, ActionConstants.OPEN_DELTA, false);
params[3] = abi.encode(poolKey.currency0, _msgSender());
params[4] = abi.encode(poolKey.currency1, _msgSender());
positionManager.modifyLiquidities{value: address(this).balance}(abi.encode(actions, params), block.timestamp);
}
function mintPosition(
PoolKey memory poolKey,
int24 tickLower,
int24 tickUpper,
uint256 liquidity,
uint128 amount0Max,
uint128 amount1Max,
address owner,
bytes calldata hookData
) external payable returns (uint256 tokenId) {
tokenId = positionManager.nextTokenId();
(poolKey, amount0Max, amount1Max) = _pullAndConvertAssets(poolKey, amount0Max, amount1Max, hookData);
bytes memory actionData =
abi.encode(poolKey, tickLower, tickUpper, liquidity, amount0Max, amount1Max, owner, "");
_callModifyLiquidity(uint8(Actions.MINT_POSITION), actionData, poolKey);
}
function increaseLiquidity(
PoolKey memory poolKey,
uint256 tokenId,
uint256 liquidity,
uint128 amount0Max,
uint128 amount1Max,
bytes calldata hookData
) external payable onlyOwnerOf(tokenId) {
(poolKey, amount0Max, amount1Max) = _pullAndConvertAssets(poolKey, amount0Max, amount1Max, hookData);
bytes memory actionData = abi.encode(tokenId, liquidity, amount0Max, amount1Max, "");
_callModifyLiquidity(uint8(Actions.INCREASE_LIQUIDITY), actionData, poolKey);
}
function decreaseLiquidity(
PoolKey memory poolKey,
uint256 tokenId,
uint128 liquidity,
uint128 amount0Min,
uint128 amount1Min,
address recipient,
bytes calldata hookData
) public onlyOwnerOf(tokenId) {
Currency currency0 = poolKey.currency0;
Currency currency1 = poolKey.currency1;
(IERC4626 vaultWrapper0, IERC4626 vaultWrapper1) = hookData.length == 0
? (IERC4626(address(0)), IERC4626(address(0)))
: abi.decode(hookData, (IERC4626, IERC4626));
if (address(vaultWrapper0) != address(0)) {
poolKey.currency0 = Currency.wrap(address(vaultWrapper0));
poolKey.hooks = yieldHarvestingHook;
}
if (address(vaultWrapper1) != address(0)) {
poolKey.currency1 = Currency.wrap(address(vaultWrapper1));
poolKey.hooks = yieldHarvestingHook;
}
if (Currency.unwrap(poolKey.currency0) > Currency.unwrap(poolKey.currency1)) {
(poolKey.currency0, poolKey.currency1) = (poolKey.currency1, poolKey.currency0);
}
bytes memory actions = new bytes(2);
actions[0] = bytes1(uint8(Actions.DECREASE_LIQUIDITY));
actions[1] = bytes1(uint8(Actions.TAKE_PAIR));
bytes[] memory params = new bytes[](2);
params[0] = abi.encode(tokenId, liquidity, amount0Min, amount1Min, "");
params[1] = abi.encode(poolKey.currency0, poolKey.currency1, ActionConstants.MSG_SENDER);
positionManager.modifyLiquidities{value: address(this).balance}(abi.encode(actions, params), block.timestamp);
//this contract will have the tokens after decreasing liquidity, now we need to withdraw from vault wrappers if needed and send to recipient
if (address(vaultWrapper0) != address(0)) {
IERC4626 underlyingVault0 = _getUnderlyingVault(vaultWrapper0);
_redeem(
vaultWrapper0,
address(underlyingVault0),
address(this),
vaultWrapper0.balanceOf(address(this)),
recipient
);
} else {
//simply transfer the tokens to recipient
currency0.transfer(recipient, currency0.balanceOfSelf());
}
if (address(vaultWrapper1) != address(0)) {
IERC4626 underlyingVault1 = _getUnderlyingVault(vaultWrapper1);
_redeem(
vaultWrapper1,
address(underlyingVault1),
address(this),
vaultWrapper1.balanceOf(address(this)),
recipient
);
} else {
//simply transfer the tokens to recipient
currency1.transfer(recipient, currency1.balanceOfSelf());
}
}
function collectFees(
PoolKey memory poolKey,
uint256 tokenId,
uint128 amount0Min,
uint128 amount1Min,
address recipient,
bytes calldata hookData
) external {
decreaseLiquidity(poolKey, tokenId, 0, amount0Min, amount1Min, recipient, hookData);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC4626.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../token/ERC20/IERC20.sol";
import {IERC20Metadata} from "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC-4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721.sol)
pragma solidity >=0.6.2;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC-721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC-721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.26;
import {IERC4626} from "lib/openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
import {IERC20} from "lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol";
import {SafeERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
contract BaseAssetToVaultWrapperHelper {
using SafeERC20 for IERC20;
using SafeERC20 for IERC4626;
function _deposit(
IERC4626 vaultWrapper,
address underlyingVault,
IERC20 asset,
address from,
uint256 amount,
address receiver
) internal returns (uint256) {
uint256 underlyingVaultShares = _depositInUnderlyingVault(underlyingVault, asset, from, amount, address(this));
return _depositIntoERC4626Vault(
vaultWrapper, IERC20(underlyingVault), address(this), underlyingVaultShares, receiver
);
}
/// @dev for aave wrappers, override this function
function _depositInUnderlyingVault(
address underlyingVault,
IERC20 asset,
address from,
uint256 amount,
address receiver
) internal virtual returns (uint256) {
return _depositIntoERC4626Vault(IERC4626(underlyingVault), asset, from, amount, receiver);
}
function _depositIntoERC4626Vault(IERC4626 vault, IERC20 asset, address from, uint256 amount, address receiver)
internal
returns (uint256)
{
if (from != address(this)) asset.safeTransferFrom(from, address(this), amount);
try vault.deposit(amount, receiver) returns (uint256 shares) {
return shares;
} catch {
// If deposit fails, it may have been because of lack of approval
asset.forceApprove(address(vault), type(uint256).max);
return vault.deposit(amount, receiver);
}
}
function _redeem(IERC4626 vaultWrapper, address underlyingVault, address from, uint256 amount, address receiver)
internal
returns (uint256)
{
uint256 underlyingVaultShares = _redeemFromERC4626Vault(vaultWrapper, from, amount, address(this));
return _redeemFromUnderlyingVault(address(underlyingVault), address(this), underlyingVaultShares, receiver);
}
/// @dev for aave wrapper, override this function
function _redeemFromUnderlyingVault(address underlyingVault, address from, uint256 amount, address receiver)
internal
virtual
returns (uint256)
{
return _redeemFromERC4626Vault(IERC4626(underlyingVault), from, amount, receiver);
}
/// @dev if from!=address(this) then they should have approve address(this) for amount of vault wrapper asset
function _redeemFromERC4626Vault(IERC4626 vault, address from, uint256 amount, address receiver)
internal
returns (uint256)
{
return vault.redeem(amount, receiver, from);
}
function _mint(
IERC4626 vaultWrapper,
address underlyingVault,
IERC20 asset,
address from,
uint256 amount,
address receiver
) internal returns (uint256 assetAmount) {
uint256 underlyingSharesNeeded = vaultWrapper.previewMint(amount);
assetAmount = _mintInUnderlyingVault(underlyingVault, asset, from, underlyingSharesNeeded, address(this));
_mintERC4626VaultShares(vaultWrapper, IERC20(underlyingVault), address(this), amount, receiver);
}
function _mintInUnderlyingVault(address vault, IERC20 asset, address from, uint256 amount, address receiver)
internal
virtual
returns (uint256)
{
return _mintERC4626VaultShares(IERC4626(vault), asset, from, amount, receiver);
}
function _mintERC4626VaultShares(IERC4626 vault, IERC20 asset, address from, uint256 amount, address receiver)
internal
returns (uint256)
{
if (from != address(this)) asset.safeTransferFrom(from, address(this), vault.previewMint(amount));
try vault.mint(amount, receiver) returns (uint256 shares) {
return shares;
} catch {
// If mint fails, it may have been because of lack of approval
asset.forceApprove(address(vault), type(uint256).max);
return vault.mint(amount, receiver);
}
}
function _withdraw(IERC4626 vaultWrapper, address underlyingVault, address from, uint256 amount, address receiver)
internal
returns (uint256 shares)
{
uint256 underlyingVaultSharesToWithdraw = vaultWrapper.previewWithdraw(amount);
shares = _withdrawFromERC4626Vault(vaultWrapper, from, amount, address(this));
return _withdrawFromUnderlyingVault(underlyingVault, address(this), underlyingVaultSharesToWithdraw, receiver);
}
function _withdrawFromUnderlyingVault(address underlyingVault, address from, uint256 amount, address receiver)
internal
virtual
returns (uint256)
{
return _withdrawFromERC4626Vault(IERC4626(underlyingVault), from, amount, receiver);
}
function _withdrawFromERC4626Vault(IERC4626 vault, address from, uint256 amount, address receiver)
internal
returns (uint256)
{
return vault.withdraw(amount, receiver, from);
}
function _getUnderlyingVault(IERC4626 vaultWrapper) internal view returns (IERC4626 underlyingVault) {
try vaultWrapper.asset() returns (address asset) {
underlyingVault = IERC4626(asset);
} catch {
underlyingVault = IERC4626(address(0));
}
return underlyingVault;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IEVC} from "../interfaces/IEthereumVaultConnector.sol";
import {ExecutionContext, EC} from "../ExecutionContext.sol";
/// @title EVCUtil
/// @custom:security-contact [email protected]
/// @author Euler Labs (https://www.eulerlabs.com/)
/// @notice This contract is an abstract base contract for interacting with the Ethereum Vault Connector (EVC).
/// It provides utility functions for authenticating the callers in the context of the EVC, a pattern for enforcing the
/// contracts to be called through the EVC.
abstract contract EVCUtil {
using ExecutionContext for EC;
uint160 internal constant ACCOUNT_ID_OFFSET = 8;
IEVC internal immutable evc;
error EVC_InvalidAddress();
error NotAuthorized();
error ControllerDisabled();
constructor(address _evc) {
if (_evc == address(0)) revert EVC_InvalidAddress();
evc = IEVC(_evc);
}
/// @notice Returns the address of the Ethereum Vault Connector (EVC) used by this contract.
/// @return The address of the EVC contract.
function EVC() external view virtual returns (address) {
return address(evc);
}
/// @notice Ensures that the msg.sender is the EVC by using the EVC callback functionality if necessary.
/// @dev Optional to use for functions requiring account and vault status checks to enforce predictable behavior.
/// @dev If this modifier used in conjuction with any other modifier, it must appear as the first (outermost)
/// modifier of the function.
modifier callThroughEVC() virtual {
_callThroughEVC();
_;
}
/// @notice Ensures that the caller is the EVC in the appropriate context.
/// @dev Should be used for checkAccountStatus and checkVaultStatus functions.
modifier onlyEVCWithChecksInProgress() virtual {
_onlyEVCWithChecksInProgress();
_;
}
/// @notice Ensures a standard authentication path on the EVC allowing the account owner or any of its EVC accounts.
/// @dev This modifier checks if the caller is the EVC and if so, verifies the execution context.
/// It reverts if the operator is authenticated, control collateral is in progress, or checks are in progress.
/// @dev This modifier must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This modifier must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This modifier can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
modifier onlyEVCAccount() virtual {
_authenticateCallerWithStandardContextState(false);
_;
}
/// @notice Ensures a standard authentication path on the EVC.
/// @dev This modifier checks if the caller is the EVC and if so, verifies the execution context.
/// It reverts if the operator is authenticated, control collateral is in progress, or checks are in progress.
/// It reverts if the authenticated account owner is known and it is not the account owner.
/// @dev It assumes that if the caller is not the EVC, the caller is the account owner.
/// @dev This modifier must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This modifier must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This modifier can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
modifier onlyEVCAccountOwner() virtual {
_authenticateCallerWithStandardContextState(true);
_;
}
/// @notice Checks whether the specified account and the other account have the same owner.
/// @dev The function is used to check whether one account is authorized to perform operations on behalf of the
/// other. Accounts are considered to have a common owner if they share the first 19 bytes of their address.
/// @param account The address of the account that is being checked.
/// @param otherAccount The address of the other account that is being checked.
/// @return A boolean flag that indicates whether the accounts have the same owner.
function _haveCommonOwner(address account, address otherAccount) internal pure returns (bool) {
bool result;
assembly {
result := lt(xor(account, otherAccount), 0x100)
}
return result;
}
/// @notice Returns the address prefix of the specified account.
/// @dev The address prefix is the first 19 bytes of the account address.
/// @param account The address of the account whose address prefix is being retrieved.
/// @return A bytes19 value that represents the address prefix of the account.
function _getAddressPrefix(address account) internal pure returns (bytes19) {
return bytes19(uint152(uint160(account) >> ACCOUNT_ID_OFFSET));
}
/// @notice Retrieves the message sender in the context of the EVC.
/// @dev This function returns the account on behalf of which the current operation is being performed, which is
/// either msg.sender or the account authenticated by the EVC.
/// @return The address of the message sender.
function _msgSender() internal view virtual returns (address) {
address sender = msg.sender;
if (sender == address(evc)) {
(sender,) = evc.getCurrentOnBehalfOfAccount(address(0));
}
return sender;
}
/// @notice Retrieves the message sender in the context of the EVC for a borrow operation.
/// @dev This function returns the account on behalf of which the current operation is being performed, which is
/// either msg.sender or the account authenticated by the EVC. This function reverts if this contract is not enabled
/// as a controller for the account on behalf of which the operation is being executed.
/// @return The address of the message sender.
function _msgSenderForBorrow() internal view virtual returns (address) {
address sender = msg.sender;
bool controllerEnabled;
if (sender == address(evc)) {
(sender, controllerEnabled) = evc.getCurrentOnBehalfOfAccount(address(this));
} else {
controllerEnabled = evc.isControllerEnabled(sender, address(this));
}
if (!controllerEnabled) {
revert ControllerDisabled();
}
return sender;
}
/// @notice Retrieves the message sender, ensuring it's any EVC account meaning that the execution context is in a
/// standard state (not operator authenticated, not control collateral in progress, not checks in progress).
/// @dev This function must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This function must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This function can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
/// @return The address of the message sender.
function _msgSenderOnlyEVCAccount() internal view returns (address) {
return _authenticateCallerWithStandardContextState(false);
}
/// @notice Retrieves the message sender, ensuring it's the EVC account owner and that the execution context is in a
/// standard state (not operator authenticated, not control collateral in progress, not checks in progress).
/// @dev It assumes that if the caller is not the EVC, the caller is the account owner.
/// @dev This function must not be used on functions utilized by liquidation flows, i.e. transfer or withdraw.
/// @dev This function must not be used on checkAccountStatus and checkVaultStatus functions.
/// @dev This function can be used on access controlled functions to prevent non-standard authentication paths on
/// the EVC.
/// @return The address of the message sender.
function _msgSenderOnlyEVCAccountOwner() internal view returns (address) {
return _authenticateCallerWithStandardContextState(true);
}
/// @notice Calls the current external function through the EVC.
/// @dev This function is used to route the current call through the EVC if it's not already coming from the EVC. It
/// makes the EVC set the execution context and call back this contract with unchanged calldata. msg.sender is used
/// as the onBehalfOfAccount.
/// @dev This function shall only be used by the callThroughEVC modifier.
function _callThroughEVC() internal {
address _evc = address(evc);
if (msg.sender == _evc) return;
assembly {
mstore(0, 0x1f8b521500000000000000000000000000000000000000000000000000000000) // EVC.call selector
mstore(4, address()) // EVC.call 1st argument - address(this)
mstore(36, caller()) // EVC.call 2nd argument - msg.sender
mstore(68, callvalue()) // EVC.call 3rd argument - msg.value
mstore(100, 128) // EVC.call 4th argument - msg.data, offset to the start of encoding - 128 bytes
mstore(132, calldatasize()) // msg.data length
calldatacopy(164, 0, calldatasize()) // original calldata
// abi encoded bytes array should be zero padded so its length is a multiple of 32
// store zero word after msg.data bytes and round up calldatasize to nearest multiple of 32
mstore(add(164, calldatasize()), 0)
let result := call(gas(), _evc, callvalue(), 0, add(164, and(add(calldatasize(), 31), not(31))), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 { revert(0, returndatasize()) }
default { return(64, sub(returndatasize(), 64)) } // strip bytes encoding from call return
}
}
/// @notice Ensures that the function is called only by the EVC during the checks phase
/// @dev Reverts if the caller is not the EVC or if checks are not in progress.
function _onlyEVCWithChecksInProgress() internal view {
if (msg.sender != address(evc) || !evc.areChecksInProgress()) {
revert NotAuthorized();
}
}
/// @notice Ensures that the function is called only by the EVC account owner or any of its EVC accounts
/// @dev This function checks if the caller is the EVC and if so, verifies that the execution context is not in a
/// special state (operator authenticated, collateral control in progress, or checks in progress). If
/// onlyAccountOwner is true and the owner was already registered on the EVC, it verifies that the onBehalfOfAccount
/// is the owner. If onlyAccountOwner is false, it allows any EVC account of the owner to call the function.
/// @param onlyAccountOwner If true, only allows the account owner; if false, allows any EVC account of the owner
/// @return The address of the message sender.
function _authenticateCallerWithStandardContextState(bool onlyAccountOwner) internal view returns (address) {
if (msg.sender == address(evc)) {
EC ec = EC.wrap(evc.getRawExecutionContext());
if (ec.isOperatorAuthenticated() || ec.isControlCollateralInProgress() || ec.areChecksInProgress()) {
revert NotAuthorized();
}
address onBehalfOfAccount = ec.getOnBehalfOfAccount();
if (onlyAccountOwner) {
address owner = evc.getAccountOwner(onBehalfOfAccount);
if (owner != address(0) && owner != onBehalfOfAccount) {
revert NotAuthorized();
}
}
return onBehalfOfAccount;
}
return msg.sender;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20Minimal} from "../interfaces/external/IERC20Minimal.sol";
import {CustomRevert} from "../libraries/CustomRevert.sol";
type Currency is address;
using {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global;
using CurrencyLibrary for Currency global;
function equals(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) == Currency.unwrap(other);
}
function greaterThan(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) > Currency.unwrap(other);
}
function lessThan(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) < Currency.unwrap(other);
}
function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) {
return Currency.unwrap(currency) >= Currency.unwrap(other);
}
/// @title CurrencyLibrary
/// @dev This library allows for transferring and holding native tokens and ERC20 tokens
library CurrencyLibrary {
/// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
error NativeTransferFailed();
/// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
error ERC20TransferFailed();
/// @notice A constant to represent the native currency
Currency public constant ADDRESS_ZERO = Currency.wrap(address(0));
function transfer(Currency currency, address to, uint256 amount) internal {
// altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol
// modified custom error selectors
bool success;
if (currency.isAddressZero()) {
assembly ("memory-safe") {
// Transfer the ETH and revert if it fails.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
// revert with NativeTransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
}
} else {
assembly ("memory-safe") {
// Get a pointer to some free memory.
let fmp := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(fmp, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success :=
and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), currency, 0, fmp, 68, 0, 32)
)
// Now clean the memory we used
mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
}
// revert with ERC20TransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(
Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector
);
}
}
}
function balanceOfSelf(Currency currency) internal view returns (uint256) {
if (currency.isAddressZero()) {
return address(this).balance;
} else {
return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this));
}
}
function balanceOf(Currency currency, address owner) internal view returns (uint256) {
if (currency.isAddressZero()) {
return owner.balance;
} else {
return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner);
}
}
function isAddressZero(Currency currency) internal pure returns (bool) {
return Currency.unwrap(currency) == Currency.unwrap(ADDRESS_ZERO);
}
function toId(Currency currency) internal pure returns (uint256) {
return uint160(Currency.unwrap(currency));
}
// If the upper 12 bytes are non-zero, they will be zero-ed out
// Therefore, fromId() and toId() are not inverses of each other
function fromId(uint256 id) internal pure returns (Currency) {
return Currency.wrap(address(uint160(id)));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "./Currency.sol";
import {IHooks} from "../interfaces/IHooks.sol";
import {PoolIdLibrary} from "./PoolId.sol";
using PoolIdLibrary for PoolKey global;
/// @notice Returns the key for identifying a pool
struct PoolKey {
/// @notice The lower currency of the pool, sorted numerically
Currency currency0;
/// @notice The higher currency of the pool, sorted numerically
Currency currency1;
/// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000
uint24 fee;
/// @notice Ticks that involve positions must be a multiple of tick spacing
int24 tickSpacing;
/// @notice The hooks of the pool
IHooks hooks;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.sol";
import {BeforeSwapDelta} from "../types/BeforeSwapDelta.sol";
/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits
/// of the address that the hooks contract is deployed to.
/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400
/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.
/// See the Hooks library for the full spec.
/// @dev Should only be callable by the v4 PoolManager.
interface IHooks {
/// @notice The hook called before the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @return bytes4 The function selector for the hook
function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4);
/// @notice The hook called after the state of a pool is initialized
/// @param sender The initial msg.sender for the initialize call
/// @param key The key for the pool being initialized
/// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
/// @param tick The current tick after the state of a pool is initialized
/// @return bytes4 The function selector for the hook
function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
external
returns (bytes4);
/// @notice The hook called before liquidity is added
/// @param sender The initial msg.sender for the add liquidity call
/// @param key The key for the pool
/// @param params The parameters for adding liquidity
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeAddLiquidity(
address sender,
PoolKey calldata key,
ModifyLiquidityParams calldata params,
bytes calldata hookData
) external returns (bytes4);
/// @notice The hook called after liquidity is added
/// @param sender The initial msg.sender for the add liquidity call
/// @param key The key for the pool
/// @param params The parameters for adding liquidity
/// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta
/// @param feesAccrued The fees accrued since the last time fees were collected from this position
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
function afterAddLiquidity(
address sender,
PoolKey calldata key,
ModifyLiquidityParams calldata params,
BalanceDelta delta,
BalanceDelta feesAccrued,
bytes calldata hookData
) external returns (bytes4, BalanceDelta);
/// @notice The hook called before liquidity is removed
/// @param sender The initial msg.sender for the remove liquidity call
/// @param key The key for the pool
/// @param params The parameters for removing liquidity
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeRemoveLiquidity(
address sender,
PoolKey calldata key,
ModifyLiquidityParams calldata params,
bytes calldata hookData
) external returns (bytes4);
/// @notice The hook called after liquidity is removed
/// @param sender The initial msg.sender for the remove liquidity call
/// @param key The key for the pool
/// @param params The parameters for removing liquidity
/// @param delta The caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta
/// @param feesAccrued The fees accrued since the last time fees were collected from this position
/// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
function afterRemoveLiquidity(
address sender,
PoolKey calldata key,
ModifyLiquidityParams calldata params,
BalanceDelta delta,
BalanceDelta feesAccrued,
bytes calldata hookData
) external returns (bytes4, BalanceDelta);
/// @notice The hook called before a swap
/// @param sender The initial msg.sender for the swap call
/// @param key The key for the pool
/// @param params The parameters for the swap
/// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
/// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)
function beforeSwap(address sender, PoolKey calldata key, SwapParams calldata params, bytes calldata hookData)
external
returns (bytes4, BeforeSwapDelta, uint24);
/// @notice The hook called after a swap
/// @param sender The initial msg.sender for the swap call
/// @param key The key for the pool
/// @param params The parameters for the swap
/// @param delta The amount owed to the caller (positive) or owed to the pool (negative)
/// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
/// @return bytes4 The function selector for the hook
/// @return int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
function afterSwap(
address sender,
PoolKey calldata key,
SwapParams calldata params,
BalanceDelta delta,
bytes calldata hookData
) external returns (bytes4, int128);
/// @notice The hook called before donate
/// @param sender The initial msg.sender for the donate call
/// @param key The key for the pool
/// @param amount0 The amount of token0 being donated
/// @param amount1 The amount of token1 being donated
/// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function beforeDonate(
address sender,
PoolKey calldata key,
uint256 amount0,
uint256 amount1,
bytes calldata hookData
) external returns (bytes4);
/// @notice The hook called after donate
/// @param sender The initial msg.sender for the donate call
/// @param key The key for the pool
/// @param amount0 The amount of token0 being donated
/// @param amount1 The amount of token1 being donated
/// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
/// @return bytes4 The function selector for the hook
function afterDonate(
address sender,
PoolKey calldata key,
uint256 amount0,
uint256 amount1,
bytes calldata hookData
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PositionInfo} from "../libraries/PositionInfoLibrary.sol";
import {INotifier} from "./INotifier.sol";
import {IImmutableState} from "./IImmutableState.sol";
import {IERC721Permit_v4} from "./IERC721Permit_v4.sol";
import {IEIP712_v4} from "./IEIP712_v4.sol";
import {IMulticall_v4} from "./IMulticall_v4.sol";
import {IPoolInitializer_v4} from "./IPoolInitializer_v4.sol";
import {IUnorderedNonce} from "./IUnorderedNonce.sol";
import {IPermit2Forwarder} from "./IPermit2Forwarder.sol";
/// @title IPositionManager
/// @notice Interface for the PositionManager contract
interface IPositionManager is
INotifier,
IImmutableState,
IERC721Permit_v4,
IEIP712_v4,
IMulticall_v4,
IPoolInitializer_v4,
IUnorderedNonce,
IPermit2Forwarder
{
/// @notice Thrown when the caller is not approved to modify a position
error NotApproved(address caller);
/// @notice Thrown when the block.timestamp exceeds the user-provided deadline
error DeadlinePassed(uint256 deadline);
/// @notice Thrown when calling transfer, subscribe, or unsubscribe when the PoolManager is unlocked.
/// @dev This is to prevent hooks from being able to trigger notifications at the same time the position is being modified.
error PoolManagerMustBeLocked();
/// @notice Unlocks Uniswap v4 PoolManager and batches actions for modifying liquidity
/// @dev This is the standard entrypoint for the PositionManager
/// @param unlockData is an encoding of actions, and parameters for those actions
/// @param deadline is the deadline for the batched actions to be executed
function modifyLiquidities(bytes calldata unlockData, uint256 deadline) external payable;
/// @notice Batches actions for modifying liquidity without unlocking v4 PoolManager
/// @dev This must be called by a contract that has already unlocked the v4 PoolManager
/// @param actions the actions to perform
/// @param params the parameters to provide for the actions
function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params) external payable;
/// @notice Used to get the ID that will be used for the next minted liquidity position
/// @return uint256 The next token ID
function nextTokenId() external view returns (uint256);
/// @notice Returns the liquidity of a position
/// @param tokenId the ERC721 tokenId
/// @return liquidity the position's liquidity, as a liquidityAmount
/// @dev this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library
function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity);
/// @notice Returns the pool key and position info of a position
/// @param tokenId the ERC721 tokenId
/// @return poolKey the pool key of the position
/// @return PositionInfo a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
function getPoolAndPositionInfo(uint256 tokenId) external view returns (PoolKey memory, PositionInfo);
/// @notice Returns the position info of a position
/// @param tokenId the ERC721 tokenId
/// @return a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
function positionInfo(uint256 tokenId) external view returns (PositionInfo);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Library to define different pool actions.
/// @dev These are suggested common commands, however additional commands should be defined as required
/// Some of these actions are not supported in the Router contracts or Position Manager contracts, but are left as they may be helpful commands for other peripheral contracts.
library Actions {
// pool actions
// liquidity actions
uint256 internal constant INCREASE_LIQUIDITY = 0x00;
uint256 internal constant DECREASE_LIQUIDITY = 0x01;
uint256 internal constant MINT_POSITION = 0x02;
uint256 internal constant BURN_POSITION = 0x03;
uint256 internal constant INCREASE_LIQUIDITY_FROM_DELTAS = 0x04;
uint256 internal constant MINT_POSITION_FROM_DELTAS = 0x05;
// swapping
uint256 internal constant SWAP_EXACT_IN_SINGLE = 0x06;
uint256 internal constant SWAP_EXACT_IN = 0x07;
uint256 internal constant SWAP_EXACT_OUT_SINGLE = 0x08;
uint256 internal constant SWAP_EXACT_OUT = 0x09;
// donate
// note this is not supported in the position manager or router
uint256 internal constant DONATE = 0x0a;
// closing deltas on the pool manager
// settling
uint256 internal constant SETTLE = 0x0b;
uint256 internal constant SETTLE_ALL = 0x0c;
uint256 internal constant SETTLE_PAIR = 0x0d;
// taking
uint256 internal constant TAKE = 0x0e;
uint256 internal constant TAKE_ALL = 0x0f;
uint256 internal constant TAKE_PORTION = 0x10;
uint256 internal constant TAKE_PAIR = 0x11;
uint256 internal constant CLOSE_CURRENCY = 0x12;
uint256 internal constant CLEAR_OR_TAKE = 0x13;
uint256 internal constant SWEEP = 0x14;
uint256 internal constant WRAP = 0x15;
uint256 internal constant UNWRAP = 0x16;
// minting/burning 6909s to close deltas
// note this is not supported in the position manager or router
uint256 internal constant MINT_6909 = 0x17;
uint256 internal constant BURN_6909 = 0x18;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Action Constants
/// @notice Common constants used in actions
/// @dev Constants are gas efficient alternatives to their literal values
library ActionConstants {
/// @notice used to signal that an action should use the input value of the open delta on the pool manager
/// or of the balance that the contract holds
uint128 internal constant OPEN_DELTA = 0;
/// @notice used to signal that an action should use the contract's entire balance of a currency
/// This value is equivalent to 1<<255, i.e. a singular 1 in the most significant bit.
uint256 internal constant CONTRACT_BALANCE = 0x8000000000000000000000000000000000000000000000000000000000000000;
/// @notice used to signal that the recipient of an action should be the msgSender
address internal constant MSG_SENDER = address(1);
/// @notice used to signal that the recipient of an action should be the address(this)
address internal constant ADDRESS_THIS = address(2);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title IWETH9
interface IWETH9 is IERC20 {
/// @notice Deposit ether to get wrapped ether
function deposit() external payable;
/// @notice Withdraw wrapped ether to get ether
function withdraw(uint256) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity >=0.6.2;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title IEVC /// @custom:security-contact [email protected] /// @author Euler Labs (https://www.eulerlabs.com/) /// @notice This interface defines the methods for the Ethereum Vault Connector. interface IEVC { /// @notice A struct representing a batch item. /// @dev Each batch item represents a single operation to be performed within a checks deferred context. struct BatchItem { /// @notice The target contract to be called. address targetContract; /// @notice The account on behalf of which the operation is to be performed. msg.sender must be authorized to /// act on behalf of this account. Must be address(0) if the target contract is the EVC itself. address onBehalfOfAccount; /// @notice The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. Must be 0 if the target contract is the EVC itself. uint256 value; /// @notice The encoded data which is called on the target contract. bytes data; } /// @notice A struct representing the result of a batch item operation. /// @dev Used only for simulation purposes. struct BatchItemResult { /// @notice A boolean indicating whether the operation was successful. bool success; /// @notice The result of the operation. bytes result; } /// @notice A struct representing the result of the account or vault status check. /// @dev Used only for simulation purposes. struct StatusCheckResult { /// @notice The address of the account or vault for which the check was performed. address checkedAddress; /// @notice A boolean indicating whether the status of the account or vault is valid. bool isValid; /// @notice The result of the check. bytes result; } /// @notice Returns current raw execution context. /// @dev When checks in progress, on behalf of account is always address(0). /// @return context Current raw execution context. function getRawExecutionContext() external view returns (uint256 context); /// @notice Returns an account on behalf of which the operation is being executed at the moment and whether the /// controllerToCheck is an enabled controller for that account. /// @dev This function should only be used by external smart contracts if msg.sender is the EVC. Otherwise, the /// account address returned must not be trusted. /// @dev When checks in progress, on behalf of account is always address(0). When address is zero, the function /// reverts to protect the consumer from ever relying on the on behalf of account address which is in its default /// state. /// @param controllerToCheck The address of the controller for which it is checked whether it is an enabled /// controller for the account on behalf of which the operation is being executed at the moment. /// @return onBehalfOfAccount An account that has been authenticated and on behalf of which the operation is being /// executed at the moment. /// @return controllerEnabled A boolean value that indicates whether controllerToCheck is an enabled controller for /// the account on behalf of which the operation is being executed at the moment. Always false if controllerToCheck /// is address(0). function getCurrentOnBehalfOfAccount(address controllerToCheck) external view returns (address onBehalfOfAccount, bool controllerEnabled); /// @notice Checks if checks are deferred. /// @return A boolean indicating whether checks are deferred. function areChecksDeferred() external view returns (bool); /// @notice Checks if checks are in progress. /// @return A boolean indicating whether checks are in progress. function areChecksInProgress() external view returns (bool); /// @notice Checks if control collateral is in progress. /// @return A boolean indicating whether control collateral is in progress. function isControlCollateralInProgress() external view returns (bool); /// @notice Checks if an operator is authenticated. /// @return A boolean indicating whether an operator is authenticated. function isOperatorAuthenticated() external view returns (bool); /// @notice Checks if a simulation is in progress. /// @return A boolean indicating whether a simulation is in progress. function isSimulationInProgress() external view returns (bool); /// @notice Checks whether the specified account and the other account have the same owner. /// @dev The function is used to check whether one account is authorized to perform operations on behalf of the /// other. Accounts are considered to have a common owner if they share the first 19 bytes of their address. /// @param account The address of the account that is being checked. /// @param otherAccount The address of the other account that is being checked. /// @return A boolean flag that indicates whether the accounts have the same owner. function haveCommonOwner(address account, address otherAccount) external pure returns (bool); /// @notice Returns the address prefix of the specified account. /// @dev The address prefix is the first 19 bytes of the account address. /// @param account The address of the account whose address prefix is being retrieved. /// @return A bytes19 value that represents the address prefix of the account. function getAddressPrefix(address account) external pure returns (bytes19); /// @notice Returns the owner for the specified account. /// @dev The function returns address(0) if the owner is not registered. Registration of the owner happens on the /// initial /// interaction with the EVC that requires authentication of an owner. /// @param account The address of the account whose owner is being retrieved. /// @return owner The address of the account owner. An account owner is an EOA/smart contract which address matches /// the first 19 bytes of the account address. function getAccountOwner(address account) external view returns (address); /// @notice Checks if lockdown mode is enabled for a given address prefix. /// @param addressPrefix The address prefix to check for lockdown mode status. /// @return A boolean indicating whether lockdown mode is enabled. function isLockdownMode(bytes19 addressPrefix) external view returns (bool); /// @notice Checks if permit functionality is disabled for a given address prefix. /// @param addressPrefix The address prefix to check for permit functionality status. /// @return A boolean indicating whether permit functionality is disabled. function isPermitDisabledMode(bytes19 addressPrefix) external view returns (bool); /// @notice Returns the current nonce for a given address prefix and nonce namespace. /// @dev Each nonce namespace provides 256 bit nonce that has to be used sequentially. There's no requirement to use /// all the nonces for a given nonce namespace before moving to the next one which allows to use permit messages in /// a non-sequential manner. /// @param addressPrefix The address prefix for which the nonce is being retrieved. /// @param nonceNamespace The nonce namespace for which the nonce is being retrieved. /// @return nonce The current nonce for the given address prefix and nonce namespace. function getNonce(bytes19 addressPrefix, uint256 nonceNamespace) external view returns (uint256 nonce); /// @notice Returns the bit field for a given address prefix and operator. /// @dev The bit field is used to store information about authorized operators for a given address prefix. Each bit /// in the bit field corresponds to one account belonging to the same owner. If the bit is set, the operator is /// authorized for the account. /// @param addressPrefix The address prefix for which the bit field is being retrieved. /// @param operator The address of the operator for which the bit field is being retrieved. /// @return operatorBitField The bit field for the given address prefix and operator. The bit field defines which /// accounts the operator is authorized for. It is a 256-position binary array like 0...010...0, marking the account /// positionally in a uint256. The position in the bit field corresponds to the account ID (0-255), where 0 is the /// owner account's ID. function getOperator(bytes19 addressPrefix, address operator) external view returns (uint256 operatorBitField); /// @notice Returns whether a given operator has been authorized for a given account. /// @param account The address of the account whose operator is being checked. /// @param operator The address of the operator that is being checked. /// @return authorized A boolean value that indicates whether the operator is authorized for the account. function isAccountOperatorAuthorized(address account, address operator) external view returns (bool authorized); /// @notice Enables or disables lockdown mode for a given address prefix. /// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC /// must be called directly. It is not possible to disable this mode by using checks-deferrable call or /// permit message. /// @param addressPrefix The address prefix for which the lockdown mode is being set. /// @param enabled A boolean indicating whether to enable or disable lockdown mode. function setLockdownMode(bytes19 addressPrefix, bool enabled) external payable; /// @notice Enables or disables permit functionality for a given address prefix. /// @dev This function can only be called by the owner of the address prefix. To disable this mode, the EVC /// must be called directly. It is not possible to disable this mode by using checks-deferrable call or (by /// definition) permit message. To support permit functionality by default, note that the logic was inverted here. To /// disable the permit functionality, one must pass true as the second argument. To enable the permit /// functionality, one must pass false as the second argument. /// @param addressPrefix The address prefix for which the permit functionality is being set. /// @param enabled A boolean indicating whether to enable or disable the disable-permit mode. function setPermitDisabledMode(bytes19 addressPrefix, bool enabled) external payable; /// @notice Sets the nonce for a given address prefix and nonce namespace. /// @dev This function can only be called by the owner of the address prefix. Each nonce namespace provides a 256 /// bit nonce that has to be used sequentially. There's no requirement to use all the nonces for a given nonce /// namespace before moving to the next one which allows the use of permit messages in a non-sequential manner. To /// invalidate signed permit messages, set the nonce for a given nonce namespace accordingly. To invalidate all the /// permit messages for a given nonce namespace, set the nonce to type(uint).max. /// @param addressPrefix The address prefix for which the nonce is being set. /// @param nonceNamespace The nonce namespace for which the nonce is being set. /// @param nonce The new nonce for the given address prefix and nonce namespace. function setNonce(bytes19 addressPrefix, uint256 nonceNamespace, uint256 nonce) external payable; /// @notice Sets the bit field for a given address prefix and operator. /// @dev This function can only be called by the owner of the address prefix. Each bit in the bit field corresponds /// to one account belonging to the same owner. If the bit is set, the operator is authorized for the account. /// @param addressPrefix The address prefix for which the bit field is being set. /// @param operator The address of the operator for which the bit field is being set. Can neither be the EVC address /// nor an address belonging to the same address prefix. /// @param operatorBitField The new bit field for the given address prefix and operator. Reverts if the provided /// value is equal to the currently stored value. function setOperator(bytes19 addressPrefix, address operator, uint256 operatorBitField) external payable; /// @notice Authorizes or deauthorizes an operator for the account. /// @dev Only the owner or authorized operator of the account can call this function. An operator is an address that /// can perform actions for an account on behalf of the owner. If it's an operator calling this function, it can /// only deauthorize itself. /// @param account The address of the account whose operator is being set or unset. /// @param operator The address of the operator that is being installed or uninstalled. Can neither be the EVC /// address nor an address belonging to the same owner as the account. /// @param authorized A boolean value that indicates whether the operator is being authorized or deauthorized. /// Reverts if the provided value is equal to the currently stored value. function setAccountOperator(address account, address operator, bool authorized) external payable; /// @notice Returns an array of collaterals enabled for an account. /// @dev A collateral is a vault for which an account's balances are under the control of the currently enabled /// controller vault. /// @param account The address of the account whose collaterals are being queried. /// @return An array of addresses that are enabled collaterals for the account. function getCollaterals(address account) external view returns (address[] memory); /// @notice Returns whether a collateral is enabled for an account. /// @dev A collateral is a vault for which account's balances are under the control of the currently enabled /// controller vault. /// @param account The address of the account that is being checked. /// @param vault The address of the collateral that is being checked. /// @return A boolean value that indicates whether the vault is an enabled collateral for the account or not. function isCollateralEnabled(address account, address vault) external view returns (bool); /// @notice Enables a collateral for an account. /// @dev A collaterals is a vault for which account's balances are under the control of the currently enabled /// controller vault. Only the owner or an operator of the account can call this function. Unless it's a duplicate, /// the collateral is added to the end of the array. There can be at most 10 unique collaterals enabled at a time. /// Account status checks are performed. /// @param account The account address for which the collateral is being enabled. /// @param vault The address being enabled as a collateral. function enableCollateral(address account, address vault) external payable; /// @notice Disables a collateral for an account. /// @dev This function does not preserve the order of collaterals in the array obtained using the getCollaterals /// function; the order may change. A collateral is a vault for which account’s balances are under the control of /// the currently enabled controller vault. Only the owner or an operator of the account can call this function. /// Disabling a collateral might change the order of collaterals in the array obtained using getCollaterals /// function. Account status checks are performed. /// @param account The account address for which the collateral is being disabled. /// @param vault The address of a collateral being disabled. function disableCollateral(address account, address vault) external payable; /// @notice Swaps the position of two collaterals so that they appear switched in the array of collaterals for a /// given account obtained by calling getCollaterals function. /// @dev A collateral is a vault for which account’s balances are under the control of the currently enabled /// controller vault. Only the owner or an operator of the account can call this function. The order of collaterals /// can be changed by specifying the indices of the two collaterals to be swapped. Indices are zero-based and must /// be in the range of 0 to the number of collaterals minus 1. index1 must be lower than index2. Account status /// checks are performed. /// @param account The address of the account for which the collaterals are being reordered. /// @param index1 The index of the first collateral to be swapped. /// @param index2 The index of the second collateral to be swapped. function reorderCollaterals(address account, uint8 index1, uint8 index2) external payable; /// @notice Returns an array of enabled controllers for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over the account's /// balances in enabled collaterals vaults. A user can have multiple controllers during a call execution, but at /// most one can be selected when the account status check is performed. /// @param account The address of the account whose controllers are being queried. /// @return An array of addresses that are the enabled controllers for the account. function getControllers(address account) external view returns (address[] memory); /// @notice Returns whether a controller is enabled for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over account’s /// balances in the enabled collaterals vaults. /// @param account The address of the account that is being checked. /// @param vault The address of the controller that is being checked. /// @return A boolean value that indicates whether the vault is enabled controller for the account or not. function isControllerEnabled(address account, address vault) external view returns (bool); /// @notice Enables a controller for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over account’s /// balances in the enabled collaterals vaults. Only the owner or an operator of the account can call this function. /// Unless it's a duplicate, the controller is added to the end of the array. Transiently, there can be at most 10 /// unique controllers enabled at a time, but at most one can be enabled after the outermost checks-deferrable /// call concludes. Account status checks are performed. /// @param account The address for which the controller is being enabled. /// @param vault The address of the controller being enabled. function enableController(address account, address vault) external payable; /// @notice Disables a controller for an account. /// @dev A controller is a vault that has been chosen for an account to have special control over account’s /// balances in the enabled collaterals vaults. Only the vault itself can call this function. Disabling a controller /// might change the order of controllers in the array obtained using getControllers function. Account status checks /// are performed. /// @param account The address for which the calling controller is being disabled. function disableController(address account) external payable; /// @notice Executes signed arbitrary data by self-calling into the EVC. /// @dev Low-level call function is used to execute the arbitrary data signed by the owner or the operator on the /// EVC contract. During that call, EVC becomes msg.sender. /// @param signer The address signing the permit message (ECDSA) or verifying the permit message signature /// (ERC-1271). It's also the owner or the operator of all the accounts for which authentication will be needed /// during the execution of the arbitrary data call. /// @param sender The address of the msg.sender which is expected to execute the data signed by the signer. If /// address(0) is passed, the msg.sender is ignored. /// @param nonceNamespace The nonce namespace for which the nonce is being used. /// @param nonce The nonce for the given account and nonce namespace. A valid nonce value is considered to be the /// value currently stored and can take any value between 0 and type(uint256).max - 1. /// @param deadline The timestamp after which the permit is considered expired. /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. /// @param data The encoded data which is self-called on the EVC contract. /// @param signature The signature of the data signed by the signer. function permit( address signer, address sender, uint256 nonceNamespace, uint256 nonce, uint256 deadline, uint256 value, bytes calldata data, bytes calldata signature ) external payable; /// @notice Calls into a target contract as per data encoded. /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost /// call ends, the account and vault status checks are performed. /// @dev This function can be used to interact with any contract while checks are deferred. If the target contract /// is msg.sender, msg.sender is called back with the calldata provided and the context set up according to the /// account provided. If the target contract is not msg.sender, only the owner or the operator of the account /// provided can call this function. /// @dev This function can be used to recover the remaining value from the EVC contract. /// @param targetContract The address of the contract to be called. /// @param onBehalfOfAccount If the target contract is msg.sender, the address of the account which will be set /// in the context. It assumes msg.sender has authenticated the account themselves. If the target contract is /// not msg.sender, the address of the account for which it is checked whether msg.sender is authorized to act /// on behalf of. /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. /// @param data The encoded data which is called on the target contract. /// @return result The result of the call. function call( address targetContract, address onBehalfOfAccount, uint256 value, bytes calldata data ) external payable returns (bytes memory result); /// @notice For a given account, calls into one of the enabled collateral vaults from the currently enabled /// controller vault as per data encoded. /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost /// call ends, the account and vault status checks are performed. /// @dev This function can be used to interact with any contract while checks are deferred as long as the contract /// is enabled as a collateral of the account and the msg.sender is the only enabled controller of the account. /// @param targetCollateral The collateral address to be called. /// @param onBehalfOfAccount The address of the account for which it is checked whether msg.sender is authorized to /// act on behalf. /// @param value The amount of value to be forwarded with the call. If the value is type(uint256).max, the whole /// balance of the EVC contract will be forwarded. /// @param data The encoded data which is called on the target collateral. /// @return result The result of the call. function controlCollateral( address targetCollateral, address onBehalfOfAccount, uint256 value, bytes calldata data ) external payable returns (bytes memory result); /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided. /// @dev This function defers the account and vault status checks (it's a checks-deferrable call). If the outermost /// call ends, the account and vault status checks are performed. /// @dev The authentication rules for each batch item are the same as for the call function. /// @param items An array of batch items to be executed. function batch(BatchItem[] calldata items) external payable; /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided. /// @dev This function always reverts as it's only used for simulation purposes. This function cannot be called /// within a checks-deferrable call. /// @param items An array of batch items to be executed. function batchRevert(BatchItem[] calldata items) external payable; /// @notice Executes multiple calls into the target contracts while checks deferred as per batch items provided. /// @dev This function does not modify state and should only be used for simulation purposes. This function cannot /// be called within a checks-deferrable call. /// @param items An array of batch items to be executed. /// @return batchItemsResult An array of batch item results for each item. /// @return accountsStatusCheckResult An array of account status check results for each account. /// @return vaultsStatusCheckResult An array of vault status check results for each vault. function batchSimulation(BatchItem[] calldata items) external payable returns ( BatchItemResult[] memory batchItemsResult, StatusCheckResult[] memory accountsStatusCheckResult, StatusCheckResult[] memory vaultsStatusCheckResult ); /// @notice Retrieves the timestamp of the last successful account status check performed for a specific account. /// @dev This function reverts if the checks are in progress. /// @dev The account status check is considered to be successful if it calls into the selected controller vault and /// obtains expected magic value. This timestamp does not change if the account status is considered valid when no /// controller enabled. When consuming, one might need to ensure that the account status check is not deferred at /// the moment. /// @param account The address of the account for which the last status check timestamp is being queried. /// @return The timestamp of the last status check as a uint256. function getLastAccountStatusCheckTimestamp(address account) external view returns (uint256); /// @notice Checks whether the status check is deferred for a given account. /// @dev This function reverts if the checks are in progress. /// @param account The address of the account for which it is checked whether the status check is deferred. /// @return A boolean flag that indicates whether the status check is deferred or not. function isAccountStatusCheckDeferred(address account) external view returns (bool); /// @notice Checks the status of an account and reverts if it is not valid. /// @dev If checks deferred, the account is added to the set of accounts to be checked at the end of the outermost /// checks-deferrable call. There can be at most 10 unique accounts added to the set at a time. Account status /// check is performed by calling into the selected controller vault and passing the array of currently enabled /// collaterals. If controller is not selected, the account is always considered valid. /// @param account The address of the account to be checked. function requireAccountStatusCheck(address account) external payable; /// @notice Forgives previously deferred account status check. /// @dev Account address is removed from the set of addresses for which status checks are deferred. This function /// can only be called by the currently enabled controller of a given account. Depending on the vault /// implementation, may be needed in the liquidation flow. /// @param account The address of the account for which the status check is forgiven. function forgiveAccountStatusCheck(address account) external payable; /// @notice Checks whether the status check is deferred for a given vault. /// @dev This function reverts if the checks are in progress. /// @param vault The address of the vault for which it is checked whether the status check is deferred. /// @return A boolean flag that indicates whether the status check is deferred or not. function isVaultStatusCheckDeferred(address vault) external view returns (bool); /// @notice Checks the status of a vault and reverts if it is not valid. /// @dev If checks deferred, the vault is added to the set of vaults to be checked at the end of the outermost /// checks-deferrable call. There can be at most 10 unique vaults added to the set at a time. This function can /// only be called by the vault itself. function requireVaultStatusCheck() external payable; /// @notice Forgives previously deferred vault status check. /// @dev Vault address is removed from the set of addresses for which status checks are deferred. This function can /// only be called by the vault itself. function forgiveVaultStatusCheck() external payable; /// @notice Checks the status of an account and a vault and reverts if it is not valid. /// @dev If checks deferred, the account and the vault are added to the respective sets of accounts and vaults to be /// checked at the end of the outermost checks-deferrable call. Account status check is performed by calling into /// selected controller vault and passing the array of currently enabled collaterals. If controller is not selected, /// the account is always considered valid. This function can only be called by the vault itself. /// @param account The address of the account to be checked. function requireAccountAndVaultStatusCheck(address account) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; type EC is uint256; /// @title ExecutionContext /// @custom:security-contact [email protected] /// @author Euler Labs (https://www.eulerlabs.com/) /// @notice This library provides functions for managing the execution context in the Ethereum Vault Connector. /// @dev The execution context is a bit field that stores the following information: /// @dev - on behalf of account - an account on behalf of which the currently executed operation is being performed /// @dev - checks deferred flag - used to indicate whether checks are deferred /// @dev - checks in progress flag - used to indicate that the account/vault status checks are in progress. This flag is /// used to prevent re-entrancy. /// @dev - control collateral in progress flag - used to indicate that the control collateral is in progress. This flag /// is used to prevent re-entrancy. /// @dev - operator authenticated flag - used to indicate that the currently executed operation is being performed by /// the account operator /// @dev - simulation flag - used to indicate that the currently executed batch call is a simulation /// @dev - stamp - dummy value for optimization purposes library ExecutionContext { uint256 internal constant ON_BEHALF_OF_ACCOUNT_MASK = 0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; uint256 internal constant CHECKS_DEFERRED_MASK = 0x0000000000000000000000FF0000000000000000000000000000000000000000; uint256 internal constant CHECKS_IN_PROGRESS_MASK = 0x00000000000000000000FF000000000000000000000000000000000000000000; uint256 internal constant CONTROL_COLLATERAL_IN_PROGRESS_LOCK_MASK = 0x000000000000000000FF00000000000000000000000000000000000000000000; uint256 internal constant OPERATOR_AUTHENTICATED_MASK = 0x0000000000000000FF0000000000000000000000000000000000000000000000; uint256 internal constant SIMULATION_MASK = 0x00000000000000FF000000000000000000000000000000000000000000000000; uint256 internal constant STAMP_OFFSET = 200; // None of the functions below modifies the state. All the functions operate on the copy // of the execution context and return its modified value as a result. In order to update // one should use the result of the function call as a new execution context value. function getOnBehalfOfAccount(EC self) internal pure returns (address result) { result = address(uint160(EC.unwrap(self) & ON_BEHALF_OF_ACCOUNT_MASK)); } function setOnBehalfOfAccount(EC self, address account) internal pure returns (EC result) { result = EC.wrap((EC.unwrap(self) & ~ON_BEHALF_OF_ACCOUNT_MASK) | uint160(account)); } function areChecksDeferred(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & CHECKS_DEFERRED_MASK != 0; } function setChecksDeferred(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | CHECKS_DEFERRED_MASK); } function areChecksInProgress(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & CHECKS_IN_PROGRESS_MASK != 0; } function setChecksInProgress(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | CHECKS_IN_PROGRESS_MASK); } function isControlCollateralInProgress(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & CONTROL_COLLATERAL_IN_PROGRESS_LOCK_MASK != 0; } function setControlCollateralInProgress(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | CONTROL_COLLATERAL_IN_PROGRESS_LOCK_MASK); } function isOperatorAuthenticated(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & OPERATOR_AUTHENTICATED_MASK != 0; } function setOperatorAuthenticated(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | OPERATOR_AUTHENTICATED_MASK); } function clearOperatorAuthenticated(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) & ~OPERATOR_AUTHENTICATED_MASK); } function isSimulationInProgress(EC self) internal pure returns (bool result) { result = EC.unwrap(self) & SIMULATION_MASK != 0; } function setSimulationInProgress(EC self) internal pure returns (EC result) { result = EC.wrap(EC.unwrap(self) | SIMULATION_MASK); } }
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Minimal ERC20 interface for Uniswap
/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3
interface IERC20Minimal {
/// @notice Returns an account's balance in the token
/// @param account The account for which to look up the number of tokens it has, i.e. its balance
/// @return The number of tokens held by the account
function balanceOf(address account) external view returns (uint256);
/// @notice Transfers the amount of token from the `msg.sender` to the recipient
/// @param recipient The account that will receive the amount transferred
/// @param amount The number of tokens to send from the sender to the recipient
/// @return Returns true for a successful transfer, false for an unsuccessful transfer
function transfer(address recipient, uint256 amount) external returns (bool);
/// @notice Returns the current allowance given to a spender by an owner
/// @param owner The account of the token owner
/// @param spender The account of the token spender
/// @return The current allowance granted by `owner` to `spender`
function allowance(address owner, address spender) external view returns (uint256);
/// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`
/// @param spender The account which will be allowed to spend a given amount of the owners tokens
/// @param amount The amount of tokens allowed to be used by `spender`
/// @return Returns true for a successful approval, false for unsuccessful
function approve(address spender, uint256 amount) external returns (bool);
/// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`
/// @param sender The account from which the transfer will be initiated
/// @param recipient The recipient of the transfer
/// @param amount The amount of the transfer
/// @return Returns true for a successful transfer, false for unsuccessful
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.
/// @param from The account from which the tokens were sent, i.e. the balance decreased
/// @param to The account to which the tokens were sent, i.e. the balance increased
/// @param value The amount of tokens that were transferred
event Transfer(address indexed from, address indexed to, uint256 value);
/// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.
/// @param owner The account that approved spending of its tokens
/// @param spender The account for which the spending allowance was modified
/// @param value The new allowance from the owner to the spender
event Approval(address indexed owner, address indexed spender, uint256 value);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with
/// `CustomError.selector.revertWith()`
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
/// @dev ERC-7751 error for wrapping bubbled up reverts
error WrappedError(address target, bytes4 selector, bytes reason, bytes details);
/// @dev Reverts with the selector of a custom error in the scratch space
function revertWith(bytes4 selector) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
revert(0, 0x04)
}
}
/// @dev Reverts with a custom error with an address argument in the scratch space
function revertWith(bytes4 selector, address addr) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with an int24 argument in the scratch space
function revertWith(bytes4 selector, int24 value) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, signextend(2, value))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with a uint160 argument in the scratch space
function revertWith(bytes4 selector, uint160 value) internal pure {
assembly ("memory-safe") {
mstore(0, selector)
mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with two int24 arguments
function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), signextend(2, value1))
mstore(add(fmp, 0x24), signextend(2, value2))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two uint160 arguments
function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two address arguments
function revertWith(bytes4 selector, address value1, address value2) internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
/// @dev this method can be vulnerable to revert data bombs
function bubbleUpAndRevertWith(
address revertingContract,
bytes4 revertingFunctionSelector,
bytes4 additionalContext
) internal pure {
bytes4 wrappedErrorSelector = WrappedError.selector;
assembly ("memory-safe") {
// Ensure the size of the revert data is a multiple of 32 bytes
let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)
let fmp := mload(0x40)
// Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
mstore(fmp, wrappedErrorSelector)
mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(
add(fmp, 0x24),
and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
// offset revert reason
mstore(add(fmp, 0x44), 0x80)
// offset additional context
mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
// size revert reason
mstore(add(fmp, 0x84), returndatasize())
// revert reason
returndatacopy(add(fmp, 0xa4), 0, returndatasize())
// size additional context
mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
// additional context
mstore(
add(fmp, add(0xc4, encodedDataSize)),
and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
revert(fmp, add(0xe4, encodedDataSize))
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "./PoolKey.sol";
type PoolId is bytes32;
/// @notice Library for computing the ID of a pool
library PoolIdLibrary {
/// @notice Returns value equal to keccak256(abi.encode(poolKey))
function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
assembly ("memory-safe") {
// 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)
poolId := keccak256(poolKey, 0xa0)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {SafeCast} from "../libraries/SafeCast.sol";
/// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0
/// and the lower 128 bits represent the amount1.
type BalanceDelta is int256;
using {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global;
using BalanceDeltaLibrary for BalanceDelta global;
using SafeCast for int256;
function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) {
assembly ("memory-safe") {
balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1))
}
}
function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
int256 res0;
int256 res1;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := signextend(15, a)
let b0 := sar(128, b)
let b1 := signextend(15, b)
res0 := add(a0, b0)
res1 := add(a1, b1)
}
return toBalanceDelta(res0.toInt128(), res1.toInt128());
}
function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
int256 res0;
int256 res1;
assembly ("memory-safe") {
let a0 := sar(128, a)
let a1 := signextend(15, a)
let b0 := sar(128, b)
let b1 := signextend(15, b)
res0 := sub(a0, b0)
res1 := sub(a1, b1)
}
return toBalanceDelta(res0.toInt128(), res1.toInt128());
}
function eq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
return BalanceDelta.unwrap(a) == BalanceDelta.unwrap(b);
}
function neq(BalanceDelta a, BalanceDelta b) pure returns (bool) {
return BalanceDelta.unwrap(a) != BalanceDelta.unwrap(b);
}
/// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type
library BalanceDeltaLibrary {
/// @notice A BalanceDelta of 0
BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0);
function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) {
assembly ("memory-safe") {
_amount0 := sar(128, balanceDelta)
}
}
function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) {
assembly ("memory-safe") {
_amount1 := signextend(15, balanceDelta)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
/// @notice Parameter struct for `ModifyLiquidity` pool operations
struct ModifyLiquidityParams {
// the lower and upper tick of the position
int24 tickLower;
int24 tickUpper;
// how to modify the liquidity
int256 liquidityDelta;
// a value to set if you want unique liquidity positions at the same range
bytes32 salt;
}
/// @notice Parameter struct for `Swap` pool operations
struct SwapParams {
/// Whether to swap token0 for token1 or vice versa
bool zeroForOne;
/// The desired input amount if negative (exactIn), or the desired output amount if positive (exactOut)
int256 amountSpecified;
/// The sqrt price at which, if reached, the swap will stop executing
uint160 sqrtPriceLimitX96;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// Return type of the beforeSwap hook.
// Upper 128 bits is the delta in specified tokens. Lower 128 bits is delta in unspecified tokens (to match the afterSwap hook)
type BeforeSwapDelta is int256;
// Creates a BeforeSwapDelta from specified and unspecified
function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified)
pure
returns (BeforeSwapDelta beforeSwapDelta)
{
assembly ("memory-safe") {
beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified))
}
}
/// @notice Library for getting the specified and unspecified deltas from the BeforeSwapDelta type
library BeforeSwapDeltaLibrary {
/// @notice A BeforeSwapDelta of 0
BeforeSwapDelta public constant ZERO_DELTA = BeforeSwapDelta.wrap(0);
/// extracts int128 from the upper 128 bits of the BeforeSwapDelta
/// returned by beforeSwap
function getSpecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaSpecified) {
assembly ("memory-safe") {
deltaSpecified := sar(128, delta)
}
}
/// extracts int128 from the lower 128 bits of the BeforeSwapDelta
/// returned by beforeSwap and afterSwap
function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) {
assembly ("memory-safe") {
deltaUnspecified := signextend(15, delta)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";
/**
* @dev PositionInfo is a packed version of solidity structure.
* Using the packaged version saves gas and memory by not storing the structure fields in memory slots.
*
* Layout:
* 200 bits poolId | 24 bits tickUpper | 24 bits tickLower | 8 bits hasSubscriber
*
* Fields in the direction from the least significant bit:
*
* A flag to know if the tokenId is subscribed to an address
* uint8 hasSubscriber;
*
* The tickUpper of the position
* int24 tickUpper;
*
* The tickLower of the position
* int24 tickLower;
*
* The truncated poolId. Truncates a bytes32 value so the most signifcant (highest) 200 bits are used.
* bytes25 poolId;
*
* Note: If more bits are needed, hasSubscriber can be a single bit.
*
*/
type PositionInfo is uint256;
using PositionInfoLibrary for PositionInfo global;
library PositionInfoLibrary {
PositionInfo internal constant EMPTY_POSITION_INFO = PositionInfo.wrap(0);
uint256 internal constant MASK_UPPER_200_BITS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000;
uint256 internal constant MASK_8_BITS = 0xFF;
uint24 internal constant MASK_24_BITS = 0xFFFFFF;
uint256 internal constant SET_UNSUBSCRIBE = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00;
uint256 internal constant SET_SUBSCRIBE = 0x01;
uint8 internal constant TICK_LOWER_OFFSET = 8;
uint8 internal constant TICK_UPPER_OFFSET = 32;
/// @dev This poolId is NOT compatible with the poolId used in UniswapV4 core. It is truncated to 25 bytes, and just used to lookup PoolKey in the poolKeys mapping.
function poolId(PositionInfo info) internal pure returns (bytes25 _poolId) {
assembly ("memory-safe") {
_poolId := and(MASK_UPPER_200_BITS, info)
}
}
function tickLower(PositionInfo info) internal pure returns (int24 _tickLower) {
assembly ("memory-safe") {
_tickLower := signextend(2, shr(TICK_LOWER_OFFSET, info))
}
}
function tickUpper(PositionInfo info) internal pure returns (int24 _tickUpper) {
assembly ("memory-safe") {
_tickUpper := signextend(2, shr(TICK_UPPER_OFFSET, info))
}
}
function hasSubscriber(PositionInfo info) internal pure returns (bool _hasSubscriber) {
assembly ("memory-safe") {
_hasSubscriber := and(MASK_8_BITS, info)
}
}
/// @dev this does not actually set any storage
function setSubscribe(PositionInfo info) internal pure returns (PositionInfo _info) {
assembly ("memory-safe") {
_info := or(info, SET_SUBSCRIBE)
}
}
/// @dev this does not actually set any storage
function setUnsubscribe(PositionInfo info) internal pure returns (PositionInfo _info) {
assembly ("memory-safe") {
_info := and(info, SET_UNSUBSCRIBE)
}
}
/// @notice Creates the default PositionInfo struct
/// @dev Called when minting a new position
/// @param _poolKey the pool key of the position
/// @param _tickLower the lower tick of the position
/// @param _tickUpper the upper tick of the position
/// @return info packed position info, with the truncated poolId and the hasSubscriber flag set to false
function initialize(PoolKey memory _poolKey, int24 _tickLower, int24 _tickUpper)
internal
pure
returns (PositionInfo info)
{
bytes25 _poolId = bytes25(PoolId.unwrap(_poolKey.toId()));
assembly {
info :=
or(
or(and(MASK_UPPER_200_BITS, _poolId), shl(TICK_UPPER_OFFSET, and(MASK_24_BITS, _tickUpper))),
shl(TICK_LOWER_OFFSET, and(MASK_24_BITS, _tickLower))
)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {ISubscriber} from "./ISubscriber.sol";
/// @title INotifier
/// @notice Interface for the Notifier contract
interface INotifier {
/// @notice Thrown when unsubscribing without a subscriber
error NotSubscribed();
/// @notice Thrown when a subscriber does not have code
error NoCodeSubscriber();
/// @notice Thrown when a user specifies a gas limit too low to avoid valid unsubscribe notifications
error GasLimitTooLow();
/// @notice Wraps the revert message of the subscriber contract on a reverting subscription
error SubscriptionReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting modify liquidity notification
error ModifyLiquidityNotificationReverted(address subscriber, bytes reason);
/// @notice Wraps the revert message of the subscriber contract on a reverting burn notification
error BurnNotificationReverted(address subscriber, bytes reason);
/// @notice Thrown when a tokenId already has a subscriber
error AlreadySubscribed(uint256 tokenId, address subscriber);
/// @notice Emitted on a successful call to subscribe
event Subscription(uint256 indexed tokenId, address indexed subscriber);
/// @notice Emitted on a successful call to unsubscribe
event Unsubscription(uint256 indexed tokenId, address indexed subscriber);
/// @notice Returns the subscriber for a respective position
/// @param tokenId the ERC721 tokenId
/// @return subscriber the subscriber contract
function subscriber(uint256 tokenId) external view returns (ISubscriber subscriber);
/// @notice Enables the subscriber to receive notifications for a respective position
/// @param tokenId the ERC721 tokenId
/// @param newSubscriber the address of the subscriber contract
/// @param data caller-provided data that's forwarded to the subscriber contract
/// @dev Calling subscribe when a position is already subscribed will revert
/// @dev payable so it can be multicalled with NATIVE related actions
/// @dev will revert if pool manager is locked
function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data) external payable;
/// @notice Removes the subscriber from receiving notifications for a respective position
/// @param tokenId the ERC721 tokenId
/// @dev Callers must specify a high gas limit (remaining gas should be higher than unsubscriberGasLimit) such that the subscriber can be notified
/// @dev payable so it can be multicalled with NATIVE related actions
/// @dev Must always allow a user to unsubscribe. In the case of a malicious subscriber, a user can always unsubscribe safely, ensuring liquidity is always modifiable.
/// @dev will revert if pool manager is locked
function unsubscribe(uint256 tokenId) external payable;
/// @notice Returns and determines the maximum allowable gas-used for notifying unsubscribe
/// @return uint256 the maximum gas limit when notifying a subscriber's `notifyUnsubscribe` function
function unsubscribeGasLimit() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
/// @title IImmutableState
/// @notice Interface for the ImmutableState contract
interface IImmutableState {
/// @notice The Uniswap v4 PoolManager contract
function poolManager() external view returns (IPoolManager);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IERC721Permit_v4
/// @notice Interface for the ERC721Permit_v4 contract
interface IERC721Permit_v4 {
error SignatureDeadlineExpired();
error NoSelfPermit();
error Unauthorized();
/// @notice Approve of a specific token ID for spending by spender via signature
/// @param spender The account that is being approved
/// @param tokenId The ID of the token that is being approved for spending
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
/// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
/// @dev payable so it can be multicalled with NATIVE related actions
function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature)
external
payable;
/// @notice Set an operator with full permission to an owner's tokens via signature
/// @param owner The address that is setting the operator
/// @param operator The address that will be set as an operator for the owner
/// @param approved The permission to set on the operator
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
/// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
/// @dev payable so it can be multicalled with NATIVE related actions
function permitForAll(
address owner,
address operator,
bool approved,
uint256 deadline,
uint256 nonce,
bytes calldata signature
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IEIP712_v4
/// @notice Interface for the EIP712 contract
interface IEIP712_v4 {
/// @notice Returns the domain separator for the current chain.
/// @return bytes32 The domain separator
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IMulticall_v4
/// @notice Interface for the Multicall_v4 contract
interface IMulticall_v4 {
/// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
/// @dev The `msg.value` is passed onto all subcalls, even if a previous subcall has consumed the ether.
/// Subcalls can instead use `address(this).value` to see the available ETH, and consume it using {value: x}.
/// @param data The encoded function data for each of the calls to make to this contract
/// @return results The results from each of the calls passed in via data
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
/// @title IPoolInitializer_v4
/// @notice Interface for the PoolInitializer_v4 contract
interface IPoolInitializer_v4 {
/// @notice Initialize a Uniswap v4 Pool
/// @dev If the pool is already initialized, this function will not revert and just return type(int24).max
/// @param key The PoolKey of the pool to initialize
/// @param sqrtPriceX96 The initial starting price of the pool, expressed as a sqrtPriceX96
/// @return The current tick of the pool, or type(int24).max if the pool creation failed, or the pool already existed
function initializePool(PoolKey calldata key, uint160 sqrtPriceX96) external payable returns (int24);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title IUnorderedNonce
/// @notice Interface for the UnorderedNonce contract
interface IUnorderedNonce {
error NonceAlreadyUsed();
/// @notice mapping of nonces consumed by each address, where a nonce is a single bit on the 256-bit bitmap
/// @dev word is at most type(uint248).max
function nonces(address owner, uint256 word) external view returns (uint256);
/// @notice Revoke a nonce by spending it, preventing it from being used again
/// @dev Used in cases where a valid nonce has not been broadcasted onchain, and the owner wants to revoke the validity of the nonce
/// @dev payable so it can be multicalled with native-token related actions
function revokeNonce(uint256 nonce) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
/// @title IPermit2Forwarder
/// @notice Interface for the Permit2Forwarder contract
interface IPermit2Forwarder {
/// @notice allows forwarding a single permit to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param permitSingle the permit data
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
/// @return err the error returned by a reverting permit call, empty if successful
function permit(address owner, IAllowanceTransfer.PermitSingle calldata permitSingle, bytes calldata signature)
external
payable
returns (bytes memory err);
/// @notice allows forwarding batch permits to permit2
/// @dev this function is payable to allow multicall with NATIVE based actions
/// @param owner the owner of the tokens
/// @param _permitBatch a batch of approvals
/// @param signature the signature of the permit; abi.encodePacked(r, s, v)
/// @return err the error returned by a reverting permit call, empty if successful
function permitBatch(address owner, IAllowanceTransfer.PermitBatch calldata _permitBatch, bytes calldata signature)
external
payable
returns (bytes memory err);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {CustomRevert} from "./CustomRevert.sol";
/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
using CustomRevert for bytes4;
error SafeCastOverflow();
/// @notice Cast a uint256 to a uint160, revert on overflow
/// @param x The uint256 to be downcasted
/// @return y The downcasted integer, now type uint160
function toUint160(uint256 x) internal pure returns (uint160 y) {
y = uint160(x);
if (y != x) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a uint256 to a uint128, revert on overflow
/// @param x The uint256 to be downcasted
/// @return y The downcasted integer, now type uint128
function toUint128(uint256 x) internal pure returns (uint128 y) {
y = uint128(x);
if (x != y) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a int128 to a uint128, revert on overflow or underflow
/// @param x The int128 to be casted
/// @return y The casted integer, now type uint128
function toUint128(int128 x) internal pure returns (uint128 y) {
if (x < 0) SafeCastOverflow.selector.revertWith();
y = uint128(x);
}
/// @notice Cast a int256 to a int128, revert on overflow or underflow
/// @param x The int256 to be downcasted
/// @return y The downcasted integer, now type int128
function toInt128(int256 x) internal pure returns (int128 y) {
y = int128(x);
if (y != x) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a uint256 to a int256, revert on overflow
/// @param x The uint256 to be casted
/// @return y The casted integer, now type int256
function toInt256(uint256 x) internal pure returns (int256 y) {
y = int256(x);
if (y < 0) SafeCastOverflow.selector.revertWith();
}
/// @notice Cast a uint256 to a int128, revert on overflow
/// @param x The uint256 to be downcasted
/// @return The downcasted integer, now type int128
function toInt128(uint256 x) internal pure returns (int128) {
if (x >= 1 << 127) SafeCastOverflow.selector.revertWith();
return int128(int256(x));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {PositionInfo} from "../libraries/PositionInfoLibrary.sol";
/// @title ISubscriber
/// @notice Interface that a Subscriber contract should implement to receive updates from the v4 position manager
interface ISubscriber {
/// @notice Called when a position subscribes to this subscriber contract
/// @param tokenId the token ID of the position
/// @param data additional data passed in by the caller
function notifySubscribe(uint256 tokenId, bytes memory data) external;
/// @notice Called when a position unsubscribes from the subscriber
/// @dev This call's gas is capped at `unsubscribeGasLimit` (set at deployment)
/// @dev Because of EIP-150, solidity may only allocate 63/64 of gasleft()
/// @param tokenId the token ID of the position
function notifyUnsubscribe(uint256 tokenId) external;
/// @notice Called when a position is burned
/// @param tokenId the token ID of the position
/// @param owner the current owner of the tokenId
/// @param info information about the position
/// @param liquidity the amount of liquidity decreased in the position, may be 0
/// @param feesAccrued the fees accrued by the position if liquidity was decreased
function notifyBurn(uint256 tokenId, address owner, PositionInfo info, uint256 liquidity, BalanceDelta feesAccrued)
external;
/// @notice Called when a position modifies its liquidity or collects fees
/// @param tokenId the token ID of the position
/// @param liquidityChange the change in liquidity on the underlying position
/// @param feesAccrued the fees to be collected from the position as a result of the modifyLiquidity call
/// @dev Note that feesAccrued can be artificially inflated by a malicious user
/// Pools with a single liquidity position can inflate feeGrowthGlobal (and consequently feesAccrued) by donating to themselves;
/// atomically donating and collecting fees within the same unlockCallback may further inflate feeGrowthGlobal/feesAccrued
function notifyModifyLiquidity(uint256 tokenId, int256 liquidityChange, BalanceDelta feesAccrued) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Currency} from "../types/Currency.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {IHooks} from "./IHooks.sol";
import {IERC6909Claims} from "./external/IERC6909Claims.sol";
import {IProtocolFees} from "./IProtocolFees.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {PoolId} from "../types/PoolId.sol";
import {IExtsload} from "./IExtsload.sol";
import {IExttload} from "./IExttload.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.sol";
/// @notice Interface for the PoolManager
interface IPoolManager is IProtocolFees, IERC6909Claims, IExtsload, IExttload {
/// @notice Thrown when a currency is not netted out after the contract is unlocked
error CurrencyNotSettled();
/// @notice Thrown when trying to interact with a non-initialized pool
error PoolNotInitialized();
/// @notice Thrown when unlock is called, but the contract is already unlocked
error AlreadyUnlocked();
/// @notice Thrown when a function is called that requires the contract to be unlocked, but it is not
error ManagerLocked();
/// @notice Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow
error TickSpacingTooLarge(int24 tickSpacing);
/// @notice Pools must have a positive non-zero tickSpacing passed to #initialize
error TickSpacingTooSmall(int24 tickSpacing);
/// @notice PoolKey must have currencies where address(currency0) < address(currency1)
error CurrenciesOutOfOrderOrEqual(address currency0, address currency1);
/// @notice Thrown when a call to updateDynamicLPFee is made by an address that is not the hook,
/// or on a pool that does not have a dynamic swap fee.
error UnauthorizedDynamicLPFeeUpdate();
/// @notice Thrown when trying to swap amount of 0
error SwapAmountCannotBeZero();
///@notice Thrown when native currency is passed to a non native settlement
error NonzeroNativeValue();
/// @notice Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta.
error MustClearExactPositiveDelta();
/// @notice Emitted when a new pool is initialized
/// @param id The abi encoded hash of the pool key struct for the new pool
/// @param currency0 The first currency of the pool by address sort order
/// @param currency1 The second currency of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param hooks The hooks contract address for the pool, or address(0) if none
/// @param sqrtPriceX96 The price of the pool on initialization
/// @param tick The initial tick of the pool corresponding to the initialized price
event Initialize(
PoolId indexed id,
Currency indexed currency0,
Currency indexed currency1,
uint24 fee,
int24 tickSpacing,
IHooks hooks,
uint160 sqrtPriceX96,
int24 tick
);
/// @notice Emitted when a liquidity position is modified
/// @param id The abi encoded hash of the pool key struct for the pool that was modified
/// @param sender The address that modified the pool
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param liquidityDelta The amount of liquidity that was added or removed
/// @param salt The extra data to make positions unique
event ModifyLiquidity(
PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt
);
/// @notice Emitted for swaps between currency0 and currency1
/// @param id The abi encoded hash of the pool key struct for the pool that was modified
/// @param sender The address that initiated the swap call, and that received the callback
/// @param amount0 The delta of the currency0 balance of the pool
/// @param amount1 The delta of the currency1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of the price of the pool after the swap
/// @param fee The swap fee in hundredths of a bip
event Swap(
PoolId indexed id,
address indexed sender,
int128 amount0,
int128 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick,
uint24 fee
);
/// @notice Emitted for donations
/// @param id The abi encoded hash of the pool key struct for the pool that was donated to
/// @param sender The address that initiated the donate call
/// @param amount0 The amount donated in currency0
/// @param amount1 The amount donated in currency1
event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);
/// @notice All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement
/// `IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract.
/// @dev The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`
/// @param data Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`
/// @return The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`
function unlock(bytes calldata data) external returns (bytes memory);
/// @notice Initialize the state for a given pool ID
/// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
/// @param key The pool key for the pool to initialize
/// @param sqrtPriceX96 The initial square root price
/// @return tick The initial tick of the pool
function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick);
/// @notice Modify the liquidity for the given pool
/// @dev Poke by calling with a zero liquidityDelta
/// @param key The pool to modify liquidity in
/// @param params The parameters for modifying the liquidity
/// @param hookData The data to pass through to the add/removeLiquidity hooks
/// @return callerDelta The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable
/// @return feesAccrued The balance delta of the fees generated in the liquidity range. Returned for informational purposes
/// @dev Note that feesAccrued can be artificially inflated by a malicious actor and integrators should be careful using the value
/// For pools with a single liquidity position, actors can donate to themselves to inflate feeGrowthGlobal (and consequently feesAccrued)
/// atomically donating and collecting fees in the same unlockCallback may make the inflated value more extreme
function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
external
returns (BalanceDelta callerDelta, BalanceDelta feesAccrued);
/// @notice Swap against the given pool
/// @param key The pool to swap in
/// @param params The parameters for swapping
/// @param hookData The data to pass through to the swap hooks
/// @return swapDelta The balance delta of the address swapping
/// @dev Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified.
/// Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG
/// the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.
function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData)
external
returns (BalanceDelta swapDelta);
/// @notice Donate the given currency amounts to the in-range liquidity providers of a pool
/// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds.
/// Donors should keep this in mind when designing donation mechanisms.
/// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of
/// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to
/// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)).
/// Read the comments in `Pool.swap()` for more information about this.
/// @param key The key of the pool to donate to
/// @param amount0 The amount of currency0 to donate
/// @param amount1 The amount of currency1 to donate
/// @param hookData The data to pass through to the donate hooks
/// @return BalanceDelta The delta of the caller after the donate
function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
external
returns (BalanceDelta);
/// @notice Writes the current ERC20 balance of the specified currency to transient storage
/// This is used to checkpoint balances for the manager and derive deltas for the caller.
/// @dev This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped
/// for native tokens because the amount to settle is determined by the sent value.
/// However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle
/// native funds, this function can be called with the native currency to then be able to settle the native currency
function sync(Currency currency) external;
/// @notice Called by the user to net out some value owed to the user
/// @dev Will revert if the requested amount is not available, consider using `mint` instead
/// @dev Can also be used as a mechanism for free flash loans
/// @param currency The currency to withdraw from the pool manager
/// @param to The address to withdraw to
/// @param amount The amount of currency to withdraw
function take(Currency currency, address to, uint256 amount) external;
/// @notice Called by the user to pay what is owed
/// @return paid The amount of currency settled
function settle() external payable returns (uint256 paid);
/// @notice Called by the user to pay on behalf of another address
/// @param recipient The address to credit for the payment
/// @return paid The amount of currency settled
function settleFor(address recipient) external payable returns (uint256 paid);
/// @notice WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently.
/// A call to clear will zero out a positive balance WITHOUT a corresponding transfer.
/// @dev This could be used to clear a balance that is considered dust.
/// Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.
function clear(Currency currency, uint256 amount) external;
/// @notice Called by the user to move value into ERC6909 balance
/// @param to The address to mint the tokens to
/// @param id The currency address to mint to ERC6909s, as a uint256
/// @param amount The amount of currency to mint
/// @dev The id is converted to a uint160 to correspond to a currency address
/// If the upper 12 bytes are not 0, they will be 0-ed out
function mint(address to, uint256 id, uint256 amount) external;
/// @notice Called by the user to move value from ERC6909 balance
/// @param from The address to burn the tokens from
/// @param id The currency address to burn from ERC6909s, as a uint256
/// @param amount The amount of currency to burn
/// @dev The id is converted to a uint160 to correspond to a currency address
/// If the upper 12 bytes are not 0, they will be 0-ed out
function burn(address from, uint256 id, uint256 amount) external;
/// @notice Updates the pools lp fees for the a pool that has enabled dynamic lp fees.
/// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
/// @param key The key of the pool to update dynamic LP fees for
/// @param newDynamicLPFee The new dynamic pool LP fee
function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IEIP712} from "./IEIP712.sol";
/// @title AllowanceTransfer
/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
/// @dev Requires user's token approval on the Permit2 contract
interface IAllowanceTransfer is IEIP712 {
/// @notice Thrown when an allowance on a token has expired.
/// @param deadline The timestamp at which the allowed amount is no longer valid
error AllowanceExpired(uint256 deadline);
/// @notice Thrown when an allowance on a token has been depleted.
/// @param amount The maximum amount allowed
error InsufficientAllowance(uint256 amount);
/// @notice Thrown when too many nonces are invalidated.
error ExcessiveInvalidation();
/// @notice Emits an event when the owner successfully invalidates an ordered nonce.
event NonceInvalidation(
address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
);
/// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
event Approval(
address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
);
/// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
event Permit(
address indexed owner,
address indexed token,
address indexed spender,
uint160 amount,
uint48 expiration,
uint48 nonce
);
/// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
event Lockdown(address indexed owner, address token, address spender);
/// @notice The permit data for a token
struct PermitDetails {
// ERC20 token address
address token;
// the maximum amount allowed to spend
uint160 amount;
// timestamp at which a spender's token allowances become invalid
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice The permit message signed for a single token allowance
struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The permit message signed for multiple token allowances
struct PermitBatch {
// the permit data for multiple token allowances
PermitDetails[] details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
/// @notice The saved permissions
/// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
/// @dev Setting amount to type(uint160).max sets an unlimited approval
struct PackedAllowance {
// amount allowed
uint160 amount;
// permission expiry
uint48 expiration;
// an incrementing value indexed per owner,token,and spender for each signature
uint48 nonce;
}
/// @notice A token spender pair.
struct TokenSpenderPair {
// the token the spender is approved
address token;
// the spender address
address spender;
}
/// @notice Details for a token transfer.
struct AllowanceTransferDetails {
// the owner of the token
address from;
// the recipient of the token
address to;
// the amount of the token
uint160 amount;
// the token to be transferred
address token;
}
/// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
/// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
/// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
function allowance(address user, address token, address spender)
external
view
returns (uint160 amount, uint48 expiration, uint48 nonce);
/// @notice Approves the spender to use up to amount of the specified token up until the expiration
/// @param token The token to approve
/// @param spender The spender address to approve
/// @param amount The approved amount of the token
/// @param expiration The timestamp at which the approval is no longer valid
/// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
/// @dev Setting amount to type(uint160).max sets an unlimited approval
function approve(address token, address spender, uint160 amount, uint48 expiration) external;
/// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitSingle Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;
/// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
/// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
/// @param owner The owner of the tokens being approved
/// @param permitBatch Data signed over by the owner specifying the terms of approval
/// @param signature The owner's signature over the permit data
function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;
/// @notice Transfer approved tokens from one address to another
/// @param from The address to transfer from
/// @param to The address of the recipient
/// @param amount The amount of the token to transfer
/// @param token The token address to transfer
/// @dev Requires the from address to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(address from, address to, uint160 amount, address token) external;
/// @notice Transfer approved tokens in a batch
/// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
/// @dev Requires the from addresses to have approved at least the desired amount
/// of tokens to msg.sender.
function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
/// @notice Enables performing a "lockdown" of the sender's Permit2 identity
/// by batch revoking approvals
/// @param approvals Array of approvals to revoke.
function lockdown(TokenSpenderPair[] calldata approvals) external;
/// @notice Invalidate nonces for a given (token, spender) pair
/// @param token The token to invalidate nonces for
/// @param spender The spender to invalidate nonces for
/// @param newNonce The new nonce to set. Invalidates all nonces less than it.
/// @dev Can't invalidate more than 2**16 nonces per transaction.
function invalidateNonces(address token, address spender, uint48 newNonce) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Interface for claims over a contract balance, wrapped as a ERC6909
interface IERC6909Claims {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OperatorSet(address indexed owner, address indexed operator, bool approved);
event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);
event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount);
/*//////////////////////////////////////////////////////////////
FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Owner balance of an id.
/// @param owner The address of the owner.
/// @param id The id of the token.
/// @return amount The balance of the token.
function balanceOf(address owner, uint256 id) external view returns (uint256 amount);
/// @notice Spender allowance of an id.
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @param id The id of the token.
/// @return amount The allowance of the token.
function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount);
/// @notice Checks if a spender is approved by an owner as an operator
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @return approved The approval status.
function isOperator(address owner, address spender) external view returns (bool approved);
/// @notice Transfers an amount of an id from the caller to a receiver.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always, unless the function reverts
function transfer(address receiver, uint256 id, uint256 amount) external returns (bool);
/// @notice Transfers an amount of an id from a sender to a receiver.
/// @param sender The address of the sender.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always, unless the function reverts
function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool);
/// @notice Approves an amount of an id to a spender.
/// @param spender The address of the spender.
/// @param id The id of the token.
/// @param amount The amount of the token.
/// @return bool True, always
function approve(address spender, uint256 id, uint256 amount) external returns (bool);
/// @notice Sets or removes an operator for the caller.
/// @param operator The address of the operator.
/// @param approved The approval status.
/// @return bool True, always
function setOperator(address operator, bool approved) external returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Currency} from "../types/Currency.sol";
import {PoolId} from "../types/PoolId.sol";
import {PoolKey} from "../types/PoolKey.sol";
/// @notice Interface for all protocol-fee related functions in the pool manager
interface IProtocolFees {
/// @notice Thrown when protocol fee is set too high
error ProtocolFeeTooLarge(uint24 fee);
/// @notice Thrown when collectProtocolFees or setProtocolFee is not called by the controller.
error InvalidCaller();
/// @notice Thrown when collectProtocolFees is attempted on a token that is synced.
error ProtocolFeeCurrencySynced();
/// @notice Emitted when the protocol fee controller address is updated in setProtocolFeeController.
event ProtocolFeeControllerUpdated(address indexed protocolFeeController);
/// @notice Emitted when the protocol fee is updated for a pool.
event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee);
/// @notice Given a currency address, returns the protocol fees accrued in that currency
/// @param currency The currency to check
/// @return amount The amount of protocol fees accrued in the currency
function protocolFeesAccrued(Currency currency) external view returns (uint256 amount);
/// @notice Sets the protocol fee for the given pool
/// @param key The key of the pool to set a protocol fee for
/// @param newProtocolFee The fee to set
function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external;
/// @notice Sets the protocol fee controller
/// @param controller The new protocol fee controller
function setProtocolFeeController(address controller) external;
/// @notice Collects the protocol fees for a given recipient and currency, returning the amount collected
/// @dev This will revert if the contract is unlocked
/// @param recipient The address to receive the protocol fees
/// @param currency The currency to withdraw
/// @param amount The amount of currency to withdraw
/// @return amountCollected The amount of currency successfully withdrawn
function collectProtocolFees(address recipient, Currency currency, uint256 amount)
external
returns (uint256 amountCollected);
/// @notice Returns the current protocol fee controller address
/// @return address The current protocol fee controller address
function protocolFeeController() external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @notice Interface for functions to access any storage slot in a contract
interface IExtsload {
/// @notice Called by external contracts to access granular pool state
/// @param slot Key of slot to sload
/// @return value The value of the slot as bytes32
function extsload(bytes32 slot) external view returns (bytes32 value);
/// @notice Called by external contracts to access granular pool state
/// @param startSlot Key of slot to start sloading from
/// @param nSlots Number of slots to load into return value
/// @return values List of loaded values.
function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory values);
/// @notice Called by external contracts to access sparse pool state
/// @param slots List of slots to SLOAD from.
/// @return values List of loaded values.
function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/// @notice Interface for functions to access any transient storage slot in a contract
interface IExttload {
/// @notice Called by external contracts to access transient storage of the contract
/// @param slot Key of slot to tload
/// @return value The value of the slot as bytes32
function exttload(bytes32 slot) external view returns (bytes32 value);
/// @notice Called by external contracts to access sparse transient pool state
/// @param slots List of slots to tload
/// @return values List of loaded values
function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IEIP712 {
function DOMAIN_SEPARATOR() external view returns (bytes32);
}{
"remappings": [
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"solmate/=lib/v4-periphery/lib/permit2/lib/solmate/",
"@aave-v3-core/=node_modules/@aave/core-v3/contracts/",
"ethereum-vault-connector/=lib/ethereum-vault-connector/src/",
"@ensdomains/=lib/v4-periphery/lib/v4-core/node_modules/@ensdomains/",
"@openzeppelin/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
"ds-test/=lib/ethereum-vault-connector/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-periphery/lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/ethereum-vault-connector/lib/openzeppelin-contracts/contracts/",
"permit2/=lib/v4-periphery/lib/permit2/",
"solady/=lib/solady/src/",
"v4-core/=lib/v4-periphery/lib/v4-core/src/",
"v4-periphery/=lib/v4-periphery/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": false
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_evc","type":"address"},{"internalType":"contract IPositionManager","name":"_positionManager","type":"address"},{"internalType":"contract IHooks","name":"_yieldHarvestingHook","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ControllerDisabled","type":"error"},{"inputs":[],"name":"EVC_InvalidAddress","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"EVC","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"amount0Min","type":"uint128"},{"internalType":"uint128","name":"amount1Min","type":"uint128"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"collectFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint128","name":"amount0Min","type":"uint128"},{"internalType":"uint128","name":"amount1Min","type":"uint128"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"decreaseLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint128","name":"amount0Max","type":"uint128"},{"internalType":"uint128","name":"amount1Max","type":"uint128"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"increaseLiquidity","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"liquidity","type":"uint256"},{"internalType":"uint128","name":"amount0Max","type":"uint128"},{"internalType":"uint128","name":"amount1Max","type":"uint128"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes","name":"hookData","type":"bytes"}],"name":"mintPosition","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract IPositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"yieldHarvestingHook","outputs":[{"internalType":"contract IHooks","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
610100604052348015610010575f80fd5b5060405161209938038061209983398101604081905261002f916100fb565b826001600160a01b03811661005757604051638133abd160e01b815260040160405180910390fd5b6001600160a01b0390811660805281811660c052821660a0819052604080516312a9293f60e21b81529051634aa4a4fc916004808201926020929091908290030181865afa1580156100ab573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100cf9190610145565b6001600160a01b031660e05250610167915050565b6001600160a01b03811681146100f8575f80fd5b50565b5f805f6060848603121561010d575f80fd5b8351610118816100e4565b6020850151909350610129816100e4565b604085015190925061013a816100e4565b809150509250925092565b5f60208284031215610155575f80fd5b8151610160816100e4565b9392505050565b60805160a05160c05160e051611e836102165f395f818160de015281816109c401528181610ac70152610b5601525f8181608e015281816103bc0152818161040301528181610c610152610d4401525f8181610111015281816101dc015281816102e6015281816105ea0152818161081f01528181610c2c01528181610cac01528181610d0c01528181610d8201526110c801525f81816101620152818161117701526111b20152611e835ff3fe608060405260043610610079575f3560e01c8063a70354a11161004c578063a70354a114610154578063abf3cf0d14610186578063dbcd549e146101a7578063dff58a5f146101c6575f80fd5b80630f6101441461007d5780633fc8cef3146100cd578063791b98bc146101005780637bd14df814610133575b5f80fd5b348015610088575f80fd5b506100b07f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156100d8575f80fd5b506100b07f000000000000000000000000000000000000000000000000000000000000000081565b34801561010b575f80fd5b506100b07f000000000000000000000000000000000000000000000000000000000000000081565b6101466101413660046119f0565b6101d9565b6040519081526020016100c4565b34801561015f575f80fd5b507f00000000000000000000000000000000000000000000000000000000000000006100b0565b348015610191575f80fd5b506101a56101a0366004611aa4565b6102bb565b005b3480156101b2575f80fd5b506101a56101c1366004611b45565b6107db565b6101a56101d4366004611bd5565b6107f4565b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166375794a3c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061025a9190611c21565b90506102698a87878686610924565b604051929c5090975095505f90610290908c908c908c908c908c908c908c90602001611c38565b60405160208183030381529060405290506102ad6002828d610dff565b509998505050505050505050565b866102c461116b565b6040516331a9108f60e11b8152600481018390526001600160a01b03918216917f00000000000000000000000000000000000000000000000000000000000000001690636352211e90602401602060405180830381865afa15801561032b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061034f9190611cfe565b6001600160a01b031614610376576040516330cd747160e01b815260040160405180910390fd5b885160208a01515f8085156103965761039186880188611d19565b610399565b5f805b90925090506001600160a01b038216156103e2576001600160a01b038083168e527f00000000000000000000000000000000000000000000000000000000000000001660808e01525b6001600160a01b03811615610429576001600160a01b0380821660208f01527f00000000000000000000000000000000000000000000000000000000000000001660808e01525b8c602001516001600160a01b03168d5f01516001600160a01b031611156104645760208d0180518e516001600160a01b03908116909252168d525b6040805160028082528183019092525f91602082018180368337019050509050600160f81b815f8151811061049b5761049b611d50565b60200101906001600160f81b03191690815f1a905350601160f81b816001815181106104c9576104c9611d50565b60200101906001600160f81b03191690815f1a905350604080516002808252606082019092525f91816020015b60608152602001906001900390816104f65790505090508d8d8d8d60405160200161055494939291909384526001600160801b039283166020850152908216604084015216606082015260a0608082018190525f9082015260c00190565b604051602081830303815290604052815f8151811061057557610575611d50565b60200260200101819052508e5f01518f6020015160016040516020016105bb939291906001600160a01b0393841681529183166020830152909116604082015260600190565b604051602081830303815290604052816001815181106105dd576105dd611d50565b60200260200101819052507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663dd46508f47848460405160200161062b929190611d92565b604051602081830303815290604052426040518463ffffffff1660e01b8152600401610658929190611e07565b5f604051808303818588803b15801561066f575f80fd5b505af1158015610681573d5f803e3d5ffd5b505050506001600160a01b038516159050610722575f6106a08561122b565b6040516370a0823160e01b8152306004820181905291925061071b9187918491906001600160a01b038416906370a08231906024015b602060405180830381865afa1580156106f1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107159190611c21565b8f611297565b5050610749565b6107498a610738886001600160a01b03166112c0565b6001600160a01b038916919061133c565b6001600160a01b038316156107a3575f6107628461122b565b6040516370a0823160e01b8152306004820181905291925061079c9186918491906001600160a01b038416906370a08231906024016106d6565b50506107ca565b6107ca8a6107b9876001600160a01b03166112c0565b6001600160a01b038816919061133c565b505050505050505050505050505050565b6107eb87875f88888888886102bb565b50505050505050565b856107fd61116b565b6040516331a9108f60e11b8152600481018390526001600160a01b03918216917f00000000000000000000000000000000000000000000000000000000000000001690636352211e90602401602060405180830381865afa158015610864573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108889190611cfe565b6001600160a01b0316146108af576040516330cd747160e01b815260040160405180910390fd5b6108bc8886868686610924565b60408051602081018c90529081018a90526001600160801b0380841660608301528216608082015260a0808201525f60c08201819052939b50919750955060e00160405160208183030381529060405290506109195f828b610dff565b505050505050505050565b6040805160a0810182525f8082526020820181905291810182905260608101829052608081018290529080808085156109685761096386880188611d19565b61096b565b5f805b91509150886001600160801b03165f14610a775789516001600160a01b0316156109bb576109b661099a61116b565b8b516001600160a01b031690306001600160801b038d166113e1565b610a77565b345f03610a77577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166323b872dd6109f961116b565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201523060248201526001600160801b038c1660448201526064016020604051808303815f875af1158015610a51573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a759190611e37565b505b6001600160801b03881615610ab057610ab0610a9161116b565b60208c01516001600160a01b031690306001600160801b038c166113e1565b6040516370a0823160e01b81523060048201525f907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa158015610b14573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b389190611c21565b90508015610bb657604051632e1a7d4d60e01b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d906024015f604051808303815f87803b158015610b9f575f80fd5b505af1158015610bb1573d5f803e3d5ffd5b505050505b8a51610bd490610bcf906001600160a01b031630611448565b6114d7565b9950610bf9610bcf308d602001516001600160a01b031661144890919063ffffffff16565b98506001600160a01b03831615610c8b575f610c148461122b565b9050610c5084828e5f0151308f6001600160801b03167f0000000000000000000000000000000000000000000000000000000000000000611513565b50506001600160a01b038084168c527f00000000000000000000000000000000000000000000000000000000000000001660808c0152610cda565b8a516001600160a01b031615610cda578a51610cda906001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160801b038d1661133c565b6001600160a01b03821615610d6e575f610cf38361122b565b9050610d3083828e60200151308e6001600160801b03167f0000000000000000000000000000000000000000000000000000000000000000611513565b50506001600160a01b0380831660208d01527f00000000000000000000000000000000000000000000000000000000000000001660808c0152610db0565b60208b0151610db0906001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160801b038c1661133c565b8a602001516001600160a01b03168b5f01516001600160a01b03161115610dee5760208b0180518c516001600160a01b03908116909252168b529798975b509899979850959695505050505050565b6040805160058082528183019092525f916020820181803683370190505090508360f81b815f81518110610e3557610e35611d50565b60200101906001600160f81b03191690815f1a905350600b60f81b81600181518110610e6357610e63611d50565b60200101906001600160f81b03191690815f1a905350600b60f81b81600281518110610e9157610e91611d50565b60200101906001600160f81b03191690815f1a905350601460f81b81600381518110610ebf57610ebf611d50565b60200101906001600160f81b03191690815f1a905350601460f81b81600481518110610eed57610eed611d50565b60200101906001600160f81b03191690815f1a90535060408051600580825260c082019092525f91816020015b6060815260200190600190039081610f1a57905050905083815f81518110610f4457610f44611d50565b6020908102919091018101919091528351604080516001600160a01b03909216928201929092525f918101829052606081019190915260800160405160208183030381529060405281600181518110610f9f57610f9f611d50565b602002602001018190525082602001515f80604051602001610fea939291906001600160a01b039390931683526001600160801b039190911660208301521515604082015260600190565b6040516020818303038152906040528160028151811061100c5761100c611d50565b6020908102919091010152825161102161116b565b604080516001600160a01b03938416602082015292909116908201526060016040516020818303038152906040528160038151811061106257611062611d50565b6020026020010181905250826020015161107a61116b565b604080516001600160a01b0393841660208201529290911690820152606001604051602081830303815290604052816004815181106110bb576110bb611d50565b60200260200101819052507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663dd46508f478484604051602001611109929190611d92565b604051602081830303815290604052426040518463ffffffff1660e01b8152600401611136929190611e07565b5f604051808303818588803b15801561114d575f80fd5b505af115801561115f573d5f803e3d5ffd5b50505050505050505050565b5f336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016810361122657604051630c281d0f60e11b81525f60048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906318503a1e906024016040805180830381865afa1580156111fe573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112229190611e50565b5090505b919050565b5f816001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611286575060408051601f3d908101601f1916820190925261128391810190611cfe565b60015b61129157505f919050565b92915050565b5f806112a58786863061153d565b90506112b3863083866115b8565b9150505b95945050505050565b5f6001600160a01b0382166112d6575047919050565b6040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015611318573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112919190611c21565b5f6001600160a01b038416611371575f805f8085875af190508061136c5761136c835f633d2cec6f60e21b6115c5565b6113db565b60405163a9059cbb60e01b81526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f511416171691505f81525f60208201525f604082015250806113db576113db8463a9059cbb60e01b633c9fd93960e21b6115c5565b50505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526113db9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061163d565b5f6001600160a01b03831661146857506001600160a01b03811631611291565b6040516370a0823160e01b81526001600160a01b0383811660048301528416906370a0823190602401602060405180830381865afa1580156114ac573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d09190611c21565b9392505050565b5f6001600160801b0382111561150f576040516306dfcc6560e41b815260806004820152602481018390526044015b60405180910390fd5b5090565b5f8061152287878787306116a9565b905061153188883084876116c1565b98975050505050505050565b604051635d043b2960e11b8152600481018390526001600160a01b03828116602483015284811660448301525f919086169063ba087652906064016020604051808303815f875af1158015611594573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112b79190611c21565b5f6112b78585858561153d565b6040516390bfb86560e01b8082526001600160a01b03851660048301526001600160e01b031984166024830152608060448301526020601f3d018190040260a0810160648401523d608484015290913d5f60a483013e60048260a4018201526001600160e01b031984168260c4018201528160e40181fd5b5f8060205f8451602086015f885af18061165c576040513d5f823e3d81fd5b50505f513d91508115611673578060011415611680565b6001600160a01b0384163b155b156113db57604051635274afe760e01b81526001600160a01b0385166004820152602401611506565b5f6116b786868686866116c1565b9695505050505050565b5f6001600160a01b03841630146116e7576116e76001600160a01b0386168530866113e1565b604051636e553f6560e01b8152600481018490526001600160a01b038381166024830152871690636e553f65906044016020604051808303815f875af1925050508015611751575060408051601f3d908101601f1916820190925261174e91810190611c21565b60015b6117da5761176a6001600160a01b038616875f196117e1565b604051636e553f6560e01b8152600481018490526001600160a01b038381166024830152871690636e553f65906044016020604051808303815f875af11580156117b6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117da9190611c21565b90506112b7565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526118328482611870565b6113db576040516001600160a01b0384811660248301525f604483015261186691869182169063095ea7b390606401611416565b6113db848261163d565b5f805f8060205f8651602088015f8a5af192503d91505f5190508280156116b7575081156118a157806001146116b7565b50505050506001600160a01b03163b151590565b6001600160a01b03811681146118c9575f80fd5b50565b8035611226816118b5565b803562ffffff81168114611226575f80fd5b8035600281900b8114611226575f80fd5b5f60a0828403121561190a575f80fd5b60405160a0810181811067ffffffffffffffff8211171561193957634e487b7160e01b5f52604160045260245ffd5b604052905080611948836118cc565b8152611956602084016118cc565b6020820152611967604084016118d7565b6040820152611978606084016118e9565b6060820152611989608084016118cc565b60808201525092915050565b80356001600160801b0381168114611226575f80fd5b5f8083601f8401126119bb575f80fd5b50813567ffffffffffffffff8111156119d2575f80fd5b6020830191508360208285010111156119e9575f80fd5b9250929050565b5f805f805f805f805f6101808a8c031215611a09575f80fd5b611a138b8b6118fa565b9850611a2160a08b016118e9565b9750611a2f60c08b016118e9565b965060e08a01359550611a456101008b01611995565b9450611a546101208b01611995565b93506101408a0135611a65816118b5565b92506101608a013567ffffffffffffffff811115611a81575f80fd5b611a8d8c828d016119ab565b915080935050809150509295985092959850929598565b5f805f805f805f80610160898b031215611abc575f80fd5b611ac68a8a6118fa565b975060a08901359650611adb60c08a01611995565b9550611ae960e08a01611995565b9450611af86101008a01611995565b9350610120890135611b09816118b5565b925061014089013567ffffffffffffffff811115611b25575f80fd5b611b318b828c016119ab565b999c989b5096995094979396929594505050565b5f805f805f805f610140888a031215611b5c575f80fd5b611b6689896118fa565b965060a08801359550611b7b60c08901611995565b9450611b8960e08901611995565b9350610100880135611b9a816118b5565b925061012088013567ffffffffffffffff811115611bb6575f80fd5b611bc28a828b016119ab565b989b979a50959850939692959293505050565b5f805f805f805f610140888a031215611bec575f80fd5b611bf689896118fa565b965060a0880135955060c08801359450611c1260e08901611995565b9350611b9a6101008901611995565b5f60208284031215611c31575f80fd5b5051919050565b87516001600160a01b0390811682526020808a01518216908301526040808a015162ffffff16908301526060808a015160020b908301526080808a015190911690820152611c8b60a082018860020b9052565b611c9a60c082018760020b9052565b8460e0820152611cb66101008201856001600160801b03169052565b6001600160801b0383166101208201526001600160a01b0382166101408201526101806101608201525f611cf161018083015f815260200190565b9998505050505050505050565b5f60208284031215611d0e575f80fd5b81516114d0816118b5565b5f8060408385031215611d2a575f80fd5b8235611d35816118b5565b91506020830135611d45816118b5565b809150509250929050565b634e487b7160e01b5f52603260045260245ffd5b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b604081525f611da46040830185611d64565b828103602084015280845180835260208301915060208160051b840101602087015f5b83811015611df957601f19868403018552611de3838351611d64565b6020958601959093509190910190600101611dc7565b509098975050505050505050565b604081525f611e196040830185611d64565b90508260208301529392505050565b80518015158114611226575f80fd5b5f60208284031215611e47575f80fd5b6114d082611e28565b5f8060408385031215611e61575f80fd5b8251611e6c816118b5565b9150611e7a60208401611e28565b90509250929050560000000000000000000000002a1176964f5d7cae5406b627bf6166664fe83c600000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a80
Deployed Bytecode
0x608060405260043610610079575f3560e01c8063a70354a11161004c578063a70354a114610154578063abf3cf0d14610186578063dbcd549e146101a7578063dff58a5f146101c6575f80fd5b80630f6101441461007d5780633fc8cef3146100cd578063791b98bc146101005780637bd14df814610133575b5f80fd5b348015610088575f80fd5b506100b07f000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a8081565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156100d8575f80fd5b506100b07f000000000000000000000000420000000000000000000000000000000000000681565b34801561010b575f80fd5b506100b07f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf81565b6101466101413660046119f0565b6101d9565b6040519081526020016100c4565b34801561015f575f80fd5b507f0000000000000000000000002a1176964f5d7cae5406b627bf6166664fe83c606100b0565b348015610191575f80fd5b506101a56101a0366004611aa4565b6102bb565b005b3480156101b2575f80fd5b506101a56101c1366004611b45565b6107db565b6101a56101d4366004611bd5565b6107f4565b5f7f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b03166375794a3c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061025a9190611c21565b90506102698a87878686610924565b604051929c5090975095505f90610290908c908c908c908c908c908c908c90602001611c38565b60405160208183030381529060405290506102ad6002828d610dff565b509998505050505050505050565b866102c461116b565b6040516331a9108f60e11b8152600481018390526001600160a01b03918216917f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf1690636352211e90602401602060405180830381865afa15801561032b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061034f9190611cfe565b6001600160a01b031614610376576040516330cd747160e01b815260040160405180910390fd5b885160208a01515f8085156103965761039186880188611d19565b610399565b5f805b90925090506001600160a01b038216156103e2576001600160a01b038083168e527f000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a801660808e01525b6001600160a01b03811615610429576001600160a01b0380821660208f01527f000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a801660808e01525b8c602001516001600160a01b03168d5f01516001600160a01b031611156104645760208d0180518e516001600160a01b03908116909252168d525b6040805160028082528183019092525f91602082018180368337019050509050600160f81b815f8151811061049b5761049b611d50565b60200101906001600160f81b03191690815f1a905350601160f81b816001815181106104c9576104c9611d50565b60200101906001600160f81b03191690815f1a905350604080516002808252606082019092525f91816020015b60608152602001906001900390816104f65790505090508d8d8d8d60405160200161055494939291909384526001600160801b039283166020850152908216604084015216606082015260a0608082018190525f9082015260c00190565b604051602081830303815290604052815f8151811061057557610575611d50565b60200260200101819052508e5f01518f6020015160016040516020016105bb939291906001600160a01b0393841681529183166020830152909116604082015260600190565b604051602081830303815290604052816001815181106105dd576105dd611d50565b60200260200101819052507f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b031663dd46508f47848460405160200161062b929190611d92565b604051602081830303815290604052426040518463ffffffff1660e01b8152600401610658929190611e07565b5f604051808303818588803b15801561066f575f80fd5b505af1158015610681573d5f803e3d5ffd5b505050506001600160a01b038516159050610722575f6106a08561122b565b6040516370a0823160e01b8152306004820181905291925061071b9187918491906001600160a01b038416906370a08231906024015b602060405180830381865afa1580156106f1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107159190611c21565b8f611297565b5050610749565b6107498a610738886001600160a01b03166112c0565b6001600160a01b038916919061133c565b6001600160a01b038316156107a3575f6107628461122b565b6040516370a0823160e01b8152306004820181905291925061079c9186918491906001600160a01b038416906370a08231906024016106d6565b50506107ca565b6107ca8a6107b9876001600160a01b03166112c0565b6001600160a01b038816919061133c565b505050505050505050505050505050565b6107eb87875f88888888886102bb565b50505050505050565b856107fd61116b565b6040516331a9108f60e11b8152600481018390526001600160a01b03918216917f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf1690636352211e90602401602060405180830381865afa158015610864573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108889190611cfe565b6001600160a01b0316146108af576040516330cd747160e01b815260040160405180910390fd5b6108bc8886868686610924565b60408051602081018c90529081018a90526001600160801b0380841660608301528216608082015260a0808201525f60c08201819052939b50919750955060e00160405160208183030381529060405290506109195f828b610dff565b505050505050505050565b6040805160a0810182525f8082526020820181905291810182905260608101829052608081018290529080808085156109685761096386880188611d19565b61096b565b5f805b91509150886001600160801b03165f14610a775789516001600160a01b0316156109bb576109b661099a61116b565b8b516001600160a01b031690306001600160801b038d166113e1565b610a77565b345f03610a77577f00000000000000000000000042000000000000000000000000000000000000066001600160a01b03166323b872dd6109f961116b565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201523060248201526001600160801b038c1660448201526064016020604051808303815f875af1158015610a51573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a759190611e37565b505b6001600160801b03881615610ab057610ab0610a9161116b565b60208c01516001600160a01b031690306001600160801b038c166113e1565b6040516370a0823160e01b81523060048201525f907f00000000000000000000000042000000000000000000000000000000000000066001600160a01b0316906370a0823190602401602060405180830381865afa158015610b14573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b389190611c21565b90508015610bb657604051632e1a7d4d60e01b8152600481018290527f00000000000000000000000042000000000000000000000000000000000000066001600160a01b031690632e1a7d4d906024015f604051808303815f87803b158015610b9f575f80fd5b505af1158015610bb1573d5f803e3d5ffd5b505050505b8a51610bd490610bcf906001600160a01b031630611448565b6114d7565b9950610bf9610bcf308d602001516001600160a01b031661144890919063ffffffff16565b98506001600160a01b03831615610c8b575f610c148461122b565b9050610c5084828e5f0151308f6001600160801b03167f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf611513565b50506001600160a01b038084168c527f000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a801660808c0152610cda565b8a516001600160a01b031615610cda578a51610cda906001600160a01b03167f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160801b038d1661133c565b6001600160a01b03821615610d6e575f610cf38361122b565b9050610d3083828e60200151308e6001600160801b03167f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf611513565b50506001600160a01b0380831660208d01527f000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a801660808c0152610db0565b60208b0151610db0906001600160a01b03167f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160801b038c1661133c565b8a602001516001600160a01b03168b5f01516001600160a01b03161115610dee5760208b0180518c516001600160a01b03908116909252168b529798975b509899979850959695505050505050565b6040805160058082528183019092525f916020820181803683370190505090508360f81b815f81518110610e3557610e35611d50565b60200101906001600160f81b03191690815f1a905350600b60f81b81600181518110610e6357610e63611d50565b60200101906001600160f81b03191690815f1a905350600b60f81b81600281518110610e9157610e91611d50565b60200101906001600160f81b03191690815f1a905350601460f81b81600381518110610ebf57610ebf611d50565b60200101906001600160f81b03191690815f1a905350601460f81b81600481518110610eed57610eed611d50565b60200101906001600160f81b03191690815f1a90535060408051600580825260c082019092525f91816020015b6060815260200190600190039081610f1a57905050905083815f81518110610f4457610f44611d50565b6020908102919091018101919091528351604080516001600160a01b03909216928201929092525f918101829052606081019190915260800160405160208183030381529060405281600181518110610f9f57610f9f611d50565b602002602001018190525082602001515f80604051602001610fea939291906001600160a01b039390931683526001600160801b039190911660208301521515604082015260600190565b6040516020818303038152906040528160028151811061100c5761100c611d50565b6020908102919091010152825161102161116b565b604080516001600160a01b03938416602082015292909116908201526060016040516020818303038152906040528160038151811061106257611062611d50565b6020026020010181905250826020015161107a61116b565b604080516001600160a01b0393841660208201529290911690820152606001604051602081830303815290604052816004815181106110bb576110bb611d50565b60200260200101819052507f0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf6001600160a01b031663dd46508f478484604051602001611109929190611d92565b604051602081830303815290604052426040518463ffffffff1660e01b8152600401611136929190611e07565b5f604051808303818588803b15801561114d575f80fd5b505af115801561115f573d5f803e3d5ffd5b50505050505050505050565b5f336001600160a01b037f0000000000000000000000002a1176964f5d7cae5406b627bf6166664fe83c6016810361122657604051630c281d0f60e11b81525f60048201527f0000000000000000000000002a1176964f5d7cae5406b627bf6166664fe83c606001600160a01b0316906318503a1e906024016040805180830381865afa1580156111fe573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112229190611e50565b5090505b919050565b5f816001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611286575060408051601f3d908101601f1916820190925261128391810190611cfe565b60015b61129157505f919050565b92915050565b5f806112a58786863061153d565b90506112b3863083866115b8565b9150505b95945050505050565b5f6001600160a01b0382166112d6575047919050565b6040516370a0823160e01b81523060048201526001600160a01b038316906370a0823190602401602060405180830381865afa158015611318573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112919190611c21565b5f6001600160a01b038416611371575f805f8085875af190508061136c5761136c835f633d2cec6f60e21b6115c5565b6113db565b60405163a9059cbb60e01b81526001600160a01b038416600482015282602482015260205f6044835f895af13d15601f3d1160015f511416171691505f81525f60208201525f604082015250806113db576113db8463a9059cbb60e01b633c9fd93960e21b6115c5565b50505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526113db9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061163d565b5f6001600160a01b03831661146857506001600160a01b03811631611291565b6040516370a0823160e01b81526001600160a01b0383811660048301528416906370a0823190602401602060405180830381865afa1580156114ac573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114d09190611c21565b9392505050565b5f6001600160801b0382111561150f576040516306dfcc6560e41b815260806004820152602481018390526044015b60405180910390fd5b5090565b5f8061152287878787306116a9565b905061153188883084876116c1565b98975050505050505050565b604051635d043b2960e11b8152600481018390526001600160a01b03828116602483015284811660448301525f919086169063ba087652906064016020604051808303815f875af1158015611594573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906112b79190611c21565b5f6112b78585858561153d565b6040516390bfb86560e01b8082526001600160a01b03851660048301526001600160e01b031984166024830152608060448301526020601f3d018190040260a0810160648401523d608484015290913d5f60a483013e60048260a4018201526001600160e01b031984168260c4018201528160e40181fd5b5f8060205f8451602086015f885af18061165c576040513d5f823e3d81fd5b50505f513d91508115611673578060011415611680565b6001600160a01b0384163b155b156113db57604051635274afe760e01b81526001600160a01b0385166004820152602401611506565b5f6116b786868686866116c1565b9695505050505050565b5f6001600160a01b03841630146116e7576116e76001600160a01b0386168530866113e1565b604051636e553f6560e01b8152600481018490526001600160a01b038381166024830152871690636e553f65906044016020604051808303815f875af1925050508015611751575060408051601f3d908101601f1916820190925261174e91810190611c21565b60015b6117da5761176a6001600160a01b038616875f196117e1565b604051636e553f6560e01b8152600481018490526001600160a01b038381166024830152871690636e553f65906044016020604051808303815f875af11580156117b6573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117da9190611c21565b90506112b7565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526118328482611870565b6113db576040516001600160a01b0384811660248301525f604483015261186691869182169063095ea7b390606401611416565b6113db848261163d565b5f805f8060205f8651602088015f8a5af192503d91505f5190508280156116b7575081156118a157806001146116b7565b50505050506001600160a01b03163b151590565b6001600160a01b03811681146118c9575f80fd5b50565b8035611226816118b5565b803562ffffff81168114611226575f80fd5b8035600281900b8114611226575f80fd5b5f60a0828403121561190a575f80fd5b60405160a0810181811067ffffffffffffffff8211171561193957634e487b7160e01b5f52604160045260245ffd5b604052905080611948836118cc565b8152611956602084016118cc565b6020820152611967604084016118d7565b6040820152611978606084016118e9565b6060820152611989608084016118cc565b60808201525092915050565b80356001600160801b0381168114611226575f80fd5b5f8083601f8401126119bb575f80fd5b50813567ffffffffffffffff8111156119d2575f80fd5b6020830191508360208285010111156119e9575f80fd5b9250929050565b5f805f805f805f805f6101808a8c031215611a09575f80fd5b611a138b8b6118fa565b9850611a2160a08b016118e9565b9750611a2f60c08b016118e9565b965060e08a01359550611a456101008b01611995565b9450611a546101208b01611995565b93506101408a0135611a65816118b5565b92506101608a013567ffffffffffffffff811115611a81575f80fd5b611a8d8c828d016119ab565b915080935050809150509295985092959850929598565b5f805f805f805f80610160898b031215611abc575f80fd5b611ac68a8a6118fa565b975060a08901359650611adb60c08a01611995565b9550611ae960e08a01611995565b9450611af86101008a01611995565b9350610120890135611b09816118b5565b925061014089013567ffffffffffffffff811115611b25575f80fd5b611b318b828c016119ab565b999c989b5096995094979396929594505050565b5f805f805f805f610140888a031215611b5c575f80fd5b611b6689896118fa565b965060a08801359550611b7b60c08901611995565b9450611b8960e08901611995565b9350610100880135611b9a816118b5565b925061012088013567ffffffffffffffff811115611bb6575f80fd5b611bc28a828b016119ab565b989b979a50959850939692959293505050565b5f805f805f805f610140888a031215611bec575f80fd5b611bf689896118fa565b965060a0880135955060c08801359450611c1260e08901611995565b9350611b9a6101008901611995565b5f60208284031215611c31575f80fd5b5051919050565b87516001600160a01b0390811682526020808a01518216908301526040808a015162ffffff16908301526060808a015160020b908301526080808a015190911690820152611c8b60a082018860020b9052565b611c9a60c082018760020b9052565b8460e0820152611cb66101008201856001600160801b03169052565b6001600160801b0383166101208201526001600160a01b0382166101408201526101806101608201525f611cf161018083015f815260200190565b9998505050505050505050565b5f60208284031215611d0e575f80fd5b81516114d0816118b5565b5f8060408385031215611d2a575f80fd5b8235611d35816118b5565b91506020830135611d45816118b5565b809150509250929050565b634e487b7160e01b5f52603260045260245ffd5b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b604081525f611da46040830185611d64565b828103602084015280845180835260208301915060208160051b840101602087015f5b83811015611df957601f19868403018552611de3838351611d64565b6020958601959093509190910190600101611dc7565b509098975050505050505050565b604081525f611e196040830185611d64565b90508260208301529392505050565b80518015158114611226575f80fd5b5f60208284031215611e47575f80fd5b6114d082611e28565b5f8060408385031215611e61575f80fd5b8251611e6c816118b5565b9150611e7a60208401611e28565b9050925092905056
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000002a1176964f5d7cae5406b627bf6166664fe83c600000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a80
-----Decoded View---------------
Arg [0] : _evc (address): 0x2A1176964F5D7caE5406B627Bf6166664FE83c60
Arg [1] : _positionManager (address): 0x4529A01c7A0410167c5740C487A8DE60232617bf
Arg [2] : _yieldHarvestingHook (address): 0x777ef319C338C6ffE32A2283F603db603E8F2A80
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000002a1176964f5d7cae5406b627bf6166664fe83c60
Arg [1] : 0000000000000000000000004529a01c7a0410167c5740c487a8de60232617bf
Arg [2] : 000000000000000000000000777ef319c338c6ffe32a2283f603db603e8f2a80
Net Worth in USD
Net Worth in ETH
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.