-
Notifications
You must be signed in to change notification settings - Fork 123
staticaddr: fractional swap amount #887
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
base: master
Are you sure you want to change the base?
Conversation
fd6cc75
to
f54115f
Compare
67612da
to
b3522b1
Compare
8b33f65
to
21fb9ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for fractional swap amounts in static loop‐in swaps by adding a new amount flag. Key changes include:
- Logic updates in the loop-in store, manager, and swap creation to use a user-specified amount if provided.
- Additions to the deposit and SQL layers to support lookup by outpoint and store the selected amount.
- Updates to the RPC protos and CLI to expose and handle the new amount flag.
Reviewed Changes
Copilot reviewed 19 out of 23 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
staticaddr/loopin/sql_store.go | Adjusts swap creation logic to set AmountRequested based on flag. |
staticaddr/loopin/manager.go | Updates loop-in initiation and sweep handling to use selected amount. |
staticaddr/loopin/loopin.go | Uses the selected amount for calculating swap and change outputs. |
staticaddr/loopin/interface.go | Adds DepositsForOutpoints signature to retrieve deposits by outpoints. |
staticaddr/loopin/actions.go | Adapts invoice and fee calculations based on the selected amount. |
staticaddr/deposit/* | Introduces functions to retrieve deposits by outpoint. |
looprpc/client.proto | Adds a new field for the swap amount in the loop-in request. |
loopdb/sqlc/* | Updates SQL queries and models to include selected_amount. |
loopd/swapclient_server.go | Updates quote requests and swap reporting to use the selected amount. |
interface.go | Exposes a new SelectedAmount field in the loop-in request interface. |
cmd/loop/staticaddr.go | Adds a new CLI flag and coin-selection logic for the swap amount. |
Files not reviewed (4)
- loopdb/sqlc/migrations/000014_static_selected_amount.down.sql: Language not supported
- loopdb/sqlc/migrations/000014_static_selected_amount.up.sql: Language not supported
- loopdb/sqlc/queries/static_address_deposits.sql: Language not supported
- loopdb/sqlc/queries/static_address_loopin.sql: Language not supported
Comments suppressed due to low confidence (2)
staticaddr/deposit/interface.go:30
- [nitpick] Consider revising the comment for clarity. For example, change it to 'Returns all deposits associated with the given outpoints.'
// DepositsForOutpoints returns all deposits that behind the given
cmd/loop/staticaddr.go:639
- Review the dust limit check to ensure it correctly handles edge cases when the available deposit sum exactly equals the swap amount plus the dust limit. Clarifying the condition could prevent unexpected behavior in deposit selection.
if depositSum-int64(dustLimit) < amount {
4b1058d
to
5625af3
Compare
5625af3
to
569359f
Compare
569359f
to
8be2c65
Compare
Rebased |
cb28b54
to
374d41e
Compare
Rebased |
The QuoteRequest adds a field select_deposits to signal that the specified quote amount should be coin-selected from the client's deposits in order to determine the number of deposits to quote for. The StaticAddressLoopInRequest gets a new amount field that either indicates that the swap amount should be allocated from the passed deposits or coin-selected from all available deposits.
374d41e
to
d62716f
Compare
Rebased master |
e81bcda
to
a109639
Compare
In this commit we add a new function SelectDeposits to the loop-in manager. It coin-selects deposits that meet an arbitrary swap amount provided by the client. We have to ensure that the server creates the correct change outputs for the htlc- and sweepless sweep transactions.
If a quote request contains an amount and flag SelectDeposits set to true the quoting coin- selects the required deposits to meet the swap amount in order to quote for the number of deposits.
The selected_amount column of all previous swaps is filled with the total value of deposits that partook in these swaps.
a109639
to
b435588
Compare
skip first 2 commits
This PR adds an
amount
flag to static loop-in swaps that allows the caller to only swap a fraction of the value of the selected deposits. If onlyamount
is selected, the client selects deposits automatically to cover for the swaps amount.To ensure backwards UX compatibility, omitting the new flag (
--amount=0
) selects the total deposit amount for swapping.This PR also adds a method
SelectDeposits
to the loop-in manager that is used to coin-select deposits in case the useronly provides a static swap amount.
TODO