Skip to content
15 changes: 15 additions & 0 deletions packages/swapper/src/swappers/CetusSwapper/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Transaction } from '@cetusprotocol/aggregator-sdk/node_modules/@mysten/sui/transactions'

Check failure on line 1 in packages/swapper/src/swappers/CetusSwapper/endpoints.ts

View workflow job for this annotation

GitHub Actions / Call / Static

Run autofix to sort these imports!
import { getProvidersExcluding } from '@cetusprotocol/aggregator-sdk'
import { TxStatus } from '@shapeshiftoss/unchained-client'
import { bnOrZero } from '@shapeshiftoss/utils'
import type { Result } from '@sniptt/monads'
Expand All @@ -21,6 +22,16 @@
import { getTradeRate } from './swapperApi/getTradeRate'
import { findBestRoute, getAggregatorClient, getCoinType, getSuiClient } from './utils/helpers'

// DEX providers that require Pyth oracle price feeds for transaction construction
// These are excluded to avoid failures when Pyth's public endpoint is unavailable
// See: https://cetus-1.gitbook.io/cetus-developer-docs/developer/cetus-aggregator/features-available
// Docs: "Some providers, such as Headalpmm and Metastable, rely on Pyth oracle prices"
const PYTH_DEPENDENT_PROVIDERS = [
'HAEDALPMM', // Haedal PMM (explicitly mentioned in docs)

Check failure on line 30 in packages/swapper/src/swappers/CetusSwapper/endpoints.ts

View workflow job for this annotation

GitHub Actions / Call / Static

Delete `·····`
'HAEDALHMMV2', // Haedal HMM V2 (variant of HAEDALPMM)

Check failure on line 31 in packages/swapper/src/swappers/CetusSwapper/endpoints.ts

View workflow job for this annotation

GitHub Actions / Call / Static

Delete `···`
'METASTABLE', // Metastable pools (explicitly mentioned in docs)

Check failure on line 32 in packages/swapper/src/swappers/CetusSwapper/endpoints.ts

View workflow job for this annotation

GitHub Actions / Call / Static

Delete `····`
]

export const cetusApi: SwapperApi = {
getTradeQuote: (
input: CommonTradeQuoteInput,
Expand Down Expand Up @@ -58,11 +69,15 @@
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 @@ -11,6 +12,16 @@
import { isSupportedChainId } from '../utils/constants'
import { findBestRoute, getAggregatorClient, getCoinType } from '../utils/helpers'

// DEX providers that require Pyth oracle price feeds for transaction construction
// These are excluded to avoid failures when Pyth's public endpoint is unavailable
// See: https://cetus-1.gitbook.io/cetus-developer-docs/developer/cetus-aggregator/features-available
// Docs: "Some providers, such as Headalpmm and Metastable, rely on Pyth oracle prices"
const PYTH_DEPENDENT_PROVIDERS = [
'HAEDALPMM', // Haedal PMM (explicitly mentioned in docs)

Check failure on line 20 in packages/swapper/src/swappers/CetusSwapper/swapperApi/getCetusTradeData.ts

View workflow job for this annotation

GitHub Actions / Call / Static

Delete `·····`
'HAEDALHMMV2', // Haedal HMM V2 (variant of HAEDALPMM)

Check failure on line 21 in packages/swapper/src/swappers/CetusSwapper/swapperApi/getCetusTradeData.ts

View workflow job for this annotation

GitHub Actions / Call / Static

Delete `···`
'METASTABLE', // Metastable pools (explicitly mentioned in docs)

Check failure on line 22 in packages/swapper/src/swappers/CetusSwapper/swapperApi/getCetusTradeData.ts

View workflow job for this annotation

GitHub Actions / Call / Static

Delete `····`
]

type CetusTradeDataInput = {
sellAsset: Asset
buyAsset: Asset
Expand Down Expand Up @@ -78,11 +89,15 @@
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
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
Loading