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

Pausable contracts #311

Merged
merged 23 commits into from
Apr 4, 2024
Merged

Pausable contracts #311

merged 23 commits into from
Apr 4, 2024

Conversation

r-czajkowski
Copy link
Contributor

@r-czajkowski r-czajkowski commented Mar 11, 2024

Depends on: #308
Closes: #170

This PR adds support for the emergency stop mechanism for stBTC contract by implementing the PausableUpgradeable contract from Open Zeppelin library.

What has been done

PausableOwnable contract

Extract common logic for the emergency stop mechanism by creating the PausableOwnable contract. It inherits the PausableUpgradeable and Ownable2StepUpgradeablecontracts from Open Zeppelin library. We assume that the Pausable contract will always be Ownable as well. The emergency stop mechanism can be triggered by an authorized account and it can be different than the owner account. Only owner of the contract can update the emergency stop account.

Make the stBTC contract pausable

Make the stBTC contract pausable by inheriting the PausableOwnable contract that provides the emergency stop mechanism. Functions that move funds should be pausble:

  • deposit and mint,
  • withdraw and redeem.

Other

  • Extract common errors (currently only ZeroAddress) to a separate file Errors.sol so we can reuse errors in the other contracts.

Implement an emergency stop mechanism that can be triggered by an
authorized account. In stBTC contract we should pause deposits and
withdrawals.
Implement an emergency stop mechanism that can be triggered by an
authorized account. In `AcreBitcoinDepositor` contract we should pause
staking finalization and unstaking in the future.
@r-czajkowski r-czajkowski added the 🔗 Solidity Solidity contracts label Mar 11, 2024
@r-czajkowski r-czajkowski requested review from dimpar and nkuba March 11, 2024 15:25
@r-czajkowski r-czajkowski self-assigned this Mar 11, 2024
@r-czajkowski r-czajkowski changed the base branch from main to upgradeable-contracts March 11, 2024 15:25
Copy link

netlify bot commented Mar 11, 2024

Deploy Preview for acre-dapp-testnet canceled.

Name Link
🔨 Latest commit 349af5d
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/660e8e0d141c6400080bed2c

Base automatically changed from upgradeable-contracts to main March 13, 2024 15:25
This error could be useful in other contracts so we extract it to a
separate file `Errors.sol` so we can reuse it across other contracts. To
avoid duplicating code, other common errors should be included here.
This abstract contract extracts a common part of the emergency stop
mechanism. The emergency stop mechanism can be triggered by an
authorized account. Only owner of the contract can update the emergency
stop account. The child contract must override the `_checkOwner`
internal function that checks if the caller is an owner of contract and
throws an error if the sender is not the owner.
Inherit the emergency stop mechanism from `AbstractPausable` contract
and override correctly the `_checkOwner` function.
Inherit the emergency stop mechanism from `AbstractPausable` contract
and override correctly the `_checkOwner` function.
@r-czajkowski r-czajkowski marked this pull request as ready for review March 14, 2024 08:01
core/contracts/AcreBitcoinDepositor.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
The staking flow can be paused by `stBTC.deposit` function pausing.
`emergencyStopAccount` -> `pauseAdmin`
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/test/stBTC.test.ts Outdated Show resolved Hide resolved
Fix the test scenario when the owner calls `unpause` function - the
caller should be an owner (in our case it's a `governance` account).
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
core/contracts/AbstractPausable.sol Outdated Show resolved Hide resolved
Variable name should be camel cased.
`NotAuthorizedAccount` -> `PausableUnauthorizedAccount`. To align with
`OwnableUnauthorizedAccount` thrown from the `Ownable` contract.
Remove the `isOwner` function and the `_onlyOwner` modifier as they were
only used in one place. There may also be a name collision with the
`Ownable` contract from the OZ library because it also defines the
`onlyOwner` modifier, so it may be confusing when and which modifier
should be used in the child contract.
The init functions are here to replace the constructor, so we should
place them in the place we define the constructor.
@r-czajkowski r-czajkowski requested a review from nkuba March 18, 2024 17:42
@r-czajkowski r-czajkowski requested a review from dimpar March 18, 2024 17:42
r-czajkowski and others added 2 commits March 18, 2024 20:13
Inherit the `Ownable2StepUpgradeable` contract because we can assume the
`Pausable` contract will always by `Ownable` as well.
nkuba
nkuba previously approved these changes Apr 4, 2024
@nkuba
Copy link
Member

nkuba commented Apr 4, 2024

@r-czajkowski I let myself update this PR. Please take a look, and if you're fine with the proposed changes I'll merge the PR.

@r-czajkowski
Copy link
Contributor Author

@r-czajkowski I let myself update this PR. Please take a look, and if you're fine with the proposed changes I'll merge the PR.

Thanks! Everything looks good! :shipit:

@nkuba nkuba enabled auto-merge April 4, 2024 11:37
@nkuba nkuba merged commit 326d35d into main Apr 4, 2024
24 checks passed
@nkuba nkuba deleted the pausable-contracts branch April 4, 2024 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔗 Solidity Solidity contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make contracts pausable
3 participants