Skip to content

Conversation

@abretonc7s
Copy link
Contributor

@abretonc7s abretonc7s commented Oct 30, 2025

Description

Implement 2x fee multiplier for HIP-3 (HyperLiquid Improvement Proposal 3) assets as per HyperLiquid protocol specification.

What changed:

  • HIP-3 assets (identified by dex:SYMBOL format like xyz:TSLA) now have 2x base exchange fees
  • Regular assets (e.g., BTC, ETH) are unaffected

Why:
HyperLiquid protocol charges double base fees for builder-deployed perpetuals (HIP-3 assets):

  • Regular taker: 0.045% -> HIP-3 taker: 0.090%
  • Regular maker: 0.015% -> HIP-3 maker: 0.030%

How:
Applied 2x multiplier to all three fee rate sources:

  1. Base rates (when no user-specific rates available)
  2. Cached user rates (from fee cache)
  3. API-fetched user rates (from HyperLiquid API)

Changelog

CHANGELOG entry: Fixed HIP-3 perpetuals to display correct 2x exchange fees

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-1950

Manual testing steps

Feature: HIP-3 Fee Display

  Scenario: user views fees for HIP-3 asset
    Given user is on Perps trading screen

    When user selects a HIP-3 asset (e.g., "xyz:XYZ100")
    And user enters a trade amount
    Then fee modal should show provider fee ~0.086% (2x base rate)
    And total fee should be ~0.186% (provider + 0.1% MetaMask)

  Scenario: user views fees for regular asset
    Given user is on Perps trading screen

    When user selects a regular asset (e.g., "BTC")
    And user enters a trade amount
    Then fee modal should show provider fee ~0.043% (base rate)
    And total fee should be ~0.143% (provider + 0.1% MetaMask)

Screenshots/Recordings

Before

HIP-3 assets showed incorrect 0.043% provider fee (missing 2x multiplier)
image

After

HIP-3 assets correctly show 0.086% provider fee (2x multiplier applied)
image

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs and MetaMask Mobile Coding Standards
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable (225 tests passing, added HIP-3 validation test)
  • I've documented my code using JSDoc format if applicable
  • I've applied the right labels on the PR

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

Technical Details

Files Modified:

  • app/components/UI/Perps/controllers/types/index.ts - Added coin parameter to FeeCalculationParams
  • app/components/UI/Perps/controllers/providers/HyperLiquidProvider.ts - Applied HIP-3 2x multiplier to all rate sources
  • app/components/UI/Perps/controllers/PerpsController.ts - Updated method signature
  • app/components/UI/Perps/hooks/usePerpsOrderFees.ts - Pass coin parameter
  • app/components/UI/Perps/hooks/usePerpsCloseAllCalculations.ts - Pass coin parameter
  • Test files - Updated all tests to pass coin parameter

Test Coverage:

  • All existing tests passing (225/225)
  • Added hip3-fee-validation.test.ts with 8 validation tests
  • Verified HIP-3 detection logic
  • Verified 2x multiplier application

Key Implementation:

// Detect HIP-3 assets by colon separator
const { dex } = parseAssetName(coin); // "xyz:TSLA" -> dex="xyz"
const isHip3Asset = dex !== null;

// Apply 2x multiplier to all rate sources
if (isHip3Asset) {
  feeRate *= 2;
}

Note

Implements a 2× fee multiplier for HIP-3 (dex:SYMBOL) assets and updates fee calculation to require coin, applying the multiplier across base, cached, and API-fetched rates with comprehensive test updates.

  • Fees/HIP-3:
    • Add HIP3_FEE_CONFIG with FEE_MULTIPLIER: 2 in constants/hyperLiquidConfig.ts.
    • Apply 2× multiplier for HIP-3 assets (detected via parseAssetName(coin)) in HyperLiquidProvider.calculateFees() for:
      • Base rates
      • Cached user rates
      • API-fetched user rates
  • API/Types:
    • Make coin required in FeeCalculationParams (controllers/types).
    • Update PerpsController.calculateFees signature to accept FeeCalculationParams and forward to provider.
  • Hooks/Usage:
    • Pass coin to fee calc in usePerpsOrderFees and usePerpsCloseAllCalculations.
  • Tests:
    • Update all fee tests to include coin.
    • Add tests verifying 2× HIP-3 fees for taker/maker in HyperLiquidProvider.test.ts.
    • Minor test cleanups (remove unused placeholders, add isFeeCacheValid edge case).

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

@abretonc7s abretonc7s requested a review from a team as a code owner October 30, 2025 12:05
@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.

@abretonc7s abretonc7s added the DO-NOT-MERGE Pull requests that should not be merged label Oct 30, 2025
Copy link
Contributor

@michalconsensys michalconsensys left a comment

Choose a reason for hiding this comment

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

👍 looks good, I've left there 2 questions

@abretonc7s abretonc7s added team-perps Perps team and removed team-earn DO-NOT-MERGE Pull requests that should not be merged labels Oct 31, 2025
@abretonc7s abretonc7s merged commit 45ff0d1 into perps/feat/newhome-nick Oct 31, 2025
78 of 92 checks passed
@abretonc7s abretonc7s deleted the perps/feat/hip3-fees branch October 31, 2025 09:21
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants