// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {
IArrakisPublicVaultRouter,
AddLiquidityData,
SwapAndAddData,
RemoveLiquidityData,
AddLiquidityPermit2Data,
SwapAndAddPermit2Data,
RemoveLiquidityPermit2Data
} from "./interfaces/IArrakisPublicVaultRouter.sol";
import {TokenPermissions} from "./structs/SPermit2.sol";
import {IArrakisMetaVaultFactory} from
"./interfaces/IArrakisMetaVaultFactory.sol";
import {IArrakisMetaVault} from "./interfaces/IArrakisMetaVault.sol";
import {IArrakisMetaVaultPublic} from
"./interfaces/IArrakisMetaVaultPublic.sol";
import {IRouterSwapExecutor} from
"./interfaces/IRouterSwapExecutor.sol";
import {
IPermit2,
SignatureTransferDetails
} from "./interfaces/IPermit2.sol";
import {IWETH9} from "./interfaces/IWETH9.sol";
import {BASE} from "./constants/CArrakis.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {
SafeERC20,
IERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from
"@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {FullMath} from "@v3-lib-0.8/contracts/FullMath.sol";
// #region solady dependencies.
import {Ownable} from "@solady/contracts/auth/Ownable.sol";
// #endregion solady dependencies.
contract ArrakisPublicVaultRouter is
IArrakisPublicVaultRouter,
ReentrancyGuard,
Ownable,
Pausable
{
using Address for address payable;
using SafeERC20 for IERC20;
// #region immutable properties.
address public immutable nativeToken;
IPermit2 public immutable permit2;
IArrakisMetaVaultFactory public immutable factory;
IWETH9 public immutable weth;
// #endregion immutable properties.
IRouterSwapExecutor public swapper;
// #region modifiers.
modifier onlyPublicVault(address vault_) {
if (!factory.isPublicVault(vault_)) revert OnlyPublicVault();
_;
}
// #endregion modifiers.
constructor(
address nativeToken_,
address permit2_,
address owner_,
address factory_,
address weth_
) {
if (
nativeToken_ == address(0) || permit2_ == address(0)
|| owner_ == address(0) || factory_ == address(0)
|| weth_ == address(0)
) revert AddressZero();
nativeToken = nativeToken_;
permit2 = IPermit2(permit2_);
_initializeOwner(owner_);
factory = IArrakisMetaVaultFactory(factory_);
weth = IWETH9(weth_);
}
// #region owner functions.
/// @notice function used to pause the router.
/// @dev only callable by owner
function pause() external onlyOwner {
_pause();
}
/// @notice function used to unpause the router.
/// @dev only callable by owner
function unpause() external onlyOwner {
_unpause();
}
function updateSwapExecutor(address swapper_)
external
whenNotPaused
onlyOwner
{
if (swapper_ == address(0)) revert AddressZero();
swapper = IRouterSwapExecutor(swapper_);
}
// #endregion owner functions.
/// @notice addLiquidity adds liquidity to meta vault of interest (mints L tokens)
/// @param params_ AddLiquidityData struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function addLiquidity(AddLiquidityData memory params_)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
)
{
// #region checks.
if (params_.amount0Max == 0 && params_.amount1Max == 0) {
revert EmptyMaxAmounts();
}
(sharesReceived, amount0, amount1) = _getMintAmounts(
params_.vault, params_.amount0Max, params_.amount1Max
);
if (sharesReceived == 0) revert NothingToMint();
if (
amount0 < params_.amount0Min
|| amount1 < params_.amount1Min
|| sharesReceived < params_.amountSharesMin
) {
revert BelowMinAmounts();
}
address token0 = IArrakisMetaVault(params_.vault).token0();
address token1 = IArrakisMetaVault(params_.vault).token1();
// #endregion checks.
// #region interactions.
if (token0 != nativeToken && amount0 > 0) {
IERC20(token0).safeTransferFrom(
msg.sender, address(this), amount0
);
}
if (token1 != nativeToken && amount1 > 0) {
IERC20(token1).safeTransferFrom(
msg.sender, address(this), amount1
);
}
_addLiquidity(
params_.vault,
amount0,
amount1,
sharesReceived,
params_.receiver,
token0,
token1
);
if (msg.value > 0) {
if (token0 == nativeToken && msg.value > amount0) {
payable(msg.sender).sendValue(msg.value - amount0);
} else if (token1 == nativeToken && msg.value > amount1) {
payable(msg.sender).sendValue(msg.value - amount1);
}
}
// #endregion interactions.
}
/// @notice swapAndAddLiquidity transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddData struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function swapAndAddLiquidity(SwapAndAddData memory params_)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.addData.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
)
{
// #region checks.
if (
params_.addData.amount0Max == 0
&& params_.addData.amount1Max == 0
) {
revert EmptyMaxAmounts();
}
address token0 =
IArrakisMetaVault(params_.addData.vault).token0();
address token1 =
IArrakisMetaVault(params_.addData.vault).token1();
// #endregion checks.
if (
token0 == nativeToken && params_.addData.amount0Max > 0
&& msg.value != params_.addData.amount0Max
) {
revert NotEnoughNativeTokenSent();
}
if (
token1 == nativeToken && params_.addData.amount1Max > 0
&& msg.value != params_.addData.amount1Max
) {
revert NotEnoughNativeTokenSent();
}
// #region interactions.
if (params_.addData.amount0Max > 0 && token0 != nativeToken) {
IERC20(token0).safeTransferFrom(
msg.sender, address(this), params_.addData.amount0Max
);
}
if (params_.addData.amount1Max > 0 && token1 != nativeToken) {
IERC20(token1).safeTransferFrom(
msg.sender, address(this), params_.addData.amount1Max
);
}
// #endregion interactions.
(amount0, amount1, sharesReceived, amount0Diff, amount1Diff) =
_swapAndAddLiquiditySendBackLeftOver(params_, token0, token1);
}
/// @notice removeLiquidity removes liquidity from vault and burns LP tokens
/// @param params_ RemoveLiquidityData struct containing data for withdrawals
/// @return amount0 actual amount of token0 transferred to receiver for burning `burnAmount`
/// @return amount1 actual amount of token1 transferred to receiver for burning `burnAmount`
function removeLiquidity(RemoveLiquidityData memory params_)
external
nonReentrant
whenNotPaused
onlyPublicVault(params_.vault)
returns (uint256 amount0, uint256 amount1)
{
if (params_.burnAmount == 0) revert NothingToBurn();
IERC20(params_.vault).safeTransferFrom(
msg.sender, address(this), params_.burnAmount
);
(amount0, amount1) = _removeLiquidity(params_);
}
/// @notice addLiquidityPermit2 adds liquidity to public vault of interest (mints LP tokens)
/// @param params_ AddLiquidityPermit2Data struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function addLiquidityPermit2(
AddLiquidityPermit2Data memory params_
)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.addData.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
)
{
// #region checks.
if (
params_.addData.amount0Max == 0
&& params_.addData.amount1Max == 0
) {
revert EmptyMaxAmounts();
}
(sharesReceived, amount0, amount1) = _getMintAmounts(
params_.addData.vault,
params_.addData.amount0Max,
params_.addData.amount1Max
);
if (sharesReceived == 0) revert NothingToMint();
if (
amount0 < params_.addData.amount0Min
|| amount1 < params_.addData.amount1Min
|| sharesReceived < params_.addData.amountSharesMin
) revert BelowMinAmounts();
address token0 =
IArrakisMetaVault(params_.addData.vault).token0();
address token1 =
IArrakisMetaVault(params_.addData.vault).token1();
// #endregion checks.
_permit2AddLengthOneOrTwo(
params_, token0, token1, amount0, amount1
);
_addLiquidity(
params_.addData.vault,
amount0,
amount1,
sharesReceived,
params_.addData.receiver,
token0,
token1
);
}
/// @notice swapAndAddLiquidityPermit2 transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddPermit2Data struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function swapAndAddLiquidityPermit2(
SwapAndAddPermit2Data memory params_
)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.swapAndAddData.addData.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
)
{
if (
params_.swapAndAddData.addData.amount0Max == 0
&& params_.swapAndAddData.addData.amount1Max == 0
) {
revert EmptyMaxAmounts();
}
address token0 = IArrakisMetaVault(
params_.swapAndAddData.addData.vault
).token0();
address token1 = IArrakisMetaVault(
params_.swapAndAddData.addData.vault
).token1();
_permit2SwapAndAddLengthOneOrTwo(params_, token0, token1);
(amount0, amount1, sharesReceived, amount0Diff, amount1Diff) =
_swapAndAddLiquiditySendBackLeftOver(
params_.swapAndAddData, token0, token1
);
}
/// @notice removeLiquidityPermit2 removes liquidity from vault and burns LP tokens
/// @param params_ RemoveLiquidityPermit2Data struct containing data for withdrawals
/// @return amount0 actual amount of token0 transferred to receiver for burning `burnAmount`
/// @return amount1 actual amount of token1 transferred to receiver for burning `burnAmount`
function removeLiquidityPermit2(
RemoveLiquidityPermit2Data memory params_
)
external
nonReentrant
whenNotPaused
onlyPublicVault(params_.removeData.vault)
returns (uint256 amount0, uint256 amount1)
{
if (params_.removeData.burnAmount == 0) {
revert NothingToBurn();
}
SignatureTransferDetails memory transferDetails =
SignatureTransferDetails({
to: address(this),
requestedAmount: params_.removeData.burnAmount
});
permit2.permitTransferFrom(
params_.permit,
transferDetails,
msg.sender,
params_.signature
);
(amount0, amount1) = _removeLiquidity(params_.removeData);
}
/// @notice wrapAndAddLiquidity wrap eth and adds liquidity to meta vault of interest (mints L tokens)
/// @param params_ AddLiquidityData struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function wrapAndAddLiquidity(AddLiquidityData memory params_)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
)
{
if (msg.value == 0) {
revert MsgValueZero();
}
// #region wrap eth.
weth.deposit{value: msg.value}();
// #endregion wrap eth.
// #region checks.
if (params_.amount0Max == 0 && params_.amount1Max == 0) {
revert EmptyMaxAmounts();
}
(sharesReceived, amount0, amount1) = _getMintAmounts(
params_.vault, params_.amount0Max, params_.amount1Max
);
if (sharesReceived == 0) revert NothingToMint();
if (
amount0 < params_.amount0Min
|| amount1 < params_.amount1Min
|| sharesReceived < params_.amountSharesMin
) {
revert BelowMinAmounts();
}
address token0 = IArrakisMetaVault(params_.vault).token0();
address token1 = IArrakisMetaVault(params_.vault).token1();
if (token0 == nativeToken || token1 == nativeToken) {
revert NativeTokenNotSupported();
}
if (token0 != address(weth) && token1 != address(weth)) {
revert NoWethToken();
}
// #endregion checks.
// #region interactions.
if (token0 != address(weth) && amount0 > 0) {
IERC20(token0).safeTransferFrom(
msg.sender, address(this), amount0
);
}
if (token1 != address(weth) && amount1 > 0) {
IERC20(token1).safeTransferFrom(
msg.sender, address(this), amount1
);
}
_addLiquidity(
params_.vault,
amount0,
amount1,
sharesReceived,
params_.receiver,
token0,
token1
);
if (token0 == address(weth) && msg.value > amount0) {
weth.withdraw(msg.value - amount0);
payable(msg.sender).sendValue(msg.value - amount0);
} else if (token1 == address(weth) && msg.value > amount1) {
weth.withdraw(msg.value - amount1);
payable(msg.sender).sendValue(msg.value - amount1);
}
// #endregion interactions.
}
/// @notice wrapAndSwapAndAddLiquidity wrap eth and transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddData struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function wrapAndSwapAndAddLiquidity(SwapAndAddData memory params_)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.addData.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
)
{
if (msg.value == 0) {
revert MsgValueZero();
}
// #region wrap eth.
weth.deposit{value: msg.value}();
// #endregion wrap eth.
// #region checks.
if (
params_.addData.amount0Max == 0
&& params_.addData.amount1Max == 0
) {
revert EmptyMaxAmounts();
}
address token0 =
IArrakisMetaVault(params_.addData.vault).token0();
address token1 =
IArrakisMetaVault(params_.addData.vault).token1();
// #endregion checks.
if (token0 == nativeToken || token1 == nativeToken) {
revert NativeTokenNotSupported();
}
if (token0 != address(weth) && token1 != address(weth)) {
revert NoWethToken();
}
// #region interactions.
if (token0 != address(weth)) {
if (params_.addData.amount0Max > 0) {
IERC20(token0).safeTransferFrom(
msg.sender,
address(this),
params_.addData.amount0Max
);
}
} else if (params_.addData.amount0Max != msg.value) {
revert MsgValueDTMaxAmount();
}
if (token1 != address(weth)) {
if (params_.addData.amount1Max > 0) {
IERC20(token1).safeTransferFrom(
msg.sender,
address(this),
params_.addData.amount1Max
);
}
} else if (params_.addData.amount1Max != msg.value) {
revert MsgValueDTMaxAmount();
}
// #endregion interactions.
(
,
,
amount0,
amount1,
sharesReceived,
amount0Diff,
amount1Diff
) = _swapAndAddLiquidity(params_, token0, token1);
/// @dev hack to get rid of stack too depth
uint256 amount0Use = (params_.swapData.zeroForOne)
? params_.addData.amount0Max - amount0Diff
: params_.addData.amount0Max + amount0Diff;
uint256 amount1Use = (params_.swapData.zeroForOne)
? params_.addData.amount1Max + amount1Diff
: params_.addData.amount1Max - amount1Diff;
unchecked {
if (amount0Use > amount0) {
if (token0 == address(weth)) {
weth.withdraw(amount0Use - amount0);
payable(msg.sender).sendValue(
amount0Use - amount0
);
} else {
uint256 balance =
IERC20(token0).balanceOf(address(this));
IERC20(token0).safeTransfer(msg.sender, balance);
}
}
if (amount1Use > amount1) {
if (token1 == address(weth)) {
weth.withdraw(amount1Use - amount1);
payable(msg.sender).sendValue(
amount1Use - amount1
);
} else {
uint256 balance =
IERC20(token1).balanceOf(address(this));
IERC20(token1).safeTransfer(msg.sender, balance);
}
}
}
}
/// @notice wrapAndAddLiquidityPermit2 wrap eth and adds liquidity to public vault of interest (mints LP tokens)
/// @param params_ AddLiquidityPermit2Data struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function wrapAndAddLiquidityPermit2(
AddLiquidityPermit2Data memory params_
)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.addData.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
)
{
if (msg.value == 0) {
revert MsgValueZero();
}
// #region wrap eth.
weth.deposit{value: msg.value}();
// #endregion wrap eth.
// #region checks.
if (
params_.addData.amount0Max == 0
&& params_.addData.amount1Max == 0
) {
revert EmptyMaxAmounts();
}
(sharesReceived, amount0, amount1) = _getMintAmounts(
params_.addData.vault,
params_.addData.amount0Max,
params_.addData.amount1Max
);
if (sharesReceived == 0) revert NothingToMint();
if (
amount0 < params_.addData.amount0Min
|| amount1 < params_.addData.amount1Min
|| sharesReceived < params_.addData.amountSharesMin
) revert BelowMinAmounts();
address token0 =
IArrakisMetaVault(params_.addData.vault).token0();
address token1 =
IArrakisMetaVault(params_.addData.vault).token1();
if (token0 == nativeToken || token1 == nativeToken) {
revert NativeTokenNotSupported();
}
if (token0 != address(weth) && token1 != address(weth)) {
revert NoWethToken();
}
// #endregion checks.
_permit2AddLengthOne(
params_, token0, token1, amount0, amount1
);
_addLiquidity(
params_.addData.vault,
amount0,
amount1,
sharesReceived,
params_.addData.receiver,
token0,
token1
);
unchecked {
if (token0 == address(weth) && msg.value > amount0) {
weth.withdraw(msg.value - amount0);
payable(msg.sender).sendValue(msg.value - amount0);
} else if (token1 == address(weth) && msg.value > amount1)
{
weth.withdraw(msg.value - amount1);
payable(msg.sender).sendValue(msg.value - amount1);
}
}
}
/// @notice wrapAndSwapAndAddLiquidityPermit2 wrap eth and transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddPermit2Data struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function wrapAndSwapAndAddLiquidityPermit2(
SwapAndAddPermit2Data memory params_
)
external
payable
nonReentrant
whenNotPaused
onlyPublicVault(params_.swapAndAddData.addData.vault)
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
)
{
if (msg.value == 0) {
revert MsgValueZero();
}
// #region wrap eth.
weth.deposit{value: msg.value}();
// #endregion wrap eth.
if (
params_.swapAndAddData.addData.amount0Max == 0
&& params_.swapAndAddData.addData.amount1Max == 0
) {
revert EmptyMaxAmounts();
}
address token0 = IArrakisMetaVault(
params_.swapAndAddData.addData.vault
).token0();
address token1 = IArrakisMetaVault(
params_.swapAndAddData.addData.vault
).token1();
if (token0 == nativeToken || token1 == nativeToken) {
revert NativeTokenNotSupported();
}
if (token0 != address(weth) && token1 != address(weth)) {
revert NoWethToken();
}
if (
token0 == address(weth)
&& params_.swapAndAddData.addData.amount0Max != msg.value
) {
revert MsgValueDTMaxAmount();
}
if (
token1 == address(weth)
&& params_.swapAndAddData.addData.amount1Max != msg.value
) {
revert MsgValueDTMaxAmount();
}
_permit2SwapAndAddLengthOne(params_, token0, token1);
(
,
,
amount0,
amount1,
sharesReceived,
amount0Diff,
amount1Diff
) = _swapAndAddLiquidity(
params_.swapAndAddData, token0, token1
);
/// @dev hack to get rid of stack too depth
uint256 amount0Use = (
params_.swapAndAddData.swapData.zeroForOne
)
? params_.swapAndAddData.addData.amount0Max - amount0Diff
: params_.swapAndAddData.addData.amount0Max + amount0Diff;
uint256 amount1Use = (
params_.swapAndAddData.swapData.zeroForOne
)
? params_.swapAndAddData.addData.amount1Max + amount1Diff
: params_.swapAndAddData.addData.amount1Max - amount1Diff;
if (amount0Use > amount0) {
if (token0 == address(weth)) {
weth.withdraw(amount0Use - amount0);
payable(msg.sender).sendValue(amount0Use - amount0);
} else {
uint256 balance =
IERC20(token0).balanceOf(address(this));
IERC20(token0).safeTransfer(msg.sender, balance);
}
}
if (amount1Use > amount1) {
if (token1 == address(weth)) {
weth.withdraw(amount1Use - amount1);
payable(msg.sender).sendValue(amount1Use - amount1);
} else {
uint256 balance =
IERC20(token1).balanceOf(address(this));
IERC20(token1).safeTransfer(msg.sender, balance);
}
}
}
receive() external payable {}
// #region external view functions.
/// @notice getMintAmounts used to get the shares we can mint from some max amounts.
/// @param vault_ meta vault address.
/// @param maxAmount0_ maximum amount of token0 user want to contribute.
/// @param maxAmount1_ maximum amount of token1 user want to contribute.
/// @return shareToMint maximum amount of share user can get for 'maxAmount0_' and 'maxAmount1_'.
/// @return amount0ToDeposit amount of token0 user should deposit into the vault for minting 'shareToMint'.
/// @return amount1ToDeposit amount of token1 user should deposit into the vault for minting 'shareToMint'.
function getMintAmounts(
address vault_,
uint256 maxAmount0_,
uint256 maxAmount1_
)
external
view
returns (
uint256 shareToMint,
uint256 amount0ToDeposit,
uint256 amount1ToDeposit
)
{
return _getMintAmounts(vault_, maxAmount0_, maxAmount1_);
}
// #endregion external view functions.
// #region internal functions.
function _addLiquidity(
address vault_,
uint256 amount0_,
uint256 amount1_,
uint256 shares_,
address receiver_,
address token0_,
address token1_
) internal {
address module = address(IArrakisMetaVault(vault_).module());
uint256 valueToSend;
if (token0_ != nativeToken) {
IERC20(token0_).forceApprove(module, amount0_);
} else {
valueToSend = amount0_;
}
if (token1_ != nativeToken) {
IERC20(token1_).forceApprove(module, amount1_);
} else {
valueToSend = amount1_;
}
IArrakisMetaVaultPublic(vault_).mint{value: valueToSend}(
shares_, receiver_
);
}
function _swapAndAddLiquidity(
SwapAndAddData memory params_,
address token0_,
address token1_
)
internal
returns (
uint256 amount0Use,
uint256 amount1Use,
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
)
{
uint256 valueToSend;
if (params_.swapData.zeroForOne) {
if (token0_ != nativeToken) {
IERC20(token0_).safeTransfer(
address(swapper), params_.swapData.amountInSwap
);
} else {
valueToSend = params_.swapData.amountInSwap;
}
} else {
if (token1_ != nativeToken) {
IERC20(token1_).safeTransfer(
address(swapper), params_.swapData.amountInSwap
);
} else {
valueToSend = params_.swapData.amountInSwap;
}
}
(amount0Diff, amount1Diff) =
swapper.swap{value: valueToSend}(params_);
emit Swapped(
params_.swapData.zeroForOne,
amount0Diff,
amount1Diff,
params_.swapData.amountOutSwap
);
amount0Use = (params_.swapData.zeroForOne)
? params_.addData.amount0Max - amount0Diff
: params_.addData.amount0Max + amount0Diff;
amount1Use = (params_.swapData.zeroForOne)
? params_.addData.amount1Max + amount1Diff
: params_.addData.amount1Max - amount1Diff;
(sharesReceived, amount0, amount1) = _getMintAmounts(
params_.addData.vault, amount0Use, amount1Use
);
if (sharesReceived == 0) revert NothingToMint();
if (
amount0 < params_.addData.amount0Min
|| amount1 < params_.addData.amount1Min
|| sharesReceived < params_.addData.amountSharesMin
) revert BelowMinAmounts();
_addLiquidity(
params_.addData.vault,
amount0,
amount1,
sharesReceived,
params_.addData.receiver,
token0_,
token1_
);
}
function _swapAndAddLiquiditySendBackLeftOver(
SwapAndAddData memory params_,
address token0_,
address token1_
)
internal
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
)
{
uint256 amount0Use;
uint256 amount1Use;
(
amount0Use,
amount1Use,
amount0,
amount1,
sharesReceived,
amount0Diff,
amount1Diff
) = _swapAndAddLiquidity(params_, token0_, token1_);
if (amount0Use > amount0) {
if (token0_ == nativeToken) {
payable(msg.sender).sendValue(amount0Use - amount0);
} else {
uint256 balance =
IERC20(token0_).balanceOf(address(this));
IERC20(token0_).safeTransfer(msg.sender, balance);
}
}
if (amount1Use > amount1) {
if (token1_ == nativeToken) {
payable(msg.sender).sendValue(amount1Use - amount1);
} else {
uint256 balance =
IERC20(token1_).balanceOf(address(this));
IERC20(token1_).safeTransfer(msg.sender, balance);
}
}
}
function _removeLiquidity(RemoveLiquidityData memory params_)
internal
returns (uint256 amount0, uint256 amount1)
{
(amount0, amount1) = IArrakisMetaVaultPublic(params_.vault)
.burn(params_.burnAmount, params_.receiver);
if (
amount0 < params_.amount0Min
|| amount1 < params_.amount1Min
) {
revert ReceivedBelowMinimum();
}
}
function _permit2AddLengthOne(
AddLiquidityPermit2Data memory params_,
address token0_,
address token1_,
uint256 amount0_,
uint256 amount1_
) internal {
uint256 permittedLength = params_.permit.permitted.length;
if (permittedLength != 1) {
revert LengthMismatch();
}
if (params_.permit.permitted[0].token == address(weth)) {
revert Permit2WethNotAuthorized();
}
_permit2Add(
permittedLength,
params_,
token0_,
token1_,
amount0_,
amount1_
);
}
function _permit2AddLengthOneOrTwo(
AddLiquidityPermit2Data memory params_,
address token0_,
address token1_,
uint256 amount0_,
uint256 amount1_
) internal {
uint256 permittedLength = params_.permit.permitted.length;
if (permittedLength != 2 && permittedLength != 1) {
revert LengthMismatch();
}
_permit2Add(
permittedLength,
params_,
token0_,
token1_,
amount0_,
amount1_
);
}
function _permit2Add(
uint256 permittedLength_,
AddLiquidityPermit2Data memory params_,
address token0_,
address token1_,
uint256 amount0_,
uint256 amount1_
) internal {
SignatureTransferDetails[] memory transfers =
new SignatureTransferDetails[](permittedLength_);
for (uint256 i; i < permittedLength_; i++) {
TokenPermissions memory tokenPermission =
params_.permit.permitted[i];
if (tokenPermission.token == token0_) {
transfers[i] = SignatureTransferDetails({
to: address(this),
requestedAmount: amount0_
});
}
if (tokenPermission.token == token1_) {
transfers[i] = SignatureTransferDetails({
to: address(this),
requestedAmount: amount1_
});
}
}
permit2.permitTransferFrom(
params_.permit, transfers, msg.sender, params_.signature
);
}
function _permit2SwapAndAddLengthOne(
SwapAndAddPermit2Data memory params_,
address token0_,
address token1_
) internal {
uint256 permittedLength = params_.permit.permitted.length;
if (permittedLength != 1) {
revert LengthMismatch();
}
if (params_.permit.permitted[0].token == address(weth)) {
revert Permit2WethNotAuthorized();
}
_permit2SwapAndAdd(permittedLength, params_, token0_, token1_);
}
function _permit2SwapAndAddLengthOneOrTwo(
SwapAndAddPermit2Data memory params_,
address token0_,
address token1_
) internal {
uint256 permittedLength = params_.permit.permitted.length;
if (permittedLength != 2 && permittedLength != 1) {
revert LengthMismatch();
}
_permit2SwapAndAdd(permittedLength, params_, token0_, token1_);
}
function _permit2SwapAndAdd(
uint256 permittedLength_,
SwapAndAddPermit2Data memory params_,
address token0_,
address token1_
) internal {
SignatureTransferDetails[] memory transfers =
new SignatureTransferDetails[](permittedLength_);
for (uint256 i; i < permittedLength_; i++) {
TokenPermissions memory tokenPermission =
params_.permit.permitted[i];
if (tokenPermission.token == token0_) {
transfers[i] = SignatureTransferDetails({
to: address(this),
requestedAmount: params_
.swapAndAddData
.addData
.amount0Max
});
}
if (tokenPermission.token == token1_) {
transfers[i] = SignatureTransferDetails({
to: address(this),
requestedAmount: params_
.swapAndAddData
.addData
.amount1Max
});
}
}
permit2.permitTransferFrom(
params_.permit, transfers, msg.sender, params_.signature
);
}
// #endregion internal functions.
// #region internal view functions.
function _getMintAmounts(
address vault_,
uint256 maxAmount0_,
uint256 maxAmount1_
)
internal
view
returns (
uint256 shareToMint,
uint256 amount0ToDeposit,
uint256 amount1ToDeposit
)
{
(uint256 amount0, uint256 amount1) =
IArrakisMetaVault(vault_).totalUnderlying();
uint256 supply = IERC20(vault_).totalSupply();
if (supply == 0) {
(amount0, amount1) = IArrakisMetaVault(vault_).getInits();
supply = BASE;
}
uint256 proportion0 = amount0 == 0
? type(uint256).max
: FullMath.mulDiv(maxAmount0_, BASE, amount0);
uint256 proportion1 = amount1 == 0
? type(uint256).max
: FullMath.mulDiv(maxAmount1_, BASE, amount1);
uint256 proportion =
proportion0 < proportion1 ? proportion0 : proportion1;
shareToMint = FullMath.mulDiv(proportion, supply, BASE);
proportion = FullMath.mulDivRoundingUp(
shareToMint, BASE, supply
);
amount0ToDeposit =
FullMath.mulDivRoundingUp(amount0, proportion, BASE);
amount1ToDeposit =
FullMath.mulDivRoundingUp(amount1, proportion, BASE);
}
// #endregion internal view functions.
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
uint256 constant MINIMUM_LIQUIDITY = 10 ** 3;
uint256 constant BASE = 1e18;
uint24 constant PIPS = 1_000_000;
uint24 constant TEN_PERCENT = 100_000;
uint256 constant WEEK = 604_800;
address constant NATIVE_COIN =
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
/// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
/// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
function mulDiv(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = a * b
// Compute the product mod 2**256 and mod 2**256 - 1
// then use the Chinese Remainder Theorem to reconstruct
// the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2**256 + prod0
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(a, b, not(0))
prod0 := mul(a, b)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division
if (prod1 == 0) {
require(denominator > 0);
assembly {
result := div(prod0, denominator)
}
return result;
}
// Make sure the result is less than 2**256.
// Also prevents denominator == 0
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0]
// Compute remainder using mulmod
uint256 remainder;
assembly {
remainder := mulmod(a, b, denominator)
}
// Subtract 256 bit number from 512 bit number
assembly {
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator
// Compute largest power of two divisor of denominator.
// Always >= 1.
// EDIT for 0.8 compatibility:
// see: https://ethereum.stackexchange.com/questions/96642/unary-operator-cannot-be-applied-to-type-uint256
uint256 twos = denominator & (~denominator + 1);
// Divide denominator by power of two
assembly {
denominator := div(denominator, twos)
}
// Divide [prod1 prod0] by the factors of two
assembly {
prod0 := div(prod0, twos)
}
// Shift in bits from prod1 into prod0. For this we need
// to flip `twos` such that it is 2**256 / twos.
// If twos is zero, then it becomes one
assembly {
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
// Invert denominator mod 2**256
// Now that denominator is an odd number, it has an inverse
// modulo 2**256 such that denominator * inv = 1 mod 2**256.
// Compute the inverse by starting with a seed that is correct
// correct for four bits. That is, denominator * inv = 1 mod 2**4
uint256 inv = (3 * denominator) ^ 2;
// Now use Newton-Raphson iteration to improve the precision.
// Thanks to Hensel's lifting lemma, this also works in modular
// arithmetic, doubling the correct bits in each step.
inv *= 2 - denominator * inv; // inverse mod 2**8
inv *= 2 - denominator * inv; // inverse mod 2**16
inv *= 2 - denominator * inv; // inverse mod 2**32
inv *= 2 - denominator * inv; // inverse mod 2**64
inv *= 2 - denominator * inv; // inverse mod 2**128
inv *= 2 - denominator * inv; // inverse mod 2**256
// Because the division is now exact we can divide by multiplying
// with the modular inverse of denominator. This will give us the
// correct result modulo 2**256. Since the precoditions guarantee
// that the outcome is less than 2**256, this is the final result.
// We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inv;
return result;
}
}
/// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
/// @param a The multiplicand
/// @param b The multiplier
/// @param denominator The divisor
/// @return result The 256-bit result
function mulDivRoundingUp(
uint256 a,
uint256 b,
uint256 denominator
) internal pure returns (uint256 result) {
result = mulDiv(a, b, denominator);
if (mulmod(a, b, denominator) > 0) {
require(result < type(uint256).max);
result++;
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {IERC20Metadata} from
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IArrakisMetaVault} from "./IArrakisMetaVault.sol";
import {IOracleWrapper} from "./IOracleWrapper.sol";
/// @title Liquidity providing module interface.
/// @author Arrakis Finance
/// @notice Module interfaces, modules are implementing differents strategies that an
/// arrakis module can use.
interface IArrakisLPModule {
// #region errors.
/// @dev triggered when an address that should not
/// be zero is equal to address zero.
error AddressZero();
/// @dev triggered when the caller is different than
/// the metaVault that own this module.
error OnlyMetaVault(address caller, address metaVault);
/// @dev triggered when the caller is different than
/// the manager defined by the metaVault.
error OnlyManager(address caller, address manager);
/// @dev triggered if proportion of minting or burning is
/// zero.
error ProportionZero();
/// @dev triggered if during withdraw more than 100% of the
/// position.
error ProportionGtBASE();
/// @dev triggered when manager want to set his more
/// earned by the position than 100% of fees earned.
error NewFeesGtPIPS(uint256 newFees);
/// @dev triggered when manager is setting the same fees
/// that already active.
error SameManagerFee();
/// @dev triggered when inits values are zeros.
error InitsAreZeros();
/// @dev triggered when pause/unpaused function is
/// called by someone else than guardian.
error OnlyGuardian();
// #endregion errors.
// #region events.
/// @notice Event describing a withdrawal of participation by an user inside this module.
/// @dev withdraw action can be indexed by receiver.
/// @param receiver address that will receive the tokens withdrawn.
/// @param proportion percentage of the current position that user want to withdraw.
/// @param amount0 amount of token0 send to "receiver" due to withdraw action.
/// @param amount1 amount of token1 send to "receiver" due to withdraw action.
event LogWithdraw(
address indexed receiver,
uint256 proportion,
uint256 amount0,
uint256 amount1
);
/// @notice Event describing a manager fee withdrawal.
/// @param manager address of the manager that will fees earned due to his fund management.
/// @param amount0 amount of token0 that manager has earned and will be transfered.
/// @param amount1 amount of token1 that manager has earned and will be transfered.
event LogWithdrawManagerBalance(
address manager, uint256 amount0, uint256 amount1
);
/// @notice Event describing manager set his fees.
/// @param oldFee fees share that have been taken by manager.
/// @param newFee fees share that have been taken by manager.
event LogSetManagerFeePIPS(uint256 oldFee, uint256 newFee);
// #endregion events.
/// @notice function used to pause the module.
/// @dev only callable by guardian
function pause() external;
/// @notice function used to unpause the module.
/// @dev only callable by guardian
function unpause() external;
/// @notice function used to initialize the module
/// when a module switch happen
/// @param data_ bytes that contain information to initialize
/// the position.
function initializePosition(bytes calldata data_) external;
/// @notice function used by metaVault to withdraw tokens from the strategy.
/// @param receiver_ address that will receive tokens.
/// @param proportion_ the proportion of the total position that need to be withdrawn.
/// @return amount0 amount of token0 withdrawn.
/// @return amount1 amount of token1 withdrawn.
function withdraw(
address receiver_,
uint256 proportion_
) external returns (uint256 amount0, uint256 amount1);
/// @notice function used by metaVault or manager to get manager fees.
/// @return amount0 amount of token0 sent to manager.
/// @return amount1 amount of token1 sent to manager.
function withdrawManagerBalance()
external
returns (uint256 amount0, uint256 amount1);
/// @notice function used to set manager fees.
/// @param newFeePIPS_ new fee that will be applied.
function setManagerFeePIPS(uint256 newFeePIPS_) external;
// #region view functions.
/// @notice function used to get metaVault as IArrakisMetaVault.
/// @return metaVault that implement IArrakisMetaVault.
function metaVault() external view returns (IArrakisMetaVault);
/// @notice function used to get the address that can pause the module.
/// @return guardian address of the pauser.
function guardian() external view returns (address);
/// @notice function used to get manager token0 balance.
/// @dev amount of fees in token0 that manager have not taken yet.
/// @return managerBalance0 amount of token0 that manager earned.
function managerBalance0() external view returns (uint256);
/// @notice function used to get manager token1 balance.
/// @dev amount of fees in token1 that manager have not taken yet.
/// @return managerBalance1 amount of token1 that manager earned.
function managerBalance1() external view returns (uint256);
/// @notice function used to get manager fees.
/// @return managerFeePIPS amount of token1 that manager earned.
function managerFeePIPS() external view returns (uint256);
/// @notice function used to get token0 as IERC20Metadata.
/// @return token0 as IERC20Metadata.
function token0() external view returns (IERC20Metadata);
/// @notice function used to get token0 as IERC20Metadata.
/// @return token1 as IERC20Metadata.
function token1() external view returns (IERC20Metadata);
/// @notice function used to get the initial amounts needed to open a position.
/// @return init0 the amount of token0 needed to open a position.
/// @return init1 the amount of token1 needed to open a position.
function getInits()
external
view
returns (uint256 init0, uint256 init1);
/// @notice function used to get the amount of token0 and token1 sitting
/// on the position.
/// @return amount0 the amount of token0 sitting on the position.
/// @return amount1 the amount of token1 sitting on the position.
function totalUnderlying()
external
view
returns (uint256 amount0, uint256 amount1);
/// @notice function used to get the amounts of token0 and token1 sitting
/// on the position for a specific price.
/// @param priceX96_ price at which we want to simulate our tokens composition
/// @return amount0 the amount of token0 sitting on the position for priceX96.
/// @return amount1 the amount of token1 sitting on the position for priceX96.
function totalUnderlyingAtPrice(uint160 priceX96_)
external
view
returns (uint256 amount0, uint256 amount1);
/// @notice function used to validate if module state is not manipulated
/// before rebalance.
/// @param oracle_ oracle that will used to check internal state.
/// @param maxDeviation_ maximum deviation allowed.
function validateRebalance(
IOracleWrapper oracle_,
uint24 maxDeviation_
) external view;
// #endregion view function.
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {IArrakisLPModule} from "./IArrakisLPModule.sol";
/// @title IArrakisMetaVault
/// @notice IArrakisMetaVault is a vault that is able to invest dynamically deposited
/// tokens into protocols through his module.
interface IArrakisMetaVault {
// #region errors.
/// @dev triggered when an address that should not
/// be zero is equal to address zero.
error AddressZero(string property);
/// @dev triggered when the caller is different than
/// the manager.
error OnlyManager(address caller, address manager);
/// @dev triggered when a low level call failed during
/// execution.
error CallFailed();
/// @dev triggered when manager try to set the active
/// module as active.
error SameModule();
/// @dev triggered when owner of the vault try to set the
/// manager with the current manager.
error SameManager();
/// @dev triggered when all tokens withdrawal has been done
/// during a switch of module.
error ModuleNotEmpty(uint256 amount0, uint256 amount1);
/// @dev triggered when owner try to whitelist a module
/// that has been already whitelisted.
error AlreadyWhitelisted(address module);
/// @dev triggered when owner try to blacklist a module
/// that has not been whitelisted.
error NotWhitelistedModule(address module);
/// @dev triggered when owner try to blacklist the active module.
error ActiveModule();
/// @dev triggered during vault creation if token0 address is greater than
/// token1 address.
error Token0GtToken1();
/// @dev triggered during vault creation if token0 address is equal to
/// token1 address.
error Token0EqToken1();
/// @dev triggered when whitelisting action is occuring and module's beacon
/// is not whitelisted on module registry.
error NotWhitelistedBeacon();
/// @dev triggered when guardian of the whitelisting module is different than
/// the guardian of the registry.
error NotSameGuardian();
/// @dev triggered when a function logic is not implemented.
error NotImplemented();
/// @dev triggered when two arrays suppposed to have the same length, have different length.
error ArrayNotSameLength();
/// @dev triggered when function is called by someone else than the owner.
error OnlyOwner();
/// @dev triggered when setModule action try to remove funds.
error WithdrawNotAllowed();
/// @dev triggered when setModule function end without
/// initiliazePosition call.
error PositionNotInitialized();
/// @dev triggered when the first external call of setModule function
/// isn't InitializePosition function.
error NotPositionInitializationCall();
// #endregion errors.
// #region events.
/// @notice Event describing a manager fee withdrawal.
/// @param amount0 amount of token0 that manager has earned and will be transfered.
/// @param amount1 amount of token1 that manager has earned and will be transfered.
event LogWithdrawManagerBalance(uint256 amount0, uint256 amount1);
/// @notice Event describing owner setting the manager.
/// @param manager address of manager that will manage the portfolio.
event LogSetManager(address manager);
/// @notice Event describing manager setting the module.
/// @param module address of the new active module.
/// @param payloads data payloads for initializing positions on the new module.
event LogSetModule(address module, bytes[] payloads);
/// @notice Event describing default module that the vault will be initialized with.
/// @param module address of the default module.
event LogSetFirstModule(address module);
/// @notice Event describing list of modules that has been whitelisted by owner.
/// @param modules list of addresses corresponding to new modules now available
/// to be activated by manager.
event LogWhiteListedModules(address[] modules);
/// @notice Event describing whitelisted of the first module during vault creation.
/// @param module default activation.
event LogWhitelistedModule(address module);
/// @notice Event describing blacklisting action of modules by owner.
/// @param modules list of addresses corresponding to old modules that has been
/// blacklisted.
event LogBlackListedModules(address[] modules);
// #endregion events.
/// @notice function used to initialize default module.
/// @param module_ address of the default module.
function initialize(address module_) external;
/// @notice function used to set module
/// @param module_ address of the new module
/// @param payloads_ datas to initialize/rebalance on the new module
function setModule(
address module_,
bytes[] calldata payloads_
) external;
/// @notice function used to whitelist modules that can used by manager.
/// @param beacons_ array of beacons addresses to use for modules creation.
/// @param data_ array of payload to use for modules creation.
function whitelistModules(
address[] calldata beacons_,
bytes[] calldata data_
) external;
/// @notice function used to blacklist modules that can used by manager.
/// @param modules_ array of module addresses to be blacklisted.
function blacklistModules(address[] calldata modules_) external;
// #region view functions.
/// @notice function used to get the list of modules whitelisted.
/// @return modules whitelisted modules addresses.
function whitelistedModules()
external
view
returns (address[] memory modules);
/// @notice function used to get the amount of token0 and token1 sitting
/// on the position.
/// @return amount0 the amount of token0 sitting on the position.
/// @return amount1 the amount of token1 sitting on the position.
function totalUnderlying()
external
view
returns (uint256 amount0, uint256 amount1);
/// @notice function used to get the amounts of token0 and token1 sitting
/// on the position for a specific price.
/// @param priceX96 price at which we want to simulate our tokens composition
/// @return amount0 the amount of token0 sitting on the position for priceX96.
/// @return amount1 the amount of token1 sitting on the position for priceX96.
function totalUnderlyingAtPrice(uint160 priceX96)
external
view
returns (uint256 amount0, uint256 amount1);
/// @notice function used to get the initial amounts needed to open a position.
/// @return init0 the amount of token0 needed to open a position.
/// @return init1 the amount of token1 needed to open a position.
function getInits()
external
view
returns (uint256 init0, uint256 init1);
/// @notice function used to get the address of token0.
function token0() external view returns (address);
/// @notice function used to get the address of token1.
function token1() external view returns (address);
/// @notice function used to get manager address.
function manager() external view returns (address);
/// @notice function used to get module used to
/// open/close/manager a position.
function module() external view returns (IArrakisLPModule);
/// @notice function used to get module registry.
/// @return registry address of module registry.
function moduleRegistry()
external
view
returns (address registry);
// #endregion view functions.
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IArrakisMetaVaultFactory {
// #region errors.
error AddressZero();
/// @dev triggered when querying vaults on factory
/// and start index is lower than end index.
error StartIndexLtEndIndex(uint256 startIndex, uint256 endIndex);
/// @dev triggered when querying vaults on factory
/// and end index of the query is bigger the biggest index of the vaults array.
error EndIndexGtNbOfVaults(
uint256 endIndex, uint256 numberOfVaults
);
/// @dev triggered when owner want to whitelist a deployer that has been already
/// whitelisted.
error AlreadyWhitelistedDeployer(address deployer);
/// @dev triggered when owner want to blackist a deployer that is not a current
/// deployer.
error NotAlreadyADeployer(address deployer);
/// @dev triggered when public vault deploy function is
/// called by an address that is not a deployer.
error NotADeployer();
/// @dev triggered when init management low level failed.
error CallFailed();
/// @dev triggered when init management happened and still the vault is
/// not under management by manager.
error VaultNotManaged();
/// @dev triggered when owner is setting a new manager, and the new manager
/// address match with the old manager address.
error SameManager();
// #endregion errors.
// #region events.
/// @notice event emitted when public vault is created by a deployer.
/// @param creator address that is creating the public vault, a deployer.
/// @param salt salt used for create3.
/// @param token0 first token of the token pair.
/// @param token1 second token of the token pair.
/// @param owner address of the owner.
/// @param module default module that will be used by the meta vault.
/// @param publicVault address of the deployed meta vault.
/// @param timeLock timeLock that will owned the meta vault.
event LogPublicVaultCreation(
address indexed creator,
bytes32 salt,
address token0,
address token1,
address owner,
address module,
address publicVault,
address timeLock
);
/// @notice event emitted when private vault is created.
/// @param creator address that is deploying the vault.
/// @param salt salt used for create3.
/// @param token0 address of the first token of the pair.
/// @param token1 address of the second token of the pair.
/// @param owner address that will owned the private vault.
/// @param module address of the default module.
/// @param privateVault address of the deployed meta vault.
event LogPrivateVaultCreation(
address indexed creator,
bytes32 salt,
address token0,
address token1,
address owner,
address module,
address privateVault
);
/// @notice event emitted when whitelisting an array of public vault
/// deployers.
/// @param deployers list of deployers added to the whitelist.
event LogWhitelistDeployers(address[] deployers);
/// @notice event emitted when blacklisting an array of public vault
/// deployers.
/// @param deployers list of deployers removed from the whitelist.
event LogBlacklistDeployers(address[] deployers);
/// @notice event emitted when owner set a new manager.
/// @param oldManager address of the previous manager.
/// @param newManager address of the new manager.
event LogSetManager(address oldManager, address newManager);
// #endregion events.
// #region state changing functions.
/// @notice function used to pause the factory.
/// @dev only callable by owner.
function pause() external;
/// @notice function used to unpause the factory.
/// @dev only callable by owner.
function unpause() external;
/// @notice function used to set a new manager.
/// @param newManager_ address that will managed newly created vault.
/// @dev only callable by owner.
function setManager(address newManager_) external;
/// @notice function used to deploy ERC20 token wrapped Arrakis
/// Meta Vault.
/// @param salt_ bytes32 used to get a deterministic all chains address.
/// @param token0_ address of the first token of the token pair.
/// @param token1_ address of the second token of the token pair.
/// @param owner_ address of the owner of the vault.
/// @param beacon_ address of the beacon that will be used to create the default module.
/// @param moduleCreationPayload_ payload for initializing the module.
/// @param initManagementPayload_ data for initialize management.
/// @return vault address of the newly created Token Meta Vault.
function deployPublicVault(
bytes32 salt_,
address token0_,
address token1_,
address owner_,
address beacon_,
bytes calldata moduleCreationPayload_,
bytes calldata initManagementPayload_
) external returns (address vault);
/// @notice function used to deploy owned Arrakis
/// Meta Vault.
/// @param salt_ bytes32 needed to compute vault address deterministic way.
/// @param token0_ address of the first token of the token pair.
/// @param token1_ address of the second token of the token pair.
/// @param owner_ address of the owner of the vault.
/// @param beacon_ address of the beacon that will be used to create the default module.
/// @param moduleCreationPayload_ payload for initializing the module.
/// @param initManagementPayload_ data for initialize management.
/// @return vault address of the newly created private Meta Vault.
function deployPrivateVault(
bytes32 salt_,
address token0_,
address token1_,
address owner_,
address beacon_,
bytes calldata moduleCreationPayload_,
bytes calldata initManagementPayload_
) external returns (address vault);
/// @notice function used to grant the role to deploy to a list of addresses.
/// @param deployers_ list of addresses that owner want to grant permission to deploy.
function whitelistDeployer(address[] calldata deployers_)
external;
/// @notice function used to grant the role to deploy to a list of addresses.
/// @param deployers_ list of addresses that owner want to revoke permission to deploy.
function blacklistDeployer(address[] calldata deployers_)
external;
// #endregion state changing functions.
// #region view/pure functions.
/// @notice get Arrakis Modular standard token name for two corresponding tokens.
/// @param token0_ address of the first token.
/// @param token1_ address of the second token.
/// @return name name of the arrakis modular token vault.
function getTokenName(
address token0_,
address token1_
) external view returns (string memory);
/// @notice get a list of public vaults created by this factory
/// @param startIndex_ start index
/// @param endIndex_ end index
/// @return vaults list of all created vaults.
function publicVaults(
uint256 startIndex_,
uint256 endIndex_
) external view returns (address[] memory);
/// @notice numOfPublicVaults counts the total number of token vaults in existence
/// @return result total number of vaults deployed
function numOfPublicVaults()
external
view
returns (uint256 result);
/// @notice isPublicVault check if the inputed vault is a public vault.
/// @param vault_ address of the address to check.
/// @return isPublicVault true if the inputed vault is public or otherwise false.
function isPublicVault(address vault_)
external
view
returns (bool);
/// @notice get a list of private vaults created by this factory
/// @param startIndex_ start index
/// @param endIndex_ end index
/// @return vaults list of all created vaults.
function privateVaults(
uint256 startIndex_,
uint256 endIndex_
) external view returns (address[] memory);
/// @notice numOfPrivateVaults counts the total number of private vaults in existence
/// @return result total number of vaults deployed
function numOfPrivateVaults()
external
view
returns (uint256 result);
/// @notice isPrivateVault check if the inputed vault is a private vault.
/// @param vault_ address of the address to check.
/// @return isPublicVault true if the inputed vault is private or otherwise false.
function isPrivateVault(address vault_)
external
view
returns (bool);
/// @notice function used to get the manager of newly deployed vault.
/// @return manager address that will manager vault that will be
/// created.
function manager() external view returns (address);
/// @notice function used to get a list of address that can deploy public vault.
function deployers() external view returns (address[] memory);
/// @notice function used to get public module registry.
function moduleRegistryPublic() external view returns (address);
/// @notice function used to get private module registry.
function moduleRegistryPrivate()
external
view
returns (address);
// #endregion view/pure functions.
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IArrakisMetaVaultPublic {
// #region errors.
error MintZero();
error BurnZero();
// #endregion errors.
// #region events.
/// @notice event emitted when a user mint some shares on a public vault.
/// @param shares amount of shares minted.
/// @param receiver address that will receive the LP token (shares).
/// @param amount0 amount of token0 needed to mint shares.
/// @param amount1 amount of token1 needed to mint shares.
event LogMint(
uint256 shares,
address receiver,
uint256 amount0,
uint256 amount1
);
/// @notice event emitted when a user burn some of his shares.
/// @param shares amount of share burned by the user.
/// @param receiver address that will receive amounts of tokens
/// related to burning the shares.
/// @param amount0 amount of token0 that is collected from burning shares.
/// @param amount1 amount of token1 that is collected from burning shares.
event LogBurn(
uint256 shares,
address receiver,
uint256 amount0,
uint256 amount1
);
// #endregion events.
/// @notice function used to mint share of the vault position
/// @param shares_ amount representing the part of the position owned by receiver.
/// @param receiver_ address where share token will be sent.
/// @return amount0 amount of token0 deposited.
/// @return amount1 amount of token1 deposited.
function mint(
uint256 shares_,
address receiver_
) external payable returns (uint256 amount0, uint256 amount1);
/// @notice function used to burn share of the vault position.
/// @param shares_ amount of share that will be burn.
/// @param receiver_ address where underlying tokens will be sent.
/// @return amount0 amount of token0 withdrawn.
/// @return amount1 amount of token1 withdrawn.
function burn(
uint256 shares_,
address receiver_
) external returns (uint256 amount0, uint256 amount1);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {
AddLiquidityData,
AddLiquidityPermit2Data,
RemoveLiquidityData,
RemoveLiquidityPermit2Data,
SwapAndAddData,
SwapAndAddPermit2Data
} from "../structs/SRouter.sol";
interface IArrakisPublicVaultRouter {
// #region errors.
error AddressZero();
error NotEnoughNativeTokenSent();
error NoNativeTokenAndValueNotZero();
error OnlyPublicVault();
error EmptyMaxAmounts();
error NothingToMint();
error NothingToBurn();
error BelowMinAmounts();
error SwapCallFailed();
error ReceivedBelowMinimum();
error LengthMismatch();
error NoNativeToken();
error MsgValueZero();
error NativeTokenNotSupported();
error MsgValueDTMaxAmount();
error NoWethToken();
error Permit2WethNotAuthorized();
// #endregion errors.
// #region events.
/// @notice event emitted when a swap happen before depositing.
/// @param zeroForOne boolean indicating if we are swap token0 to token1 or the inverse.
/// @param amount0Diff amount of token0 get or consumed by the swap.
/// @param amount1Diff amount of token1 get or consumed by the swap.
/// @param amountOutSwap minimum amount of tokens out wanted after swap.
event Swapped(
bool zeroForOne,
uint256 amount0Diff,
uint256 amount1Diff,
uint256 amountOutSwap
);
// #endregion events.
// #region functions.
/// @notice function used to pause the router.
/// @dev only callable by owner
function pause() external;
/// @notice function used to unpause the router.
/// @dev only callable by owner
function unpause() external;
/// @notice addLiquidity adds liquidity to meta vault of interest (mints L tokens)
/// @param params_ AddLiquidityData struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function addLiquidity(AddLiquidityData memory params_)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
);
/// @notice swapAndAddLiquidity transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddData struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function swapAndAddLiquidity(SwapAndAddData memory params_)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
);
/// @notice removeLiquidity removes liquidity from vault and burns LP tokens
/// @param params_ RemoveLiquidityData struct containing data for withdrawals
/// @return amount0 actual amount of token0 transferred to receiver for burning `burnAmount`
/// @return amount1 actual amount of token1 transferred to receiver for burning `burnAmount`
function removeLiquidity(RemoveLiquidityData memory params_)
external
returns (uint256 amount0, uint256 amount1);
/// @notice addLiquidityPermit2 adds liquidity to public vault of interest (mints LP tokens)
/// @param params_ AddLiquidityPermit2Data struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function addLiquidityPermit2(
AddLiquidityPermit2Data memory params_
)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
);
/// @notice swapAndAddLiquidityPermit2 transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddPermit2Data struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function swapAndAddLiquidityPermit2(
SwapAndAddPermit2Data memory params_
)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
);
/// @notice removeLiquidityPermit2 removes liquidity from vault and burns LP tokens
/// @param params_ RemoveLiquidityPermit2Data struct containing data for withdrawals
/// @return amount0 actual amount of token0 transferred to receiver for burning `burnAmount`
/// @return amount1 actual amount of token1 transferred to receiver for burning `burnAmount`
function removeLiquidityPermit2(
RemoveLiquidityPermit2Data memory params_
) external returns (uint256 amount0, uint256 amount1);
/// @notice wrapAndAddLiquidity wrap eth and adds liquidity to meta vault of interest (mints L tokens)
/// @param params_ AddLiquidityData struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function wrapAndAddLiquidity(AddLiquidityData memory params_)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
);
/// @notice wrapAndSwapAndAddLiquidity wrap eth and transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddData struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function wrapAndSwapAndAddLiquidity(SwapAndAddData memory params_)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
);
/// @notice wrapAndAddLiquidityPermit2 wrap eth and adds liquidity to public vault of interest (mints LP tokens)
/// @param params_ AddLiquidityPermit2Data struct containing data for adding liquidity
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
function wrapAndAddLiquidityPermit2(
AddLiquidityPermit2Data memory params_
)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived
);
/// @notice wrapAndSwapAndAddLiquidityPermit2 wrap eth and transfer tokens to and calls RouterSwapExecutor
/// @param params_ SwapAndAddPermit2Data struct containing data for swap
/// @return amount0 amount of token0 transferred from msg.sender to mint `mintAmount`
/// @return amount1 amount of token1 transferred from msg.sender to mint `mintAmount`
/// @return sharesReceived amount of public vault tokens transferred to `receiver`
/// @return amount0Diff token0 balance difference post swap
/// @return amount1Diff token1 balance difference post swap
function wrapAndSwapAndAddLiquidityPermit2(
SwapAndAddPermit2Data memory params_
)
external
payable
returns (
uint256 amount0,
uint256 amount1,
uint256 sharesReceived,
uint256 amount0Diff,
uint256 amount1Diff
);
// #endregion functions.
// #region view functions.
/// @notice getMintAmounts used to get the shares we can mint from some max amounts.
/// @param vault_ meta vault address.
/// @param maxAmount0_ maximum amount of token0 user want to contribute.
/// @param maxAmount1_ maximum amount of token1 user want to contribute.
/// @return shareToMint maximum amount of share user can get for 'maxAmount0_' and 'maxAmount1_'.
/// @return amount0ToDeposit amount of token0 user should deposit into the vault for minting 'shareToMint'.
/// @return amount1ToDeposit amount of token1 user should deposit into the vault for minting 'shareToMint'.
function getMintAmounts(
address vault_,
uint256 maxAmount0_,
uint256 maxAmount1_
)
external
view
returns (
uint256 shareToMint,
uint256 amount0ToDeposit,
uint256 amount1ToDeposit
);
// #endregion view functions.
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IOracleWrapper {
// #region errors.
error AddressZero();
error DecimalsToken0Zero();
error DecimalsToken1Zero();
// #endregion errors.
/// @notice function used to get price0.
/// @return price0 price of token0/token1.
function getPrice0() external view returns (uint256 price0);
/// @notice function used to get price1.
/// @return price1 price of token1/token0.
function getPrice1() external view returns (uint256 price1);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {
PermitBatchTransferFrom,
SignatureTransferDetails,
PermitTransferFrom
} from "../structs/SPermit2.sol";
interface IPermit2 {
function permitTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {SwapAndAddData} from "../structs/SRouter.sol";
interface IRouterSwapExecutor {
// #region errors.
error OnlyRouter(address caller, address router);
error AddressZero();
error SwapCallFailed();
error ReceivedBelowMinimum();
// #endregion errors.
/// @notice function used to swap tokens.
/// @param _swapData struct containing all the informations for swapping.
/// @return amount0Diff the difference in token0 amount before and after the swap.
/// @return amount1Diff the difference in token1 amount before and after the swap.
function swap(SwapAndAddData memory _swapData)
external
payable
returns (uint256 amount0Diff, uint256 amount1Diff);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
interface IWETH9 {
function deposit() external payable;
function withdraw(uint256 wad) external;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
///
/// @dev Note:
/// This implementation does NOT auto-initialize the owner to `msg.sender`.
/// You MUST call the `_initializeOwner` in the constructor / initializer.
///
/// While the ownable portion follows
/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
/// the nomenclature for the 2-step ownership handover may be unique to this codebase.
abstract contract Ownable {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The caller is not authorized to call the function.
error Unauthorized();
/// @dev The `newOwner` cannot be the zero address.
error NewOwnerIsZeroAddress();
/// @dev The `pendingOwner` does not have a valid handover request.
error NoHandoverRequest();
/// @dev Cannot double-initialize.
error AlreadyInitialized();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EVENTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ownership is transferred from `oldOwner` to `newOwner`.
/// This event is intentionally kept the same as OpenZeppelin's Ownable to be
/// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
/// despite it not being as lightweight as a single argument event.
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
/// @dev An ownership handover to `pendingOwner` has been requested.
event OwnershipHandoverRequested(address indexed pendingOwner);
/// @dev The ownership handover to `pendingOwner` has been canceled.
event OwnershipHandoverCanceled(address indexed pendingOwner);
/// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;
/// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;
/// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STORAGE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The owner slot is given by:
/// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
/// It is intentionally chosen to be a high value
/// to avoid collision with lower slots.
/// The choice of manual storage layout is to enable compatibility
/// with both regular and upgradeable contracts.
bytes32 internal constant _OWNER_SLOT =
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;
/// The ownership handover slot of `newOwner` is given by:
/// ```
/// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
/// let handoverSlot := keccak256(0x00, 0x20)
/// ```
/// It stores the expiry timestamp of the two-step ownership handover.
uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* INTERNAL FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
function _guardInitializeOwner() internal pure virtual returns (bool guard) {}
/// @dev Initializes the owner directly without authorization guard.
/// This function must be called upon initialization,
/// regardless of whether the contract is upgradeable or not.
/// This is to enable generalization to both regular and upgradeable contracts,
/// and to save gas in case the initial owner is not the caller.
/// For performance reasons, this function will not check if there
/// is an existing owner.
function _initializeOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
if sload(ownerSlot) {
mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
revert(0x1c, 0x04)
}
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
} else {
/// @solidity memory-safe-assembly
assembly {
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Store the new value.
sstore(_OWNER_SLOT, newOwner)
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
}
}
}
/// @dev Sets the owner directly without authorization guard.
function _setOwner(address newOwner) internal virtual {
if (_guardInitializeOwner()) {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
}
} else {
/// @solidity memory-safe-assembly
assembly {
let ownerSlot := _OWNER_SLOT
// Clean the upper 96 bits.
newOwner := shr(96, shl(96, newOwner))
// Emit the {OwnershipTransferred} event.
log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
// Store the new value.
sstore(ownerSlot, newOwner)
}
}
}
/// @dev Throws if the sender is not the owner.
function _checkOwner() internal view virtual {
/// @solidity memory-safe-assembly
assembly {
// If the caller is not the stored owner, revert.
if iszero(eq(caller(), sload(_OWNER_SLOT))) {
mstore(0x00, 0x82b42900) // `Unauthorized()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Returns how long a two-step ownership handover is valid for in seconds.
/// Override to return a different value if needed.
/// Made internal to conserve bytecode. Wrap it in a public function if needed.
function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
return 48 * 3600;
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC UPDATE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Allows the owner to transfer the ownership to `newOwner`.
function transferOwnership(address newOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
if iszero(shl(96, newOwner)) {
mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
revert(0x1c, 0x04)
}
}
_setOwner(newOwner);
}
/// @dev Allows the owner to renounce their ownership.
function renounceOwnership() public payable virtual onlyOwner {
_setOwner(address(0));
}
/// @dev Request a two-step ownership handover to the caller.
/// The request will automatically expire in 48 hours (172800 seconds) by default.
function requestOwnershipHandover() public payable virtual {
unchecked {
uint256 expires = block.timestamp + _ownershipHandoverValidFor();
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to `expires`.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), expires)
// Emit the {OwnershipHandoverRequested} event.
log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
}
}
}
/// @dev Cancels the two-step ownership handover to the caller, if any.
function cancelOwnershipHandover() public payable virtual {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, caller())
sstore(keccak256(0x0c, 0x20), 0)
// Emit the {OwnershipHandoverCanceled} event.
log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
}
}
/// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
/// Reverts if there is no existing ownership handover requested by `pendingOwner`.
function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
/// @solidity memory-safe-assembly
assembly {
// Compute and set the handover slot to 0.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
let handoverSlot := keccak256(0x0c, 0x20)
// If the handover does not exist, or has expired.
if gt(timestamp(), sload(handoverSlot)) {
mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
revert(0x1c, 0x04)
}
// Set the handover slot to 0.
sstore(handoverSlot, 0)
}
_setOwner(pendingOwner);
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* PUBLIC READ FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Returns the owner of the contract.
function owner() public view virtual returns (address result) {
/// @solidity memory-safe-assembly
assembly {
result := sload(_OWNER_SLOT)
}
}
/// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
function ownershipHandoverExpiresAt(address pendingOwner)
public
view
virtual
returns (uint256 result)
{
/// @solidity memory-safe-assembly
assembly {
// Compute the handover slot.
mstore(0x0c, _HANDOVER_SLOT_SEED)
mstore(0x00, pendingOwner)
// Load the handover slot.
result := sload(keccak256(0x0c, 0x20))
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* MODIFIERS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Marks a function as only callable by the owner.
modifier onlyOwner() virtual {
_checkOwner();
_;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
struct TokenPermissions {
address token;
uint256 amount;
}
struct PermitTransferFrom {
TokenPermissions permitted;
uint256 nonce;
uint256 deadline;
}
struct SignatureTransferDetails {
address to;
uint256 requestedAmount;
}
struct PermitBatchTransferFrom {
TokenPermissions[] permitted;
uint256 nonce;
uint256 deadline;
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {
PermitBatchTransferFrom,
PermitTransferFrom
} from "./SPermit2.sol";
struct AddLiquidityData {
uint256 amount0Max;
uint256 amount1Max;
uint256 amount0Min;
uint256 amount1Min;
uint256 amountSharesMin;
address vault;
address receiver;
}
struct RemoveLiquidityData {
uint256 burnAmount;
uint256 amount0Min;
uint256 amount1Min;
address vault;
address payable receiver; // not need to have receiveETH if reciever is payable.
}
struct SwapData {
bytes swapPayload;
uint256 amountInSwap;
uint256 amountOutSwap;
address swapRouter;
bool zeroForOne;
}
struct SwapAndAddData {
SwapData swapData;
AddLiquidityData addData;
}
struct AddLiquidityPermit2Data {
AddLiquidityData addData;
PermitBatchTransferFrom permit;
bytes signature;
}
struct RemoveLiquidityPermit2Data {
RemoveLiquidityData removeData;
PermitTransferFrom permit;
bytes signature;
}
struct SwapAndAddPermit2Data {
SwapAndAddData swapAndAddData;
PermitBatchTransferFrom permit;
bytes signature;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @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.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
{
"compilationTarget": {
"src/ArrakisPublicVaultRouter.sol": "ArrakisPublicVaultRouter"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 10000
},
"remappings": [
":@create3/contracts/=lib/create3/contracts/",
":@ensdomains/=lib/v4-periphery/lib/v4-core/node_modules/@ensdomains/",
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@solady/contracts/=lib/solady/src/",
":@uniswap/v3-core/=lib/valantis-hot/lib/v3-core/",
":@uniswap/v3-periphery/=lib/valantis-hot/lib/v3-periphery/",
":@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
":@v3-lib-0.8/contracts/=lib/v3-lib-0.8/contracts/",
":@valantis-core/contracts/=lib/valantis-hot/lib/valantis-core/src/",
":@valantis-hot/contracts-test/=lib/valantis-hot/test/",
":@valantis-hot/contracts/=lib/valantis-hot/src/",
":automate/=lib/automate/contracts/",
":create3/=lib/create3/contracts/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-gas-snapshot/=lib/v4-periphery/lib/forge-gas-snapshot/src/",
":forge-std/=lib/forge-std/src/",
":hardhat/=lib/v4-periphery/lib/v4-core/node_modules/hardhat/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
":solady/=lib/solady/",
":solmate/=lib/v4-periphery/lib/solmate/src/",
":v3-core/=lib/valantis-hot/lib/v3-core/contracts/",
":v3-lib-0.8/=lib/v3-lib-0.8/contracts/",
":v3-periphery/=lib/valantis-hot/lib/v3-periphery/contracts/",
":v4-core/=lib/v4-periphery/lib/v4-core/src/",
":v4-periphery/=lib/v4-periphery/contracts/",
":valantis-core/=lib/valantis-hot/lib/valantis-core/",
":valantis-hot/=lib/valantis-hot/"
]
}
[{"inputs":[{"internalType":"address","name":"nativeToken_","type":"address"},{"internalType":"address","name":"permit2_","type":"address"},{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"factory_","type":"address"},{"internalType":"address","name":"weth_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AddressZero","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"BelowMinAmounts","type":"error"},{"inputs":[],"name":"EmptyMaxAmounts","type":"error"},{"inputs":[],"name":"LengthMismatch","type":"error"},{"inputs":[],"name":"MsgValueDTMaxAmount","type":"error"},{"inputs":[],"name":"MsgValueZero","type":"error"},{"inputs":[],"name":"NativeTokenNotSupported","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"NoNativeToken","type":"error"},{"inputs":[],"name":"NoNativeTokenAndValueNotZero","type":"error"},{"inputs":[],"name":"NoWethToken","type":"error"},{"inputs":[],"name":"NotEnoughNativeTokenSent","type":"error"},{"inputs":[],"name":"NothingToBurn","type":"error"},{"inputs":[],"name":"NothingToMint","type":"error"},{"inputs":[],"name":"OnlyPublicVault","type":"error"},{"inputs":[],"name":"Permit2WethNotAuthorized","type":"error"},{"inputs":[],"name":"ReceivedBelowMinimum","type":"error"},{"inputs":[],"name":"SwapCallFailed","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"zeroForOne","type":"bool"},{"indexed":false,"internalType":"uint256","name":"amount0Diff","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Diff","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOutSwap","type":"uint256"}],"name":"Swapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"params_","type":"tuple"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"addData","type":"tuple"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct TokenPermissions[]","name":"permitted","type":"tuple[]"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct PermitBatchTransferFrom","name":"permit","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct AddLiquidityPermit2Data","name":"params_","type":"tuple"}],"name":"addLiquidityPermit2","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IArrakisMetaVaultFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vault_","type":"address"},{"internalType":"uint256","name":"maxAmount0_","type":"uint256"},{"internalType":"uint256","name":"maxAmount1_","type":"uint256"}],"name":"getMintAmounts","outputs":[{"internalType":"uint256","name":"shareToMint","type":"uint256"},{"internalType":"uint256","name":"amount0ToDeposit","type":"uint256"},{"internalType":"uint256","name":"amount1ToDeposit","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nativeToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"contract IPermit2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"burnAmount","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address payable","name":"receiver","type":"address"}],"internalType":"struct RemoveLiquidityData","name":"params_","type":"tuple"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"burnAmount","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address payable","name":"receiver","type":"address"}],"internalType":"struct RemoveLiquidityData","name":"removeData","type":"tuple"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct TokenPermissions","name":"permitted","type":"tuple"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct PermitTransferFrom","name":"permit","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct RemoveLiquidityPermit2Data","name":"params_","type":"tuple"}],"name":"removeLiquidityPermit2","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"bytes","name":"swapPayload","type":"bytes"},{"internalType":"uint256","name":"amountInSwap","type":"uint256"},{"internalType":"uint256","name":"amountOutSwap","type":"uint256"},{"internalType":"address","name":"swapRouter","type":"address"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"internalType":"struct SwapData","name":"swapData","type":"tuple"},{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"addData","type":"tuple"}],"internalType":"struct SwapAndAddData","name":"params_","type":"tuple"}],"name":"swapAndAddLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"},{"internalType":"uint256","name":"amount0Diff","type":"uint256"},{"internalType":"uint256","name":"amount1Diff","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"bytes","name":"swapPayload","type":"bytes"},{"internalType":"uint256","name":"amountInSwap","type":"uint256"},{"internalType":"uint256","name":"amountOutSwap","type":"uint256"},{"internalType":"address","name":"swapRouter","type":"address"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"internalType":"struct SwapData","name":"swapData","type":"tuple"},{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"addData","type":"tuple"}],"internalType":"struct SwapAndAddData","name":"swapAndAddData","type":"tuple"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct TokenPermissions[]","name":"permitted","type":"tuple[]"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct PermitBatchTransferFrom","name":"permit","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct SwapAndAddPermit2Data","name":"params_","type":"tuple"}],"name":"swapAndAddLiquidityPermit2","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"},{"internalType":"uint256","name":"amount0Diff","type":"uint256"},{"internalType":"uint256","name":"amount1Diff","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"swapper","outputs":[{"internalType":"contract IRouterSwapExecutor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"swapper_","type":"address"}],"name":"updateSwapExecutor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"params_","type":"tuple"}],"name":"wrapAndAddLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"addData","type":"tuple"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct TokenPermissions[]","name":"permitted","type":"tuple[]"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct PermitBatchTransferFrom","name":"permit","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct AddLiquidityPermit2Data","name":"params_","type":"tuple"}],"name":"wrapAndAddLiquidityPermit2","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"bytes","name":"swapPayload","type":"bytes"},{"internalType":"uint256","name":"amountInSwap","type":"uint256"},{"internalType":"uint256","name":"amountOutSwap","type":"uint256"},{"internalType":"address","name":"swapRouter","type":"address"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"internalType":"struct SwapData","name":"swapData","type":"tuple"},{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"addData","type":"tuple"}],"internalType":"struct SwapAndAddData","name":"params_","type":"tuple"}],"name":"wrapAndSwapAndAddLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"},{"internalType":"uint256","name":"amount0Diff","type":"uint256"},{"internalType":"uint256","name":"amount1Diff","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"components":[{"internalType":"bytes","name":"swapPayload","type":"bytes"},{"internalType":"uint256","name":"amountInSwap","type":"uint256"},{"internalType":"uint256","name":"amountOutSwap","type":"uint256"},{"internalType":"address","name":"swapRouter","type":"address"},{"internalType":"bool","name":"zeroForOne","type":"bool"}],"internalType":"struct SwapData","name":"swapData","type":"tuple"},{"components":[{"internalType":"uint256","name":"amount0Max","type":"uint256"},{"internalType":"uint256","name":"amount1Max","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"},{"internalType":"uint256","name":"amountSharesMin","type":"uint256"},{"internalType":"address","name":"vault","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"internalType":"struct AddLiquidityData","name":"addData","type":"tuple"}],"internalType":"struct SwapAndAddData","name":"swapAndAddData","type":"tuple"},{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct TokenPermissions[]","name":"permitted","type":"tuple[]"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct PermitBatchTransferFrom","name":"permit","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct SwapAndAddPermit2Data","name":"params_","type":"tuple"}],"name":"wrapAndSwapAndAddLiquidityPermit2","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"sharesReceived","type":"uint256"},{"internalType":"uint256","name":"amount0Diff","type":"uint256"},{"internalType":"uint256","name":"amount1Diff","type":"uint256"}],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]