@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 +20 -9
- package/dist/api/cow/errors/OperatorError.d.ts +2 -2
- package/dist/api/cow/errors/QuoteError.d.ts +3 -3
- package/dist/api/cow/index.d.ts +1 -1
- package/dist/api/cow/types.d.ts +34 -1
- package/dist/api/cow-subgraph/graphql.d.ts +192 -132
- package/dist/api/cow-subgraph/index.d.ts +2 -1
- package/dist/api/metadata/index.d.ts +28 -1
- package/dist/api/metadata/types.d.ts +18 -0
- package/dist/appData.schema-0c8db23b.js +2 -0
- package/dist/appData.schema-0c8db23b.js.map +1 -0
- package/dist/appData.schema-412cbfbf.js +2 -0
- package/dist/appData.schema-412cbfbf.js.map +1 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +2 -2
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +2 -2
- package/dist/index.module.js.map +1 -1
- package/dist/utils/appData.d.ts +1 -2
- package/dist/utils/common.d.ts +3 -1
- package/dist/utils/ipfs.d.ts +2 -0
- package/dist/utils/sign.d.ts +1 -1
- package/package.json +7 -2
- package/dist/appData.schema-d44994e0.js +0 -2
- package/dist/appData.schema-d44994e0.js.map +0 -1
- package/dist/appData.schema-fb2df827.js +0 -2
- package/dist/appData.schema-fb2df827.js.map +0 -1
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 {
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
|
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?:
|
|
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:
|
|
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?:
|
|
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?:
|
|
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:
|
|
32
|
+
export declare function isValidQuoteError(error: unknown): error is GpQuoteError;
|
package/dist/api/cow/index.d.ts
CHANGED
|
@@ -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 '
|
|
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 {
|
package/dist/api/cow/types.d.ts
CHANGED
|
@@ -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
|
+
};
|