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

Bitcoin Redeemer implementation #335

Merged
merged 26 commits into from
Apr 9, 2024
Merged

Bitcoin Redeemer implementation #335

merged 26 commits into from
Apr 9, 2024

Conversation

nkuba
Copy link
Member

@nkuba nkuba commented Apr 3, 2024

Closes: #159

In this PR we integrate the withdrawal of tBTC from stBTC vault with tBTC Bridge redemption, so the user can withdraw directly to Bitcoin in one transaction.

For the Bitcoin-only experience, it is expected that the owner of the stake will be Safe with Bitcoin message signatures verification capability as per https://github.com/thesis/orangekit/tree/main/solidity.

This implementation is different from the initial implementation in #309 as we removed ERC20 permits to handle withdrawals, as dApp users will produce Bitcoin signatures for the Safe, not the EIP-712 Ethereum signatures.

nkuba added 10 commits April 3, 2024 21:14
The contract is used to integrate stBTC unstaking with bridging to
Bitcoin via tBTC Bridge.

The `requestRedemption` function expects the owner of stBTC shares to
approve stBTC token shares to the BticoinRedeemer contract. Then when
`requestRedemption` function is called it redeems stBTC and calls
TBTC token contract to redeem tBTC to Bitcoin.
The event is emitted after stbtc.redeem call, but we control the stBTC
contract, so there is no risk.
We use the wrapper in tests instead the snapshots, so we want to be
consistent.
For consistency with BitcoinRedeemerUpdated and DispatcherUpdated we
added old treasury address in the event.
This function name should better describe what is happening inside.
Instead of requiring the user to approve and request redemption in two
transactions we use approveAndCall pattern to cover it within one
transaction.
@nkuba nkuba requested a review from dimpar April 3, 2024 19:35
Copy link

netlify bot commented Apr 3, 2024

Deploy Preview for acre-dapp-testnet ready!

Name Link
🔨 Latest commit d59a027
🔍 Latest deploy log https://app.netlify.com/sites/acre-dapp-testnet/deploys/661517585f78a00008c1ef79
😎 Deploy Preview https://deploy-preview-335--acre-dapp-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

We use @thesis-co/solidity-contracts in BitcoinRedeemer for receive
approval interfaces.
@nkuba nkuba requested review from pdyraga and lukasz-zimnoch April 3, 2024 19:58
@nkuba nkuba self-assigned this Apr 3, 2024
@nkuba nkuba added the 🔗 Solidity Solidity contracts label Apr 4, 2024
nkuba added 6 commits April 4, 2024 10:47
The package is named: `@thesis-co/solidity-contracts` in its
package.json file. To reduce confusion we match the name here.
Slither is reporting:
```
stBTC (contracts/stBTC.sol#24-365) should inherit from ITBTCToken (contracts/bridge/ITBTCToken.sol#7-25)
Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#missing-inheritance
```

The stBTC contract shouldn't inherit from ITBTCToken contract.
lukasz-zimnoch
lukasz-zimnoch previously approved these changes Apr 4, 2024
Copy link
Member

@lukasz-zimnoch lukasz-zimnoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Leaving final approval for @pdyraga and @dimpar

function redeemSharesAndUnmint(
address owner,
uint256 shares,
bytes calldata tbtcRedemptionData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the redeemer is set to the sBTC owner address, I believe this ~solves the problem of potential redemption timeouts. sBTC owner will be able to claim Bank balance in tBTC bridge. Not ideal UX but something.

Copy link
Member Author

@nkuba nkuba Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it should be enforced on-chain or it's enough for the SDK to prepare the redemption data correctly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is enough to have it handled in the SDK but I would also make it very clear in the documentation of the redeemSharesAndUnmint function. This is absolutely not clear for someone who is not familiar with tBTC internals.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nkuba added 3 commits April 8, 2024 14:40
Current implementation of the redemptions mechanism assumes specific
TBTCVault contract implementation to be the owner of the TBTC Token
contract. We want to ensure that the owner of TBTC Vault haven't
changed, so we don't accidentially lock the tBTC tokens.
@nkuba nkuba requested a review from pdyraga April 8, 2024 14:04
@nkuba nkuba added this to the MVP milestone Apr 9, 2024
@dimpar
Copy link
Member

dimpar commented Apr 9, 2024

Not directly related to BitcoinRedeemer tests but it assumes 0 fee basis points as temporarily defined in stBTC contract. Once we change entryFeeBasisPoints and exitFeeBasisPoints upon contract deployments to values other than 0, these tests start to fail. Short term solution is to set these values here to 0. Long term we should handle it globally before running any tests.

[-stBtcAmountToRedeem],
)

expect(await stbtc.totalSupply()).to.be.equal(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move it to a new it to check totalSupply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context("when tBTC.approveAndCall returns false", () => {
beforeAfterSnapshotWrapper()

before(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts about unpacking beforeAfteSnapshoWrapper and move tbtc.setApproveAndCallResult(false) to "before"? Now we have duplicates of "before".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pattern we use across the tests. We could improve it in the future globally for all tests in a separate PR.

@dimpar dimpar enabled auto-merge April 9, 2024 10:27
@dimpar dimpar merged commit 014c33e into main Apr 9, 2024
24 checks passed
@dimpar dimpar deleted the bitcoin-redeemer-2 branch April 9, 2024 10:27
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.

Integrate Acre unstaking with tBTC unminting
4 participants