import type { SuiClient } from '@mysten/sui/client'; import type { Transaction } from '@mysten/sui/transactions'; import type { TransactionResult } from '@mysten/sui/transactions'; import { returnMergedCoins } from 'navi-sdk'; async function getCoinDetails( client: SuiClient, address: string, coinType: any = '0x2::sui::SUI', ) { const coinAddress = coinType.address ? coinType.address : coinType; const coinDetails = await client.getCoins({ owner: address, coinType: coinAddress, }); return coinDetails; } export async function getCoinPTB( address: string, coin: string, amountIn: number | string | bigint, txb: Transaction, client: SuiClient, ) { let coinA: TransactionResult; if (coin === '0x2::sui::SUI') { coinA = txb.splitCoins(txb.gas, [txb.pure.u64(amountIn)]); } else { const coinInfo = await getCoinDetails(client, address, coin); // Check if user has enough balance for tokenA if (!coinInfo.data[0]) { throw new Error('Insufficient balance for this coin'); } // Merge coins if necessary, to cover the amount needed const mergedCoin = returnMergedCoins(txb as any, coinInfo); coinA = txb.splitCoins(mergedCoin, [txb.pure.u64(amountIn)]); } return coinA; } export const MOVE_DEX_INFO = { BluefinSwap: { name: 'Bluefin', image: 'https://assets.coingecko.com/coins/images/30883/standard/Bluefin_Logo.png?1696529730', }, BLUEFIN: { name: 'Bluefin', image: 'https://assets.coingecko.com/coins/images/30883/standard/Bluefin_Logo.png?1696529730', }, bluefin: { name: 'Bluefin', image: 'https://assets.coingecko.com/coins/images/30883/standard/Bluefin_Logo.png?1696529730', }, CETUS: { name: 'Cetus', image: 'https://assets.coingecko.com/coins/images/30256/standard/cetus.png', }, cetus: { name: 'Cetus', image: 'https://assets.coingecko.com/coins/images/30256/standard/cetus.png', }, CetusSwap: { name: 'Cetus', image: 'https://assets.coingecko.com/coins/images/30256/standard/cetus.png', }, SUISWAP: { name: 'Suiswap', image: 'https://assets.coingecko.com/coins/images/30688/standard/suiswap-200.png', }, suiswap: { name: 'Suiswap', image: 'https://assets.coingecko.com/coins/images/30688/standard/suiswap-200.png', }, FLOWX: { name: 'FlowX', image: 'https://assets.coingecko.com/coins/images/33317/standard/logo_flx.png?1701435649', }, FLOWXCLMM: { name: 'FlowX', image: 'https://assets.coingecko.com/coins/images/33317/standard/logo_flx.png?1701435649', }, flowx: { name: 'FlowX', image: 'https://assets.coingecko.com/coins/images/33317/standard/logo_flx.png?1701435649', }, FlowxV2Swap: { name: 'FlowX', image: 'https://assets.coingecko.com/coins/images/33317/standard/logo_flx.png?1701435649', }, FlowxV3Swap: { name: 'FlowX', image: 'https://assets.coingecko.com/coins/images/33317/standard/logo_flx.png?1701435649', }, FLOWXV3: { name: 'FlowX', image: 'https://assets.coingecko.com/coins/images/33317/standard/logo_flx.png?1701435649', }, KRIYAV3: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, KRIYA: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, Kriya: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, kriya: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, kriya_v2: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, Kriya_V2: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, kriyaV2: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, KriyaV2: { name: 'Kriya', image: 'https://cryptologos.cc/logos/sui-sui-logo.svg?v=035', }, KRIYA_V2: { name: 'Kriya', image: 'https://cryptologos.cc/logos/sui-sui-logo.svg?v=035', }, KriyaV2Swap: { name: 'Kriya', image: 'https://cryptologos.cc/logos/sui-sui-logo.svg?v=035', }, kriya_v3: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, Kriya_V3: { name: 'Kriya', image: 'https://cryptologos.cc/logos/sui-sui-logo.svg?v=035', }, KRIYA_V3: { name: 'Kriya', image: 'https://cryptologos.cc/logos/sui-sui-logo.svg?v=035', }, kriyaV3: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, KriyaV3: { name: 'Kriya', image: 'https://cryptologos.cc/logos/sui-sui-logo.svg?v=035', }, KriyaV3Swap: { name: 'Kriya', image: 'https://cryptologos.cc/logos/sui-sui-logo.svg?v=035', }, KriyaDexSwap: { name: 'Kriya', image: 'https://img.cryptorank.io/coins/kriya_dex1705937575164.png', }, bric: { name: 'Obric', image: 'https://icons.llamao.fi/icons/protocols/obric?w=48&h=48', }, Obric: { name: 'Obric', image: 'https://icons.llamao.fi/icons/protocols/obric?w=48&h=48', }, OBRIC: { name: 'Obric', image: 'https://icons.llamao.fi/icons/protocols/obric?w=48&h=48', }, AFTERMATH: { name: 'Aftermath', image: 'https://aftermath.finance/_next/image?url=%2Flogos%2Fprimary.png&w=3840&q=75', }, Aftermath: { name: 'Aftermath', image: 'https://aftermath.finance/_next/image?url=%2Flogos%2Fprimary.png&w=3840&q=75', }, aftermath: { name: 'Aftermath', image: 'https://aftermath.finance/_next/image?url=%2Flogos%2Fprimary.png&w=3840&q=75', }, AftermathSwap: { name: 'Aftermath', image: 'https://aftermath.finance/_next/image?url=%2Flogos%2Fprimary.png&w=3840&q=75', }, BLUEMOVE: { name: 'BlueMove', image: 'https://assets.coingecko.com/coins/images/28917/standard/BlueMoveCoin.png', }, BlueMove: { name: 'BlueMove', image: 'https://assets.coingecko.com/coins/images/28917/standard/BlueMoveCoin.png', }, BluemoveSwap: { name: 'BlueMove', image: 'https://assets.coingecko.com/coins/images/28917/standard/BlueMoveCoin.png', }, TURBOS: { name: 'Turbos', image: 'https://img.cryptorank.io/coins/turbos_finance1680078612538.png', }, Turbos: { name: 'Turbos', image: 'https://img.cryptorank.io/coins/turbos_finance1680078612538.png', }, turbos: { name: 'Turbos', image: 'https://img.cryptorank.io/coins/turbos_finance1680078612538.png', }, TurbosSwap: { name: 'Turbos', image: 'https://img.cryptorank.io/coins/turbos_finance1680078612538.png', }, DEEPBOOK: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, Deepbook: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, deepbook: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, deepbook_v3: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, DEEPBOOKV3: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, DEEPBOOK_V3: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, Deepbook_V3: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, DeepbookSwap: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, DeepbookV3Swap: { name: 'DeepBook', image: 'https://cdn.prod.website-files.com/65fdccb65290aeb1c597b611/66e13b4438786b0e8b9be93c_Group%202147256899.png', }, }; export const mappingSuiToken = (address: string) => { if ( address === '0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI' ) { return '0x2::sui::SUI'; } return address; }; export const handleFormatValue = ( fromTokenPriceUSD: any, fromTokenDecimals: any, toTokenPriceUSD: any, toTokenDecimals: any, inputAmount: any, outputAmount: any, ) => { const fromValue = fromTokenPriceUSD ? (Number(inputAmount) * Number(fromTokenPriceUSD)) / 10 ** (fromTokenDecimals || 18) : 0; const toValue = toTokenPriceUSD ? (Number(outputAmount) * Number(toTokenPriceUSD)) / 10 ** (toTokenDecimals || 18) : 0; return { fromValue: fromValue || 0, toValue: toValue || 0, }; }; const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); export const retryOperation = async ( operation: () => Promise, maxRetries: number = 3, delayMs: number = 1000, ): Promise => { let lastError: any; for (let attempt = 1; attempt <= maxRetries; attempt++) { try { return await operation(); } catch (error) { lastError = error; console.error(`Attempt ${attempt} failed:`, error); if (attempt < maxRetries) { await delay(delayMs * attempt); // Exponential backoff continue; } } } throw lastError; };