1
1
// SPDX-License-Identifier: MIT
2
2
pragma solidity ^ 0.8.0 ;
3
3
4
- import {Math} from "openzeppelin-contracts/contracts/utils/math/Math.sol " ;
5
- import {INonfungiblePositionManager} from "v3-periphery/interfaces/INonfungiblePositionManager.sol " ;
6
- import {IMulticall} from "v3-periphery/interfaces/IMulticall.sol " ;
7
- import {IUniswapV3Factory} from "v3-core/contracts/interfaces/IUniswapV3Factory.sol " ;
8
- import {IUniswapV3Pool} from "v3-core/contracts/interfaces/IUniswapV3Pool.sol " ;
9
- import {IERC721Receiver } from "openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol " ;
10
- import {ITokenDistributor, IERC20 , Party} from "party-protocol/contracts/distribution/ITokenDistributor.sol " ;
11
- import {GovernableERC20} from "./GovernableERC20.sol " ;
12
- import {FeeRecipient} from "./FeeCollector.sol " ;
4
+ import { Math } from "openzeppelin-contracts/contracts/utils/math/Math.sol " ;
5
+ import { INonfungiblePositionManager } from "v3-periphery/interfaces/INonfungiblePositionManager.sol " ;
6
+ import { IMulticall } from "v3-periphery/interfaces/IMulticall.sol " ;
7
+ import { IUniswapV3Factory } from "v3-core/contracts/interfaces/IUniswapV3Factory.sol " ;
8
+ import { IUniswapV3Pool } from "v3-core/contracts/interfaces/IUniswapV3Pool.sol " ;
9
+ import { IERC721Receiver } from "openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol " ;
10
+ import { ITokenDistributor, IERC20 , Party } from "party-protocol/contracts/distribution/ITokenDistributor.sol " ;
11
+ import { GovernableERC20 } from "./GovernableERC20.sol " ;
12
+ import { FeeRecipient } from "./FeeCollector.sol " ;
13
13
14
14
contract ERC20CreatorV3 is IERC721Receiver {
15
15
struct TokenDistributionConfiguration {
@@ -29,15 +29,9 @@ contract ERC20CreatorV3 is IERC721Receiver {
29
29
TokenDistributionConfiguration config
30
30
);
31
31
32
- event FeeRecipientUpdated (
33
- address indexed oldFeeRecipient ,
34
- address indexed newFeeRecipient
35
- );
32
+ event FeeRecipientUpdated (address indexed oldFeeRecipient , address indexed newFeeRecipient );
36
33
37
- event FeeBasisPointsUpdated (
38
- uint16 oldFeeBasisPoints ,
39
- uint16 newFeeBasisPoints
40
- );
34
+ event FeeBasisPointsUpdated (uint16 oldFeeBasisPoints , uint16 newFeeBasisPoints );
41
35
42
36
error InvalidTokenDistribution ();
43
37
error OnlyFeeRecipient ();
@@ -84,8 +78,7 @@ contract ERC20CreatorV3 is IERC721Receiver {
84
78
uint16 feeBasisPoints_ ,
85
79
uint16 poolFee
86
80
) {
87
- if (poolFee != 500 && poolFee != 3000 && poolFee != 10_000 )
88
- revert InvalidPoolFee ();
81
+ if (poolFee != 500 && poolFee != 3000 && poolFee != 10_000 ) revert InvalidPoolFee ();
89
82
if (feeBasisPoints_ > 5e3 ) revert InvalidFeeBasisPoints ();
90
83
91
84
TOKEN_DISTRIBUTOR = tokenDistributor;
@@ -99,9 +92,7 @@ contract ERC20CreatorV3 is IERC721Receiver {
99
92
100
93
int24 tickSpacing = UNISWAP_V3_FACTORY.feeAmountTickSpacing (POOL_FEE);
101
94
MAX_TICK = (887272 /* TickMath.MAX_TICK */ / tickSpacing) * tickSpacing;
102
- MIN_TICK =
103
- (- 887272 /* TickMath.MIN_TICK */ / tickSpacing) *
104
- tickSpacing;
95
+ MIN_TICK = (- 887272 /* TickMath.MIN_TICK */ / tickSpacing) * tickSpacing;
105
96
}
106
97
107
98
/// @notice Creates a new ERC20 token, LPs it in a locked full range Uniswap V3 position, and distributes some of the new token to party members.
@@ -137,19 +128,14 @@ contract ERC20CreatorV3 is IERC721Receiver {
137
128
IERC20 token = IERC20 (
138
129
address (
139
130
new GovernableERC20 {
140
- salt: keccak256 (
141
- abi.encode (blockhash (block .number - 1 ), msg .sender )
142
- )
131
+ salt: keccak256 (abi.encode (blockhash (block .number - 1 ), msg .sender ))
143
132
}(name, symbol, config.totalSupply, address (this ))
144
133
)
145
134
);
146
135
147
136
if (config.numTokensForDistribution > 0 ) {
148
137
// Create distribution
149
- token.transfer (
150
- address (TOKEN_DISTRIBUTOR),
151
- config.numTokensForDistribution
152
- );
138
+ token.transfer (address (TOKEN_DISTRIBUTOR), config.numTokensForDistribution);
153
139
TOKEN_DISTRIBUTOR.createErc20Distribution (
154
140
token,
155
141
Party (payable (party)),
@@ -173,22 +159,13 @@ contract ERC20CreatorV3 is IERC721Receiver {
173
159
: (config.numTokensForLP, msg .value - feeAmount);
174
160
175
161
// Create and initialize pool. Reverts if pool already created.
176
- address pool = UNISWAP_V3_FACTORY.createPool (
177
- address (token),
178
- WETH,
179
- POOL_FEE
180
- );
162
+ address pool = UNISWAP_V3_FACTORY.createPool (address (token), WETH, POOL_FEE);
181
163
182
164
// Initialize pool for the derived starting price
183
- uint160 sqrtPriceX96 = uint160 (
184
- (Math.sqrt ((amount1 * 1e18 ) / amount0) * _X96) / 1e9
185
- );
165
+ uint160 sqrtPriceX96 = uint160 ((Math.sqrt ((amount1 * 1e18 ) / amount0) * _X96) / 1e9 );
186
166
IUniswapV3Pool (pool).initialize (sqrtPriceX96);
187
167
188
- token.approve (
189
- address (UNISWAP_V3_POSITION_MANAGER),
190
- config.numTokensForLP
191
- );
168
+ token.approve (address (UNISWAP_V3_POSITION_MANAGER), config.numTokensForLP);
192
169
193
170
// Use multicall to sweep back excess ETH
194
171
bytes [] memory calls = new bytes [](2 );
@@ -210,12 +187,9 @@ contract ERC20CreatorV3 is IERC721Receiver {
210
187
})
211
188
)
212
189
);
213
- calls[1 ] = abi.encodePacked (
214
- UNISWAP_V3_POSITION_MANAGER.refundETH.selector
215
- );
216
- bytes memory mintReturnData = IMulticall (
217
- address (UNISWAP_V3_POSITION_MANAGER)
218
- ).multicall {value: msg .value - feeAmount}(calls)[0 ];
190
+ calls[1 ] = abi.encodePacked (UNISWAP_V3_POSITION_MANAGER.refundETH.selector );
191
+ bytes memory mintReturnData = IMulticall (address (UNISWAP_V3_POSITION_MANAGER))
192
+ .multicall { value: msg .value - feeAmount }(calls)[0 ];
219
193
220
194
lpTokenId = abi.decode (mintReturnData, (uint256 ));
221
195
}
@@ -237,19 +211,16 @@ contract ERC20CreatorV3 is IERC721Receiver {
237
211
238
212
// Transfer fee
239
213
if (feeAmount > 0 ) {
240
- feeRecipient.call {value: feeAmount, gas: 100_000 }("" );
214
+ feeRecipient.call { value: feeAmount, gas: 100_000 }("" );
241
215
}
242
216
243
217
// Transfer remaining ETH to the party
244
218
if (address (this ).balance > 0 ) {
245
- payable (party).call {value: address (this ).balance, gas: 100_000 }("" );
219
+ payable (party).call { value: address (this ).balance, gas: 100_000 }("" );
246
220
}
247
221
248
222
FeeRecipient[] memory recipients = new FeeRecipient [](1 );
249
- recipients[0 ] = FeeRecipient ({
250
- recipient: payable (lpFeeRecipient),
251
- percentageBps: 10_000
252
- });
223
+ recipients[0 ] = FeeRecipient ({ recipient: payable (lpFeeRecipient), percentageBps: 10_000 });
253
224
254
225
// Transfer LP to fee collector contract
255
226
UNISWAP_V3_POSITION_MANAGER.safeTransferFrom (
0 commit comments