Skip to content

Commit

Permalink
Merge pull request #76 from perpetual-protocol/feature/handle-CH_OMPS…
Browse files Browse the repository at this point in the history
…-error-code

feat(error): add OVER_MAXIMUM_PRICE_SPREAD_ERROR
  • Loading branch information
lsps9150414 authored Jun 30, 2022
2 parents a46db17 + f4a11ea commit 615fed2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/errors/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum ContractErrorCode {
NOT_ENOUGH_LIQUIDITY = "OB_NEL",
NON_EXISTENT_OPEN_ORDER = "OB_NEO",
MARKET_NUMBER_EXCEEDS = "AB_MNE",
OVER_MAXIMUM_PRICE_SPREAD = "CH_OMPS",

/* UNISWAP ERROR */
LIQUIDITY_MATH_ERROR_LS = "LS", // https://github.com/Uniswap/v3-core/blob/f03155670ec1667406b83a539e23dcccf32a03bc/contracts/libraries/LiquidityMath.sol#L12
Expand Down Expand Up @@ -71,6 +72,7 @@ export enum ErrorName {
NOT_ENOUGH_LIQUIDITY_ERROR = "not_enough_liquidity_error",
NON_EXISTENT_OPEN_ORDER_ERROR = "non_existent_open_order_error",
MARKET_NUMBER_EXCEEDS_ERROR = "market_number_exceeds_error",
OVER_MAXIMUM_PRICE_SPREAD_ERROR = "over_maximum_price_spread_error",

/* UNISWAP Error*/
UNISWAP_ERROR = "uniswap_error",
Expand Down Expand Up @@ -372,6 +374,13 @@ export class MarketNumberExceedsError extends ContractWriteError<AccountBalance>
}
}

export class OverMaximumPriceSpreadError extends ContractWriteError<ClearingHouse> {
constructor(data: ContractWriteErrorParams<keyof ClearingHouse>) {
super({ ...data })
this.name = ErrorName.OVER_MAXIMUM_PRICE_SPREAD_ERROR
}
}

// NOTE: if wanna see the detail message of uniswap error, see the rawError fields
export class UniswapV3Error extends ContractWriteError<ClearingHouse> {
constructor(data: ContractWriteErrorParams<keyof ClearingHouse>) {
Expand Down
5 changes: 5 additions & 0 deletions src/transactionSender/errorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
isRpcNativeGasTooLowError,
isRpcNativeUserDeniedError,
MarketNumberExceedsError,
OverMaximumPriceSpreadError,
} from "../errors"
import { ClearingHouse, Exchange, OrderBook } from "../contracts/type"

Expand Down Expand Up @@ -101,6 +102,10 @@ export function getTransactionErrorFactory({
ErrorClass = MarketNumberExceedsError
break
}
case ContractErrorCode.OVER_MAXIMUM_PRICE_SPREAD: {
ErrorClass = OverMaximumPriceSpreadError
break
}
default: {
ErrorClass = ContractWriteError
}
Expand Down

0 comments on commit 615fed2

Please sign in to comment.