-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathOperatorError.ts
More file actions
109 lines (104 loc) 路 5.93 KB
/
Copy pathOperatorError.ts
File metadata and controls
109 lines (104 loc) 路 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
export interface ApiErrorObject {
errorType: ApiErrorCodes
description: string
// TODO: Replace any with proper type definitions
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: any
}
// Conforms to backend API
// https://github.com/cowprotocol/services/blob/d66ff0b0c5a187264f3b0f86810ef04da21255e8/crates/orderbook/openapi.yml#L1214-L1239
export enum ApiErrorCodes {
AlreadyCancelled = 'AlreadyCancelled',
AmountIsZero = 'AmountIsZero',
AppDataHashMismatch = 'AppDataHashMismatch',
AppdataFromMismatch = 'AppdataFromMismatch',
DuplicateOrder = 'DuplicateOrder',
ExcessiveValidTo = 'ExcessiveValidTo',
IncompatibleSigningScheme = 'IncompatibleSigningScheme',
InsufficientAllowance = 'InsufficientAllowance',
InsufficientBalance = 'InsufficientBalance',
InsufficientFee = 'InsufficientFee',
InsufficientValidTo = 'InsufficientValidTo',
InvalidAppData = 'InvalidAppData',
InvalidEip1271Signature = 'InvalidEip1271Signature',
InvalidNativeSellToken = 'InvalidNativeSellToken',
InvalidQuote = 'InvalidQuote',
InvalidSignature = 'InvalidSignature',
MissingFrom = 'MissingFrom',
MissingOrderData = 'MissingOrderData',
NoLiquidity = 'NoLiquidity',
NotFound = 'NotFound',
OrderExpired = 'OrderExpired',
OrderFullyExecuted = 'OrderFullyExecuted',
OrderNotFound = 'OrderNotFound',
QuoteNotFound = 'QuoteNotFound',
SameBuyAndSellToken = 'SameBuyAndSellToken',
SellAmountDoesNotCoverFee = 'SellAmountDoesNotCoverFee',
SellAmountOverflow = 'SellAmountOverflow',
TooManyLimitOrders = 'TooManyLimitOrders',
TransferEthToContract = 'TransferEthToContract',
TransferSimulationFailed = 'TransferSimulationFailed',
UnsupportedBuyTokenDestination = 'UnsupportedBuyTokenDestination',
UnsupportedOrderType = 'UnsupportedOrderType',
UnsupportedSellTokenSource = 'UnsupportedSellTokenSource',
UnsupportedToken = 'UnsupportedToken',
WrongOwner = 'WrongOwner',
ZeroAmount = 'ZeroAmount',
UNHANDLED_GET_ERROR = 'UNHANDLED_GET_ERROR',
UNHANDLED_CREATE_ERROR = 'UNHANDLED_CREATE_ERROR',
UNHANDLED_DELETE_ERROR = 'UNHANDLED_DELETE_ERROR',
}
export enum ApiErrorCodeDetails {
AlreadyCancelled = 'Order is already cancelled.',
AmountIsZero = 'Cannot place order with 0 amounts.',
AppDataHashMismatch = 'AppDataHashMismatch',
AppdataFromMismatch = 'AppdataFromMismatch',
DuplicateOrder = 'There was another identical order already submitted. Please try again.',
ExcessiveValidTo = 'Order expiration too far in the future. Please try again with a shorter expiration.',
IncompatibleSigningScheme = 'IncompatibleSigningScheme',
InsufficientAllowance = 'The account needs to approve the selling token in order to trade.',
InsufficientBalance = "The account doesn't have enough funds.",
InsufficientFee = "The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",
InsufficientValidTo = 'The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.',
InvalidAppData = 'InvalidAppData',
InvalidEip1271Signature = 'InvalidEip1271Signature',
InvalidNativeSellToken = 'InvalidNativeSellToken',
InvalidQuote = 'InvalidQuote',
InvalidSignature = 'The order signature is invalid. Check whether your Wallet app supports off-chain signing.',
MissingFrom = 'MissingFrom',
MissingOrderData = 'The order has missing information.',
NoLiquidity = 'Token pair selected has insufficient liquidity.',
NotFound = 'Token is not found.',
OrderExpired = 'Order is expired.',
OrderFullyExecuted = 'Order is already filled.',
OrderNotFound = 'The order you are trying to cancel does not exist.',
QuoteNotFound = 'Quote expired. Please try again and sign the order faster.',
SameBuyAndSellToken = 'Sell and buy token can not be the same.',
SellAmountDoesNotCoverFee = 'Sell amount does not sufficiently cover the current fee.',
SellAmountOverflow = 'SellAmountOverflow',
TooManyLimitOrders = 'The limit of open limit orders has been reached. You can currently have up to 50 open limit orders.',
TransferEthToContract = 'Sending native currency to smart contract wallets is not currently supported.',
TransferSimulationFailed = 'Transfer simulation of native currency failed. This is likely due to the current unsupported state of smart contract wallets.',
UnsupportedBuyTokenDestination = 'Buy token destination is unsupported. Please try again with a different destination.',
UnsupportedOrderType = 'Order type unsupported. Please try again with a different order type.',
UnsupportedSellTokenSource = 'Sell token source is unsupported. Please try again with a different source.',
UnsupportedToken = 'One of the tokens you are trading is unsupported. Please read the FAQ for more info.',
WrongOwner = "The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CoW Swap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",
ZeroAmount = 'Order amount cannot be zero.',
UNHANDLED_GET_ERROR = 'Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.',
UNHANDLED_CREATE_ERROR = 'The order was not accepted by the network.',
UNHANDLED_DELETE_ERROR = 'The order cancellation was not accepted by the network.',
}
export class OperatorError extends Error {
name = 'OperatorError'
type: ApiErrorCodes
description: ApiErrorObject['description']
constructor(apiError: ApiErrorObject) {
super(apiError.description)
this.type = apiError.errorType
this.description = apiError.description
const message = ApiErrorCodeDetails[apiError.errorType]
// In case we don't have a custom message, use the one provided by the backend in the description
this.message = message === this.type.toString() ? this.description : message
}
}