Skip to content

Commit 02e4b30

Browse files
authored
feat: add pausable (#10)
* feat: add pausable * refactor: Remove unused imports in IPausableRole * refactor: Tweak to !hasPausableRole[msg.sender]
1 parent ae7b6c3 commit 02e4b30

File tree

56 files changed

+345
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+345
-58
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
143677
1+
143699
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
134868
1+
134890
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
109021
1+
109043
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
298905
1+
298927
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
141089
1+
141133
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
92245
1+
92267
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9201
1+
9179
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
67437
1+
67459
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
150992
1+
151014
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
68616
1+
68638
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
53952
1+
53974
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
968047
1+
968069
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
121561
1+
121583
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
337237
1+
337259
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
56298
1+
56320
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
93040
1+
93084
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
95025
1+
95069
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
74469
1+
74513
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
318945
1+
318967
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
41876
1+
41898
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19493
1+
19515
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
37221
1+
37243
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
37345
1+
37367
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22699
1+
22743
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24243
1+
24265
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8126
1+
8148
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
348452
1+
350592
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
61000
1+
61140
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
241390
1+
243530
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
84138
1+
84302
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
53445
1+
53609
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
36477
1+
36544
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
43322
1+
43462
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
26294
1+
26272
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
30760
1+
30715
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
56445
1+
56609
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
104543
1+
104707
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
25044269
1+
25044433
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
36336
1+
36500
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
103041
1+
103205
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
41986
1+
42150
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
36339
1+
36503
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
19448
1+
19612
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
37427
1+
37494
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
27615
1+
29755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
21897
1+
22061
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
11418
1+
11352

src/Fees.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
// Copyright (C) 2024 PancakeSwap
33
pragma solidity ^0.8.24;
44

5-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
6-
5+
import {PausableRole} from "./PausableRole.sol";
76
import {Currency} from "./types/Currency.sol";
87
import {IProtocolFeeController} from "./interfaces/IProtocolFeeController.sol";
98
import {IFees} from "./interfaces/IFees.sol";
109
import {PoolKey} from "./types/PoolKey.sol";
1110
import {IVault} from "./interfaces/IVault.sol";
1211

13-
abstract contract Fees is IFees, Ownable {
12+
abstract contract Fees is IFees, PausableRole {
1413
uint8 public constant MIN_PROTOCOL_FEE_DENOMINATOR = 4;
1514

1615
mapping(Currency currency => uint256) public protocolFeesAccrued;

src/PausableRole.sol

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
// Copyright (C) 2024 PancakeSwap
3+
pragma solidity ^0.8.24;
4+
5+
import {IPausableRole} from "./interfaces/IPausableRole.sol";
6+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
7+
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
8+
9+
/// @notice Allow owner and multiple accounts to pause but only owner can unpause
10+
/// @dev Potentially allow security partners to programatically pause()
11+
abstract contract PausableRole is IPausableRole, Ownable, Pausable {
12+
mapping(address => bool) public hasPausableRole;
13+
14+
modifier onlyPausableRoleOrOwner() {
15+
if (msg.sender != owner() && !hasPausableRole[msg.sender]) revert NoPausableRole();
16+
_;
17+
}
18+
19+
function pause() public override onlyPausableRoleOrOwner {
20+
_pause();
21+
}
22+
23+
function unpause() public override onlyOwner {
24+
_unpause();
25+
}
26+
27+
function grantPausableRole(address account) public override onlyOwner {
28+
hasPausableRole[account] = true;
29+
emit PausableRoleGranted(account);
30+
}
31+
32+
function revokePausableRole(address account) public override onlyOwner {
33+
hasPausableRole[account] = false;
34+
emit PausableRoleRevoked(account);
35+
}
36+
}

src/interfaces/IPausableRole.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.24;
3+
4+
interface IPausableRole {
5+
/// @notice Thrown when the caller does not have the pausable role or is not owner
6+
error NoPausableRole();
7+
8+
event PausableRoleGranted(address indexed account);
9+
event PausableRoleRevoked(address indexed account);
10+
11+
/// @notice Pause the contract, called by the owner or an account with the pausable role
12+
function pause() external;
13+
14+
/// @notice Unpause the contract, called by the owner
15+
function unpause() external;
16+
17+
/// @notice Grant the pausable role to an account, called by the owner
18+
function grantPausableRole(address account) external;
19+
20+
/// @notice Revoke the pausable role to an account, called by the owner
21+
function revokePausableRole(address account) external;
22+
}

src/pool-cl/CLPoolManager.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
137137
ICLPoolManager.ModifyLiquidityParams memory params,
138138
bytes calldata hookData
139139
) external override poolManagerMatch(address(key.poolManager)) returns (BalanceDelta delta) {
140+
// Do not allow add liquidity when paused()
141+
if (paused() && params.liquidityDelta > 0) revert PoolPaused();
142+
140143
PoolId id = key.toId();
141144
_checkPoolInitialized(id);
142145

@@ -196,6 +199,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
196199
external
197200
override
198201
poolManagerMatch(address(key.poolManager))
202+
whenNotPaused
199203
returns (BalanceDelta delta)
200204
{
201205
PoolId id = key.toId();
@@ -258,6 +262,7 @@ contract CLPoolManager is ICLPoolManager, Fees, Extsload {
258262
external
259263
override
260264
poolManagerMatch(address(key.poolManager))
265+
whenNotPaused
261266
returns (BalanceDelta delta)
262267
{
263268
PoolId id = key.toId();

src/pool-cl/interfaces/ICLPoolManager.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface ICLPoolManager is IFees, IPoolManager, IExtsload {
2121
error TickSpacingTooSmall();
2222
/// @notice Error thrown when Unauthorized caller
2323
error UnauthorizedCaller();
24+
/// @notice Error thrown when add liquidity is called when paused()
25+
error PoolPaused();
2426

2527
/// @notice Emitted when a new pool is initialized
2628
/// @param id The abi encoded hash of the pool key struct for the new pool

test/Extsload.t.sol

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {IProtocolFeeController} from "../src/interfaces/IProtocolFeeController.s
1111

1212
contract ExtsloadTest is Test, GasSnapshot {
1313
// Slot
14-
// 0 PoolManager#Ownable#_owner
15-
// 1 PooAlManager#Fees#protocolFeesAccrued
16-
// 2 PooAlManager#Fees#protocolFeeController
17-
// 3 PooAlManager#pools
14+
// 0 PoolManager#PausableRole#Pausable#_paused and PooAlManager#PausableRole#Ownable#_owner
15+
// 1 PoolManager#PausableRole#hasPausableRole
16+
// 2 PooAlManager#Fees#protocolFeesAccrued
17+
// 3 PooAlManager#Fees#protocolFeeController
18+
// 4 PooAlManager#pools
1819
ICLPoolManager poolManager;
1920

2021
function setUp() public {
@@ -25,19 +26,21 @@ contract ExtsloadTest is Test, GasSnapshot {
2526
}
2627

2728
function testExtsload() public {
29+
// as contract is not paused, slot0 is 0x0...0_owner_address,
30+
// if paused, slot0 is 0x0...1_owner_address
2831
snapStart("ExtsloadTest#extsload");
2932
bytes32 slot0 = poolManager.extsload(0x00);
3033
snapEnd();
3134
assertEq(abi.encode(slot0), abi.encode(address(this)));
3235

33-
bytes32 slot2 = poolManager.extsload(bytes32(uint256(0x02)));
34-
assertEq(abi.encode(slot2), abi.encode(address(0xabcd)));
36+
bytes32 slot3 = poolManager.extsload(bytes32(uint256(0x03)));
37+
assertEq(abi.encode(slot3), abi.encode(address(0xabcd)));
3538
}
3639

3740
function testExtsloadInBatch() public {
3841
bytes32[] memory slots = new bytes32[](2);
3942
slots[0] = 0x00;
40-
slots[1] = bytes32(uint256(0x02));
43+
slots[1] = bytes32(uint256(0x03));
4144
snapStart("ExtsloadTest#extsloadInBatch");
4245
slots = poolManager.extsload(slots);
4346
snapEnd();

0 commit comments

Comments
 (0)