Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reentrancy-no-eth slither warning #67

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions contracts/BNBPartyCreation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ abstract contract BNBPartyCreation is BNBPartySwaps {
/// @param _token Address of the token to be used in the liquidity pool
/// @return liquidityPool Address of the newly created liquidity pool
/// @dev Sets the token amounts based on the balance and initializes the pool
function _createFLP(address _token) internal returns (address liquidityPool) {
function _createFLP(address _token) internal returns (address liquidityPool, uint256 tokenId) {
(address token0, address token1, uint160 sqrtPrice, Ticks memory ticks) = _getTokenPairAndPrice(_token);
// Determine the token amounts
(uint256 amount0, uint256 amount1) = _calculateAmounts(token0);
IERC20(_token).safeIncreaseAllowance(address(BNBPositionManager), party.initialTokenAmount);
liquidityPool = _createLP(
(liquidityPool, tokenId) = _createLP(
BNBPositionManager,
token0,
token1,
Expand All @@ -28,8 +28,6 @@ abstract contract BNBPartyCreation is BNBPartySwaps {
party.partyLpFee,
ticks
);
isParty[liquidityPool] = true; // Mark the liquidity pool as a party pool
isTokenOnPartyLP[_token] = true; // Mark the token as part of the party LP
}

/// @notice Creates a new liquidity pool and mints liquidity positions.
Expand All @@ -51,7 +49,7 @@ abstract contract BNBPartyCreation is BNBPartySwaps {
uint160 sqrtPriceX96,
uint24 fee,
Ticks memory ticks
) internal returns (address liquidityPool) {
) internal returns (address liquidityPool, uint256 tokenId) {
// Create LP
liquidityPool = liquidityManager.createAndInitializePoolIfNecessary(
token0,
Expand All @@ -61,7 +59,7 @@ abstract contract BNBPartyCreation is BNBPartySwaps {
);

// Mint LP
(lpToTokenId[liquidityPool], , , ) = liquidityManager.mint(
(tokenId, , , ) = liquidityManager.mint(
INonfungiblePositionManager.MintParams({
token0: token0,
token1: token1,
Expand Down
10 changes: 7 additions & 3 deletions contracts/BNBPartyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard, BNBPartyManageab
// Create new token
newToken = new ERC20Token(name, symbol, party.initialTokenAmount);
// Create First Liquidity Pool
address liquidityPool = _createFLP(address(newToken));
lpToCreator[liquidityPool] = msg.sender;
(address liquidityPool, uint256 tokenId) = _createFLP(address(newToken));
lpToCreator[liquidityPool] = msg.sender; // Set the creator of the liquidity pool
lpToTokenId[liquidityPool] = tokenId; // Set the token ID of the liquidity pool
isParty[liquidityPool] = true; // Mark the liquidity pool as a party pool
isTokenOnPartyLP[address(newToken)] = true; // Mark the token as part of the party LP
if (msg.value > party.createTokenFee) {
_executeSwap(address(newToken));
}
Expand All @@ -65,7 +68,8 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard, BNBPartyManageab

if (WBNBBalance - feesEarned < party.partyTarget) return;
// Handle liquidity
_handleLiquidity(recipient);
(address liquidityPool, uint256 tokenId) = _handleLiquidity(recipient);
lpToTokenId[liquidityPool] = tokenId;
}

/// @notice Allows users to join the party by swapping BNB for the specified token
Expand Down
4 changes: 2 additions & 2 deletions contracts/BNBPartyLiquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract contract BNBPartyLiquidity is BNBPartyLiquidityHelper {
/// @notice Handles liquidity by decreasing the liquidity, collecting tokens, and creating a new liquidity pool.
/// @param recipient Address receiving the bonus BNB
/// @dev Decreases liquidity, collects tokens, creates a new pool, and sends bonuses
function _handleLiquidity(address recipient) internal {
function _handleLiquidity(address recipient) internal returns (address liquidityPool, uint256 tokenId){
IUniswapV3Pool pool = IUniswapV3Pool(msg.sender);
(uint160 sqrtPriceX96, , , , , , ) = pool.slot0();
address token0 = pool.token0();
Expand Down Expand Up @@ -47,7 +47,7 @@ abstract contract BNBPartyLiquidity is BNBPartyLiquidityHelper {
IERC20(token0).safeIncreaseAllowance(address(positionManager), amount0);
IERC20(token1).safeIncreaseAllowance(address(positionManager), amount1);
// Create new Liquidity Pool
_createLP(positionManager, token0, token1, amount0, amount1, newSqrtPriceX96, party.lpFee, _getTicks(token0, party.lpTicks));
(liquidityPool, tokenId) = _createLP(positionManager, token0, token1, amount0, amount1, newSqrtPriceX96, party.lpFee, _getTicks(token0, party.lpTicks));

// Send bonuses
_unwrapAndSendBNB(recipient, unwrapAmount);
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const LOW_OPTIMIZER_COMPILER_SETTINGS = {
}

const BNB_FACTORY_COMPILER_SETTINGS = {
version: "0.8.25",
version: "0.8.26",
settings: {
evmVersion: "istanbul",
optimizer: {
Expand Down