Skip to content

swapserverrpc: arbitrary static swap amount #951

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Jun 11, 2025

This PR adds an amount field to the ServerStaticAddressLoopInRequest.

    The optional swap amount the client is attempting to swap. If specified the
    server will take out this amount from the total value of provided
    deposit_outpoints and will send the change back to the static address. If
    this results in dust change the server will reject the swap request. If the
    amount is not specified the server will use the total amount of the
    deposit_outpoints as swap amount without providing an additional flag - this
    is due to backwards compatibility.
   

@hieblmi hieblmi self-assigned this Jun 11, 2025
@hieblmi hieblmi requested review from bhandras, starius and sputn1ck June 11, 2025 13:31
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@hieblmi hieblmi force-pushed the swap-amount-rpcs branch 3 times, most recently from f87ec32 to 947d08b Compare June 17, 2025 18:00
Copy link
Collaborator

@starius starius left a comment

Choose a reason for hiding this comment

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

LGTM! 🌴
One comment.

server will take out this amount from the total value of provided
deposit_outpoints and will send the change back to the static address. If
not specified the server will use the total amount of the deposit_outpoints
as swap amount.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens, if the amount is too close to the total amount (so the change would be dust)? I think it makes sense if it fails and suggests to remove the flag to use the whole amount.
Could you add the actual expected behavior in this case to the comment, please?

Also, if the amount is equal to the total amount, it makes sense just to succeed, right? And if higher - fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I expanded the comment to explain.

Note, there is no flag to use the whole amount of provided deposits for backwards compatibility. If deposits are specified without an amount the whole amount is used.

@hieblmi hieblmi force-pushed the swap-amount-rpcs branch 4 times, most recently from 72e88de to d023b0c Compare June 27, 2025 19:18
@hieblmi hieblmi force-pushed the swap-amount-rpcs branch from d023b0c to e33e83c Compare July 2, 2025 17:00
@hieblmi
Copy link
Collaborator Author

hieblmi commented Jul 2, 2025

Rebased master

hieblmi added 4 commits July 9, 2025 15:46
Optional change of a swap is encoded in its sweeps
as a pointer to the same change output. This change
is taken into account when constructing the unsigned
batch transaction when it comes to tx weight and
outputs.
Presigning sweeps takes change outputs into account.
Each sweep belonging to the same sweep group points
to the same change output, if existent.
sweepbatcher.presign scans all passed sweeps for
change outputs and passes them to constructUnsignedTx.
The batcher now presigns sweep groups including
an optional change output. Change is usually
leftover from the client's swap amount which
is returned to the client.
@hieblmi hieblmi force-pushed the swap-amount-rpcs branch from e33e83c to eb909ac Compare July 9, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants