Fix market order price rounding for builder-deployed perp dexs - #311
Open
pucedoteth wants to merge 1 commit into
Open
Fix market order price rounding for builder-deployed perp dexs#311pucedoteth wants to merge 1 commit into
pucedoteth wants to merge 1 commit into
Conversation
_slippage_price classifies an asset as spot with `asset >= 10_000`, but builder-deployed (HIP-3) perp dex assets start at 110000, so they are also caught by that check. Those perps are then rounded to 8 - szDecimals decimals instead of 6 - szDecimals, and market_open/market_close can produce a price with too many decimal places, which the exchange rejects. Spot asset ids live in [10000, 110000), so bound the check on both sides.
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.
Problem
Exchange._slippage_pricedecides how many decimal places a market-order price may have:Spot asset ids are
index + 10000, but builder-deployed (HIP-3) perp dex asset ids are110000 + i * 10000 + index(seeInfo.__init__). Those are also>= 10_000, so every HIP-3 perp is classified as spot and rounded to8 - szDecimalsdecimals instead of6 - szDecimals.market_open/market_closeon a HIP-3 dex can therefore build a price with more decimal places than perps allow, and the exchange rejects the order. For an asset withszDecimals == 0and a mid of0.0012345678, a 5% buy slippage price comes out as0.0012963(7 decimals) where the perp limit is 6.#225 fixed the
all_midslookup for HIP-3 dexs but left this check untouched.Fix
Spot asset ids live in
[10000, 110000), so bound the check on both sides:Tests
Adds
tests/exchange_test.pycovering_slippage_pricefor a perp, a spot pair, and a builder-deployed perp asset. The last one fails onmaster(0.0012963 != 0.001296) and passes with the fix. The existing suite still passes (39 tests).