-
Notifications
You must be signed in to change notification settings - Fork 192
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
fix: parse jupiter errors to human readable translations #8433
base: develop
Are you sure you want to change the base?
Changes from all commits
59e9a58
e2ee21d
98d42b4
2de18a2
17f168a
8ed7c3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,34 @@ import type { Asset } from '@shapeshiftoss/types' | |
|
||
import { executeSolanaTransaction } from '../..' | ||
import type { BuyAssetBySellIdInput, Swapper } from '../../types' | ||
import { JUPITER_ERRORS, SolanaLogsError } from './errorPatterns' | ||
import { jupiterSupportedChainIds } from './utils/constants' | ||
|
||
export const jupiterSwapper: Swapper = { | ||
executeSolanaTransaction, | ||
executeSolanaTransaction: async (...args) => { | ||
try { | ||
const txid = await executeSolanaTransaction(...args) | ||
return txid | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove me, all errors are |
||
const errorMessage = e.message | ||
const swapperErrorType = Object.keys(JUPITER_ERRORS).reduce( | ||
(acc, errorPattern) => { | ||
if (errorMessage.includes(errorPattern)) { | ||
acc = JUPITER_ERRORS[errorPattern] | ||
} | ||
|
||
return acc | ||
}, | ||
undefined as undefined | string, | ||
) | ||
|
||
if (swapperErrorType) throw new SolanaLogsError(swapperErrorType) | ||
} | ||
|
||
throw e | ||
} | ||
}, | ||
|
||
filterAssetIdsBySellable: (assets: Asset[]): Promise<AssetId[]> => { | ||
return Promise.resolve( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export class SolanaLogsError extends Error { | ||
constructor(name: string) { | ||
super(name) | ||
this.name = name | ||
} | ||
} | ||
|
||
export enum JUPITER_ERROR_PATTERNS { | ||
SLIPPAGE_TOLERANCE_EXCEEDED = 'SlippageToleranceExceeded', | ||
UNDER_MINIMUM_AMOUNT = 'RequireGteViolated', | ||
CONSUMED_MORE_FEES = 'exceeded CUs meter', | ||
} | ||
|
||
export enum JUPITER_ERROR_NAMES { | ||
SLIPPAGE_TOLERANCE_EXCEEDED = 'SlippageToleranceExceeded', | ||
UNDER_MINIMUM_AMOUNT = 'UnderMinimumAmount', | ||
CONSUMED_MORE_FEES = 'ConsumedMoreFees', | ||
} | ||
Comment on lines
+8
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: don't pluralize enums |
||
|
||
export const JUPITER_ERRORS: Record<JUPITER_ERROR_PATTERNS | string, string> = { | ||
[JUPITER_ERROR_PATTERNS.SLIPPAGE_TOLERANCE_EXCEEDED]: | ||
JUPITER_ERROR_NAMES.SLIPPAGE_TOLERANCE_EXCEEDED, | ||
[JUPITER_ERROR_PATTERNS.UNDER_MINIMUM_AMOUNT]: JUPITER_ERROR_NAMES.UNDER_MINIMUM_AMOUNT, | ||
[JUPITER_ERROR_PATTERNS.CONSUMED_MORE_FEES]: JUPITER_ERROR_NAMES.CONSUMED_MORE_FEES, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './utils/constants' | ||
export * from './errorPatterns' |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -974,7 +974,10 @@ | |||||
"unsafeQuote": "This amount is below the recommended minimum for this pair (%{recommendedMin} %{symbol}). This could cause your trade to fail or loss of funds.", | ||||||
"rateLimitExceeded": "Rate limit exceeded, try again later", | ||||||
"maxSlippageExceededWithExpectedSlippage": "The maximum allowed slippage tolerance for this trade has been exceeded during simulation. Expected slippage: %{expectedSlippage}%. Try again with a higher slipppage tolerance.", | ||||||
"executionRevertedWithExpectedSlippage": "Execution reverted during execution. This may be due to insufficient slippage tolerance. Expected slippage: %{expectedSlippage}%. Try again with a higher slipppage tolerance." | ||||||
"executionRevertedWithExpectedSlippage": "Execution reverted during execution. This may be due to insufficient slippage tolerance. Expected slippage: %{expectedSlippage}%. Try again with a higher slipppage tolerance.", | ||||||
"slippageExceeded": "Slippage tolerance exceeded.", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"underMinimumAmount": "One or more of the assets in this trade are below the minimum amount required for this trade.", | ||||||
"consumedMoreFees": "The transaction did revert because the fees consumed by this trade were higher than expected." | ||||||
}, | ||||||
"swappingComingSoonForWallet": "Swapping for %{walletName} is coming soon", | ||||||
"recentTrades": "Recent Trades", | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { JUPITER_ERROR_NAMES } from '@shapeshiftoss/swapper' | ||
|
||
export const jupiterErrorNamesToTranslationKeys: Record<string, string> = { | ||
[JUPITER_ERROR_NAMES.SLIPPAGE_TOLERANCE_EXCEEDED]: 'trade.errors.slippageExceeded', | ||
[JUPITER_ERROR_NAMES.UNDER_MINIMUM_AMOUNT]: 'trade.errors.underMinimumAmount', | ||
[JUPITER_ERROR_NAMES.CONSUMED_MORE_FEES]: 'trade.errors.consumedMoreFees', | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used again in 2de18a2