@cowprotocol/sdk-order-book 1.0.0 → 1.1.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/README.md +33 -0
- package/dist/index.d.mts +18 -4
- package/dist/index.d.ts +18 -4
- package/dist/index.js +54 -13
- package/dist/index.mjs +52 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -121,6 +121,39 @@ const orderBookApi = new OrderBookApi({
|
|
|
121
121
|
})
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
+
### Partner API (Authenticated Access)
|
|
125
|
+
|
|
126
|
+
Partners can use the Partner API for authenticated, rate-limited access with higher request quotas. Provide your API key and the SDK will automatically route requests through the partner gateway and attach the `X-API-Key` header.
|
|
127
|
+
|
|
128
|
+
| Environment | Partner API Base URL |
|
|
129
|
+
|-------------|---------------------|
|
|
130
|
+
| Production | `https://partners.cow.fi` |
|
|
131
|
+
| Staging | `https://partners.barn.cow.fi` |
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
const orderBookApi = new OrderBookApi({
|
|
135
|
+
chainId: SupportedChainId.MAINNET,
|
|
136
|
+
apiKey: 'your-partner-api-key',
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
To use the Partner API with the Trading SDK, pass a configured `OrderBookApi` instance:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { TradingSdk } from '@cowprotocol/sdk-trading'
|
|
144
|
+
|
|
145
|
+
const orderBookApi = new OrderBookApi({
|
|
146
|
+
chainId: SupportedChainId.MAINNET,
|
|
147
|
+
apiKey: 'your-partner-api-key',
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
const sdk = new TradingSdk(
|
|
151
|
+
{ chainId: SupportedChainId.MAINNET, appCode: 'YOUR_APP_CODE' },
|
|
152
|
+
{ orderBookApi },
|
|
153
|
+
adapter,
|
|
154
|
+
)
|
|
155
|
+
```
|
|
156
|
+
|
|
124
157
|
### Rate Limiting Configuration
|
|
125
158
|
|
|
126
159
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -1129,6 +1129,18 @@ declare const ORDER_BOOK_PROD_CONFIG: ApiBaseUrls;
|
|
|
1129
1129
|
* An object containing *staging* environment base URLs for each supported `chainId`.
|
|
1130
1130
|
*/
|
|
1131
1131
|
declare const ORDER_BOOK_STAGING_CONFIG: ApiBaseUrls;
|
|
1132
|
+
/**
|
|
1133
|
+
* An object containing *partner production* environment base URLs for each supported `chainId`.
|
|
1134
|
+
* Used when apiKey is set; requests include X-API-Key header.
|
|
1135
|
+
* @see {@link https://partners.cow.fi}
|
|
1136
|
+
*/
|
|
1137
|
+
declare const ORDER_BOOK_PARTNER_PROD_CONFIG: ApiBaseUrls;
|
|
1138
|
+
/**
|
|
1139
|
+
* An object containing *partner staging* environment base URLs for each supported `chainId`.
|
|
1140
|
+
* Used when apiKey is set and env is staging; requests include X-API-Key header.
|
|
1141
|
+
* @see {@link https://partners.barn.cow.fi}
|
|
1142
|
+
*/
|
|
1143
|
+
declare const ORDER_BOOK_PARTNER_STAGING_CONFIG: ApiBaseUrls;
|
|
1132
1144
|
/**
|
|
1133
1145
|
* The parameters for the `getOrders` request.
|
|
1134
1146
|
*/
|
|
@@ -1344,8 +1356,9 @@ declare class OrderBookApi {
|
|
|
1344
1356
|
*/
|
|
1345
1357
|
private getContextWithOverride;
|
|
1346
1358
|
/**
|
|
1347
|
-
* Get the base URLs for the API endpoints given the
|
|
1348
|
-
*
|
|
1359
|
+
* Get the base URLs for the API endpoints given the context.
|
|
1360
|
+
* Uses partner URLs when apiKey is set (and no custom baseUrls override).
|
|
1361
|
+
* @param context The merged API context for the request.
|
|
1349
1362
|
* @returns The base URLs for the API endpoints.
|
|
1350
1363
|
*/
|
|
1351
1364
|
private getApiBaseUrls;
|
|
@@ -1401,10 +1414,11 @@ interface FetchParams {
|
|
|
1401
1414
|
* @param body The body of the request.
|
|
1402
1415
|
* @param rateLimiter The rate limiter to use.
|
|
1403
1416
|
* @param backoffOpts The backoff options to use.
|
|
1417
|
+
* @param additionalHeaders Optional additional headers (e.g. X-API-Key for Partner API).
|
|
1404
1418
|
* @returns The response of the request.
|
|
1405
1419
|
* @throws If the API returns an error or if the request fails.
|
|
1406
1420
|
*/
|
|
1407
|
-
declare function request<T>(baseUrl: string, { path, query, method, body }: FetchParams, rateLimiter: RateLimiter, backoffOpts: BackoffOptions): Promise<T>;
|
|
1421
|
+
declare function request<T>(baseUrl: string, { path, query, method, body }: FetchParams, rateLimiter: RateLimiter, backoffOpts: BackoffOptions, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
1408
1422
|
|
|
1409
1423
|
type OrderAmountsBig = {
|
|
1410
1424
|
sellAmount: bigint;
|
|
@@ -1532,4 +1546,4 @@ interface ProtocolFeeAmountParams {
|
|
|
1532
1546
|
*/
|
|
1533
1547
|
declare function getProtocolFeeAmount(params: ProtocolFeeAmountParams): bigint;
|
|
1534
1548
|
|
|
1535
|
-
export { type Address, type Amounts, type AppData, type AppDataHash, type AppDataObject, type Auction, type AuctionOrder, type AuctionPrices, type BigUint, BuyTokenDestination, type CallData, type CompetitionAuction, CompetitionOrderStatus, type Costs, DEFAULT_BACKOFF_OPTIONS, DEFAULT_LIMITER_OPTIONS, type EcdsaSignature, EcdsaSigningScheme, type EnrichedOrder, type EthflowData, type ExecutedAmounts, type ExecutedProtocolFee, type FeePolicy, type FetchParams, type GetOrdersRequest, type GetTradesRequest, type InteractionData, type NativePriceResponse, ORDER_BOOK_PROD_CONFIG, ORDER_BOOK_STAGING_CONFIG, OnchainOrderData, type Order, type OrderAmountsBig, OrderBookApi, OrderBookApiError, type OrderCancellation, OrderCancellationError, type OrderCancellations, OrderClass, type OrderCreation, OrderKind, type OrderMetaData, type OrderParameters, OrderPostError, type OrderQuoteRequest, type OrderQuoteResponse, type OrderQuoteSide, OrderQuoteSideKindBuy, OrderQuoteSideKindSell, type OrderQuoteValidity, OrderStatus, type PreSignature, PriceEstimationError, type PriceImprovement, PriceQuality, type ProtocolFeeAmountParams, type Quote, type QuoteAmountsAfterSlippage, type QuoteAmountsAfterSlippageParams, type QuoteAmountsAndCosts, type QuoteAmountsAndCostsParams, type QuoteAmountsWithNetworkCosts, type QuoteParameters, type QuotePriceParams, SellTokenSource, type Signature, SigningScheme, type SolverCompetitionResponse, type SolverSettlement, type Surplus, type TokenAmount, type TotalSurplus, type Trade, type TransactionHash, type UID, type Volume, getProtocolFeeAmount, getQuoteAmountsAfterPartnerFee, getQuoteAmountsAfterSlippage, getQuoteAmountsAndCosts, request };
|
|
1549
|
+
export { type Address, type Amounts, type AppData, type AppDataHash, type AppDataObject, type Auction, type AuctionOrder, type AuctionPrices, type BigUint, BuyTokenDestination, type CallData, type CompetitionAuction, CompetitionOrderStatus, type Costs, DEFAULT_BACKOFF_OPTIONS, DEFAULT_LIMITER_OPTIONS, type EcdsaSignature, EcdsaSigningScheme, type EnrichedOrder, type EthflowData, type ExecutedAmounts, type ExecutedProtocolFee, type FeePolicy, type FetchParams, type GetOrdersRequest, type GetTradesRequest, type InteractionData, type NativePriceResponse, ORDER_BOOK_PARTNER_PROD_CONFIG, ORDER_BOOK_PARTNER_STAGING_CONFIG, ORDER_BOOK_PROD_CONFIG, ORDER_BOOK_STAGING_CONFIG, OnchainOrderData, type Order, type OrderAmountsBig, OrderBookApi, OrderBookApiError, type OrderCancellation, OrderCancellationError, type OrderCancellations, OrderClass, type OrderCreation, OrderKind, type OrderMetaData, type OrderParameters, OrderPostError, type OrderQuoteRequest, type OrderQuoteResponse, type OrderQuoteSide, OrderQuoteSideKindBuy, OrderQuoteSideKindSell, type OrderQuoteValidity, OrderStatus, type PreSignature, PriceEstimationError, type PriceImprovement, PriceQuality, type ProtocolFeeAmountParams, type Quote, type QuoteAmountsAfterSlippage, type QuoteAmountsAfterSlippageParams, type QuoteAmountsAndCosts, type QuoteAmountsAndCostsParams, type QuoteAmountsWithNetworkCosts, type QuoteParameters, type QuotePriceParams, SellTokenSource, type Signature, SigningScheme, type SolverCompetitionResponse, type SolverSettlement, type Surplus, type TokenAmount, type TotalSurplus, type Trade, type TransactionHash, type UID, type Volume, getProtocolFeeAmount, getQuoteAmountsAfterPartnerFee, getQuoteAmountsAfterSlippage, getQuoteAmountsAndCosts, request };
|
package/dist/index.d.ts
CHANGED
|
@@ -1129,6 +1129,18 @@ declare const ORDER_BOOK_PROD_CONFIG: ApiBaseUrls;
|
|
|
1129
1129
|
* An object containing *staging* environment base URLs for each supported `chainId`.
|
|
1130
1130
|
*/
|
|
1131
1131
|
declare const ORDER_BOOK_STAGING_CONFIG: ApiBaseUrls;
|
|
1132
|
+
/**
|
|
1133
|
+
* An object containing *partner production* environment base URLs for each supported `chainId`.
|
|
1134
|
+
* Used when apiKey is set; requests include X-API-Key header.
|
|
1135
|
+
* @see {@link https://partners.cow.fi}
|
|
1136
|
+
*/
|
|
1137
|
+
declare const ORDER_BOOK_PARTNER_PROD_CONFIG: ApiBaseUrls;
|
|
1138
|
+
/**
|
|
1139
|
+
* An object containing *partner staging* environment base URLs for each supported `chainId`.
|
|
1140
|
+
* Used when apiKey is set and env is staging; requests include X-API-Key header.
|
|
1141
|
+
* @see {@link https://partners.barn.cow.fi}
|
|
1142
|
+
*/
|
|
1143
|
+
declare const ORDER_BOOK_PARTNER_STAGING_CONFIG: ApiBaseUrls;
|
|
1132
1144
|
/**
|
|
1133
1145
|
* The parameters for the `getOrders` request.
|
|
1134
1146
|
*/
|
|
@@ -1344,8 +1356,9 @@ declare class OrderBookApi {
|
|
|
1344
1356
|
*/
|
|
1345
1357
|
private getContextWithOverride;
|
|
1346
1358
|
/**
|
|
1347
|
-
* Get the base URLs for the API endpoints given the
|
|
1348
|
-
*
|
|
1359
|
+
* Get the base URLs for the API endpoints given the context.
|
|
1360
|
+
* Uses partner URLs when apiKey is set (and no custom baseUrls override).
|
|
1361
|
+
* @param context The merged API context for the request.
|
|
1349
1362
|
* @returns The base URLs for the API endpoints.
|
|
1350
1363
|
*/
|
|
1351
1364
|
private getApiBaseUrls;
|
|
@@ -1401,10 +1414,11 @@ interface FetchParams {
|
|
|
1401
1414
|
* @param body The body of the request.
|
|
1402
1415
|
* @param rateLimiter The rate limiter to use.
|
|
1403
1416
|
* @param backoffOpts The backoff options to use.
|
|
1417
|
+
* @param additionalHeaders Optional additional headers (e.g. X-API-Key for Partner API).
|
|
1404
1418
|
* @returns The response of the request.
|
|
1405
1419
|
* @throws If the API returns an error or if the request fails.
|
|
1406
1420
|
*/
|
|
1407
|
-
declare function request<T>(baseUrl: string, { path, query, method, body }: FetchParams, rateLimiter: RateLimiter, backoffOpts: BackoffOptions): Promise<T>;
|
|
1421
|
+
declare function request<T>(baseUrl: string, { path, query, method, body }: FetchParams, rateLimiter: RateLimiter, backoffOpts: BackoffOptions, additionalHeaders?: Record<string, string>): Promise<T>;
|
|
1408
1422
|
|
|
1409
1423
|
type OrderAmountsBig = {
|
|
1410
1424
|
sellAmount: bigint;
|
|
@@ -1532,4 +1546,4 @@ interface ProtocolFeeAmountParams {
|
|
|
1532
1546
|
*/
|
|
1533
1547
|
declare function getProtocolFeeAmount(params: ProtocolFeeAmountParams): bigint;
|
|
1534
1548
|
|
|
1535
|
-
export { type Address, type Amounts, type AppData, type AppDataHash, type AppDataObject, type Auction, type AuctionOrder, type AuctionPrices, type BigUint, BuyTokenDestination, type CallData, type CompetitionAuction, CompetitionOrderStatus, type Costs, DEFAULT_BACKOFF_OPTIONS, DEFAULT_LIMITER_OPTIONS, type EcdsaSignature, EcdsaSigningScheme, type EnrichedOrder, type EthflowData, type ExecutedAmounts, type ExecutedProtocolFee, type FeePolicy, type FetchParams, type GetOrdersRequest, type GetTradesRequest, type InteractionData, type NativePriceResponse, ORDER_BOOK_PROD_CONFIG, ORDER_BOOK_STAGING_CONFIG, OnchainOrderData, type Order, type OrderAmountsBig, OrderBookApi, OrderBookApiError, type OrderCancellation, OrderCancellationError, type OrderCancellations, OrderClass, type OrderCreation, OrderKind, type OrderMetaData, type OrderParameters, OrderPostError, type OrderQuoteRequest, type OrderQuoteResponse, type OrderQuoteSide, OrderQuoteSideKindBuy, OrderQuoteSideKindSell, type OrderQuoteValidity, OrderStatus, type PreSignature, PriceEstimationError, type PriceImprovement, PriceQuality, type ProtocolFeeAmountParams, type Quote, type QuoteAmountsAfterSlippage, type QuoteAmountsAfterSlippageParams, type QuoteAmountsAndCosts, type QuoteAmountsAndCostsParams, type QuoteAmountsWithNetworkCosts, type QuoteParameters, type QuotePriceParams, SellTokenSource, type Signature, SigningScheme, type SolverCompetitionResponse, type SolverSettlement, type Surplus, type TokenAmount, type TotalSurplus, type Trade, type TransactionHash, type UID, type Volume, getProtocolFeeAmount, getQuoteAmountsAfterPartnerFee, getQuoteAmountsAfterSlippage, getQuoteAmountsAndCosts, request };
|
|
1549
|
+
export { type Address, type Amounts, type AppData, type AppDataHash, type AppDataObject, type Auction, type AuctionOrder, type AuctionPrices, type BigUint, BuyTokenDestination, type CallData, type CompetitionAuction, CompetitionOrderStatus, type Costs, DEFAULT_BACKOFF_OPTIONS, DEFAULT_LIMITER_OPTIONS, type EcdsaSignature, EcdsaSigningScheme, type EnrichedOrder, type EthflowData, type ExecutedAmounts, type ExecutedProtocolFee, type FeePolicy, type FetchParams, type GetOrdersRequest, type GetTradesRequest, type InteractionData, type NativePriceResponse, ORDER_BOOK_PARTNER_PROD_CONFIG, ORDER_BOOK_PARTNER_STAGING_CONFIG, ORDER_BOOK_PROD_CONFIG, ORDER_BOOK_STAGING_CONFIG, OnchainOrderData, type Order, type OrderAmountsBig, OrderBookApi, OrderBookApiError, type OrderCancellation, OrderCancellationError, type OrderCancellations, OrderClass, type OrderCreation, OrderKind, type OrderMetaData, type OrderParameters, OrderPostError, type OrderQuoteRequest, type OrderQuoteResponse, type OrderQuoteSide, OrderQuoteSideKindBuy, OrderQuoteSideKindSell, type OrderQuoteValidity, OrderStatus, type PreSignature, PriceEstimationError, type PriceImprovement, PriceQuality, type ProtocolFeeAmountParams, type Quote, type QuoteAmountsAfterSlippage, type QuoteAmountsAfterSlippageParams, type QuoteAmountsAndCosts, type QuoteAmountsAndCostsParams, type QuoteAmountsWithNetworkCosts, type QuoteParameters, type QuotePriceParams, SellTokenSource, type Signature, SigningScheme, type SolverCompetitionResponse, type SolverSettlement, type Surplus, type TokenAmount, type TotalSurplus, type Trade, type TransactionHash, type UID, type Volume, getProtocolFeeAmount, getQuoteAmountsAfterPartnerFee, getQuoteAmountsAfterSlippage, getQuoteAmountsAndCosts, request };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ __export(src_exports, {
|
|
|
25
25
|
DEFAULT_BACKOFF_OPTIONS: () => DEFAULT_BACKOFF_OPTIONS,
|
|
26
26
|
DEFAULT_LIMITER_OPTIONS: () => DEFAULT_LIMITER_OPTIONS,
|
|
27
27
|
EcdsaSigningScheme: () => EcdsaSigningScheme,
|
|
28
|
+
ORDER_BOOK_PARTNER_PROD_CONFIG: () => ORDER_BOOK_PARTNER_PROD_CONFIG,
|
|
29
|
+
ORDER_BOOK_PARTNER_STAGING_CONFIG: () => ORDER_BOOK_PARTNER_STAGING_CONFIG,
|
|
28
30
|
ORDER_BOOK_PROD_CONFIG: () => ORDER_BOOK_PROD_CONFIG,
|
|
29
31
|
ORDER_BOOK_STAGING_CONFIG: () => ORDER_BOOK_STAGING_CONFIG,
|
|
30
32
|
OnchainOrderData: () => OnchainOrderData,
|
|
@@ -118,11 +120,12 @@ var getResponseBody = async (response) => {
|
|
|
118
120
|
}
|
|
119
121
|
return void 0;
|
|
120
122
|
};
|
|
121
|
-
async function request(baseUrl, { path, query, method, body }, rateLimiter, backoffOpts) {
|
|
123
|
+
async function request(baseUrl, { path, query, method, body }, rateLimiter, backoffOpts, additionalHeaders) {
|
|
122
124
|
const queryString = query ? "?" + query : "";
|
|
123
125
|
const headers = {
|
|
124
126
|
Accept: "application/json",
|
|
125
|
-
"Content-Type": "application/json"
|
|
127
|
+
"Content-Type": "application/json",
|
|
128
|
+
...additionalHeaders
|
|
126
129
|
};
|
|
127
130
|
const url = `${baseUrl}${path}${queryString}`;
|
|
128
131
|
const bodyContent = (() => {
|
|
@@ -175,6 +178,8 @@ function transformEthFlowOrder(order) {
|
|
|
175
178
|
// src/api.ts
|
|
176
179
|
var PROD_BASE_URL = "https://api.cow.fi";
|
|
177
180
|
var STAGING_BASE_URL = "https://barn.api.cow.fi";
|
|
181
|
+
var PARTNER_PROD_BASE_URL = "https://partners.cow.fi";
|
|
182
|
+
var PARTNER_STAGING_BASE_URL = "https://partners.barn.cow.fi";
|
|
178
183
|
var ORDER_BOOK_PROD_CONFIG = {
|
|
179
184
|
[import_sdk_config2.SupportedChainId.MAINNET]: `${PROD_BASE_URL}/mainnet`,
|
|
180
185
|
[import_sdk_config2.SupportedChainId.GNOSIS_CHAIN]: `${PROD_BASE_URL}/xdai`,
|
|
@@ -203,6 +208,34 @@ var ORDER_BOOK_STAGING_CONFIG = {
|
|
|
203
208
|
[import_sdk_config2.SupportedChainId.PLASMA]: `${STAGING_BASE_URL}/plasma`,
|
|
204
209
|
[import_sdk_config2.SupportedChainId.INK]: `${STAGING_BASE_URL}/ink`
|
|
205
210
|
};
|
|
211
|
+
var ORDER_BOOK_PARTNER_PROD_CONFIG = {
|
|
212
|
+
[import_sdk_config2.SupportedChainId.MAINNET]: `${PARTNER_PROD_BASE_URL}/mainnet`,
|
|
213
|
+
[import_sdk_config2.SupportedChainId.GNOSIS_CHAIN]: `${PARTNER_PROD_BASE_URL}/xdai`,
|
|
214
|
+
[import_sdk_config2.SupportedChainId.ARBITRUM_ONE]: `${PARTNER_PROD_BASE_URL}/arbitrum_one`,
|
|
215
|
+
[import_sdk_config2.SupportedChainId.BASE]: `${PARTNER_PROD_BASE_URL}/base`,
|
|
216
|
+
[import_sdk_config2.SupportedChainId.SEPOLIA]: `${PARTNER_PROD_BASE_URL}/sepolia`,
|
|
217
|
+
[import_sdk_config2.SupportedChainId.POLYGON]: `${PARTNER_PROD_BASE_URL}/polygon`,
|
|
218
|
+
[import_sdk_config2.SupportedChainId.AVALANCHE]: `${PARTNER_PROD_BASE_URL}/avalanche`,
|
|
219
|
+
[import_sdk_config2.SupportedChainId.LENS]: `${PARTNER_PROD_BASE_URL}/lens`,
|
|
220
|
+
[import_sdk_config2.SupportedChainId.BNB]: `${PARTNER_PROD_BASE_URL}/bnb`,
|
|
221
|
+
[import_sdk_config2.SupportedChainId.LINEA]: `${PARTNER_PROD_BASE_URL}/linea`,
|
|
222
|
+
[import_sdk_config2.SupportedChainId.PLASMA]: `${PARTNER_PROD_BASE_URL}/plasma`,
|
|
223
|
+
[import_sdk_config2.SupportedChainId.INK]: `${PARTNER_PROD_BASE_URL}/ink`
|
|
224
|
+
};
|
|
225
|
+
var ORDER_BOOK_PARTNER_STAGING_CONFIG = {
|
|
226
|
+
[import_sdk_config2.SupportedChainId.MAINNET]: `${PARTNER_STAGING_BASE_URL}/mainnet`,
|
|
227
|
+
[import_sdk_config2.SupportedChainId.GNOSIS_CHAIN]: `${PARTNER_STAGING_BASE_URL}/xdai`,
|
|
228
|
+
[import_sdk_config2.SupportedChainId.ARBITRUM_ONE]: `${PARTNER_STAGING_BASE_URL}/arbitrum_one`,
|
|
229
|
+
[import_sdk_config2.SupportedChainId.BASE]: `${PARTNER_STAGING_BASE_URL}/base`,
|
|
230
|
+
[import_sdk_config2.SupportedChainId.SEPOLIA]: `${PARTNER_STAGING_BASE_URL}/sepolia`,
|
|
231
|
+
[import_sdk_config2.SupportedChainId.POLYGON]: `${PARTNER_STAGING_BASE_URL}/polygon`,
|
|
232
|
+
[import_sdk_config2.SupportedChainId.AVALANCHE]: `${PARTNER_STAGING_BASE_URL}/avalanche`,
|
|
233
|
+
[import_sdk_config2.SupportedChainId.LENS]: `${PARTNER_STAGING_BASE_URL}/lens`,
|
|
234
|
+
[import_sdk_config2.SupportedChainId.BNB]: `${PARTNER_STAGING_BASE_URL}/bnb`,
|
|
235
|
+
[import_sdk_config2.SupportedChainId.LINEA]: `${PARTNER_STAGING_BASE_URL}/linea`,
|
|
236
|
+
[import_sdk_config2.SupportedChainId.PLASMA]: `${PARTNER_STAGING_BASE_URL}/plasma`,
|
|
237
|
+
[import_sdk_config2.SupportedChainId.INK]: `${PARTNER_STAGING_BASE_URL}/ink`
|
|
238
|
+
};
|
|
206
239
|
function cleanObjectFromUndefinedValues(obj) {
|
|
207
240
|
return Object.keys(obj).reduce(
|
|
208
241
|
(acc, key) => {
|
|
@@ -428,8 +461,8 @@ var OrderBookApi = class {
|
|
|
428
461
|
* @returns The API endpoint to get the order.
|
|
429
462
|
*/
|
|
430
463
|
getOrderLink(orderUid, contextOverride) {
|
|
431
|
-
const
|
|
432
|
-
return this.getApiBaseUrls(
|
|
464
|
+
const context = this.getContextWithOverride(contextOverride ?? {});
|
|
465
|
+
return this.getApiBaseUrls(context)[context.chainId] + `/api/v1/orders/${orderUid}`;
|
|
433
466
|
}
|
|
434
467
|
/**
|
|
435
468
|
* Apply an override to the context for a request.
|
|
@@ -440,14 +473,18 @@ var OrderBookApi = class {
|
|
|
440
473
|
return { ...this.context, ...contextOverride };
|
|
441
474
|
}
|
|
442
475
|
/**
|
|
443
|
-
* Get the base URLs for the API endpoints given the
|
|
444
|
-
*
|
|
476
|
+
* Get the base URLs for the API endpoints given the context.
|
|
477
|
+
* Uses partner URLs when apiKey is set (and no custom baseUrls override).
|
|
478
|
+
* @param context The merged API context for the request.
|
|
445
479
|
* @returns The base URLs for the API endpoints.
|
|
446
480
|
*/
|
|
447
|
-
getApiBaseUrls(
|
|
448
|
-
if (
|
|
449
|
-
return
|
|
450
|
-
|
|
481
|
+
getApiBaseUrls(context) {
|
|
482
|
+
if (context.baseUrls)
|
|
483
|
+
return context.baseUrls;
|
|
484
|
+
if (context.apiKey) {
|
|
485
|
+
return context.env === "prod" ? ORDER_BOOK_PARTNER_PROD_CONFIG : ORDER_BOOK_PARTNER_STAGING_CONFIG;
|
|
486
|
+
}
|
|
487
|
+
return context.env === "prod" ? ORDER_BOOK_PROD_CONFIG : ORDER_BOOK_STAGING_CONFIG;
|
|
451
488
|
}
|
|
452
489
|
/**
|
|
453
490
|
* Make a request to the API.
|
|
@@ -456,12 +493,14 @@ var OrderBookApi = class {
|
|
|
456
493
|
* @returns The response from the API.
|
|
457
494
|
*/
|
|
458
495
|
fetch(params, contextOverride = {}) {
|
|
459
|
-
const
|
|
460
|
-
const
|
|
496
|
+
const context = this.getContextWithOverride(contextOverride);
|
|
497
|
+
const { chainId, backoffOpts: _backoffOpts, apiKey } = context;
|
|
498
|
+
const baseUrl = this.getApiBaseUrls(context)[chainId];
|
|
461
499
|
const backoffOpts = _backoffOpts || DEFAULT_BACKOFF_OPTIONS;
|
|
462
500
|
const rateLimiter = contextOverride.limiterOpts ? new import_limiter.RateLimiter(contextOverride.limiterOpts) : this.rateLimiter;
|
|
501
|
+
const additionalHeaders = apiKey ? { "X-API-Key": apiKey } : void 0;
|
|
463
502
|
(0, import_sdk_common.log)(`Fetching OrderBook API: ${baseUrl}${params.path}. Params: ${JSON.stringify(params, import_sdk_common.jsonWithBigintReplacer)}`);
|
|
464
|
-
return request(baseUrl, params, rateLimiter, backoffOpts);
|
|
503
|
+
return request(baseUrl, params, rateLimiter, backoffOpts, additionalHeaders);
|
|
465
504
|
}
|
|
466
505
|
};
|
|
467
506
|
|
|
@@ -785,6 +824,8 @@ function getQuoteAmountsAndCosts(params) {
|
|
|
785
824
|
DEFAULT_BACKOFF_OPTIONS,
|
|
786
825
|
DEFAULT_LIMITER_OPTIONS,
|
|
787
826
|
EcdsaSigningScheme,
|
|
827
|
+
ORDER_BOOK_PARTNER_PROD_CONFIG,
|
|
828
|
+
ORDER_BOOK_PARTNER_STAGING_CONFIG,
|
|
788
829
|
ORDER_BOOK_PROD_CONFIG,
|
|
789
830
|
ORDER_BOOK_STAGING_CONFIG,
|
|
790
831
|
OnchainOrderData,
|
package/dist/index.mjs
CHANGED
|
@@ -71,11 +71,12 @@ var getResponseBody = async (response) => {
|
|
|
71
71
|
}
|
|
72
72
|
return void 0;
|
|
73
73
|
};
|
|
74
|
-
async function request(baseUrl, { path, query, method, body }, rateLimiter, backoffOpts) {
|
|
74
|
+
async function request(baseUrl, { path, query, method, body }, rateLimiter, backoffOpts, additionalHeaders) {
|
|
75
75
|
const queryString = query ? "?" + query : "";
|
|
76
76
|
const headers = {
|
|
77
77
|
Accept: "application/json",
|
|
78
|
-
"Content-Type": "application/json"
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
...additionalHeaders
|
|
79
80
|
};
|
|
80
81
|
const url = `${baseUrl}${path}${queryString}`;
|
|
81
82
|
const bodyContent = (() => {
|
|
@@ -128,6 +129,8 @@ function transformEthFlowOrder(order) {
|
|
|
128
129
|
// src/api.ts
|
|
129
130
|
var PROD_BASE_URL = "https://api.cow.fi";
|
|
130
131
|
var STAGING_BASE_URL = "https://barn.api.cow.fi";
|
|
132
|
+
var PARTNER_PROD_BASE_URL = "https://partners.cow.fi";
|
|
133
|
+
var PARTNER_STAGING_BASE_URL = "https://partners.barn.cow.fi";
|
|
131
134
|
var ORDER_BOOK_PROD_CONFIG = {
|
|
132
135
|
[SupportedChainId.MAINNET]: `${PROD_BASE_URL}/mainnet`,
|
|
133
136
|
[SupportedChainId.GNOSIS_CHAIN]: `${PROD_BASE_URL}/xdai`,
|
|
@@ -156,6 +159,34 @@ var ORDER_BOOK_STAGING_CONFIG = {
|
|
|
156
159
|
[SupportedChainId.PLASMA]: `${STAGING_BASE_URL}/plasma`,
|
|
157
160
|
[SupportedChainId.INK]: `${STAGING_BASE_URL}/ink`
|
|
158
161
|
};
|
|
162
|
+
var ORDER_BOOK_PARTNER_PROD_CONFIG = {
|
|
163
|
+
[SupportedChainId.MAINNET]: `${PARTNER_PROD_BASE_URL}/mainnet`,
|
|
164
|
+
[SupportedChainId.GNOSIS_CHAIN]: `${PARTNER_PROD_BASE_URL}/xdai`,
|
|
165
|
+
[SupportedChainId.ARBITRUM_ONE]: `${PARTNER_PROD_BASE_URL}/arbitrum_one`,
|
|
166
|
+
[SupportedChainId.BASE]: `${PARTNER_PROD_BASE_URL}/base`,
|
|
167
|
+
[SupportedChainId.SEPOLIA]: `${PARTNER_PROD_BASE_URL}/sepolia`,
|
|
168
|
+
[SupportedChainId.POLYGON]: `${PARTNER_PROD_BASE_URL}/polygon`,
|
|
169
|
+
[SupportedChainId.AVALANCHE]: `${PARTNER_PROD_BASE_URL}/avalanche`,
|
|
170
|
+
[SupportedChainId.LENS]: `${PARTNER_PROD_BASE_URL}/lens`,
|
|
171
|
+
[SupportedChainId.BNB]: `${PARTNER_PROD_BASE_URL}/bnb`,
|
|
172
|
+
[SupportedChainId.LINEA]: `${PARTNER_PROD_BASE_URL}/linea`,
|
|
173
|
+
[SupportedChainId.PLASMA]: `${PARTNER_PROD_BASE_URL}/plasma`,
|
|
174
|
+
[SupportedChainId.INK]: `${PARTNER_PROD_BASE_URL}/ink`
|
|
175
|
+
};
|
|
176
|
+
var ORDER_BOOK_PARTNER_STAGING_CONFIG = {
|
|
177
|
+
[SupportedChainId.MAINNET]: `${PARTNER_STAGING_BASE_URL}/mainnet`,
|
|
178
|
+
[SupportedChainId.GNOSIS_CHAIN]: `${PARTNER_STAGING_BASE_URL}/xdai`,
|
|
179
|
+
[SupportedChainId.ARBITRUM_ONE]: `${PARTNER_STAGING_BASE_URL}/arbitrum_one`,
|
|
180
|
+
[SupportedChainId.BASE]: `${PARTNER_STAGING_BASE_URL}/base`,
|
|
181
|
+
[SupportedChainId.SEPOLIA]: `${PARTNER_STAGING_BASE_URL}/sepolia`,
|
|
182
|
+
[SupportedChainId.POLYGON]: `${PARTNER_STAGING_BASE_URL}/polygon`,
|
|
183
|
+
[SupportedChainId.AVALANCHE]: `${PARTNER_STAGING_BASE_URL}/avalanche`,
|
|
184
|
+
[SupportedChainId.LENS]: `${PARTNER_STAGING_BASE_URL}/lens`,
|
|
185
|
+
[SupportedChainId.BNB]: `${PARTNER_STAGING_BASE_URL}/bnb`,
|
|
186
|
+
[SupportedChainId.LINEA]: `${PARTNER_STAGING_BASE_URL}/linea`,
|
|
187
|
+
[SupportedChainId.PLASMA]: `${PARTNER_STAGING_BASE_URL}/plasma`,
|
|
188
|
+
[SupportedChainId.INK]: `${PARTNER_STAGING_BASE_URL}/ink`
|
|
189
|
+
};
|
|
159
190
|
function cleanObjectFromUndefinedValues(obj) {
|
|
160
191
|
return Object.keys(obj).reduce(
|
|
161
192
|
(acc, key) => {
|
|
@@ -381,8 +412,8 @@ var OrderBookApi = class {
|
|
|
381
412
|
* @returns The API endpoint to get the order.
|
|
382
413
|
*/
|
|
383
414
|
getOrderLink(orderUid, contextOverride) {
|
|
384
|
-
const
|
|
385
|
-
return this.getApiBaseUrls(
|
|
415
|
+
const context = this.getContextWithOverride(contextOverride ?? {});
|
|
416
|
+
return this.getApiBaseUrls(context)[context.chainId] + `/api/v1/orders/${orderUid}`;
|
|
386
417
|
}
|
|
387
418
|
/**
|
|
388
419
|
* Apply an override to the context for a request.
|
|
@@ -393,14 +424,18 @@ var OrderBookApi = class {
|
|
|
393
424
|
return { ...this.context, ...contextOverride };
|
|
394
425
|
}
|
|
395
426
|
/**
|
|
396
|
-
* Get the base URLs for the API endpoints given the
|
|
397
|
-
*
|
|
427
|
+
* Get the base URLs for the API endpoints given the context.
|
|
428
|
+
* Uses partner URLs when apiKey is set (and no custom baseUrls override).
|
|
429
|
+
* @param context The merged API context for the request.
|
|
398
430
|
* @returns The base URLs for the API endpoints.
|
|
399
431
|
*/
|
|
400
|
-
getApiBaseUrls(
|
|
401
|
-
if (
|
|
402
|
-
return
|
|
403
|
-
|
|
432
|
+
getApiBaseUrls(context) {
|
|
433
|
+
if (context.baseUrls)
|
|
434
|
+
return context.baseUrls;
|
|
435
|
+
if (context.apiKey) {
|
|
436
|
+
return context.env === "prod" ? ORDER_BOOK_PARTNER_PROD_CONFIG : ORDER_BOOK_PARTNER_STAGING_CONFIG;
|
|
437
|
+
}
|
|
438
|
+
return context.env === "prod" ? ORDER_BOOK_PROD_CONFIG : ORDER_BOOK_STAGING_CONFIG;
|
|
404
439
|
}
|
|
405
440
|
/**
|
|
406
441
|
* Make a request to the API.
|
|
@@ -409,12 +444,14 @@ var OrderBookApi = class {
|
|
|
409
444
|
* @returns The response from the API.
|
|
410
445
|
*/
|
|
411
446
|
fetch(params, contextOverride = {}) {
|
|
412
|
-
const
|
|
413
|
-
const
|
|
447
|
+
const context = this.getContextWithOverride(contextOverride);
|
|
448
|
+
const { chainId, backoffOpts: _backoffOpts, apiKey } = context;
|
|
449
|
+
const baseUrl = this.getApiBaseUrls(context)[chainId];
|
|
414
450
|
const backoffOpts = _backoffOpts || DEFAULT_BACKOFF_OPTIONS;
|
|
415
451
|
const rateLimiter = contextOverride.limiterOpts ? new RateLimiter(contextOverride.limiterOpts) : this.rateLimiter;
|
|
452
|
+
const additionalHeaders = apiKey ? { "X-API-Key": apiKey } : void 0;
|
|
416
453
|
log(`Fetching OrderBook API: ${baseUrl}${params.path}. Params: ${JSON.stringify(params, jsonWithBigintReplacer)}`);
|
|
417
|
-
return request(baseUrl, params, rateLimiter, backoffOpts);
|
|
454
|
+
return request(baseUrl, params, rateLimiter, backoffOpts, additionalHeaders);
|
|
418
455
|
}
|
|
419
456
|
};
|
|
420
457
|
|
|
@@ -737,6 +774,8 @@ export {
|
|
|
737
774
|
DEFAULT_BACKOFF_OPTIONS,
|
|
738
775
|
DEFAULT_LIMITER_OPTIONS,
|
|
739
776
|
EcdsaSigningScheme,
|
|
777
|
+
ORDER_BOOK_PARTNER_PROD_CONFIG,
|
|
778
|
+
ORDER_BOOK_PARTNER_STAGING_CONFIG,
|
|
740
779
|
ORDER_BOOK_PROD_CONFIG,
|
|
741
780
|
ORDER_BOOK_STAGING_CONFIG,
|
|
742
781
|
OnchainOrderData,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-order-book",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CowProtocol Order Book package",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"cross-fetch": "^3.2.0",
|
|
32
32
|
"exponential-backoff": "^3.1.2",
|
|
33
33
|
"limiter": "^3.0.0",
|
|
34
|
-
"@cowprotocol/sdk-config": "0.
|
|
35
|
-
"@cowprotocol/sdk-common": "0.6.
|
|
34
|
+
"@cowprotocol/sdk-config": "0.9.0",
|
|
35
|
+
"@cowprotocol/sdk-common": "0.6.3"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|