import type { TargetNamespace, Wallet } from './shared'; import type { Provider } from '@hub3js/core'; import type { DefaultNamespaces } from '@hub3js/namespaces'; import type { QueueContext, QueueDef, QueueStorage, } from '@arthur2079/queue-manager-core'; import type { LegacyConnectResult as ConnectResult } from '@arthur2079/wallets-core/legacy'; import type { Meta, Network, Providers, WalletState, WalletType, } from '@arthur2079/wallets-shared'; import type { Transaction } from 'rango-sdk'; import type { APIErrorCode, EvmBlockchainMeta, PendingSwap, PendingSwapStep, SignerFactory, } from 'rango-types'; export type RemoveNameField = { [Property in keyof T as Exclude]: T[Property]; }; export type ArrayElement = A extends readonly (infer T)[] ? T : never; export type SwapQueueDef = QueueDef< SwapStorage, SwapActionTypes, SwapQueueContext >; export interface SwapStorage extends QueueStorage { swapDetails: PendingSwap; } export enum SwapActionTypes { START = 'START', SCHEDULE_NEXT_STEP = 'SCHEDULE_NEXT_STEP', CREATE_TRANSACTION = 'CREATE_TRANSACTION', CHECK_PREREQUISITES = 'CHECK_PREREQUISITES', CHECK_XRPL_TRUSTLINE = 'CHECK_XRPL_TRUSTLINE', CHECK_STELLAR_TRUSTLINE = 'CHECK_STELLAR_TRUSTLINE', CHECK_XRPL_TRUSTLINE_TRANSACTION_STATUS = 'CHECK_XRPL_TRUSTLINE_TRANSACTION_STATUS', EXECUTE_TRANSACTION = 'EXECUTE_TRANSACTION', EXECUTE_XRPL_TRANSACTION = 'EXECUTE_XRPL_TRANSACTION', EXECUTE_STELLAR_TRANSACTION = 'EXECUTE_STELLAR_TRANSACTION', EXECUTE_HYPERLIQUID_TRANSACTION = 'EXECUTE_HYPERLIQUID_TRANSACTION', CHECK_HYPERLIQUID_TRANSACTION_STATUS = 'CHECK_HYPERLIQUID_TRANSACTION_STATUS', CHECK_TRANSACTION_STATUS = 'CHECK_TRANSACTION_STATUS', } export type GetCurrentAddress = ( type: WalletType, network: Network ) => string | undefined; export enum BlockReason { WAIT_FOR_CONNECT_WALLET = 'waiting_for_connecting_wallet', WAIT_FOR_NETWORK_CHANGE = 'waiting_for_network_change', DEPENDS_ON_OTHER_QUEUES = 'depends_on_other_queues', } // eslint-disable-next-line @typescript-eslint/no-explicit-any export interface Block { reason: BlockReason; description: string; details?: T; } export interface SwapQueueContext extends QueueContext { meta: Meta; wallets: Wallet | null; providers: Providers; hubProvider: (type: WalletType) => Provider; getSigners: (type: WalletType) => Promise; switchNetwork: ( wallet: WalletType, namespaces: TargetNamespace ) => Promise | undefined; canSwitchNetworkTo: UseQueueManagerParams['canSwitchNetworkTo']; state: (type: WalletType) => WalletState; isMobileWallet: (type: WalletType) => boolean; // Dynamically will be added to context. claimedBy?: string; resetClaimedBy?: () => void; } export type LastConnectedWallet = { walletType: string; network?: string; accounts?: string[]; }; export interface UseQueueManagerParams { lastConnectedWallet: LastConnectedWallet | null; disconnectedWallet: WalletType | undefined; clearDisconnectedWallet: () => void; evmChains: EvmBlockchainMeta[]; canSwitchNetworkTo: ( type: WalletType, network: Network, namespace: TargetNamespace ) => boolean; } export enum WidgetEvents { RouteEvent = 'routeEvent', StepEvent = 'stepEvent', } export type Step = Pick< PendingSwapStep, | 'diagnosisUrl' | 'estimatedTimeInSeconds' | 'explorerUrl' | 'feeInUsd' | 'executedTransactionId' | 'executedTransactionTime' | 'expectedOutputAmountHumanReadable' | 'fromBlockchain' | 'toBlockchain' | 'fromSymbol' | 'toSymbol' | 'toSymbolAddress' | 'fromSymbolAddress' | 'swapperType' | 'outputAmount' | 'fromAmountMaxValue' | 'fromAmountMinValue' | 'fromAmountPrecision' | 'fromAmountRestrictionType' | 'fromDecimals' | 'status' > & { swapperName: string; transaction: Transaction | null }; export type Route = Pick< PendingSwap, | 'creationTime' | 'finishTime' | 'requestId' | 'inputAmount' | 'status' | 'wallets' > & { steps: Step[]; slippage: string; infiniteApproval?: boolean }; export type SwapEvent = RouteEvent | StepEvent; export enum RouteEventType { STARTED = 'started', FAILED = 'failed', SUCCEEDED = 'succeeded', } export enum StepExecutionEventStatus { CREATE_TX = 'create_tx', SEND_TX = 'send_tx', TX_SENT = 'tx_sent', } export enum StepExecutionBlockedEventStatus { WAITING_FOR_QUEUE = 'waiting_for_queue', WAITING_FOR_WALLET_CONNECT = 'waiting_for_wallet_connect', WAITING_FOR_NETWORK_CHANGE = 'waiting_for_network_change', WAITING_FOR_CHANGE_WALLET_ACCOUNT = 'waiting_for_change_wallet_account', } export enum StepEventType { STARTED = 'started', FAILED = 'failed', SUCCEEDED = 'succeeded', TX_EXECUTION = 'tx_execution', TX_EXECUTION_BLOCKED = 'tx_execution_blocked', APPROVAL_TX_SUCCEEDED = 'approval_tx_succeeded', CHECK_STATUS = 'check_status', OUTPUT_REVEALED = 'output_revealed', } export enum EventSeverity { ERROR = 'error', SUCCESS = 'success', WARNING = 'warning', INFO = 'info', } export type Event< T extends StepEventType | RouteEventType, U extends Record = Record > = { type: T; message: string; messageSeverity: EventSeverity; } & U; export type FailedRouteEventPayload = { inputAmount: string; inputAmountUsd: string; reason?: string; reasonCode: APIErrorCode; swapMode: 'swap' | 'refuel'; }; export type FailedStepEventPayload = Omit; export type SucceededRouteEventPayload = { inputAmount: string; inputAmountUsd: string; outputAmount: string; outputAmountUsd: string; swapMode: 'swap' | 'refuel'; }; export type SucceededStepEventPayload = Omit< SucceededRouteEventPayload, 'swapMode' >; export type OutputRevealedEventPayload = { outputAmount: string }; export type StepExecutionEventPayload = { status: | StepExecutionEventStatus.CREATE_TX | StepExecutionEventStatus.SEND_TX | StepExecutionEventStatus.TX_SENT; }; export type StepBlockedEventPayload = | { status: StepExecutionBlockedEventStatus.WAITING_FOR_QUEUE } | { status: StepExecutionBlockedEventStatus.WAITING_FOR_WALLET_CONNECT; requiredWallet?: string; requiredAccount?: string; } | { status: StepExecutionBlockedEventStatus.WAITING_FOR_CHANGE_WALLET_ACCOUNT; requiredAccount?: string; } | { status: StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE; currentNetwork?: string; requiredNetwork?: string; }; export type RouteStartedEvent = Event; export type RouteFailedEvent = Event< RouteEventType.FAILED, FailedRouteEventPayload >; export type RouteSucceededEvent = Event< RouteEventType.SUCCEEDED, SucceededRouteEventPayload >; export type StepStartedEvent = Event; export type StepSucceededEvent = Event< StepEventType.SUCCEEDED, SucceededStepEventPayload >; export type StepFailedEvent = Event< StepEventType.FAILED, FailedStepEventPayload >; export type StepTxExecutionUpdatedEvent = Event< StepEventType.TX_EXECUTION, StepExecutionEventPayload >; export type StepTxExecutionBlockedEvent = Event< StepEventType.TX_EXECUTION_BLOCKED, StepBlockedEventPayload >; export type StepCheckStatusEvent = Event; export type StepApprovalTxSucceededEvent = Event; export type StepOutputRevealedEvent = Event< StepEventType.OUTPUT_REVEALED, OutputRevealedEventPayload >; export type StepEvent = | StepStartedEvent | StepSucceededEvent | StepFailedEvent | StepTxExecutionUpdatedEvent | StepTxExecutionBlockedEvent | StepCheckStatusEvent | StepApprovalTxSucceededEvent | StepOutputRevealedEvent; export type RouteEvent = | RouteStartedEvent | RouteSucceededEvent | RouteFailedEvent; export type RouteEventData = { route: Route; event: RouteEvent }; export type StepEventData = { route: Route; step: Step; event: StepEvent }; export type RouteExecutionEvents = { [WidgetEvents.RouteEvent]: RouteEventData; [WidgetEvents.StepEvent]: StepEventData; };