@cowprotocol/cow-sdk 0.0.9 → 0.0.12

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 CHANGED
@@ -166,12 +166,16 @@ const appDataDoc = cowSdk.metadataApi.generateAppDataDoc(
166
166
  }
167
167
  */
168
168
 
169
+ // Calculate appDataHash (and cidV0) for given doc without uploading to IPFS
170
+ // This operation is deterministic and can be used to know before the upload the actual hash
171
+ const { appDataHash, cidv0 } = await cowSdk.metadataApi.calculateAppDataHash(appDataDoc)
172
+
169
173
  // Upload AppDataDoc to IPFS (Pinata)
170
174
  const cowSdk = new CowSdk(4, {
171
175
  ipfs: { pinataApiKey: 'YOUR_PINATA_API_KEY', pinataApiSecret: 'YOUR_PINATA_API_SECRET' },
172
176
  })
173
177
 
174
- await cowSdk.metadataApi.uploadMetadataDocToIpfs(appDataDoc)
178
+ const uploadedAppDataHash = await cowSdk.metadataApi.uploadMetadataDocToIpfs(appDataDoc)
175
179
  /* 0x5ddb2c8207c10b96fac92cb934ef9ba004bc007a073c9e5b13edc422f209ed80 */
176
180
  ```
177
181
 
@@ -184,22 +188,29 @@ const chainId = 1 // Mainnet
184
188
  const cowSdk = new CowSdk(chainId)
185
189
 
186
190
  // Get Cow Protocol totals
187
- const { totals } = await cowSdk.cowSubgraphApi.getTotals()
188
- const { tokens, orders, traders, settlements, volumeUsd, volumeEth, feesUsd, feesEth } = totals
191
+ const { tokens, orders, traders, settlements, volumeUsd, volumeEth, feesUsd, feesEth } = await cowSdk.cowSubgraphApi.getTotals()
189
192
  console.log({ tokens, orders, traders, settlements, volumeUsd, volumeEth, feesUsd, feesEth })
190
193
 
194
+ // Get last 24 hours volume in usd
195
+ const { hourlyTotals } = await cowSdk.cowSubgraphApi.getLastHoursVolume(24)
196
+ console.log(hourlyTotals)
197
+
198
+ // Get last week volume in usd
199
+ const { dailyTotals } = await cowSdk.cowSubgraphApi.getLastDaysVolume(7)
200
+ console.log(dailyTotals)
201
+
191
202
  // Get the last 5 batches
192
203
  const query = `
193
- query LastBatches($n: Int!) {
194
- settlements(orderBy: timestamp, orderDirection: desc, first: $n) {
195
- txHash
196
- timestamp
204
+ query LastBatches($n: Int!) {
205
+ settlements(orderBy: firstTradeTimestamp, orderDirection: desc, first: $n) {
206
+ txHash
207
+ firstTradeTimestamp
208
+ }
197
209
  }
198
- }
199
210
  `
200
211
  const variables = { n: 5 }
201
212
  const response = await cowSdk.cowSubgraphApi.runQuery(query, variables)
202
- console.log(response.data.settlements)
213
+ console.log(response)
203
214
  ```
204
215
 
205
216
  ### Install Dependencies
@@ -3,7 +3,7 @@ declare type ApiActionType = 'get' | 'create' | 'delete';
3
3
  export interface ApiErrorObject {
4
4
  errorType: ApiErrorCodes;
5
5
  description: string;
6
- data?: any;
6
+ data?: unknown;
7
7
  }
8
8
  export declare enum ApiErrorCodes {
9
9
  DuplicateOrder = "DuplicateOrder",
@@ -59,5 +59,5 @@ export default class OperatorError extends CowError {
59
59
  static getErrorFromStatusCode(response: Response, action: 'create' | 'delete'): Promise<string>;
60
60
  constructor(apiError: ApiErrorObject);
61
61
  }
62
- export declare function isValidOperatorError(error: any): error is OperatorError;
62
+ export declare function isValidOperatorError(error: unknown): error is OperatorError;
63
63
  export {};
@@ -3,7 +3,7 @@ import { ApiErrorObject } from './OperatorError';
3
3
  export interface GpQuoteErrorObject {
4
4
  errorType: GpQuoteErrorCodes;
5
5
  description: string;
6
- data?: any;
6
+ data?: unknown;
7
7
  }
8
8
  export declare enum GpQuoteErrorCodes {
9
9
  UnsupportedToken = "UnsupportedToken",
@@ -23,10 +23,10 @@ export declare function mapOperatorErrorToQuoteError(error?: ApiErrorObject): Gp
23
23
  export default class GpQuoteError extends CowError {
24
24
  name: string;
25
25
  description: string;
26
- data?: any;
26
+ data?: unknown;
27
27
  static quoteErrorDetails: typeof GpQuoteErrorDetails;
28
28
  static getErrorMessage(response: Response): Promise<string>;
29
29
  static getErrorFromStatusCode(response: Response): Promise<string>;
30
30
  constructor(quoteError: GpQuoteErrorObject);
31
31
  }
32
- export declare function isValidQuoteError(error: any): error is GpQuoteError;
32
+ export declare function isValidQuoteError(error: unknown): error is GpQuoteError;
@@ -1,6 +1,6 @@
1
1
  import { SupportedChainId as ChainId } from '../../constants/chains';
2
2
  import { OrderCreation } from '../../utils/sign';
3
- import { FeeQuoteParams, PriceInformation, PriceQuoteParams, SimpleGetQuoteResponse } from '../../utils/price';
3
+ import { FeeQuoteParams, PriceInformation, PriceQuoteParams, SimpleGetQuoteResponse } from './types';
4
4
  import { GetOrdersParams, GetTradesParams, OrderCancellationParams, OrderID, OrderMetaData, ProfileData, TradeMetaData } from './types';
5
5
  import { Context } from '../../utils/context';
6
6
  export declare class CowApi {
@@ -1,4 +1,4 @@
1
- import { OrderKind } from '@gnosis.pm/gp-v2-contracts';
1
+ import { GetQuoteResponse, OrderKind } from '@gnosis.pm/gp-v2-contracts';
2
2
  import { SupportedChainId as ChainId } from '../../constants/chains';
3
3
  import { OrderCancellation, SigningSchemeValue } from '../../utils/sign';
4
4
  /**
@@ -71,3 +71,36 @@ export declare type ProfileData = {
71
71
  referralVolumeUsd: number;
72
72
  lastUpdated: string;
73
73
  };
74
+ export interface QuoteParams {
75
+ quoteParams: FeeQuoteParams;
76
+ fetchFee: boolean;
77
+ previousFee?: FeeInformation;
78
+ isPriceRefresh: boolean;
79
+ }
80
+ export interface FeeInformation {
81
+ expirationDate: string;
82
+ amount: string;
83
+ }
84
+ export interface PriceInformation {
85
+ token: string;
86
+ amount: string | null;
87
+ }
88
+ export declare type SimpleGetQuoteResponse = Pick<GetQuoteResponse, 'from'> & {
89
+ quote: Omit<GetQuoteResponse['quote'], 'sellAmount' | 'buyAmount' | 'feeAmount' | 'validTo'> & {
90
+ sellAmount: string;
91
+ buyAmount: string;
92
+ validTo: string;
93
+ feeAmount: string;
94
+ };
95
+ expiration: string;
96
+ };
97
+ export declare type FeeQuoteParams = Pick<OrderMetaData, 'sellToken' | 'buyToken' | 'kind'> & {
98
+ amount: string;
99
+ userAddress?: string | null;
100
+ receiver?: string | null;
101
+ validTo: number;
102
+ };
103
+ export declare type PriceQuoteParams = Omit<FeeQuoteParams, 'sellToken' | 'buyToken'> & {
104
+ baseToken: string;
105
+ quoteToken: string;
106
+ };