feat(exchange): real on-chain buy/sell + live UZS price - #48
Merged
Conversation
Stage 5 (scope-C, final screen). Replace the hardcoded $85 exchange screen (the /exchange/* endpoints never existed -> 404 -> frontend fallbacks) with the real on-chain price and a real two-step swap signed by the user's wallet. - contracts: UZD -> V3.1 (was retired V2); add EXCHANGE + EXCHANGE_ABI - chain: approveForExchange / exchangeBuy / exchangeSell (viem, wallet-signed) - api: getRates (public /rates) + getQuote (auth /quote); drop the dead getPrice/getOrderbook/getSwapQuote/executeSwap - format: computeMinOut (client-side slippage floor from estimated_out_wei) + vitest - exchange page: price from /rates in UZS (no $, no fake bid/ask spread); quote from /quote; swap = approve -> buy/sell, each receipt-gated (status==success), pending by step; minOut with 1% slippage (buy minOltinOut>0); on-chain error mapping (stale/treasury/dust/gas, approve-already-spent note); wei amounts (parseTokenAmount), balance checked in wei - useRates hook; Rates/Quote types
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.
Stage 5 (scope-C, final screen). Real on-chain price (/rates, UZS) + real two-step swap (approve → Exchange.buy/sell) signed by the wallet, replacing the hardcoded $85 fallbacks. Frontend-only (backend /rates+/quote already exist). Gate-2 APPROVED (/security-review + /typescript-review clean; 2 suggestions applied: fresh quote before signing + quote.side check). Gates: tsc + eslint 0 err + vitest 21/21 (computeMinOut red→green). On-chain staging proven: BUY 1000 UZD→+0.000634 OLTIN minted; SELL 0.1 OLTIN→+157603.83 UZD from treasury; all receipts success. Report: .claude/reports/2026-07-29-stage5-exchange.md. FLAGGED follow-up (Reviewer, pre-demo priority): history feed misrepresents multi-token swap/transfer events by symbol.