Skip to content

Commit

Permalink
feat(errror): add NOT_ENOUGH_MINIMUM_REQUIRED_MARGIN_ERROR
Browse files Browse the repository at this point in the history
  • Loading branch information
lsps9150414 committed Jul 4, 2022
1 parent ff292bc commit d32361a
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 @@ -32,6 +32,7 @@ export enum ContractErrorCode {
NON_EXISTENT_OPEN_ORDER = "OB_NEO",
MARKET_NUMBER_EXCEEDS = "AB_MNE",
OVER_MAXIMUM_PRICE_SPREAD = "CH_OMPS",
NOT_ENOUGH_MINIMUM_REQUIRED_MARGIN = "CH_NEMRM",

/* UNISWAP ERROR */
LIQUIDITY_MATH_ERROR_LS = "LS", // https://github.com/Uniswap/v3-core/blob/f03155670ec1667406b83a539e23dcccf32a03bc/contracts/libraries/LiquidityMath.sol#L12
Expand Down Expand Up @@ -73,6 +74,7 @@ export enum ErrorName {
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",
NOT_ENOUGH_MINIMUM_REQUIRED_MARGIN_ERROR = "not_enough_minimum_required_margin_error",

/* UNISWAP Error*/
UNISWAP_ERROR = "uniswap_error",
Expand Down Expand Up @@ -381,6 +383,13 @@ export class OverMaximumPriceSpreadError extends ContractWriteError<ClearingHous
}
}

export class NotEnoughMinimumRequiredMarginError extends ContractWriteError<ClearingHouse> {
constructor(data: ContractWriteErrorParams<keyof ClearingHouse>) {
super({ ...data })
this.name = ErrorName.NOT_ENOUGH_MINIMUM_REQUIRED_MARGIN_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 @@ -19,6 +19,7 @@ import {
isRpcNativeUserDeniedError,
MarketNumberExceedsError,
OverMaximumPriceSpreadError,
NotEnoughMinimumRequiredMarginError,
} from "../errors"
import { ClearingHouse, Exchange, OrderBook } from "../contracts/type"

Expand Down Expand Up @@ -106,6 +107,10 @@ export function getTransactionErrorFactory({
ErrorClass = OverMaximumPriceSpreadError
break
}
case ContractErrorCode.NOT_ENOUGH_MINIMUM_REQUIRED_MARGIN: {
ErrorClass = NotEnoughMinimumRequiredMarginError
break
}
default: {
ErrorClass = ContractWriteError
}
Expand Down

0 comments on commit d32361a

Please sign in to comment.