@cowprotocol/cow-sdk 2.3.0 → 2.4.0-rc.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.
- package/dist/common/chains.d.ts +4 -0
- package/dist/common/configs.d.ts +48 -0
- package/dist/common/consts.d.ts +17 -0
- package/dist/composable/conditionalorder.d.ts +160 -0
- package/dist/composable/extensible.d.ts +6 -0
- package/dist/composable/generated/ComposableCoW.d.ts +340 -0
- package/dist/composable/generated/ExtensibleFallbackHandler.d.ts +282 -0
- package/dist/composable/generated/TWAP.d.ts +141 -0
- package/dist/composable/generated/common.d.ts +21 -0
- package/dist/composable/generated/factories/ComposableCoW__factory.d.ts +475 -0
- package/dist/composable/generated/factories/ExtensibleFallbackHandler__factory.d.ts +389 -0
- package/dist/composable/generated/factories/TWAP__factory.d.ts +260 -0
- package/dist/composable/generated/factories/index.d.ts +3 -0
- package/dist/composable/generated/index.d.ts +7 -0
- package/dist/composable/index.d.ts +4 -0
- package/dist/composable/multiplexer.d.ts +221 -0
- package/dist/composable/types/index.d.ts +1 -0
- package/dist/composable/types/twap.d.ts +114 -0
- package/dist/index-856e1ad2.js +29 -0
- package/dist/index-856e1ad2.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.module.js +4 -4
- package/dist/index.module.js.map +1 -1
- package/dist/order-book/api.d.ts +202 -8
- package/dist/order-book/generated/index.d.ts +3 -1
- package/dist/order-book/generated/models/OrderQuoteSide.d.ts +5 -8
- package/dist/order-book/generated/models/OrderQuoteSideKindBuy.d.ts +3 -0
- package/dist/order-book/generated/models/OrderQuoteSideKindSell.d.ts +3 -0
- package/dist/order-book/request.d.ts +33 -0
- package/dist/order-book/transformOrder.d.ts +7 -1
- package/dist/order-book/types.d.ts +3 -0
- package/dist/order-signing/orderSigningUtils.d.ts +79 -2
- package/dist/order-signing/types.d.ts +28 -1
- package/dist/order-signing/utils.d.ts +17 -5
- package/dist/package.json +15 -6
- package/dist/subgraph/api.d.ts +54 -0
- package/dist/subgraph/queries.d.ts +11 -0
- package/dist/utils-16a884bc.js +2 -0
- package/dist/utils-16a884bc.js.map +1 -0
- package/dist/utils-3ea4a36c.js +2 -0
- package/dist/utils-3ea4a36c.js.map +1 -0
- package/dist/utils-6743154b.js +2 -0
- package/dist/utils-6743154b.js.map +1 -0
- package/package.json +15 -6
- package/dist/index-5345e65e.js +0 -29
- package/dist/index-5345e65e.js.map +0 -1
- package/dist/order-book/transformError.d.ts +0 -6
- package/dist/utils-3ba6bb0d.js +0 -2
- package/dist/utils-3ba6bb0d.js.map +0 -1
- package/dist/utils-73bb1896.js +0 -2
- package/dist/utils-73bb1896.js.map +0 -1
- package/dist/utils-d0998201.js +0 -2
- package/dist/utils-d0998201.js.map +0 -1
package/dist/order-book/api.d.ts
CHANGED
|
@@ -2,36 +2,230 @@ import 'cross-fetch/polyfill';
|
|
|
2
2
|
import { Address, AppDataDocument, AppDataHash, NativePriceResponse, OrderCancellations, OrderCreation, OrderQuoteRequest, OrderQuoteResponse, SolverCompetitionResponse, TotalSurplus, Trade, TransactionHash, UID } from './generated';
|
|
3
3
|
import { ApiContext, ApiBaseUrls, PartialApiContext, RequestOptions } from '../common/configs';
|
|
4
4
|
import { EnrichedOrder } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* An object containing *production* environment base URLs for each supported `chainId`.
|
|
7
|
+
* @see {@link https://api.cow.fi/docs/#/}
|
|
8
|
+
*/
|
|
5
9
|
export declare const ORDER_BOOK_PROD_CONFIG: ApiBaseUrls;
|
|
10
|
+
/**
|
|
11
|
+
* An object containing *staging* environment base URLs for each supported `chainId`.
|
|
12
|
+
*/
|
|
6
13
|
export declare const ORDER_BOOK_STAGING_CONFIG: ApiBaseUrls;
|
|
14
|
+
/**
|
|
15
|
+
* The parameters for the `getOrders` request.
|
|
16
|
+
*/
|
|
17
|
+
export type GetOrdersRequest = {
|
|
18
|
+
owner: Address;
|
|
19
|
+
offset?: number;
|
|
20
|
+
limit?: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The CoW Protocol OrderBook API client.
|
|
24
|
+
*
|
|
25
|
+
* This is the main entry point for interacting with the CoW Protocol OrderBook API. The main advantage of using
|
|
26
|
+
* this client is the batteries-included approach to interacting with the API. It handles:
|
|
27
|
+
*
|
|
28
|
+
* - Environment configuration (mainnet, staging, etc.)
|
|
29
|
+
* - Rate limiting
|
|
30
|
+
* - Retries
|
|
31
|
+
* - Backoff
|
|
32
|
+
* - Error handling
|
|
33
|
+
* - Request signing
|
|
34
|
+
* - Request validation
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
*
|
|
38
|
+
* ```typescript
|
|
39
|
+
* import { OrderBookApi, OrderSigningUtils, SupportedChainId } from '@cowprotocol/cow-sdk'
|
|
40
|
+
* import { Web3Provider } from '@ethersproject/providers'
|
|
41
|
+
*
|
|
42
|
+
* const account = 'YOUR_WALLET_ADDRESS'
|
|
43
|
+
* const chainId = 5 // Goerli
|
|
44
|
+
* const provider = new Web3Provider(window.ethereum)
|
|
45
|
+
* const signer = provider.getSigner()
|
|
46
|
+
*
|
|
47
|
+
* const quoteRequest = {
|
|
48
|
+
* sellToken: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', // WETH goerli
|
|
49
|
+
* buyToken: '0x02abbdbaaa7b1bb64b5c878f7ac17f8dda169532', // GNO goerli
|
|
50
|
+
* from: account,
|
|
51
|
+
* receiver: account,
|
|
52
|
+
* sellAmountBeforeFee: (0.4 * 10 ** 18).toString(), // 0.4 WETH
|
|
53
|
+
* kind: OrderQuoteSide.kind.SELL,
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* const orderBookApi = new OrderBookApi({ chainId: SupportedChainId.GOERLI })
|
|
57
|
+
*
|
|
58
|
+
* async function main() {
|
|
59
|
+
* const { quote } = await orderBookApi.getQuote(quoteRequest)
|
|
60
|
+
*
|
|
61
|
+
* const orderSigningResult = await OrderSigningUtils.signOrder(quote, chainId, signer)
|
|
62
|
+
*
|
|
63
|
+
* const orderId = await orderBookApi.sendOrder({ ...quote, ...orderSigningResult })
|
|
64
|
+
*
|
|
65
|
+
* const order = await orderBookApi.getOrder(orderId)
|
|
66
|
+
*
|
|
67
|
+
* const trades = await orderBookApi.getTrades({ orderId })
|
|
68
|
+
*
|
|
69
|
+
* const orderCancellationSigningResult = await OrderSigningUtils.signOrderCancellations([orderId], chainId, signer)
|
|
70
|
+
*
|
|
71
|
+
* const cancellationResult = await orderBookApi.sendSignedOrderCancellations({...orderCancellationSigningResult, orderUids: [orderId] })
|
|
72
|
+
*
|
|
73
|
+
* console.log('Results: ', { orderId, order, trades, orderCancellationSigningResult, cancellationResult })
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @see {@link Swagger documentation https://api.cow.fi/docs/#/}
|
|
78
|
+
* @see {@link OrderBook API https://github.com/cowprotocol/services}
|
|
79
|
+
*/
|
|
7
80
|
export declare class OrderBookApi {
|
|
8
81
|
context: ApiContext & RequestOptions;
|
|
9
82
|
private rateLimiter;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new instance of the CoW Protocol OrderBook API client.
|
|
85
|
+
* @param context - The API context to use. If not provided, the default context will be used.
|
|
86
|
+
*/
|
|
10
87
|
constructor(context?: PartialApiContext & RequestOptions);
|
|
88
|
+
/**
|
|
89
|
+
* Get the version of the API.
|
|
90
|
+
* @param contextOverride Optional context override for this request.
|
|
91
|
+
* @returns The version of the API.
|
|
92
|
+
* @see {@link https://api.cow.fi/docs/#/default/get_api_v1_version}
|
|
93
|
+
*/
|
|
11
94
|
getVersion(contextOverride?: PartialApiContext): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Get all the trades for either an `owner` **OR** `orderUid`.
|
|
97
|
+
*
|
|
98
|
+
* Given that an order *may* be partially fillable, it is possible that a discrete order (`orderUid`)
|
|
99
|
+
* may have *multiple* trades. Therefore, this method returns a list of trades, either for *all* the orders
|
|
100
|
+
* of a given `owner`, or for a discrete order (`orderUid`).
|
|
101
|
+
* @param request Either an `owner` or an `orderUid` **MUST** be specified.
|
|
102
|
+
* @param contextOverride Optional context override for this request.
|
|
103
|
+
* @returns A list of trades matching the request.
|
|
104
|
+
*/
|
|
12
105
|
getTrades(request: {
|
|
13
106
|
owner?: Address;
|
|
14
107
|
orderUid?: UID;
|
|
15
108
|
}, contextOverride?: PartialApiContext): Promise<Array<Trade>>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Get a list of orders for a given `owner`.
|
|
111
|
+
* @param request The request parameters with `request.offset = 0` and `request.limit = 1000` by default.
|
|
112
|
+
* @param contextOverride Optional context override for this request.
|
|
113
|
+
* @returns A list of orders matching the request.
|
|
114
|
+
* @see {@link GetOrdersRequest}
|
|
115
|
+
* @see {@link EnrichedOrder}
|
|
116
|
+
*/
|
|
117
|
+
getOrders({ owner, offset, limit }: GetOrdersRequest, contextOverride?: PartialApiContext): Promise<Array<EnrichedOrder>>;
|
|
118
|
+
/**
|
|
119
|
+
* Get a list of orders from a given settlement transaction hash.
|
|
120
|
+
* @param txHash The transaction hash.
|
|
121
|
+
* @param contextOverride Optional context override for this request.
|
|
122
|
+
* @returns A list of orders matching the request.
|
|
123
|
+
* @see {@link EnrichedOrder}
|
|
124
|
+
*/
|
|
21
125
|
getTxOrders(txHash: TransactionHash, contextOverride?: PartialApiContext): Promise<Array<EnrichedOrder>>;
|
|
22
|
-
|
|
23
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Get an order by its unique identifier, `orderUid`.
|
|
128
|
+
* @param orderUid The unique identifier of the order.
|
|
129
|
+
* @param contextOverride Optional context override for this request.
|
|
130
|
+
* @returns The order matching the request.
|
|
131
|
+
*/
|
|
132
|
+
getOrder(orderUid: UID, contextOverride?: PartialApiContext): Promise<EnrichedOrder>;
|
|
133
|
+
/**
|
|
134
|
+
* Attempt to get an order by its unique identifier, `orderUid`, from multiple environments.
|
|
135
|
+
*
|
|
136
|
+
* **NOTE**: The environment refers to either `prod` or `staging`. This allows a conveience method to
|
|
137
|
+
* attempt to get an order from both environments, in the event that the order is not found in the
|
|
138
|
+
* environment specified in the context.
|
|
139
|
+
* @param orderUid The unique identifier of the order.
|
|
140
|
+
* @param contextOverride Optional context override for this request.
|
|
141
|
+
* @returns The order matching the request.
|
|
142
|
+
* @throws {OrderBookApiError} If the order is not found in any of the environments.
|
|
143
|
+
*/
|
|
144
|
+
getOrderMultiEnv(orderUid: UID, contextOverride?: PartialApiContext): Promise<EnrichedOrder>;
|
|
145
|
+
/**
|
|
146
|
+
* Get a quote for an order.
|
|
147
|
+
* This allows for the calculation of the total cost of an order, including fees, before signing and submitting.
|
|
148
|
+
* @param requestBody The parameters for the order quote request.
|
|
149
|
+
* @param contextOverride Optional context override for this request.
|
|
150
|
+
* @returns A hydrated order matching the request ready to be signed.
|
|
151
|
+
*/
|
|
24
152
|
getQuote(requestBody: OrderQuoteRequest, contextOverride?: PartialApiContext): Promise<OrderQuoteResponse>;
|
|
153
|
+
/**
|
|
154
|
+
* Cancel one or more orders.
|
|
155
|
+
*
|
|
156
|
+
* **NOTE**: Cancellation is on a best-effort basis. Orders that are already in the process of being settled
|
|
157
|
+
* (ie. transaction has been submitted to chain by the solver) cannot not be cancelled.
|
|
158
|
+
* **CAUTION**: This method can only be used to cancel orders that were signed using `EIP-712` or `eth_sign (EIP-191)`.
|
|
159
|
+
* @param requestBody Orders to be cancelled and signed instructions to cancel them.
|
|
160
|
+
* @param contextOverride Optional context override for this request.
|
|
161
|
+
* @returns A list of order unique identifiers that were successfully cancelled.
|
|
162
|
+
*/
|
|
25
163
|
sendSignedOrderCancellations(requestBody: OrderCancellations, contextOverride?: PartialApiContext): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Submit an order to the order book.
|
|
166
|
+
* @param requestBody The signed order to be submitted.
|
|
167
|
+
* @param contextOverride Optional context override for this request.
|
|
168
|
+
* @returns The unique identifier of the order.
|
|
169
|
+
*/
|
|
26
170
|
sendOrder(requestBody: OrderCreation, contextOverride?: PartialApiContext): Promise<UID>;
|
|
171
|
+
/**
|
|
172
|
+
* Get the native price of a token.
|
|
173
|
+
*
|
|
174
|
+
* **NOTE**: The native price is the price of the token in the native currency of the chain. For example, on Ethereum
|
|
175
|
+
* this would be the price of the token in ETH.
|
|
176
|
+
* @param tokenAddress The address of the ERC-20 token.
|
|
177
|
+
* @param contextOverride Optional context override for this request.
|
|
178
|
+
* @returns The native price of the token.
|
|
179
|
+
*/
|
|
27
180
|
getNativePrice(tokenAddress: Address, contextOverride?: PartialApiContext): Promise<NativePriceResponse>;
|
|
181
|
+
/**
|
|
182
|
+
* Given a user's address, get the total surplus that they have earned.
|
|
183
|
+
* @param address The user's address
|
|
184
|
+
* @param contextOverride Optional context override for this request.
|
|
185
|
+
* @returns Calculated user's surplus
|
|
186
|
+
*/
|
|
28
187
|
getTotalSurplus(address: Address, contextOverride?: PartialApiContext): Promise<TotalSurplus>;
|
|
188
|
+
/**
|
|
189
|
+
* Retrieve the full app data for a given app data hash.
|
|
190
|
+
* @param appDataHash `bytes32` hash of the app data
|
|
191
|
+
* @param contextOverride Optional context override for this request.
|
|
192
|
+
* @returns Full app data that was uploaded
|
|
193
|
+
*/
|
|
29
194
|
getAppData(appDataHash: AppDataHash, contextOverride?: PartialApiContext): Promise<AppDataDocument>;
|
|
195
|
+
/**
|
|
196
|
+
* Upload the full app data that corresponds to a given app data hash.
|
|
197
|
+
* @param appDataHash `bytes32` hash of the app data
|
|
198
|
+
* @param fullAppData Full app data to be uploaded
|
|
199
|
+
* @param contextOverride Optional context override for this request.
|
|
200
|
+
* @returns The string encoding of the full app data that was uploaded.
|
|
201
|
+
*/
|
|
30
202
|
uploadAppData(appDataHash: AppDataHash, fullAppData: string, contextOverride?: PartialApiContext): Promise<AppDataDocument>;
|
|
31
203
|
getSolverCompetition(auctionId: number, contextOverride?: PartialApiContext): Promise<SolverCompetitionResponse>;
|
|
32
204
|
getSolverCompetition(txHash: string, contextOverride?: PartialApiContext): Promise<SolverCompetitionResponse>;
|
|
33
|
-
|
|
205
|
+
/**
|
|
206
|
+
* Generate an API endpoint for an order by its unique identifier, `orderUid`.
|
|
207
|
+
* @param orderUid The unique identifier of the order.
|
|
208
|
+
* @param contextOverride Optional context override for this request.
|
|
209
|
+
* @returns The API endpoint to get the order.
|
|
210
|
+
*/
|
|
211
|
+
getOrderLink(orderUid: UID, contextOverride?: PartialApiContext): string;
|
|
212
|
+
/**
|
|
213
|
+
* Apply an override to the context for a request.
|
|
214
|
+
* @param contextOverride Optional context override for this request.
|
|
215
|
+
* @returns New context with the override applied.
|
|
216
|
+
*/
|
|
34
217
|
private getContextWithOverride;
|
|
218
|
+
/**
|
|
219
|
+
* Get the base URLs for the API endpoints given the environment.
|
|
220
|
+
* @param env The environment to get the base URLs for.
|
|
221
|
+
* @returns The base URLs for the API endpoints.
|
|
222
|
+
*/
|
|
35
223
|
private getApiBaseUrls;
|
|
224
|
+
/**
|
|
225
|
+
* Make a request to the API.
|
|
226
|
+
* @param params The parameters for the request.
|
|
227
|
+
* @param contextOverride Optional context override for this request.
|
|
228
|
+
* @returns The response from the API.
|
|
229
|
+
*/
|
|
36
230
|
private fetch;
|
|
37
231
|
}
|
|
@@ -25,7 +25,9 @@ export type { OrderParameters } from './models/OrderParameters';
|
|
|
25
25
|
export { OrderPostError } from './models/OrderPostError';
|
|
26
26
|
export type { OrderQuoteRequest } from './models/OrderQuoteRequest';
|
|
27
27
|
export type { OrderQuoteResponse } from './models/OrderQuoteResponse';
|
|
28
|
-
export { OrderQuoteSide } from './models/OrderQuoteSide';
|
|
28
|
+
export type { OrderQuoteSide } from './models/OrderQuoteSide';
|
|
29
|
+
export { OrderQuoteSideKindBuy } from './models/OrderQuoteSideKindBuy';
|
|
30
|
+
export { OrderQuoteSideKindSell } from './models/OrderQuoteSideKindSell';
|
|
29
31
|
export type { OrderQuoteValidity } from './models/OrderQuoteValidity';
|
|
30
32
|
export { OrderStatus } from './models/OrderStatus';
|
|
31
33
|
export type { PreSignature } from './models/PreSignature';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type { OrderQuoteSideKindBuy } from './OrderQuoteSideKindBuy';
|
|
2
|
+
import type { OrderQuoteSideKindSell } from './OrderQuoteSideKindSell';
|
|
1
3
|
import type { TokenAmount } from './TokenAmount';
|
|
2
4
|
/**
|
|
3
5
|
* The buy or sell side when quoting an order.
|
|
4
6
|
*/
|
|
5
7
|
export type OrderQuoteSide = ({
|
|
6
|
-
kind:
|
|
8
|
+
kind: OrderQuoteSideKindSell;
|
|
7
9
|
/**
|
|
8
10
|
* The total amount that is available for the order. From this value, the fee
|
|
9
11
|
* is deducted and the buy amount is calculated.
|
|
@@ -11,20 +13,15 @@ export type OrderQuoteSide = ({
|
|
|
11
13
|
*/
|
|
12
14
|
sellAmountBeforeFee: TokenAmount;
|
|
13
15
|
} | {
|
|
14
|
-
kind:
|
|
16
|
+
kind: OrderQuoteSideKindSell;
|
|
15
17
|
/**
|
|
16
18
|
* The `sellAmount` for the order.
|
|
17
19
|
*/
|
|
18
20
|
sellAmountAfterFee: TokenAmount;
|
|
19
21
|
} | {
|
|
20
|
-
kind:
|
|
22
|
+
kind: OrderQuoteSideKindBuy;
|
|
21
23
|
/**
|
|
22
24
|
* The `buyAmount` for the order.
|
|
23
25
|
*/
|
|
24
26
|
buyAmountAfterFee: TokenAmount;
|
|
25
27
|
});
|
|
26
|
-
export declare namespace OrderQuoteSide {
|
|
27
|
-
enum kind {
|
|
28
|
-
SELL = "sell"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,16 +1,49 @@
|
|
|
1
1
|
import { BackoffOptions } from 'exponential-backoff';
|
|
2
2
|
import { RateLimiter, RateLimiterOpts } from 'limiter';
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when the CoW Protocol OrderBook API returns an error.
|
|
5
|
+
*/
|
|
3
6
|
export declare class OrderBookApiError<T = unknown> extends Error {
|
|
4
7
|
readonly response: Response;
|
|
5
8
|
readonly body: T;
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when the CoW Protocol OrderBook API returns an error.
|
|
11
|
+
* @param response The response from the CoW Protocol OrderBook API.
|
|
12
|
+
* @param body The body of the response.
|
|
13
|
+
* @constructor
|
|
14
|
+
*/
|
|
6
15
|
constructor(response: Response, body: T);
|
|
7
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The default backoff options for CoW Protocol's API
|
|
19
|
+
* @see {@link Backoff configuration: https://www.npmjs.com/package/@insertish/exponential-backoff}
|
|
20
|
+
*/
|
|
8
21
|
export declare const DEFAULT_BACKOFF_OPTIONS: BackoffOptions;
|
|
22
|
+
/**
|
|
23
|
+
* The default rate limiter options for CoW Protocol's API.
|
|
24
|
+
*
|
|
25
|
+
* **CAUTION**: The CoW Protocol OrderBook API is limited to 5 requests per second per IP.
|
|
26
|
+
*/
|
|
9
27
|
export declare const DEFAULT_LIMITER_OPTIONS: RateLimiterOpts;
|
|
28
|
+
/**
|
|
29
|
+
* Describe the parameters for a fetch request.
|
|
30
|
+
*/
|
|
10
31
|
export interface FetchParams {
|
|
11
32
|
path: string;
|
|
12
33
|
method: 'GET' | 'POST' | 'DELETE' | 'PUT';
|
|
13
34
|
body?: unknown;
|
|
14
35
|
query?: URLSearchParams;
|
|
15
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Helper function to make a rate-limited request to an API.
|
|
39
|
+
* @param baseUrl The base URL of the API.
|
|
40
|
+
* @param path The path of the request.
|
|
41
|
+
* @param query The query parameters of the request.
|
|
42
|
+
* @param method The HTTP method of the request.
|
|
43
|
+
* @param body The body of the request.
|
|
44
|
+
* @param rateLimiter The rate limiter to use.
|
|
45
|
+
* @param backoffOpts The backoff options to use.
|
|
46
|
+
* @returns The response of the request.
|
|
47
|
+
* @throws If the API returns an error or if the request fails.
|
|
48
|
+
*/
|
|
16
49
|
export declare function request<T>(baseUrl: string, { path, query, method, body }: FetchParams, rateLimiter: RateLimiter, backoffOpts: BackoffOptions): Promise<T>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Order } from './generated';
|
|
2
2
|
import { EnrichedOrder } from './types';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Apply programmatic transformations to an order.
|
|
5
|
+
*
|
|
6
|
+
* For example, transformations may be applied to an order to recognise it as a Native EthFlow order.
|
|
7
|
+
* @param order to apply transformations to
|
|
8
|
+
* @returns An order with the total fee added.
|
|
9
|
+
*/
|
|
4
10
|
export declare function transformOrder(order: Order): EnrichedOrder;
|
|
@@ -2,9 +2,86 @@ import type { SupportedChainId } from '../common';
|
|
|
2
2
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
3
3
|
import type { TypedDataDomain } from '@cowprotocol/contracts';
|
|
4
4
|
import type { SigningResult, UnsignedOrder } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Utility class for signing order intents and cancellations.
|
|
7
|
+
*
|
|
8
|
+
* @remarks This class only supports `eth_sign` and wallet-native EIP-712 signing. For use of
|
|
9
|
+
* `presign` and `eip1271` {@link https://docs.cow.fi/ | see the docs}.
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { OrderSigningUtils, SupportedChainId } from '@cowprotocol/cow-sdk'
|
|
14
|
+
* import { Web3Provider } from '@ethersproject/providers'
|
|
15
|
+
*
|
|
16
|
+
* const account = 'YOUR_WALLET_ADDRESS'
|
|
17
|
+
* const chainId = 5 // Goerli
|
|
18
|
+
* const provider = new Web3Provider(window.ethereum)
|
|
19
|
+
* const signer = provider.getSigner()
|
|
20
|
+
*
|
|
21
|
+
* async function main() {
|
|
22
|
+
* const { order: Order } = { ... }
|
|
23
|
+
* const orderSigningResult = await OrderSigningUtils.signOrder(quote, chainId, signer)
|
|
24
|
+
*
|
|
25
|
+
* const orderId = await orderBookApi.sendOrder({ ...quote, ...orderSigningResult })
|
|
26
|
+
*
|
|
27
|
+
* const order = await orderBookApi.getOrder(orderId)
|
|
28
|
+
*
|
|
29
|
+
* const trades = await orderBookApi.getTrades({ orderId })
|
|
30
|
+
*
|
|
31
|
+
* const orderCancellationSigningResult = await OrderSigningUtils.signOrderCancellations([orderId], chainId, signer)
|
|
32
|
+
*
|
|
33
|
+
* const cancellationResult = await orderBookApi.sendSignedOrderCancellations({...orderCancellationSigningResult, orderUids: [orderId] })
|
|
34
|
+
*
|
|
35
|
+
* console.log('Results: ', { orderId, order, trades, orderCancellationSigningResult, cancellationResult })
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
5
39
|
export declare class OrderSigningUtils {
|
|
40
|
+
/**
|
|
41
|
+
* Sign the order intent with the specified signer.
|
|
42
|
+
*
|
|
43
|
+
* @remarks If the API reports an error with the signature, it is likely to be due to an incorrectly
|
|
44
|
+
* specified `chainId`. Please ensure that the `chainId` is correct for the network you are
|
|
45
|
+
* using.
|
|
46
|
+
* @param {UnsignedOrder} order The unsigned order intent to be placed.
|
|
47
|
+
* @param {SupportedChainId} chainId The CoW Protocol `chainId` context that's being used.
|
|
48
|
+
* @param {Signer} signer The signer who is placing the order intent.
|
|
49
|
+
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the order.
|
|
50
|
+
*/
|
|
6
51
|
static signOrder(order: UnsignedOrder, chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
7
|
-
|
|
8
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Sign a cancellation message of an order intent with the specified signer.
|
|
54
|
+
* @param {string} orderUid The unique identifier of the order to cancel.
|
|
55
|
+
* @param {SupportedChainId} chainId The CoW Protocol `chainid` context that's being used.
|
|
56
|
+
* @param {Signer} signer The signer who initially placed the order intent.
|
|
57
|
+
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
58
|
+
*/
|
|
59
|
+
static signOrderCancellation(orderUid: string, chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Sign a cancellation message of multiple order intents with the specified signer.
|
|
62
|
+
* @param {string[]} orderUids An array of `orderUid` to cancel.
|
|
63
|
+
* @param {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
64
|
+
* @param {Signer} signer The signer who initially placed the order intents.
|
|
65
|
+
* @returns {Promise<SigningResult>} Encoded signature including signing scheme for the cancellation.
|
|
66
|
+
*/
|
|
67
|
+
static signOrderCancellations(orderUids: string[], chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Get the EIP-712 typed domain data being used for signing.
|
|
70
|
+
* @param {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
71
|
+
* @return The EIP-712 typed domain data.
|
|
72
|
+
* @see https://eips.ethereum.org/EIPS/eip-712
|
|
73
|
+
*/
|
|
9
74
|
static getDomain(chainId: SupportedChainId): Promise<TypedDataDomain>;
|
|
75
|
+
/**
|
|
76
|
+
* Get the domain separator hash for the EIP-712 typed domain data being used for signing.
|
|
77
|
+
* @param chainId {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
78
|
+
* @returns A string representation of the EIP-712 typed domain data hash.
|
|
79
|
+
*/
|
|
80
|
+
static getDomainSeparator(chainId: SupportedChainId): Promise<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Get the EIP-712 types used for signing a GPv2Order.Data struct. This is useful for when
|
|
83
|
+
* signing orders using smart contracts, whereby this SDK cannot do the EIP-1271 signing for you.
|
|
84
|
+
* @returns The EIP-712 types used for signing.
|
|
85
|
+
*/
|
|
86
|
+
static getEIP712Types(): Record<string, any>;
|
|
10
87
|
}
|
|
@@ -1,25 +1,52 @@
|
|
|
1
1
|
import type { SupportedChainId } from '../common';
|
|
2
2
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
3
3
|
import type { OrderParameters, EcdsaSigningScheme } from '../order-book';
|
|
4
|
+
/**
|
|
5
|
+
* Unsigned order intent to be placed.
|
|
6
|
+
*/
|
|
4
7
|
export type UnsignedOrder = Omit<OrderParameters, 'receiver'> & {
|
|
5
8
|
receiver: string;
|
|
6
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Encoded signature including signing scheme for the order.
|
|
12
|
+
*/
|
|
7
13
|
export type SigningResult = {
|
|
8
14
|
signature: string;
|
|
9
15
|
signingScheme: EcdsaSigningScheme;
|
|
10
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for signing an order intent.
|
|
19
|
+
* @param chainId The CoW Protocol `chainId` context that's being used.
|
|
20
|
+
* @param signer The signer who is placing the order intent.
|
|
21
|
+
* @param order The unsigned order intent to be placed.
|
|
22
|
+
* @param signingScheme The signing scheme to use for the signature.
|
|
23
|
+
*/
|
|
11
24
|
export interface SignOrderParams {
|
|
12
25
|
chainId: SupportedChainId;
|
|
13
26
|
signer: Signer;
|
|
14
27
|
order: UnsignedOrder;
|
|
15
28
|
signingScheme: EcdsaSigningScheme;
|
|
16
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Parameters for signing an order cancellation.
|
|
32
|
+
* @param chainId The CoW Protocol `chainId` context that's being used.
|
|
33
|
+
* @param signer The signer who initially placed the order intent.
|
|
34
|
+
* @param orderUid The unique identifier of the order to cancel.
|
|
35
|
+
* @param signingScheme The signing scheme to use for the signature.
|
|
36
|
+
*/
|
|
17
37
|
export interface SignOrderCancellationParams {
|
|
18
38
|
chainId: SupportedChainId;
|
|
19
39
|
signer: Signer;
|
|
20
|
-
|
|
40
|
+
orderUid: string;
|
|
21
41
|
signingScheme: EcdsaSigningScheme;
|
|
22
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Parameters for signing multiple bulk order cancellations.
|
|
45
|
+
* @param chainId The CoW Protocol `chainId` context that's being used.
|
|
46
|
+
* @param signer The signer who initially placed the order intents.
|
|
47
|
+
* @param orderUids An array of `orderUid` to cancel.
|
|
48
|
+
* @param signingScheme The signing scheme to use for the signature.
|
|
49
|
+
*/
|
|
23
50
|
export interface SignOrderCancellationsParams {
|
|
24
51
|
chainId: SupportedChainId;
|
|
25
52
|
signer: Signer;
|
|
@@ -5,7 +5,6 @@ import { SupportedChainId } from '../common';
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns the signature for the specified order with the signing scheme encoded
|
|
7
7
|
* into the signature.
|
|
8
|
-
* @export
|
|
9
8
|
* @param {UnsignedOrder} order The order to sign.
|
|
10
9
|
* @param {SupportedChainId} chainId The chain Id
|
|
11
10
|
* @param {Signer} signer The owner for the order used to sign.
|
|
@@ -15,13 +14,26 @@ export declare function signOrder(order: UnsignedOrder, chainId: SupportedChainI
|
|
|
15
14
|
/**
|
|
16
15
|
* Returns the signature for the Order Cancellation with the signing scheme encoded
|
|
17
16
|
* into the signature.
|
|
18
|
-
*
|
|
19
|
-
* @export
|
|
20
|
-
* @param {string} orderId The unique identifier of the order being cancelled.
|
|
17
|
+
* @param {string} orderUid The unique identifier of the order being cancelled.
|
|
21
18
|
* @param {SupportedChainId} chainId The chain Id
|
|
22
19
|
* @param {Signer} signer The owner for the order used to sign.
|
|
23
20
|
* @return {*} Encoded signature including signing scheme for the order.
|
|
24
21
|
*/
|
|
25
|
-
export declare function signOrderCancellation(
|
|
22
|
+
export declare function signOrderCancellation(orderUid: string, chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the signature for the Order Cancellations with the signing scheme encoded
|
|
25
|
+
* into the signature.
|
|
26
|
+
*
|
|
27
|
+
* @param {string[]} orderUids The unique identifiers of the orders being cancelled.
|
|
28
|
+
* @param {SupportedChainId} chainId The CoW Protocol protocol `chainId` context that's being used.
|
|
29
|
+
* @param {Signer} signer The owner that had placed the orders used to sign.
|
|
30
|
+
* @returns {*} Encoded signature including signing scheme for the order.
|
|
31
|
+
*/
|
|
26
32
|
export declare function signOrderCancellations(orderUids: string[], chainId: SupportedChainId, signer: Signer): Promise<SigningResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the TypedDataDomain used for signing for the specified chainId.
|
|
35
|
+
* @param {SupportedChainId} chainId The chain Id
|
|
36
|
+
* @return {*} The TypedDataDomain for the specified chainId.
|
|
37
|
+
* @throws {CowError} If the chainId is not supported.
|
|
38
|
+
*/
|
|
27
39
|
export declare function getDomain(chainId: SupportedChainId): TypedDataDomain;
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/cow-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-rc.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"files": [
|
|
6
6
|
"/dist"
|
|
@@ -22,19 +22,22 @@
|
|
|
22
22
|
"format": "prettier --write \"src/**/*.+(ts|json)\"",
|
|
23
23
|
"test": "jest",
|
|
24
24
|
"test:coverage": "jest --coverage --json --outputFile=jest.results.json && cat ./coverage/lcov.info | coveralls",
|
|
25
|
-
"
|
|
25
|
+
"test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
|
|
26
|
+
"codegen": "npm run graphql:codegen && npm run swagger:codegen && npm run typechain:codegen",
|
|
26
27
|
"prepare": "npm run build",
|
|
27
28
|
"prepublishOnly": "npm test && npm run lint",
|
|
28
29
|
"graphql:codegen": "graphql-codegen --config graphql-codegen.yml",
|
|
29
|
-
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/
|
|
30
|
+
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/v2.119.0/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false",
|
|
31
|
+
"typechain:codegen": "typechain --target ethers-v5 --out-dir ./src/composable/generated './abi/*.json'"
|
|
30
32
|
},
|
|
31
33
|
"dependencies": {
|
|
32
34
|
"@cowprotocol/contracts": "^1.4.0",
|
|
33
35
|
"@ethersproject/abstract-signer": "^5.7.0",
|
|
34
|
-
"
|
|
35
|
-
"limiter": "^2.1.0",
|
|
36
|
+
"@openzeppelin/merkle-tree": "^1.0.5",
|
|
36
37
|
"cross-fetch": "^3.1.5",
|
|
37
|
-
"
|
|
38
|
+
"exponential-backoff": "^3.1.1",
|
|
39
|
+
"graphql-request": "^4.3.0",
|
|
40
|
+
"limiter": "^2.1.0"
|
|
38
41
|
},
|
|
39
42
|
"peerDependencies": {
|
|
40
43
|
"ethers": "^5.7.2"
|
|
@@ -47,6 +50,7 @@
|
|
|
47
50
|
"@graphql-codegen/cli": "3.0.0",
|
|
48
51
|
"@graphql-codegen/typescript": "3.0.0",
|
|
49
52
|
"@graphql-codegen/typescript-operations": "^3.0.0",
|
|
53
|
+
"@typechain/ethers-v5": "^11.0.0",
|
|
50
54
|
"@types/jest": "^29.4.0",
|
|
51
55
|
"@types/node": "^18.13.0",
|
|
52
56
|
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
@@ -56,6 +60,7 @@
|
|
|
56
60
|
"eslint": "^8.33.0",
|
|
57
61
|
"eslint-config-prettier": "^8.6.0",
|
|
58
62
|
"eslint-plugin-prettier": "^4.2.1",
|
|
63
|
+
"eslint-plugin-unused-imports": "^3.0.0",
|
|
59
64
|
"ethers": "^5.7.2",
|
|
60
65
|
"graphql": "^16.3.0",
|
|
61
66
|
"jest": "^29.4.2",
|
|
@@ -65,6 +70,7 @@
|
|
|
65
70
|
"prettier": "^2.5.1",
|
|
66
71
|
"ts-mockito": "^2.6.1",
|
|
67
72
|
"tsc-watch": "^6.0.0",
|
|
73
|
+
"typechain": "^8.2.0",
|
|
68
74
|
"typescript": "^4.9.5"
|
|
69
75
|
},
|
|
70
76
|
"jest": {
|
|
@@ -75,6 +81,9 @@
|
|
|
75
81
|
],
|
|
76
82
|
"collectCoverageFrom": [
|
|
77
83
|
"src/**/*.{ts,tsx}"
|
|
84
|
+
],
|
|
85
|
+
"coveragePathIgnorePatterns": [
|
|
86
|
+
"src/composable/generated"
|
|
78
87
|
]
|
|
79
88
|
},
|
|
80
89
|
"keywords": [
|