Add makeMaxSpend wallet API with core fallback shim#727
Open
j0ntz wants to merge 1 commit into
Open
Conversation
Add makeMaxSpend to EdgeCurrencyWallet and EdgeMemoryWallet, mirroring makeSpend but building a transaction that atomically spends the maximum amount. The wallet API routes to EdgeCurrencyEngine.makeMaxSpend when the engine implements it, otherwise falls back to a shim that combines getMaxSpendable and makeSpend. Deprecate the public getMaxSpendable API.
2 tasks
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 40b8361. Configure here.
| return await makeSpendInner( | ||
| spendInfo, | ||
| async (engineSpendInfo, opts) => | ||
| await makeMaxSpend(engineSpendInfo, opts), |
There was a problem hiding this comment.
Unbound makeMaxSpend breaks class engines
High Severity
When a native EdgeCurrencyEngine.makeMaxSpend exists, the wallet copies it off the engine and invokes the bare function. Class-based engines (the usual pattern here) rely on this; that call drops the engine instance and can throw or misbehave at runtime.
Reviewed by Cursor Bugbot for commit 40b8361. Configure here.
6 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.


CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
none
Description
Add a
makeMaxSpendmethod toEdgeCurrencyWalletandEdgeMemoryWallet. It has the same signature asmakeSpendbut builds a transaction that atomically spends the maximum amount, avoiding the race that affects separategetMaxSpendable+makeSpendcalls when network state changes between them.The wallet API routes to
EdgeCurrencyEngine.makeMaxSpendwhen the engine implements it. For engines that don't, the core provides a fallback shim that combinesgetMaxSpendableandmakeSpend(so every wallet getsmakeMaxSpendregardless of engine support).EdgeCurrencyEngine.makeMaxSpendis therefore optional.getMaxSpendableis now deprecated on the publicEdgeCurrencyWalletandEdgeMemoryWalletAPIs. The engine-levelgetMaxSpendableremains (the fallback shim still uses it as a building block).makeSpend's implementation was extracted into a sharedmakeSpendInnerhelper that bothmakeSpendandmakeMaxSpenddelegate to. For a max spend the saved spend targets are backfilled from the resulting transaction so the recorded amount reflects the real send.Asana: https://app.asana.com/0/1215088146871429/1207967192999590
Testing
npm run types(tsc) clean.npm test(mocha) — 163 passing, including a newcan make max spendtest that exercises the core fallback shim end to end.coreWallet.makeMaxSpend, which built the max-spend transaction (max amount = balance − network fee) and rendered it ready to send.Note
Medium Risk
Changes the wallet spend construction path and max-send behavior; fallback still uses the legacy two-step max calculation, while native engine support affects fee/amount correctness for max sends.
Overview
Adds
makeMaxSpendonEdgeCurrencyWalletandEdgeMemoryWallet(same shape asmakeSpend) so clients can build a max-amount send in one call instead ofgetMaxSpendablethenmakeSpend, which can race when balances or fees change between steps.makeSpendlogic is consolidated intomakeSpendInnerincurrency-wallet-api.ts, used by bothmakeSpendandmakeMaxSpend. When the engine implements optionalEdgeCurrencyEngine.makeMaxSpend, the core delegates there; otherwise it falls back togetMaxSpendableInnerplusmakeSpendon the first spend target. For max spends, savedspendTargetsmetadata is backfilled from the built transaction (native amount minus network fee for parent currency).Public
getMaxSpendableon currency and memory wallets is deprecated in favor ofmakeMaxSpend; enginegetMaxSpendableremains for the shim. Acan make max spendtest covers the fallback path on the fake engine.Reviewed by Cursor Bugbot for commit 40b8361. Bugbot is set up for automated code reviews on this repo. Configure here.