@huuduynvc/v3-periphery 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +339 -0
- package/README.md +52 -0
- package/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json +1230 -0
- package/artifacts/contracts/NonfungibleTokenPositionDescriptor.sol/NonfungibleTokenPositionDescriptor.json +161 -0
- package/artifacts/contracts/SwapRouter.sol/SwapRouter.json +574 -0
- package/artifacts/contracts/V3Migrator.sol/V3Migrator.json +360 -0
- package/artifacts/contracts/examples/PairFlash.sol/PairFlash.json +196 -0
- package/artifacts/contracts/interfaces/IERC20Metadata.sol/IERC20Metadata.json +233 -0
- package/artifacts/contracts/interfaces/IERC721Permit.sol/IERC721Permit.json +360 -0
- package/artifacts/contracts/interfaces/IMulticall.sol/IMulticall.json +30 -0
- package/artifacts/contracts/interfaces/INonfungiblePositionManager.sol/INonfungiblePositionManager.json +998 -0
- package/artifacts/contracts/interfaces/INonfungibleTokenPositionDescriptor.sol/INonfungibleTokenPositionDescriptor.json +35 -0
- package/artifacts/contracts/interfaces/IPeripheryImmutableState.sol/IPeripheryImmutableState.json +37 -0
- package/artifacts/contracts/interfaces/IPeripheryPayments.sol/IPeripheryPayments.json +59 -0
- package/artifacts/contracts/interfaces/IPeripheryPaymentsWithFee.sol/IPeripheryPaymentsWithFee.json +120 -0
- package/artifacts/contracts/interfaces/IPoolInitializer.sol/IPoolInitializer.json +45 -0
- package/artifacts/contracts/interfaces/IQuoter.sol/IQuoter.json +137 -0
- package/artifacts/contracts/interfaces/IQuoterV2.sol/IQuoterV2.json +211 -0
- package/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json +163 -0
- package/artifacts/contracts/interfaces/ISwapRouter.sol/ISwapRouter.json +248 -0
- package/artifacts/contracts/interfaces/ITickLens.sol/ITickLens.json +52 -0
- package/artifacts/contracts/interfaces/IV3Migrator.sol/IV3Migrator.json +296 -0
- package/artifacts/contracts/interfaces/external/IERC1271.sol/IERC1271.json +35 -0
- package/artifacts/contracts/interfaces/external/IERC20PermitAllowed.sol/IERC20PermitAllowed.json +59 -0
- package/artifacts/contracts/interfaces/external/IWETH9.sol/IWETH9.json +214 -0
- package/artifacts/contracts/lens/Quoter.sol/Quoter.json +202 -0
- package/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json +276 -0
- package/artifacts/contracts/lens/TickLens.sol/TickLens.json +52 -0
- package/artifacts/contracts/lens/UniswapInterfaceMulticall.sol/UniswapInterfaceMulticall.json +101 -0
- package/artifacts/contracts/libraries/BytesLib.sol/BytesLib.json +10 -0
- package/artifacts/contracts/libraries/CallbackValidation.sol/CallbackValidation.json +10 -0
- package/artifacts/contracts/libraries/ChainId.sol/ChainId.json +10 -0
- package/artifacts/contracts/libraries/HexStrings.sol/HexStrings.json +10 -0
- package/artifacts/contracts/libraries/LiquidityAmounts.sol/LiquidityAmounts.json +10 -0
- package/artifacts/contracts/libraries/NFTDescriptor.sol/NFTDescriptor.json +102 -0
- package/artifacts/contracts/libraries/NFTSVG.sol/NFTSVG.json +10 -0
- package/artifacts/contracts/libraries/OracleLibrary.sol/OracleLibrary.json +10 -0
- package/artifacts/contracts/libraries/Path.sol/Path.json +10 -0
- package/artifacts/contracts/libraries/PoolAddress.sol/PoolAddress.json +10 -0
- package/artifacts/contracts/libraries/PoolTicksCounter.sol/PoolTicksCounter.json +10 -0
- package/artifacts/contracts/libraries/PositionKey.sol/PositionKey.json +10 -0
- package/artifacts/contracts/libraries/PositionValue.sol/PositionValue.json +10 -0
- package/artifacts/contracts/libraries/TokenRatioSortOrder.sol/TokenRatioSortOrder.json +10 -0
- package/artifacts/contracts/libraries/TransferHelper.sol/TransferHelper.json +10 -0
- package/contracts/base/BlockTimestamp.sol +12 -0
- package/contracts/base/ERC721Permit.sol +86 -0
- package/contracts/base/LiquidityManagement.sol +90 -0
- package/contracts/base/Multicall.sol +28 -0
- package/contracts/base/PeripheryImmutableState.sol +18 -0
- package/contracts/base/PeripheryPayments.sol +70 -0
- package/contracts/base/PeripheryPaymentsWithFee.sol +55 -0
- package/contracts/base/PeripheryValidation.sol +11 -0
- package/contracts/base/PoolInitializer.sol +32 -0
- package/contracts/base/SelfPermit.sol +63 -0
- package/contracts/interfaces/IERC20Metadata.sol +18 -0
- package/contracts/interfaces/IERC721Permit.sol +32 -0
- package/contracts/interfaces/IMulticall.sol +13 -0
- package/contracts/interfaces/INonfungiblePositionManager.sol +180 -0
- package/contracts/interfaces/INonfungibleTokenPositionDescriptor.sol +17 -0
- package/contracts/interfaces/IPeripheryImmutableState.sol +12 -0
- package/contracts/interfaces/IPeripheryPayments.sol +28 -0
- package/contracts/interfaces/IPeripheryPaymentsWithFee.sol +29 -0
- package/contracts/interfaces/IPoolInitializer.sol +22 -0
- package/contracts/interfaces/IQuoter.sol +51 -0
- package/contracts/interfaces/IQuoterV2.sol +98 -0
- package/contracts/interfaces/ISelfPermit.sol +76 -0
- package/contracts/interfaces/ISwapRouter.sol +67 -0
- package/contracts/interfaces/ITickLens.sol +25 -0
- package/contracts/interfaces/IV3Migrator.sol +34 -0
- package/contracts/interfaces/external/IERC1271.sol +16 -0
- package/contracts/interfaces/external/IERC20PermitAllowed.sol +27 -0
- package/contracts/interfaces/external/IWETH9.sol +13 -0
- package/contracts/libraries/BytesLib.sol +101 -0
- package/contracts/libraries/CallbackValidation.sol +36 -0
- package/contracts/libraries/ChainId.sol +13 -0
- package/contracts/libraries/HexStrings.sol +29 -0
- package/contracts/libraries/LiquidityAmounts.sol +137 -0
- package/contracts/libraries/NFTDescriptor.sol +477 -0
- package/contracts/libraries/NFTSVG.sol +406 -0
- package/contracts/libraries/OracleLibrary.sol +161 -0
- package/contracts/libraries/Path.sol +69 -0
- package/contracts/libraries/PoolAddress.sol +48 -0
- package/contracts/libraries/PoolTicksCounter.sol +97 -0
- package/contracts/libraries/PositionKey.sol +13 -0
- package/contracts/libraries/PositionValue.sol +167 -0
- package/contracts/libraries/TokenRatioSortOrder.sol +12 -0
- package/contracts/libraries/TransferHelper.sol +60 -0
- package/package.json +68 -0
@@ -0,0 +1,180 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
pragma abicoder v2;
|
4
|
+
|
5
|
+
import '@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol';
|
6
|
+
import '@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol';
|
7
|
+
|
8
|
+
import './IPoolInitializer.sol';
|
9
|
+
import './IERC721Permit.sol';
|
10
|
+
import './IPeripheryPayments.sol';
|
11
|
+
import './IPeripheryImmutableState.sol';
|
12
|
+
import '../libraries/PoolAddress.sol';
|
13
|
+
|
14
|
+
/// @title Non-fungible token for positions
|
15
|
+
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
|
16
|
+
/// and authorized.
|
17
|
+
interface INonfungiblePositionManager is
|
18
|
+
IPoolInitializer,
|
19
|
+
IPeripheryPayments,
|
20
|
+
IPeripheryImmutableState,
|
21
|
+
IERC721Metadata,
|
22
|
+
IERC721Enumerable,
|
23
|
+
IERC721Permit
|
24
|
+
{
|
25
|
+
/// @notice Emitted when liquidity is increased for a position NFT
|
26
|
+
/// @dev Also emitted when a token is minted
|
27
|
+
/// @param tokenId The ID of the token for which liquidity was increased
|
28
|
+
/// @param liquidity The amount by which liquidity for the NFT position was increased
|
29
|
+
/// @param amount0 The amount of token0 that was paid for the increase in liquidity
|
30
|
+
/// @param amount1 The amount of token1 that was paid for the increase in liquidity
|
31
|
+
event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
|
32
|
+
/// @notice Emitted when liquidity is decreased for a position NFT
|
33
|
+
/// @param tokenId The ID of the token for which liquidity was decreased
|
34
|
+
/// @param liquidity The amount by which liquidity for the NFT position was decreased
|
35
|
+
/// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
|
36
|
+
/// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
|
37
|
+
event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
|
38
|
+
/// @notice Emitted when tokens are collected for a position NFT
|
39
|
+
/// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
|
40
|
+
/// @param tokenId The ID of the token for which underlying tokens were collected
|
41
|
+
/// @param recipient The address of the account that received the collected tokens
|
42
|
+
/// @param amount0 The amount of token0 owed to the position that was collected
|
43
|
+
/// @param amount1 The amount of token1 owed to the position that was collected
|
44
|
+
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);
|
45
|
+
|
46
|
+
/// @notice Returns the position information associated with a given token ID.
|
47
|
+
/// @dev Throws if the token ID is not valid.
|
48
|
+
/// @param tokenId The ID of the token that represents the position
|
49
|
+
/// @return nonce The nonce for permits
|
50
|
+
/// @return operator The address that is approved for spending
|
51
|
+
/// @return token0 The address of the token0 for a specific pool
|
52
|
+
/// @return token1 The address of the token1 for a specific pool
|
53
|
+
/// @return fee The fee associated with the pool
|
54
|
+
/// @return tickLower The lower end of the tick range for the position
|
55
|
+
/// @return tickUpper The higher end of the tick range for the position
|
56
|
+
/// @return liquidity The liquidity of the position
|
57
|
+
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
|
58
|
+
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
|
59
|
+
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
|
60
|
+
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
|
61
|
+
function positions(uint256 tokenId)
|
62
|
+
external
|
63
|
+
view
|
64
|
+
returns (
|
65
|
+
uint96 nonce,
|
66
|
+
address operator,
|
67
|
+
address token0,
|
68
|
+
address token1,
|
69
|
+
uint24 fee,
|
70
|
+
int24 tickLower,
|
71
|
+
int24 tickUpper,
|
72
|
+
uint128 liquidity,
|
73
|
+
uint256 feeGrowthInside0LastX128,
|
74
|
+
uint256 feeGrowthInside1LastX128,
|
75
|
+
uint128 tokensOwed0,
|
76
|
+
uint128 tokensOwed1
|
77
|
+
);
|
78
|
+
|
79
|
+
struct MintParams {
|
80
|
+
address token0;
|
81
|
+
address token1;
|
82
|
+
uint24 fee;
|
83
|
+
int24 tickLower;
|
84
|
+
int24 tickUpper;
|
85
|
+
uint256 amount0Desired;
|
86
|
+
uint256 amount1Desired;
|
87
|
+
uint256 amount0Min;
|
88
|
+
uint256 amount1Min;
|
89
|
+
address recipient;
|
90
|
+
uint256 deadline;
|
91
|
+
}
|
92
|
+
|
93
|
+
/// @notice Creates a new position wrapped in a NFT
|
94
|
+
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
|
95
|
+
/// a method does not exist, i.e. the pool is assumed to be initialized.
|
96
|
+
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
|
97
|
+
/// @return tokenId The ID of the token that represents the minted position
|
98
|
+
/// @return liquidity The amount of liquidity for this position
|
99
|
+
/// @return amount0 The amount of token0
|
100
|
+
/// @return amount1 The amount of token1
|
101
|
+
function mint(MintParams calldata params)
|
102
|
+
external
|
103
|
+
payable
|
104
|
+
returns (
|
105
|
+
uint256 tokenId,
|
106
|
+
uint128 liquidity,
|
107
|
+
uint256 amount0,
|
108
|
+
uint256 amount1
|
109
|
+
);
|
110
|
+
|
111
|
+
struct IncreaseLiquidityParams {
|
112
|
+
uint256 tokenId;
|
113
|
+
uint256 amount0Desired;
|
114
|
+
uint256 amount1Desired;
|
115
|
+
uint256 amount0Min;
|
116
|
+
uint256 amount1Min;
|
117
|
+
uint256 deadline;
|
118
|
+
}
|
119
|
+
|
120
|
+
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
|
121
|
+
/// @param params tokenId The ID of the token for which liquidity is being increased,
|
122
|
+
/// amount0Desired The desired amount of token0 to be spent,
|
123
|
+
/// amount1Desired The desired amount of token1 to be spent,
|
124
|
+
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
|
125
|
+
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
|
126
|
+
/// deadline The time by which the transaction must be included to effect the change
|
127
|
+
/// @return liquidity The new liquidity amount as a result of the increase
|
128
|
+
/// @return amount0 The amount of token0 to acheive resulting liquidity
|
129
|
+
/// @return amount1 The amount of token1 to acheive resulting liquidity
|
130
|
+
function increaseLiquidity(IncreaseLiquidityParams calldata params)
|
131
|
+
external
|
132
|
+
payable
|
133
|
+
returns (
|
134
|
+
uint128 liquidity,
|
135
|
+
uint256 amount0,
|
136
|
+
uint256 amount1
|
137
|
+
);
|
138
|
+
|
139
|
+
struct DecreaseLiquidityParams {
|
140
|
+
uint256 tokenId;
|
141
|
+
uint128 liquidity;
|
142
|
+
uint256 amount0Min;
|
143
|
+
uint256 amount1Min;
|
144
|
+
uint256 deadline;
|
145
|
+
}
|
146
|
+
|
147
|
+
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
|
148
|
+
/// @param params tokenId The ID of the token for which liquidity is being decreased,
|
149
|
+
/// amount The amount by which liquidity will be decreased,
|
150
|
+
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
|
151
|
+
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
|
152
|
+
/// deadline The time by which the transaction must be included to effect the change
|
153
|
+
/// @return amount0 The amount of token0 accounted to the position's tokens owed
|
154
|
+
/// @return amount1 The amount of token1 accounted to the position's tokens owed
|
155
|
+
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
|
156
|
+
external
|
157
|
+
payable
|
158
|
+
returns (uint256 amount0, uint256 amount1);
|
159
|
+
|
160
|
+
struct CollectParams {
|
161
|
+
uint256 tokenId;
|
162
|
+
address recipient;
|
163
|
+
uint128 amount0Max;
|
164
|
+
uint128 amount1Max;
|
165
|
+
}
|
166
|
+
|
167
|
+
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
|
168
|
+
/// @param params tokenId The ID of the NFT for which tokens are being collected,
|
169
|
+
/// recipient The account that should receive the tokens,
|
170
|
+
/// amount0Max The maximum amount of token0 to collect,
|
171
|
+
/// amount1Max The maximum amount of token1 to collect
|
172
|
+
/// @return amount0 The amount of fees collected in token0
|
173
|
+
/// @return amount1 The amount of fees collected in token1
|
174
|
+
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
|
175
|
+
|
176
|
+
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
|
177
|
+
/// must be collected first.
|
178
|
+
/// @param tokenId The ID of the token that is being burned
|
179
|
+
function burn(uint256 tokenId) external payable;
|
180
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.5.0;
|
3
|
+
|
4
|
+
import './INonfungiblePositionManager.sol';
|
5
|
+
|
6
|
+
/// @title Describes position NFT tokens via URI
|
7
|
+
interface INonfungibleTokenPositionDescriptor {
|
8
|
+
/// @notice Produces the URI describing a particular token ID for a position manager
|
9
|
+
/// @dev Note this URI may be a data: URI with the JSON contents directly inlined
|
10
|
+
/// @param positionManager The position manager for which to describe the token
|
11
|
+
/// @param tokenId The ID of the token for which to produce a description, which may not be valid
|
12
|
+
/// @return The URI of the ERC721-compliant metadata
|
13
|
+
function tokenURI(INonfungiblePositionManager positionManager, uint256 tokenId)
|
14
|
+
external
|
15
|
+
view
|
16
|
+
returns (string memory);
|
17
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.5.0;
|
3
|
+
|
4
|
+
/// @title Immutable state
|
5
|
+
/// @notice Functions that return immutable state of the router
|
6
|
+
interface IPeripheryImmutableState {
|
7
|
+
/// @return Returns the address of the Uniswap V3 factory
|
8
|
+
function factory() external view returns (address);
|
9
|
+
|
10
|
+
/// @return Returns the address of WETH9
|
11
|
+
function WETH9() external view returns (address);
|
12
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
|
4
|
+
/// @title Periphery Payments
|
5
|
+
/// @notice Functions to ease deposits and withdrawals of ETH
|
6
|
+
interface IPeripheryPayments {
|
7
|
+
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
|
8
|
+
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
|
9
|
+
/// @param amountMinimum The minimum amount of WETH9 to unwrap
|
10
|
+
/// @param recipient The address receiving ETH
|
11
|
+
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
|
12
|
+
|
13
|
+
/// @notice Refunds any ETH balance held by this contract to the `msg.sender`
|
14
|
+
/// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
|
15
|
+
/// that use ether for the input amount
|
16
|
+
function refundETH() external payable;
|
17
|
+
|
18
|
+
/// @notice Transfers the full amount of a token held by this contract to recipient
|
19
|
+
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
|
20
|
+
/// @param token The contract address of the token which will be transferred to `recipient`
|
21
|
+
/// @param amountMinimum The minimum amount of token required for a transfer
|
22
|
+
/// @param recipient The destination address of the token
|
23
|
+
function sweepToken(
|
24
|
+
address token,
|
25
|
+
uint256 amountMinimum,
|
26
|
+
address recipient
|
27
|
+
) external payable;
|
28
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
|
4
|
+
import './IPeripheryPayments.sol';
|
5
|
+
|
6
|
+
/// @title Periphery Payments
|
7
|
+
/// @notice Functions to ease deposits and withdrawals of ETH
|
8
|
+
interface IPeripheryPaymentsWithFee is IPeripheryPayments {
|
9
|
+
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH, with a percentage between
|
10
|
+
/// 0 (exclusive), and 1 (inclusive) going to feeRecipient
|
11
|
+
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
|
12
|
+
function unwrapWETH9WithFee(
|
13
|
+
uint256 amountMinimum,
|
14
|
+
address recipient,
|
15
|
+
uint256 feeBips,
|
16
|
+
address feeRecipient
|
17
|
+
) external payable;
|
18
|
+
|
19
|
+
/// @notice Transfers the full amount of a token held by this contract to recipient, with a percentage between
|
20
|
+
/// 0 (exclusive) and 1 (inclusive) going to feeRecipient
|
21
|
+
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
|
22
|
+
function sweepTokenWithFee(
|
23
|
+
address token,
|
24
|
+
uint256 amountMinimum,
|
25
|
+
address recipient,
|
26
|
+
uint256 feeBips,
|
27
|
+
address feeRecipient
|
28
|
+
) external payable;
|
29
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
pragma abicoder v2;
|
4
|
+
|
5
|
+
/// @title Creates and initializes V3 Pools
|
6
|
+
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
|
7
|
+
/// require the pool to exist.
|
8
|
+
interface IPoolInitializer {
|
9
|
+
/// @notice Creates a new pool if it does not exist, then initializes if not initialized
|
10
|
+
/// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool
|
11
|
+
/// @param token0 The contract address of token0 of the pool
|
12
|
+
/// @param token1 The contract address of token1 of the pool
|
13
|
+
/// @param fee The fee amount of the v3 pool for the specified token pair
|
14
|
+
/// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
|
15
|
+
/// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
|
16
|
+
function createAndInitializePoolIfNecessary(
|
17
|
+
address token0,
|
18
|
+
address token1,
|
19
|
+
uint24 fee,
|
20
|
+
uint160 sqrtPriceX96
|
21
|
+
) external payable returns (address pool);
|
22
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
pragma abicoder v2;
|
4
|
+
|
5
|
+
/// @title Quoter Interface
|
6
|
+
/// @notice Supports quoting the calculated amounts from exact input or exact output swaps
|
7
|
+
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
|
8
|
+
/// to compute the result. They are also not gas efficient and should not be called on-chain.
|
9
|
+
interface IQuoter {
|
10
|
+
/// @notice Returns the amount out received for a given exact input swap without executing the swap
|
11
|
+
/// @param path The path of the swap, i.e. each token pair and the pool fee
|
12
|
+
/// @param amountIn The amount of the first token to swap
|
13
|
+
/// @return amountOut The amount of the last token that would be received
|
14
|
+
function quoteExactInput(bytes memory path, uint256 amountIn) external returns (uint256 amountOut);
|
15
|
+
|
16
|
+
/// @notice Returns the amount out received for a given exact input but for a swap of a single pool
|
17
|
+
/// @param tokenIn The token being swapped in
|
18
|
+
/// @param tokenOut The token being swapped out
|
19
|
+
/// @param fee The fee of the token pool to consider for the pair
|
20
|
+
/// @param amountIn The desired input amount
|
21
|
+
/// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
|
22
|
+
/// @return amountOut The amount of `tokenOut` that would be received
|
23
|
+
function quoteExactInputSingle(
|
24
|
+
address tokenIn,
|
25
|
+
address tokenOut,
|
26
|
+
uint24 fee,
|
27
|
+
uint256 amountIn,
|
28
|
+
uint160 sqrtPriceLimitX96
|
29
|
+
) external returns (uint256 amountOut);
|
30
|
+
|
31
|
+
/// @notice Returns the amount in required for a given exact output swap without executing the swap
|
32
|
+
/// @param path The path of the swap, i.e. each token pair and the pool fee. Path must be provided in reverse order
|
33
|
+
/// @param amountOut The amount of the last token to receive
|
34
|
+
/// @return amountIn The amount of first token required to be paid
|
35
|
+
function quoteExactOutput(bytes memory path, uint256 amountOut) external returns (uint256 amountIn);
|
36
|
+
|
37
|
+
/// @notice Returns the amount in required to receive the given exact output amount but for a swap of a single pool
|
38
|
+
/// @param tokenIn The token being swapped in
|
39
|
+
/// @param tokenOut The token being swapped out
|
40
|
+
/// @param fee The fee of the token pool to consider for the pair
|
41
|
+
/// @param amountOut The desired output amount
|
42
|
+
/// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
|
43
|
+
/// @return amountIn The amount required as the input for the swap in order to receive `amountOut`
|
44
|
+
function quoteExactOutputSingle(
|
45
|
+
address tokenIn,
|
46
|
+
address tokenOut,
|
47
|
+
uint24 fee,
|
48
|
+
uint256 amountOut,
|
49
|
+
uint160 sqrtPriceLimitX96
|
50
|
+
) external returns (uint256 amountIn);
|
51
|
+
}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
pragma abicoder v2;
|
4
|
+
|
5
|
+
/// @title QuoterV2 Interface
|
6
|
+
/// @notice Supports quoting the calculated amounts from exact input or exact output swaps.
|
7
|
+
/// @notice For each pool also tells you the number of initialized ticks crossed and the sqrt price of the pool after the swap.
|
8
|
+
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
|
9
|
+
/// to compute the result. They are also not gas efficient and should not be called on-chain.
|
10
|
+
interface IQuoterV2 {
|
11
|
+
/// @notice Returns the amount out received for a given exact input swap without executing the swap
|
12
|
+
/// @param path The path of the swap, i.e. each token pair and the pool fee
|
13
|
+
/// @param amountIn The amount of the first token to swap
|
14
|
+
/// @return amountOut The amount of the last token that would be received
|
15
|
+
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
|
16
|
+
/// @return initializedTicksCrossedList List of the initialized ticks that the swap crossed for each pool in the path
|
17
|
+
/// @return gasEstimate The estimate of the gas that the swap consumes
|
18
|
+
function quoteExactInput(bytes memory path, uint256 amountIn)
|
19
|
+
external
|
20
|
+
returns (
|
21
|
+
uint256 amountOut,
|
22
|
+
uint160[] memory sqrtPriceX96AfterList,
|
23
|
+
uint32[] memory initializedTicksCrossedList,
|
24
|
+
uint256 gasEstimate
|
25
|
+
);
|
26
|
+
|
27
|
+
struct QuoteExactInputSingleParams {
|
28
|
+
address tokenIn;
|
29
|
+
address tokenOut;
|
30
|
+
uint256 amountIn;
|
31
|
+
uint24 fee;
|
32
|
+
uint160 sqrtPriceLimitX96;
|
33
|
+
}
|
34
|
+
|
35
|
+
/// @notice Returns the amount out received for a given exact input but for a swap of a single pool
|
36
|
+
/// @param params The params for the quote, encoded as `QuoteExactInputSingleParams`
|
37
|
+
/// tokenIn The token being swapped in
|
38
|
+
/// tokenOut The token being swapped out
|
39
|
+
/// fee The fee of the token pool to consider for the pair
|
40
|
+
/// amountIn The desired input amount
|
41
|
+
/// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
|
42
|
+
/// @return amountOut The amount of `tokenOut` that would be received
|
43
|
+
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
|
44
|
+
/// @return initializedTicksCrossed The number of initialized ticks that the swap crossed
|
45
|
+
/// @return gasEstimate The estimate of the gas that the swap consumes
|
46
|
+
function quoteExactInputSingle(QuoteExactInputSingleParams memory params)
|
47
|
+
external
|
48
|
+
returns (
|
49
|
+
uint256 amountOut,
|
50
|
+
uint160 sqrtPriceX96After,
|
51
|
+
uint32 initializedTicksCrossed,
|
52
|
+
uint256 gasEstimate
|
53
|
+
);
|
54
|
+
|
55
|
+
/// @notice Returns the amount in required for a given exact output swap without executing the swap
|
56
|
+
/// @param path The path of the swap, i.e. each token pair and the pool fee. Path must be provided in reverse order
|
57
|
+
/// @param amountOut The amount of the last token to receive
|
58
|
+
/// @return amountIn The amount of first token required to be paid
|
59
|
+
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
|
60
|
+
/// @return initializedTicksCrossedList List of the initialized ticks that the swap crossed for each pool in the path
|
61
|
+
/// @return gasEstimate The estimate of the gas that the swap consumes
|
62
|
+
function quoteExactOutput(bytes memory path, uint256 amountOut)
|
63
|
+
external
|
64
|
+
returns (
|
65
|
+
uint256 amountIn,
|
66
|
+
uint160[] memory sqrtPriceX96AfterList,
|
67
|
+
uint32[] memory initializedTicksCrossedList,
|
68
|
+
uint256 gasEstimate
|
69
|
+
);
|
70
|
+
|
71
|
+
struct QuoteExactOutputSingleParams {
|
72
|
+
address tokenIn;
|
73
|
+
address tokenOut;
|
74
|
+
uint256 amount;
|
75
|
+
uint24 fee;
|
76
|
+
uint160 sqrtPriceLimitX96;
|
77
|
+
}
|
78
|
+
|
79
|
+
/// @notice Returns the amount in required to receive the given exact output amount but for a swap of a single pool
|
80
|
+
/// @param params The params for the quote, encoded as `QuoteExactOutputSingleParams`
|
81
|
+
/// tokenIn The token being swapped in
|
82
|
+
/// tokenOut The token being swapped out
|
83
|
+
/// fee The fee of the token pool to consider for the pair
|
84
|
+
/// amountOut The desired output amount
|
85
|
+
/// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
|
86
|
+
/// @return amountIn The amount required as the input for the swap in order to receive `amountOut`
|
87
|
+
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
|
88
|
+
/// @return initializedTicksCrossed The number of initialized ticks that the swap crossed
|
89
|
+
/// @return gasEstimate The estimate of the gas that the swap consumes
|
90
|
+
function quoteExactOutputSingle(QuoteExactOutputSingleParams memory params)
|
91
|
+
external
|
92
|
+
returns (
|
93
|
+
uint256 amountIn,
|
94
|
+
uint160 sqrtPriceX96After,
|
95
|
+
uint32 initializedTicksCrossed,
|
96
|
+
uint256 gasEstimate
|
97
|
+
);
|
98
|
+
}
|
@@ -0,0 +1,76 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
|
4
|
+
/// @title Self Permit
|
5
|
+
/// @notice Functionality to call permit on any EIP-2612-compliant token for use in the route
|
6
|
+
interface ISelfPermit {
|
7
|
+
/// @notice Permits this contract to spend a given token from `msg.sender`
|
8
|
+
/// @dev The `owner` is always msg.sender and the `spender` is always address(this).
|
9
|
+
/// @param token The address of the token spent
|
10
|
+
/// @param value The amount that can be spent of token
|
11
|
+
/// @param deadline A timestamp, the current blocktime must be less than or equal to this timestamp
|
12
|
+
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
|
13
|
+
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
|
14
|
+
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
|
15
|
+
function selfPermit(
|
16
|
+
address token,
|
17
|
+
uint256 value,
|
18
|
+
uint256 deadline,
|
19
|
+
uint8 v,
|
20
|
+
bytes32 r,
|
21
|
+
bytes32 s
|
22
|
+
) external payable;
|
23
|
+
|
24
|
+
/// @notice Permits this contract to spend a given token from `msg.sender`
|
25
|
+
/// @dev The `owner` is always msg.sender and the `spender` is always address(this).
|
26
|
+
/// Can be used instead of #selfPermit to prevent calls from failing due to a frontrun of a call to #selfPermit
|
27
|
+
/// @param token The address of the token spent
|
28
|
+
/// @param value The amount that can be spent of token
|
29
|
+
/// @param deadline A timestamp, the current blocktime must be less than or equal to this timestamp
|
30
|
+
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
|
31
|
+
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
|
32
|
+
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
|
33
|
+
function selfPermitIfNecessary(
|
34
|
+
address token,
|
35
|
+
uint256 value,
|
36
|
+
uint256 deadline,
|
37
|
+
uint8 v,
|
38
|
+
bytes32 r,
|
39
|
+
bytes32 s
|
40
|
+
) external payable;
|
41
|
+
|
42
|
+
/// @notice Permits this contract to spend the sender's tokens for permit signatures that have the `allowed` parameter
|
43
|
+
/// @dev The `owner` is always msg.sender and the `spender` is always address(this)
|
44
|
+
/// @param token The address of the token spent
|
45
|
+
/// @param nonce The current nonce of the owner
|
46
|
+
/// @param expiry The timestamp at which the permit is no longer valid
|
47
|
+
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
|
48
|
+
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
|
49
|
+
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
|
50
|
+
function selfPermitAllowed(
|
51
|
+
address token,
|
52
|
+
uint256 nonce,
|
53
|
+
uint256 expiry,
|
54
|
+
uint8 v,
|
55
|
+
bytes32 r,
|
56
|
+
bytes32 s
|
57
|
+
) external payable;
|
58
|
+
|
59
|
+
/// @notice Permits this contract to spend the sender's tokens for permit signatures that have the `allowed` parameter
|
60
|
+
/// @dev The `owner` is always msg.sender and the `spender` is always address(this)
|
61
|
+
/// Can be used instead of #selfPermitAllowed to prevent calls from failing due to a frontrun of a call to #selfPermitAllowed.
|
62
|
+
/// @param token The address of the token spent
|
63
|
+
/// @param nonce The current nonce of the owner
|
64
|
+
/// @param expiry The timestamp at which the permit is no longer valid
|
65
|
+
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
|
66
|
+
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
|
67
|
+
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
|
68
|
+
function selfPermitAllowedIfNecessary(
|
69
|
+
address token,
|
70
|
+
uint256 nonce,
|
71
|
+
uint256 expiry,
|
72
|
+
uint8 v,
|
73
|
+
bytes32 r,
|
74
|
+
bytes32 s
|
75
|
+
) external payable;
|
76
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
pragma abicoder v2;
|
4
|
+
|
5
|
+
import '@huuduynvc/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
|
6
|
+
|
7
|
+
/// @title Router token swapping functionality
|
8
|
+
/// @notice Functions for swapping tokens via Uniswap V3
|
9
|
+
interface ISwapRouter is IUniswapV3SwapCallback {
|
10
|
+
struct ExactInputSingleParams {
|
11
|
+
address tokenIn;
|
12
|
+
address tokenOut;
|
13
|
+
uint24 fee;
|
14
|
+
address recipient;
|
15
|
+
uint256 deadline;
|
16
|
+
uint256 amountIn;
|
17
|
+
uint256 amountOutMinimum;
|
18
|
+
uint160 sqrtPriceLimitX96;
|
19
|
+
}
|
20
|
+
|
21
|
+
/// @notice Swaps `amountIn` of one token for as much as possible of another token
|
22
|
+
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
|
23
|
+
/// @return amountOut The amount of the received token
|
24
|
+
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
|
25
|
+
|
26
|
+
struct ExactInputParams {
|
27
|
+
bytes path;
|
28
|
+
address recipient;
|
29
|
+
uint256 deadline;
|
30
|
+
uint256 amountIn;
|
31
|
+
uint256 amountOutMinimum;
|
32
|
+
}
|
33
|
+
|
34
|
+
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
|
35
|
+
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
|
36
|
+
/// @return amountOut The amount of the received token
|
37
|
+
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
|
38
|
+
|
39
|
+
struct ExactOutputSingleParams {
|
40
|
+
address tokenIn;
|
41
|
+
address tokenOut;
|
42
|
+
uint24 fee;
|
43
|
+
address recipient;
|
44
|
+
uint256 deadline;
|
45
|
+
uint256 amountOut;
|
46
|
+
uint256 amountInMaximum;
|
47
|
+
uint160 sqrtPriceLimitX96;
|
48
|
+
}
|
49
|
+
|
50
|
+
/// @notice Swaps as little as possible of one token for `amountOut` of another token
|
51
|
+
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
|
52
|
+
/// @return amountIn The amount of the input token
|
53
|
+
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
|
54
|
+
|
55
|
+
struct ExactOutputParams {
|
56
|
+
bytes path;
|
57
|
+
address recipient;
|
58
|
+
uint256 deadline;
|
59
|
+
uint256 amountOut;
|
60
|
+
uint256 amountInMaximum;
|
61
|
+
}
|
62
|
+
|
63
|
+
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
|
64
|
+
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
|
65
|
+
/// @return amountIn The amount of the input token
|
66
|
+
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
|
67
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
pragma abicoder v2;
|
4
|
+
|
5
|
+
/// @title Tick Lens
|
6
|
+
/// @notice Provides functions for fetching chunks of tick data for a pool
|
7
|
+
/// @dev This avoids the waterfall of fetching the tick bitmap, parsing the bitmap to know which ticks to fetch, and
|
8
|
+
/// then sending additional multicalls to fetch the tick data
|
9
|
+
interface ITickLens {
|
10
|
+
struct PopulatedTick {
|
11
|
+
int24 tick;
|
12
|
+
int128 liquidityNet;
|
13
|
+
uint128 liquidityGross;
|
14
|
+
}
|
15
|
+
|
16
|
+
/// @notice Get all the tick data for the populated ticks from a word of the tick bitmap of a pool
|
17
|
+
/// @param pool The address of the pool for which to fetch populated tick data
|
18
|
+
/// @param tickBitmapIndex The index of the word in the tick bitmap for which to parse the bitmap and
|
19
|
+
/// fetch all the populated ticks
|
20
|
+
/// @return populatedTicks An array of tick data for the given word in the tick bitmap
|
21
|
+
function getPopulatedTicksInWord(address pool, int16 tickBitmapIndex)
|
22
|
+
external
|
23
|
+
view
|
24
|
+
returns (PopulatedTick[] memory populatedTicks);
|
25
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
// SPDX-License-Identifier: GPL-2.0-or-later
|
2
|
+
pragma solidity >=0.7.5;
|
3
|
+
pragma abicoder v2;
|
4
|
+
|
5
|
+
import './IMulticall.sol';
|
6
|
+
import './ISelfPermit.sol';
|
7
|
+
import './IPoolInitializer.sol';
|
8
|
+
|
9
|
+
/// @title V3 Migrator
|
10
|
+
/// @notice Enables migration of liqudity from Uniswap v2-compatible pairs into Uniswap v3 pools
|
11
|
+
interface IV3Migrator is IMulticall, ISelfPermit, IPoolInitializer {
|
12
|
+
struct MigrateParams {
|
13
|
+
address pair; // the Uniswap v2-compatible pair
|
14
|
+
uint256 liquidityToMigrate; // expected to be balanceOf(msg.sender)
|
15
|
+
uint8 percentageToMigrate; // represented as a numerator over 100
|
16
|
+
address token0;
|
17
|
+
address token1;
|
18
|
+
uint24 fee;
|
19
|
+
int24 tickLower;
|
20
|
+
int24 tickUpper;
|
21
|
+
uint256 amount0Min; // must be discounted by percentageToMigrate
|
22
|
+
uint256 amount1Min; // must be discounted by percentageToMigrate
|
23
|
+
address recipient;
|
24
|
+
uint256 deadline;
|
25
|
+
bool refundAsETH;
|
26
|
+
}
|
27
|
+
|
28
|
+
/// @notice Migrates liquidity to v3 by burning v2 liquidity and minting a new position for v3
|
29
|
+
/// @dev Slippage protection is enforced via `amount{0,1}Min`, which should be a discount of the expected values of
|
30
|
+
/// the maximum amount of v3 liquidity that the v2 liquidity can get. For the special case of migrating to an
|
31
|
+
/// out-of-range position, `amount{0,1}Min` may be set to 0, enforcing that the position remains out of range
|
32
|
+
/// @param params The params necessary to migrate v2 liquidity, encoded as `MigrateParams` in calldata
|
33
|
+
function migrate(MigrateParams calldata params) external;
|
34
|
+
}
|