Repository navigation
fix(perps): clarify IOC and price movement failures #10385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
geositta
wants to merge
10
commits into
main
Choose a base branch
from
feat/perps-ioc-price-movement-failures
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+421
−62
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30d2e84
fix: fix(perps): clarify IOC and price movement failures
geositta 5b8e685
chore: add file
geositta c6940e4
fix(perps): clarify price movement failures
geositta 4792008
fix(perps): rm slippage param
geositta e20b9e6
chore: linting
geositta d6510bd
chore: test updates
geositta ddfefc3
chore: update changelog
geositta a8644e3
fix(perps-controller): classify thrown partial closes from requested …
geositta d5a350f
fix(perps): preserve exact-size retry semantics
geositta 9f1b078
Merge remote-tracking branch 'origin/main' into feat/perps-ioc-price-…
geositta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { PERPS_ERROR_CODES } from './perpsErrorCodes.js'; | ||
| import type { PerpsErrorCode } from './perpsErrorCodes.js'; | ||
|
|
||
| /** | ||
| * Details for a local price movement rejection. | ||
| * | ||
| * The numeric values are kept unformatted so clients can localize and format | ||
| * them for their own surfaces while the legacy error string remains available. | ||
| */ | ||
| export type PriceMovedErrorDetails = { | ||
| code: typeof PERPS_ERROR_CODES.PRICE_MOVED; | ||
| priceDeltaBps: number; | ||
| maxSlippageBps: number; | ||
| expectedPrice: number; | ||
| currentPrice: number; | ||
| }; | ||
|
|
||
| export type PerpsErrorDetails = PriceMovedErrorDetails; | ||
|
|
||
| export type PerpsErrorResultFields = { | ||
| errorCode?: PerpsErrorCode; | ||
| errorDetails?: PerpsErrorDetails; | ||
| }; | ||
|
|
||
| /** | ||
| * Error that preserves a stable client-facing code and optional structured | ||
| * details across provider and controller error boundaries. | ||
| */ | ||
| export class PerpsControllerError extends Error { | ||
| readonly errorCode: PerpsErrorCode; | ||
|
|
||
| readonly errorDetails?: PerpsErrorDetails; | ||
|
|
||
| constructor( | ||
| errorCode: PerpsErrorCode, | ||
| message: string, | ||
| errorDetails?: PerpsErrorDetails, | ||
| ) { | ||
| super(message); | ||
| this.name = 'PerpsControllerError'; | ||
| this.errorCode = errorCode; | ||
| this.errorDetails = errorDetails; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a normalized local price movement error. | ||
| * | ||
| * @param params - Price movement context. | ||
| * @param params.expectedPrice - Price used when the order was sized. | ||
| * @param params.currentPrice - Current price used for submission. | ||
| * @param params.formattedExpectedPrice - Provider-formatted expected price. | ||
| * @param params.formattedCurrentPrice - Provider-formatted current price. | ||
| * @param params.priceDeltaBps - Absolute price movement in basis points. | ||
| * @param params.maxSlippageBps - Maximum allowed movement in basis points. | ||
| * @returns A structured price movement error. | ||
| */ | ||
| export function createPriceMovedError(params: { | ||
| expectedPrice: number; | ||
| currentPrice: number; | ||
| formattedExpectedPrice: string; | ||
| formattedCurrentPrice: string; | ||
| priceDeltaBps: number; | ||
| maxSlippageBps: number; | ||
| }): PerpsControllerError { | ||
| const { | ||
| expectedPrice, | ||
| currentPrice, | ||
| formattedExpectedPrice, | ||
| formattedCurrentPrice, | ||
| priceDeltaBps, | ||
| maxSlippageBps, | ||
| } = params; | ||
|
|
||
| return new PerpsControllerError( | ||
| PERPS_ERROR_CODES.PRICE_MOVED, | ||
| `Price moved too much: ${priceDeltaBps.toFixed(0)} bps (max: ${maxSlippageBps} bps). ` + | ||
| `Expected: ${formattedExpectedPrice}, Current: ${formattedCurrentPrice}`, | ||
| { | ||
| code: PERPS_ERROR_CODES.PRICE_MOVED, | ||
| priceDeltaBps, | ||
| maxSlippageBps, | ||
| expectedPrice, | ||
| currentPrice, | ||
| }, | ||
| ); | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.