Skip to content

Commit 1314cc1

Browse files
Merge pull request #78 from bnb-party/issue-75
use internal `modifiers` for `constructor`
2 parents 1766100 + 11ebe2b commit 1314cc1

5 files changed

+39
-40
lines changed

contracts/BNBPartyFactory.sol

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard, BNBPartyManageab
3737
payable
3838
override
3939
nonReentrant
40-
insufficientBNB
40+
insufficientBNB(party.createTokenFee)
4141
whenNotPaused
4242
notZeroAddress(address(BNBPositionManager))
4343
returns (IERC20 newToken)
@@ -58,7 +58,8 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard, BNBPartyManageab
5858

5959
/// @notice Handles token swaps for the liquidity pool
6060
/// @param recipient The address of the entity making the exchange
61-
function handleSwap(address recipient) external override onlyParty notZeroAddress(recipient) whenNotPaused {
61+
function handleSwap(address recipient) external override notZeroAddress(recipient) whenNotPaused {
62+
if (!isParty[msg.sender]) revert LPNotAtParty(); // Reverts if the LP is not part of a party
6263
IUniswapV3Pool pool = IUniswapV3Pool(msg.sender);
6364

6465
uint256 WBNBBalance = WBNB.balanceOf(msg.sender);

contracts/BNBPartyFee.sol

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

4-
import "./BNBPartyModifiers.sol";
4+
import "./BNBPartyState.sol";
55
import "./interfaces/IUniswapV3Pool.sol";
66

77
/// @title BNBPartyFee
88
/// @notice This abstract contract provides internal functions for calculating fees in the BNB Party system.
9-
abstract contract BNBPartyFee is BNBPartyModifiers {
9+
abstract contract BNBPartyFee is BNBPartyState {
1010
/// @notice Internal function to retrieve the fee growth inside the position from the last observation
1111
/// @param pool Address of the Uniswap V3 pool
1212
/// @return feeGrowthInside0LastX128 Fee growth inside for token0 from the last observation

contracts/BNBPartyManageable.sol

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

4-
import "./BNBPartyModifiers.sol";
4+
import "./BNBPartyFee.sol";
55
import "@openzeppelin/contracts/utils/Pausable.sol";
66

77
/// @title BNBPartyManageable
88
/// @notice This abstract contract provides management functions for setting position managers, swap routers, and withdrawing fees in the BNBParty system.
9-
abstract contract BNBPartyManageable is BNBPartyModifiers, Pausable {
9+
abstract contract BNBPartyManageable is BNBPartyFee, Pausable {
1010
/// @notice Sets the non-fungible position managers for BNB Party and Pancakeswap V3
1111
/// @param _BNBPositionManager Address of the new BNB Party non-fungible position manager
1212
/// @param _positionManager Address of the new Pancakeswap V3 non-fungible position manager

contracts/BNBPartyModifiers.sol

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

4-
import "./BNBPartyState.sol";
4+
import "./interfaces/IBNBPartyFactory.sol";
5+
import "@bnb-party/v3-periphery/contracts/interfaces/ISwapRouter.sol";
56

67
/// @title BNBPartyModifiers
78
/// @notice This abstract contract provides various modifiers used in the BNBParty system to enforce conditions on function calls.
8-
abstract contract BNBPartyModifiers is BNBPartyState {
9-
/// @notice Restricts function access to liquidity pools that are part of a party
10-
/// @dev Reverts if the caller is not a registered party liquidity pool
11-
modifier onlyParty() {
12-
if (!isParty[msg.sender]) revert LPNotAtParty();
13-
_;
14-
}
15-
9+
abstract contract BNBPartyModifiers is IBNBPartyFactory{
1610
/// @notice Ensures the provided address is not a zero address
1711
/// @param _address Address to be checked
1812
/// @dev Reverts if the address is zero
@@ -23,8 +17,8 @@ abstract contract BNBPartyModifiers is BNBPartyState {
2317

2418
/// @notice Ensures the amount of BNB sent is sufficient to cover the token creation fee
2519
/// @dev Reverts if the sent BNB is less than the required fee
26-
modifier insufficientBNB() {
27-
if (msg.value < party.createTokenFee) revert InsufficientBNB();
20+
modifier insufficientBNB(uint256 fee) {
21+
if (msg.value < fee) revert InsufficientBNB();
2822
_;
2923
}
3024

contracts/BNBPartyState.sol

+27-23
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
pragma solidity ^0.8.0;
33

44
import "@openzeppelin/contracts/access/Ownable.sol";
5-
import "@bnb-party/v3-periphery/contracts/interfaces/ISwapRouter.sol";
65
import "./interfaces/ISqrtPriceCalculator.sol";
76
import "./interfaces/INonfungiblePositionManager.sol";
8-
import "./interfaces/IBNBPartyFactory.sol";
97
import "./interfaces/IWBNB.sol";
8+
import "./BNBPartyModifiers.sol";
109

1110
/// @title BNBPartyState
1211
/// @notice This abstract contract handles the state variables and initial setup for the BNBParty system.
13-
abstract contract BNBPartyState is IBNBPartyFactory, Ownable {
12+
abstract contract BNBPartyState is BNBPartyModifiers, Ownable {
1413
INonfungiblePositionManager public BNBPositionManager; // BNB Party position manager
1514
INonfungiblePositionManager public positionManager; // Default Pancakeswap V3 position manager
1615
ISwapRouter public BNBSwapRouter; // V3 swap router
@@ -19,7 +18,7 @@ abstract contract BNBPartyState is IBNBPartyFactory, Ownable {
1918
mapping(address => uint256) public lpToTokenId; // Mapping from LiquidityPool to its NFT tokenId
2019
mapping(address => address) public lpToCreator; // Mapping from LiquidityPool to its creator
2120
mapping(address => bool) public isTokenOnPartyLP; // Mapping to track if a token is part of a party
22-
uint256 constant FEE_GROWTH_GLOBAL_SCALE = 2**128;
21+
uint256 constant FEE_GROWTH_GLOBAL_SCALE = 2 ** 128;
2322

2423
Party public party; // store party parameters
2524

@@ -29,27 +28,32 @@ abstract contract BNBPartyState is IBNBPartyFactory, Ownable {
2928
/// @notice Constructor to initialize the BNBPartyState contract
3029
/// @param _party Struct containing party parameters
3130
/// @param _WBNB Address of the Wrapped BNB token contract
32-
constructor(Party memory _party, IWBNB _WBNB, ISqrtPriceCalculator _sqrtPriceCalculator) Ownable(_msgSender()) {
33-
if (address(_WBNB) == address(0)) {
34-
revert ZeroAddress(); // Reverts if the WBNB address is zero
35-
}
36-
if(address(_sqrtPriceCalculator) == address(0)) {
37-
revert ZeroAddress(); // Reverts if the sqrt price calculator address is zero
38-
}
39-
if (_party.partyTarget == 0) {
40-
revert ZeroAmount(); // Reverts if the party target is zero
41-
}
42-
if (_party.initialTokenAmount == 0) {
43-
revert ZeroAmount(); // Reverts if the initial token amount is zero
44-
}
45-
if (_party.partyTarget <= (_party.bonusPartyCreator + _party.bonusTargetReach + _party.targetReachFee)) {
46-
revert BonusGreaterThanTarget(); // Reverts if the party target is less than or equal to the sum of bonuses and fees
47-
}
48-
if (_party.sqrtPriceX96 == 0) {
49-
revert ZeroAmount(); // Reverts if the sqrt price is zero
50-
}
31+
constructor(
32+
Party memory _party,
33+
IWBNB _WBNB,
34+
ISqrtPriceCalculator _sqrtPriceCalculator
35+
) Ownable(_msgSender()) {
36+
_constructorValidation(_party, _WBNB, _sqrtPriceCalculator);
5137
party = _party;
5238
WBNB = _WBNB;
5339
sqrtPriceCalculator = _sqrtPriceCalculator;
5440
}
41+
42+
function _constructorValidation(
43+
Party memory _party,
44+
IWBNB _WBNB,
45+
ISqrtPriceCalculator _sqrtPriceCalculator
46+
)
47+
private
48+
pure
49+
notZeroAddress(address(_WBNB))
50+
notZeroAddress(address(_sqrtPriceCalculator))
51+
notZeroAmount(_party.partyTarget)
52+
notZeroAmount(_party.initialTokenAmount)
53+
notZeroAmount(_party.sqrtPriceX96)
54+
{
55+
if (_party.partyTarget <= (_party.bonusPartyCreator + _party.bonusTargetReach + _party.targetReachFee)) {
56+
revert BonusGreaterThanTarget(); // Reverts if the party target is less than or equal to the sum of bonuses and fees
57+
}
58+
}
5559
}

0 commit comments

Comments
 (0)