@cowprotocol/cow-sdk 5.10.2 → 5.11.0-RC.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 +2 -0
- package/dist/README.md +2 -0
- package/dist/bridging/BridgingSdk/BridgingSdk.d.ts +90 -0
- package/dist/bridging/BridgingSdk/getCrossChainOrder.d.ts +14 -0
- package/dist/bridging/BridgingSdk/getErc20Decimals.d.ts +4 -0
- package/dist/bridging/BridgingSdk/getQuoteWithBridging.d.ts +32 -0
- package/dist/bridging/BridgingSdk/getQuoteWithoutBridge.d.ts +7 -0
- package/dist/bridging/const.d.ts +2 -0
- package/dist/bridging/errors.d.ts +4 -0
- package/dist/bridging/index.d.ts +6 -0
- package/dist/bridging/providers/across/AcrossApi.d.ts +27 -0
- package/dist/bridging/providers/across/AcrossBridgeProvider.d.ts +43 -0
- package/dist/bridging/providers/across/abi.d.ts +154 -0
- package/dist/bridging/providers/across/const/contracts.d.ts +3 -0
- package/dist/bridging/providers/across/const/misc.d.ts +1 -0
- package/dist/bridging/providers/across/const/tokens.d.ts +11 -0
- package/dist/bridging/providers/across/createAcrossDepositCall.d.ts +9 -0
- package/dist/bridging/providers/across/types.d.ts +169 -0
- package/dist/bridging/providers/across/util.d.ts +39 -0
- package/dist/bridging/providers/mock/MockBridgeProvider.d.ts +21 -0
- package/dist/bridging/types.d.ts +287 -0
- package/dist/bridging/utils.d.ts +9 -0
- package/dist/chains/const/index.d.ts +25 -0
- package/dist/chains/const/path.d.ts +1 -0
- package/dist/chains/details/arbitrum.d.ts +7 -0
- package/dist/chains/details/avalanche.d.ts +2 -0
- package/dist/chains/details/base.d.ts +7 -0
- package/dist/chains/details/gnosis.d.ts +7 -0
- package/dist/chains/details/mainnet.d.ts +7 -0
- package/dist/chains/details/optimism.d.ts +2 -0
- package/dist/chains/details/polygon.d.ts +2 -0
- package/dist/chains/details/sepolia.d.ts +7 -0
- package/dist/chains/index.d.ts +3 -0
- package/dist/chains/types.d.ts +123 -0
- package/dist/chains/utils.d.ts +18 -0
- package/dist/common/consts/config.d.ts +9 -0
- package/dist/common/{consts.d.ts → consts/contracts.d.ts} +1 -12
- package/dist/common/consts/path.d.ts +1 -0
- package/dist/common/consts/tokens.d.ts +9 -0
- package/dist/common/index.d.ts +12 -5
- package/dist/common/{configs.d.ts → types/config.d.ts} +1 -9
- package/dist/common/{cow-error.d.ts → types/cow-error.d.ts} +0 -1
- package/dist/common/types/ethereum.d.ts +5 -0
- package/dist/common/types/tokens.d.ts +12 -0
- package/dist/common/types/wallets.d.ts +5 -0
- package/dist/common/utils/config.d.ts +4 -0
- package/dist/common/utils/log.d.ts +2 -0
- package/dist/common/utils/serialize.d.ts +1 -0
- package/dist/common/utils/wallet.d.ts +3 -0
- package/dist/composable/Multiplexer.d.ts +1 -1
- package/dist/composable/contracts.d.ts +1 -1
- package/dist/composable/types.d.ts +1 -1
- package/dist/composable/utils.d.ts +1 -1
- package/dist/cow-shed/CowShedSdk.d.ts +69 -0
- package/dist/cow-shed/{proxyInitCode.d.ts → contracts/CoWShedHooks.d.ts} +44 -0
- package/dist/cow-shed/contracts/utils.d.ts +4 -0
- package/dist/cow-shed/index.d.ts +2 -3
- package/dist/cow-shed/types.d.ts +0 -16
- package/dist/hooks/utils.d.ts +3 -0
- package/dist/index-ef9ef589.js +29 -0
- package/dist/index-ef9ef589.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.module.js +4 -4
- package/dist/index.module.js.map +1 -1
- package/dist/order-book/api.d.ts +1 -1
- package/dist/order-book/quoteAmountsAndCostsUtils.d.ts +13 -2
- package/dist/order-book/types.d.ts +54 -18
- package/dist/order-signing/orderSigningUtils.d.ts +1 -1
- package/dist/order-signing/types.d.ts +1 -1
- package/dist/order-signing/utils.d.ts +1 -1
- package/dist/package.json +13 -11
- package/dist/schemas/trading/LimitOrderAdvancedSettings.ts +26 -0
- package/dist/schemas/trading/LimitTradeParameters.ts +3 -0
- package/dist/schemas/trading/QuoteResultsSerialized.ts +21 -12
- package/dist/schemas/trading/QuoterParameters.ts +11 -1
- package/dist/schemas/trading/SwapAdvancedSettings.ts +206 -0
- package/dist/schemas/trading/TradeParameters.ts +3 -0
- package/dist/src/bridging/README.md +54 -0
- package/dist/src/cow-shed/README.md +60 -0
- package/dist/src/trading/README.md +55 -7
- package/dist/src/weiroll/README.md +58 -0
- package/dist/subgraph/api.d.ts +2 -2
- package/dist/test/utils.d.ts +1 -0
- package/dist/trading/appDataUtils.d.ts +2 -1
- package/dist/trading/calculateUniqueOrderId.d.ts +3 -4
- package/dist/trading/consts.d.ts +2 -4
- package/dist/trading/getEthFlowTransaction.d.ts +6 -5
- package/dist/trading/getOrderTypedData.d.ts +1 -1
- package/dist/trading/getPreSignTransaction.d.ts +2 -2
- package/dist/trading/getQuote.d.ts +1 -1
- package/dist/trading/postCoWProtocolTrade.d.ts +4 -4
- package/dist/trading/postLimitOrder.d.ts +2 -2
- package/dist/trading/postSellNativeCurrencyOrder.d.ts +2 -6
- package/dist/trading/postSwapOrder.d.ts +3 -3
- package/dist/trading/tradingSdk.d.ts +14 -11
- package/dist/trading/types.d.ts +73 -11
- package/dist/trading/utils.d.ts +8 -4
- package/dist/utils-757fe114.js +2 -0
- package/dist/utils-757fe114.js.map +1 -0
- package/dist/utils-9a7618d8.js +2 -0
- package/dist/utils-9a7618d8.js.map +1 -0
- package/dist/utils-f4151c05.js +2 -0
- package/dist/utils-f4151c05.js.map +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/weiroll/index.d.ts +23 -0
- package/package.json +13 -11
- package/dist/common/chains.d.ts +0 -11
- package/dist/cow-shed/CoWShedHooks.d.ts +0 -35
- package/dist/cow-shed/contracts.d.ts +0 -4
- package/dist/index-2ed223c8.js +0 -29
- package/dist/index-2ed223c8.js.map +0 -1
- package/dist/utils-4bdd94dd.js +0 -2
- package/dist/utils-4bdd94dd.js.map +0 -1
- package/dist/utils-63156cab.js +0 -2
- package/dist/utils-63156cab.js.map +0 -1
- package/dist/utils-faedc0ab.js +0 -2
- package/dist/utils-faedc0ab.js.map +0 -1
- /package/dist/common/{ipfs.d.ts → consts/ipfs.d.ts} +0 -0
package/dist/order-book/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'cross-fetch/polyfill';
|
|
2
|
-
import { ApiBaseUrls, ApiContext, PartialApiContext } from '../common/
|
|
2
|
+
import { ApiBaseUrls, ApiContext, PartialApiContext } from '../common/types/config';
|
|
3
3
|
import { Address, AppDataHash, AppDataObject, CompetitionOrderStatus, NativePriceResponse, OrderCancellations, OrderCreation, OrderQuoteRequest, OrderQuoteResponse, SolverCompetitionResponse, TotalSurplus, Trade, TransactionHash, UID } from './generated';
|
|
4
4
|
import { EnrichedOrder } from './types';
|
|
5
5
|
/**
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { QuoteAmountsAndCosts } from './types';
|
|
2
2
|
import { type OrderParameters } from './generated';
|
|
3
|
-
interface
|
|
3
|
+
export interface QuoteAmountsAndCostsParams {
|
|
4
4
|
orderParams: OrderParameters;
|
|
5
5
|
sellDecimals: number;
|
|
6
6
|
buyDecimals: number;
|
|
7
7
|
slippagePercentBps: number;
|
|
8
8
|
partnerFeeBps: number | undefined;
|
|
9
9
|
}
|
|
10
|
-
export declare function getQuoteAmountsAndCosts(params:
|
|
10
|
+
export declare function getQuoteAmountsAndCosts(params: QuoteAmountsAndCostsParams): QuoteAmountsAndCosts;
|
|
11
|
+
type BigNumber = {
|
|
12
|
+
big: bigint;
|
|
13
|
+
num: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* BigInt works well with subtraction and addition, but it's not very good with multiplication and division
|
|
17
|
+
* To multiply/divide token amounts we have to convert them to numbers, but we have to be careful with precision
|
|
18
|
+
* @param value
|
|
19
|
+
* @param decimals
|
|
20
|
+
*/
|
|
21
|
+
export declare function getBigNumber(value: string | bigint | number, decimals: number): BigNumber;
|
|
11
22
|
export {};
|
|
@@ -5,7 +5,23 @@ import { Order } from './generated';
|
|
|
5
5
|
export interface EnrichedOrder extends Order {
|
|
6
6
|
totalFee: string;
|
|
7
7
|
}
|
|
8
|
+
export interface Amounts<T> {
|
|
9
|
+
sellAmount: T;
|
|
10
|
+
buyAmount: T;
|
|
11
|
+
}
|
|
12
|
+
export interface Costs<T> {
|
|
13
|
+
networkFee: {
|
|
14
|
+
amountInSellCurrency: T;
|
|
15
|
+
amountInBuyCurrency: T;
|
|
16
|
+
};
|
|
17
|
+
partnerFee: {
|
|
18
|
+
amount: T;
|
|
19
|
+
bps: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
8
22
|
/**
|
|
23
|
+
* Details about costs and amounts, costs and fees of a quote.
|
|
24
|
+
*
|
|
9
25
|
* CoW Protocol quote has amounts (sell/buy) and costs (network fee), there is also partner fees.
|
|
10
26
|
* Besides that, CoW Protocol supports both sell and buy orders and the fees and costs are calculated differently.
|
|
11
27
|
*
|
|
@@ -16,23 +32,43 @@ export interface EnrichedOrder extends Order {
|
|
|
16
32
|
* For sell-orders the partner fee is subtracted from the buy amount after network costs.
|
|
17
33
|
* For buy-orders the partner fee is added on top of the sell amount after network costs.
|
|
18
34
|
*/
|
|
19
|
-
export interface QuoteAmountsAndCosts<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
35
|
+
export interface QuoteAmountsAndCosts<T = bigint> {
|
|
36
|
+
/**
|
|
37
|
+
* Whether the quote is a sell or buy order.
|
|
38
|
+
*/
|
|
23
39
|
isSell: boolean;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Estimated costs of settling the order.
|
|
42
|
+
*
|
|
43
|
+
* Costs are only payed if the order is executed. They cover the concept of gas costs to pay the solver for settling
|
|
44
|
+
* your order onchain for you.
|
|
45
|
+
*
|
|
46
|
+
* They are payed in the sell token although for convenience, the costs data includes also the buy token
|
|
47
|
+
* so UIs can decide how to show it to the user.
|
|
48
|
+
*/
|
|
49
|
+
costs: Costs<T>;
|
|
50
|
+
/**
|
|
51
|
+
* Amounts before network costs. This amount could be shown to the user to reflect how much they are expected to get
|
|
52
|
+
* before applying any costs or fees (if costs and fees are displayed separately).
|
|
53
|
+
*/
|
|
54
|
+
beforeNetworkCosts: Amounts<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Amounts after including network costs.
|
|
57
|
+
*/
|
|
58
|
+
afterNetworkCosts: Amounts<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Amounts after including partner fees (if any).
|
|
61
|
+
*
|
|
62
|
+
* This amount could be shown to the user, as the expected to receive amount already including any fees or costs.
|
|
63
|
+
*/
|
|
64
|
+
afterPartnerFees: Amounts<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Amounts after including the slippage tolerance.
|
|
67
|
+
*
|
|
68
|
+
* This is the minimum that the user will receive and the amount they will sign.
|
|
69
|
+
*
|
|
70
|
+
* It already accounts for all costs, fees and some slippage tolerance so they can execute the order even in the
|
|
71
|
+
* event of the buy token appreciating.
|
|
72
|
+
*/
|
|
73
|
+
afterSlippage: Amounts<T>;
|
|
38
74
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SupportedChainId } from '../
|
|
1
|
+
import type { SupportedChainId } from '../chains';
|
|
2
2
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
3
3
|
import type { Order, TypedDataDomain, OrderUidParams } from '@cowprotocol/contracts';
|
|
4
4
|
import type { SigningResult, UnsignedOrder } from './types';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TypedDataDomain, Order, OrderUidParams } from '@cowprotocol/contracts';
|
|
2
2
|
import type { Signer } from '@ethersproject/abstract-signer';
|
|
3
3
|
import type { SigningResult, UnsignedOrder } from './types';
|
|
4
|
-
import { SupportedChainId } from '../
|
|
4
|
+
import type { SupportedChainId } from '../chains';
|
|
5
5
|
/**
|
|
6
6
|
* Returns the signature for the specified order with the signing scheme encoded
|
|
7
7
|
* into the signature.
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/cow-sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.11.0-RC.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"files": [
|
|
6
6
|
"/dist"
|
|
@@ -33,13 +33,15 @@
|
|
|
33
33
|
"trading:generateSchemas": "ts-node scripts/generateTradingSchemas.ts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cowprotocol/app-data": "^
|
|
37
|
-
"@cowprotocol/contracts": "^1.
|
|
38
|
-
"@ethersproject/abstract-signer": "^5.
|
|
39
|
-
"@openzeppelin/merkle-tree": "^1.0.
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
36
|
+
"@cowprotocol/app-data": "^3.0.0",
|
|
37
|
+
"@cowprotocol/contracts": "^1.8.0",
|
|
38
|
+
"@ethersproject/abstract-signer": "^5.8.0",
|
|
39
|
+
"@openzeppelin/merkle-tree": "^1.0.8",
|
|
40
|
+
"@weiroll/weiroll.js": "^0.3.0",
|
|
41
|
+
"cross-fetch": "^3.2.0",
|
|
42
|
+
"deepmerge": "^4.3.1",
|
|
43
|
+
"exponential-backoff": "^3.1.2",
|
|
44
|
+
"graphql": "^16.11.0",
|
|
43
45
|
"graphql-request": "^4.3.0",
|
|
44
46
|
"limiter": "^3.0.0"
|
|
45
47
|
},
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
"@graphql-codegen/typescript": "3.0.0",
|
|
56
58
|
"@graphql-codegen/typescript-operations": "^3.0.0",
|
|
57
59
|
"@typechain/ethers-v5": "^11.0.0",
|
|
58
|
-
"@types/jest": "^29.
|
|
60
|
+
"@types/jest": "^29.5.14",
|
|
59
61
|
"@types/node": "^22.9.0",
|
|
60
62
|
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
61
63
|
"@typescript-eslint/parser": "^5.51.0",
|
|
@@ -66,8 +68,8 @@
|
|
|
66
68
|
"eslint-config-prettier": "^8.6.0",
|
|
67
69
|
"eslint-plugin-prettier": "^4.2.1",
|
|
68
70
|
"eslint-plugin-unused-imports": "^3.0.0",
|
|
69
|
-
"ethers": "^5.
|
|
70
|
-
"jest": "^29.
|
|
71
|
+
"ethers": "^5.8.0",
|
|
72
|
+
"jest": "^29.7.0",
|
|
71
73
|
"jest-fetch-mock": "^3.0.3",
|
|
72
74
|
"microbundle": "^0.15.1",
|
|
73
75
|
"openapi-typescript-codegen": "^0.23.0",
|
|
@@ -221,6 +221,32 @@ export default {
|
|
|
221
221
|
}
|
|
222
222
|
},
|
|
223
223
|
"additionalProperties": false
|
|
224
|
+
},
|
|
225
|
+
"additionalParams": {
|
|
226
|
+
"type": "object",
|
|
227
|
+
"properties": {
|
|
228
|
+
"checkEthFlowOrderExists": {
|
|
229
|
+
"type": "object",
|
|
230
|
+
"additionalProperties": false,
|
|
231
|
+
"description": "Selling native token orders are special, because they are created from smart-contract, and their validTo is always the same. Because of that, you might get the same orderId when trying to create an order with the same parameters The callback is needed to check if there is already an order with the same orderId"
|
|
232
|
+
},
|
|
233
|
+
"networkCostsAmount": {
|
|
234
|
+
"type": "string",
|
|
235
|
+
"description": "Cost of executing the order onchain. The value is used in getQuoteAmountsAndCosts in order to calculate proper amounts"
|
|
236
|
+
},
|
|
237
|
+
"signingScheme": {
|
|
238
|
+
"type": "string",
|
|
239
|
+
"enum": [
|
|
240
|
+
"eip712",
|
|
241
|
+
"ethsign",
|
|
242
|
+
"presign",
|
|
243
|
+
"eip1271"
|
|
244
|
+
],
|
|
245
|
+
"description": "By default, is EIP712 for EOA wallets. You might need other types of signing, for example PRESIGN when sign order via Smart Contract wallets."
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
"additionalProperties": false,
|
|
249
|
+
"description": "Additional parameters for posting orders. In most of the cases you don't need to use them."
|
|
224
250
|
}
|
|
225
251
|
},
|
|
226
252
|
"additionalProperties": false,
|
|
@@ -64,6 +64,9 @@ export default {
|
|
|
64
64
|
],
|
|
65
65
|
"description": "Is this order a buy or sell?"
|
|
66
66
|
},
|
|
67
|
+
"owner": {
|
|
68
|
+
"type": "string"
|
|
69
|
+
},
|
|
67
70
|
"sellToken": {
|
|
68
71
|
"type": "string",
|
|
69
72
|
"description": "ERC-20 token to be sold."
|
|
@@ -91,7 +94,7 @@ export default {
|
|
|
91
94
|
"sellToken",
|
|
92
95
|
"sellTokenDecimals"
|
|
93
96
|
],
|
|
94
|
-
"description": "
|
|
97
|
+
"description": "Information about the trade, including the kind of order, the owner, the sell and buy tokens, and the amount."
|
|
95
98
|
},
|
|
96
99
|
"orderToSign": {
|
|
97
100
|
"type": "object",
|
|
@@ -180,7 +183,7 @@ export default {
|
|
|
180
183
|
"sellToken",
|
|
181
184
|
"validTo"
|
|
182
185
|
],
|
|
183
|
-
"description": "
|
|
186
|
+
"description": "Information about the order to be signed.\n\nFor signining, please use orderTypedData (EIP-712 typed data, which also includes the unsigned order)"
|
|
184
187
|
},
|
|
185
188
|
"quoteResponse": {
|
|
186
189
|
"type": "object",
|
|
@@ -305,7 +308,7 @@ export default {
|
|
|
305
308
|
"verified"
|
|
306
309
|
],
|
|
307
310
|
"additionalProperties": false,
|
|
308
|
-
"description": "
|
|
311
|
+
"description": "Information about the quote response from the order book API."
|
|
309
312
|
},
|
|
310
313
|
"appDataInfo": {
|
|
311
314
|
"type": "object",
|
|
@@ -554,7 +557,7 @@ export default {
|
|
|
554
557
|
"appDataKeccak256"
|
|
555
558
|
],
|
|
556
559
|
"additionalProperties": false,
|
|
557
|
-
"description": "
|
|
560
|
+
"description": "Information about the app-data, including the JSON document and the keccak256 hash of the full document."
|
|
558
561
|
},
|
|
559
562
|
"orderTypedData": {
|
|
560
563
|
"type": "object",
|
|
@@ -708,13 +711,14 @@ export default {
|
|
|
708
711
|
"message"
|
|
709
712
|
],
|
|
710
713
|
"additionalProperties": false,
|
|
711
|
-
"description": "EIP-712 typed data for
|
|
714
|
+
"description": "EIP-712 typed data for the order ready to be signed."
|
|
712
715
|
},
|
|
713
716
|
"amountsAndCosts": {
|
|
714
717
|
"type": "object",
|
|
715
718
|
"properties": {
|
|
716
719
|
"isSell": {
|
|
717
|
-
"type": "boolean"
|
|
720
|
+
"type": "boolean",
|
|
721
|
+
"description": "Whether the quote is a sell or buy order."
|
|
718
722
|
},
|
|
719
723
|
"costs": {
|
|
720
724
|
"type": "object",
|
|
@@ -756,7 +760,8 @@ export default {
|
|
|
756
760
|
"networkFee",
|
|
757
761
|
"partnerFee"
|
|
758
762
|
],
|
|
759
|
-
"additionalProperties": false
|
|
763
|
+
"additionalProperties": false,
|
|
764
|
+
"description": "Estimated costs of settling the order.\n\nCosts are only payed if the order is executed. They cover the concept of gas costs to pay the solver for settling your order onchain for you.\n\nThey are payed in the sell token although for convenience, the costs data includes also the buy token so UIs can decide how to show it to the user."
|
|
760
765
|
},
|
|
761
766
|
"beforeNetworkCosts": {
|
|
762
767
|
"type": "object",
|
|
@@ -772,7 +777,8 @@ export default {
|
|
|
772
777
|
"sellAmount",
|
|
773
778
|
"buyAmount"
|
|
774
779
|
],
|
|
775
|
-
"additionalProperties": false
|
|
780
|
+
"additionalProperties": false,
|
|
781
|
+
"description": "Amounts before network costs. This amount could be shown to the user to reflect how much they are expected to get before applying any costs or fees (if costs and fees are displayed separately)."
|
|
776
782
|
},
|
|
777
783
|
"afterNetworkCosts": {
|
|
778
784
|
"type": "object",
|
|
@@ -788,7 +794,8 @@ export default {
|
|
|
788
794
|
"sellAmount",
|
|
789
795
|
"buyAmount"
|
|
790
796
|
],
|
|
791
|
-
"additionalProperties": false
|
|
797
|
+
"additionalProperties": false,
|
|
798
|
+
"description": "Amounts after including network costs."
|
|
792
799
|
},
|
|
793
800
|
"afterPartnerFees": {
|
|
794
801
|
"type": "object",
|
|
@@ -804,7 +811,8 @@ export default {
|
|
|
804
811
|
"sellAmount",
|
|
805
812
|
"buyAmount"
|
|
806
813
|
],
|
|
807
|
-
"additionalProperties": false
|
|
814
|
+
"additionalProperties": false,
|
|
815
|
+
"description": "Amounts after including partner fees (if any).\n\nThis amount could be shown to the user, as the expected to receive amount already including any fees or costs."
|
|
808
816
|
},
|
|
809
817
|
"afterSlippage": {
|
|
810
818
|
"type": "object",
|
|
@@ -820,7 +828,8 @@ export default {
|
|
|
820
828
|
"sellAmount",
|
|
821
829
|
"buyAmount"
|
|
822
830
|
],
|
|
823
|
-
"additionalProperties": false
|
|
831
|
+
"additionalProperties": false,
|
|
832
|
+
"description": "Amounts after including the slippage tolerance.\n\nThis is the minimum that the user will receive and the amount they will sign.\n\nIt already accounts for all costs, fees and some slippage tolerance so they can execute the order even in the event of the buy token appreciating."
|
|
824
833
|
}
|
|
825
834
|
},
|
|
826
835
|
"required": [
|
|
@@ -832,7 +841,7 @@ export default {
|
|
|
832
841
|
"afterSlippage"
|
|
833
842
|
],
|
|
834
843
|
"additionalProperties": false,
|
|
835
|
-
"description": "
|
|
844
|
+
"description": "Details about costs and amounts, costs and fees of a quote.\n\nCoW Protocol quote has amounts (sell/buy) and costs (network fee), there is also partner fees. Besides that, CoW Protocol supports both sell and buy orders and the fees and costs are calculated differently.\n\nThe order of adding fees and costs is as follows: 1. Network fee is always added to the sell amount 2. Partner fee is added to the surplus amount (sell amount for sell-orders, buy amount for buy-orders)\n\nFor sell-orders the partner fee is subtracted from the buy amount after network costs. For buy-orders the partner fee is added on top of the sell amount after network costs."
|
|
836
845
|
}
|
|
837
846
|
},
|
|
838
847
|
"required": [
|
|
@@ -13,13 +13,23 @@ export default {
|
|
|
13
13
|
100,
|
|
14
14
|
42161,
|
|
15
15
|
8453,
|
|
16
|
+
137,
|
|
17
|
+
43114,
|
|
16
18
|
11155111
|
|
17
19
|
],
|
|
18
|
-
"description": "Supported chains and their `chainId` for the SDK."
|
|
20
|
+
"description": "Supported chains and their `chainId` for the SDK.\n\nA supported chain, is a chain where CoW Protocol is deployed, so you can sell tokens from there."
|
|
19
21
|
},
|
|
20
22
|
"appCode": {
|
|
21
23
|
"type": "string",
|
|
22
24
|
"description": "The code identifying the CLI, UI, service generating the order."
|
|
25
|
+
},
|
|
26
|
+
"env": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"enum": [
|
|
29
|
+
"prod",
|
|
30
|
+
"staging"
|
|
31
|
+
],
|
|
32
|
+
"description": "The environment to use for the Cow API."
|
|
23
33
|
}
|
|
24
34
|
},
|
|
25
35
|
"required": [
|
|
@@ -327,6 +327,212 @@ export default {
|
|
|
327
327
|
}
|
|
328
328
|
},
|
|
329
329
|
"additionalProperties": false
|
|
330
|
+
},
|
|
331
|
+
"additionalParams": {
|
|
332
|
+
"type": "object",
|
|
333
|
+
"properties": {
|
|
334
|
+
"checkEthFlowOrderExists": {
|
|
335
|
+
"type": "object",
|
|
336
|
+
"additionalProperties": false,
|
|
337
|
+
"description": "Selling native token orders are special, because they are created from smart-contract, and their validTo is always the same. Because of that, you might get the same orderId when trying to create an order with the same parameters The callback is needed to check if there is already an order with the same orderId"
|
|
338
|
+
},
|
|
339
|
+
"networkCostsAmount": {
|
|
340
|
+
"type": "string",
|
|
341
|
+
"description": "Cost of executing the order onchain. The value is used in getQuoteAmountsAndCosts in order to calculate proper amounts"
|
|
342
|
+
},
|
|
343
|
+
"signingScheme": {
|
|
344
|
+
"type": "string",
|
|
345
|
+
"enum": [
|
|
346
|
+
"eip712",
|
|
347
|
+
"ethsign",
|
|
348
|
+
"presign",
|
|
349
|
+
"eip1271"
|
|
350
|
+
],
|
|
351
|
+
"description": "By default, is EIP712 for EOA wallets. You might need other types of signing, for example PRESIGN when sign order via Smart Contract wallets."
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
"additionalProperties": false,
|
|
355
|
+
"description": "Additional parameters for posting orders. In most of the cases you don't need to use them."
|
|
356
|
+
},
|
|
357
|
+
"quoteSigner": {
|
|
358
|
+
"anyOf": [
|
|
359
|
+
{
|
|
360
|
+
"type": "object",
|
|
361
|
+
"properties": {
|
|
362
|
+
"provider": {
|
|
363
|
+
"type": "object",
|
|
364
|
+
"properties": {
|
|
365
|
+
"_isProvider": {
|
|
366
|
+
"type": "boolean"
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
"required": [
|
|
370
|
+
"_isProvider"
|
|
371
|
+
],
|
|
372
|
+
"additionalProperties": false
|
|
373
|
+
},
|
|
374
|
+
"_isSigner": {
|
|
375
|
+
"type": "boolean"
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
"required": [
|
|
379
|
+
"_isSigner"
|
|
380
|
+
],
|
|
381
|
+
"additionalProperties": false
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
"type": "object",
|
|
385
|
+
"properties": {
|
|
386
|
+
"isMetaMask": {
|
|
387
|
+
"type": "boolean"
|
|
388
|
+
},
|
|
389
|
+
"isStatus": {
|
|
390
|
+
"type": "boolean"
|
|
391
|
+
},
|
|
392
|
+
"host": {
|
|
393
|
+
"type": "string"
|
|
394
|
+
},
|
|
395
|
+
"path": {
|
|
396
|
+
"type": "string"
|
|
397
|
+
},
|
|
398
|
+
"sendAsync": {
|
|
399
|
+
"$comment": "(request: {\n method: string;\n params?: Array<any>;\n }, callback: (error: any, response: any) => void) => void",
|
|
400
|
+
"type": "object",
|
|
401
|
+
"properties": {
|
|
402
|
+
"namedArgs": {
|
|
403
|
+
"type": "object",
|
|
404
|
+
"properties": {
|
|
405
|
+
"request": {
|
|
406
|
+
"type": "object",
|
|
407
|
+
"properties": {
|
|
408
|
+
"method": {
|
|
409
|
+
"type": "string"
|
|
410
|
+
},
|
|
411
|
+
"params": {
|
|
412
|
+
"type": "array",
|
|
413
|
+
"items": {}
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
"required": [
|
|
417
|
+
"method"
|
|
418
|
+
],
|
|
419
|
+
"additionalProperties": false
|
|
420
|
+
},
|
|
421
|
+
"callback": {
|
|
422
|
+
"$comment": "(error: any, response: any) => void",
|
|
423
|
+
"type": "object",
|
|
424
|
+
"properties": {
|
|
425
|
+
"namedArgs": {
|
|
426
|
+
"type": "object",
|
|
427
|
+
"properties": {
|
|
428
|
+
"error": {},
|
|
429
|
+
"response": {}
|
|
430
|
+
},
|
|
431
|
+
"required": [
|
|
432
|
+
"error",
|
|
433
|
+
"response"
|
|
434
|
+
],
|
|
435
|
+
"additionalProperties": false
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
"required": [
|
|
441
|
+
"request",
|
|
442
|
+
"callback"
|
|
443
|
+
],
|
|
444
|
+
"additionalProperties": false
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
"send": {
|
|
449
|
+
"$comment": "(request: {\n method: string;\n params?: Array<any>;\n }, callback: (error: any, response: any) => void) => void",
|
|
450
|
+
"type": "object",
|
|
451
|
+
"properties": {
|
|
452
|
+
"namedArgs": {
|
|
453
|
+
"type": "object",
|
|
454
|
+
"properties": {
|
|
455
|
+
"request": {
|
|
456
|
+
"type": "object",
|
|
457
|
+
"properties": {
|
|
458
|
+
"method": {
|
|
459
|
+
"type": "string"
|
|
460
|
+
},
|
|
461
|
+
"params": {
|
|
462
|
+
"type": "array",
|
|
463
|
+
"items": {}
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
"required": [
|
|
467
|
+
"method"
|
|
468
|
+
],
|
|
469
|
+
"additionalProperties": false
|
|
470
|
+
},
|
|
471
|
+
"callback": {
|
|
472
|
+
"$comment": "(error: any, response: any) => void",
|
|
473
|
+
"type": "object",
|
|
474
|
+
"properties": {
|
|
475
|
+
"namedArgs": {
|
|
476
|
+
"type": "object",
|
|
477
|
+
"properties": {
|
|
478
|
+
"error": {},
|
|
479
|
+
"response": {}
|
|
480
|
+
},
|
|
481
|
+
"required": [
|
|
482
|
+
"error",
|
|
483
|
+
"response"
|
|
484
|
+
],
|
|
485
|
+
"additionalProperties": false
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
"required": [
|
|
491
|
+
"request",
|
|
492
|
+
"callback"
|
|
493
|
+
],
|
|
494
|
+
"additionalProperties": false
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
"request": {
|
|
499
|
+
"$comment": "(request: {\n method: string;\n params?: Array<any>;\n }) => Promise<any>",
|
|
500
|
+
"type": "object",
|
|
501
|
+
"properties": {
|
|
502
|
+
"namedArgs": {
|
|
503
|
+
"type": "object",
|
|
504
|
+
"properties": {
|
|
505
|
+
"request": {
|
|
506
|
+
"type": "object",
|
|
507
|
+
"properties": {
|
|
508
|
+
"method": {
|
|
509
|
+
"type": "string"
|
|
510
|
+
},
|
|
511
|
+
"params": {
|
|
512
|
+
"type": "array",
|
|
513
|
+
"items": {}
|
|
514
|
+
}
|
|
515
|
+
},
|
|
516
|
+
"required": [
|
|
517
|
+
"method"
|
|
518
|
+
],
|
|
519
|
+
"additionalProperties": false
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
"required": [
|
|
523
|
+
"request"
|
|
524
|
+
],
|
|
525
|
+
"additionalProperties": false
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
"additionalProperties": false
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
"type": "string"
|
|
534
|
+
}
|
|
535
|
+
]
|
|
330
536
|
}
|
|
331
537
|
},
|
|
332
538
|
"additionalProperties": false,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Bridging SDK
|
|
2
|
+
|
|
3
|
+
SDK for swapping between chains.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { SupportedChainId, BridgingSdk, QuoteBridgeRequest, OrderKind, assertIsBridgeQuoteAndPost } from '@cowprotocol/cow-sdk'
|
|
9
|
+
|
|
10
|
+
const sdk = new BridgingSdk()
|
|
11
|
+
|
|
12
|
+
const parameters: QuoteBridgeRequest = {
|
|
13
|
+
// Cross-chain orders, are always SELL orders (BUY not supported yet)
|
|
14
|
+
kind: OrderKind.SELL,
|
|
15
|
+
|
|
16
|
+
// Sell token (and source chain)
|
|
17
|
+
sellTokenChainId: SupportedChainId.ARBITRUM_ONE,
|
|
18
|
+
sellTokenAddress: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
19
|
+
sellTokenDecimals: 18,
|
|
20
|
+
|
|
21
|
+
// Buy token (and target chain)
|
|
22
|
+
buyTokenChainId: SupportedChainId.BASE,
|
|
23
|
+
buyTokenAddress: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
24
|
+
buyTokenDecimals: 18,
|
|
25
|
+
|
|
26
|
+
// Amount to sell
|
|
27
|
+
amount: '120000000000000000'
|
|
28
|
+
|
|
29
|
+
signer: '<privateKeyOrEthersSigner>',
|
|
30
|
+
|
|
31
|
+
// Optional parameters
|
|
32
|
+
appCode: '<YOUR_APP_CODE>',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Get a quote (and the post callback) for a cross-chain swap
|
|
36
|
+
const quoteResult = await sdk.getQuote(parameters)
|
|
37
|
+
assertIsBridgeQuoteAndPost(quoteResult) // Assert that the quote result is of type BridgeQuoteAndPost (type for cross-chain quotes, as opposed to QuoteAndPost for single-chain quotes). The assertion makes typescript happy.
|
|
38
|
+
const { swap, bridge, postSwapOrderFromQuote } = quoteResult
|
|
39
|
+
|
|
40
|
+
// Display all data related to the swap (costs, amounts, appData including the bridging hook, etc.) 🐮
|
|
41
|
+
console.log('Swap info', swap)
|
|
42
|
+
|
|
43
|
+
// Display all data related to the bridge (costs, amounts, provider info, hook, and the bridging quote) ✉️
|
|
44
|
+
console.log('Bridge info', bridge)
|
|
45
|
+
|
|
46
|
+
// Get the buy amount after slippage in the target chain
|
|
47
|
+
const { buyAmount } = bridge.amountsAndCosts.afterSlippage
|
|
48
|
+
|
|
49
|
+
if (confirm(`You will get at least: ${buyAmount}, ok?`)) {
|
|
50
|
+
const orderId = await postSwapOrderFromQuote()
|
|
51
|
+
|
|
52
|
+
console.log('Order created, id: ', orderId)
|
|
53
|
+
}
|
|
54
|
+
```
|