UniswapAdapter
Extends: BaseAdapter
The UniswapAdapter
is designed to interact with the Uniswap V3 Protocol.
This adapter enables users to harness the power of Uniswap v3 trading capabilities and integrate them into their financial strategies.
Structs
DepositExtraData
Used to provide the necessary data when performing a Deposit operation.
Members
Name | Type | Description |
---|---|---|
tokenId | uint256 | The ID of the target NFT LP token |
fee | uint24 | The fee tier for the provided liquidity |
tickLower | int24 | The value of the lower tick threshold |
tickUpper | int24 | The value of the upper tick threshold |
WithdrawExtraData
Used to provide the necessary data when performing a Withdraw operation.
Members
Name | Type | Description |
---|---|---|
tokenId | uint256 | The ID of the target NFT LP token |
percentageToWithdraw | uint128 | The percentage to withdraw (should be parsed with 4 decimal units) |
SwapExtraData
Used to provide the necessary data when performing a Swap operation.
Members
Name | Type | Description |
---|---|---|
fee | uint24 | The fee tier for the swap operation (determines the associated fees) |
sqrtPriceLimitX96 | uint160 | The square root of the price limit for the swap operation (helps control the price range for the swap) |
InitializeData
Defines the necessary data for initializing the Adapter.
Members
Name | Type | Description |
---|---|---|
nonfungiblePositionManager | INonfungiblePositionManager | The interface representing the Uniswap NonfungiblePositionManager contract instance |
swapRouter | ISwapRouter | The interface representing the Uniswap SwapRouter contract instance |
nativeToken | address | The address of the wrapped native token address |
Layout
Used to store crucial data for the Adapter's functionality in a specific storage slot.
Members
Name | Type | Description |
---|---|---|
nonfungiblePositionManager | INonfungiblePositionManager | The interface representing the Uniswap NonfungiblePositionManager contract instance |
swapRouter | ISwapRouter | The interface representing the Uniswap SwapRouter contract instance |
nativeToken | address | The address of the wrapped native token address |
State Variables
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
PERCENTAGE
Constant value representing 100% for percentages.
Arguments that refer to percentages are formatted with respect to PERCENTAGE
value.
Constructor
Sets the value of the STORAGE_SLOT state variable.
The value is computed as the keccak256 hash of the abi encoding of:
- The
Nexera-FI.UniswapAdapter
string literal - The address of this contract (UniswapAdapter)
Functions
initialize
Initializes the Adapter.
Parameters
Name | Type | Description |
---|---|---|
initData_ | bytes | The ABI encoded InitializeData |
_deposit
Internal function for handling Deposit Operations.
This function is responsible for either minting a new NFT LP token or adding liquidity to an existing NFT LP token via interacting with Uniswap's:
- TransferHelper library
- NonfungiblePositionManager contract
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | ABI encoded data of type DepositExtraData |
_withdraw
Internal function for handling Withdraw Operations.
This function is responsible for facilitating withdrawals of liquidity from a NFT LP position. It processes the specified output tokens and verifies the expected input tokens, ensuring accurate and secure withdrawal operations.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | ABI encoded data of type WithdrawExtraData |
_decreaseLiquidity
Internal helper function for decreasing liquidity for a specific NFT LP position (Withdraw Operation).
This function internally interacts with Uniswap's:
- NonfungiblePositionManager contract
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
withdrawExtraData | WithdrawExtraData | Struct of type WithdrawExtraData with the necessary data (NFT LP tokenId & percentage to withdraw) |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
liquidity | uint128 | The liquidity of the position associated with the specified NFT LP token |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of 1st token (token0) received after the decrease in liquidity |
<none> | uint256 | The amount of 2nd token (token1) received after the decrease in liquidity |
_swap
Internal function for handling Swap Operations.
This function is responsible for executing token swaps with specified trade settings via interacting with Uniswap's:
- SwapRouter contract
- TransferHelper library
- NonfungiblePositionManager contract
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
extraData | bytes | ABI encoded data of type SwapExtraData |
_collect
Internal function for handling Collect Operations.
This function is responsible for collecting fees owed to a specific position associated with an NFT LP token via interacting with Uniswap's:
- NonfungiblePositionManager contract
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Not used in this context. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. Members refer to the repsecitve maximum amount of the tokens (token0 & token1) that is expected to be collected from the position. |
extraData | bytes | ABI encoded data of type uint256 , representing the unique identifier (tokenId) of the NFT LP position from which to collect fees from |
_operate
This function always raises the OPERATION_NOT_SUPPORTED error, as Operate is not an action supported within the Uniswap v3 protocol.
Called by executeAction function.
_checkAddresses
Internal helper function used for address validation within Withdraw and Collect Operations.
This function interacts with Uniswap's:
- NonfungiblePositionManager contract
Called by _withdraw and _collect functions.
Parameters
Name | Type | Description |
---|---|---|
tokenId | uint256 | The unique identifier of the NFT LP token position |
expectedIn | Adapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
_requireValidInAndOutForSwap
Checks the validity of input (expectedIn
) and output (out
) parameters for a Swap operation.
It ensures that there is only one token to send and one token to receive, and that the token addresses are not invalid.
Called by _swap function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
_requireValidInAndOutForDepositAndWithdraw
Checks the validity of input (expectedIn
) and output (out
) parameters for both Deposit and Withdraw operations.
It ensures that there are two token compositions to send and receive, and it verifies that the token addresses are valid and consistent between the input and output.
Called by _deposit and _withdraw functions.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
layout
Retrieves a reference to the Layout struct stored at a specified storage slot.