Skip to content

fix(predict): fix fee amount calculation cp-7.69.0#27232

Merged
matallui merged 1 commit into
mainfrom
predict/fix-fee-calculation
Mar 9, 2026
Merged

fix(predict): fix fee amount calculation cp-7.69.0#27232
matallui merged 1 commit into
mainfrom
predict/fix-fee-calculation

Conversation

@matallui

@matallui matallui commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Description

Fix the Predict fee calculation to match the backend order relay calculation. Previously, individual fee components (metamaskFee, providerFee) were rounded to 3 decimal places before summing, and previewOrder was passing size instead of makerAmount as the fee basis. This caused rounding discrepancies that led to order failures on certain amounts (e.g., $6.12 yielding a $0.244 fee instead of $0.2448).

Changes:

  • Remove per-component rounding of metamaskFee and providerFee — keep full precision
  • Round only totalFee to 6 decimal places (matching backend precision)
  • Use makerAmount instead of size as the userBetAmount in previewOrder, aligning with the backend order relay

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/PRED-740

Manual testing steps

Feature: Predict fee calculation accuracy

  Scenario: user places a bet with an amount that previously caused rounding errors
    Given the user is on the Predict market detail screen

    When user enters a bet amount of $6.12
    Then the displayed fee should be $0.2448 (not $0.244)
    And the order should succeed without a fee mismatch error

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Updates fee math used for order previews/relaying; incorrect rounding or amount basis could still cause fee mismatches and failed orders, but the change is localized to fee computation.

Overview
Adjusts Predict’s Polymarket fee calculation to stop rounding metamaskFee/providerFee individually and instead round only totalFee to 6 decimals, matching backend precision.

Updates previewOrder (BUY) to compute fees from the rounded makerAmount rather than the raw input size, reducing client/backend fee discrepancies that can cause order submission failures.

Written by Cursor Bugbot for commit 06004e3. This will update automatically on new commits. Configure here.

@matallui matallui requested a review from a team as a code owner March 9, 2026 22:48
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-predict Predict team label Mar 9, 2026
@github-actions github-actions Bot added the size-S label Mar 9, 2026
@matallui matallui changed the title fix(predict): fix fee amount calculation fix(predict): fix fee amount calculation cp-7.69.0 Mar 9, 2026
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePredictions, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes modify fee calculation and order preview logic in the Polymarket Predict provider (app/components/UI/Predict/providers/polymarket/utils.ts). Specifically:

  • Removed 3-decimal rounding for individual metamaskFee and providerFee.
  • Changed totalFee rounding to 6 decimals.
  • Updated previewOrder to use makerAmount instead of size for userBetAmount when calculating fees.

These changes directly impact the Predict (Polymarket) flow, including fee previews, order summaries, and potentially final transaction values. This can affect:

  • Opening new prediction positions
  • Fee display and correctness
  • Balance updates after transactions
  • On-chain confirmation flows tied to prediction orders

Therefore:

  • SmokePredictions is required to validate full position lifecycle and balance synchronization.
  • SmokeConfirmations is required because opening/closing prediction positions involves on-chain transactions and confirmations.
  • SmokeWalletPlatform is required because Predictions is embedded in the Trending tab and tightly integrated with wallet platform flows.

No other core wallet, network, or controller logic is affected.

Performance Test Selection:
The changes are limited to arithmetic rounding and parameter usage in fee calculation utilities. There are no UI rendering, list performance, network loading, controller, or initialization changes. No measurable performance impact is expected.

View GitHub Actions results

@caieu caieu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@matallui matallui enabled auto-merge March 9, 2026 22:59
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
9 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud

sonarqubecloud Bot commented Mar 9, 2026

Copy link
Copy Markdown

@matallui matallui added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit dbf2c8f Mar 9, 2026
126 checks passed
@matallui matallui deleted the predict/fix-fee-calculation branch March 9, 2026 23:43
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 9, 2026
@metamaskbot metamaskbot added the release-7.70.0 Issue or pull request that will be included in release 7.70.0 label Mar 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.70.0 Issue or pull request that will be included in release 7.70.0 size-S team-predict Predict team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants