import type { NotifierParams } from './services/eventEmitter'; import type { SwapStatus, TargetNamespace, Wallet } from './shared'; import type { ArrayElement, LastConnectedWallet, Step, SwapQueueContext, SwapQueueDef, SwapStorage, UseQueueManagerParams } from './types'; import type { Provider } from '@hub3js/core'; import type { DefaultNamespaces } from '@hub3js/namespaces'; import type { ExecuterActions, Manager, QueueInfo } from '@arthur2079/queue-manager-core'; import type { Meta, Network, Providers, WalletState, WalletType } from '@arthur2079/wallets-shared'; import type { CreateTransactionResponse, EvmBlockchainMeta, Transaction } from 'rango-sdk'; import type { APIErrorCode, PendingSwap, PendingSwapStep, SignerErrorCode, StepStatus, SwapStepStatus } from 'rango-types'; import { PendingSwapNetworkStatus, TransactionType } from 'rango-types'; import { StepEventType, SwapActionTypes } from './types'; type WhenTaskBlocked = Parameters>; type WhenTaskBlockedEvent = WhenTaskBlocked[0]; type WhenTaskBlockedMeta = WhenTaskBlocked[1]; /** * * We simply use module-level variable to keep track of which queue has claimed the execution of parallel runnings. * */ export declare function claimQueue(): { claimedBy: () => string | undefined; setClaimer: (queue_id: string) => void; reset: () => void; }; /** * * We use module-level variable to keep track of * map of transactions hash to the TransactionResponse and ... * */ type TransactionData = { response?: any; receiptReceived?: boolean; }; export declare function inMemoryTransactionsData(): { getTransactionDataByHash: (hash: string) => TransactionData; setTransactionDataByHash: (hash: string, data: TransactionData) => void; }; /** * * Returns `steps`, if it's a `running` swap. * Each `PendingSwap` has a `steps` inside it, `steps` shows how many tasks should be created and run to finish the swap. * */ export declare const getCurrentStep: (swap: PendingSwap) => PendingSwapStep | null; /** * * Returns current step transaction * */ export declare const getCurrentStepTx: (currentStep: PendingSwapStep) => Transaction | null; /** * * Set current step transaction * */ export declare const setCurrentStepTx: (currentStep: PendingSwapStep, transaction: Transaction) => PendingSwapStep; /** * * Returns current step transaction type * */ export declare const getCurrentStepTxType: (currentStep: PendingSwapStep) => TransactionType | undefined; /** * * Returns a boolean indicating that current step is an approval tx or not. * */ export declare const isApprovalCurrentStepTx: (currentStep: PendingSwapStep) => boolean; /** * When we are doing a swap, there are some common fields that will be updated together. * This function helps us to update a swap status and also it will update some more fields like `extraMessageSeverity` based on the input. */ export declare function updateSwapStatus({ getStorage, setStorage, nextStatus, nextStepStatus, message, details, errorCode, hasAlreadyProceededToSign, trace, }: { getStorage: ExecuterActions['getStorage']; setStorage: ExecuterActions['setStorage']; nextStatus?: SwapStatus; nextStepStatus?: StepStatus; message?: string; details?: string | null | undefined; errorCode?: APIErrorCode | SignerErrorCode | null; hasAlreadyProceededToSign?: boolean; trace?: Error | null | undefined; }): { swap: PendingSwap; step: PendingSwapStep | null; failureType?: APIErrorCode; }; /** * * Set current step transaction hash, update pending swap status, and notify user if needed * */ export declare function setStepTransactionIds({ getStorage, setStorage }: ExecuterActions, txId: string | null, explorerUrl?: { url?: string; description?: string; }): void; /** * If a swap needs a wallet to be connected, * By calling this function some related fields will be updated to show a correct message and state for notfiying the user. */ export declare function markRunningSwapAsWaitingForConnectingWallet({ getStorage, setStorage, }: Pick, reason: string, reasonDetail: string): void; /** * If a swap needs a certain network to proceed, * By calling this function some related fields will be updated to show a correct message and state for notfiying the user. */ export declare function markRunningSwapAsSwitchingNetwork({ getStorage, setStorage, }: Pick): { swap: PendingSwap; step: PendingSwapStep; } | undefined; /** * We are marking the queue as it depends on other queues to be run (on Parallel mode) * By calling this function some related fields will be updated to show a correct message and state for notfiying the user. */ export declare function markRunningSwapAsDependsOnOtherQueues({ getStorage, setStorage, }: Pick): { swap: PendingSwap; step: PendingSwapStep; } | undefined; export declare function delay(ms: number): Promise; /** * * To execute a swap, we are keeping the user prefrences on what wallet they are going to use for a sepecific blockchain * By passing the swap and the network we are looking for, it returns the wallet name that user selected. * */ export declare const getSwapWalletType: (swap: PendingSwap, network: Network) => WalletType; /** * * We are keeping the connected wallet in a specific structure (`Wallet`), * By using this function we normally want to check a specific wallet is connected and exists or not. * */ export declare function isWalletNull(wallet: Wallet | null): boolean; /** * In a `PendingSwap`, each step needs a wallet to proceed, * By using this function we can access what wallet exactly we need to run current step. */ export declare function getRequiredWallet(swap: PendingSwap): { type: WalletType | null; namespace: TargetNamespace | null; address: string | null; }; export declare function getProviderChainId(providers: Providers, hubProvider: (type: WalletType) => Provider, walletType: string): Promise; /** * For running a swap safely, we need to make sure about the state of wallet * which means the netowrk/chain of wallet should be exactly on what a transaction needs. */ /** * The EVM chain a wallet must be actively connected to in order to sign the current step. * * For Hyperliquid the wallet is stored under the "HYPERLIQUID" key, but the action is an * EIP-712 message signed with the Arbitrum domain chainId. Many wallets reject * `eth_signTypedData_v4` unless their active chain matches that chainId, so the wallet * must actually be on Arbitrum (HYPERLIQUID_SIGN_NETWORK) before signing — even though * the step's network/storage key is "HYPERLIQUID". */ export declare function getRequiredSignNetwork(step: PendingSwapStep, fallbackNetwork: string): string; export declare function isNetworkMatchedForTransaction(swap: PendingSwap, step: PendingSwapStep, wallet: Wallet | null, meta: Meta, providers: Providers, hubProvider: (type: WalletType) => Provider): Promise; export declare const isTxAlreadyCreated: (swap: PendingSwap, step: PendingSwapStep) => boolean; export declare function resetNetworkStatus(actions: ExecuterActions): void; export declare function updateNetworkStatus(actions: Pick, 'getStorage' | 'setStorage'>, data?: { message: string; details: string; status: PendingSwapNetworkStatus | null; }): void; /** * Event handler for blocked tasks. * If a transcation execution is manually blocked (like for parallel or waiting for wallet), * This function will be called by queue manager using `queue definition`. * * It checks if the required wallet is connected, unblock the queue to be run. */ export declare function onBlockForConnectWallet(event: WhenTaskBlockedEvent, meta: WhenTaskBlockedMeta): void; /** * Event handler for blocked tasks. * If a transcation execution is manually blocked (like for parallel or waiting for walle), * This function will be called by queue manager using `queue definition`. * * It checks if the required network is connected, unblock the queue to be run. * Note: it automatically try to switch the network if its `provider` supports. */ export declare function onBlockForChangeNetwork(_event: WhenTaskBlockedEvent, meta: WhenTaskBlockedMeta): void; /** * Event handler for blocked tasks. (Parallel mode) * If a transcation execution flow is manually blocked (like for parallel or waiting for walle), * This function will be called by queue manager using `queue definition`. * * It checks the blocked tasks, if there is no active `claimed` queue, try to give it to the best candidate. */ export declare function onDependsOnOtherQueues(_event: WhenTaskBlockedEvent, meta: WhenTaskBlockedMeta): void; export declare function isRequiredWalletConnected(swap: PendingSwap, getState: (type: WalletType) => WalletState): { ok: boolean; reason: 'not_connected' | 'account_miss_match'; }; export declare function updateStorageWithPrerequisiteResult(actions: ExecuterActions, prerequisiteResult: SwapStepStatus['prerequisiteResults'][number]): void; export declare function updateStorageOnSuccessfulSign(actions: ExecuterActions, signResult: { hash: string; response?: any; }, data: { isApproval: boolean; }): void; export declare function handleSuccessfulSign(actions: ExecuterActions, data: { isApproval: boolean; }): ({ hash, response }: { hash: string; response?: any; }) => void; export declare function handleRejectedSign(actions: ExecuterActions): (error: any) => void; export declare function checkWaitingForConnectWalletChange(params: { lastConnectedWallet: LastConnectedWallet; manager?: Manager; evmChains: EvmBlockchainMeta[]; }): void; export declare function checkWaitingForNetworkChange(manager?: Manager): void; /** * Get list of all running swaps * * @param manager * @returns list of pending swaps */ export declare function getRunningSwaps(manager: Manager): PendingSwap[]; /** * * Trying to reset notifications for pending swaps to correct message on page load. * We could remove this after supporting auto connect for wallets. * * @param swaps * @param notifier * @returns */ export declare function resetRunningSwapNotifsOnPageLoad(runningSwaps: PendingSwap[]): void; /** * * Try to run blocked tasks by wallet and network name. * Goes through queues and extract blocked queues with matched wallet. * If found any blocked tasks with same wallet and network, runs them. * If not, runs only blocked tasks with matched wallet. * * @param wallet_network a string includes `wallet` type and `network` type. * @param manager * @returns */ export declare function retryOn(lastConnectedWallet: LastConnectedWallet, manager?: Manager, canSwitchNetworkTo?: UseQueueManagerParams['canSwitchNetworkTo'], options?: { fallbackToOnlyWallet: boolean; }): void; export declare function isNeedBlockQueueForParallel(step: PendingSwapStep): boolean; export declare function throwOnOK(rawResponse: Promise): Promise; export declare function cancelSwap(swap: QueueInfo, manager?: Manager): { swap: PendingSwap; step: PendingSwapStep | null; }; export declare function getLastSuccessfulStep(steps: T): ArrayElement | undefined; export declare function getFailedStep(steps: T): ArrayElement | undefined; export declare function isApprovalTX(step: Step): boolean; export declare function getTokenAmountInUsd(amount: string | number, usdPrice: string | number): string; export declare function getSwapInputUsd(swap: PendingSwap): string; export declare function getSwapOutputUsd(swap: PendingSwap): string; export declare function getLastFinishedStep(swap: PendingSwap): { step: PendingSwapStep; index: number; } | undefined; export declare function getLastFinishedStepInput(swap: PendingSwap): string; export declare function getLastFinishedStepInputUsd(swap: PendingSwap): string; export declare function getLastSuccessfulStepOutputUsd(swap: PendingSwap): string; export declare function createStepFailedEvent(swap: PendingSwap, message: string, reasonCode?: APIErrorCode): NotifierParams['event'] & { type: StepEventType.FAILED; }; export {}; //# sourceMappingURL=helpers.d.ts.map