Repository navigation
Conversation
Contributor
Author
|
this PR is ready for another review. I resolved the merge conflicts with the develop branch (pushed 0612726). |
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.
Overview
This PR adds an on-chain exact-share selling path (
sell_shares/quote_sell_shares) backed by a pool-favoring integer square root, so clients no longer have to invert the constant-product curve off-chain to sell an exact number of shares or fully close a position. The Python model and frontend integration docs are updated to mirror and document the new arithmetic.Related Issue
Changes
🧮 Exact-share selling math
oracledesk-stellar/model/fpmm_model.pycalc_sell_sharesmirroring the Rustmath::calc_sell_sharesbit-for-bit: computes the discriminant with the sameb = r_sold + shares_in + r_other/D = b^2 - 4*r_other*shares_informulation, usesmath.isqrtfor the seed, and applies the same pool-favoring correction loop (notisqrtalone) so results match Rust exactly._check_sell_shares_known_values,_check_sell_shares_k_non_decreasing, and_check_sell_shares_never_beats_calc_selland wires them intorun_all()so the model validates the new function against pinned fixtures, thek-never-decreases invariant, and the "never pays more thancalc_sellcharges for the same shares" property.📚 Docs
oracledesk-stellar/docs/frontend-integration.mdsell_shares(trader, market_id, outcome, shares_in, min_collateral_out)andquote_sell_shares, replacing the three-step off-chain workaround (read reserves → invert curve → padmax_shares_in).shares_in == held) that leaves no dust inDataKey::Position.agents/core/src/fpmm.tspath toagents/core/fpmm.ts.Verification Results
calc_sell_sharesmirrored in Python with the same correction loopmodel/fpmm_model.pyknever decreases and never beatscalc_sell_check_sell_shares_k_non_decreasing,_check_sell_shares_never_beats_calc_sell_check_sell_shares_known_valuesdocs/frontend-integration.mddocumentssell_sharesagents/core/src/fpmm.tspath fixedagents/core/fpmm.tsNotes
This PR covers the Python mirror and the frontend docs from the issue. The Rust
math::isqrt/calc_sell_shares, theMarketCore::sell_shares/quote_sell_sharesentrypoints, the TypeScript mirror inagents/core/fpmm.ts, the regenerated bindings, and the refreshed vendoredmarket_core.wasmcopies are tracked separately and are not part of this change set.Closes #2