Skip to content

feat(backend): rework fixed send fee calculation#3376

Merged
cozminu merged 8 commits into
mainfrom
cozmin/raf-902
Apr 11, 2025
Merged

feat(backend): rework fixed send fee calculation#3376
cozminu merged 8 commits into
mainfrom
cozmin/raf-902

Conversation

@cozminu
Copy link
Copy Markdown
Contributor

@cozminu cozminu commented Apr 7, 2025

Changes proposed in this pull request

For fixed debit amounts:

  • moved fee calculation before payment quote retrieval (using options.debitAmount)
  • subtracted receive amount value from payment quote retrieval
  • fee is calculated with the options.debitAmount.value as principal
  • added fee back to the final quote to insert in db

For fixed receive amounts:

  • moved fee calculation after payment quote retrieval for fixed debit amounts (as quote.debitAmount is needed, rather than the options.debitAmount). This cannot be done before retrieving the payment quote because we don't know the peer's exchange rate in advance.
  • fee is calculated with quote.debitAmount.value as principal
  • added to the final quote to insert in db

Changed mockQuote's receiveAmount logic a bit because one of the tests were failing:
debitAmountValue | fixedFee | basisPointFee | exchangeRate | expectedReceiveAmountValue
${200n} | ${20} | ${200} | ${0.455} | ${80n}

Fees: (200 * (200 * 0.0001)) - 20 = 24
Debit - fees: 200 - 24 = 176
Receive: 176 USD * 0.455 = 80.08 XRP (this returned 81 instead of 80 and it should be Math.floor'd instead of Math.ceil'd because the peer will deliver 80 XRP for 175.82417582 USD)

Context

fixes #3055

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Make sure that all checks pass
  • Bruno collection updated (if necessary)
  • Documentation issue created with user-docs label (if necessary)
  • OpenAPI specs updated (if necessary)

@github-actions github-actions Bot added type: tests Testing related pkg: backend Changes in the backend package. type: source Changes business logic labels Apr 7, 2025
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 7, 2025

Deploy Preview for brilliant-pasca-3e80ec canceled.

Name Link
🔨 Latest commit 0832eac
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/67f78bd788f391000935b7ac

@cozminu cozminu changed the title Cozmin/raf 902 feat(backend): rework fixed send fee calculation Apr 7, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2025

🚀 Performance Test Results

Test Configuration:

  • VUs: 4
  • Duration: 1m0s

Test Metrics:

  • Requests/s: 41.77
  • Iterations/s: 13.94
  • Failed Requests: 0.00% (0 of 2514)
📜 Logs

> performance@1.0.0 run-tests:testenv /home/runner/work/rafiki/rafiki/test/performance
> ./scripts/run-tests.sh -e test "-k" "-q" "--vus" "4" "--duration" "1m"

Cloud Nine GraphQL API is up: http://localhost:3101/graphql
Cloud Nine Wallet Address is up: http://localhost:3100/
Happy Life Bank Address is up: http://localhost:4100/
cloud-nine-wallet-test-backend already set
cloud-nine-wallet-test-auth already set
happy-life-bank-test-backend already set
happy-life-bank-test-auth already set
     data_received..................: 877 kB 15 kB/s
     data_sent......................: 1.8 MB 30 kB/s
     http_req_blocked...............: avg=6.13µs   min=2.37µs  med=5.32µs   max=285.03µs p(90)=6.17µs   p(95)=6.61µs  
     http_req_connecting............: avg=357ns    min=0s      med=0s       max=245.21µs p(90)=0s       p(95)=0s      
     http_req_duration..............: avg=95.13ms  min=11.4ms  med=78.98ms  max=628.53ms p(90)=166.59ms p(95)=193.99ms
       { expected_response:true }...: avg=95.13ms  min=11.4ms  med=78.98ms  max=628.53ms p(90)=166.59ms p(95)=193.99ms
     http_req_failed................: 0.00%  ✓ 0         ✗ 2514
     http_req_receiving.............: avg=90.55µs  min=26.89µs med=81.23µs  max=1.33ms   p(90)=115.21µs p(95)=144.25µs
     http_req_sending...............: avg=34.76µs  min=11.84µs med=28.06µs  max=2.37ms   p(90)=40.07µs  p(95)=53.1µs  
     http_req_tls_handshaking.......: avg=0s       min=0s      med=0s       max=0s       p(90)=0s       p(95)=0s      
     http_req_waiting...............: avg=95ms     min=11.27ms med=78.87ms  max=628.2ms  p(90)=166.48ms p(95)=193.9ms 
     http_reqs......................: 2514   41.773143/s
     iteration_duration.............: avg=286.66ms min=184.9ms med=273.19ms max=1.19s    p(90)=348.57ms p(95)=373.73ms
     iterations.....................: 839    13.940997/s
     vus............................: 4      min=4       max=4 
     vus_max........................: 4      min=4       max=4 

@cozminu cozminu requested a review from mkurapov April 9, 2025 11:38
Copy link
Copy Markdown
Contributor

@mkurapov mkurapov 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! will also request @BlairCurrey to take a look

Comment thread packages/backend/src/open_payments/quote/service.ts Outdated
@mkurapov mkurapov requested a review from BlairCurrey April 9, 2025 13:37
Co-authored-by: Max Kurapov <max@interledger.org>
Copy link
Copy Markdown
Contributor

@BlairCurrey BlairCurrey left a comment

Choose a reason for hiding this comment

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

Looks great. Appreciate the detailed description in the PR body.

Comment thread package.json
"path-to-regexp@>=0.1.7": "^0.1.12",
"path-to-regexp@>=6.3.0": "^6.3.0"
"path-to-regexp@>=6.3.0": "^6.3.0",
"next": "^15.2.3"
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.

I assume this was to resolve some issue with the docker trivy scan?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

@cozminu cozminu self-assigned this Apr 11, 2025
@cozminu cozminu merged commit 4905027 into main Apr 11, 2025
44 checks passed
@cozminu cozminu deleted the cozmin/raf-902 branch April 11, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rework Fixed Send Fee Calculation

3 participants