Skip to content
6 changes: 6 additions & 0 deletions packages/swapper/src/swappers/CetusSwapper/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getProvidersExcluding } from '@cetusprotocol/aggregator-sdk'
import { Transaction } from '@cetusprotocol/aggregator-sdk/node_modules/@mysten/sui/transactions'
import { TxStatus } from '@shapeshiftoss/unchained-client'
import { bnOrZero } from '@shapeshiftoss/utils'
Expand All @@ -19,6 +20,7 @@ import { SwapperName } from '../../types'
import { checkSuiSwapStatus, getExecutableTradeStep, isExecutableTradeQuote } from '../../utils'
import { getTradeQuote } from './swapperApi/getTradeQuote'
import { getTradeRate } from './swapperApi/getTradeRate'
import { PYTH_DEPENDENT_PROVIDERS } from './utils/constants'
import { findBestRoute, getAggregatorClient, getCoinType, getSuiClient } from './utils/helpers'

export const cetusApi: SwapperApi = {
Expand Down Expand Up @@ -58,11 +60,15 @@ export const cetusApi: SwapperApi = {
const sellCoinType = getCoinType(sellAsset)
const buyCoinType = getCoinType(buyAsset)

// Exclude Pyth-dependent providers to avoid oracle failures
const providersWithoutPyth = getProvidersExcluding(PYTH_DEPENDENT_PROVIDERS)

const routerData = await findBestRoute(
client,
sellCoinType,
buyCoinType,
sellAmountIncludingProtocolFeesCryptoBaseUnit,
providersWithoutPyth,
)

if (!routerData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { RouterDataV3 } from '@cetusprotocol/aggregator-sdk'
import { getProvidersExcluding } from '@cetusprotocol/aggregator-sdk'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
import type { AssetId } from '@shapeshiftoss/caip'
import { suiAssetId } from '@shapeshiftoss/caip'
import type { Asset } from '@shapeshiftoss/types'
Expand All @@ -8,7 +9,7 @@ import { Err, Ok } from '@sniptt/monads'
import type { ProtocolFee, SwapErrorRight, SwapperDeps } from '../../../types'
import { TradeQuoteError } from '../../../types'
import { getInputOutputRate, makeSwapErrorRight } from '../../../utils'
import { isSupportedChainId } from '../utils/constants'
import { isSupportedChainId, PYTH_DEPENDENT_PROVIDERS } from '../utils/constants'
import { findBestRoute, getAggregatorClient, getCoinType } from '../utils/helpers'

type CetusTradeDataInput = {
Expand Down Expand Up @@ -78,11 +79,15 @@ export const getCetusTradeData = async (
const sellCoinType = getCoinType(sellAsset)
const buyCoinType = getCoinType(buyAsset)

// Exclude Pyth-dependent providers to avoid oracle failures
const providersWithoutPyth = getProvidersExcluding(PYTH_DEPENDENT_PROVIDERS)

const routerData = await findBestRoute(
client,
sellCoinType,
buyCoinType,
sellAmountIncludingProtocolFeesCryptoBaseUnit,
providersWithoutPyth,
)

if (!routerData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export const isSupportedChainId = (
): chainId is (typeof SUPPORTED_CETUS_CHAIN_IDS)[number] => {
return SUPPORTED_CETUS_CHAIN_IDS.includes(chainId)
}

export const PYTH_DEPENDENT_PROVIDERS = ['HAEDALPMM', 'HAEDALHMMV2', 'METASTABLE']
Comment thread
gomesalexandre marked this conversation as resolved.
2 changes: 2 additions & 0 deletions packages/swapper/src/swappers/CetusSwapper/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ export const findBestRoute = async (
sellCoinType: string,
buyCoinType: string,
sellAmountCryptoBaseUnit: string,
providers?: string[],
): Promise<RouterDataV3 | undefined> => {
const routerData = await client.findRouters({
from: sellCoinType,
target: buyCoinType,
amount: sellAmountCryptoBaseUnit,
byAmountIn: true,
...(providers && { providers }),
})

if (!routerData) {
Expand Down