@cowprotocol/sdk-trading 0.1.0-monorepo.0

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.
@@ -0,0 +1,326 @@
1
+ import { latest, AppDataParams, LatestAppDataDocVersion } from '@cowprotocol/sdk-app-data';
2
+ import { OrderKind, OrderParameters, TokenAmount, SigningScheme, OrderQuoteRequest, QuoteAmountsAndCosts, OrderQuoteResponse, AppData, AppDataHash, Signature, OrderBookApi } from '@cowprotocol/sdk-order-book';
3
+ import { AccountAddress, SignerLike, AbstractSigner, Signer, AbstractProviderAdapter, EthFlowContract } from '@cowprotocol/sdk-common';
4
+ import { UnsignedOrder } from '@cowprotocol/sdk-order-signing';
5
+ import { CowEnv, SupportedChainId } from '@cowprotocol/sdk-config';
6
+
7
+ declare const ORDER_PRIMARY_TYPE: "Order";
8
+ /**
9
+ * EIP-712 typed data domain.
10
+ */
11
+ interface TypedDataDomain {
12
+ name: string;
13
+ version: string;
14
+ chainId: number;
15
+ verifyingContract: string;
16
+ }
17
+ /**
18
+ * EIP-712 typed data field.
19
+ */
20
+ interface TypedDataField {
21
+ name: string;
22
+ type: string;
23
+ }
24
+ /**
25
+ * EIP-712 typed data for an order.
26
+ */
27
+ interface OrderTypedData {
28
+ domain: TypedDataDomain;
29
+ primaryType: typeof ORDER_PRIMARY_TYPE;
30
+ types: Record<string, TypedDataField[]>;
31
+ message: UnsignedOrder;
32
+ }
33
+ /**
34
+ * Minimal set of parameters to create a trade.
35
+ */
36
+ interface TradeBaseParameters {
37
+ kind: OrderKind;
38
+ owner?: AccountAddress;
39
+ sellToken: OrderParameters['sellToken'];
40
+ sellTokenDecimals: number;
41
+ buyToken: OrderParameters['buyToken'];
42
+ buyTokenDecimals: number;
43
+ amount: TokenAmount;
44
+ }
45
+ /**
46
+ * Optional parameters to create a trade.
47
+ */
48
+ interface TradeOptionalParameters {
49
+ env?: CowEnv;
50
+ partiallyFillable?: OrderParameters['partiallyFillable'];
51
+ /**
52
+ * Slippage in basis points.
53
+ * If not provided, it will use AUTO slippage, which would suggest a slippage based on the quote.
54
+ */
55
+ slippageBps?: latest.SlippageBips;
56
+ receiver?: OrderParameters['receiver'];
57
+ validFor?: OrderParameters['validTo'];
58
+ partnerFee?: latest.PartnerFee;
59
+ }
60
+ /**
61
+ * Information about the trader.
62
+ */
63
+ interface TraderParameters {
64
+ chainId: SupportedChainId;
65
+ appCode: latest.AppCode;
66
+ signer?: SignerLike;
67
+ env?: CowEnv;
68
+ }
69
+ type QuoterParameters = Omit<TraderParameters, 'signer'> & {
70
+ account: AccountAddress;
71
+ };
72
+ /**
73
+ * Trade type, assets, amounts, and optional parameters.
74
+ */
75
+ interface TradeParameters extends TradeBaseParameters, TradeOptionalParameters {
76
+ }
77
+ interface SwapParameters extends TradeParameters, TraderParameters {
78
+ }
79
+ interface LimitTradeParameters extends Omit<TradeParameters, 'amount'> {
80
+ sellAmount: OrderParameters['sellAmount'];
81
+ buyAmount: OrderParameters['buyAmount'];
82
+ /**
83
+ * Id of the quote to be used for the limit order.
84
+ */
85
+ quoteId?: number;
86
+ validTo?: OrderParameters['validTo'];
87
+ }
88
+ interface LimitTradeParametersFromQuote extends LimitTradeParameters {
89
+ quoteId: number;
90
+ }
91
+ interface LimitOrderParameters extends TraderParameters, LimitTradeParameters {
92
+ }
93
+ interface SwapAdvancedSettings {
94
+ quoteRequest?: Partial<Omit<OrderQuoteRequest, 'kind'> & {
95
+ validTo: number;
96
+ }>;
97
+ appData?: AppDataParams;
98
+ additionalParams?: PostTradeAdditionalParams;
99
+ quoteSigner?: SignerLike;
100
+ }
101
+ interface LimitOrderAdvancedSettings {
102
+ appData?: AppDataParams;
103
+ additionalParams?: PostTradeAdditionalParams;
104
+ }
105
+ /**
106
+ * Quote information for the CoW Protocol order, including information about the trade, quote, order, "app-data", and more.
107
+ *
108
+ * This data is used to create a trade, sign an order, and post it to the order book.
109
+ */
110
+ interface QuoteResults {
111
+ /**
112
+ * Information about the trade, including the kind of order, the owner, the sell and buy tokens, and the amount.
113
+ */
114
+ tradeParameters: TradeParameters;
115
+ /**
116
+ * The suggested slippage based on the quote.
117
+ *
118
+ */
119
+ suggestedSlippageBps: number;
120
+ /**
121
+ * Details about costs and amounts, costs and fees of a quote.
122
+ */
123
+ amountsAndCosts: QuoteAmountsAndCosts;
124
+ /**
125
+ * Information about the order to be signed.
126
+ *
127
+ * For signining, please use orderTypedData (EIP-712 typed data, which also includes the unsigned order)
128
+ */
129
+ orderToSign: UnsignedOrder;
130
+ /**
131
+ * Information about the quote response from the order book API.
132
+ */
133
+ quoteResponse: OrderQuoteResponse;
134
+ /**
135
+ * Information about the app-data, including the JSON document and the keccak256 hash of the full document.
136
+ */
137
+ appDataInfo: TradingAppDataInfo;
138
+ /**
139
+ * EIP-712 typed data for the order ready to be signed.
140
+ */
141
+ orderTypedData: OrderTypedData;
142
+ }
143
+ interface QuoteResultsSerialized extends Omit<QuoteResults, 'amountsAndCosts'> {
144
+ amountsAndCosts: QuoteAmountsAndCosts<string>;
145
+ }
146
+ interface OrderPostingResult {
147
+ orderId: string;
148
+ txHash?: string;
149
+ signingScheme: SigningScheme;
150
+ signature: Signature;
151
+ orderToSign: UnsignedOrder;
152
+ }
153
+ interface QuoteAndPost {
154
+ quoteResults: QuoteResults;
155
+ postSwapOrderFromQuote(advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
156
+ }
157
+ type AppDataRootSchema = latest.AppDataRootSchema;
158
+ interface BuildAppDataParams {
159
+ appCode: latest.AppCode;
160
+ slippageBps: latest.SlippageBips;
161
+ orderClass: latest.OrderClass['orderClass'];
162
+ partnerFee?: latest.PartnerFee;
163
+ }
164
+ /**
165
+ * Information about the app-data for trading operations, including the JSON document and the keccak256 hash of the full document.
166
+ *
167
+ * See https://github.com/cowprotocol/app-data
168
+ */
169
+ interface TradingAppDataInfo {
170
+ doc: LatestAppDataDocVersion;
171
+ fullAppData: AppData;
172
+ appDataKeccak256: AppDataHash;
173
+ }
174
+ /**
175
+ * A standard Ethereum transaction object
176
+ */
177
+ interface TradingTransactionParams {
178
+ data: string;
179
+ gasLimit: string;
180
+ to: string;
181
+ value: string;
182
+ }
183
+ interface EthFlowOrderExistsCallback {
184
+ (orderId: string, orderDigest: string): Promise<boolean>;
185
+ }
186
+ /**
187
+ * Additional parameters for posting orders.
188
+ * In most of the cases you don't need to use them.
189
+ */
190
+ interface PostTradeAdditionalParams {
191
+ /**
192
+ * Selling native token orders are special, because they are created from smart-contract,
193
+ * and their validTo is always the same.
194
+ * Because of that, you might get the same orderId when trying to create an order with the same parameters
195
+ * The callback is needed to check if there is already an order with the same orderId
196
+ *
197
+ * @see https://github.com/cowprotocol/ethflowcontract/blob/main/src/libraries/EthFlowOrder.sol#L90
198
+ */
199
+ checkEthFlowOrderExists?: EthFlowOrderExistsCallback;
200
+ /**
201
+ * Cost of executing the order onchain.
202
+ * The value is used in getQuoteAmountsAndCosts in order to calculate proper amounts
203
+ */
204
+ networkCostsAmount?: string;
205
+ /**
206
+ * By default, is EIP712 for EOA wallets.
207
+ * You might need other types of signing, for example PRESIGN when sign order via Smart Contract wallets.
208
+ */
209
+ signingScheme?: SigningScheme;
210
+ }
211
+
212
+ type QuoteResultsWithSigner = {
213
+ result: QuoteResults & {
214
+ signer: AbstractSigner;
215
+ };
216
+ orderBookApi: OrderBookApi;
217
+ };
218
+ declare function getQuote(_tradeParameters: TradeParameters, trader: QuoterParameters, advancedSettings?: SwapAdvancedSettings, _orderBookApi?: OrderBookApi): Promise<{
219
+ result: QuoteResults;
220
+ orderBookApi: OrderBookApi;
221
+ }>;
222
+ declare function getQuoteWithSigner(swapParameters: SwapParameters, advancedSettings?: SwapAdvancedSettings, orderBookApi?: OrderBookApi): Promise<QuoteResultsWithSigner>;
223
+
224
+ declare function postSellNativeCurrencyOrder(orderBookApi: OrderBookApi, appData: Pick<TradingAppDataInfo, 'fullAppData' | 'appDataKeccak256'>, _params: LimitTradeParametersFromQuote, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<OrderPostingResult>;
225
+
226
+ declare function getPreSignTransaction(signer: Signer, chainId: SupportedChainId, account: string, orderId: string): Promise<TradingTransactionParams>;
227
+
228
+ type WithPartialTraderParams<T> = T & Partial<TraderParameters>;
229
+ declare let utmContent: string | undefined;
230
+ declare let disableUtm: boolean;
231
+ interface TradingSdkOptions {
232
+ enableLogging: boolean;
233
+ orderBookApi: OrderBookApi;
234
+ utmContent?: string;
235
+ disableUtm?: boolean;
236
+ }
237
+ declare class TradingSdk {
238
+ traderParams: Partial<TraderParameters>;
239
+ readonly options: Partial<TradingSdkOptions>;
240
+ constructor(traderParams?: Partial<TraderParameters>, options?: Partial<TradingSdkOptions>, adapter?: AbstractProviderAdapter);
241
+ setTraderParams(params: Partial<TraderParameters>): this;
242
+ getQuote(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteAndPost>;
243
+ getQuoteResults(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteResultsWithSigner>;
244
+ postSwapOrder(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
245
+ postLimitOrder(params: WithPartialTraderParams<LimitTradeParameters>, advancedSettings?: LimitOrderAdvancedSettings): Promise<OrderPostingResult>;
246
+ /**
247
+ * Posts a sell order for native currency (e.g., ETH) using the EthFlow contract.
248
+ * This method creates an on-chain transaction for selling native tokens.
249
+ *
250
+ * @param params - The trade parameters including token addresses and amounts
251
+ * @param advancedSettings - Optional advanced settings for the swap
252
+ * @returns Promise resolving to the order posting result with transaction hash and order ID
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const parameters: TradeParameters = {
257
+ * kind: OrderKind.SELL,
258
+ * sellToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // Native ETH
259
+ * sellTokenDecimals: 18,
260
+ * buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
261
+ * buyTokenDecimals: 18,
262
+ * amount: '100000000000000000', // 0.1 ETH
263
+ * }
264
+ *
265
+ * const { orderId, txHash } = await sdk.postSellNativeCurrencyOrder(parameters)
266
+ * ```
267
+ */
268
+ postSellNativeCurrencyOrder(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<ReturnType<typeof postSellNativeCurrencyOrder>>;
269
+ getPreSignTransaction(params: WithPartialTraderParams<{
270
+ orderId: string;
271
+ account: string;
272
+ }>): ReturnType<typeof getPreSignTransaction>;
273
+ private mergeParams;
274
+ }
275
+
276
+ declare function getEthFlowTransaction(appDataKeccak256: string, _params: LimitTradeParametersFromQuote, chainId: SupportedChainId, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<{
277
+ orderId: string;
278
+ transaction: TradingTransactionParams;
279
+ orderToSign: UnsignedOrder;
280
+ }>;
281
+ declare function getEthFlowContract(signer: Signer, env?: CowEnv): EthFlowContract;
282
+
283
+ interface OrderToSignParams {
284
+ from: string;
285
+ networkCostsAmount?: string;
286
+ }
287
+ declare function getOrderToSign({ from, networkCostsAmount }: OrderToSignParams, limitOrderParams: LimitTradeParameters, appDataKeccak256: string): UnsignedOrder;
288
+
289
+ declare function postCoWProtocolTrade(orderBookApi: OrderBookApi, paramAppData: TradingAppDataInfo, params: LimitTradeParameters, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<OrderPostingResult>;
290
+
291
+ declare function postLimitOrder(params: LimitOrderParameters, advancedSettings?: LimitOrderAdvancedSettings, _orderBookApi?: OrderBookApi): Promise<OrderPostingResult>;
292
+
293
+ declare function postSwapOrder(params: SwapParameters, advancedSettings?: SwapAdvancedSettings, orderBookApi?: OrderBookApi): Promise<OrderPostingResult>;
294
+ declare function postSwapOrderFromQuote({ orderBookApi, result: { signer, appDataInfo: _appDataInfo, quoteResponse, tradeParameters }, }: QuoteResultsWithSigner, advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
295
+
296
+ interface SuggestSlippageBps {
297
+ tradeParameters: TradeParameters;
298
+ quote: OrderQuoteResponse;
299
+ trader: QuoterParameters;
300
+ advancedSettings?: SwapAdvancedSettings;
301
+ }
302
+ /**
303
+ * Return the slippage in BPS that would allow the fee to increase by the multiplying factor percent.
304
+ */
305
+ declare function suggestSlippageBps(params: SuggestSlippageBps): number;
306
+
307
+ declare function buildAppData({ slippageBps, appCode, orderClass: orderClassName, partnerFee }: BuildAppDataParams, advancedParams?: AppDataParams): Promise<TradingAppDataInfo>;
308
+ declare function generateAppDataFromDoc(doc: AppDataRootSchema): Promise<Pick<TradingAppDataInfo, 'fullAppData' | 'appDataKeccak256'>>;
309
+ declare function mergeAppDataDoc(_doc: LatestAppDataDocVersion, appDataOverride: AppDataParams): Promise<TradingAppDataInfo>;
310
+
311
+ declare function calculateUniqueOrderId(chainId: SupportedChainId, order: UnsignedOrder, checkEthFlowOrderExists?: EthFlowOrderExistsCallback, env?: CowEnv): Promise<string>;
312
+
313
+ declare function getPartnerFeeBps(partnerFee: latest.PartnerFee | undefined): number | undefined;
314
+
315
+ declare function swapParamsToLimitOrderParams(params: TradeParameters, quoteResponse: OrderQuoteResponse): LimitTradeParametersFromQuote;
316
+ declare function mapQuoteAmountsAndCosts<T, R>(value: QuoteAmountsAndCosts<T>, mapper: (value: T) => R): QuoteAmountsAndCosts<R>;
317
+ /**
318
+ * Set sell token to the initial one
319
+ * Because for ETH-flow orders we do quote requests with wrapped token
320
+ */
321
+ declare function getTradeParametersAfterQuote({ quoteParameters, sellToken, }: {
322
+ quoteParameters: TradeParameters;
323
+ sellToken: string;
324
+ }): TradeParameters;
325
+
326
+ export { type AppDataRootSchema, type BuildAppDataParams, type EthFlowOrderExistsCallback, type LimitOrderAdvancedSettings, type LimitOrderParameters, type LimitTradeParameters, type LimitTradeParametersFromQuote, ORDER_PRIMARY_TYPE, type OrderPostingResult, type OrderTypedData, type PostTradeAdditionalParams, type QuoteAndPost, type QuoteResults, type QuoteResultsSerialized, type QuoteResultsWithSigner, type QuoterParameters, type SwapAdvancedSettings, type SwapParameters, type TradeBaseParameters, type TradeOptionalParameters, type TradeParameters, type TraderParameters, type TradingAppDataInfo, TradingSdk, type TradingSdkOptions, type TradingTransactionParams, type WithPartialTraderParams, buildAppData, calculateUniqueOrderId, disableUtm, generateAppDataFromDoc, getEthFlowContract, getEthFlowTransaction, getOrderToSign, getPartnerFeeBps, getPreSignTransaction, getQuote, getQuoteWithSigner, getTradeParametersAfterQuote, mapQuoteAmountsAndCosts, mergeAppDataDoc, postCoWProtocolTrade, postLimitOrder, postSellNativeCurrencyOrder, postSwapOrder, postSwapOrderFromQuote, suggestSlippageBps, swapParamsToLimitOrderParams, utmContent };
@@ -0,0 +1,326 @@
1
+ import { latest, AppDataParams, LatestAppDataDocVersion } from '@cowprotocol/sdk-app-data';
2
+ import { OrderKind, OrderParameters, TokenAmount, SigningScheme, OrderQuoteRequest, QuoteAmountsAndCosts, OrderQuoteResponse, AppData, AppDataHash, Signature, OrderBookApi } from '@cowprotocol/sdk-order-book';
3
+ import { AccountAddress, SignerLike, AbstractSigner, Signer, AbstractProviderAdapter, EthFlowContract } from '@cowprotocol/sdk-common';
4
+ import { UnsignedOrder } from '@cowprotocol/sdk-order-signing';
5
+ import { CowEnv, SupportedChainId } from '@cowprotocol/sdk-config';
6
+
7
+ declare const ORDER_PRIMARY_TYPE: "Order";
8
+ /**
9
+ * EIP-712 typed data domain.
10
+ */
11
+ interface TypedDataDomain {
12
+ name: string;
13
+ version: string;
14
+ chainId: number;
15
+ verifyingContract: string;
16
+ }
17
+ /**
18
+ * EIP-712 typed data field.
19
+ */
20
+ interface TypedDataField {
21
+ name: string;
22
+ type: string;
23
+ }
24
+ /**
25
+ * EIP-712 typed data for an order.
26
+ */
27
+ interface OrderTypedData {
28
+ domain: TypedDataDomain;
29
+ primaryType: typeof ORDER_PRIMARY_TYPE;
30
+ types: Record<string, TypedDataField[]>;
31
+ message: UnsignedOrder;
32
+ }
33
+ /**
34
+ * Minimal set of parameters to create a trade.
35
+ */
36
+ interface TradeBaseParameters {
37
+ kind: OrderKind;
38
+ owner?: AccountAddress;
39
+ sellToken: OrderParameters['sellToken'];
40
+ sellTokenDecimals: number;
41
+ buyToken: OrderParameters['buyToken'];
42
+ buyTokenDecimals: number;
43
+ amount: TokenAmount;
44
+ }
45
+ /**
46
+ * Optional parameters to create a trade.
47
+ */
48
+ interface TradeOptionalParameters {
49
+ env?: CowEnv;
50
+ partiallyFillable?: OrderParameters['partiallyFillable'];
51
+ /**
52
+ * Slippage in basis points.
53
+ * If not provided, it will use AUTO slippage, which would suggest a slippage based on the quote.
54
+ */
55
+ slippageBps?: latest.SlippageBips;
56
+ receiver?: OrderParameters['receiver'];
57
+ validFor?: OrderParameters['validTo'];
58
+ partnerFee?: latest.PartnerFee;
59
+ }
60
+ /**
61
+ * Information about the trader.
62
+ */
63
+ interface TraderParameters {
64
+ chainId: SupportedChainId;
65
+ appCode: latest.AppCode;
66
+ signer?: SignerLike;
67
+ env?: CowEnv;
68
+ }
69
+ type QuoterParameters = Omit<TraderParameters, 'signer'> & {
70
+ account: AccountAddress;
71
+ };
72
+ /**
73
+ * Trade type, assets, amounts, and optional parameters.
74
+ */
75
+ interface TradeParameters extends TradeBaseParameters, TradeOptionalParameters {
76
+ }
77
+ interface SwapParameters extends TradeParameters, TraderParameters {
78
+ }
79
+ interface LimitTradeParameters extends Omit<TradeParameters, 'amount'> {
80
+ sellAmount: OrderParameters['sellAmount'];
81
+ buyAmount: OrderParameters['buyAmount'];
82
+ /**
83
+ * Id of the quote to be used for the limit order.
84
+ */
85
+ quoteId?: number;
86
+ validTo?: OrderParameters['validTo'];
87
+ }
88
+ interface LimitTradeParametersFromQuote extends LimitTradeParameters {
89
+ quoteId: number;
90
+ }
91
+ interface LimitOrderParameters extends TraderParameters, LimitTradeParameters {
92
+ }
93
+ interface SwapAdvancedSettings {
94
+ quoteRequest?: Partial<Omit<OrderQuoteRequest, 'kind'> & {
95
+ validTo: number;
96
+ }>;
97
+ appData?: AppDataParams;
98
+ additionalParams?: PostTradeAdditionalParams;
99
+ quoteSigner?: SignerLike;
100
+ }
101
+ interface LimitOrderAdvancedSettings {
102
+ appData?: AppDataParams;
103
+ additionalParams?: PostTradeAdditionalParams;
104
+ }
105
+ /**
106
+ * Quote information for the CoW Protocol order, including information about the trade, quote, order, "app-data", and more.
107
+ *
108
+ * This data is used to create a trade, sign an order, and post it to the order book.
109
+ */
110
+ interface QuoteResults {
111
+ /**
112
+ * Information about the trade, including the kind of order, the owner, the sell and buy tokens, and the amount.
113
+ */
114
+ tradeParameters: TradeParameters;
115
+ /**
116
+ * The suggested slippage based on the quote.
117
+ *
118
+ */
119
+ suggestedSlippageBps: number;
120
+ /**
121
+ * Details about costs and amounts, costs and fees of a quote.
122
+ */
123
+ amountsAndCosts: QuoteAmountsAndCosts;
124
+ /**
125
+ * Information about the order to be signed.
126
+ *
127
+ * For signining, please use orderTypedData (EIP-712 typed data, which also includes the unsigned order)
128
+ */
129
+ orderToSign: UnsignedOrder;
130
+ /**
131
+ * Information about the quote response from the order book API.
132
+ */
133
+ quoteResponse: OrderQuoteResponse;
134
+ /**
135
+ * Information about the app-data, including the JSON document and the keccak256 hash of the full document.
136
+ */
137
+ appDataInfo: TradingAppDataInfo;
138
+ /**
139
+ * EIP-712 typed data for the order ready to be signed.
140
+ */
141
+ orderTypedData: OrderTypedData;
142
+ }
143
+ interface QuoteResultsSerialized extends Omit<QuoteResults, 'amountsAndCosts'> {
144
+ amountsAndCosts: QuoteAmountsAndCosts<string>;
145
+ }
146
+ interface OrderPostingResult {
147
+ orderId: string;
148
+ txHash?: string;
149
+ signingScheme: SigningScheme;
150
+ signature: Signature;
151
+ orderToSign: UnsignedOrder;
152
+ }
153
+ interface QuoteAndPost {
154
+ quoteResults: QuoteResults;
155
+ postSwapOrderFromQuote(advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
156
+ }
157
+ type AppDataRootSchema = latest.AppDataRootSchema;
158
+ interface BuildAppDataParams {
159
+ appCode: latest.AppCode;
160
+ slippageBps: latest.SlippageBips;
161
+ orderClass: latest.OrderClass['orderClass'];
162
+ partnerFee?: latest.PartnerFee;
163
+ }
164
+ /**
165
+ * Information about the app-data for trading operations, including the JSON document and the keccak256 hash of the full document.
166
+ *
167
+ * See https://github.com/cowprotocol/app-data
168
+ */
169
+ interface TradingAppDataInfo {
170
+ doc: LatestAppDataDocVersion;
171
+ fullAppData: AppData;
172
+ appDataKeccak256: AppDataHash;
173
+ }
174
+ /**
175
+ * A standard Ethereum transaction object
176
+ */
177
+ interface TradingTransactionParams {
178
+ data: string;
179
+ gasLimit: string;
180
+ to: string;
181
+ value: string;
182
+ }
183
+ interface EthFlowOrderExistsCallback {
184
+ (orderId: string, orderDigest: string): Promise<boolean>;
185
+ }
186
+ /**
187
+ * Additional parameters for posting orders.
188
+ * In most of the cases you don't need to use them.
189
+ */
190
+ interface PostTradeAdditionalParams {
191
+ /**
192
+ * Selling native token orders are special, because they are created from smart-contract,
193
+ * and their validTo is always the same.
194
+ * Because of that, you might get the same orderId when trying to create an order with the same parameters
195
+ * The callback is needed to check if there is already an order with the same orderId
196
+ *
197
+ * @see https://github.com/cowprotocol/ethflowcontract/blob/main/src/libraries/EthFlowOrder.sol#L90
198
+ */
199
+ checkEthFlowOrderExists?: EthFlowOrderExistsCallback;
200
+ /**
201
+ * Cost of executing the order onchain.
202
+ * The value is used in getQuoteAmountsAndCosts in order to calculate proper amounts
203
+ */
204
+ networkCostsAmount?: string;
205
+ /**
206
+ * By default, is EIP712 for EOA wallets.
207
+ * You might need other types of signing, for example PRESIGN when sign order via Smart Contract wallets.
208
+ */
209
+ signingScheme?: SigningScheme;
210
+ }
211
+
212
+ type QuoteResultsWithSigner = {
213
+ result: QuoteResults & {
214
+ signer: AbstractSigner;
215
+ };
216
+ orderBookApi: OrderBookApi;
217
+ };
218
+ declare function getQuote(_tradeParameters: TradeParameters, trader: QuoterParameters, advancedSettings?: SwapAdvancedSettings, _orderBookApi?: OrderBookApi): Promise<{
219
+ result: QuoteResults;
220
+ orderBookApi: OrderBookApi;
221
+ }>;
222
+ declare function getQuoteWithSigner(swapParameters: SwapParameters, advancedSettings?: SwapAdvancedSettings, orderBookApi?: OrderBookApi): Promise<QuoteResultsWithSigner>;
223
+
224
+ declare function postSellNativeCurrencyOrder(orderBookApi: OrderBookApi, appData: Pick<TradingAppDataInfo, 'fullAppData' | 'appDataKeccak256'>, _params: LimitTradeParametersFromQuote, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<OrderPostingResult>;
225
+
226
+ declare function getPreSignTransaction(signer: Signer, chainId: SupportedChainId, account: string, orderId: string): Promise<TradingTransactionParams>;
227
+
228
+ type WithPartialTraderParams<T> = T & Partial<TraderParameters>;
229
+ declare let utmContent: string | undefined;
230
+ declare let disableUtm: boolean;
231
+ interface TradingSdkOptions {
232
+ enableLogging: boolean;
233
+ orderBookApi: OrderBookApi;
234
+ utmContent?: string;
235
+ disableUtm?: boolean;
236
+ }
237
+ declare class TradingSdk {
238
+ traderParams: Partial<TraderParameters>;
239
+ readonly options: Partial<TradingSdkOptions>;
240
+ constructor(traderParams?: Partial<TraderParameters>, options?: Partial<TradingSdkOptions>, adapter?: AbstractProviderAdapter);
241
+ setTraderParams(params: Partial<TraderParameters>): this;
242
+ getQuote(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteAndPost>;
243
+ getQuoteResults(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<QuoteResultsWithSigner>;
244
+ postSwapOrder(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
245
+ postLimitOrder(params: WithPartialTraderParams<LimitTradeParameters>, advancedSettings?: LimitOrderAdvancedSettings): Promise<OrderPostingResult>;
246
+ /**
247
+ * Posts a sell order for native currency (e.g., ETH) using the EthFlow contract.
248
+ * This method creates an on-chain transaction for selling native tokens.
249
+ *
250
+ * @param params - The trade parameters including token addresses and amounts
251
+ * @param advancedSettings - Optional advanced settings for the swap
252
+ * @returns Promise resolving to the order posting result with transaction hash and order ID
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * const parameters: TradeParameters = {
257
+ * kind: OrderKind.SELL,
258
+ * sellToken: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // Native ETH
259
+ * sellTokenDecimals: 18,
260
+ * buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
261
+ * buyTokenDecimals: 18,
262
+ * amount: '100000000000000000', // 0.1 ETH
263
+ * }
264
+ *
265
+ * const { orderId, txHash } = await sdk.postSellNativeCurrencyOrder(parameters)
266
+ * ```
267
+ */
268
+ postSellNativeCurrencyOrder(params: WithPartialTraderParams<TradeParameters>, advancedSettings?: SwapAdvancedSettings): Promise<ReturnType<typeof postSellNativeCurrencyOrder>>;
269
+ getPreSignTransaction(params: WithPartialTraderParams<{
270
+ orderId: string;
271
+ account: string;
272
+ }>): ReturnType<typeof getPreSignTransaction>;
273
+ private mergeParams;
274
+ }
275
+
276
+ declare function getEthFlowTransaction(appDataKeccak256: string, _params: LimitTradeParametersFromQuote, chainId: SupportedChainId, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<{
277
+ orderId: string;
278
+ transaction: TradingTransactionParams;
279
+ orderToSign: UnsignedOrder;
280
+ }>;
281
+ declare function getEthFlowContract(signer: Signer, env?: CowEnv): EthFlowContract;
282
+
283
+ interface OrderToSignParams {
284
+ from: string;
285
+ networkCostsAmount?: string;
286
+ }
287
+ declare function getOrderToSign({ from, networkCostsAmount }: OrderToSignParams, limitOrderParams: LimitTradeParameters, appDataKeccak256: string): UnsignedOrder;
288
+
289
+ declare function postCoWProtocolTrade(orderBookApi: OrderBookApi, paramAppData: TradingAppDataInfo, params: LimitTradeParameters, additionalParams?: PostTradeAdditionalParams, paramSigner?: SignerLike): Promise<OrderPostingResult>;
290
+
291
+ declare function postLimitOrder(params: LimitOrderParameters, advancedSettings?: LimitOrderAdvancedSettings, _orderBookApi?: OrderBookApi): Promise<OrderPostingResult>;
292
+
293
+ declare function postSwapOrder(params: SwapParameters, advancedSettings?: SwapAdvancedSettings, orderBookApi?: OrderBookApi): Promise<OrderPostingResult>;
294
+ declare function postSwapOrderFromQuote({ orderBookApi, result: { signer, appDataInfo: _appDataInfo, quoteResponse, tradeParameters }, }: QuoteResultsWithSigner, advancedSettings?: SwapAdvancedSettings): Promise<OrderPostingResult>;
295
+
296
+ interface SuggestSlippageBps {
297
+ tradeParameters: TradeParameters;
298
+ quote: OrderQuoteResponse;
299
+ trader: QuoterParameters;
300
+ advancedSettings?: SwapAdvancedSettings;
301
+ }
302
+ /**
303
+ * Return the slippage in BPS that would allow the fee to increase by the multiplying factor percent.
304
+ */
305
+ declare function suggestSlippageBps(params: SuggestSlippageBps): number;
306
+
307
+ declare function buildAppData({ slippageBps, appCode, orderClass: orderClassName, partnerFee }: BuildAppDataParams, advancedParams?: AppDataParams): Promise<TradingAppDataInfo>;
308
+ declare function generateAppDataFromDoc(doc: AppDataRootSchema): Promise<Pick<TradingAppDataInfo, 'fullAppData' | 'appDataKeccak256'>>;
309
+ declare function mergeAppDataDoc(_doc: LatestAppDataDocVersion, appDataOverride: AppDataParams): Promise<TradingAppDataInfo>;
310
+
311
+ declare function calculateUniqueOrderId(chainId: SupportedChainId, order: UnsignedOrder, checkEthFlowOrderExists?: EthFlowOrderExistsCallback, env?: CowEnv): Promise<string>;
312
+
313
+ declare function getPartnerFeeBps(partnerFee: latest.PartnerFee | undefined): number | undefined;
314
+
315
+ declare function swapParamsToLimitOrderParams(params: TradeParameters, quoteResponse: OrderQuoteResponse): LimitTradeParametersFromQuote;
316
+ declare function mapQuoteAmountsAndCosts<T, R>(value: QuoteAmountsAndCosts<T>, mapper: (value: T) => R): QuoteAmountsAndCosts<R>;
317
+ /**
318
+ * Set sell token to the initial one
319
+ * Because for ETH-flow orders we do quote requests with wrapped token
320
+ */
321
+ declare function getTradeParametersAfterQuote({ quoteParameters, sellToken, }: {
322
+ quoteParameters: TradeParameters;
323
+ sellToken: string;
324
+ }): TradeParameters;
325
+
326
+ export { type AppDataRootSchema, type BuildAppDataParams, type EthFlowOrderExistsCallback, type LimitOrderAdvancedSettings, type LimitOrderParameters, type LimitTradeParameters, type LimitTradeParametersFromQuote, ORDER_PRIMARY_TYPE, type OrderPostingResult, type OrderTypedData, type PostTradeAdditionalParams, type QuoteAndPost, type QuoteResults, type QuoteResultsSerialized, type QuoteResultsWithSigner, type QuoterParameters, type SwapAdvancedSettings, type SwapParameters, type TradeBaseParameters, type TradeOptionalParameters, type TradeParameters, type TraderParameters, type TradingAppDataInfo, TradingSdk, type TradingSdkOptions, type TradingTransactionParams, type WithPartialTraderParams, buildAppData, calculateUniqueOrderId, disableUtm, generateAppDataFromDoc, getEthFlowContract, getEthFlowTransaction, getOrderToSign, getPartnerFeeBps, getPreSignTransaction, getQuote, getQuoteWithSigner, getTradeParametersAfterQuote, mapQuoteAmountsAndCosts, mergeAppDataDoc, postCoWProtocolTrade, postLimitOrder, postSellNativeCurrencyOrder, postSwapOrder, postSwapOrderFromQuote, suggestSlippageBps, swapParamsToLimitOrderParams, utmContent };