@cowprotocol/cow-sdk 1.0.2-RC.7 → 2.0.0-alpha.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 +11 -13
- package/package.json +28 -31
- package/dist/CowSdk.d.ts +0 -21
- package/dist/api/0x/error/index.d.ts +0 -21
- package/dist/api/0x/index.d.ts +0 -11
- package/dist/api/0x/types.d.ts +0 -87
- package/dist/api/0x/utils.d.ts +0 -17
- package/dist/api/base/index.d.ts +0 -27
- package/dist/api/cow/errors/OperatorError.d.ts +0 -63
- package/dist/api/cow/errors/QuoteError.d.ts +0 -32
- package/dist/api/cow/index.d.ts +0 -26
- package/dist/api/cow/transformOrder.d.ts +0 -2
- package/dist/api/cow/types.d.ts +0 -133
- package/dist/api/cow-subgraph/graphql.d.ts +0 -3195
- package/dist/api/cow-subgraph/index.d.ts +0 -23
- package/dist/api/cow-subgraph/queries.d.ts +0 -3
- package/dist/api/index.d.ts +0 -3
- package/dist/api/metadata/index.d.ts +0 -58
- package/dist/api/metadata/types.d.ts +0 -22
- package/dist/api/paraswap/constants.d.ts +0 -10
- package/dist/api/paraswap/error/index.d.ts +0 -10
- package/dist/api/paraswap/index.d.ts +0 -32
- package/dist/api/paraswap/types.d.ts +0 -19
- package/dist/api/paraswap/utils.d.ts +0 -19
- package/dist/constants/chains.d.ts +0 -6
- package/dist/constants/index.d.ts +0 -5
- package/dist/constants/tokens.d.ts +0 -5
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
- package/dist/index.modern.mjs +0 -29
- package/dist/index.modern.mjs.map +0 -1
- package/dist/index.module.js +0 -29
- package/dist/index.module.js.map +0 -1
- package/dist/types/index.d.ts +0 -15
- package/dist/types/sdk.d.ts +0 -39
- package/dist/types/utilities.d.ts +0 -5
- package/dist/utils/appData.d.ts +0 -3
- package/dist/utils/common.d.ts +0 -9
- package/dist/utils/context.d.ts +0 -42
- package/dist/utils/ipfs.d.ts +0 -10
- package/dist/utils/market.d.ts +0 -16
- package/dist/utils/sign.d.ts +0 -55
- package/dist/utils/tokens.d.ts +0 -2
package/README.md
CHANGED
|
@@ -73,7 +73,6 @@ The next sections will guide you through the process of creating a valid order.
|
|
|
73
73
|
> For a quick snippet with the full process on posting an order see the [Post an Order Example](./docs/post-order-example.ts).
|
|
74
74
|
|
|
75
75
|
### Enable tokens (token approval)
|
|
76
|
-
|
|
77
76
|
Because of the use of off-chain signing (meta-transactions), users will need to **Enable the sell token** before signed
|
|
78
77
|
orders can be considered as valid ones.
|
|
79
78
|
|
|
@@ -92,9 +91,10 @@ import { CowSdk, OrderKind } from '@cowprotocol/cow-sdk'
|
|
|
92
91
|
|
|
93
92
|
const mnemonic = 'fall dirt bread cactus...'
|
|
94
93
|
const wallet = Wallet.fromMnemonic(mnemonic)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
|
|
95
|
+
const cowSdk = new CowSdk(
|
|
96
|
+
100, { // Leaving chainId empty will default to MAINNET
|
|
97
|
+
signer: wallet // Provide a signer, so you can sign order
|
|
98
98
|
})
|
|
99
99
|
```
|
|
100
100
|
|
|
@@ -102,13 +102,13 @@ const cowSdk = new CowSdk(100, {
|
|
|
102
102
|
|
|
103
103
|
To create an order, you need to get a price/fee quote first:
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
* The SDK will give you easy access to the API, which returns the `Market Price` and the `Fee` for any given trade you intent to do.
|
|
106
|
+
* The returned `Market Price` is not strictly needed, you can use your own pricing logic.
|
|
107
|
+
* You can choose a price that is below this Market price (**Market Order**), or above Market Price (**Limit Order**).
|
|
108
|
+
* The `Fee` however is very important.
|
|
109
|
+
* It is the required amount in sell token the trader agrees on paying for executing the order onchain.
|
|
110
|
+
* Normally, its value is proportional to the current Gas Price of the network.
|
|
111
|
+
* This fee is never charged if you don't trade.
|
|
112
112
|
|
|
113
113
|
To get the quote, you simply specify the trade you intent to do:
|
|
114
114
|
|
|
@@ -192,7 +192,6 @@ const orderId = await cowSdk.cowApi.sendOrder({
|
|
|
192
192
|
```
|
|
193
193
|
|
|
194
194
|
### BONUS: Show link to Explorer
|
|
195
|
-
|
|
196
195
|
Once the order is posted, its good to allow to check the state of it.
|
|
197
196
|
|
|
198
197
|
One easy is to check in the CoW Explorer. You can create a CoW Explorer link if you have the `orderId`:
|
|
@@ -321,7 +320,6 @@ const uploadedAppDataHash = await cowSdk.metadataApi.uploadMetadataDocToIpfs(app
|
|
|
321
320
|
```
|
|
322
321
|
|
|
323
322
|
## Convert IPFS CIDv0 to AppData (and back)
|
|
324
|
-
|
|
325
323
|
Given an IPFS CIDv0 you can convert it to an `AppData`
|
|
326
324
|
|
|
327
325
|
```js
|
package/package.json
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/cow-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
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.mjs"
|
|
11
|
-
},
|
|
12
|
-
"types": "dist/index.d.ts",
|
|
13
5
|
"files": [
|
|
14
6
|
"/dist"
|
|
15
7
|
],
|
|
16
8
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
9
|
+
"prebuild": "rm -rf dist && yarn run codegen",
|
|
10
|
+
"build": "tsc --module commonjs",
|
|
11
|
+
"postbuild": "cp package.json dist && cp README.md dist",
|
|
12
|
+
"start:metadata": "tsc-watch --noClear -p ./tsconfig.json --onSuccess \"node ./dist/metadata/index.js\"",
|
|
13
|
+
"start:order-book": "tsc-watch --noClear -p ./tsconfig.json --onSuccess \"node ./dist/order-book/index.js\"",
|
|
14
|
+
"start:subgraph": "tsc-watch --noClear -p ./tsconfig.json --onSuccess \"node ./dist/subgraph/index.js\"",
|
|
19
15
|
"lint": "eslint src",
|
|
20
16
|
"format": "prettier --write \"src/**/*.+(ts|json)\"",
|
|
21
17
|
"test": "jest",
|
|
22
18
|
"test:coverage": "jest --coverage --json --outputFile=jest.results.json && cat ./coverage/lcov.info | coveralls",
|
|
23
|
-
"
|
|
19
|
+
"codegen": "npm run graphql:codegen && npm run swagger:codegen",
|
|
24
20
|
"prepublishOnly": "npm test && npm run lint",
|
|
25
|
-
"graphql:codegen": "graphql-codegen --config graphql-codegen.yml"
|
|
21
|
+
"graphql:codegen": "graphql-codegen --config graphql-codegen.yml",
|
|
22
|
+
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/fix/orderbook-openapi/crates/orderbook/openapi.yml --output src/order-book/generated --client fetch --name OrderBookClient"
|
|
26
23
|
},
|
|
27
24
|
"dependencies": {
|
|
28
25
|
"@cowprotocol/app-data": "^0.0.3-RC.0",
|
|
@@ -32,30 +29,31 @@
|
|
|
32
29
|
"graphql": "^16.3.0",
|
|
33
30
|
"graphql-request": "^4.3.0",
|
|
34
31
|
"ipfs-only-hash": "^4.0.0",
|
|
35
|
-
"
|
|
36
|
-
"multiformats": "^9.6.4",
|
|
37
|
-
"paraswap": "^5.2.0",
|
|
38
|
-
"paraswap-core": "^1.0.2"
|
|
32
|
+
"multiformats": "^9.6.4"
|
|
39
33
|
},
|
|
40
34
|
"devDependencies": {
|
|
41
35
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
42
36
|
"@babel/plugin-proposal-private-methods": "^7.18.6",
|
|
37
|
+
"@babel/preset-env": "^7.20.2",
|
|
43
38
|
"@babel/preset-typescript": "^7.18.6",
|
|
44
|
-
"@graphql-codegen/cli": "
|
|
45
|
-
"@graphql-codegen/typescript": "
|
|
46
|
-
"@graphql-codegen/typescript-operations": "^
|
|
47
|
-
"@types/jest": "^
|
|
48
|
-
"@
|
|
49
|
-
"@typescript-eslint/
|
|
39
|
+
"@graphql-codegen/cli": "3.0.0",
|
|
40
|
+
"@graphql-codegen/typescript": "3.0.0",
|
|
41
|
+
"@graphql-codegen/typescript-operations": "^3.0.0",
|
|
42
|
+
"@types/jest": "^29.4.0",
|
|
43
|
+
"@types/node": "^18.13.0",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
45
|
+
"@typescript-eslint/parser": "^5.51.0",
|
|
50
46
|
"babel-plugin-inline-import": "^3.0.0",
|
|
51
47
|
"coveralls": "^3.1.1",
|
|
52
|
-
"eslint": "^8.
|
|
53
|
-
"eslint-config-prettier": "^8.
|
|
54
|
-
"eslint-plugin-prettier": "^4.
|
|
55
|
-
"jest": "^
|
|
48
|
+
"eslint": "^8.33.0",
|
|
49
|
+
"eslint-config-prettier": "^8.6.0",
|
|
50
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
51
|
+
"jest": "^29.4.2",
|
|
56
52
|
"jest-fetch-mock": "^3.0.3",
|
|
57
|
-
"
|
|
58
|
-
"prettier": "^2.5.1"
|
|
53
|
+
"openapi-typescript-codegen": "^0.23.0",
|
|
54
|
+
"prettier": "^2.5.1",
|
|
55
|
+
"tsc-watch": "^6.0.0",
|
|
56
|
+
"typescript": "^4.9.5"
|
|
59
57
|
},
|
|
60
58
|
"jest": {
|
|
61
59
|
"automock": false,
|
|
@@ -64,8 +62,7 @@
|
|
|
64
62
|
"./setupTests.js"
|
|
65
63
|
],
|
|
66
64
|
"collectCoverageFrom": [
|
|
67
|
-
"src/**/*.{ts,tsx}"
|
|
68
|
-
"!src/api/cow/errors/*.{ts,tsx}"
|
|
65
|
+
"src/**/*.{ts,tsx}"
|
|
69
66
|
]
|
|
70
67
|
},
|
|
71
68
|
"keywords": [
|
package/dist/CowSdk.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Signer } from 'ethers';
|
|
2
|
-
import { CowApi, CowSubgraphApi, MetadataApi } from './api';
|
|
3
|
-
import { SupportedChainId as ChainId } from './constants/chains';
|
|
4
|
-
import { Context, CowContext } from './utils/context';
|
|
5
|
-
import { UnsignedOrder } from './utils/sign';
|
|
6
|
-
import { SdkOptions, ParaswapEnabled, ZeroXEnabled, OptionsWithApisEnabledStatus } from 'sdk';
|
|
7
|
-
export declare class CowSdk<T extends ChainId = ChainId, Opt extends SdkOptions = OptionsWithApisEnabledStatus> {
|
|
8
|
-
context: Context;
|
|
9
|
-
cowApi: CowApi;
|
|
10
|
-
metadataApi: MetadataApi;
|
|
11
|
-
cowSubgraphApi: CowSubgraphApi;
|
|
12
|
-
zeroXApi: ZeroXEnabled<Opt>;
|
|
13
|
-
paraswapApi: ParaswapEnabled<Opt>;
|
|
14
|
-
constructor(chainId?: T, cowContext?: CowContext, options?: Opt);
|
|
15
|
-
updateChainId: (chainId: ChainId) => void;
|
|
16
|
-
updateContext: (cowContext: CowContext, chainId?: ChainId) => Promise<void>;
|
|
17
|
-
signOrder(order: Omit<UnsignedOrder, 'appData'>): Promise<import("./utils/sign").SigningResult>;
|
|
18
|
-
signOrderCancellation(orderId: string): Promise<import("./utils/sign").SigningResult>;
|
|
19
|
-
_checkSigner(signer?: Signer | undefined): Signer;
|
|
20
|
-
}
|
|
21
|
-
export default CowSdk;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { CowError } from '../../../utils/common';
|
|
2
|
-
interface ValidationError {
|
|
3
|
-
field: string;
|
|
4
|
-
code: number;
|
|
5
|
-
reason: string;
|
|
6
|
-
}
|
|
7
|
-
export interface ZeroXErrorResponse {
|
|
8
|
-
code: number;
|
|
9
|
-
reason: string;
|
|
10
|
-
validationErrors?: ValidationError[];
|
|
11
|
-
}
|
|
12
|
-
export declare const logPrefix = "0x-sdk:";
|
|
13
|
-
export default class ZeroXError extends CowError {
|
|
14
|
-
name: string;
|
|
15
|
-
description: string;
|
|
16
|
-
message: string;
|
|
17
|
-
static getErrorMessage(response: Response): Promise<string>;
|
|
18
|
-
static getErrorFromStatusCode(response: Response): Promise<string>;
|
|
19
|
-
constructor(apiError: ZeroXErrorResponse);
|
|
20
|
-
}
|
|
21
|
-
export {};
|
package/dist/api/0x/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { SupportedChainId } from '../../constants/chains';
|
|
2
|
-
import BaseApi from '../base';
|
|
3
|
-
import { Options, PriceQuoteLegacyParams } from '../cow/types';
|
|
4
|
-
import { ZeroXOptions, ZeroXQuote } from './types';
|
|
5
|
-
export declare class ZeroXApi extends BaseApi {
|
|
6
|
-
ZEROX_OPTIONS: ZeroXOptions;
|
|
7
|
-
ZEROX_OPTIONS_URL: string;
|
|
8
|
-
constructor(chainId: SupportedChainId, options: Partial<ZeroXOptions> | undefined);
|
|
9
|
-
getQuote(params: PriceQuoteLegacyParams, options?: Options): Promise<ZeroXQuote | null>;
|
|
10
|
-
updateOptions({ affiliateAddressMap, excludedSources }: Partial<ZeroXOptions>): Promise<void>;
|
|
11
|
-
}
|
package/dist/api/0x/types.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { SupportedChainId } from '../../constants/chains';
|
|
2
|
-
interface GetSwapQuoteResponseLiquiditySource {
|
|
3
|
-
name: string;
|
|
4
|
-
proportion: string;
|
|
5
|
-
intermediateToken?: string;
|
|
6
|
-
hops?: string[];
|
|
7
|
-
}
|
|
8
|
-
interface ZeroXBaseQuote {
|
|
9
|
-
chainId: SupportedChainId;
|
|
10
|
-
price: string;
|
|
11
|
-
buyAmount: string;
|
|
12
|
-
sellAmount: string;
|
|
13
|
-
sources: GetSwapQuoteResponseLiquiditySource[];
|
|
14
|
-
gasPrice: string;
|
|
15
|
-
estimatedGas: string;
|
|
16
|
-
sellTokenToEthRate: string;
|
|
17
|
-
buyTokenToEthRate: string;
|
|
18
|
-
protocolFee: string;
|
|
19
|
-
minimumProtocolFee: string;
|
|
20
|
-
allowanceTarget?: string;
|
|
21
|
-
}
|
|
22
|
-
export interface ZeroXQuote extends ZeroXBaseQuote {
|
|
23
|
-
sellTokenAddress: string;
|
|
24
|
-
buyTokenAddress: string;
|
|
25
|
-
value: string;
|
|
26
|
-
gas: string;
|
|
27
|
-
}
|
|
28
|
-
export declare type ZeroXOptions = {
|
|
29
|
-
affiliateAddressMap: Partial<Record<number, string>>;
|
|
30
|
-
excludedSources: ERC20BridgeSource[];
|
|
31
|
-
};
|
|
32
|
-
export declare enum ERC20BridgeSource {
|
|
33
|
-
Native = "Native",
|
|
34
|
-
Uniswap = "Uniswap",
|
|
35
|
-
UniswapV2 = "Uniswap_V2",
|
|
36
|
-
Eth2Dai = "Eth2Dai",
|
|
37
|
-
Kyber = "Kyber",
|
|
38
|
-
Curve = "Curve",
|
|
39
|
-
LiquidityProvider = "LiquidityProvider",
|
|
40
|
-
MultiBridge = "MultiBridge",
|
|
41
|
-
Balancer = "Balancer",
|
|
42
|
-
BalancerV2 = "Balancer_V2",
|
|
43
|
-
Cream = "CREAM",
|
|
44
|
-
Bancor = "Bancor",
|
|
45
|
-
MakerPsm = "MakerPsm",
|
|
46
|
-
MStable = "mStable",
|
|
47
|
-
Mooniswap = "Mooniswap",
|
|
48
|
-
MultiHop = "MultiHop",
|
|
49
|
-
Shell = "Shell",
|
|
50
|
-
Swerve = "Swerve",
|
|
51
|
-
SnowSwap = "SnowSwap",
|
|
52
|
-
SushiSwap = "SushiSwap",
|
|
53
|
-
Dodo = "DODO",
|
|
54
|
-
DodoV2 = "DODO_V2",
|
|
55
|
-
CryptoCom = "CryptoCom",
|
|
56
|
-
Linkswap = "Linkswap",
|
|
57
|
-
KyberDmm = "KyberDMM",
|
|
58
|
-
Smoothy = "Smoothy",
|
|
59
|
-
Component = "Component",
|
|
60
|
-
Saddle = "Saddle",
|
|
61
|
-
XSigma = "xSigma",
|
|
62
|
-
UniswapV3 = "Uniswap_V3",
|
|
63
|
-
CurveV2 = "Curve_V2",
|
|
64
|
-
Lido = "Lido",
|
|
65
|
-
ShibaSwap = "ShibaSwap",
|
|
66
|
-
Clipper = "Clipper",
|
|
67
|
-
PancakeSwap = "PancakeSwap",
|
|
68
|
-
PancakeSwapV2 = "PancakeSwap_V2",
|
|
69
|
-
BakerySwap = "BakerySwap",
|
|
70
|
-
Nerve = "Nerve",
|
|
71
|
-
Belt = "Belt",
|
|
72
|
-
Ellipsis = "Ellipsis",
|
|
73
|
-
ApeSwap = "ApeSwap",
|
|
74
|
-
CafeSwap = "CafeSwap",
|
|
75
|
-
CheeseSwap = "CheeseSwap",
|
|
76
|
-
JulSwap = "JulSwap",
|
|
77
|
-
ACryptos = "ACryptoS",
|
|
78
|
-
QuickSwap = "QuickSwap",
|
|
79
|
-
ComethSwap = "ComethSwap",
|
|
80
|
-
Dfyn = "Dfyn",
|
|
81
|
-
WaultSwap = "WaultSwap",
|
|
82
|
-
Polydex = "Polydex",
|
|
83
|
-
FirebirdOneSwap = "FirebirdOneSwap",
|
|
84
|
-
JetSwap = "JetSwap",
|
|
85
|
-
IronSwap = "IronSwap"
|
|
86
|
-
}
|
|
87
|
-
export {};
|
package/dist/api/0x/utils.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { OrderKind } from '@cowprotocol/contracts';
|
|
2
|
-
import { SupportedChainId } from '../../constants/chains';
|
|
3
|
-
import { PriceInformation, PriceQuoteLegacyParams } from '../cow/types';
|
|
4
|
-
import { ZeroXOptions, ZeroXQuote } from './types';
|
|
5
|
-
export declare function get0xUrls(): Partial<Record<SupportedChainId, string>>;
|
|
6
|
-
export declare function normaliseQuoteResponse(priceRaw: ZeroXQuote | null, kind: OrderKind): PriceInformation | null;
|
|
7
|
-
export declare function getMatchaChainId(chainId: SupportedChainId): SupportedChainId | null;
|
|
8
|
-
export declare function optionsToMatchaParamsUrl({ excludedSources, affiliateAddress, }: {
|
|
9
|
-
excludedSources: ZeroXOptions['excludedSources'];
|
|
10
|
-
affiliateAddress: string;
|
|
11
|
-
}): string;
|
|
12
|
-
export declare function handleQuoteResponse<T = unknown, P extends PriceQuoteLegacyParams = PriceQuoteLegacyParams>(response: Response, params?: P): Promise<T>;
|
|
13
|
-
export declare function throwOrReturnAffiliateAddress({ affiliateAddressMap, chainId, }: {
|
|
14
|
-
affiliateAddressMap: ZeroXOptions['affiliateAddressMap'];
|
|
15
|
-
chainId: SupportedChainId;
|
|
16
|
-
}): string;
|
|
17
|
-
export declare function extractExcludedSources({ excludedSources }: Pick<ZeroXOptions, 'excludedSources'>): string;
|
package/dist/api/base/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { SupportedChainId } from '../../constants/chains';
|
|
2
|
-
import { Context } from '../../utils/context';
|
|
3
|
-
import { Options } from '../cow/types';
|
|
4
|
-
interface ConstructorParams {
|
|
5
|
-
context: Context;
|
|
6
|
-
name: string;
|
|
7
|
-
apiVersion?: string;
|
|
8
|
-
getApiUrl: (...params: any[]) => Partial<Record<SupportedChainId, string>>;
|
|
9
|
-
defaultHeaders?: HeadersInit;
|
|
10
|
-
}
|
|
11
|
-
export default class BaseApi {
|
|
12
|
-
context: Context;
|
|
13
|
-
API_NAME: string;
|
|
14
|
-
API_VERSION: string;
|
|
15
|
-
API_URL_GETTER: (...params: any[]) => Partial<Record<SupportedChainId, string>>;
|
|
16
|
-
DEFAULT_HEADERS: HeadersInit;
|
|
17
|
-
constructor({ context, name, getApiUrl, defaultHeaders, apiVersion, }: ConstructorParams);
|
|
18
|
-
protected getApiBaseUrl(...params: unknown[]): Promise<string>;
|
|
19
|
-
protected post(url: string, data: unknown, options?: Options, onlySingleEnv?: boolean): Promise<Response>;
|
|
20
|
-
protected get(url: string, options?: Options): Promise<Response>;
|
|
21
|
-
protected delete(url: string, data: unknown, options?: Options): Promise<Response>;
|
|
22
|
-
protected fetchSingleEnv(url: string, method: 'GET' | 'POST' | 'DELETE', fetchFn: BaseApi['fetch'], getApiUrl: BaseApi['API_URL_GETTER'], options?: Options, data?: unknown): Promise<Response>;
|
|
23
|
-
protected fetchMultipleEnvs(url: string, method: 'GET' | 'POST' | 'DELETE', fetchFn: BaseApi['fetch'], getApiUrl: BaseApi['API_URL_GETTER'], options?: Options, data?: unknown): Promise<Response>;
|
|
24
|
-
protected fetch(url: string, method: 'GET' | 'POST' | 'DELETE', baseUrl: string, data?: unknown, requestOptions?: RequestInit): Promise<Response>;
|
|
25
|
-
private fetchMultipleEnvsRecursive;
|
|
26
|
-
}
|
|
27
|
-
export {};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { CowError } from '../../../utils/common';
|
|
2
|
-
declare type ApiActionType = 'get' | 'create' | 'delete';
|
|
3
|
-
export interface ApiErrorObject {
|
|
4
|
-
errorType: ApiErrorCodes;
|
|
5
|
-
description: string;
|
|
6
|
-
data?: unknown;
|
|
7
|
-
}
|
|
8
|
-
export declare enum ApiErrorCodes {
|
|
9
|
-
DuplicateOrder = "DuplicateOrder",
|
|
10
|
-
InvalidSignature = "InvalidSignature",
|
|
11
|
-
MissingOrderData = "MissingOrderData",
|
|
12
|
-
InsufficientValidTo = "InsufficientValidTo",
|
|
13
|
-
InsufficientAllowance = "InsufficientAllowance",
|
|
14
|
-
InsufficientBalance = "InsufficientBalance",
|
|
15
|
-
InsufficientFee = "InsufficientFee",
|
|
16
|
-
WrongOwner = "WrongOwner",
|
|
17
|
-
NotFound = "NotFound",
|
|
18
|
-
OrderNotFound = "OrderNotFound",
|
|
19
|
-
AlreadyCancelled = "AlreadyCancelled",
|
|
20
|
-
OrderFullyExecuted = "OrderFullyExecuted",
|
|
21
|
-
OrderExpired = "OrderExpired",
|
|
22
|
-
NoLiquidity = "NoLiquidity",
|
|
23
|
-
UnsupportedToken = "UnsupportedToken",
|
|
24
|
-
AmountIsZero = "AmountIsZero",
|
|
25
|
-
SellAmountDoesNotCoverFee = "SellAmountDoesNotCoverFee",
|
|
26
|
-
TransferEthToContract = "TransferEthToContract",
|
|
27
|
-
UNHANDLED_GET_ERROR = "UNHANDLED_GET_ERROR",
|
|
28
|
-
UNHANDLED_CREATE_ERROR = "UNHANDLED_CREATE_ERROR",
|
|
29
|
-
UNHANDLED_DELETE_ERROR = "UNHANDLED_DELETE_ERROR"
|
|
30
|
-
}
|
|
31
|
-
export declare enum ApiErrorCodeDetails {
|
|
32
|
-
DuplicateOrder = "There was another identical order already submitted. Please try again.",
|
|
33
|
-
InsufficientFee = "The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",
|
|
34
|
-
InvalidSignature = "The order signature is invalid. Check whether your Wallet app supports off-chain signing.",
|
|
35
|
-
MissingOrderData = "The order has missing information",
|
|
36
|
-
InsufficientValidTo = "The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.",
|
|
37
|
-
InsufficientAllowance = "The account doesn't have enough funds",
|
|
38
|
-
InsufficientBalance = "The account needs to approve the selling token in order to trade",
|
|
39
|
-
WrongOwner = "The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CowSwap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",
|
|
40
|
-
NotFound = "Not found",
|
|
41
|
-
OrderNotFound = "The order you are trying to cancel does not exist",
|
|
42
|
-
AlreadyCancelled = "Order is already cancelled",
|
|
43
|
-
OrderFullyExecuted = "Order is already filled",
|
|
44
|
-
OrderExpired = "Order is expired",
|
|
45
|
-
NoLiquidity = "Token pair selected has insufficient liquidity",
|
|
46
|
-
UnsupportedToken = "One of the tokens you are trading is unsupported. Please read the FAQ for more info.",
|
|
47
|
-
AmountIsZero = "Amount is zero",
|
|
48
|
-
SellAmountDoesNotCoverFee = "Sell amount does not sufficiently cover the current fee",
|
|
49
|
-
TransferEthToContract = "Sending the native currency to smart contract wallets is not currently supported",
|
|
50
|
-
UNHANDLED_GET_ERROR = "Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.",
|
|
51
|
-
UNHANDLED_CREATE_ERROR = "The order was not accepted by the network",
|
|
52
|
-
UNHANDLED_DELETE_ERROR = "The order cancellation was not accepted by the network"
|
|
53
|
-
}
|
|
54
|
-
export default class OperatorError extends CowError {
|
|
55
|
-
name: string;
|
|
56
|
-
description: ApiErrorObject['description'];
|
|
57
|
-
static apiErrorDetails: typeof ApiErrorCodeDetails;
|
|
58
|
-
static getErrorMessage(response: Response, action: ApiActionType): Promise<string>;
|
|
59
|
-
static getErrorFromStatusCode(response: Response, action: 'create' | 'delete'): Promise<string>;
|
|
60
|
-
constructor(apiError: ApiErrorObject);
|
|
61
|
-
}
|
|
62
|
-
export declare function isValidOperatorError(error: unknown): error is OperatorError;
|
|
63
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { CowError } from '../../../utils/common';
|
|
2
|
-
import { ApiErrorObject } from './OperatorError';
|
|
3
|
-
export interface GpQuoteErrorObject {
|
|
4
|
-
errorType: GpQuoteErrorCodes;
|
|
5
|
-
description: string;
|
|
6
|
-
data?: unknown;
|
|
7
|
-
}
|
|
8
|
-
export declare enum GpQuoteErrorCodes {
|
|
9
|
-
UnsupportedToken = "UnsupportedToken",
|
|
10
|
-
InsufficientLiquidity = "InsufficientLiquidity",
|
|
11
|
-
FeeExceedsFrom = "FeeExceedsFrom",
|
|
12
|
-
ZeroPrice = "ZeroPrice",
|
|
13
|
-
UNHANDLED_ERROR = "UNHANDLED_ERROR"
|
|
14
|
-
}
|
|
15
|
-
export declare enum GpQuoteErrorDetails {
|
|
16
|
-
UnsupportedToken = "One of the tokens you are trading is unsupported. Please read the FAQ for more info.",
|
|
17
|
-
InsufficientLiquidity = "Token pair selected has insufficient liquidity",
|
|
18
|
-
FeeExceedsFrom = "Current fee exceeds entered \"from\" amount",
|
|
19
|
-
ZeroPrice = "Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.",
|
|
20
|
-
UNHANDLED_ERROR = "Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later."
|
|
21
|
-
}
|
|
22
|
-
export declare function mapOperatorErrorToQuoteError(error?: ApiErrorObject): GpQuoteErrorObject;
|
|
23
|
-
export default class GpQuoteError extends CowError {
|
|
24
|
-
name: string;
|
|
25
|
-
description: string;
|
|
26
|
-
data?: unknown;
|
|
27
|
-
static quoteErrorDetails: typeof GpQuoteErrorDetails;
|
|
28
|
-
static getErrorMessage(response: Response): Promise<string>;
|
|
29
|
-
static getErrorFromStatusCode(response: Response): Promise<string>;
|
|
30
|
-
constructor(quoteError: GpQuoteErrorObject);
|
|
31
|
-
}
|
|
32
|
-
export declare function isValidQuoteError(error: unknown): error is GpQuoteError;
|
package/dist/api/cow/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { QuoteQuery } from '@cowprotocol/contracts';
|
|
2
|
-
import { OrderCreation } from '../../utils/sign';
|
|
3
|
-
import { FeeQuoteParams, GetOrdersParams, GetTradesParams, Options, OrderCancellationParams, OrderID, OrderMetaData, PriceInformation, PriceQuoteLegacyParams, ProfileData, SimpleGetQuoteResponse, TradeMetaData } from './types';
|
|
4
|
-
import { Context } from '../../utils/context';
|
|
5
|
-
import BaseApi from '../base';
|
|
6
|
-
export declare class CowApi extends BaseApi {
|
|
7
|
-
constructor(context: Context);
|
|
8
|
-
getProfileData(address: string, options?: Options): Promise<ProfileData | null>;
|
|
9
|
-
getTrades(params: GetTradesParams, options?: Options): Promise<TradeMetaData[]>;
|
|
10
|
-
getOrders(params: GetOrdersParams, options?: Options): Promise<OrderMetaData[]>;
|
|
11
|
-
getTxOrders(txHash: string, options?: Options): Promise<OrderMetaData[]>;
|
|
12
|
-
getOrder(orderId: string, options?: Options): Promise<OrderMetaData | null>;
|
|
13
|
-
getPriceQuoteLegacy(params: PriceQuoteLegacyParams, options?: Options): Promise<PriceInformation | null>;
|
|
14
|
-
getQuoteLegacyParams(params: FeeQuoteParams, options?: Options): Promise<SimpleGetQuoteResponse>;
|
|
15
|
-
getQuote(params: QuoteQuery, options?: Options): Promise<SimpleGetQuoteResponse>;
|
|
16
|
-
sendSignedOrderCancellation(params: OrderCancellationParams, options?: Options): Promise<void>;
|
|
17
|
-
sendOrder(params: {
|
|
18
|
-
order: Omit<OrderCreation, 'appData'>;
|
|
19
|
-
owner: string;
|
|
20
|
-
}, options?: Options): Promise<OrderID>;
|
|
21
|
-
getOrderLink(orderId: OrderID): Promise<string>;
|
|
22
|
-
protected getApiBaseUrl(): Promise<string>;
|
|
23
|
-
private getProfile;
|
|
24
|
-
private mapNewToLegacyParams;
|
|
25
|
-
private fetchProfile;
|
|
26
|
-
}
|
package/dist/api/cow/types.d.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { GetQuoteResponse, OrderKind } from '@cowprotocol/contracts';
|
|
2
|
-
import { SupportedChainId as ChainId } from '../../constants/chains';
|
|
3
|
-
import { Env } from '../../utils/context';
|
|
4
|
-
import { OrderCancellation, SigningSchemeValue } from '../../utils/sign';
|
|
5
|
-
import type { StrictUnion } from '../../types/utilities';
|
|
6
|
-
/**
|
|
7
|
-
* Unique identifier for the order, calculated by keccak256(orderDigest, ownerAddress, validTo),
|
|
8
|
-
* where orderDigest = keccak256(orderStruct). bytes32.
|
|
9
|
-
*/
|
|
10
|
-
export declare type OrderID = string;
|
|
11
|
-
export declare type ApiOrderStatus = 'fulfilled' | 'expired' | 'cancelled' | 'presignaturePending' | 'open';
|
|
12
|
-
export declare type OrderClass = 'market' | 'limit' | 'liquidity';
|
|
13
|
-
export interface OrderDto {
|
|
14
|
-
creationDate: string;
|
|
15
|
-
owner: string;
|
|
16
|
-
uid: OrderID;
|
|
17
|
-
availableBalance: string;
|
|
18
|
-
executedBuyAmount: string;
|
|
19
|
-
executedSellAmount: string;
|
|
20
|
-
executedSellAmountBeforeFees: string;
|
|
21
|
-
executedFeeAmount: string;
|
|
22
|
-
executedSurplusFee: string | null;
|
|
23
|
-
invalidated: false;
|
|
24
|
-
sellToken: string;
|
|
25
|
-
buyToken: string;
|
|
26
|
-
sellAmount: string;
|
|
27
|
-
buyAmount: string;
|
|
28
|
-
validTo: number;
|
|
29
|
-
appData: number;
|
|
30
|
-
feeAmount: string;
|
|
31
|
-
kind: OrderKind;
|
|
32
|
-
class: OrderClass;
|
|
33
|
-
partiallyFillable: false;
|
|
34
|
-
signature: string;
|
|
35
|
-
signingScheme: SigningSchemeValue;
|
|
36
|
-
status: ApiOrderStatus;
|
|
37
|
-
receiver: string;
|
|
38
|
-
ethflowData?: EthFlowData;
|
|
39
|
-
onchainUser?: string;
|
|
40
|
-
}
|
|
41
|
-
export interface OrderMetaData extends OrderDto {
|
|
42
|
-
totalFee: string;
|
|
43
|
-
}
|
|
44
|
-
declare type EthFlowData = {
|
|
45
|
-
userValidTo: number;
|
|
46
|
-
isRefunded: boolean;
|
|
47
|
-
};
|
|
48
|
-
export interface TradeMetaData {
|
|
49
|
-
blockNumber: number;
|
|
50
|
-
logIndex: number;
|
|
51
|
-
orderUid: OrderID;
|
|
52
|
-
owner: string;
|
|
53
|
-
sellToken: string;
|
|
54
|
-
buyToken: string;
|
|
55
|
-
sellAmount: string;
|
|
56
|
-
buyAmount: string;
|
|
57
|
-
sellAmountBeforeFees: string;
|
|
58
|
-
txHash: string;
|
|
59
|
-
}
|
|
60
|
-
export interface UnsupportedToken {
|
|
61
|
-
[token: string]: {
|
|
62
|
-
address: string;
|
|
63
|
-
dateAdded: number;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
export declare type PaginationParams = {
|
|
67
|
-
limit?: number;
|
|
68
|
-
offset?: number;
|
|
69
|
-
};
|
|
70
|
-
export declare type OrderCancellationParams = {
|
|
71
|
-
chainId: ChainId;
|
|
72
|
-
cancellation: OrderCancellation;
|
|
73
|
-
owner: string;
|
|
74
|
-
};
|
|
75
|
-
export declare type GetOrdersParams = {
|
|
76
|
-
owner: string;
|
|
77
|
-
} & PaginationParams;
|
|
78
|
-
declare type WithOwner = {
|
|
79
|
-
owner: string;
|
|
80
|
-
};
|
|
81
|
-
declare type WithOrderId = {
|
|
82
|
-
orderId: string;
|
|
83
|
-
};
|
|
84
|
-
export declare type GetTradesParams = StrictUnion<WithOwner | WithOrderId>;
|
|
85
|
-
export declare type ProfileData = {
|
|
86
|
-
totalTrades: number;
|
|
87
|
-
totalReferrals: number;
|
|
88
|
-
tradeVolumeUsd: number;
|
|
89
|
-
referralVolumeUsd: number;
|
|
90
|
-
lastUpdated: string;
|
|
91
|
-
};
|
|
92
|
-
export interface QuoteParams {
|
|
93
|
-
quoteParams: FeeQuoteParams;
|
|
94
|
-
fetchFee: boolean;
|
|
95
|
-
previousFee?: FeeInformation;
|
|
96
|
-
isPriceRefresh: boolean;
|
|
97
|
-
}
|
|
98
|
-
export interface FeeInformation {
|
|
99
|
-
expirationDate: string;
|
|
100
|
-
amount: string;
|
|
101
|
-
}
|
|
102
|
-
export interface PriceInformation {
|
|
103
|
-
token: string;
|
|
104
|
-
amount: string | null;
|
|
105
|
-
quoteId?: number;
|
|
106
|
-
}
|
|
107
|
-
export declare type SimpleGetQuoteResponse = Pick<GetQuoteResponse, 'from'> & {
|
|
108
|
-
quote: Omit<GetQuoteResponse['quote'], 'sellAmount' | 'buyAmount' | 'feeAmount' | 'validTo'> & {
|
|
109
|
-
sellAmount: string;
|
|
110
|
-
buyAmount: string;
|
|
111
|
-
validTo: string;
|
|
112
|
-
feeAmount: string;
|
|
113
|
-
};
|
|
114
|
-
expiration: string;
|
|
115
|
-
id: number | null;
|
|
116
|
-
};
|
|
117
|
-
export declare type FeeQuoteParams = Pick<OrderMetaData, 'sellToken' | 'buyToken' | 'kind'> & {
|
|
118
|
-
amount: string;
|
|
119
|
-
userAddress?: string | null;
|
|
120
|
-
receiver?: string | null;
|
|
121
|
-
validTo: number;
|
|
122
|
-
};
|
|
123
|
-
export declare type PriceQuoteLegacyParams = Omit<FeeQuoteParams, 'sellToken' | 'buyToken'> & {
|
|
124
|
-
baseToken: string;
|
|
125
|
-
quoteToken: string;
|
|
126
|
-
};
|
|
127
|
-
export declare type Options = {
|
|
128
|
-
chainId?: ChainId;
|
|
129
|
-
env?: Env;
|
|
130
|
-
requestOptions?: RequestInit;
|
|
131
|
-
apiUrlGetterParams?: unknown[];
|
|
132
|
-
};
|
|
133
|
-
export {};
|