stacks.js icon indicating copy to clipboard operation
stacks.js copied to clipboard

sbtc withdrawal does not use dust amount

Open friedger opened this issue 2 years ago • 1 comments

What version of Stacks.js are you using?

    "sbtc": "^0.1.8"

Describe the bug

Calling sbtcWithdrawHelper results in a btc tx with 3 outputs where the second spends the total amount.

Screenshot from 2023-10-25 17-23-12

How to reproduce

Follow the tutorial on https://stacks-network.github.io/sbtc-docs/withdrawal.html and call

 const tx = await sbtcWithdrawHelper({
      sbtcWalletAddress,
      bitcoinAddress: btcAddress,
      amountSats: total,
      signature,
      feeRate: await helper.estimateFeeRate('low'),
      utxos,
      bitcoinChangeAddress: btcAddress,
      fulfillmentFeeSats: 2000,
    });

Expected behavior

Second output should be a dust value as described in https://github.com/stacks-network/sbtc/blob/main/sbtc-core/src/operations/op_return/withdrawal_request.rs#L287C22-L287C43

friedger avatar Oct 25 '23 16:10 friedger

Got it, thanks for the report. I had been using the same serialization from the bridge-lib earlier, but only the dust amount was withdrawn, so I assumed this was the right way of doing things. This way I got the withdraw to work on devenv 😬

fyi, I heard you were asking about helper methods eg. for fetching balance. See the tests/ folder in the sbtc package. (They are not runnable as a whole test-suite right now, but more are a collection of runnable snippets helpful for the sbtc devenv flow)

janniks avatar Oct 25 '23 16:10 janniks