Skip to content

Conversation

@Matt561
Copy link
Contributor

@Matt561 Matt561 commented Oct 20, 2025

Description

Adds determineMakerStatus function in usePerpsOrderFees to accurately display order fees based on maker/taker status.

  • Maker: Order sits on the order book and provides liquidity
  • Taker: Order executes immediately and takes liquidity

Changelog

CHANGELOG entry: added accurate market or taker status for order fee calculations

Related issues

Fixes: TAT-1662: Trade fee does not adjust for market or limit order maker or taker

Manual testing steps

Feature: Perps Maker/Taker Fee Calculation

  Background:
    Given user is on Perps Order View
    And order book data is available

  # Core Behavior
  Scenario: user places market order
    When user places a $10,000 market order
    Then fee displays 0.045% ($4.50)

  Scenario: user places limit buy below ask price
    When user places $10,000 limit buy at $49,500 (below $50,001 ask)
    Then fee displays 0.015% ($1.50)

  Scenario: user places limit buy at or above ask price
    When user places $10,000 limit buy at $50,100 (above $50,001 ask)
    Then fee displays 0.045% ($4.50)

  Scenario: user places limit sell above bid price
    When user places $10,000 limit sell at $50,500 (above $49,999 bid)
    Then fee displays 0.015% ($1.50)

  Scenario: user places limit sell at or below bid price
    When user places $10,000 limit sell at $49,900 (below $49,999 bid)
    Then fee displays 0.045% ($4.50)

  # Dynamic Updates (Maker -> Taker)
  Scenario: user adjusts limit price crossing market threshold
    Given user has $10,000 limit buy at $49,500 showing 0.015% fee
    When user changes limit price to $50,100
    Then fee updates to 0.045% ($4.50)

  # Close Position (Market Orders Only)
  Scenario: user closes position with market order
    Given user has open position
    When user closes 50% with market order
    Then fee displays 0.045% (taker fee)

  # Fallback Behavior
  Scenario: user places order without order book data
    Given WebSocket is disconnected
    And order book data is unavailable
    When user places any limit order
    Then fee displays 0.045% (conservative taker fee)

Screenshots/Recordings

Before

After

tat-1662-trade-fee-does-not-adjust-for-market-or-limit-order-maker-or-taker-after-demo.mov

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

Derives maker/taker status in usePerpsOrderFees from limit price and live bid/ask, updates order/close views to pass required data, enables order book in streams, and adds comprehensive tests.

  • Hooks:
    • Add determineMakerStatus and compute isMaker in usePerpsOrderFees using orderType, limitPrice, direction, and L2 bestBid/Ask.
    • Extend hook params: limitPrice, direction, currentAskPrice, currentBidPrice; remove external isMaker usage; minor fix in formatFeeRate (use Number.isNaN).
  • Views:
    • PerpsOrderView: pass limitPrice, direction, currentAskPrice/bid to usePerpsOrderFees; restore fee/rewards computation block at new location.
    • PerpsClosePositionView: pass limitPrice, inferred direction and live bestBid/Ask to usePerpsOrderFees for closing fees.
  • Streaming:
    • PerpsStreamManager: include includeOrderBook: true in subscribeToPrices (main and prewarm) to supply bid/ask to fee logic.
  • Tests:
    • Massive expansion of usePerpsOrderFees.test.ts to cover maker/taker determination, edge cases, loading, recalculation, rewards/discounts, caching, and points estimation; update expectations for new params and logic.
    • Update PerpsStreamManager.test.tsx to expect includeOrderBook: true on price subscriptions.

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

@Matt561 Matt561 requested a review from a team as a code owner October 20, 2025 18:29
@Matt561 Matt561 added No QA Needed Apply this label when your PR does not need any QA effort. team-perps Perps team labels Oct 20, 2025
@github-actions
Copy link
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.

@Matt561 Matt561 added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Oct 20, 2025
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@Matt561 Matt561 added this pull request to the merge queue Oct 21, 2025
Merged via the queue into main with commit 58b99bd Oct 21, 2025
81 of 83 checks passed
@Matt561 Matt561 deleted the feat/tat-1662-trade-fee-does-not-adjust-for-market-or-limit-order-maker-or-taker branch October 21, 2025 15:27
@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2025
@metamaskbot metamaskbot added release-7.59.0 Issue or pull request that will be included in release 7.59.0 release-7.58.0 Issue or pull request that will be included in release 7.58.0 and removed release-7.59.0 Issue or pull request that will be included in release 7.59.0 labels Oct 21, 2025
@metamaskbot
Copy link
Collaborator

Missing release label release-7.58.0 on PR. Adding release label release-7.58.0 on PR and removing other release labels(release-7.59.0), as PR was added to branch 7.58.0 when release was cut.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

No QA Needed Apply this label when your PR does not need any QA effort. release-7.58.0 Issue or pull request that will be included in release 7.58.0 size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-earn team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants