feat(perps-controller): report the winning fee source on fee quotes - #10650
Merged
Merged
Conversation
Contributor
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
geositta
previously approved these changes
Oct 1, 2026
geositta
left a comment
Contributor
There was a problem hiding this comment.
Looks good to merge. Thanks for documenting that a rewards source can represent no reduction, and submission resolves the fee again.
4 tasks
# Conflicts: # packages/perps-controller/CHANGELOG.md
geositta
approved these changes
Oct 2, 2026
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.
Explanation
PerpsController.calculateFeesalready decides which fee source wins for a quote (default,rewardsorsubscription) insideRewardsIntegrationService.resolveFee, and uses that winner to re-price the MetaMask builder fee. The winner itself was dropped before the quote reached clients, so a client wanting to say why a fee is reduced (for example, a member badge for a subscription waiver versus a VIP badge for a rewards discount) had to guess from the rates.This PR adds an optional
feeSourcetoFeeCalculationResult, set inapplyFeeResolutionfrom the same resolution the rates were priced with.Why
applyFeeResolution. It is the only place that knows whether the resolution actually made it into the quote. Its early-return paths (no resolution, no MetaMask rate, or a placement that carries no builder fee, such as TWAP or Lighter) hand back the provider's quote untouched, sofeeSourceis absent there instead of naming a discount the quote does not contain. The label and the rates come from one resolution object and cannot disagree.Why
feeSourcerather thansource.FeeCalculationResultmixes protocol and MetaMask components, so a baresourceis ambiguous.TradingServicealready logs this value asfeeSource.Reliability notes (documented on the field):
subscriptionalways means a real reduction: the resolver only picks it when it is strictly cheaper after venue quantization.rewardswins ties with the default (<=), so it can carry a 0% discount. Consumers should checkmetamaskFeeRatebefore presenting it as a reduction. The value is kept identical toPerpsFeeResolution.sourcerather than normalized, so the preview, the submit-path logs and attribution all use the same vocabulary.References
N/A
Checklist
Note
Low Risk
Additive optional field on fee quote types with no change to fee math; consumers that ignore the new property behave as before.
Overview
Fee previews from
calculateFeescan now expose which fee source (default,rewards, orsubscription) the quoted MetaMask builder fee was priced from, so UIs can label discounts without inferring them from rates alone.An optional
feeSourceonFeeCalculationResultis set inapplyFeeResolutionfrom the same unified resolution used to re-pricemetamaskFeeRateand totals. When the quote is not re-priced (no resolution, no MetaMask rate, or placements with no builder fee),feeSourcestays absent. JSDoc and the changelog note thatrewardscan win with a 0% discount—clients should checkmetamaskFeeRatebefore showing a reduction—and that the field describes the preview only (submit resolves fees again).Tests assert
feeSourcefor subscription, rewards, and default winning paths.Reviewed by Cursor Bugbot for commit 59ca4b0. Bugbot is set up for automated code reviews on this repo. Configure here.