Open
Conversation
- Add trading.service.ts with buyShares() method for acquiring shares - Implement slippage protection with configurable min shares parameter (5% default) - Create Trade entity records with CONFIRMED status for all buy transactions - Add Share entity creation and updates with cost basis tracking - Update market totalVolume on each buy transaction atomically - Add trading.controller.ts with POST /buy endpoint for HTTP requests - Implement trading routes for buy/sell/odds endpoints - Integrate with Stellar AMM contract for price execution - Use Prisma transactions for data consistency and atomicity - Track user USDC balance changes and position updates - Add comprehensive error handling (insufficient balance, closed markets, slippage) - Add 17 passing integration tests covering all acceptance criteria - All tests verified: buy flow, validation, database updates, share positions Acceptance Criteria Met: Create trading.service.ts with buyShares() method Include slippage protection (min shares param) Record Trade entity in database Update/create Share entity Update market volume Create trading routes and controller Unit + integration tests (17 tests passing)
- Replace hardcoded 90% return with trade-based calculation - Winners receive 1 USDC per share minus configurable platform fees - PnL now reflects actual entry price from AMM odds at time of trade - Add configurable PLATFORM_FEE_PERCENTAGE (default 2%) - Include fallback mechanisms for predictions without trade data - Update e2e test to match new calculation logic - Add comprehensive documentation in SETTLEMENT_PNL_FIX.md This ensures fair payouts based on actual risk/reward at entry time.
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 #92
@GoSTEAN Pls Review Pr
i Just Fixed settle Predictions — hardcoded PnL calculation