feat: add boltz savings swap#1081
Open
coreyphillips wants to merge 6 commits into
Open
Conversation
cd6afdc to
45fce11
Compare
Greptile SummaryThis PR adds a Boltz reverse-swap path for moving Lightning funds into savings. The main changes are:
Confidence Score: 4/5The swap lifecycle can report completion too early and can lose claim handling during startup, navigation, or event-subscription races.
TransferViewModel.kt, SavingsProgressScreen.kt, and WalletViewModel.kt
|
| Filename | Overview |
|---|---|
| app/src/main/java/to/bitkit/viewmodels/TransferViewModel.kt | Adds quote calculation and reverse-swap execution, with races in quote replacement and claim-event subscription. |
| app/src/main/java/to/bitkit/ui/screens/transfer/SavingsProgressScreen.kt | Adds swap progress handling but treats pending swaps as complete and ties execution to the screen lifecycle. |
| app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt | Adds swap resumption and balance refresh handling without retrying failed stream startup. |
| app/src/main/java/to/bitkit/services/BoltzService.kt | Adds the Boltz FFI wrapper and a non-replaying event bridge used by swap execution and wallet updates. |
| app/src/main/java/to/bitkit/ui/screens/transfer/SavingsConfirmScreen.kt | Adds live quotes, amount adjustment, swap confirmation, and the channel-close fallback. |
| app/src/main/java/to/bitkit/viewmodels/SwapsViewModel.kt | Adds sorted swap history, manual claims, and status-based claim gating. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant UI as Savings Progress
participant TVM as TransferViewModel
participant LN as LightningRepo
participant Boltz as BoltzService
participant WVM as WalletViewModel
UI->>TVM: executeSavingsSwap()
TVM->>Boltz: createReverseSwap()
TVM-->>Boltz: schedule event collection
TVM->>LN: pay hold invoice
Boltz-->>TVM: Claimed or Error
alt Event observed
TVM-->>UI: Success or Failure
else No event within 60 seconds
TVM-->>UI: Pending
UI-->>UI: Show success
WVM->>Boltz: Continue background updates
end
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant UI as Savings Progress
participant TVM as TransferViewModel
participant LN as LightningRepo
participant Boltz as BoltzService
participant WVM as WalletViewModel
UI->>TVM: executeSavingsSwap()
TVM->>Boltz: createReverseSwap()
TVM-->>Boltz: schedule event collection
TVM->>LN: pay hold invoice
Boltz-->>TVM: Claimed or Error
alt Event observed
TVM-->>UI: Success or Failure
else No event within 60 seconds
TVM-->>UI: Pending
UI-->>UI: Show success
WVM->>Boltz: Continue background updates
end
Reviews (1): Last reviewed commit: "fix: gate swap claim and harden boltz fl..." | Re-trigger Greptile
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a swap-based path for transferring spending balance to savings, so Lightning funds can move on-chain through a Boltz reverse swap instead of only by closing a channel.
Description
Preview
QA Notes
Manual Tests
regression:Savings Confirm → Close channel instead: falls back to the channel-close path.regression:Start the app with a pending swap: swap resumes and balance updates once it lands on-chain.Automated Checks
TransferViewModelTest.kt.SwapsViewModelTest.kt.WalletViewModelTest.kt.compileDevDebugKotlin,testDevDebugUnitTest, anddetektall pass.