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 the calculation of Boltz fees #31

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

ok300
Copy link
Contributor

@ok300 ok300 commented Mar 22, 2024

When calculating the Boltz service fees:

  • it's always the LN invoice amount that's used as input
  • the service fee is rounded up to the nearest full sat (ceil instead of round, which rounds up or down)

This is the case for both submarine and reverse submarine swaps.

This can be checked by manually entering values in https://boltz.exchange and observing the calculated Boltz fee:

  • reverse submarine swap (LN -> BTC)
    • test validity of ceil
      • enter invoice amount as 50000
      • the Boltz fee is 250
        • change invoice amount to 50001
      • the Boltz fee is now 251 (round would have resulted in 250, ceil leads to the correct 251)
    • test validity of invoice amount as service fee input
      • enter receive (BTC) amount as 38356
      • Boltz fee will become 251
      • change receive (BTC) amount to 38357
      • Boltz service fee remains 251

Similar tests can be done with the reverse direction (normal submarine swaps).

Therefore, this PR:

  • changes the service fee rounding to use ceil
  • renames the input arg of the service fee method to explicitly state it is the invoice amount
    • "input" or "output" is somewhat vague, as "user input" can mean both "swap input" or "swap output", depending on the app's use case.

@i5hi
Copy link
Collaborator

i5hi commented Mar 26, 2024

Hey @ok300 Thanks for the PR! Logic and code looks good.

It fails the linting tests. I'll take care of it for now. For successive PRs make sure you run rust fmt ;)

@i5hi i5hi merged commit b0be519 into SatoshiPortal:trunk Mar 26, 2024
3 of 4 checks passed
hydra-yse pushed a commit to hydra-yse/boltz-rust that referenced this pull request Mar 28, 2024
…ing-fix

Fix the calculation of Boltz fees
hydra-yse pushed a commit to hydra-yse/boltz-rust that referenced this pull request Mar 28, 2024
…ing-fix

Fix the calculation of Boltz fees
@ok300 ok300 deleted the ok300-boltz-fees-rounding-fix branch August 15, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants