@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.
Files changed (88) hide show
  1. package/LICENSE +339 -0
  2. package/README.md +52 -0
  3. package/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json +1230 -0
  4. package/artifacts/contracts/NonfungibleTokenPositionDescriptor.sol/NonfungibleTokenPositionDescriptor.json +161 -0
  5. package/artifacts/contracts/SwapRouter.sol/SwapRouter.json +574 -0
  6. package/artifacts/contracts/V3Migrator.sol/V3Migrator.json +360 -0
  7. package/artifacts/contracts/examples/PairFlash.sol/PairFlash.json +196 -0
  8. package/artifacts/contracts/interfaces/IERC20Metadata.sol/IERC20Metadata.json +233 -0
  9. package/artifacts/contracts/interfaces/IERC721Permit.sol/IERC721Permit.json +360 -0
  10. package/artifacts/contracts/interfaces/IMulticall.sol/IMulticall.json +30 -0
  11. package/artifacts/contracts/interfaces/INonfungiblePositionManager.sol/INonfungiblePositionManager.json +998 -0
  12. package/artifacts/contracts/interfaces/INonfungibleTokenPositionDescriptor.sol/INonfungibleTokenPositionDescriptor.json +35 -0
  13. package/artifacts/contracts/interfaces/IPeripheryImmutableState.sol/IPeripheryImmutableState.json +37 -0
  14. package/artifacts/contracts/interfaces/IPeripheryPayments.sol/IPeripheryPayments.json +59 -0
  15. package/artifacts/contracts/interfaces/IPeripheryPaymentsWithFee.sol/IPeripheryPaymentsWithFee.json +120 -0
  16. package/artifacts/contracts/interfaces/IPoolInitializer.sol/IPoolInitializer.json +45 -0
  17. package/artifacts/contracts/interfaces/IQuoter.sol/IQuoter.json +137 -0
  18. package/artifacts/contracts/interfaces/IQuoterV2.sol/IQuoterV2.json +211 -0
  19. package/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json +163 -0
  20. package/artifacts/contracts/interfaces/ISwapRouter.sol/ISwapRouter.json +248 -0
  21. package/artifacts/contracts/interfaces/ITickLens.sol/ITickLens.json +52 -0
  22. package/artifacts/contracts/interfaces/IV3Migrator.sol/IV3Migrator.json +296 -0
  23. package/artifacts/contracts/interfaces/external/IERC1271.sol/IERC1271.json +35 -0
  24. package/artifacts/contracts/interfaces/external/IERC20PermitAllowed.sol/IERC20PermitAllowed.json +59 -0
  25. package/artifacts/contracts/interfaces/external/IWETH9.sol/IWETH9.json +214 -0
  26. package/artifacts/contracts/lens/Quoter.sol/Quoter.json +202 -0
  27. package/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json +276 -0
  28. package/artifacts/contracts/lens/TickLens.sol/TickLens.json +52 -0
  29. package/artifacts/contracts/lens/UniswapInterfaceMulticall.sol/UniswapInterfaceMulticall.json +101 -0
  30. package/artifacts/contracts/libraries/BytesLib.sol/BytesLib.json +10 -0
  31. package/artifacts/contracts/libraries/CallbackValidation.sol/CallbackValidation.json +10 -0
  32. package/artifacts/contracts/libraries/ChainId.sol/ChainId.json +10 -0
  33. package/artifacts/contracts/libraries/HexStrings.sol/HexStrings.json +10 -0
  34. package/artifacts/contracts/libraries/LiquidityAmounts.sol/LiquidityAmounts.json +10 -0
  35. package/artifacts/contracts/libraries/NFTDescriptor.sol/NFTDescriptor.json +102 -0
  36. package/artifacts/contracts/libraries/NFTSVG.sol/NFTSVG.json +10 -0
  37. package/artifacts/contracts/libraries/OracleLibrary.sol/OracleLibrary.json +10 -0
  38. package/artifacts/contracts/libraries/Path.sol/Path.json +10 -0
  39. package/artifacts/contracts/libraries/PoolAddress.sol/PoolAddress.json +10 -0
  40. package/artifacts/contracts/libraries/PoolTicksCounter.sol/PoolTicksCounter.json +10 -0
  41. package/artifacts/contracts/libraries/PositionKey.sol/PositionKey.json +10 -0
  42. package/artifacts/contracts/libraries/PositionValue.sol/PositionValue.json +10 -0
  43. package/artifacts/contracts/libraries/TokenRatioSortOrder.sol/TokenRatioSortOrder.json +10 -0
  44. package/artifacts/contracts/libraries/TransferHelper.sol/TransferHelper.json +10 -0
  45. package/contracts/base/BlockTimestamp.sol +12 -0
  46. package/contracts/base/ERC721Permit.sol +86 -0
  47. package/contracts/base/LiquidityManagement.sol +90 -0
  48. package/contracts/base/Multicall.sol +28 -0
  49. package/contracts/base/PeripheryImmutableState.sol +18 -0
  50. package/contracts/base/PeripheryPayments.sol +70 -0
  51. package/contracts/base/PeripheryPaymentsWithFee.sol +55 -0
  52. package/contracts/base/PeripheryValidation.sol +11 -0
  53. package/contracts/base/PoolInitializer.sol +32 -0
  54. package/contracts/base/SelfPermit.sol +63 -0
  55. package/contracts/interfaces/IERC20Metadata.sol +18 -0
  56. package/contracts/interfaces/IERC721Permit.sol +32 -0
  57. package/contracts/interfaces/IMulticall.sol +13 -0
  58. package/contracts/interfaces/INonfungiblePositionManager.sol +180 -0
  59. package/contracts/interfaces/INonfungibleTokenPositionDescriptor.sol +17 -0
  60. package/contracts/interfaces/IPeripheryImmutableState.sol +12 -0
  61. package/contracts/interfaces/IPeripheryPayments.sol +28 -0
  62. package/contracts/interfaces/IPeripheryPaymentsWithFee.sol +29 -0
  63. package/contracts/interfaces/IPoolInitializer.sol +22 -0
  64. package/contracts/interfaces/IQuoter.sol +51 -0
  65. package/contracts/interfaces/IQuoterV2.sol +98 -0
  66. package/contracts/interfaces/ISelfPermit.sol +76 -0
  67. package/contracts/interfaces/ISwapRouter.sol +67 -0
  68. package/contracts/interfaces/ITickLens.sol +25 -0
  69. package/contracts/interfaces/IV3Migrator.sol +34 -0
  70. package/contracts/interfaces/external/IERC1271.sol +16 -0
  71. package/contracts/interfaces/external/IERC20PermitAllowed.sol +27 -0
  72. package/contracts/interfaces/external/IWETH9.sol +13 -0
  73. package/contracts/libraries/BytesLib.sol +101 -0
  74. package/contracts/libraries/CallbackValidation.sol +36 -0
  75. package/contracts/libraries/ChainId.sol +13 -0
  76. package/contracts/libraries/HexStrings.sol +29 -0
  77. package/contracts/libraries/LiquidityAmounts.sol +137 -0
  78. package/contracts/libraries/NFTDescriptor.sol +477 -0
  79. package/contracts/libraries/NFTSVG.sol +406 -0
  80. package/contracts/libraries/OracleLibrary.sol +161 -0
  81. package/contracts/libraries/Path.sol +69 -0
  82. package/contracts/libraries/PoolAddress.sol +48 -0
  83. package/contracts/libraries/PoolTicksCounter.sol +97 -0
  84. package/contracts/libraries/PositionKey.sol +13 -0
  85. package/contracts/libraries/PositionValue.sol +167 -0
  86. package/contracts/libraries/TokenRatioSortOrder.sol +12 -0
  87. package/contracts/libraries/TransferHelper.sol +60 -0
  88. package/package.json +68 -0
@@ -0,0 +1,48 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.5.0;
3
+
4
+ /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
5
+ library PoolAddress {
6
+ bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
7
+
8
+ /// @notice The identifying key of the pool
9
+ struct PoolKey {
10
+ address token0;
11
+ address token1;
12
+ uint24 fee;
13
+ }
14
+
15
+ /// @notice Returns PoolKey: the ordered tokens with the matched fee levels
16
+ /// @param tokenA The first token of a pool, unsorted
17
+ /// @param tokenB The second token of a pool, unsorted
18
+ /// @param fee The fee level of the pool
19
+ /// @return Poolkey The pool details with ordered token0 and token1 assignments
20
+ function getPoolKey(
21
+ address tokenA,
22
+ address tokenB,
23
+ uint24 fee
24
+ ) internal pure returns (PoolKey memory) {
25
+ if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
26
+ return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
27
+ }
28
+
29
+ /// @notice Deterministically computes the pool address given the factory and PoolKey
30
+ /// @param factory The Uniswap V3 factory contract address
31
+ /// @param key The PoolKey
32
+ /// @return pool The contract address of the V3 pool
33
+ function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
34
+ require(key.token0 < key.token1);
35
+ pool = address(
36
+ uint256(
37
+ keccak256(
38
+ abi.encodePacked(
39
+ hex'ff',
40
+ factory,
41
+ keccak256(abi.encode(key.token0, key.token1, key.fee)),
42
+ POOL_INIT_CODE_HASH
43
+ )
44
+ )
45
+ )
46
+ );
47
+ }
48
+ }
@@ -0,0 +1,97 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.6.0;
3
+
4
+
5
+ import '@huuduynvc/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
6
+
7
+ library PoolTicksCounter {
8
+ /// @dev This function counts the number of initialized ticks that would incur a gas cost between tickBefore and tickAfter.
9
+ /// When tickBefore and/or tickAfter themselves are initialized, the logic over whether we should count them depends on the
10
+ /// direction of the swap. If we are swapping upwards (tickAfter > tickBefore) we don't want to count tickBefore but we do
11
+ /// want to count tickAfter. The opposite is true if we are swapping downwards.
12
+ function countInitializedTicksCrossed(
13
+ IUniswapV3Pool self,
14
+ int24 tickBefore,
15
+ int24 tickAfter
16
+ ) internal view returns (uint32 initializedTicksCrossed) {
17
+ int16 wordPosLower;
18
+ int16 wordPosHigher;
19
+ uint8 bitPosLower;
20
+ uint8 bitPosHigher;
21
+ bool tickBeforeInitialized;
22
+ bool tickAfterInitialized;
23
+
24
+ {
25
+ // Get the key and offset in the tick bitmap of the active tick before and after the swap.
26
+ int16 wordPos = int16((tickBefore / self.tickSpacing()) >> 8);
27
+ uint8 bitPos = uint8((tickBefore / self.tickSpacing()) % 256);
28
+
29
+ int16 wordPosAfter = int16((tickAfter / self.tickSpacing()) >> 8);
30
+ uint8 bitPosAfter = uint8((tickAfter / self.tickSpacing()) % 256);
31
+
32
+ // In the case where tickAfter is initialized, we only want to count it if we are swapping downwards.
33
+ // If the initializable tick after the swap is initialized, our original tickAfter is a
34
+ // multiple of tick spacing, and we are swapping downwards we know that tickAfter is initialized
35
+ // and we shouldn't count it.
36
+ tickAfterInitialized =
37
+ ((self.tickBitmap(wordPosAfter) & (1 << bitPosAfter)) > 0) &&
38
+ ((tickAfter % self.tickSpacing()) == 0) &&
39
+ (tickBefore > tickAfter);
40
+
41
+ // In the case where tickBefore is initialized, we only want to count it if we are swapping upwards.
42
+ // Use the same logic as above to decide whether we should count tickBefore or not.
43
+ tickBeforeInitialized =
44
+ ((self.tickBitmap(wordPos) & (1 << bitPos)) > 0) &&
45
+ ((tickBefore % self.tickSpacing()) == 0) &&
46
+ (tickBefore < tickAfter);
47
+
48
+ if (wordPos < wordPosAfter || (wordPos == wordPosAfter && bitPos <= bitPosAfter)) {
49
+ wordPosLower = wordPos;
50
+ bitPosLower = bitPos;
51
+ wordPosHigher = wordPosAfter;
52
+ bitPosHigher = bitPosAfter;
53
+ } else {
54
+ wordPosLower = wordPosAfter;
55
+ bitPosLower = bitPosAfter;
56
+ wordPosHigher = wordPos;
57
+ bitPosHigher = bitPos;
58
+ }
59
+ }
60
+
61
+ // Count the number of initialized ticks crossed by iterating through the tick bitmap.
62
+ // Our first mask should include the lower tick and everything to its left.
63
+ uint256 mask = type(uint256).max << bitPosLower;
64
+ while (wordPosLower <= wordPosHigher) {
65
+ // If we're on the final tick bitmap page, ensure we only count up to our
66
+ // ending tick.
67
+ if (wordPosLower == wordPosHigher) {
68
+ mask = mask & (type(uint256).max >> (255 - bitPosHigher));
69
+ }
70
+
71
+ uint256 masked = self.tickBitmap(wordPosLower) & mask;
72
+ initializedTicksCrossed += countOneBits(masked);
73
+ wordPosLower++;
74
+ // Reset our mask so we consider all bits on the next iteration.
75
+ mask = type(uint256).max;
76
+ }
77
+
78
+ if (tickAfterInitialized) {
79
+ initializedTicksCrossed -= 1;
80
+ }
81
+
82
+ if (tickBeforeInitialized) {
83
+ initializedTicksCrossed -= 1;
84
+ }
85
+
86
+ return initializedTicksCrossed;
87
+ }
88
+
89
+ function countOneBits(uint256 x) private pure returns (uint16) {
90
+ uint16 bits = 0;
91
+ while (x != 0) {
92
+ bits++;
93
+ x &= (x - 1);
94
+ }
95
+ return bits;
96
+ }
97
+ }
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.5.0;
3
+
4
+ library PositionKey {
5
+ /// @dev Returns the key of the position in the core library
6
+ function compute(
7
+ address owner,
8
+ int24 tickLower,
9
+ int24 tickUpper
10
+ ) internal pure returns (bytes32) {
11
+ return keccak256(abi.encodePacked(owner, tickLower, tickUpper));
12
+ }
13
+ }
@@ -0,0 +1,167 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.6.8 <0.8.0;
3
+
4
+ import '@huuduynvc/v3-core/contracts/interfaces/IUniswapV3Pool.sol';
5
+ import '@huuduynvc/v3-core/contracts/libraries/FixedPoint128.sol';
6
+ import '@huuduynvc/v3-core/contracts/libraries/TickMath.sol';
7
+ import '@huuduynvc/v3-core/contracts/libraries/Tick.sol';
8
+ import '../interfaces/INonfungiblePositionManager.sol';
9
+ import './LiquidityAmounts.sol';
10
+ import './PoolAddress.sol';
11
+ import './PositionKey.sol';
12
+
13
+ /// @title Returns information about the token value held in a Uniswap V3 NFT
14
+ library PositionValue {
15
+ /// @notice Returns the total amounts of token0 and token1, i.e. the sum of fees and principal
16
+ /// that a given nonfungible position manager token is worth
17
+ /// @param positionManager The Uniswap V3 NonfungiblePositionManager
18
+ /// @param tokenId The tokenId of the token for which to get the total value
19
+ /// @param sqrtRatioX96 The square root price X96 for which to calculate the principal amounts
20
+ /// @return amount0 The total amount of token0 including principal and fees
21
+ /// @return amount1 The total amount of token1 including principal and fees
22
+ function total(
23
+ INonfungiblePositionManager positionManager,
24
+ uint256 tokenId,
25
+ uint160 sqrtRatioX96
26
+ ) internal view returns (uint256 amount0, uint256 amount1) {
27
+ (uint256 amount0Principal, uint256 amount1Principal) = principal(positionManager, tokenId, sqrtRatioX96);
28
+ (uint256 amount0Fee, uint256 amount1Fee) = fees(positionManager, tokenId);
29
+ return (amount0Principal + amount0Fee, amount1Principal + amount1Fee);
30
+ }
31
+
32
+ /// @notice Calculates the principal (currently acting as liquidity) owed to the token owner in the event
33
+ /// that the position is burned
34
+ /// @param positionManager The Uniswap V3 NonfungiblePositionManager
35
+ /// @param tokenId The tokenId of the token for which to get the total principal owed
36
+ /// @param sqrtRatioX96 The square root price X96 for which to calculate the principal amounts
37
+ /// @return amount0 The principal amount of token0
38
+ /// @return amount1 The principal amount of token1
39
+ function principal(
40
+ INonfungiblePositionManager positionManager,
41
+ uint256 tokenId,
42
+ uint160 sqrtRatioX96
43
+ ) internal view returns (uint256 amount0, uint256 amount1) {
44
+ (, , , , , int24 tickLower, int24 tickUpper, uint128 liquidity, , , , ) = positionManager.positions(tokenId);
45
+
46
+ return
47
+ LiquidityAmounts.getAmountsForLiquidity(
48
+ sqrtRatioX96,
49
+ TickMath.getSqrtRatioAtTick(tickLower),
50
+ TickMath.getSqrtRatioAtTick(tickUpper),
51
+ liquidity
52
+ );
53
+ }
54
+
55
+ struct FeeParams {
56
+ address token0;
57
+ address token1;
58
+ uint24 fee;
59
+ int24 tickLower;
60
+ int24 tickUpper;
61
+ uint128 liquidity;
62
+ uint256 positionFeeGrowthInside0LastX128;
63
+ uint256 positionFeeGrowthInside1LastX128;
64
+ uint256 tokensOwed0;
65
+ uint256 tokensOwed1;
66
+ }
67
+
68
+ /// @notice Calculates the total fees owed to the token owner
69
+ /// @param positionManager The Uniswap V3 NonfungiblePositionManager
70
+ /// @param tokenId The tokenId of the token for which to get the total fees owed
71
+ /// @return amount0 The amount of fees owed in token0
72
+ /// @return amount1 The amount of fees owed in token1
73
+ function fees(INonfungiblePositionManager positionManager, uint256 tokenId)
74
+ internal
75
+ view
76
+ returns (uint256 amount0, uint256 amount1)
77
+ {
78
+ (
79
+ ,
80
+ ,
81
+ address token0,
82
+ address token1,
83
+ uint24 fee,
84
+ int24 tickLower,
85
+ int24 tickUpper,
86
+ uint128 liquidity,
87
+ uint256 positionFeeGrowthInside0LastX128,
88
+ uint256 positionFeeGrowthInside1LastX128,
89
+ uint256 tokensOwed0,
90
+ uint256 tokensOwed1
91
+ ) = positionManager.positions(tokenId);
92
+
93
+ return
94
+ _fees(
95
+ positionManager,
96
+ FeeParams({
97
+ token0: token0,
98
+ token1: token1,
99
+ fee: fee,
100
+ tickLower: tickLower,
101
+ tickUpper: tickUpper,
102
+ liquidity: liquidity,
103
+ positionFeeGrowthInside0LastX128: positionFeeGrowthInside0LastX128,
104
+ positionFeeGrowthInside1LastX128: positionFeeGrowthInside1LastX128,
105
+ tokensOwed0: tokensOwed0,
106
+ tokensOwed1: tokensOwed1
107
+ })
108
+ );
109
+ }
110
+
111
+ function _fees(INonfungiblePositionManager positionManager, FeeParams memory feeParams)
112
+ private
113
+ view
114
+ returns (uint256 amount0, uint256 amount1)
115
+ {
116
+ (uint256 poolFeeGrowthInside0LastX128, uint256 poolFeeGrowthInside1LastX128) =
117
+ _getFeeGrowthInside(
118
+ IUniswapV3Pool(
119
+ PoolAddress.computeAddress(
120
+ positionManager.factory(),
121
+ PoolAddress.PoolKey({token0: feeParams.token0, token1: feeParams.token1, fee: feeParams.fee})
122
+ )
123
+ ),
124
+ feeParams.tickLower,
125
+ feeParams.tickUpper
126
+ );
127
+
128
+ amount0 =
129
+ FullMath.mulDiv(
130
+ poolFeeGrowthInside0LastX128 - feeParams.positionFeeGrowthInside0LastX128,
131
+ feeParams.liquidity,
132
+ FixedPoint128.Q128
133
+ ) +
134
+ feeParams.tokensOwed0;
135
+
136
+ amount1 =
137
+ FullMath.mulDiv(
138
+ poolFeeGrowthInside1LastX128 - feeParams.positionFeeGrowthInside1LastX128,
139
+ feeParams.liquidity,
140
+ FixedPoint128.Q128
141
+ ) +
142
+ feeParams.tokensOwed1;
143
+ }
144
+
145
+ function _getFeeGrowthInside(
146
+ IUniswapV3Pool pool,
147
+ int24 tickLower,
148
+ int24 tickUpper
149
+ ) private view returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) {
150
+ (, int24 tickCurrent, , , , , ) = pool.slot0();
151
+ (, , uint256 lowerFeeGrowthOutside0X128, uint256 lowerFeeGrowthOutside1X128, , , , ) = pool.ticks(tickLower);
152
+ (, , uint256 upperFeeGrowthOutside0X128, uint256 upperFeeGrowthOutside1X128, , , , ) = pool.ticks(tickUpper);
153
+
154
+ if (tickCurrent < tickLower) {
155
+ feeGrowthInside0X128 = lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
156
+ feeGrowthInside1X128 = lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
157
+ } else if (tickCurrent < tickUpper) {
158
+ uint256 feeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128();
159
+ uint256 feeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128();
160
+ feeGrowthInside0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
161
+ feeGrowthInside1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
162
+ } else {
163
+ feeGrowthInside0X128 = upperFeeGrowthOutside0X128 - lowerFeeGrowthOutside0X128;
164
+ feeGrowthInside1X128 = upperFeeGrowthOutside1X128 - lowerFeeGrowthOutside1X128;
165
+ }
166
+ }
167
+ }
@@ -0,0 +1,12 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity =0.7.6;
3
+
4
+ library TokenRatioSortOrder {
5
+ int256 constant NUMERATOR_MOST = 300;
6
+ int256 constant NUMERATOR_MORE = 200;
7
+ int256 constant NUMERATOR = 100;
8
+
9
+ int256 constant DENOMINATOR_MOST = -300;
10
+ int256 constant DENOMINATOR_MORE = -200;
11
+ int256 constant DENOMINATOR = -100;
12
+ }
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.6.0;
3
+
4
+ import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
5
+
6
+ library TransferHelper {
7
+ /// @notice Transfers tokens from the targeted address to the given destination
8
+ /// @notice Errors with 'STF' if transfer fails
9
+ /// @param token The contract address of the token to be transferred
10
+ /// @param from The originating address from which the tokens will be transferred
11
+ /// @param to The destination address of the transfer
12
+ /// @param value The amount to be transferred
13
+ function safeTransferFrom(
14
+ address token,
15
+ address from,
16
+ address to,
17
+ uint256 value
18
+ ) internal {
19
+ (bool success, bytes memory data) =
20
+ token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
21
+ require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
22
+ }
23
+
24
+ /// @notice Transfers tokens from msg.sender to a recipient
25
+ /// @dev Errors with ST if transfer fails
26
+ /// @param token The contract address of the token which will be transferred
27
+ /// @param to The recipient of the transfer
28
+ /// @param value The value of the transfer
29
+ function safeTransfer(
30
+ address token,
31
+ address to,
32
+ uint256 value
33
+ ) internal {
34
+ (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
35
+ require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
36
+ }
37
+
38
+ /// @notice Approves the stipulated contract to spend the given allowance in the given token
39
+ /// @dev Errors with 'SA' if transfer fails
40
+ /// @param token The contract address of the token to be approved
41
+ /// @param to The target of the approval
42
+ /// @param value The amount of the given token the target will be allowed to spend
43
+ function safeApprove(
44
+ address token,
45
+ address to,
46
+ uint256 value
47
+ ) internal {
48
+ (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
49
+ require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
50
+ }
51
+
52
+ /// @notice Transfers ETH to the recipient address
53
+ /// @dev Fails with `STE`
54
+ /// @param to The destination of the transfer
55
+ /// @param value The value to be transferred
56
+ function safeTransferETH(address to, uint256 value) internal {
57
+ (bool success, ) = to.call{value: value}(new bytes(0));
58
+ require(success, 'STE');
59
+ }
60
+ }
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@huuduynvc/v3-periphery",
3
+ "description": "🎚 Peripheral smart contracts for interacting with Uniswap V3",
4
+ "license": "GPL-2.0-or-later",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "version": "1.3.0",
9
+ "homepage": "https://uniswap.org",
10
+ "keywords": [
11
+ "uniswap",
12
+ "periphery",
13
+ "v3"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/matthew-dex/v3-periphery"
18
+ },
19
+ "files": [
20
+ "contracts/base",
21
+ "contracts/interfaces",
22
+ "contracts/libraries",
23
+ "artifacts/contracts/**/*.json",
24
+ "!artifacts/contracts/**/*.dbg.json",
25
+ "!artifacts/contracts/test/**/*",
26
+ "!artifacts/contracts/base/**/*"
27
+ ],
28
+ "engines": {
29
+ "node": ">=10"
30
+ },
31
+ "dependencies": {
32
+ "@openzeppelin/contracts": "3.4.1-solc-0.7-2",
33
+ "@uniswap/lib": "^4.0.1-alpha",
34
+ "@huuduynvc/v2-core": "1.0.1",
35
+ "@huuduynvc/v3-core": "1.0.0",
36
+ "base64-sol": "1.0.1",
37
+ "hardhat-watcher": "^2.1.1"
38
+ },
39
+ "devDependencies": {
40
+ "@nomiclabs/hardhat-ethers": "^2.0.2",
41
+ "@nomiclabs/hardhat-etherscan": "^2.1.1",
42
+ "@nomiclabs/hardhat-waffle": "^2.0.1",
43
+ "@typechain/ethers-v5": "^4.0.0",
44
+ "@types/chai": "^4.2.6",
45
+ "@types/mocha": "^5.2.7",
46
+ "chai": "^4.2.0",
47
+ "decimal.js": "^10.2.1",
48
+ "ethereum-waffle": "^3.0.2",
49
+ "ethers": "^5.0.8",
50
+ "hardhat": "^2.2.0",
51
+ "hardhat-typechain": "^0.3.5",
52
+ "is-svg": "^4.3.1",
53
+ "mocha": "^6.2.2",
54
+ "mocha-chai-jest-snapshot": "^1.1.0",
55
+ "prettier": "^2.0.5",
56
+ "prettier-plugin-solidity": "^1.0.0-beta.10",
57
+ "solhint": "^3.2.1",
58
+ "solhint-plugin-prettier": "^0.0.5",
59
+ "ts-generator": "^0.1.1",
60
+ "ts-node": "^8.5.4",
61
+ "typechain": "^4.0.0",
62
+ "typescript": "^3.7.3"
63
+ },
64
+ "scripts": {
65
+ "compile": "hardhat compile",
66
+ "test": "hardhat test"
67
+ }
68
+ }