import type { SwapLifecycleEvent } from '@layerswap/widget-types'; import type { ApiResponse } from '@layerswap/widget-types'; import type { SwapResponse } from '../lib/apiClients/layerSwapApiClient'; import { type SwapLifecycleContext } from './swapLifecycle'; /** * Runs after the swap exists. Isolated: a throw is reported via onError * (`SideEffectError`) and never rejects the attempt. Return values (including * promises) are ignored. */ export type SwapCreatedEffect = { name: string; run: (swap: SwapResponse) => void; }; export type PreparedSwapRequest = { request: () => Promise | undefined>; /** True iff the request being sent carries use_gasless. */ useGasless: boolean; /** Post-creation effects, in order. Built by prepare() because they depend on the same plan as the request. */ onCreated: ReadonlyArray; }; export type SwapCreationHooks = { path: string; lifecycleContext: SwapLifecycleContext; onLifecycle: (event: SwapLifecycleEvent) => void; /** Request scope only: fired when the API rejected or returned `error` for a use_gasless request. */ onGaslessUnavailable: () => void; }; /** * Request scope. The gasless flip is keyed to the API refusing the request (rejection or * an `error` envelope); a 2xx without an id is not a gasless refusal. */ export declare function requestSwap({ request, useGasless }: Pick, onGaslessUnavailable: () => void): Promise; /** Post-creation scope. Synchronous by contract: nothing here can reject the attempt. */ export declare function announceCreatedSwap(swap: SwapResponse, effects: ReadonlyArray): void; /** * Attempt scope. Invariants: * (a) exactly one of swap_created / swap_creation_failed per call; * (b) the promise rejects iff swap_creation_failed was emitted; * (c) onGaslessUnavailable fires only from requestSwap; * (d) post-creation effects never affect (a)/(b). */ export declare function createSwapAttempt(prepare: () => Promise, hooks: SwapCreationHooks): Promise; //# sourceMappingURL=swapCreation.d.ts.map