-
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 4 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,25 @@ import type { Asset } from '@shapeshiftoss/types' | |
|
||
import { executeSolanaTransaction } from '../..' | ||
import type { BuyAssetBySellIdInput, Swapper } from '../../types' | ||
import { JUPITER_ERRORS, SolanaLogsError } from './errors' | ||
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 swapperError = JUPITER_ERRORS.find(error => errorMessage.includes(error.value)) | ||
|
||
if (swapperError) throw new SolanaLogsError(swapperError.key) | ||
} | ||
|
||
throw e | ||
} | ||
}, | ||
|
||
filterAssetIdsBySellable: (assets: Asset[]): Promise<AssetId[]> => { | ||
return Promise.resolve( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { SwapperErrorMapping } from '../baseErrors' | ||
import { SWAPPER_ERRORS } from '../baseErrors' | ||
|
||
export class SolanaLogsError extends Error { | ||
constructor(message: string) { | ||
super(message) | ||
this.name = 'SolanaLogsError' | ||
} | ||
} | ||
|
||
export const JUPITER_ERROR_VALUES = { | ||
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. Not sure about the naming here, this is rather a subtring check , maybe something like 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. This also looks better suited to an enum. 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. Changed in 17f168a |
||
SLIPPAGE_TOLERANCE_EXCEEDED: 'SlippageToleranceExceeded', | ||
UNDER_MINIMUM_AMOUNT: 'RequireGteViolated', | ||
CONSUMED_MORE_FEES: 'exceeded CUs meter', | ||
} as const | ||
|
||
export const JUPITER_ERRORS: SwapperErrorMapping[] = [ | ||
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. preferably-blocking: This is redundant.
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. Changed in 17f168a |
||
{ | ||
key: SWAPPER_ERRORS.SLIPPAGE_TOLERANCE_EXCEEDED, | ||
value: JUPITER_ERROR_VALUES.SLIPPAGE_TOLERANCE_EXCEEDED, | ||
}, | ||
{ | ||
key: SWAPPER_ERRORS.UNDER_MINIMUM_AMOUNT, | ||
value: JUPITER_ERROR_VALUES.UNDER_MINIMUM_AMOUNT, | ||
}, | ||
{ | ||
key: SWAPPER_ERRORS.CONSUMED_MORE_FEES, | ||
value: JUPITER_ERROR_VALUES.CONSUMED_MORE_FEES, | ||
}, | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './utils/constants' | ||
export * from './errors' |
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. Also if we use indexes this goes away, feels weird to import and export this guy in the same file ( 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. Removed in 17f168a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export enum SWAPPER_ERRORS { | ||
SLIPPAGE_TOLERANCE_EXCEEDED = 'trade.errors.slippageExceeded', | ||
UNDER_MINIMUM_AMOUNT = 'trade.errors.underMinimumAmount', | ||
CONSUMED_MORE_FEES = 'trade.errors.consumedMoreFees', | ||
} | ||
|
||
export type SwapperErrorMapping = { | ||
key: SWAPPER_ERRORS | ||
value: string | ||
} | ||
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. See https://github.com/shapeshift/web/pull/8433/files#r1894277094, we're effectively reinventing objects. 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. Yeah this is just a 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. Changed in 17f168a |
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 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