@cowprotocol/cow-sdk 0.0.1 → 0.0.9

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.
Files changed (44) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +201 -7
  4. package/dist/CowSdk.d.ts +23 -0
  5. package/dist/api/cow/errors/OperatorError.d.ts +63 -0
  6. package/dist/api/cow/errors/QuoteError.d.ts +32 -0
  7. package/dist/api/cow/index.d.ts +38 -0
  8. package/dist/api/cow/types.d.ts +73 -0
  9. package/dist/api/cow-subgraph/graphql.d.ts +2576 -0
  10. package/dist/api/cow-subgraph/index.d.ts +17 -0
  11. package/dist/api/cow-subgraph/queries.d.ts +3 -0
  12. package/dist/api/index.d.ts +3 -0
  13. package/dist/api/metadata/index.d.ts +11 -0
  14. package/dist/api/metadata/types.d.ts +15 -0
  15. package/dist/appData.schema-d44994e0.js +2 -0
  16. package/dist/appData.schema-d44994e0.js.map +1 -0
  17. package/dist/appData.schema-fb2df827.js +2 -0
  18. package/dist/appData.schema-fb2df827.js.map +1 -0
  19. package/dist/constants/chains.d.ts +6 -0
  20. package/dist/constants/index.d.ts +4 -0
  21. package/dist/constants/tokens.d.ts +5 -0
  22. package/dist/index.d.ts +5 -0
  23. package/dist/index.js +29 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/index.modern.js +29 -0
  26. package/dist/index.modern.js.map +1 -0
  27. package/dist/index.module.js +29 -0
  28. package/dist/index.module.js.map +1 -0
  29. package/dist/types/index.d.ts +8 -0
  30. package/dist/utils/appData.d.ts +10 -0
  31. package/dist/utils/common.d.ts +7 -0
  32. package/dist/utils/context.d.ts +39 -0
  33. package/dist/utils/ipfs.d.ts +8 -0
  34. package/dist/utils/sign.d.ts +54 -0
  35. package/dist/utils/tokens.d.ts +2 -0
  36. package/package.json +61 -16
  37. package/babel.config.js +0 -6
  38. package/docs/images/CoW.png +0 -0
  39. package/src/CowSdk.ts +0 -10
  40. package/src/index.ts +0 -1
  41. package/src/schemas/appData.schema.json +0 -86
  42. package/src/utils/appData.spec.ts +0 -68
  43. package/src/utils/appData.ts +0 -34
  44. package/tsconfig.json +0 -11
@@ -0,0 +1,54 @@
1
+ import { Order, OrderCancellation as OrderCancellationGp, SigningScheme } from '@gnosis.pm/gp-v2-contracts';
2
+ import { SupportedChainId as ChainId } from '../constants/chains';
3
+ import { Signer } from '@ethersproject/abstract-signer';
4
+ export declare type UnsignedOrder = Omit<Order, 'receiver'> & {
5
+ receiver: string;
6
+ };
7
+ export interface SignOrderParams {
8
+ chainId: ChainId;
9
+ signer: Signer;
10
+ order: UnsignedOrder;
11
+ signingScheme: SigningScheme;
12
+ }
13
+ export interface OrderCreation extends UnsignedOrder {
14
+ signingScheme: SigningScheme;
15
+ signature: string;
16
+ }
17
+ export interface SingOrderCancellationParams {
18
+ chainId: ChainId;
19
+ signer: Signer;
20
+ orderId: string;
21
+ signingScheme: SigningScheme;
22
+ }
23
+ export interface OrderCancellation extends OrderCancellationGp {
24
+ signature: string;
25
+ signingScheme: SigningScheme;
26
+ }
27
+ export declare type SigningSchemeValue = 'eip712' | 'ethsign' | 'eip1271' | 'presign';
28
+ export declare function getSigningSchemeApiValue(ecdaSigningScheme: SigningScheme): string;
29
+ export declare function getSigningSchemeLibValue(ecdaSigningScheme: SigningScheme): number;
30
+ export declare type SigningResult = {
31
+ signature: string;
32
+ signingScheme: SigningScheme;
33
+ };
34
+ /**
35
+ * Returns the signature for the specified order with the signing scheme encoded
36
+ * into the signature.
37
+ * @export
38
+ * @param {UnsignedOrder} order The order to sign.
39
+ * @param {ChainId} chainId The chain Id
40
+ * @param {Signer} signer The owner for the order used to sign.
41
+ * @return {*} Encoded signature including signing scheme for the order.
42
+ */
43
+ export declare function signOrder(order: UnsignedOrder, chainId: ChainId, signer: Signer): Promise<SigningResult>;
44
+ /**
45
+ * Returns the signature for the Order Cancellation with the signing scheme encoded
46
+ * into the signature.
47
+ *
48
+ * @export
49
+ * @param {string} orderId The unique identifier of the order being cancelled.
50
+ * @param {ChainId} chainId The chain Id
51
+ * @param {Signer} signer The owner for the order used to sign.
52
+ * @return {*} Encoded signature including signing scheme for the order.
53
+ */
54
+ export declare function signOrderCancellation(orderId: string, chainId: ChainId, signer: Signer): Promise<SigningResult>;
@@ -0,0 +1,2 @@
1
+ import { SupportedChainId as ChainId } from '../constants/chains';
2
+ export declare function toErc20Address(tokenAddress: string, chainId: ChainId): string;
package/package.json CHANGED
@@ -1,25 +1,70 @@
1
1
  {
2
2
  "name": "@cowprotocol/cow-sdk",
3
- "version": "0.0.1",
4
- "license": "MIT",
3
+ "version": "0.0.9",
4
+ "license": "(MIT OR Apache-2.0)",
5
+ "source": "src/index.ts",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.module.js",
8
+ "exports": {
9
+ "require": "./dist/index.js",
10
+ "default": "./dist/index.modern.js"
11
+ },
12
+ "types": "dist/index.d.ts",
13
+ "files": [
14
+ "/dist"
15
+ ],
16
+ "scripts": {
17
+ "build": "microbundle -f modern,esm,cjs",
18
+ "start": "microbundle -f modern,esm,cjs watch",
19
+ "lint": "eslint src",
20
+ "format": "prettier --write \"src/**/*.+(ts|json)\"",
21
+ "test": "jest",
22
+ "test:coverage": "jest --coverage --json --outputFile=jest.results.json && cat ./coverage/lcov.info | coveralls",
23
+ "prepare": "npm run build && npm run graphql:codegen",
24
+ "prepublishOnly": "npm test && npm run lint",
25
+ "graphql:codegen": "graphql-codegen --config graphql-codegen.yml"
26
+ },
27
+ "dependencies": {
28
+ "@gnosis.pm/gp-v2-contracts": "^1.1.2",
29
+ "ajv": "^8.8.2",
30
+ "cross-fetch": "^3.1.5",
31
+ "ethers": "^5.5.3",
32
+ "graphql": "^16.3.0",
33
+ "graphql-request": "^4.1.0",
34
+ "loglevel": "^1.8.0",
35
+ "multiformats": "^9.6.4"
36
+ },
5
37
  "devDependencies": {
38
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
6
39
  "@babel/preset-typescript": "^7.16.0",
40
+ "@graphql-codegen/cli": "2.6.2",
41
+ "@graphql-codegen/typescript": "2.4.8",
42
+ "@graphql-codegen/typescript-operations": "^2.3.5",
7
43
  "@types/jest": "^27.0.3",
44
+ "@typescript-eslint/eslint-plugin": "^5.9.0",
45
+ "@typescript-eslint/parser": "^5.9.0",
46
+ "coveralls": "^3.1.1",
47
+ "eslint": "^8.6.0",
48
+ "eslint-config-prettier": "^8.3.0",
49
+ "eslint-plugin-prettier": "^4.0.0",
8
50
  "jest": "^27.3.1",
9
- "microbundle": "^0.14.2"
51
+ "jest-fetch-mock": "^3.0.3",
52
+ "microbundle": "^0.14.2",
53
+ "prettier": "^2.5.1"
10
54
  },
11
- "source": "src/index.ts",
12
- "exports": {
13
- "require": "./dist/cow-sdk.cjs",
14
- "default": "./dist/cow-sdk.modern.js"
15
- },
16
- "main": "./dist/cow-sdk.cjs",
17
- "module": "./dist/cow-sdk.module.js",
18
- "unpkg": "./dist/cow-sdk.umd.js",
19
- "scripts": {
20
- "build": "microbundle",
21
- "start": "microbundle watch",
22
- "test": "jest"
55
+ "jest": {
56
+ "automock": false,
57
+ "resetMocks": false,
58
+ "setupFiles": [
59
+ "./setupTests.js"
60
+ ]
23
61
  },
24
- "types": "dist/index.d.ts"
62
+ "keywords": [
63
+ "cow",
64
+ "cow-protocol",
65
+ "sdk",
66
+ "crypto",
67
+ "typescript",
68
+ "subgraph"
69
+ ]
25
70
  }
package/babel.config.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- ['@babel/preset-env', {targets: {node: 'current'}}],
4
- '@babel/preset-typescript',
5
- ],
6
- };
Binary file
package/src/CowSdk.ts DELETED
@@ -1,10 +0,0 @@
1
- import { version as SDK_VERSION } from '../package.json'
2
- import { validateAppDataDocument } from './utils/appData'
3
-
4
- export class CowSdk {
5
- static version = SDK_VERSION
6
-
7
- validateAppDataDocument = validateAppDataDocument
8
- }
9
-
10
- export default CowSdk
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './CowSdk'
@@ -1,86 +0,0 @@
1
- {
2
- "$id": "https://cowswap.exchange/appdata.schema.json",
3
- "$schema": "http://json-schema.org/draft-07/schema",
4
- "description": "Metadata JSON document for adding information to orders.",
5
- "required": [
6
- "version",
7
- "metadata"
8
- ],
9
- "title": "AppData Root Schema",
10
- "type": "object",
11
- "properties": {
12
- "version": {
13
- "$id": "#/properties/version",
14
- "description": "Semantic versioning of document",
15
- "examples": [
16
- "1.0.0",
17
- "1.2.3"
18
- ],
19
- "title": "Semantic Versioning",
20
- "type": "string"
21
- },
22
- "appCode": {
23
- "$id": "#/properties/appCode",
24
- "description": "The code identifying the CLI, UI, service generating the order.",
25
- "examples": [
26
- "CowSwap"
27
- ],
28
- "title": "App Code",
29
- "type": "string"
30
- },
31
- "metadata": {
32
- "$id": "#/properties/metadata",
33
- "default": {},
34
- "description": "Each metadata will specify one aspect of the order.",
35
- "required": [],
36
- "title": "Metadata descriptors",
37
- "type": "object",
38
- "properties": {
39
- "referrer": {
40
- "$ref": "#/definitions/kindMetadata/referrer"
41
- }
42
- }
43
- }
44
- },
45
- "definitions": {
46
- "version": {
47
- "$id": "#/definitions/version",
48
- "description": "Semantic versioning of document",
49
- "examples": [
50
- "1.0.0",
51
- "1.2.3"
52
- ],
53
- "title": "Semantic Versioning",
54
- "type": "string"
55
- },
56
- "ethereumAddress": {
57
- "$id": "#/definitions/ethereumAddress",
58
- "pattern": "^0x[a-fA-F0-9]{40}$",
59
- "title": "Ethereum compatible address",
60
- "examples": [
61
- "0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9"
62
- ],
63
- "type": "string"
64
- },
65
- "kindMetadata": {
66
- "referrer": {
67
- "$id": "#/definitions/referrer",
68
- "required": [
69
- "version",
70
- "address"
71
- ],
72
- "title": "Referrer",
73
- "type": "object",
74
- "properties": {
75
- "version": {
76
- "$ref": "#/definitions/version"
77
- },
78
- "address": {
79
- "$ref": "#/definitions/ethereumAddress",
80
- "title": "Referrer address"
81
- }
82
- }
83
- }
84
- }
85
- }
86
- }
@@ -1,68 +0,0 @@
1
- import {validateAppDataDocument } from './appData'
2
-
3
- const VALID_RESULT = {
4
- result: true,
5
- }
6
-
7
- test('Valid minimal document', async () => {
8
- const validation = await validateAppDataDocument({
9
- "version": "0.1.0",
10
- "metadata": {}
11
- })
12
- expect(validation).toEqual(VALID_RESULT);
13
- });
14
-
15
- test('Valid minimal document + appCode', async () => {
16
- const validation = await validateAppDataDocument({
17
- "version": "0.1.0",
18
- "appCode": "MyApp",
19
- "metadata": {}
20
- })
21
- expect(validation).toEqual(VALID_RESULT);
22
- });
23
-
24
-
25
- test('Valid minimal document + appCode + referrer', async () => {
26
- const validation = await validateAppDataDocument({
27
- "version": "0.1.0",
28
- "appCode": "MyApp",
29
- "metadata": {
30
- "referrer": {
31
- "version": "0.1.0",
32
- "address": "0xFEB4acf3df3cDEA7399794D0869ef76A6EfAff52"
33
- }
34
- }
35
- })
36
- expect(validation).toEqual(VALID_RESULT);
37
- });
38
-
39
- test('Invalid: Bad referrer', async () => {
40
- const validation = await validateAppDataDocument({
41
- "version": "0.1.0",
42
- "appCode": "MyApp",
43
- "metadata": {
44
- "referrer": {
45
- "version": "0.1.0",
46
- "address": "this is not an ethereum address"
47
- }
48
- }
49
- })
50
- expect(validation.result).toBeFalsy();
51
- });
52
-
53
- test('Invalid: No version', async () => {
54
- const validation = await validateAppDataDocument({
55
- "appCode": "MyApp",
56
- "metadata": {}
57
- })
58
- expect(validation.result).toBeFalsy();
59
- });
60
-
61
-
62
- test('Invalid: No metadata', async () => {
63
- const validation = await validateAppDataDocument({
64
- "version": "0.1.0",
65
- "appCode": "MyApp",
66
- })
67
- expect(validation.result).toBeFalsy();
68
- });
@@ -1,34 +0,0 @@
1
- import Ajv from 'ajv'
2
-
3
- let validate: Ajv.ValidateFunction | undefined
4
- let ajv: Ajv.Ajv
5
-
6
- interface ValidationResult {
7
- result: boolean,
8
- errors?: Ajv.ErrorObject[]
9
- }
10
-
11
- async function getValidator(): Promise<{ ajv: Ajv.Ajv, validate: Ajv.ValidateFunction }> {
12
- if (!ajv) {
13
- ajv = new Ajv()
14
- }
15
-
16
- if (!validate) {
17
- const appDataSchema = await import('../schemas/appData.schema.json');
18
- validate = ajv.compile(appDataSchema)
19
- }
20
-
21
-
22
- return { ajv, validate }
23
- }
24
-
25
- export async function validateAppDataDocument(appDataDocument: any): Promise<ValidationResult>{
26
- const { ajv, validate } = await getValidator()
27
- const result = !!(await validate(appDataDocument))
28
-
29
-
30
- return {
31
- result,
32
- errors: ajv.errors ?? undefined
33
- }
34
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "moduleResolution": "node",
4
- "module": "ESNext",
5
- "target": "ESNext",
6
- "strict": true,
7
- "alwaysStrict": true,
8
- "resolveJsonModule": true,
9
- "allowSyntheticDefaultImports": true
10
- },
11
- }