import { IntentHash, IntentPrimitive, MultiPayload } from "./intents/shared-types.cjs"; import { IIntentSigner } from "./intents/interfaces/intent-signer.cjs"; import { BatchWithdrawalResult, Bridge, BridgeConfigs, CreateWithdrawalCompletionPromisesParams, FeeEstimation, IIntentsSDK, IntentPublishResult, IntentSettlementStatus, NearTxInfo, ParsedAssetInfo, PartialRPCEndpointMap, ProcessWithdrawalArgs, QuoteOptions, SignAndSendArgs, SignAndSendWithdrawalArgs, TxInfo, TxNoInfo, WithdrawalParams, WithdrawalResult } from "./shared-types.cjs"; import { IIntentRelayer } from "./intents/interfaces/intent-relayer.cjs"; import { ISaltManager } from "./intents/interfaces/salt-manager.cjs"; import { IntentPayloadBuilder } from "./intents/intent-payload-builder.cjs"; import { EnvConfig, ILogger, NearIntentsEnv } from "@defuse-protocol/internal-utils"; //#region src/sdk.d.ts interface IntentsSDKConfig { /** * Environment configuration. Can be: * - "production" or "stage" to use preset configurations * - A custom EnvConfig object for private environments * * Defaults to "production" if not specified. * * @example * // Use preset * new IntentsSDK({ env: "production", referral: "..." }); * * // Use custom config for private environment * new IntentsSDK({ * env: { * contractID: "intents.private-shard", * poaTokenFactoryContractID: "", * poaBridgeBaseURL: "", * solverRelayBaseURL: "https://private-relay.example.com", * managerConsoleBaseURL: "", * nearIntentsBaseURL: "", * }, * referral: "...", * }); */ env?: NearIntentsEnv | EnvConfig; intentSigner?: IIntentSigner; rpc?: PartialRPCEndpointMap; referral: string; solverRelayApiKey?: string; hotBridgeApiKey?: string; bridgeConfigs?: BridgeConfigs; } declare class IntentsSDK implements IIntentsSDK { protected envConfig: EnvConfig; protected referral: string; protected intentRelayer: IIntentRelayer; protected intentSigner?: IIntentSigner; protected bridges: Bridge[]; protected solverRelayApiKey: string | undefined; protected hotBridgeApiKey: string | undefined; protected saltManager: ISaltManager; constructor(args: IntentsSDKConfig); setIntentSigner(signer: IIntentSigner): void; /** * Create a new intent payload builder with environment context. * Use this to build custom intent payloads for your API or advanced use cases. * * @returns A new IntentPayloadBuilder instance configured with the SDK's environment * * @example * ```typescript * // Build a custom intent payload * const payload = await sdk.intentBuilder() * .setSigner('0x1234...') // User's EVM address * .setDeadline(new Date(Date.now() + 5 * 60 * 1000)) * .addIntent({ * intent: 'ft_withdraw', * token: 'usdc.omft.near', * amount: '1000000', * receiver_id: 'user.near' * }) * .build(); * * // Return to user for signing with their preferred method (MetaMask, etc.) * return payload; * ``` */ intentBuilder(): IntentPayloadBuilder; /** * Invalidate multiple nonces by creating and sending empty signed intents. * This prevents previously created but unused intent payloads from being executed. * * For expirable nonces (versioned nonces with embedded deadlines), the intent's * deadline is automatically set to the minimum of: * 1. The nonce's embedded deadline (can't exceed this) * 2. 1 minute from now (for quick invalidation when possible) * * @param args.nonces - Array of nonce strings to invalidate (up to 400 nonces per call, but depends on gas consumption) * @param args.signer - Optional intent signer to use (defaults to SDK's configured signer) * @param args.logger - Optional logger for debugging * * @example * ```typescript * // Invalidate unused nonces * await sdk.invalidateNonces({ * nonces: ['nonce1', 'nonce2', 'nonce3'] * }); * ``` */ invalidateNonces(args: { nonces: string[]; signer?: IIntentSigner; logger?: ILogger; }): Promise; createWithdrawalIntents(args: { withdrawalParams: WithdrawalParams; feeEstimation: FeeEstimation; referral?: string; logger?: ILogger; }): Promise; estimateWithdrawalFee(args: { withdrawalParams: WithdrawalParams; quoteOptions?: QuoteOptions; logger?: ILogger; }): Promise; estimateWithdrawalFee(args: { withdrawalParams: WithdrawalParams[]; quoteOptions?: QuoteOptions; logger?: ILogger; }): Promise; protected _estimateWithdrawalFee(args: { withdrawalParams: WithdrawalParams; quoteOptions?: QuoteOptions; logger?: ILogger; }): Promise; /** * Wait for withdrawal(s) to complete on the destination chain. * * **Important:** Waits until the withdrawal completes, fails, or the chain-specific * p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a shorter timeout budget. * * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors). * Inspect `error.cause` to determine the reason. * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain. * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError"). * * @param args.withdrawalParams - Single withdrawal or array of withdrawals * @param args.intentTx - The NEAR transaction info from the published intent * @param args.signal - Optional AbortSignal for cancellation/timeout * @param args.logger - Optional logger for debugging * * @example * ```typescript * // With timeout * const result = await sdk.waitForWithdrawalCompletion({ * withdrawalParams, * intentTx, * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout * }); * ``` */ waitForWithdrawalCompletion(args: { withdrawalParams: WithdrawalParams; intentTx: NearTxInfo; signal?: AbortSignal; logger?: ILogger; }): Promise; waitForWithdrawalCompletion(args: { withdrawalParams: WithdrawalParams[]; intentTx: NearTxInfo; signal?: AbortSignal; logger?: ILogger; }): Promise>; /** * Create promises that resolve when each withdrawal completes on the destination chain. * Use this for granular control over handling individual withdrawals as they complete, * rather than waiting for all to finish. * * **Important:** Each promise waits until the withdrawal completes, fails, or the * chain-specific p99 timeout is exceeded. Use `AbortSignal.timeout()` to set a * shorter timeout budget. * * @throws {WithdrawalWatchError} When status polling fails (timeout or consecutive errors). * Inspect `error.cause` to determine the reason. * @throws {WithdrawalFailedError} When the withdrawal fails on the destination chain. * @throws {DOMException} When the provided AbortSignal is aborted (name: "AbortError"). * * @param params.withdrawalParams - Array of withdrawal parameters * @param params.intentTx - The NEAR transaction info from the published intent * @param params.signal - Optional AbortSignal for cancellation/timeout * @param params.logger - Optional logger for debugging * @returns Array of promises, one per withdrawal, that resolve with transaction info * * @example * ```typescript * const promises = sdk.createWithdrawalCompletionPromises({ * withdrawalParams: [withdrawal1, withdrawal2], * intentTx, * signal: AbortSignal.timeout(5 * 60 * 1000), // 5 minute timeout * }); * * // Handle each withdrawal as it completes * for (const promise of promises) { * promise.then((result) => console.log('Withdrawal completed:', result)); * } * ``` */ createWithdrawalCompletionPromises(params: CreateWithdrawalCompletionPromisesParams): Array>; parseAssetId(assetId: string): ParsedAssetInfo; sendSignedIntents(args: { multiPayloads: MultiPayload[]; quoteHashes?: string[]; logger?: ILogger; }): Promise<{ tickets: IntentHash[]; }>; signAndSendIntent(args: SignAndSendArgs): Promise; private withSaltRetry; signAndSendWithdrawalIntent(args: SignAndSendWithdrawalArgs | SignAndSendWithdrawalArgs): Promise; waitForIntentSettlement(args: { intentHash: IntentHash; /** AbortSignal for cancellation/timeout. Use AbortSignal.timeout(ms) for timeout. */ signal?: AbortSignal; logger?: ILogger; }): Promise; getIntentStatus({ intentHash, logger }: { intentHash: IntentHash; logger?: ILogger; }): Promise; processWithdrawal(args: ProcessWithdrawalArgs): Promise; processWithdrawal(args: ProcessWithdrawalArgs): Promise; } //#endregion export { IntentsSDK, IntentsSDKConfig };