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: pausable tidy #102

Merged
merged 1 commit into from
Feb 21, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ utils
├─ LibBit — "A library ported from solady for bit twiddling operations"
├─ MerkleProofLib — "Gas optimized merkle proof verification library"
├─ Multicallable — "Enables a single call to call multiple methods within a contract"
├─ Pausable — "An implementation of the Pausable standard"
├─ ReentrancyGuard — "Gas optimized reentrancy protection for smart contracts"
├─ Refunded — "Efficient gas refunds distributed through a modifier"
├─ SafeTransferLib — "Safe ETH and ERC20 transfer library that gracefully handles missing return values"
Expand Down
40 changes: 19 additions & 21 deletions src/utils/Pausable.huff
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,48 @@
#define event Unpaused(address)



// Storage

/// @notice Paused Storage Slot
#define constant PAUSED_SLOT = FREE_STORAGE_POINTER()

/// @notice Unpaused representation
#define constant _UNPAUSED = 0x01
#define constant NOT_PAUSED = 0x01

/// @notice Paused representation
#define constant _PAUSED = 0x02
#define constant PAUSED = 0x02


/// @notice Pausable constructor
#define macro PAUSABLE_CONSTRUCTOR() = takes (0) returns (0) {
[_UNPAUSED] [PAUSED_SLOT] sstore // []
[NOT_PAUSED] [PAUSED_SLOT] sstore // []
}

/// @notice whenNotPaused modifier
#define macro WHEN_NOT_PAUSED_MODIFIER() = takes (0) returns (0) {
[PAUSED_SLOT] sload // [isPaused]
[_UNPAUSED] eq when_not_paused jumpi // []
0x00 dup1 revert // []
when_not_paused: // []
[PAUSED_SLOT] sload // [isPaused]
[NOT_PAUSED] eq when_not_paused jumpi // []
0x00 dup1 revert // []
when_not_paused: // []
}

/// @notice whenPaused modifier
#define macro WHEN_PAUSED_MODIFIER() = takes (0) returns (0) {
[PAUSED_SLOT] sload // [isPaused]
[_PAUSED] eq when_paused jumpi // []
0x00 dup1 revert // []
when_paused: // []
}
[PAUSED_SLOT] sload // [isPaused]
[PAUSED] eq when_paused jumpi // []
0x00 dup1 revert // []
when_paused: // []
}

/// @notice return whether contract is paused
#define macro PAUSABLE_IS_PAUSED() = takes (0) returns (0) {
0x01 // [1]
[PAUSED_SLOT] sload // [isPaused, 1]
sub // [bool]
0x00 mstore // []
0x20 0x00 return // []
0x01 // [1]
[PAUSED_SLOT] sload // [isPaused, 1]
sub // [bool]
0x00 mstore // []
0x20 0x00 return // []
}


/// @notice Pause the contract
#define macro PAUSABLE_PAUSE() = takes (0) returns (0) {
WHEN_NOT_PAUSED_MODIFIER() // []
Expand All @@ -76,7 +74,7 @@
caller __EVENT_HASH(Paused) 0x00 dup1 // [0, 0, EVENT_PAUSED, msg.sender]
log2 // []

[_PAUSED] [PAUSED_SLOT] sstore // []
[PAUSED] [PAUSED_SLOT] sstore // []
stop
}

Expand All @@ -88,6 +86,6 @@
caller __EVENT_HASH(Unpaused) 0x00 dup1 // [0, 0, EVENT_UNPAUSED, msg.sender]
log2 // []

[_UNPAUSED] [PAUSED_SLOT] sstore // []
[NOT_PAUSED] [PAUSED_SLOT] sstore // []
stop
}