import type { AccountResponse, AccountSummary, ActionParamsMap, ActionStep, CreateActionResponse, ExecuteActionResponse, MarketRef, Position, SignedActionStep } from '@lifi/perps-types'; import { ActionType } from '@lifi/perps-types'; import type { Address } from 'viem'; import type { BuildProviderSetupParams, CancelOrdersParams, ExecuteProviderSetupParams, ExecuteProviderSetupResult, GetAccountResult, GetSetupParams, ModifyOrdersParams, PerpsClientOptions, PlaceOrderParams, PlaceTriggerOrderParams, ProviderSetup, WithdrawParams } from '../types/api.js'; import type { PerpsSDKClient } from '../types/provider.js'; /** * The primary high-level perps API: wraps a {@link PerpsSDKClient} and owns the * end-to-end signing pipeline for provider setup, orders, and account-level * actions. Construct via `new PerpsClient(options)` or the SDK's higher-level * wiring. * * @public */ export declare class PerpsClient { private sdkClient; private providerMetadataCache; private _userWallet; constructor(options: PerpsClientOptions); /** * Set or update the end-user's wallet. Used whenever an action's descriptor * names the user wallet in its `signers` list. Pass undefined to clear. * * @public */ setUserWallet(userWallet: PerpsSDKClient['userWallet']): void; /** * The underlying low-level {@link PerpsSDKClient} (config, user wallet, * provider registry) backing this instance. * * @public */ get client(): PerpsSDKClient; private getProviderMetadata; /** * Resolve the registered provider plugin for `provider`, throwing a * `PerpsError` when the caller has not registered one via the SDK's * `providers` option. The plugin owns signer identity and write-side signing. */ private requireProvider; /** * Ask the provider plugin for the signer-bearing wire fields of `action` — * the on-wire `signerAddress` and any signer-derived params (e.g. * Hyperliquid's `agentAddress` for `APPROVE_AGENT`). Forwards the descriptor's * `signers` so the plugin can branch on signer role. Returns empty when the * plugin signs as the user or with a non-EVM credential. Core constructs no * `signerAddress` itself; signer identity is plugin-owned. */ private resolveActionRequest; /** * Delegate signing of `actions` to the provider plugin. The plugin owns * every signing arm and branches on the descriptor's `signers` internally, * reading the end-user's wallet from the {@link SignActionsContext} when an * arm signs as the user. */ private delegateSignActions; /** * Assemble the per-call context the provider plugin needs in order to sign: * the end-user's wallet and the descriptor's declared `signers`. Core * forwards `signers` as data so the plugin can pick WHO signs; it does not * branch on them. Provider-owned session credentials (the Hyperliquid agent * keypair, Lighter's API key) are resolved inside the provider's * `signActions`, not threaded through here. */ private buildSignActionsContext; /** * Sign a single provider setup action step by delegating to the provider * plugin, which branches on the step's signing scheme internally. Lets * consumers collect signed setup actions without embedding per-method * signing logic. * * @throws {PerpsError} When the step's action is not declared by the provider. * @public */ signProviderSetupAction(provider: string, address: Address, step: ActionStep): Promise; /** * Build (but do not sign or submit) the unsigned action steps for `action`, * letting the provider plugin contribute any signer-bearing request fields. * * @public */ buildAction(action: T, params: { provider: string; address: Address; params: ActionParamsMap[T]; }): Promise; /** * Fetch the user's account state from the backend and attach the * SDK-projected `settings` array — one `AccountConfigSetting` per * descriptor on `Provider.setup` + `Provider.options`. Callers read * `result.settings` directly without re-deriving values from the typed * `AccountConfig`. * * @throws {PerpsError} When the provider plugin is not registered, or the * backend account fetch fails. * @public */ getAccount(params: { provider: string; address: Address; }): Promise; /** * Roll an already-fetched {@link AccountResponse} (plus its positions) up * into an {@link AccountSummary}, delegating to the owning provider so the * venue-specific collateral and margin semantics are applied correctly. */ getAccountSummary(account: AccountResponse, positions: Position[]): AccountSummary; /** * Thin existence check for a provider account at `address`. Returns * `true` when `getAccount` resolves, `false` when the backend reports * `PerpsErrorCode.AccountNotFound`, and re-throws on any other error * (transport failures, validation errors, server errors). * * @throws {PerpsError} On any backend error other than * `PerpsErrorCode.AccountNotFound`. * @public */ accountExists(provider: string, address: Address): Promise; /** * Return the unsatisfied entries on `Provider.setup` for this account as a * flat, self-describing list. Trading is gated on `isReady === true`. * * `Provider.options` descriptors are NEVER returned here — options are * post-setup tunables and never gate trading. Option state is surfaced * separately via `getAccount().settings`. * * @public */ checkSetup(params: GetSetupParams): Promise; /** * Build the unsigned setup `ActionStep`s still outstanding for an account, * ordered by descriptor `sequence`. The backend filters already-satisfied * setup; each plugin contributes its own signer-bearing request fields and * any local-state params (e.g. Lighter's known pubkey). * * @public */ buildProviderSetup(params: BuildProviderSetupParams): Promise; /** * Submit the signed setup steps returned by `checkSetup` (and signed by the * caller / `signProviderSetupAction`). Routes the batch on the first step's * action and lets the plugin contribute that action's `signerAddress`. * Throws on any per-step venue rejection. * * @public */ executeProviderSetup(params: ExecuteProviderSetupParams): Promise; /** * Sign and submit one pre-staged setup `ActionStep` end-to-end. * * The caller is expected to have already obtained the step from a prior * {@link checkSetup} call (typically cached by the widget's react-query) — * we do NOT refetch. This avoids the double `createAction` round-trip and * keeps the nonce that was allocated at staging time committed all the way * through submit. If the cached step has gone stale (Lighter's `/nextNonce` * advanced underneath us), `executeProviderSetup` will surface a nonce * conflict that the caller invalidates on, refetches `checkSetup`, and * retries with a fresh step. * * @throws {PerpsError} When the step's action is not in the provider's * `setup` descriptors. * @public */ executeProviderSetupAction(params: { provider: string; address: Address; step: ActionStep; }): Promise; /** * Sign and submit a single provider-option change (a `Provider.options` * tunable such as Lighter `ACCOUNT_TYPE` or Hyperliquid `ACCOUNT_MODE`) * end-to-end, throwing on a venue rejection. * * Options are dispatched through the same {@link execute} pipeline as * trades, but unlike a trade an option change is a single mandatory action: * a per-action `success: false` (returned as a 200 OK) means the user's * selection was rejected and must surface, not be silently dropped. This * wrapper inspects the result and throws a {@link PerpsError} carrying the * venue `error`, giving options the same throw contract that setup has via * {@link executeProviderSetupAction}. The only structural difference is that * an option carries `params` (the selected value) rather than a pre-staged * step. * * `execute` itself is unchanged — it still returns results without throwing, * which the trade hooks rely on for partial-fill handling. * * @throws {PerpsError} `PerpsErrorCode.ExchangeRejected` carrying the venue * error when any returned result has `success: false`; also the errors * `execute` itself can throw (unregistered provider, no signer, signing * failure). * @public */ executeProviderOption(params: { provider: string; address: Address; action: T; params: ActionParamsMap[T]; }): Promise; /** * Place a market or limit order. Convenience wrapper over {@link execute} * with `ActionType.PLACE_ORDER`. * * @throws {PerpsError} When the provider is unregistered or the action * cannot be signed/submitted. * @example * ```ts * await client.placeOrder({ * provider: 'hyperliquid', * address: '0xUser', * market: { symbol: 'ETH' }, * side: 'buy', * size: '0.1', * }) * ``` * @public */ placeOrder(params: PlaceOrderParams): Promise; /** * Place a trigger (take-profit / stop-loss) order. Convenience wrapper over * {@link execute} with `ActionType.PLACE_TRIGGER_ORDER`. * * @throws {PerpsError} When the provider is unregistered or the action * cannot be signed/submitted. * @public */ placeTriggerOrder(params: PlaceTriggerOrderParams): Promise; /** * Cancel one or more open orders. Convenience wrapper over {@link execute} * with `ActionType.CANCEL_ORDER`. * * @throws {PerpsError} When the provider is unregistered or the action * cannot be signed/submitted. * @public */ cancelOrders(params: CancelOrdersParams): Promise; /** * Modify one or more open orders. Convenience wrapper over {@link execute} * with `ActionType.MODIFY_ORDER`. * * @throws {PerpsError} When the provider is unregistered or the action * cannot be signed/submitted. * @public */ modifyOrders(params: ModifyOrdersParams): Promise; /** * Add or remove isolated-position margin. Convenience wrapper over * {@link execute} with `ActionType.UPDATE_POSITION_MARGIN`. * * @throws {PerpsError} When the provider is unregistered or the action * cannot be signed/submitted. * @public */ updatePositionMargin(params: { provider: string; address: Address; market: MarketRef; action: 'add' | 'remove'; amount: string; }): Promise; /** * Withdraw funds from the provider account. Convenience wrapper over * {@link execute} with `ActionType.WITHDRAWAL`. * * @throws {PerpsError} When the provider is unregistered or the action * cannot be signed/submitted. * @public */ withdraw(params: WithdrawParams): Promise; /** * Execute any action through the SDK's signing pipeline: fetch the unsigned * steps, delegate signing to the provider plugin (which branches on the * descriptor's scheme and signer internally), and submit. Core stays * signer-agnostic — the plugin owns WHO signs and HOW. * * @throws {PerpsError} When the action is not declared by the provider, * the plugin cannot sign it, or submission fails. * @public */ execute(params: { provider: string; address: Address; action: T; params: ActionParamsMap[T]; }): Promise; } //# sourceMappingURL=PerpsClient.d.ts.map