Skip to content
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

chore: release v1.726.0 #8454

Merged
merged 14 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/swapper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './thorchain-utils'
export * from './cowswap-utils'
export * from './safe-utils'
export * from './swappers/CowSwapper'
export * from './swappers/JupiterSwapper'
26 changes: 25 additions & 1 deletion packages/swapper/src/swappers/JupiterSwapper/JupiterSwapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
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(
Expand Down
28 changes: 28 additions & 0 deletions packages/swapper/src/swappers/JupiterSwapper/errorPatterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export class SolanaLogsError extends Error {
constructor(name: string) {
super(name)
this.name = name
}
}

export enum JUPITER_ERROR_PATTERNS {
SLIPPAGE_TOLERANCE_EXCEEDED = 'SlippageToleranceExceeded',
JUPITER_SLIPPAGE_ERROR_CODE = '0x1771',
UNDER_MINIMUM_AMOUNT = 'RequireGteViolated',
CONSUMED_MORE_FEES = 'exceeded CUs meter',
}

export enum JUPITER_ERROR_NAME {
SLIPPAGE_TOLERANCE_EXCEEDED = 'SlippageToleranceExceeded',
UNDER_MINIMUM_AMOUNT = 'UnderMinimumAmount',
CONSUMED_MORE_FEES = 'ConsumedMoreFees',
}

export const JUPITER_ERRORS: Record<JUPITER_ERROR_PATTERNS | string, string> = {
[JUPITER_ERROR_PATTERNS.SLIPPAGE_TOLERANCE_EXCEEDED]:
JUPITER_ERROR_NAME.SLIPPAGE_TOLERANCE_EXCEEDED,
[JUPITER_ERROR_PATTERNS.JUPITER_SLIPPAGE_ERROR_CODE]:
JUPITER_ERROR_NAME.SLIPPAGE_TOLERANCE_EXCEEDED,
[JUPITER_ERROR_PATTERNS.UNDER_MINIMUM_AMOUNT]: JUPITER_ERROR_NAME.UNDER_MINIMUM_AMOUNT,
[JUPITER_ERROR_PATTERNS.CONSUMED_MORE_FEES]: JUPITER_ERROR_NAME.CONSUMED_MORE_FEES,
}
2 changes: 2 additions & 0 deletions packages/swapper/src/swappers/JupiterSwapper/index.ts
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
Expand Up @@ -43,7 +43,6 @@ type GetJupiterSwapArgs = {
fromAddress: string
rawQuote: unknown
toAddress?: string
useSharedAccounts: boolean
feeAccount: string | undefined
}

Expand Down Expand Up @@ -81,15 +80,13 @@ export const getJupiterSwapInstructions = ({
fromAddress,
toAddress,
rawQuote,
useSharedAccounts,
feeAccount,
}: GetJupiterSwapArgs): Promise<
Result<AxiosResponse<SwapInstructionsResponse, any>, SwapErrorRight>
> =>
jupiterService.post<SwapInstructionsResponse>(`${apiUrl}/swap-instructions`, {
userPublicKey: fromAddress,
destinationTokenAccount: toAddress,
useSharedAccounts,
quoteResponse: rawQuote,
dynamicComputeUnitLimit: true,
prioritizationFeeLamports: 'auto',
Expand Down Expand Up @@ -274,10 +271,6 @@ export const createSwapInstructions = async ({
fromAddress: sendAddress,
toAddress: isCrossAccountTrade ? destinationTokenAccount?.toString() : undefined,
rawQuote: priceResponse,
// It would be better to use this only if routes number are > 1 and for cross account trades,
// but Jupiter has a bug under the hood when swapping SPL to Token2022 and taking referral fees
// Also it reduce sol numbers and compute units in the end, so TXs fees are smaller
useSharedAccounts: true,
feeAccount: affiliateBps !== '0' && tokenAccount ? tokenAccount.toString() : undefined,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"ETH.SNX-0XC011A73EE8576FB46F5E1C5751CA3B9FE0AF2A6F": "eip155:1/erc20:0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",
"ETH.TGT-0X108A850856DB3F85D0269A2693D896B394C80325": "eip155:1/erc20:0x108a850856db3f85d0269a2693d896b394c80325",
"ETH.THOR-0XA5F2211B9B8170F694421F2046281775E8468044": "eip155:1/erc20:0xa5f2211b9b8170f694421f2046281775e8468044",
"ETH.UOS-0XD13C7342E1EF687C5AD21B27C2B65D772CAB5C8C": "eip155:1/erc20:0xd13c7342e1ef687c5ad21b27c2b65d772cab5c8c",
"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48": "eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"ETH.USDP-0X8E870D67F660D95D5BE530380D0EC0BD388289E1": "eip155:1/erc20:0x8e870d67f660d95d5be530380d0ec0bd388289e1",
"ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7": "eip155:1/erc20:0xdac17f958d2ee523a2206206994597c13d831ec7",
Expand Down
Loading
Loading