Skip to content

Commit a957934

Browse files
authored
add lint and format files (#28)
1 parent 1e69fb9 commit a957934

22 files changed

+262
-532
lines changed

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
- name: Install Dependencies
2323
run: yarn install
2424

25+
- name: Run lint
26+
run: yarn lint:check
27+
2528
- name: Install Foundry
2629
uses: foundry-rs/foundry-toolchain@v1
2730
with:
@@ -32,6 +35,6 @@ jobs:
3235

3336
- name: Run tests
3437
run: forge test -vvv --evm-version shanghai --fork-url ${{ secrets.SEPOLIA_FORK_URL }}
35-
38+
3639
- name: Upload Selectors
3740
run: forge selectors upload --all

.prettierignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build
2+
cache
3+
out
4+
lib
5+
node_modules
6+
artifacts
7+
etherscan.json
8+
.vscode

.prettierrc.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins: ["prettier-plugin-solidity"]
2+
arrowParens: "avoid"
3+
bracketSpacing: true
4+
endOfLine: "auto"
5+
printWidth: 100
6+
singleQuote: false
7+
tabWidth: 2
8+
trailingComma: "all"
9+
10+
overrides:
11+
- files: ["*.sol", "*.t.sol"]
12+
options:
13+
tabWidth: 4
14+
parser: "solidity-parse"

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Click "Use this template" on [GitHub](https://github.com/foundry-rs/forge-template) to create a new repository with this repo as the initial state.
1010

1111
Or, if your repo already exists, run:
12+
1213
```sh
1314
forge init
1415
forge build
@@ -25,12 +26,12 @@ pragma solidity 0.8.10;
2526
import "forge-std/Test.sol";
2627
2728
contract ContractTest is Test {
28-
function testExample() public {
29-
vm.roll(100);
30-
console.log(1);
31-
emit log("hi");
32-
assertTrue(true);
33-
}
29+
function testExample() public {
30+
vm.roll(100);
31+
console.log(1);
32+
emit log("hi");
33+
assertTrue(true);
34+
}
3435
}
3536
```
3637

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"devDependencies": {
3+
"prettier": "^3.2.5",
4+
"prettier-plugin-solidity": "^1.3.1"
5+
},
6+
"scripts": {
7+
"lint:fix": "prettier --write .",
8+
"lint:check": "prettier --check ."
9+
}
10+
}

src/ERC20Creator.sol

+7-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
44
import "../lib/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
55
import "../lib/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
66
import "party-protocol/contracts/distribution/ITokenDistributor.sol";
7-
import {GovernableERC20, ERC20} from "./GovernableERC20.sol";
7+
import { GovernableERC20, ERC20 } from "./GovernableERC20.sol";
88

99
contract ERC20Creator {
1010
event ERC20Created(
@@ -17,14 +17,8 @@ contract ERC20Creator {
1717
TokenConfiguration config
1818
);
1919

20-
event FeeRecipientUpdated(
21-
address indexed oldFeeRecipient,
22-
address indexed newFeeRecipient
23-
);
24-
event FeeBasisPointsUpdated(
25-
uint16 oldFeeBasisPoints,
26-
uint16 newFeeBasisPoints
27-
);
20+
event FeeRecipientUpdated(address indexed oldFeeRecipient, address indexed newFeeRecipient);
21+
event FeeBasisPointsUpdated(uint16 oldFeeBasisPoints, uint16 newFeeBasisPoints);
2822

2923
error InvalidFeeBasisPoints();
3024
error InvalidTokenDistribution();
@@ -80,19 +74,11 @@ contract ERC20Creator {
8074
}
8175

8276
// Create token
83-
token = new GovernableERC20(
84-
name,
85-
symbol,
86-
config.totalSupply,
87-
address(this)
88-
);
77+
token = new GovernableERC20(name, symbol, config.totalSupply, address(this));
8978

9079
if (config.numTokensForDistribution > 0) {
9180
// Create distribution
92-
token.transfer(
93-
address(TOKEN_DISTRIBUTOR),
94-
config.numTokensForDistribution
95-
);
81+
token.transfer(address(TOKEN_DISTRIBUTOR), config.numTokensForDistribution);
9682
TOKEN_DISTRIBUTOR.createErc20Distribution(
9783
IERC20(address(token)),
9884
Party(payable(partyAddress)),
@@ -108,7 +94,7 @@ contract ERC20Creator {
10894
// Create locked LP pair
10995
uint256 numETHForLP = ethValue - feeAmount;
11096
token.approve(address(UNISWAP_V2_ROUTER), config.numTokensForLP);
111-
UNISWAP_V2_ROUTER.addLiquidityETH{value: numETHForLP}(
97+
UNISWAP_V2_ROUTER.addLiquidityETH{ value: numETHForLP }(
11298
address(token),
11399
config.numTokensForLP,
114100
config.numTokensForLP,
@@ -121,7 +107,7 @@ contract ERC20Creator {
121107
token.transfer(recipientAddress, config.numTokensForRecipient);
122108

123109
// Send fee
124-
feeRecipient.call{value: feeAmount, gas: 100_000}("");
110+
feeRecipient.call{ value: feeAmount, gas: 100_000 }("");
125111

126112
emit ERC20Created(
127113
address(token),

src/ERC20CreatorV3.sol

+24-53
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.0;
33

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";
1313

1414
contract ERC20CreatorV3 is IERC721Receiver {
1515
struct TokenDistributionConfiguration {
@@ -29,15 +29,9 @@ contract ERC20CreatorV3 is IERC721Receiver {
2929
TokenDistributionConfiguration config
3030
);
3131

32-
event FeeRecipientUpdated(
33-
address indexed oldFeeRecipient,
34-
address indexed newFeeRecipient
35-
);
32+
event FeeRecipientUpdated(address indexed oldFeeRecipient, address indexed newFeeRecipient);
3633

37-
event FeeBasisPointsUpdated(
38-
uint16 oldFeeBasisPoints,
39-
uint16 newFeeBasisPoints
40-
);
34+
event FeeBasisPointsUpdated(uint16 oldFeeBasisPoints, uint16 newFeeBasisPoints);
4135

4236
error InvalidTokenDistribution();
4337
error OnlyFeeRecipient();
@@ -84,8 +78,7 @@ contract ERC20CreatorV3 is IERC721Receiver {
8478
uint16 feeBasisPoints_,
8579
uint16 poolFee
8680
) {
87-
if (poolFee != 500 && poolFee != 3000 && poolFee != 10_000)
88-
revert InvalidPoolFee();
81+
if (poolFee != 500 && poolFee != 3000 && poolFee != 10_000) revert InvalidPoolFee();
8982
if (feeBasisPoints_ > 5e3) revert InvalidFeeBasisPoints();
9083

9184
TOKEN_DISTRIBUTOR = tokenDistributor;
@@ -99,9 +92,7 @@ contract ERC20CreatorV3 is IERC721Receiver {
9992

10093
int24 tickSpacing = UNISWAP_V3_FACTORY.feeAmountTickSpacing(POOL_FEE);
10194
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;
10596
}
10697

10798
/// @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 {
137128
IERC20 token = IERC20(
138129
address(
139130
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))
143132
}(name, symbol, config.totalSupply, address(this))
144133
)
145134
);
146135

147136
if (config.numTokensForDistribution > 0) {
148137
// Create distribution
149-
token.transfer(
150-
address(TOKEN_DISTRIBUTOR),
151-
config.numTokensForDistribution
152-
);
138+
token.transfer(address(TOKEN_DISTRIBUTOR), config.numTokensForDistribution);
153139
TOKEN_DISTRIBUTOR.createErc20Distribution(
154140
token,
155141
Party(payable(party)),
@@ -173,22 +159,13 @@ contract ERC20CreatorV3 is IERC721Receiver {
173159
: (config.numTokensForLP, msg.value - feeAmount);
174160

175161
// 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);
181163

182164
// 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);
186166
IUniswapV3Pool(pool).initialize(sqrtPriceX96);
187167

188-
token.approve(
189-
address(UNISWAP_V3_POSITION_MANAGER),
190-
config.numTokensForLP
191-
);
168+
token.approve(address(UNISWAP_V3_POSITION_MANAGER), config.numTokensForLP);
192169

193170
// Use multicall to sweep back excess ETH
194171
bytes[] memory calls = new bytes[](2);
@@ -210,12 +187,9 @@ contract ERC20CreatorV3 is IERC721Receiver {
210187
})
211188
)
212189
);
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];
219193

220194
lpTokenId = abi.decode(mintReturnData, (uint256));
221195
}
@@ -237,19 +211,16 @@ contract ERC20CreatorV3 is IERC721Receiver {
237211

238212
// Transfer fee
239213
if (feeAmount > 0) {
240-
feeRecipient.call{value: feeAmount, gas: 100_000}("");
214+
feeRecipient.call{ value: feeAmount, gas: 100_000 }("");
241215
}
242216

243217
// Transfer remaining ETH to the party
244218
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 }("");
246220
}
247221

248222
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 });
253224

254225
// Transfer LP to fee collector contract
255226
UNISWAP_V3_POSITION_MANAGER.safeTransferFrom(

0 commit comments

Comments
 (0)