Skip to content

Allow setting custom markup fees for Vortex and partners#604

Merged
ebma merged 125 commits into
stagingfrom
552-set-a-mark-up-fee-for-vortex
Jun 3, 2025
Merged

Allow setting custom markup fees for Vortex and partners#604
ebma merged 125 commits into
stagingfrom
552-set-a-mark-up-fee-for-vortex

Conversation

@ebma
Copy link
Copy Markdown
Member

@ebma ebma commented Apr 29, 2025

This pull request introduces several changes across configuration, code quality, and feature updates. The most significant updates include adding a new DistributeFeesHandler class, modifying existing phase handlers to integrate the new phase, and updating configurations for caching and external APIs. Additionally, the ESLint configuration and dependencies have been streamlined for better maintainability.

Feature Updates:

  • Added a new DistributeFeesHandler class to handle the distribution of network, vortex, and partner fees using a stablecoin on Pendulum. This includes methods for executing the phase, submitting transactions, and transitioning to the next phase. (api/src/api/services/phases/handlers/distribute-fees-handler.ts)
  • Updated MoonbeamToPendulumXcmPhaseHandler and NablaSwapPhaseHandler to transition to the new distributeFees phase where applicable. (api/src/api/services/phases/handlers/moonbeam-to-pendulum-xcm-handler.ts, [1]; api/src/api/services/phases/handlers/nabla-swap-handler.ts, [2]
  • Registered the new DistributeFeesHandler in the phase handler registry. (api/src/api/services/phases/register-handlers.ts) [1] [2]

Configuration Updates:

  • Added new environment variables for CoinGecko API integration and caching configurations (COINGECKO_API_KEY, COINGECKO_API_URL, CRYPTO_CACHE_TTL_MS, FIAT_CACHE_TTL_MS). (api/.env.example)

Code Quality and Dependency Updates:

  • Removed eslint-config-airbnb-base from the package.json dependencies and corresponding ESLint rules, simplifying the ESLint configuration. (api/package.json, [1]; api/.eslintrc.js, [2] [3]
  • Removed unused imports and redundant functions, such as calculateTotalReceive and calculateTotalReceiveOnramp, to clean up the codebase. (api/src/api/helpers/quote.ts)

Minor Enhancements:

  • Added validation for transaction data in several phase handlers to ensure robust error handling. (api/src/api/services/phases/handlers/nabla-approve-handler.ts, [1]; api/src/api/services/phases/handlers/pendulum-moonbeam-phase-handler.ts, [2]; api/src/api/services/phases/handlers/nabla-swap-handler.ts, [3]

These changes collectively improve the functionality, maintainability, and robustness of the application.

Review tips

I would recommend reading docs/architecture/ramp-journey-and-fees.md and docs/refactoring/fee-handling-refactor-summary-2025-04-30-md before starting to look at the code.

Closes #552.

ebma added 3 commits April 29, 2025 09:57
Replaced single `fee` field with detailed fee breakdowns (`networkFee`, `processingFee`, `partnerMarkupFee`, `totalFee`, and `feeCurrency`). Added support for partner-specific fee configurations via `partnerId` in the quote process. Updated models, services, and associations to support the new fee structure and partner relationship.
Replaced individual fee fields with a unified JSON fee structure across the system. This simplifies fee data representation, provides better flexibility, and consolidates related fields into a single object. Updated migrations, models, endpoints, and services to align with the new structure.
@ebma ebma linked an issue Apr 29, 2025 that may be closed by this pull request
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 29, 2025

Deploy Preview for pendulum-pay canceled.

Name Link
🔨 Latest commit d17dab0
🔍 Latest deploy log https://app.netlify.com/projects/pendulum-pay/deploys/683a213d8b6f02000817e4b7

ebma added 15 commits April 29, 2025 11:24
Revised fee storage to directly use detailed fee components in the database. Updated API response to transform and aggregate fees accordingly, ensuring clarity and reducing redundant transformations. Adjusted vortex fee logic to align with partner configuration.
This commit updates the database migration and model to eliminate the 'network_estimate' fee type from the ENUM definition. Associated seed data for 'network_estimate' has also been removed to align with the updated structure.
Removed obsolete helper functions for fee calculation and integrated fee logic directly into the ramp service. Improved clarity by renaming variables and restructuring the output amount calculation. Added logic to calculate network fees in USD for EVM on-ramps and prepared the service for dynamic pricing updates.
Core fee calculation now focuses on vortex, anchor, and partner markup fees, removing unnecessary network fee logic. Introduced a unified fee structure for maintaining detailed breakdowns, improving clarity and maintainability. This change refines the QuoteTicket creation process by leveraging a cleaner fee structure.
Revised the fee calculation workflow to include proper breakdowns and introduced a placeholder function for converting fees into output currencies. Added safety checks for negative output amounts, refined fee structures, and ensured the final output amount considers all applicable fees. Future implementation will enhance currency conversion using accurate exchange rates.
Replaces the combined "processing" fee field with distinct "vortex" and "anchor" fields throughout the codebase. Updates interfaces, models, and calculations to align with the new detailed fee structure. This improves clarity and consistency in fee handling.
@ebma ebma requested a review from Copilot April 30, 2025 08:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a granular fee structure for Vortex by replacing the single fee field with a detailed breakdown that includes network, vortex, anchor, and partner markup fees, along with the related database schema, API, and frontend changes. Key changes include:

  • Updating database models and migrations (for quote tickets, partners, and fee configurations).
  • Refactoring fee calculation logic in the QuoteService along with corresponding frontend modifications.
  • Enhancing associated documentation and decision logs to reflect the new fee structure.

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
memory-bank/*.md Added decision logs and context updates for the fee structure.
frontend/src/hooks/* & components/* Updated fee property usage to reference the new fee structure.
api/src/models/* & migrations/* Changed fee field type to JSONB, added partner and fee configuration models, and updated associations.
api/src/api/services/ramp/quote.service.ts Refactored fee calculation logic to compute and store detailed fee components.
docs/* Provided detailed architectural and refactoring plans for the fee enhancements.

Comment thread api/src/api/services/ramp/quote.service.ts Outdated
Comment thread api/src/api/services/ramp/quote.service.ts Outdated
ebma added 8 commits April 30, 2025 11:29
Added functionality to determine and convert fees to a target fiat currency using placeholder logic. Updated fee storage and response structure to utilize the target fiat instead of USD, ensuring better alignment with input/output currencies. Placeholder conversion logic still needs proper implementation with live price feeds.
Introduced `grossOutputAmount`, `anchorFeeFiat`, `distributableFeesFiat`, and `targetFiat` to the `QuoteTicketMetadata` interface. Updated the quote service to calculate and store these fields, ensuring a more detailed fee structure is preserved. This enhances tracking and transparency of fee components.
Introduce separate handling for anchor fees by adding placeholder methods for Fiat-to-USD and USD-to-token conversions. Reorganize input/output amount calculations to distinguish between gross and net values and ensure proper fee deduction. Added better type safety and logging for future implementation of price-related conversions.
Replaced manual calculation of `outputAmountBeforeFees` with `grossOutputAmount` from quote metadata for improved accuracy and consistency. Updated all relevant validations, calculations, and transaction preparations to align with this change. Added error handling to ensure `grossOutputAmount` is present in metadata.
Introduce a handler to distribute network, vortex, and partner fees in stablecoin on Pendulum. Includes placeholder implementations for fiat to USD and USD to token unit conversions, fee processing, and blockchain transactions with error handling. Future improvements include stablecoin selection logic and proper conversion methods.
@ebma ebma force-pushed the 552-set-a-mark-up-fee-for-vortex branch from 30eac25 to 7dea737 Compare May 30, 2025 10:00
@ebma ebma force-pushed the 552-set-a-mark-up-fee-for-vortex branch from e1872bd to 65bdc98 Compare May 30, 2025 17:56
@ebma ebma force-pushed the 552-set-a-mark-up-fee-for-vortex branch from 65bdc98 to 5a53d93 Compare May 30, 2025 20:28
@ebma
Copy link
Copy Markdown
Member Author

ebma commented May 30, 2025

@pendulum-chain/devs I addressed most/all the relevant comments. This is finally ready for merge now.

@ebma ebma merged commit 054f787 into staging Jun 3, 2025
5 checks passed
@ebma ebma deleted the 552-set-a-mark-up-fee-for-vortex branch June 3, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set a mark-up fee for Vortex

4 participants