fix(tokens): fall back to the house sell fee on the buy leg - #1305
Merged
Conversation
A launchpad token whose metadata omits `sellFeeBps` was treated as fee-free when it funded a buy — both when trimming the entry to what the balance can afford and when grossing the fee up into the debit at confirm time. The convert leg already falls back to the house rate for the same case, so the two legs disagreed about the same token, and iOS assumes the house rate on every leg. Erring high is the safe direction here: the fee is grossed up into the debit, so a zero fallback prices a debit the funding balance can't actually cover, and the swap fails downstream rather than being trimmed up front. Names the fallback once as `HOUSE_SELL_FEE_BPS` next to the rest of the fee math, with `sellFeeBpsOrHouseRate` reading it off a pool, so the buy leg, the convert leg, and the on-top Dollars rate can't drift apart again.
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.
Came out of an iOS↔Android diff of the fee-affordable entry correction (#1302 here, code-ios-app#625 there). The pure math and the unit suites match case-for-case; this was the one behavioral difference.
The bug
A launchpad token whose metadata omits
sellFeeBpswas treated as fee-free when it funded a buy — in two places that have to agree:SwapViewModel.buyFeeFor— the bps used to trim the entry down to what the balance can affordOnBuyConfirmed— the bps folded into the debit at confirm timeBoth fell back to
0. The convert leg (convertFeeBps) already falls back to the house rate for exactly the same case, so the two legs priced the same token differently, and iOS assumes the house rate on every leg (sellFeeBps ?? 100inBuyAmountViewModel,BuyConfirmationViewModel).Why the house rate is the right fallback
The fee is grossed up into the debit. Under-estimating it prices a debit the funding balance can't actually cover, so the entry is never trimmed and the swap fails downstream instead. Over-estimating only trims the entry slightly harder. Erring high is the safe direction.
The change
HOUSE_SELL_FEE_BPSnow lives once next to the rest of the fee math inLaunchpadSellFee.kt, withLaunchpadMetadata?.sellFeeBpsOrHouseRatereading it off a pool. The buy leg, the convert leg, and the on-top Dollars rate all resolve through it, so they can't drift apart again.DEFAULT_CONVERT_FEE_BPSkeeps its name and now aliases the shared constant — no behavior change on the USDF paths.Tests added to
LaunchpadSellFeeTestfor both sides of the fallback.