Skip to content

Commit

Permalink
add token LP party validation
Browse files Browse the repository at this point in the history
  • Loading branch information
YouStillAlive committed Sep 24, 2024
1 parent 83442bd commit d606500
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions contracts/BNBPartyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.0;

import "./token/ERC20Token.sol";
import "./BNBPartyLiquidity.sol";
import "./interfaces/IUniswapV3Factory.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@bnb-party/v3-periphery/contracts/interfaces/IPeripheryPayments.sol";
Expand Down Expand Up @@ -79,6 +80,7 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard {
address tokenOut,
uint256 amountOutMinimum
) external payable notZeroAddress(tokenOut) notZeroValue {
_tokenValidation(tokenOut);
(ISwapRouter router, uint24 fee) = _getRouterAndFee(tokenOut);
ISwapRouter.ExactInputParams memory params = ISwapRouter
.ExactInputParams({
Expand All @@ -100,6 +102,7 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard {
uint256 amountIn,
uint256 amountOutMinimum
) external notZeroAddress(tokenIn) notZeroAmount(amountIn) {
_tokenValidation(tokenIn);
IERC20(tokenIn).safeTransferFrom(msg.sender, address(this), amountIn);
(ISwapRouter router, uint24 fee) = _getRouterAndFee(tokenIn);
IERC20(tokenIn).safeIncreaseAllowance(address(router), amountIn);
Expand All @@ -115,4 +118,10 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard {
_executeSwap(router, params);
IPeripheryPayments(address(router)).unwrapWETH9(amountOutMinimum, msg.sender);
}

function _tokenValidation(address token) internal view {
address factory = INonfungiblePositionManager(BNBPositionManager).factory();
address pool = IUniswapV3Factory(factory).getPool(token, address(WBNB), party.partyLpFee);// getPool implements position checking by itself
if (!isParty[pool]) revert LPNotAtParty();
}
}
3 changes: 3 additions & 0 deletions contracts/interfaces/INonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,7 @@ interface INonfungiblePositionManager is IPoolInitializer {
function burn(uint256 tokenId) external payable;

function WETH9() external view returns (address);

///@notice Returns the address of the v3-factory
function factory() external view returns (address);
}
18 changes: 18 additions & 0 deletions contracts/interfaces/IUniswapV3Factory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
}

0 comments on commit d606500

Please sign in to comment.