@cowprotocol/cow-sdk 5.10.1 → 6.0.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/dist/bridging/BridgingSdk/BridgingSdk.d.ts +49 -0
- package/dist/bridging/BridgingSdk/getQuoteWithBridging.d.ts +9 -0
- package/dist/bridging/BridgingSdk/getQuoteWithoutBridge.d.ts +7 -0
- package/dist/bridging/const.d.ts +2 -0
- package/dist/bridging/index.d.ts +5 -0
- package/dist/bridging/providers/across/AcrossApi.d.ts +195 -0
- package/dist/bridging/providers/across/AcrossBridgeProvider.d.ts +41 -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/tokens.d.ts +11 -0
- package/dist/bridging/providers/across/createAcrossDepositCall.d.ts +9 -0
- package/dist/bridging/providers/across/util.d.ts +39 -0
- package/dist/bridging/providers/mock/MockBridgeProvider.d.ts +20 -0
- package/dist/bridging/types.d.ts +243 -0
- package/dist/bridging/utils.d.ts +2 -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/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 +122 -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} +7 -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 +10 -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/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 +1 -3
- package/dist/cow-shed/types.d.ts +0 -16
- package/dist/hooks/utils.d.ts +2 -0
- package/dist/index-f14ff795.js +29 -0
- package/dist/index-f14ff795.js.map +1 -0
- package/dist/index.d.ts +1 -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 +4 -2
- 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 +1 -1
- package/dist/schemas/trading/SwapAdvancedSettings.ts +26 -0
- package/dist/schemas/trading/TradeParameters.ts +3 -0
- package/dist/src/bridging/README.md +44 -0
- package/dist/src/cow-shed/README.md +60 -0
- package/dist/src/trading/README.md +1 -0
- package/dist/src/weiroll/README.md +55 -0
- package/dist/subgraph/api.d.ts +2 -2
- package/dist/trading/calculateUniqueOrderId.d.ts +3 -4
- package/dist/trading/consts.d.ts +2 -0
- package/dist/trading/getEthFlowTransaction.d.ts +4 -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/postSellNativeCurrencyOrder.d.ts +2 -3
- package/dist/trading/postSwapOrder.d.ts +1 -1
- package/dist/trading/tradingSdk.d.ts +13 -10
- package/dist/trading/types.d.ts +61 -10
- package/dist/trading/utils.d.ts +8 -4
- package/dist/{utils-35087bda.js → utils-23d3241a.js} +1 -1
- package/dist/utils-23d3241a.js.map +1 -0
- package/dist/{utils-04fc2d68.js → utils-31e2d1e7.js} +1 -1
- package/dist/utils-31e2d1e7.js.map +1 -0
- package/dist/{utils-ce0d26d7.js → utils-6959b448.js} +2 -2
- package/dist/utils-6959b448.js.map +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/weiroll/index.d.ts +20 -0
- package/package.json +4 -2
- 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-cc713836.js +0 -29
- package/dist/index-cc713836.js.map +0 -1
- package/dist/utils-04fc2d68.js.map +0 -1
- package/dist/utils-35087bda.js.map +0 -1
- package/dist/utils-ce0d26d7.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": "
|
|
3
|
+
"version": "6.0.0-RC.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"files": [
|
|
6
6
|
"/dist"
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@cowprotocol/contracts": "^1.6.0",
|
|
38
38
|
"@ethersproject/abstract-signer": "^5.7.0",
|
|
39
39
|
"@openzeppelin/merkle-tree": "^1.0.5",
|
|
40
|
+
"@weiroll/weiroll.js": "^0.3.0",
|
|
40
41
|
"cross-fetch": "^3.1.5",
|
|
41
42
|
"exponential-backoff": "^3.1.1",
|
|
42
43
|
"graphql": "^16.3.0",
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"eslint-config-prettier": "^8.6.0",
|
|
67
68
|
"eslint-plugin-prettier": "^4.2.1",
|
|
68
69
|
"eslint-plugin-unused-imports": "^3.0.0",
|
|
69
|
-
"ethers": "^5.
|
|
70
|
+
"ethers": "^5.8.0",
|
|
70
71
|
"jest": "^29.6.4",
|
|
71
72
|
"jest-fetch-mock": "^3.0.3",
|
|
72
73
|
"microbundle": "^0.15.1",
|
|
@@ -79,6 +80,7 @@
|
|
|
79
80
|
"typescript": "^4.9.5"
|
|
80
81
|
},
|
|
81
82
|
"jest": {
|
|
83
|
+
"maxWorkers": 1,
|
|
82
84
|
"automock": false,
|
|
83
85
|
"resetMocks": false,
|
|
84
86
|
"setupFiles": [
|
|
@@ -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": [
|
|
@@ -15,7 +15,7 @@ export default {
|
|
|
15
15
|
8453,
|
|
16
16
|
11155111
|
|
17
17
|
],
|
|
18
|
-
"description": "Supported chains and their `chainId` for the SDK."
|
|
18
|
+
"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
19
|
},
|
|
20
20
|
"appCode": {
|
|
21
21
|
"type": "string",
|
|
@@ -327,6 +327,32 @@ 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."
|
|
330
356
|
}
|
|
331
357
|
},
|
|
332
358
|
"additionalProperties": false,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Bridging SDK
|
|
2
|
+
|
|
3
|
+
SDK for swapping between chains.
|
|
4
|
+
|
|
5
|
+
This documentation is a WIP as this feature remains in development, as the SDK is subject to change.
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { SupportedChainId, BridgingSdk, QuoteBridgeRequest, OrderKind } from '@cowprotocol/cow-sdk'
|
|
11
|
+
|
|
12
|
+
const sdk = new BridgingSdk({
|
|
13
|
+
signer: '<privateKeyOrEthersSigner>',
|
|
14
|
+
appCode: '<YOUR_APP_CODE>',
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const parameters: QuoteBridgeRequest = {
|
|
18
|
+
// Cross-chain orders, are always SELL orders (BUY not supported yet)
|
|
19
|
+
kind: OrderKind.SELL,
|
|
20
|
+
|
|
21
|
+
// Sell token (and source chain)
|
|
22
|
+
sellTokenChainId: SupportedChainId.ARBITRUM_ONE,
|
|
23
|
+
sellTokenAddress: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
24
|
+
sellTokenDecimals: 18,
|
|
25
|
+
|
|
26
|
+
// Buy token (and target chain)
|
|
27
|
+
buyTokenChainId: SupportedChainId.BASE,
|
|
28
|
+
buyTokenAddress: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
29
|
+
buyTokenDecimals: 18,
|
|
30
|
+
|
|
31
|
+
// Amount to sell
|
|
32
|
+
amount: '120000000000000000'
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { quoteResults, postSwapOrderFromQuote } = await sdk.getQuote(parameters)
|
|
36
|
+
|
|
37
|
+
const { buyAmount } = quoteResults.amountsAndCosts.afterSlippage
|
|
38
|
+
|
|
39
|
+
if (confirm(`You will get at least: ${buyAmount}, ok?`)) {
|
|
40
|
+
const orderId = await postSwapOrderFromQuote()
|
|
41
|
+
|
|
42
|
+
console.log('Order created, id: ', orderId)
|
|
43
|
+
}
|
|
44
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Cow Shed SDK
|
|
2
|
+
|
|
3
|
+
The Cow Shed SDK is a TypeScript library that provides a set of functions to interact with the [Cow Shed contract](https://github.com/cowdao-grants/cow-shed).
|
|
4
|
+
|
|
5
|
+
In essence, CoW Shed acts as a user owned smart contract (1/1 multisig if you will) that can execute multiple calls on behalf of the user (once the user has pre-authorized the calls).
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { ethers } from 'ethers'
|
|
11
|
+
import { CowShedSdk, ICoWShedCall, SupportedChainId } from '@cowprotocol/cow-sdk'
|
|
12
|
+
|
|
13
|
+
const cowShedSdk = new CowShedSdk({
|
|
14
|
+
signer: '<privateKeyOrEthersSigner>', // You can provide the signer in the constructor, or the `signCalls` method
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// Get the cow-shed account for any given chainId and owner's address
|
|
18
|
+
const cowShedAccount = cowShedSdk.getCowShedAccount(1, '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')
|
|
19
|
+
|
|
20
|
+
// Prepare the calls you want to execute using the cow-shed account
|
|
21
|
+
const calls: ICoWShedCall[] = [
|
|
22
|
+
{
|
|
23
|
+
target: '<contract-address-1>',
|
|
24
|
+
callData: 'call-data-1',
|
|
25
|
+
value: 0n,
|
|
26
|
+
isDelegateCall: true,
|
|
27
|
+
allowFailure: false,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
target: '<contract-address-2>',
|
|
31
|
+
callData: '<call-data-2>',
|
|
32
|
+
value: 0n,
|
|
33
|
+
isDelegateCall: true,
|
|
34
|
+
allowFailure: false,
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
// Sign the calls
|
|
39
|
+
const preAuthorizedCall = await cowShedSdk.signCalls({
|
|
40
|
+
chainId: SupportedChainId.MAINNET,
|
|
41
|
+
calls,
|
|
42
|
+
signer: '<privateKeyOrEthersSigner>',
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Get the details of the pre-authorized call you need to send
|
|
46
|
+
const { signedMulticall, gasLimit, cowShedAccount } = preAuthorizedCall
|
|
47
|
+
const { to, data, value } = signedMulticall
|
|
48
|
+
|
|
49
|
+
// Execute the transaction using any wallet. The calldata has been pre-authed, so you don't need any special permissions to send this transaction
|
|
50
|
+
let anotherWallet = new ethers.Wallet('<another-private-key>');
|
|
51
|
+
const tx = await anotherWallet.sendTransaction({
|
|
52
|
+
to,
|
|
53
|
+
data,
|
|
54
|
+
value,
|
|
55
|
+
gasLimit,
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
@@ -32,6 +32,7 @@ Main functions:
|
|
|
32
32
|
- `getQuote` - Fetch a quote for a swap order.
|
|
33
33
|
|
|
34
34
|
Special cases:
|
|
35
|
+
- 'setTraderParams' - In case if you work with different chains and need to switch between them in runtime.
|
|
35
36
|
- `postSellNativeCurrencyOrder` - Sell blockchain native tokens (e.g., ETH on Ethereum).
|
|
36
37
|
- `getPreSignTransaction` - Sign an order using a smart contract wallet.
|
|
37
38
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Weiroll utils
|
|
2
|
+
|
|
3
|
+
This module some utilities to simplify the use of the [Weiroll contract](https://github.com/weiroll/weiroll).
|
|
4
|
+
|
|
5
|
+
Weiroll is a simple and efficient operation-chaining/scripting language for the EVM.
|
|
6
|
+
|
|
7
|
+
The main utility function is `createWeirollDelegateCall` which returns an EVM `delegatecall` with some plan encoded as Weiroll calldata.
|
|
8
|
+
|
|
9
|
+
To understand how this works, let's see an example:
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { CommandFlags, createWeirollDelegateCall } from './index'
|
|
15
|
+
import { Planner, Contract as WeirollContract } from '@weiroll/weiroll.js'
|
|
16
|
+
import { ethers } from 'ethers'
|
|
17
|
+
|
|
18
|
+
const ERC20_ABI = [
|
|
19
|
+
'function balanceOf(address account) external view returns (uint256)',
|
|
20
|
+
'function transfer(address to, uint256 amount) external returns (bool)',
|
|
21
|
+
] as const
|
|
22
|
+
|
|
23
|
+
// Create ethers DAI contract
|
|
24
|
+
const contract = new ethers.Contract('0x6b175474e89094c44da98b954eedeac495271d0f', ERC20_ABI)
|
|
25
|
+
|
|
26
|
+
// Create the Weiroll contract (wrapping the ethers contract)
|
|
27
|
+
// You can choose between different command flags, like `CALL`, `DELEGATECALL`, `STATICCALL`, etc.
|
|
28
|
+
const daiContract = WeirollContract.createContract(contract, CommandFlags.CALL)
|
|
29
|
+
|
|
30
|
+
// Let's pretend we have a smart contract that wants to transfer all DAI to Vitalik
|
|
31
|
+
const ownerContractAddress = '0xf6e72Db5454dd049d0788e411b06CfAF16853042'
|
|
32
|
+
|
|
33
|
+
// Main function to create the delegatecall
|
|
34
|
+
const { to, value, data } = createWeirollDelegateCall((planner: Planner) => {
|
|
35
|
+
// Add to plan: Get the balance of the token
|
|
36
|
+
const daiBalance = planner.add(daiContract.balanceOf(ownerContractAddress))
|
|
37
|
+
|
|
38
|
+
// Add to plan: Transfer all balance to Vitalik. Note how we can chain the balance from previous call
|
|
39
|
+
planner.add(daiContract.transfer('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', daiBalance))
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Execute the delegatecall from "ownerContract" context.
|
|
43
|
+
// For illustration purposes, lets imagine there's a contract with a function `executeDelegateCall` (not a very realistic example because this would likely need a signature to be safe)
|
|
44
|
+
|
|
45
|
+
// Create instance of owner contract
|
|
46
|
+
const SMART_ACCOUNT_ABI = [
|
|
47
|
+
'function executeDelegateCall(address,uint256,bytes)',
|
|
48
|
+
]
|
|
49
|
+
const ownerContract = new ethers.Contract(ownerContractAddress, SMART_ACCOUNT_ABI)
|
|
50
|
+
|
|
51
|
+
// Execute the delegatecall, transferring all DAI to Vitalik
|
|
52
|
+
const tx = await ownerContract.executeDelegateCall(to, value, data)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
|
package/dist/subgraph/api.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Variables } from 'graphql-request';
|
|
2
2
|
import { DocumentNode } from 'graphql/index';
|
|
3
|
-
import { SupportedChainId } from '../
|
|
4
|
-
import { ApiContext } from '../common/
|
|
3
|
+
import { SupportedChainId } from '../chains/types';
|
|
4
|
+
import { ApiContext } from '../common/types/config';
|
|
5
5
|
import { LastDaysVolumeQuery, LastHoursVolumeQuery, TotalsQuery } from './graphql';
|
|
6
6
|
type SubgraphApiBaseUrls = Record<SupportedChainId, string | null>;
|
|
7
7
|
interface SubgraphApiContext extends Omit<ApiContext, 'baseUrls'> {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { UnsignedOrder } from '../order-signing';
|
|
2
|
-
import { CowEnv
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
2
|
+
import { CowEnv } from '../common';
|
|
3
|
+
import { SupportedChainId } from '../chains';
|
|
4
|
+
import { EthFlowOrderExistsCallback } from './types';
|
|
6
5
|
export declare function calculateUniqueOrderId(chainId: SupportedChainId, order: UnsignedOrder, checkEthFlowOrderExists?: EthFlowOrderExistsCallback, env?: CowEnv): Promise<string>;
|
package/dist/trading/consts.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { SigningScheme } from '../order-book';
|
|
2
|
+
import { SupportedChainId } from '../chains';
|
|
2
3
|
export declare function log(text: string): void;
|
|
3
4
|
export declare namespace log {
|
|
4
5
|
var enabled: boolean;
|
|
5
6
|
}
|
|
6
7
|
export declare const DEFAULT_QUOTE_VALIDITY: number;
|
|
7
8
|
export declare const DEFAULT_SLIPPAGE_BPS = 50;
|
|
9
|
+
export declare const ETH_FLOW_DEFAULT_SLIPPAGE_BPS: Record<SupportedChainId, number>;
|
|
8
10
|
export declare const SIGN_SCHEME_MAP: {
|
|
9
11
|
eip712: SigningScheme;
|
|
10
12
|
ethsign: SigningScheme;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare function getEthFlowTransaction(signer: Signer, appDataKeccak256: string, _params: LimitTradeParametersFromQuote, chainId: SupportedChainId, networkCostsAmount?: string, checkEthFlowOrderExists?: EthFlowOrderExistsCallback): Promise<{
|
|
1
|
+
import { LimitTradeParametersFromQuote, PostTradeAdditionalParams, TransactionParams } from './types';
|
|
2
|
+
import { SupportedChainId } from '../chains';
|
|
3
|
+
import { Signer } from '@ethersproject/abstract-signer';
|
|
4
|
+
export declare function getEthFlowTransaction(signer: Signer, appDataKeccak256: string, _params: LimitTradeParametersFromQuote, chainId: SupportedChainId, additionalParams?: PostTradeAdditionalParams): Promise<{
|
|
6
5
|
orderId: string;
|
|
7
6
|
transaction: TransactionParams;
|
|
8
7
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { OrderTypedData } from './types';
|
|
2
2
|
import { UnsignedOrder } from '../order-signing';
|
|
3
|
-
import { SupportedChainId } from '../
|
|
3
|
+
import { SupportedChainId } from '../chains';
|
|
4
4
|
export declare function getOrderTypedData(chainId: SupportedChainId, orderToSign: UnsignedOrder): Promise<OrderTypedData>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SupportedChainId } from '../
|
|
2
|
-
import type { Signer } from '
|
|
1
|
+
import { SupportedChainId } from '../chains';
|
|
2
|
+
import type { Signer } from '@ethersproject/abstract-signer';
|
|
3
3
|
import { TransactionParams } from './types';
|
|
4
4
|
export declare function getPreSignTransaction(signer: Signer, chainId: SupportedChainId, account: string, orderId: string): Promise<TransactionParams>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QuoteResults, QuoterParameters, SwapAdvancedSettings, SwapParameters, TradeParameters } from './types';
|
|
2
2
|
import { OrderBookApi } from '../order-book';
|
|
3
|
-
import { Signer } from '
|
|
3
|
+
import { Signer } from '@ethersproject/abstract-signer';
|
|
4
4
|
export type QuoteResultsWithSigner = {
|
|
5
5
|
result: QuoteResults & {
|
|
6
6
|
signer: Signer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrderBookApi
|
|
2
|
-
import type { Signer } from '
|
|
3
|
-
import { AppDataInfo, LimitTradeParameters } from './types';
|
|
4
|
-
export declare function postCoWProtocolTrade(orderBookApi: OrderBookApi, signer: Signer, appData: AppDataInfo, params: LimitTradeParameters,
|
|
1
|
+
import { OrderBookApi } from '../order-book';
|
|
2
|
+
import type { Signer } from '@ethersproject/abstract-signer';
|
|
3
|
+
import { AppDataInfo, LimitTradeParameters, PostTradeAdditionalParams } from './types';
|
|
4
|
+
export declare function postCoWProtocolTrade(orderBookApi: OrderBookApi, signer: Signer, appData: AppDataInfo, params: LimitTradeParameters, additionalParams?: PostTradeAdditionalParams): Promise<string>;
|