Repository navigation
fix(offramp): require coin on GET /offramp/rate and return naira per unit of that asset - #257
Open
Daveeee-tech wants to merge 2 commits into
Open
Daveeee-tech wants to merge 2 commits into
Daveeee-tech wants to merge 2 commits into
Conversation
…acle656#237) GET /offramp/rate previously called Linq's /b2b/rate which always returns naira per dollar. Dividing a naira amount by that gives the right USDC figure by coincidence (1 USDC = 1 USD) but the wrong figure for any other asset by exactly that asset's price — the same defect that caused the onramp to buy 0.6 XLM instead of 3.6 for a 1000 NGN purchase. Changes: - src/api/ngn.ts: export ngnPerCoin so the offramp can reuse the same price path - src/api/offramp.ts: require coin query param (400 without it), call ngnPerCoin(), cache per-coin, response is { coin, rate, indicative: true } - src/__tests__/routes/offramp.test.ts: add 7 tests pinning XLM vs USDC rates differ, 400 on missing/unknown coin, no currency field, 502 on pricing failure - src/openapi/schemas.ts: add offrampRateQuerySchema, update offrampRateResponseSchema (coin enum, rate description, drop currency) - src/openapi/build.ts: add request.query to /offramp/rate registration, update summary - openapi.json: regenerated to match new schema
|
@Daveeee-tech Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #237
Summary
GET /offramp/ratetook no coin and passed through whatever the provider's/b2b/ratereturned. ForUSDSUIthat is naira per dollar, which a client can mistake for naira per unit of any other asset. The onramp had the same defect and it cost real money (₦1,000 bought 0.6 XLM instead of 3.6). The onramp now refuses requests without a coin. This PR gives the offramp the same treatment.The endpoint now requires a
coin, prices it through the existingngnPerCoinhelper from the onramp side (no second price path), and states which asset it priced. A request with no coin is refused, so a dollar rate can no longer be returned silently. The web wallet is updated in the same change so cash-out keeps quoting correctly.What changed
GET /offramp/rate: requirescoin. A missing or unsupported coin returns a 400 with an explanation, mirroringGET /onramp/rate(including the comment explaining why).ngnPerCoin, shared with the onramp. No new pricing logic.{ "coin": "XLM", "currency": "NGN", "rate": <naira per 1 XLM>, "indicative": true }frontend/wallet/lib/offramp.ts:<confirm after grepping, list any others>.frontend/wallet/lib/offramp.ts: now passescoinon every rate request. The cash-out flow is USDC-only today, so it passesUSDCand quotes the same as before.<updated spec for the new required param, if the route is documented there>.Behaviour
/offramp/rate(no coin)/offramp/rate?coin=USDC/offramp/rate?coin=XLMTests
offramp.tstest or manual check: cash-out still quotes correctly withcoinpassednpm testrun before and after:<N passing / failing before>then<N passing / failing after>openapiCoverage.test.tsis red onmainbefore this change (W082's scope) and is unchanged by this PRAll tests mock
global.fetch, following the existing suites. No test or code path reaches the provider.Safety notes
Notes for reviewers
GET /onramp/rate; the validation and error shape are intentionally identical./offramp/ratewithout a coin. The wallet is the only known caller and is updated here:<confirm>.