fix(sdk-coin-sol): account for tx fee in MAX withdraw (COIN-88)#8676
Closed
bitgo-ai-agent-dev[bot] wants to merge 2 commits into
Closed
fix(sdk-coin-sol): account for tx fee in MAX withdraw (COIN-88)#8676bitgo-ai-agent-dev[bot] wants to merge 2 commits into
bitgo-ai-agent-dev[bot] wants to merge 2 commits into
Conversation
The Solana fee payer is charged the transaction fee on top of the transfer amount. The server-side maximumSpendable API was returning balance minus the rent-exempt reserve without subtracting the transaction fee, so submitting that amount left an unsendable dust residue equal to approximately one transaction fee. Add Sol.getMaximumSpendable() which queries the Solana node for the current balance, builds a representative transfer, fetches the fee via getFeeForMessage, and returns balance - fee. Add an optional getMaximumSpendable hook on BaseCoin/IBaseCoin so any coin can supply its own computation. Update wallet.ts sweep() to use the coin-level result when available, falling back to the BitGo API. Ticket: COIN-88 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
9c11474 to
6468395
Compare
8c5ea01 to
2409f3f
Compare
pritam-gembali
requested changes
May 4, 2026
Contributor
pritam-gembali
left a comment
There was a problem hiding this comment.
this fix shouldn't be client side. it should be server side on maxSpendable API
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.
Summary
Sol.getMaximumSpendable(walletAddress)queries the Solana node for balance, builds a representative transfer, gets the fee viagetFeeForMessage, and returnsbalance - feegetMaximumSpendablehook onBaseCoin/IBaseCoin(defaults toundefined→ server API fallback)wallet.tssweep()now callsbaseCoin.getMaximumSpendable()first; if it returns a value, that is used as the sweep amount instead of the server-side/maximumSpendableendpointRoot cause
The server-side
/maximumSpendableAPI for SOL returnsbalance − reserved_rentbut does not subtract the transaction fee. Because the Solana fee payer pays the fee on top of the transfer amount, submittingmaximumSpendableas the transfer amount leaves~fee_amountof SOL stranded in the wallet — too small to send because sending it would also require paying a fee.Test plan
yarn run unit-test --scope @bitgo/sdk-coin-sol— 588 passing, 0 failingmodules/sdk-coin-sol/test/unit/sol.tsunderdescribe('getMaximumSpendable')cover: normal case (balance − fee), zero-balance wallet, balance smaller than fee (returns 0)tsc --noEmit --skipLibCheck) on bothsdk-coin-solandsdk-core🤖 Generated with Claude Code