feat(core,webapp): persist and expose realized profit breakdown#125
Draft
itamarreif wants to merge 1 commit intomainfrom
Draft
feat(core,webapp): persist and expose realized profit breakdown#125itamarreif wants to merge 1 commit intomainfrom
itamarreif wants to merge 1 commit intomainfrom
Conversation
Only the total USDC realized profit was stored. This adds the full
per-token and gas breakdown so it can be displayed alongside expected
profit on the signal detail page.
DB (001_initial.sql):
- Add 9 nullable columns to successful_trade: realized_surplus_{a,b},
realized_usdc_amount_{a,b}, realized_gas_amount_{eth,usdc},
realized_token_usdc_price_{a,b}, realized_gas_price_usdc
Core (database/trade.rs):
- Extend TradeSuccessRow with the new optional fields
- Write all fields from RealizedProfit in insert_successful_trade
- Select new columns in get_successful_by_symbols
Backend (routes/trades.rs):
- Add RealizedProfitDetail response struct
- Include it as Option<RealizedProfitDetail> in SuccessfulTradeResponse
(None for older rows that predate the schema change)
Frontend (types.ts):
- Add RealizedProfitDetail interface
- Add realized_profit_detail: RealizedProfitDetail | null to SuccessfulTrade
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Only the total USDC realized profit was previously stored in
successful_trade. This PR persists the full breakdown and exposes it in the API response so the UI can show it alongside the expected profit on the signal detail page.001_initial.sql): 9 nullable columns added tosuccessful_trade— per-token surplus, per-token USDC amount, gas in ETH and USDC, and the three prices used for conversion. Nullable so existing rows remain valid.database/trade.rs):TradeSuccessRowextended;insert_successful_tradenow writes all fields fromRealizedProfit;get_successful_by_symbolsselects the new columns.routes/trades.rs): newRealizedProfitDetailstruct;SuccessfulTradeResponsegainsrealized_profit_detail: Option<RealizedProfitDetail>(null for pre-migration rows).types.ts):RealizedProfitDetailinterface + updatedSuccessfulTradetype.Test plan
just db-resetto apply the updated schemaGET /trades/successfulreturnsrealized_profit_detailwith all 9 fields populatedrealized_profit_detail: nullwithout erroringcargo clippy -p kuma-core -p kuma-backendpasses🤖 Generated with Claude Code