@cowprotocol/sdk-trading 0.11.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -265,6 +265,14 @@ declare function postSellNativeCurrencyOrder(orderBookApi: OrderBookApi, appData
265
265
  declare function getPreSignTransaction(signer: Signer, chainId: SupportedChainId, orderId: string): Promise<TradingTransactionParams>;
266
266
 
267
267
  type WithPartialTraderParams<T> = T & Partial<TraderParameters>;
268
+ /**
269
+ * Parameters for quoting that don't require a signer.
270
+ * Requires `owner` (the account address) instead of a signer,
271
+ * since quoting only needs an address to estimate costs.
272
+ */
273
+ type QuoteOnlyParams<T> = T & Partial<Omit<TraderParameters, 'signer'>> & {
274
+ owner: AccountAddress;
275
+ };
268
276
  type OrderTraderParams = WithPartialTraderParams<{
269
277
  orderUid: string;
270
278
  }>;
@@ -278,6 +286,40 @@ declare class TradingSdk {
278
286
  constructor(traderParams?: Partial<TraderParameters>, options?: Partial<TradingSdkOptions>, adapter?: AbstractProviderAdapter);
279
287
  setTraderParams(params: Partial<TraderParameters>): this;
280
288
  getQuote(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteAndPost>;
289
+ /**
290
+ * Gets a quote without requiring a signer or wallet connection.
291
+ * Useful for building UIs that preview swap quotes before the user connects a wallet.
292
+ *
293
+ * Unlike {@link getQuote}, this method only requires an `owner` address (the account
294
+ * to quote for) instead of a signer. The returned result contains quote information
295
+ * but no `postSwapOrderFromQuote` helper, since posting requires signing.
296
+ *
297
+ * @param params - Trade parameters with `owner` address. Signer is not needed.
298
+ * @param advancedSettings - Optional advanced settings for the swap quote.
299
+ * @returns Quote results including amounts, costs, slippage, and order data.
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * // Get a quote without a connected wallet
304
+ * const sdk = new TradingSdk(
305
+ * { chainId: 1, appCode: 'My App' },
306
+ * { orderBookApi },
307
+ * )
308
+ *
309
+ * const quoteResults = await sdk.getQuoteOnly({
310
+ * owner: '0x1234...', // any valid address
311
+ * kind: OrderKind.SELL,
312
+ * sellToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
313
+ * sellTokenDecimals: 6,
314
+ * buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
315
+ * buyTokenDecimals: 18,
316
+ * amount: '1000000000', // 1000 USDC
317
+ * })
318
+ *
319
+ * console.log(quoteResults.amountsAndCosts)
320
+ * ```
321
+ */
322
+ getQuoteOnly(params: QuoteOnlyParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteResults>;
281
323
  getQuoteResults(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteResultsWithSigner>;
282
324
  postSwapOrder(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
283
325
  postLimitOrder(params: WithPartialTraderParams<LimitTradeParameters>, advancedSettings?: LimitOrderAdvancedSettings): Promise<OrderPostingResult>;
@@ -355,6 +397,11 @@ declare class TradingSdk {
355
397
  }>): Promise<string>;
356
398
  private resolveOrderBookApi;
357
399
  private mergeParams;
400
+ /**
401
+ * Merges quoter-specific parameters (chainId, appCode, env, owner) without requiring a signer.
402
+ * Used by quote-only operations that don't need signing capability.
403
+ */
404
+ private mergeQuoterParams;
358
405
  }
359
406
 
360
407
  declare function getEthFlowTransaction(appDataKeccak256: string, _params: LimitTradeParametersFromQuote, chainId: SupportedChainId, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<{
@@ -372,7 +419,7 @@ interface OrderToSignParams {
372
419
  applyCostsSlippageAndFees?: boolean;
373
420
  protocolFeeBps?: number;
374
421
  }
375
- declare function getOrderToSign({ chainId, from, networkCostsAmount, isEthFlow, applyCostsSlippageAndFees, protocolFeeBps }: OrderToSignParams, limitOrderParams: LimitTradeParameters, appDataKeccak256: string): UnsignedOrder;
422
+ declare function getOrderToSign({ chainId, from, networkCostsAmount, isEthFlow, applyCostsSlippageAndFees, protocolFeeBps, }: OrderToSignParams, limitOrderParams: LimitTradeParameters, appDataKeccak256: string): UnsignedOrder;
376
423
 
377
424
  declare function postCoWProtocolTrade(orderBookApi: OrderBookApi, appData: TradingAppDataInfo, params: LimitTradeParameters, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<OrderPostingResult>;
378
425
 
@@ -423,4 +470,4 @@ declare function getTradeParametersAfterQuote({ quoteParameters, sellToken, }: {
423
470
  sellToken: string;
424
471
  }): TradeParameters;
425
472
 
426
- 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 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, getTradeParametersAfterQuote, mapQuoteAmountsAndCosts, mergeAppDataDoc, postCoWProtocolTrade, postLimitOrder, postSellNativeCurrencyOrder, postSwapOrder, postSwapOrderFromQuote, suggestSlippageBps, swapParamsToLimitOrderParams };
473
+ 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 };
package/dist/index.d.ts CHANGED
@@ -265,6 +265,14 @@ declare function postSellNativeCurrencyOrder(orderBookApi: OrderBookApi, appData
265
265
  declare function getPreSignTransaction(signer: Signer, chainId: SupportedChainId, orderId: string): Promise<TradingTransactionParams>;
266
266
 
267
267
  type WithPartialTraderParams<T> = T & Partial<TraderParameters>;
268
+ /**
269
+ * Parameters for quoting that don't require a signer.
270
+ * Requires `owner` (the account address) instead of a signer,
271
+ * since quoting only needs an address to estimate costs.
272
+ */
273
+ type QuoteOnlyParams<T> = T & Partial<Omit<TraderParameters, 'signer'>> & {
274
+ owner: AccountAddress;
275
+ };
268
276
  type OrderTraderParams = WithPartialTraderParams<{
269
277
  orderUid: string;
270
278
  }>;
@@ -278,6 +286,40 @@ declare class TradingSdk {
278
286
  constructor(traderParams?: Partial<TraderParameters>, options?: Partial<TradingSdkOptions>, adapter?: AbstractProviderAdapter);
279
287
  setTraderParams(params: Partial<TraderParameters>): this;
280
288
  getQuote(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteAndPost>;
289
+ /**
290
+ * Gets a quote without requiring a signer or wallet connection.
291
+ * Useful for building UIs that preview swap quotes before the user connects a wallet.
292
+ *
293
+ * Unlike {@link getQuote}, this method only requires an `owner` address (the account
294
+ * to quote for) instead of a signer. The returned result contains quote information
295
+ * but no `postSwapOrderFromQuote` helper, since posting requires signing.
296
+ *
297
+ * @param params - Trade parameters with `owner` address. Signer is not needed.
298
+ * @param advancedSettings - Optional advanced settings for the swap quote.
299
+ * @returns Quote results including amounts, costs, slippage, and order data.
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * // Get a quote without a connected wallet
304
+ * const sdk = new TradingSdk(
305
+ * { chainId: 1, appCode: 'My App' },
306
+ * { orderBookApi },
307
+ * )
308
+ *
309
+ * const quoteResults = await sdk.getQuoteOnly({
310
+ * owner: '0x1234...', // any valid address
311
+ * kind: OrderKind.SELL,
312
+ * sellToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
313
+ * sellTokenDecimals: 6,
314
+ * buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
315
+ * buyTokenDecimals: 18,
316
+ * amount: '1000000000', // 1000 USDC
317
+ * })
318
+ *
319
+ * console.log(quoteResults.amountsAndCosts)
320
+ * ```
321
+ */
322
+ getQuoteOnly(params: QuoteOnlyParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteResults>;
281
323
  getQuoteResults(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteResultsWithSigner>;
282
324
  postSwapOrder(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
283
325
  postLimitOrder(params: WithPartialTraderParams<LimitTradeParameters>, advancedSettings?: LimitOrderAdvancedSettings): Promise<OrderPostingResult>;
@@ -355,6 +397,11 @@ declare class TradingSdk {
355
397
  }>): Promise<string>;
356
398
  private resolveOrderBookApi;
357
399
  private mergeParams;
400
+ /**
401
+ * Merges quoter-specific parameters (chainId, appCode, env, owner) without requiring a signer.
402
+ * Used by quote-only operations that don't need signing capability.
403
+ */
404
+ private mergeQuoterParams;
358
405
  }
359
406
 
360
407
  declare function getEthFlowTransaction(appDataKeccak256: string, _params: LimitTradeParametersFromQuote, chainId: SupportedChainId, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<{
@@ -372,7 +419,7 @@ interface OrderToSignParams {
372
419
  applyCostsSlippageAndFees?: boolean;
373
420
  protocolFeeBps?: number;
374
421
  }
375
- declare function getOrderToSign({ chainId, from, networkCostsAmount, isEthFlow, applyCostsSlippageAndFees, protocolFeeBps }: OrderToSignParams, limitOrderParams: LimitTradeParameters, appDataKeccak256: string): UnsignedOrder;
422
+ declare function getOrderToSign({ chainId, from, networkCostsAmount, isEthFlow, applyCostsSlippageAndFees, protocolFeeBps, }: OrderToSignParams, limitOrderParams: LimitTradeParameters, appDataKeccak256: string): UnsignedOrder;
376
423
 
377
424
  declare function postCoWProtocolTrade(orderBookApi: OrderBookApi, appData: TradingAppDataInfo, params: LimitTradeParameters, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<OrderPostingResult>;
378
425
 
@@ -423,4 +470,4 @@ declare function getTradeParametersAfterQuote({ quoteParameters, sellToken, }: {
423
470
  sellToken: string;
424
471
  }): TradeParameters;
425
472
 
426
- 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 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, getTradeParametersAfterQuote, mapQuoteAmountsAndCosts, mergeAppDataDoc, postCoWProtocolTrade, postLimitOrder, postSellNativeCurrencyOrder, postSwapOrder, postSwapOrderFromQuote, suggestSlippageBps, swapParamsToLimitOrderParams };
473
+ 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 };
package/dist/index.js CHANGED
@@ -42,6 +42,7 @@ __export(src_exports, {
42
42
  getPreSignTransaction: () => getPreSignTransaction,
43
43
  getQuote: () => getQuote,
44
44
  getQuoteWithSigner: () => getQuoteWithSigner,
45
+ getQuoteWithoutSigner: () => getQuote,
45
46
  getTradeParametersAfterQuote: () => getTradeParametersAfterQuote,
46
47
  mapQuoteAmountsAndCosts: () => mapQuoteAmountsAndCosts,
47
48
  mergeAppDataDoc: () => mergeAppDataDoc,
@@ -134,14 +135,19 @@ function unsignedOrderForSigning(order) {
134
135
  }
135
136
 
136
137
  // src/getOrderToSign.ts
137
- function getOrderToSign({ chainId, from, networkCostsAmount = "0", isEthFlow, applyCostsSlippageAndFees = true, protocolFeeBps }, limitOrderParams, appDataKeccak256) {
138
+ function getOrderToSign({
139
+ chainId,
140
+ from,
141
+ networkCostsAmount = "0",
142
+ isEthFlow,
143
+ applyCostsSlippageAndFees = true,
144
+ protocolFeeBps
145
+ }, limitOrderParams, appDataKeccak256) {
138
146
  const {
139
147
  sellAmount,
140
148
  buyAmount,
141
149
  sellToken,
142
- sellTokenDecimals,
143
150
  buyToken,
144
- buyTokenDecimals,
145
151
  kind,
146
152
  partiallyFillable = false,
147
153
  slippageBps = getDefaultSlippageBps(chainId, isEthFlow),
@@ -165,16 +171,14 @@ function getOrderToSign({ chainId, from, networkCostsAmount = "0", isEthFlow, ap
165
171
  let sellAmountToUse = sellAmount;
166
172
  let buyAmountToUse = buyAmount;
167
173
  if (applyCostsSlippageAndFees) {
168
- const { afterSlippage } = (0, import_sdk_order_book2.getQuoteAmountsAndCosts)({
174
+ const { isSell, beforeAllFees, afterSlippage } = (0, import_sdk_order_book2.getQuoteAmountsAndCosts)({
169
175
  orderParams,
170
176
  slippagePercentBps: slippageBps,
171
177
  partnerFeeBps: getPartnerFeeBps(partnerFee),
172
- protocolFeeBps,
173
- sellDecimals: sellTokenDecimals,
174
- buyDecimals: buyTokenDecimals
178
+ protocolFeeBps
175
179
  });
176
- sellAmountToUse = afterSlippage.sellAmount.toString();
177
- buyAmountToUse = afterSlippage.buyAmount.toString();
180
+ sellAmountToUse = isSell ? beforeAllFees.sellAmount.toString() : afterSlippage.sellAmount.toString();
181
+ buyAmountToUse = isSell ? afterSlippage.buyAmount.toString() : beforeAllFees.buyAmount.toString();
178
182
  }
179
183
  return {
180
184
  sellToken,
@@ -255,6 +259,7 @@ function mapQuoteAmountsAndCosts(value, mapper) {
255
259
  buyAmount: mapper(value2.buyAmount)
256
260
  };
257
261
  }
262
+ const beforeNetworkCosts = serializeAmounts(value.beforeNetworkCosts);
258
263
  return {
259
264
  ...value,
260
265
  costs: {
@@ -274,10 +279,12 @@ function mapQuoteAmountsAndCosts(value, mapper) {
274
279
  }
275
280
  },
276
281
  beforeAllFees: serializeAmounts(value.beforeAllFees),
277
- beforeNetworkCosts: serializeAmounts(value.beforeNetworkCosts),
282
+ beforeNetworkCosts,
283
+ afterProtocolFees: beforeNetworkCosts,
278
284
  afterNetworkCosts: serializeAmounts(value.afterNetworkCosts),
279
285
  afterPartnerFees: serializeAmounts(value.afterPartnerFees),
280
- afterSlippage: serializeAmounts(value.afterSlippage)
286
+ afterSlippage: serializeAmounts(value.afterSlippage),
287
+ amountsToSign: serializeAmounts(value.amountsToSign)
281
288
  };
282
289
  }
283
290
  function getTradeParametersAfterQuote({
@@ -459,7 +466,7 @@ var import_deepmerge = __toESM(require("deepmerge"));
459
466
  // ../sdk/package.json
460
467
  var package_default = {
461
468
  name: "@cowprotocol/cow-sdk",
462
- version: "7.3.7",
469
+ version: "7.4.0",
463
470
  license: "(MIT OR Apache-2.0)",
464
471
  description: "CoW Protocol SDK - get quote, configure your order, and trade",
465
472
  main: "./dist/index.js",
@@ -664,18 +671,16 @@ var MAX_SLIPPAGE_BPS = 1e4;
664
671
  var SLIPPAGE_FEE_MULTIPLIER_PERCENT = 50;
665
672
  var SLIPPAGE_VOLUME_MULTIPLIER_PERCENT = 0.5;
666
673
  function suggestSlippageBps(params) {
674
+ const { quote, trader, isEthFlow, volumeMultiplierPercent = SLIPPAGE_VOLUME_MULTIPLIER_PERCENT } = params;
675
+ const isSell = quote.quote.kind === import_sdk_order_book5.OrderKind.SELL;
667
676
  const {
668
- quote,
669
- tradeParameters,
670
- trader,
671
- isEthFlow,
672
- volumeMultiplierPercent = SLIPPAGE_VOLUME_MULTIPLIER_PERCENT
673
- } = params;
674
- const { sellTokenDecimals, buyTokenDecimals } = tradeParameters;
675
- const { isSell, sellAmountBeforeNetworkCosts, sellAmountAfterNetworkCosts } = (0, import_sdk_order_book5.getQuoteAmountsWithCosts)({
676
- sellDecimals: sellTokenDecimals,
677
- buyDecimals: buyTokenDecimals,
678
- orderParams: quote.quote
677
+ beforeNetworkCosts: { sellAmount: sellAmountBeforeNetworkCosts },
678
+ afterNetworkCosts: { sellAmount: sellAmountAfterNetworkCosts }
679
+ } = (0, import_sdk_order_book5.getQuoteAmountsAndCosts)({
680
+ orderParams: quote.quote,
681
+ protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : 0,
682
+ partnerFeeBps: void 0,
683
+ slippagePercentBps: 0
679
684
  });
680
685
  const { feeAmount: feeAmountString } = quote.quote;
681
686
  const feeAmount = BigInt(feeAmountString);
@@ -720,17 +725,16 @@ async function resolveSlippageSuggestion(chainId, tradeParameters, trader, quote
720
725
  orderParams: quote.quote,
721
726
  slippagePercentBps: 0,
722
727
  partnerFeeBps: getPartnerFeeBps(tradeParameters.partnerFee),
723
- protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0,
724
- sellDecimals: tradeParameters.sellTokenDecimals,
725
- buyDecimals: tradeParameters.buyTokenDecimals
728
+ protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0
726
729
  });
730
+ const { isSell, beforeAllFees, afterSlippage } = amountsAndCosts;
727
731
  try {
728
732
  const suggestedSlippage = await getSlippageSuggestion({
729
733
  chainId,
730
734
  sellToken: tradeParameters.sellToken,
731
735
  buyToken: tradeParameters.buyToken,
732
- sellAmount: amountsAndCosts.afterSlippage.sellAmount,
733
- buyAmount: amountsAndCosts.afterSlippage.buyAmount
736
+ sellAmount: isSell ? beforeAllFees.sellAmount : afterSlippage.sellAmount,
737
+ buyAmount: isSell ? afterSlippage.buyAmount : beforeAllFees.buyAmount
734
738
  });
735
739
  const suggestedSlippageBps = suggestedSlippage.slippageBps;
736
740
  return {
@@ -865,15 +869,13 @@ async function getQuoteRaw(_tradeParameters, trader, advancedSettings, _orderBoo
865
869
  }
866
870
  async function getQuote(_tradeParameters, trader, advancedSettings, _orderBookApi) {
867
871
  const { quote, orderBookApi, tradeParameters, slippageBps, suggestedSlippageBps, appDataInfo, isEthFlow } = await getQuoteRaw(_tradeParameters, trader, advancedSettings, _orderBookApi);
868
- const { partnerFee, sellTokenDecimals, buyTokenDecimals } = tradeParameters;
872
+ const { partnerFee } = tradeParameters;
869
873
  const { chainId, account: from } = trader;
870
874
  const amountsAndCosts = (0, import_sdk_order_book7.getQuoteAmountsAndCosts)({
871
875
  orderParams: quote.quote,
872
876
  slippagePercentBps: slippageBps,
873
877
  partnerFeeBps: getPartnerFeeBps(partnerFee),
874
- protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0,
875
- sellDecimals: sellTokenDecimals,
876
- buyDecimals: buyTokenDecimals
878
+ protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0
877
879
  });
878
880
  const orderToSign = getOrderToSign(
879
881
  {
@@ -1156,6 +1158,50 @@ var TradingSdk = class {
1156
1158
  }
1157
1159
  };
1158
1160
  }
1161
+ /**
1162
+ * Gets a quote without requiring a signer or wallet connection.
1163
+ * Useful for building UIs that preview swap quotes before the user connects a wallet.
1164
+ *
1165
+ * Unlike {@link getQuote}, this method only requires an `owner` address (the account
1166
+ * to quote for) instead of a signer. The returned result contains quote information
1167
+ * but no `postSwapOrderFromQuote` helper, since posting requires signing.
1168
+ *
1169
+ * @param params - Trade parameters with `owner` address. Signer is not needed.
1170
+ * @param advancedSettings - Optional advanced settings for the swap quote.
1171
+ * @returns Quote results including amounts, costs, slippage, and order data.
1172
+ *
1173
+ * @example
1174
+ * ```typescript
1175
+ * // Get a quote without a connected wallet
1176
+ * const sdk = new TradingSdk(
1177
+ * { chainId: 1, appCode: 'My App' },
1178
+ * { orderBookApi },
1179
+ * )
1180
+ *
1181
+ * const quoteResults = await sdk.getQuoteOnly({
1182
+ * owner: '0x1234...', // any valid address
1183
+ * kind: OrderKind.SELL,
1184
+ * sellToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1185
+ * sellTokenDecimals: 6,
1186
+ * buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1187
+ * buyTokenDecimals: 18,
1188
+ * amount: '1000000000', // 1000 USDC
1189
+ * })
1190
+ *
1191
+ * console.log(quoteResults.amountsAndCosts)
1192
+ * ```
1193
+ */
1194
+ async getQuoteOnly(params, advancedSettings) {
1195
+ const quoterParams = this.mergeQuoterParams(params);
1196
+ const trader = {
1197
+ chainId: quoterParams.chainId,
1198
+ appCode: quoterParams.appCode,
1199
+ env: quoterParams.env,
1200
+ account: quoterParams.owner
1201
+ };
1202
+ const result = await getQuote(quoterParams, trader, advancedSettings, this.options.orderBookApi);
1203
+ return result.result;
1204
+ }
1159
1205
  async getQuoteResults(params, advancedSettings) {
1160
1206
  return getQuoteWithSigner(this.mergeParams(params), advancedSettings, this.options.orderBookApi);
1161
1207
  }
@@ -1329,6 +1375,27 @@ var TradingSdk = class {
1329
1375
  ...traderParams
1330
1376
  };
1331
1377
  }
1378
+ /**
1379
+ * Merges quoter-specific parameters (chainId, appCode, env, owner) without requiring a signer.
1380
+ * Used by quote-only operations that don't need signing capability.
1381
+ */
1382
+ mergeQuoterParams(params) {
1383
+ const chainId = params.chainId || this.traderParams.chainId;
1384
+ const appCode = params.appCode || this.traderParams.appCode;
1385
+ const env = params.env || this.traderParams.env || "prod";
1386
+ if (!chainId) {
1387
+ throw new Error("Missing quoter parameters: chainId");
1388
+ }
1389
+ if (!appCode) {
1390
+ throw new Error("Missing quoter parameters: appCode");
1391
+ }
1392
+ return {
1393
+ ...params,
1394
+ chainId,
1395
+ appCode,
1396
+ env
1397
+ };
1398
+ }
1332
1399
  };
1333
1400
  function assertTraderParams(params) {
1334
1401
  if (!isTraderParameters(params)) {
@@ -1362,6 +1429,7 @@ function isTraderParameters(params) {
1362
1429
  getPreSignTransaction,
1363
1430
  getQuote,
1364
1431
  getQuoteWithSigner,
1432
+ getQuoteWithoutSigner,
1365
1433
  getTradeParametersAfterQuote,
1366
1434
  mapQuoteAmountsAndCosts,
1367
1435
  mergeAppDataDoc,
package/dist/index.mjs CHANGED
@@ -81,14 +81,19 @@ function unsignedOrderForSigning(order) {
81
81
  }
82
82
 
83
83
  // src/getOrderToSign.ts
84
- function getOrderToSign({ chainId, from, networkCostsAmount = "0", isEthFlow, applyCostsSlippageAndFees = true, protocolFeeBps }, limitOrderParams, appDataKeccak256) {
84
+ function getOrderToSign({
85
+ chainId,
86
+ from,
87
+ networkCostsAmount = "0",
88
+ isEthFlow,
89
+ applyCostsSlippageAndFees = true,
90
+ protocolFeeBps
91
+ }, limitOrderParams, appDataKeccak256) {
85
92
  const {
86
93
  sellAmount,
87
94
  buyAmount,
88
95
  sellToken,
89
- sellTokenDecimals,
90
96
  buyToken,
91
- buyTokenDecimals,
92
97
  kind,
93
98
  partiallyFillable = false,
94
99
  slippageBps = getDefaultSlippageBps(chainId, isEthFlow),
@@ -112,16 +117,14 @@ function getOrderToSign({ chainId, from, networkCostsAmount = "0", isEthFlow, ap
112
117
  let sellAmountToUse = sellAmount;
113
118
  let buyAmountToUse = buyAmount;
114
119
  if (applyCostsSlippageAndFees) {
115
- const { afterSlippage } = getQuoteAmountsAndCosts({
120
+ const { isSell, beforeAllFees, afterSlippage } = getQuoteAmountsAndCosts({
116
121
  orderParams,
117
122
  slippagePercentBps: slippageBps,
118
123
  partnerFeeBps: getPartnerFeeBps(partnerFee),
119
- protocolFeeBps,
120
- sellDecimals: sellTokenDecimals,
121
- buyDecimals: buyTokenDecimals
124
+ protocolFeeBps
122
125
  });
123
- sellAmountToUse = afterSlippage.sellAmount.toString();
124
- buyAmountToUse = afterSlippage.buyAmount.toString();
126
+ sellAmountToUse = isSell ? beforeAllFees.sellAmount.toString() : afterSlippage.sellAmount.toString();
127
+ buyAmountToUse = isSell ? afterSlippage.buyAmount.toString() : beforeAllFees.buyAmount.toString();
125
128
  }
126
129
  return {
127
130
  sellToken,
@@ -207,6 +210,7 @@ function mapQuoteAmountsAndCosts(value, mapper) {
207
210
  buyAmount: mapper(value2.buyAmount)
208
211
  };
209
212
  }
213
+ const beforeNetworkCosts = serializeAmounts(value.beforeNetworkCosts);
210
214
  return {
211
215
  ...value,
212
216
  costs: {
@@ -226,10 +230,12 @@ function mapQuoteAmountsAndCosts(value, mapper) {
226
230
  }
227
231
  },
228
232
  beforeAllFees: serializeAmounts(value.beforeAllFees),
229
- beforeNetworkCosts: serializeAmounts(value.beforeNetworkCosts),
233
+ beforeNetworkCosts,
234
+ afterProtocolFees: beforeNetworkCosts,
230
235
  afterNetworkCosts: serializeAmounts(value.afterNetworkCosts),
231
236
  afterPartnerFees: serializeAmounts(value.afterPartnerFees),
232
- afterSlippage: serializeAmounts(value.afterSlippage)
237
+ afterSlippage: serializeAmounts(value.afterSlippage),
238
+ amountsToSign: serializeAmounts(value.amountsToSign)
233
239
  };
234
240
  }
235
241
  function getTradeParametersAfterQuote({
@@ -405,7 +411,7 @@ async function postCoWProtocolTrade(orderBookApi, appData, params, additionalPar
405
411
  // src/getQuote.ts
406
412
  import { getGlobalAdapter as getGlobalAdapter5, log as log4 } from "@cowprotocol/sdk-common";
407
413
  import {
408
- getQuoteAmountsAndCosts as getQuoteAmountsAndCosts3,
414
+ getQuoteAmountsAndCosts as getQuoteAmountsAndCosts4,
409
415
  OrderBookApi as OrderBookApi3,
410
416
  OrderQuoteSideKindBuy,
411
417
  OrderQuoteSideKindSell,
@@ -424,7 +430,7 @@ import deepmerge from "deepmerge";
424
430
  // ../sdk/package.json
425
431
  var package_default = {
426
432
  name: "@cowprotocol/cow-sdk",
427
- version: "7.3.7",
433
+ version: "7.4.0",
428
434
  license: "(MIT OR Apache-2.0)",
429
435
  description: "CoW Protocol SDK - get quote, configure your order, and trade",
430
436
  main: "./dist/index.js",
@@ -591,11 +597,11 @@ async function getOrderTypedData(chainId, orderToSign) {
591
597
 
592
598
  // src/resolveSlippageSuggestion.ts
593
599
  import { bpsToPercentage, log as log3 } from "@cowprotocol/sdk-common";
594
- import { getQuoteAmountsAndCosts as getQuoteAmountsAndCosts2, PriceQuality } from "@cowprotocol/sdk-order-book";
600
+ import { getQuoteAmountsAndCosts as getQuoteAmountsAndCosts3, PriceQuality } from "@cowprotocol/sdk-order-book";
595
601
 
596
602
  // src/suggestSlippageBps.ts
597
603
  import { percentageToBps } from "@cowprotocol/sdk-common";
598
- import { getQuoteAmountsWithCosts } from "@cowprotocol/sdk-order-book";
604
+ import { getQuoteAmountsAndCosts as getQuoteAmountsAndCosts2, OrderKind } from "@cowprotocol/sdk-order-book";
599
605
 
600
606
  // src/suggestSlippageFromFee.ts
601
607
  import { applyPercentage } from "@cowprotocol/sdk-common";
@@ -629,18 +635,16 @@ var MAX_SLIPPAGE_BPS = 1e4;
629
635
  var SLIPPAGE_FEE_MULTIPLIER_PERCENT = 50;
630
636
  var SLIPPAGE_VOLUME_MULTIPLIER_PERCENT = 0.5;
631
637
  function suggestSlippageBps(params) {
638
+ const { quote, trader, isEthFlow, volumeMultiplierPercent = SLIPPAGE_VOLUME_MULTIPLIER_PERCENT } = params;
639
+ const isSell = quote.quote.kind === OrderKind.SELL;
632
640
  const {
633
- quote,
634
- tradeParameters,
635
- trader,
636
- isEthFlow,
637
- volumeMultiplierPercent = SLIPPAGE_VOLUME_MULTIPLIER_PERCENT
638
- } = params;
639
- const { sellTokenDecimals, buyTokenDecimals } = tradeParameters;
640
- const { isSell, sellAmountBeforeNetworkCosts, sellAmountAfterNetworkCosts } = getQuoteAmountsWithCosts({
641
- sellDecimals: sellTokenDecimals,
642
- buyDecimals: buyTokenDecimals,
643
- orderParams: quote.quote
641
+ beforeNetworkCosts: { sellAmount: sellAmountBeforeNetworkCosts },
642
+ afterNetworkCosts: { sellAmount: sellAmountAfterNetworkCosts }
643
+ } = getQuoteAmountsAndCosts2({
644
+ orderParams: quote.quote,
645
+ protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : 0,
646
+ partnerFeeBps: void 0,
647
+ slippagePercentBps: 0
644
648
  });
645
649
  const { feeAmount: feeAmountString } = quote.quote;
646
650
  const feeAmount = BigInt(feeAmountString);
@@ -681,21 +685,20 @@ async function resolveSlippageSuggestion(chainId, tradeParameters, trader, quote
681
685
  if (priceQuality === PriceQuality.FAST || !getSlippageSuggestion) {
682
686
  return { slippageBps: defaultSuggestion };
683
687
  }
684
- const amountsAndCosts = getQuoteAmountsAndCosts2({
688
+ const amountsAndCosts = getQuoteAmountsAndCosts3({
685
689
  orderParams: quote.quote,
686
690
  slippagePercentBps: 0,
687
691
  partnerFeeBps: getPartnerFeeBps(tradeParameters.partnerFee),
688
- protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0,
689
- sellDecimals: tradeParameters.sellTokenDecimals,
690
- buyDecimals: tradeParameters.buyTokenDecimals
692
+ protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0
691
693
  });
694
+ const { isSell, beforeAllFees, afterSlippage } = amountsAndCosts;
692
695
  try {
693
696
  const suggestedSlippage = await getSlippageSuggestion({
694
697
  chainId,
695
698
  sellToken: tradeParameters.sellToken,
696
699
  buyToken: tradeParameters.buyToken,
697
- sellAmount: amountsAndCosts.afterSlippage.sellAmount,
698
- buyAmount: amountsAndCosts.afterSlippage.buyAmount
700
+ sellAmount: isSell ? beforeAllFees.sellAmount : afterSlippage.sellAmount,
701
+ buyAmount: isSell ? afterSlippage.buyAmount : beforeAllFees.buyAmount
699
702
  });
700
703
  const suggestedSlippageBps = suggestedSlippage.slippageBps;
701
704
  return {
@@ -830,15 +833,13 @@ async function getQuoteRaw(_tradeParameters, trader, advancedSettings, _orderBoo
830
833
  }
831
834
  async function getQuote(_tradeParameters, trader, advancedSettings, _orderBookApi) {
832
835
  const { quote, orderBookApi, tradeParameters, slippageBps, suggestedSlippageBps, appDataInfo, isEthFlow } = await getQuoteRaw(_tradeParameters, trader, advancedSettings, _orderBookApi);
833
- const { partnerFee, sellTokenDecimals, buyTokenDecimals } = tradeParameters;
836
+ const { partnerFee } = tradeParameters;
834
837
  const { chainId, account: from } = trader;
835
- const amountsAndCosts = getQuoteAmountsAndCosts3({
838
+ const amountsAndCosts = getQuoteAmountsAndCosts4({
836
839
  orderParams: quote.quote,
837
840
  slippagePercentBps: slippageBps,
838
841
  partnerFeeBps: getPartnerFeeBps(partnerFee),
839
- protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0,
840
- sellDecimals: sellTokenDecimals,
841
- buyDecimals: buyTokenDecimals
842
+ protocolFeeBps: quote.protocolFeeBps ? Number(quote.protocolFeeBps) : void 0
842
843
  });
843
844
  const orderToSign = getOrderToSign(
844
845
  {
@@ -1127,6 +1128,50 @@ var TradingSdk = class {
1127
1128
  }
1128
1129
  };
1129
1130
  }
1131
+ /**
1132
+ * Gets a quote without requiring a signer or wallet connection.
1133
+ * Useful for building UIs that preview swap quotes before the user connects a wallet.
1134
+ *
1135
+ * Unlike {@link getQuote}, this method only requires an `owner` address (the account
1136
+ * to quote for) instead of a signer. The returned result contains quote information
1137
+ * but no `postSwapOrderFromQuote` helper, since posting requires signing.
1138
+ *
1139
+ * @param params - Trade parameters with `owner` address. Signer is not needed.
1140
+ * @param advancedSettings - Optional advanced settings for the swap quote.
1141
+ * @returns Quote results including amounts, costs, slippage, and order data.
1142
+ *
1143
+ * @example
1144
+ * ```typescript
1145
+ * // Get a quote without a connected wallet
1146
+ * const sdk = new TradingSdk(
1147
+ * { chainId: 1, appCode: 'My App' },
1148
+ * { orderBookApi },
1149
+ * )
1150
+ *
1151
+ * const quoteResults = await sdk.getQuoteOnly({
1152
+ * owner: '0x1234...', // any valid address
1153
+ * kind: OrderKind.SELL,
1154
+ * sellToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1155
+ * sellTokenDecimals: 6,
1156
+ * buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1157
+ * buyTokenDecimals: 18,
1158
+ * amount: '1000000000', // 1000 USDC
1159
+ * })
1160
+ *
1161
+ * console.log(quoteResults.amountsAndCosts)
1162
+ * ```
1163
+ */
1164
+ async getQuoteOnly(params, advancedSettings) {
1165
+ const quoterParams = this.mergeQuoterParams(params);
1166
+ const trader = {
1167
+ chainId: quoterParams.chainId,
1168
+ appCode: quoterParams.appCode,
1169
+ env: quoterParams.env,
1170
+ account: quoterParams.owner
1171
+ };
1172
+ const result = await getQuote(quoterParams, trader, advancedSettings, this.options.orderBookApi);
1173
+ return result.result;
1174
+ }
1130
1175
  async getQuoteResults(params, advancedSettings) {
1131
1176
  return getQuoteWithSigner(this.mergeParams(params), advancedSettings, this.options.orderBookApi);
1132
1177
  }
@@ -1300,6 +1345,27 @@ var TradingSdk = class {
1300
1345
  ...traderParams
1301
1346
  };
1302
1347
  }
1348
+ /**
1349
+ * Merges quoter-specific parameters (chainId, appCode, env, owner) without requiring a signer.
1350
+ * Used by quote-only operations that don't need signing capability.
1351
+ */
1352
+ mergeQuoterParams(params) {
1353
+ const chainId = params.chainId || this.traderParams.chainId;
1354
+ const appCode = params.appCode || this.traderParams.appCode;
1355
+ const env = params.env || this.traderParams.env || "prod";
1356
+ if (!chainId) {
1357
+ throw new Error("Missing quoter parameters: chainId");
1358
+ }
1359
+ if (!appCode) {
1360
+ throw new Error("Missing quoter parameters: appCode");
1361
+ }
1362
+ return {
1363
+ ...params,
1364
+ chainId,
1365
+ appCode,
1366
+ env
1367
+ };
1368
+ }
1303
1369
  };
1304
1370
  function assertTraderParams(params) {
1305
1371
  if (!isTraderParameters(params)) {
@@ -1332,6 +1398,7 @@ export {
1332
1398
  getPreSignTransaction,
1333
1399
  getQuote,
1334
1400
  getQuoteWithSigner,
1401
+ getQuote as getQuoteWithoutSigner,
1335
1402
  getTradeParametersAfterQuote,
1336
1403
  mapQuoteAmountsAndCosts,
1337
1404
  mergeAppDataDoc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/sdk-trading",
3
- "version": "0.11.1",
3
+ "version": "1.0.1",
4
4
  "description": "CowProtocol trading",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -29,18 +29,18 @@
29
29
  "ts-jest": "^29.0.0",
30
30
  "tsx": "^4.19.4",
31
31
  "@cow-sdk/typescript-config": "0.0.0-beta.0",
32
- "@cowprotocol/sdk-ethers-v6-adapter": "0.3.8",
33
- "@cowprotocol/sdk-viem-adapter": "0.3.8",
34
- "@cowprotocol/sdk-ethers-v5-adapter": "0.3.8"
32
+ "@cowprotocol/sdk-ethers-v5-adapter": "0.3.9",
33
+ "@cowprotocol/sdk-ethers-v6-adapter": "0.3.9",
34
+ "@cowprotocol/sdk-viem-adapter": "0.3.9"
35
35
  },
36
36
  "dependencies": {
37
37
  "deepmerge": "^4.3.1",
38
- "@cowprotocol/sdk-common": "0.6.2",
39
- "@cowprotocol/sdk-app-data": "4.6.5",
40
- "@cowprotocol/sdk-order-book": "0.6.6",
41
- "@cowprotocol/sdk-order-signing": "0.1.33",
42
- "@cowprotocol/sdk-contracts-ts": "1.6.1",
43
- "@cowprotocol/sdk-config": "0.8.1"
38
+ "@cowprotocol/sdk-common": "0.6.3",
39
+ "@cowprotocol/sdk-config": "0.9.0",
40
+ "@cowprotocol/sdk-app-data": "4.6.6",
41
+ "@cowprotocol/sdk-order-book": "1.1.0",
42
+ "@cowprotocol/sdk-contracts-ts": "1.7.0",
43
+ "@cowprotocol/sdk-order-signing": "0.1.35"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsup src/index.ts --format esm,cjs --dts",