fix: don't return tx when user doesn't have enough funds #556
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.
There's an edgecase that produces on-chain failures (InsufficientUserFunds errors) which is the following.
The user has 1 SOL and he wants to trade for USDC. He requests a quote for 1 SOL, because he has a lot of SOL he's supposed to pay for token accounts, but after he pays for the token accounts he no longer has 1 SOL.
Normally when the user doens't have enough funds we don't return the transaction to the user, but here yes because of flawed logic.
This happened this morning:
https://solscan.io/tx/3vniKPxn6EbUjZXrV2gquiPaasS4vCeZcGSxdF5dxztmPdZQskKLC47nX4MFXV2BYoAuB72UHgyimnHanukhKnzR
This shouldn't happen to normal users since normally frontends don't let you trade your full balance (and leave some SOL for token creations).