-
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
4b1058d
to
5625af3
Compare
5625af3
to
569359f
Compare
569359f
to
8be2c65
Compare
Rebased |
0127354
to
8adb766
Compare
d58da27
to
90d2ee6
Compare
90d2ee6
to
24c68d2
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 pull request adds a --amount
flag to static loop-in swaps that allows users to swap only a fraction of their deposit value. The remaining value is sent back as change to the static address.
Key changes:
- Added amount field to swap server RPC for fractional swap amounts
- Extended sweep batcher to handle change outputs in transaction construction
- Created deposit selection mechanism for automatic coin selection when only amount is specified
Reviewed Changes
Copilot reviewed 41 out of 42 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
utils/dust_limit.go | New utility function for calculating dust limits |
swapserverrpc/staticaddr.proto | Added optional amount field to loop-in request |
sweepbatcher/sweep_batcher.go | Extended batcher to support change outputs and presigning |
sweepbatcher/sweep_batch.go | Enhanced transaction construction with change output handling |
staticaddr/loopin/sql_store.go | Added selected amount storage and migration support |
Comments suppressed due to low confidence (1)
staticaddr/loopin/sql_store.go:23
- Changing the constant name from
outpointSeparator
toOutpointSeparator
makes it exported, which may not be intended if it's only used internally. Consider if this should remain private.
const OutpointSeparator = ";"
sweepbatcher/sweep_batcher_test.go
Outdated
@@ -2798,6 +2798,8 @@ func testSweepBatcherComposite(t *testing.T, store testStore, | |||
ctx, cancel := context.WithCancel(context.Background()) | |||
defer cancel() | |||
|
|||
lnd.SetMinRelayFee(200) |
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.
The hardcoded minimum relay fee value (200) is used inconsistently throughout the test file. Consider defining this as a constant or using a more descriptive variable to improve maintainability and make the test intentions clearer.
lnd.SetMinRelayFee(200) | |
lnd.SetMinRelayFee(minRelayFee) |
Copilot uses AI. Check for mistakes.
@@ -113,7 +128,7 @@ func (h *mockPresignedHelper) DestPkScript(ctx context.Context, | |||
} | |||
|
|||
// SignTx tries to sign the transaction. If all the inputs are online, it signs | |||
// the exact transaction passed and adds it to presignedBatches. Otherwise it | |||
// the exact transaction passed and adds it to presignedBatches. Otherwise, it |
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.
[nitpick] The comment should maintain consistent punctuation. The sentence should end without a comma: 'Otherwise it' rather than 'Otherwise, it'.
// the exact transaction passed and adds it to presignedBatches. Otherwise, it | |
// the exact transaction passed and adds it to presignedBatches. Otherwise it |
Copilot uses AI. Check for mistakes.
sweepbatcher/sweep_batch.go
Outdated
@@ -1382,15 +1484,21 @@ func (b *batch) publishMixedBatch(ctx context.Context) (btcutil.Amount, error, | |||
// known in advance to be non-cooperative (nonCoopHint) and not failed | |||
// to sign cooperatively in previous rounds (coopFailed). If any of them | |||
// fails, the sweep is excluded from all following rounds and another | |||
// round is attempted. Otherwise the cycle completes and we sign the | |||
// round is attempted. Otherwise, the cycle completes and we sign the |
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.
[nitpick] The comment should maintain consistent punctuation. The sentence should end without a comma: 'Otherwise the cycle completes' rather than 'Otherwise, the cycle completes'.
// round is attempted. Otherwise, the cycle completes and we sign the | |
// round is attempted. Otherwise the cycle completes and we sign the |
Copilot uses AI. Check for mistakes.
sweepbatcher/sweep_batch.go
Outdated
@@ -1450,7 +1559,7 @@ func (b *batch) publishMixedBatch(ctx context.Context) (btcutil.Amount, error, | |||
// If there was any failure of cooperative signing, we need to | |||
// update weight estimates (since non-cooperative signing has | |||
// larger witness) and hence update the whole transaction and | |||
// all the signatures. Otherwise we complete cooperative part. | |||
// all the signatures. Otherwise, we complete cooperative part. |
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.
[nitpick] The comment should maintain consistent punctuation. The sentence should end without a comma: 'Otherwise we complete cooperative part' rather than 'Otherwise, we complete cooperative part'.
// all the signatures. Otherwise, we complete cooperative part. | |
// all the signatures. Otherwise we complete the cooperative part. |
Copilot uses AI. Check for mistakes.
} | ||
} | ||
|
||
log.Infof("Updating selected swap amounts for %d loop out swaps", |
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.
The log message refers to 'loop out swaps' but this is migrating loop-in swaps. The message should be corrected to 'loop in swaps'.
log.Infof("Updating selected swap amounts for %d loop out swaps", | |
log.Infof("Updating selected swap amounts for %d loop in swaps", |
Copilot uses AI. Check for mistakes.
24c68d2
to
dd855df
Compare
since deposits have been normalized in the db in the context of a static address swap this commit now retrieves the deposit information as part of GetLoopInByHash and GetStaticAddressLoopInSwapsByStates.
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.
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.
dd855df
to
6af4a98
Compare
first relevant commit in this PR is 81c4117
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