import { cowAppDataLatestScheme, AppDataParams, LatestAppDataDocVersion } from '@cowprotocol/sdk-app-data'; import { OrderKind, OrderParameters, TokenAmount, SigningScheme, OrderQuoteRequest, QuoteAmountsAndCosts, OrderQuoteResponse, AppData, AppDataHash, Signature, OrderBookApi, EnrichedOrder } from '@cowprotocol/sdk-order-book'; import { AccountAddress, AbstractSigner, Provider, SignerLike, Signer, AbstractProviderAdapter, Address, EthFlowContract } from '@cowprotocol/sdk-common'; import { UnsignedOrder, ORDER_PRIMARY_TYPE } from '@cowprotocol/sdk-order-signing'; import { CowEnv, AddressPerChain, SupportedChainId, ProtocolOptions } from '@cowprotocol/sdk-config'; /** * EIP-712 typed data domain. */ interface TypedDataDomain { name: string; version: string; chainId: number; verifyingContract: string; } /** * EIP-712 typed data field. */ interface TypedDataField { name: string; type: string; } /** * EIP-712 typed data for an order. */ interface OrderTypedData { domain: TypedDataDomain; primaryType: typeof ORDER_PRIMARY_TYPE; types: Record; message: UnsignedOrder; } /** * Minimal set of parameters to create a trade. */ interface TradeBaseParameters { kind: OrderKind; owner?: AccountAddress; sellToken: OrderParameters['sellToken']; sellTokenDecimals: number; buyToken: OrderParameters['buyToken']; buyTokenDecimals: number; amount: TokenAmount; } /** * Optional parameters to create a trade. */ interface TradeOptionalParameters { env?: CowEnv; /** * Custom address of settlement contract */ settlementContractOverride?: Partial; /** * Custom address of sell native token contract */ ethFlowContractOverride?: Partial; partiallyFillable?: OrderParameters['partiallyFillable']; /** * Slippage in basis points. * If not provided, it will use AUTO slippage, which would suggest a slippage based on the quote. */ slippageBps?: cowAppDataLatestScheme.SlippageBips; receiver?: OrderParameters['receiver']; validFor?: OrderParameters['validTo']; /** * Exact validTo timestamp in seconds since epoch. * If provided, this will be used instead of calculating from validFor. */ validTo?: OrderParameters['validTo']; partnerFee?: cowAppDataLatestScheme.PartnerFee; } /** * Information about the trader. */ interface TraderParameters { chainId: SupportedChainId; appCode: cowAppDataLatestScheme.AppCode; signer?: SignerLike; env?: CowEnv; settlementContractOverride?: Partial; ethFlowContractOverride?: Partial; } type QuoterParameters = Omit & { account: AccountAddress; }; interface SlippageToleranceResponse { slippageBps: number | null; } interface SlippageToleranceRequest { chainId: SupportedChainId; sellToken: OrderParameters['sellToken']; buyToken: OrderParameters['buyToken']; sellAmount?: bigint; buyAmount?: bigint; } /** * Trade type, assets, amounts, and optional parameters. */ interface TradeParameters extends TradeBaseParameters, TradeOptionalParameters { } interface SwapParameters extends TradeParameters, TraderParameters { } interface LimitTradeParameters extends Omit { sellAmount: OrderParameters['sellAmount']; buyAmount: OrderParameters['buyAmount']; /** * Id of the quote to be used for the limit order. */ quoteId?: number; validTo?: OrderParameters['validTo']; } interface LimitTradeParametersFromQuote extends LimitTradeParameters { quoteId: number; } interface LimitOrderParameters extends TraderParameters, LimitTradeParameters { } /** * When postSwapOrderFromQuote() is called, it will execute provided callback corresponding to signing order */ interface SigningStepManager { beforeBridgingSign?(): Promise | void; afterBridgingSign?(): Promise | void; beforeOrderSign?(): Promise | void; afterOrderSign?(): Promise | void; onBridgingSignError?(): void; onOrderSignError?(): void; } interface SwapAdvancedSettings extends LimitOrderAdvancedSettings { quoteSigner?: SignerLike; /** * An optional callback to use custom logic for slippage suggestion */ getSlippageSuggestion?(request: SlippageToleranceRequest): Promise; getCorrelatedTokens?(chainId: SupportedChainId): Promise; /** * Allows bridging trades like (USDC (mainnet) -> USDC (mainnet) -> DAI (base) */ allowIntermediateEqSellToken?: boolean; } interface LimitOrderAdvancedSettings { quoteRequest?: Partial & { validTo: number; }>; appData?: AppDataParams; additionalParams?: PostTradeAdditionalParams; } /** * Quote information for the CoW Protocol order, including information about the trade, quote, order, "app-data", and more. * * This data is used to create a trade, sign an order, and post it to the order book. */ interface QuoteResults { /** * Information about the trade, including the kind of order, the owner, the sell and buy tokens, and the amount. */ tradeParameters: TradeParameters; /** * The suggested slippage based on the quote. * */ suggestedSlippageBps: number; /** * Details about costs and amounts, costs and fees of a quote. */ amountsAndCosts: QuoteAmountsAndCosts; /** * Information about the order to be signed. * * For signining, please use orderTypedData (EIP-712 typed data, which also includes the unsigned order) */ orderToSign: UnsignedOrder; /** * Information about the quote response from the order book API. */ quoteResponse: OrderQuoteResponse; /** * Information about the app-data, including the JSON document and the keccak256 hash of the full document. */ appDataInfo: TradingAppDataInfo; /** * EIP-712 typed data for the order ready to be signed. */ orderTypedData: OrderTypedData; } interface QuoteResultsSerialized extends Omit { amountsAndCosts: QuoteAmountsAndCosts; } interface OrderPostingResult { orderId: string; txHash?: string; signingScheme: SigningScheme; signature: Signature; orderToSign: UnsignedOrder; } interface QuoteAndPost { quoteResults: QuoteResults; postSwapOrderFromQuote(advancedSettings?: SwapAdvancedSettings, signingStepManager?: SigningStepManager): Promise; } type AppDataRootSchema = cowAppDataLatestScheme.AppDataRootSchema; interface BuildAppDataParams { appCode: cowAppDataLatestScheme.AppCode; slippageBps: cowAppDataLatestScheme.SlippageBips; orderClass: cowAppDataLatestScheme.OrderClass['orderClass']; partnerFee?: cowAppDataLatestScheme.PartnerFee; } /** * Information about the app-data for trading operations, including the JSON document and the keccak256 hash of the full document. * * See https://github.com/cowprotocol/app-data */ interface TradingAppDataInfo { doc: LatestAppDataDocVersion; fullAppData: AppData; appDataKeccak256: AppDataHash; } /** * A standard Ethereum transaction object */ interface TradingTransactionParams { data: string; gasLimit: string; to: string; value: string; } interface EthFlowOrderExistsCallback { (orderId: string, orderDigest: string): Promise; } /** * Additional parameters for posting orders. * In most of the cases you don't need to use them. */ interface PostTradeAdditionalParams { /** * Selling native token orders are special, because they are created from smart-contract, * and their validTo is always the same. * Because of that, you might get the same orderId when trying to create an order with the same parameters * The callback is needed to check if there is already an order with the same orderId * * @see https://github.com/cowprotocol/ethflowcontract/blob/main/src/libraries/EthFlowOrder.sol#L90 */ checkEthFlowOrderExists?: EthFlowOrderExistsCallback; /** * Cost of executing the order onchain. * The value is used in getQuoteAmountsAndCosts in order to calculate proper amounts */ networkCostsAmount?: string; /** * By default, is EIP712 for EOA wallets. * You might need other types of signing, for example PRESIGN when sign order via Smart Contract wallets. */ signingScheme?: SigningScheme; customEIP1271Signature?: (orderToSign: UnsignedOrder, signer: AbstractSigner) => Promise; /** * By default, we adjust the quoted sell/buy amounts to include network gas costs, slippage buffer, * partner fees, and similar extras. Disable this when you prefer to post the raw amounts provided * by the caller (for example, for limit orders that should not include these costs). */ applyCostsSlippageAndFees?: boolean; protocolFeeBps?: number; } type QuoteResultsWithSigner = { result: QuoteResults & { signer: AbstractSigner; }; orderBookApi: OrderBookApi; }; declare function getQuote(_tradeParameters: TradeParameters, trader: QuoterParameters, advancedSettings?: SwapAdvancedSettings, _orderBookApi?: OrderBookApi): Promise<{ result: QuoteResults; orderBookApi: OrderBookApi; }>; declare function getQuoteWithSigner(swapParameters: SwapParameters, advancedSettings?: SwapAdvancedSettings, orderBookApi?: OrderBookApi): Promise; declare function postSellNativeCurrencyOrder(orderBookApi: OrderBookApi, appData: Pick, _params: LimitTradeParametersFromQuote, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise; declare function getPreSignTransaction(signer: Signer, chainId: SupportedChainId, orderId: string, options?: ProtocolOptions): Promise; type WithPartialTraderParams = T & Partial; /** * Parameters for quoting that don't require a signer. * Requires `owner` (the account address) instead of a signer, * since quoting only needs an address to estimate costs. */ type QuoteOnlyParams = T & Partial> & { owner: AccountAddress; }; type OrderTraderParams = WithPartialTraderParams<{ orderUid: string; }>; interface TradingSdkOptions { enableLogging: boolean; orderBookApi: OrderBookApi; } declare class TradingSdk { traderParams: Partial; readonly options: Partial; constructor(traderParams?: Partial, options?: Partial, adapter?: AbstractProviderAdapter); setTraderParams(params: Partial): this; getQuote(params: WithPartialTraderParams, advancedSettings?: SwapAdvancedSettings): Promise; /** * Gets a quote without requiring a signer or wallet connection. * Useful for building UIs that preview swap quotes before the user connects a wallet. * * Unlike {@link getQuote}, this method only requires an `owner` address (the account * to quote for) instead of a signer. The returned result contains quote information * but no `postSwapOrderFromQuote` helper, since posting requires signing. * * @param params - Trade parameters with `owner` address. Signer is not needed. * @param advancedSettings - Optional advanced settings for the swap quote. * @returns Quote results including amounts, costs, slippage, and order data. * * @example * ```typescript * // Get a quote without a connected wallet * const sdk = new TradingSdk( * { chainId: 1, appCode: 'My App' }, * { orderBookApi }, * ) * * const quoteResults = await sdk.getQuoteOnly({ * owner: '0x1234...', // any valid address * kind: OrderKind.SELL, * sellToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', * sellTokenDecimals: 6, * buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', * buyTokenDecimals: 18, * amount: '1000000000', // 1000 USDC * }) * * console.log(quoteResults.amountsAndCosts) * ``` */ getQuoteOnly(params: QuoteOnlyParams, advancedSettings?: SwapAdvancedSettings): Promise; getQuoteResults(params: WithPartialTraderParams, advancedSettings?: SwapAdvancedSettings): Promise; postSwapOrder(params: WithPartialTraderParams, advancedSettings?: SwapAdvancedSettings): Promise; postLimitOrder(params: WithPartialTraderParams, advancedSettings?: LimitOrderAdvancedSettings): Promise; /** * Posts a sell order for native currency (e.g., ETH) using the EthFlow contract. * This method creates an on-chain transaction for selling native tokens. * * @param params - The trade parameters including token addresses and amounts * @param advancedSettings - Optional advanced settings for the swap * @returns Promise resolving to the order posting result with transaction hash and order ID * * @example * ```typescript * const parameters: TradeParameters = { * kind: OrderKind.SELL, * sellToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // Native ETH * sellTokenDecimals: 18, * buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59', * buyTokenDecimals: 18, * amount: '100000000000000000', // 0.1 ETH * } * * const { orderId, txHash } = await sdk.postSellNativeCurrencyOrder(parameters) * ``` */ postSellNativeCurrencyOrder(params: WithPartialTraderParams, advancedSettings?: SwapAdvancedSettings): Promise>; getPreSignTransaction(params: OrderTraderParams): ReturnType; getOrder(params: OrderTraderParams): Promise; offChainCancelOrder(params: OrderTraderParams): Promise; onChainCancelOrder(params: OrderTraderParams, _order?: EnrichedOrder): Promise; /** * Checks the current allowance for the CoW Protocol Vault Relayer to spend an ERC-20 token. * * @param params - Parameters including token address and owner address * @returns Promise resolving to the current allowance amount as a bigint * * @example * ```typescript * const params = { * tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC * owner: '0x123...', * chainId: 1, * } * * const allowance = await sdk.getCowProtocolAllowance(params) * console.log('Current allowance:', allowance.toString()) * ``` */ getCowProtocolAllowance(params: WithPartialTraderParams<{ tokenAddress: string; owner: string; vaultRelayerAddress?: Address; }>): Promise; /** * Approves the CoW Protocol Vault Relayer to spend a specified amount of an ERC-20 token. * This method creates an on-chain approval transaction. * * @param params - Parameters including token address and amount to approve * @returns Promise resolving to the transaction hash of the approval transaction * * @example * ```typescript * const params = { * tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC * amount: '1000000000', // 1000 USDC (6 decimals) * chainId: 1, * } * * const txHash = await sdk.approveCowProtocol(params) * console.log('Approval transaction:', txHash) * ``` */ approveCowProtocol(params: WithPartialTraderParams<{ tokenAddress: string; amount: bigint; vaultRelayerAddress?: Address; }>): Promise; private resolveOrderBookApi; private mergeParams; /** * Merges quoter-specific parameters (chainId, appCode, env, owner) without requiring a signer. * Used by quote-only operations that don't need signing capability. */ private mergeQuoterParams; } declare function getEthFlowTransaction(appDataKeccak256: string, _params: LimitTradeParametersFromQuote, chainId: SupportedChainId, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<{ orderId: string; transaction: TradingTransactionParams; orderToSign: UnsignedOrder; }>; declare function getEthFlowContract(signer: Signer, chainId: SupportedChainId, options?: ProtocolOptions): EthFlowContract; interface OrderToSignParams { chainId: SupportedChainId; isEthFlow: boolean; from: string; networkCostsAmount?: string; applyCostsSlippageAndFees?: boolean; protocolFeeBps?: number; } declare function getOrderToSign({ chainId, from, networkCostsAmount, isEthFlow, applyCostsSlippageAndFees, protocolFeeBps, }: OrderToSignParams, limitOrderParams: LimitTradeParameters, appDataKeccak256: string): UnsignedOrder; declare function postCoWProtocolTrade(orderBookApi: OrderBookApi, appData: TradingAppDataInfo, params: LimitTradeParameters, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise; declare function postLimitOrder(_params: LimitOrderParameters, advancedSettings?: LimitOrderAdvancedSettings, _orderBookApi?: OrderBookApi): Promise; declare function postSwapOrder(params: SwapParameters, advancedSettings?: SwapAdvancedSettings, orderBookApi?: OrderBookApi): Promise; declare function postSwapOrderFromQuote({ orderBookApi, result: { signer, appDataInfo: _appDataInfo, quoteResponse, tradeParameters }, }: QuoteResultsWithSigner, advancedSettings?: SwapAdvancedSettings): Promise; interface SuggestSlippageBps { tradeParameters: Pick; isEthFlow: boolean; quote: OrderQuoteResponse; trader: QuoterParameters; advancedSettings?: SwapAdvancedSettings; volumeMultiplierPercent?: number; } /** * Return the slippage in BPS that would allow the fee to increase by the multiplying factor percent. */ declare function suggestSlippageBps(params: SuggestSlippageBps): number; /** * Get default UTM parameters for developer attribution tracking */ declare function getDefaultUtmParams(): { utmCampaign: string; utmContent: string; utmMedium: string; utmSource: string; utmTerm: string; }; declare function buildAppData({ slippageBps, appCode, orderClass: orderClassName, partnerFee }: BuildAppDataParams, advancedParams?: AppDataParams): Promise; declare function generateAppDataFromDoc(doc: AppDataRootSchema): Promise>; declare function mergeAppDataDoc(_doc: LatestAppDataDocVersion, appDataOverride: AppDataParams): Promise; declare function calculateUniqueOrderId(chainId: SupportedChainId, order: UnsignedOrder, checkEthFlowOrderExists?: EthFlowOrderExistsCallback, options?: ProtocolOptions): Promise; declare function getPartnerFeeBps(partnerFee: cowAppDataLatestScheme.PartnerFee | undefined): number | undefined; declare function swapParamsToLimitOrderParams(params: TradeParameters, quoteResponse: OrderQuoteResponse): LimitTradeParametersFromQuote; declare function mapQuoteAmountsAndCosts(value: QuoteAmountsAndCosts, mapper: (value: T) => R): QuoteAmountsAndCosts; /** * Set sell token to the initial one * Because for ETH-flow orders we do quote requests with wrapped token */ declare function getTradeParametersAfterQuote({ quoteParameters, sellToken, }: { quoteParameters: TradeParameters; sellToken: string; }): TradeParameters; export { type AppDataRootSchema, type BuildAppDataParams, type EthFlowOrderExistsCallback, type LimitOrderAdvancedSettings, type LimitOrderParameters, type LimitTradeParameters, type LimitTradeParametersFromQuote, type OrderPostingResult, type OrderTraderParams, type OrderTypedData, type PostTradeAdditionalParams, type QuoteAndPost, type QuoteOnlyParams, type QuoteResults, type QuoteResultsSerialized, type QuoteResultsWithSigner, type QuoterParameters, type SigningStepManager, type SlippageToleranceRequest, type SlippageToleranceResponse, type SwapAdvancedSettings, type SwapParameters, type TradeBaseParameters, type TradeOptionalParameters, type TradeParameters, type TraderParameters, type TradingAppDataInfo, TradingSdk, type TradingSdkOptions, type TradingTransactionParams, type WithPartialTraderParams, buildAppData, calculateUniqueOrderId, generateAppDataFromDoc, getDefaultUtmParams, getEthFlowContract, getEthFlowTransaction, getOrderToSign, getPartnerFeeBps, getPreSignTransaction, getQuote, getQuoteWithSigner, getQuote as getQuoteWithoutSigner, getTradeParametersAfterQuote, mapQuoteAmountsAndCosts, mergeAppDataDoc, postCoWProtocolTrade, postLimitOrder, postSellNativeCurrencyOrder, postSwapOrder, postSwapOrderFromQuote, suggestSlippageBps, swapParamsToLimitOrderParams };