Skip to content

Commit d38d1f1

Browse files
eric-stacksgitbook-bot
authored andcommitted
GITBOOK-11: added explainers on sBTC fees
1 parent a201aa0 commit d38d1f1

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed
-35.9 KB
Binary file not shown.

docs/build/sbtc/how-to-use-the-sbtc-js-library-for-bridging/btc-to-sbtc.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const deposit = buildSbtcDepositAddress({
6060
```
6161

6262
{% hint style="info" %}
63-
The `maxSignerFee` applies to the bitcoin transaction sweeping funds into, or out of, the consolidated UTXO locked exclusively by sBTC Signers' aggregate address. Depending on network congestion, specify a custom fee your users would be willing to spend. The default value will be 80,000 sats. If the actual fee spent is less than the default value, the difference will be returned.
63+
The `maxSignerFee` refers to the fee in the bitcoin transaction sweeping funds into, or out of, the consolidated UTXO locked exclusively by sBTC Signers' aggregate address. Depending on network congestion, specify a custom fee your users would be willing to spend. The default value will be 80,000 sats. The user's responsibility of the actual fee spent is actually deducted from the amount of sBTC that will be minted.
6464
{% endhint %}
6565

6666
The `buildSbtcDepositAddress` will return with a schema of:
@@ -199,7 +199,9 @@ And that's all to it. You've successfully allowed your app to handle incoming BT
199199

200200
***
201201

202-
### \[Insights] What scripts make up the custom P2TR bitcoin address?
202+
### \[Additional Insights] 
203+
204+
### What scripts make up the custom P2TR bitcoin address?
203205

204206
As mentioned above, you're not directly sending bitcoin to the public sBTC Signers' [bitcoin address](https://mempool.space/address/bc1prcs82tvrz70jk8u79uekwdfjhd0qhs2mva6e526arycu7fu25zsqhyztuy), but rather sending to a custom P2TR address where both the user and sBTC Signers have control over. Besides the default key path spend, this custom P2TR address also contains 2 sets of scripts:
205207

@@ -266,3 +268,22 @@ export function buildSbtcReclaimScript(opts: {
266268
{% endcode %}
267269

268270
Behind the scenes, these two script construction methods are being abstracted away by `buildSbtcDepositAddress` which you've implemented on the front-end.
271+
272+
### How are fees dealt with?
273+
274+
**During deposits**
275+
276+
The `maxSignerFee` refers to the fee in the bitcoin transaction sweeping funds into the consolidated UTXO locked exclusively by sBTC Signers' aggregate address. Depending on network congestion, specify a custom fee your users would be willing to spend. The default value will be 80,000 sats. The user's responsibility of the actual fee spent (for the sweep transaction) is actually deducted from the amount of sBTC that will be minted.
277+
278+
**During withdrawals**
279+
280+
The fees specified in `max-fee` of the function `initiate-withdrawal-request` of the [`.sbtc-withdrawal`](https://explorer.hiro.so/txid/SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-withdrawal?chain=mainnet) contract are referring to the fees paid of the bitcoin withdrawal transaction.
281+
282+
#### How to estimate how much in fees one should spend?
283+
284+
If you want to estimate how much one would expect to be charged in fees, you'd have to estimate the size of the transaction (vbytes) and the current network's fee rate. Below are some estimations you could use as a benchmark:
285+
286+
**For deposits**: \~250 vbytes times the prevailing sats per vbyte fee rate \
287+
**For withdrawals**: \~170 vbtytes times the prevailing sats per vbyte rate 
288+
289+
And although many deposits and withdrawals can be combined, these values should be the maximum that a user will be charged regardless of how many other deposits or withdrawals are being serviced in a single transaction by the Signers. Meaning when more than one user's request is included in a sweep transaction on the L1, the users share the fees in proportion to their deposit or withdrawal request's actual weight on the L1.

docs/build/sbtc/how-to-use-the-sbtc-js-library-for-bridging/sbtc-to-btc.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,29 @@ And that's all to it. You've successfully allowed your app to handle incoming sB
171171

172172
***
173173

174-
### \[Insights] What are the different bitcoin address types?
174+
### \[Additional Insights] 
175+
176+
### What are the different bitcoin address types?
175177

176178
Bitcoin addresses come in several types, each serving specific purposes and providing different functionalities. Each address type has evolved to enhance security, scalability, and functionality of Bitcoin transactions in response to the network's growing needs.
177179

178180
Check out the dedicated Hiro blog post to learn more about the why and how different bitcoin addresses are constructed:
179181

180182
{% embed url="https://www.hiro.so/blog/understanding-the-differences-between-bitcoin-address-formats-when-developing-your-app" %}
181183

184+
### Why does the withdrawal (peg-out) take longer to provide a bitcoin txid from the Emily API?
185+
186+
The current flow right now goes like this:
187+
188+
1. The user creates a withdrawal request via a contract call on Stacks. In this example, let's say the withdrawal transaction is confirmed in a Stacks block anchored to a Bitcoin block at height N.
189+
2. The Signers and Emily get the event from the contract call above. Emily marks the withdrawal as pending.
190+
3. The Signers wait until that Bitcoin block is final enough, which is at Bitcoin block N+6. When that Bitcoin block arrives they create and broadcast a sweep transaction fulfilling the withdrawal request. Then the Signers tell Emily that they have accepted the withdrawal request.
191+
4. Usually the sweep transaction is included in the next block, so it's confirmed at block N+7.
192+
5. The Signers issue the contract call finalizing the withdrawal on Stacks, and Emily finds out about the transaction fulfilling the withdrawal.
193+
194+
Here are some useful notes about the above process: \
195+
When the Signers tell Emily that the withdrawal has been accepted, they don't tell her about the bitcoin transaction that it's accepted in. This is intentional, because the final transaction fulfilling the withdrawal is not known until it is confirmed. It could also be the case that the Signers attempt to fulfill the withdrawal request but end up never fulfilling it. As in, the Signers could create a transaction fulfilling the withdrawal request, where they broadcast it to the Bitcoin network, but that transaction is never confirmed and never will be. Moreover, this situation is not too unlikely; it can happen when fees spike relative to the user's max fee. The current approach sidesteps all of that UX complexity and prudently informs Emily about the transaction ID after it is known to be confirmed. Moreover, some wallets can tell you if there is a payment made out to you by just examining the Bitcoin mempool. 
196+
182197
[^1]: ```
183198
type AddressInfo = {
184199
bech32: boolean;

0 commit comments

Comments
 (0)