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

add Pausable #58

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion contracts/BNBPartyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard, BNBPartyManageab
override
nonReentrant
insufficientBNB
whenNotPaused
notZeroAddress(address(BNBPositionManager))
returns (IERC20 newToken)
{
Expand All @@ -54,7 +55,7 @@ contract BNBPartyFactory is BNBPartyLiquidity, ReentrancyGuard, BNBPartyManageab

/// @notice Handles token swaps for the liquidity pool
/// @param recipient The address of the entity making the exchange
function handleSwap(address recipient) external override onlyParty notZeroAddress(recipient) {
function handleSwap(address recipient) external override onlyParty notZeroAddress(recipient) whenNotPaused {
IUniswapV3Pool pool = IUniswapV3Pool(msg.sender);

uint256 WBNBBalance = WBNB.balanceOf(msg.sender);
Expand Down
13 changes: 12 additions & 1 deletion contracts/BNBPartyManageable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
pragma solidity ^0.8.0;

import "./BNBPartyModifiers.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";

/// @title BNBPartyManageable
/// @notice This abstract contract provides management functions for setting position managers, swap routers, and withdrawing fees in the BNBParty system.
abstract contract BNBPartyManageable is BNBPartyModifiers {
abstract contract BNBPartyManageable is BNBPartyModifiers, Pausable {
/// @notice Sets the non-fungible position managers for BNB Party and Pancakeswap V3
/// @param _BNBPositionManager Address of the new BNB Party non-fungible position manager
/// @param _positionManager Address of the new Pancakeswap V3 non-fungible position manager
Expand Down Expand Up @@ -59,6 +60,16 @@ abstract contract BNBPartyManageable is BNBPartyModifiers {
_withdrawLPFees(liquidityPools, positionManager);
}

/// @notice Pauses the contract
function pause() external onlyOwner {
_pause();
}

/// @notice Unpauses the contract
function unpause() external onlyOwner {
_unpause();
}

/// @notice Internal function to withdraw LP fees from specified liquidity pools
/// @param liquidityPools Array of liquidity pool addresses from which fees will be withdrawn
/// @param manager The non-fungible position manager used to collect fees
Expand Down
35 changes: 34 additions & 1 deletion test/BNBPartyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,39 @@ describe("BNBPartyFactory", function () {
await bnbPartyFactory.setBNBPartySwapRouter(await BNBSwapRouter.getAddress())
})

it("should set pause", async function () {
await bnbPartyFactory.pause()
expect(await bnbPartyFactory.paused()).to.be.true
await bnbPartyFactory.unpause()
})

it("should unpause", async function () {
await bnbPartyFactory.pause()
await bnbPartyFactory.unpause()
expect(await bnbPartyFactory.paused()).to.be.false
})

it("should revert party creation if paused", async function () {
await bnbPartyFactory.pause()
await expect(
bnbPartyFactory.createParty(name, symbol, { value: tokenCreationFee })
).to.be.revertedWithCustomError(bnbPartyFactory, "EnforcedPause")
await bnbPartyFactory.unpause()
})

it("should revert join party if paused", async function () {
await bnbPartyFactory.createParty(name, symbol, { value: tokenCreationFee })
await bnbPartyFactory.pause()
const tokenId = (await BNBPositionManager.totalSupply()) - 1n
const position = await BNBPositionManager.positions(tokenId)
const MEME = position.token1 == (await weth9.getAddress()) ? position.token0 : position.token1
await expect(bnbPartyFactory.joinParty(MEME, 0, { value: BNBToTarget })).to.be.revertedWithCustomError(
bnbPartyFactory,
"EnforcedPause"
)
await bnbPartyFactory.unpause()
})

describe("Second Liquidity Pool", function () {
let MEME: string
let tokenId: string
Expand Down Expand Up @@ -148,7 +181,7 @@ describe("BNBPartyFactory", function () {
const lpAddress = await v3Factory.getPool(await weth9.getAddress(), MEME, FeeAmount.HIGH)
const balance = await weth9.balanceOf(lpAddress)
const percentFee = ethers.parseEther("0.14") // target 13 + 1 BNB - 1% fee
expect(balance).to.be.equal(BNBToTarget - returnFeeAmount - bonusFee - targetReachFee - percentFee - 1n)
expect(balance).to.be.equal(BNBToTarget - returnFeeAmount - bonusFee - targetReachFee - percentFee - 2n)
})

it("should send MEME to new LP", async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/WithdrawFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("Withdraw fees", function () {
const lpPool = (await ethers.getContractAt("UniswapV3Pool", lpAddress)) as any as IUniswapV3Pool
const liquidity = await lpPool.liquidity()
const feeGrowthGlobalX128 = await lpPool.feeGrowthGlobal1X128() > 0 ? await lpPool.feeGrowthGlobal1X128() : await lpPool.feeGrowthGlobal0X128()
expect(await bnbPartyFactory.calculateFees(liquidity, feeGrowthGlobalX128)).to.be.equal(amountIn / 100n) // 1 % fee
expect(await bnbPartyFactory.calculateFees(liquidity, feeGrowthGlobalX128)).to.be.equal(amountIn / 100n - 1n) // 1 % fee
})

it("calculateFees should return fee from 5 swaps", async () => {
Expand All @@ -102,8 +102,8 @@ describe("Withdraw fees", function () {
expect(await bnbPartyFactory.calculateFees(liquidity, feeGrowthGlobalX128)).to.be.equal(amountIn / 20n) // 1 % fee
})

it("isToken0WBNB should return false if token0 is not WBNB", async () => {
expect(await bnbPartyFactory.isToken0WBNB(lpAddress)).to.be.false
it("isToken0WBNB should return true if token0 is WBNB", async () => {
expect(await bnbPartyFactory.isToken0WBNB(lpAddress)).to.be.true
})

it("isToken0WBNB should revert if set zero address", async () => {
Expand Down