Repository navigation
fix(hypercore): index outcome sides by position and model outcome settlement - #97
Merged
Merged
Conversation
…tlement outcomes() treated a side as side 0 only if it was named exactly "Yes". Template outcomes name their sides "template:Yes" and "template:No", or after the participants, so both of their sides got the second side's asset index: 157 of the 296 outcomes on mainnet. An order placed with the first side's OutcomeMarket traded the other side. Sides are now indexed by their position in side_specs, as the asset encoding 10 * outcome + side expects. - OutcomeInfo carries the quoteToken, venue and deployerFeeScale that outcomeMeta returns, and implements Deserialize - HttpClient::settled_outcome returns Option<SettledOutcome> instead of raw JSON: the spec, settle fraction, details and, for an outcome in a question, the question's state. null means not settled
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.
outcomes()treated a side as side 0 only if it was named exactly"Yes". Template outcomes name their sidestemplate:Yesandtemplate:No, or after the participants (template:{shortNameA}), so both of their sides got the second side's asset index. On mainnet that is 157 of the 296 outcomes listed today. An order placed with the first side'sOutcomeMarkettraded the other side, and the first side could not be reached at all.The asset encoding is
10 * outcome + side, wheresideis the position insideSpecs, so sides are now indexed by position. Settlement fills agree: across 60 settled mainnet outcomes, 58 of them templates, every#<outcome>0fill settled at the outcome'ssettleFractionand every#<outcome>1fill at1 - settleFraction.Two more gaps I hit while building a HIP-4 settlement keeper on the SDK, which reads both endpoints as raw JSON for now:
outcomeMetareturnsquoteToken,venueanddeployerFeeScalefor each outcome, and the SDK dropped them.OutcomeInfonow carries all three, and implementsDeserialize.venueanddeployer_fee_scaleare optional: on mainnet, the 8 daily "Recurring" outcomes (BTC, ETH, SOL and HYPE) have no venue, and 72 outcomes have no fee scale.settled_outcomereturned raw JSON. It now returnsOption<SettledOutcome>: the outcome'sspec, itssettle_fraction, the deployer'sdetailsand, for an outcome in a question, the question with itsOutcomeQuestionState(ActiveorSettled, with any other shape kept as raw JSON). The exchange answersnullfor an outcome that has not settled or does not exist, which isNone.Breaking:
HttpClient::settled_outcomereturnsOption<SettledOutcome>instead ofserde_json::Value.OutcomeInfogainedquote_token,venueanddeployer_fee_scale, so struct literals need them.Verified:
cargo test --lib: 185 passed, 5 ignored (the live audits). New:outcome_markets_index_sides_by_position,outcome_info_deserialize_venue_fields,settled_outcome_deserializeandoutcome_question_state_keeps_unknown_shapes, using payloads copied from mainnet and testnet.test_http_outcome_markets_are_distinct(mainnet and testnet) passes here. With the old name check put back, it fails on mainnet with 435 distinct indices for 592 sides, andoutcome_markets_index_sides_by_positionfails too.test_http_undocumented_typed_responsesalso parsessettled_outcome(9)and checks that an unknown ID isNone.cargo clippy -p hypersdk --all-targets: no new warnings.cd hypecli && cargo checkpasses.cargo +nightly fmt. Nightly's import reorder intypes/deploy.rsis left out.