@cowprotocol/cow-sdk 6.0.0-RC.9 → 6.0.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 +3 -1
- package/dist/README.md +3 -1
- package/dist/bridging/BridgingSdk/BridgingSdk.d.ts +87 -63
- package/dist/bridging/BridgingSdk/findBridgeProviderFromHook.d.ts +2 -0
- package/dist/bridging/BridgingSdk/getBridgeSignedHook.d.ts +8 -0
- package/dist/bridging/BridgingSdk/getCrossChainOrder.d.ts +16 -0
- package/dist/bridging/BridgingSdk/getQuoteWithBridge.d.ts +3 -0
- package/dist/bridging/BridgingSdk/getQuoteWithoutBridge.d.ts +7 -7
- package/dist/bridging/BridgingSdk/mock/bridgeRequestMocks.d.ts +20 -0
- package/dist/bridging/BridgingSdk/types.d.ts +43 -0
- package/dist/bridging/const.d.ts +4 -2
- package/dist/bridging/errors.d.ts +22 -0
- package/dist/bridging/index.d.ts +8 -5
- package/dist/bridging/providers/across/AcrossApi.d.ts +30 -195
- package/dist/bridging/providers/across/AcrossBridgeProvider.d.ts +44 -41
- package/dist/bridging/providers/across/abi.d.ts +154 -154
- package/dist/bridging/providers/across/const/contracts.d.ts +3 -3
- package/dist/bridging/providers/across/const/interfaces.d.ts +3 -0
- package/dist/bridging/providers/across/const/misc.d.ts +2 -0
- package/dist/bridging/providers/across/const/tokens.d.ts +11 -11
- package/dist/bridging/providers/across/createAcrossDepositCall.d.ts +9 -9
- package/dist/bridging/providers/across/getDepositParams.d.ts +4 -0
- package/dist/bridging/providers/across/types.d.ts +242 -0
- package/dist/bridging/providers/across/util.d.ts +43 -39
- package/dist/bridging/providers/bungee/BungeeApi.d.ts +67 -0
- package/dist/bridging/providers/bungee/BungeeBridgeProvider.d.ts +44 -0
- package/dist/bridging/providers/bungee/abi.d.ts +203 -0
- package/dist/bridging/providers/bungee/const/contracts.d.ts +4 -0
- package/dist/bridging/providers/bungee/const/misc.d.ts +8 -0
- package/dist/bridging/providers/bungee/createBungeeDepositCall.d.ts +7 -0
- package/dist/bridging/providers/bungee/getBridgingStatusFromEvents.d.ts +3 -0
- package/dist/bridging/providers/bungee/types.d.ts +267 -0
- package/dist/bridging/providers/bungee/util.d.ts +62 -0
- package/dist/bridging/providers/mock/MockBridgeProvider.d.ts +26 -20
- package/dist/bridging/providers/utils/getGasLimitEstimationForHook.d.ts +4 -0
- package/dist/bridging/types.d.ts +323 -251
- package/dist/bridging/utils.d.ts +9 -6
- package/dist/chains/const/index.d.ts +25 -25
- package/dist/chains/const/path.d.ts +1 -1
- package/dist/chains/details/arbitrum.d.ts +7 -7
- package/dist/chains/details/avalanche.d.ts +2 -0
- package/dist/chains/details/base.d.ts +7 -7
- package/dist/chains/details/gnosis.d.ts +7 -7
- package/dist/chains/details/index.d.ts +8 -0
- package/dist/chains/details/mainnet.d.ts +7 -7
- package/dist/chains/details/optimism.d.ts +2 -2
- package/dist/chains/details/polygon.d.ts +2 -2
- package/dist/chains/details/sepolia.d.ts +7 -7
- package/dist/chains/index.d.ts +4 -3
- package/dist/chains/types.d.ts +127 -122
- package/dist/chains/utils.d.ts +18 -18
- package/dist/common/consts/config.d.ts +9 -9
- package/dist/common/consts/contracts.d.ts +43 -34
- package/dist/common/consts/ipfs.d.ts +2 -2
- package/dist/common/consts/order.d.ts +1 -0
- package/dist/common/consts/path.d.ts +1 -1
- package/dist/common/consts/tokens.d.ts +9 -9
- package/dist/common/generated/CoWShed.d.ts +219 -219
- package/dist/common/generated/CoWShedFactory.d.ts +191 -191
- package/dist/common/generated/ComposableCoW.d.ts +340 -340
- package/dist/common/generated/EthFlow.d.ts +117 -117
- package/dist/common/generated/ExtensibleFallbackHandler.d.ts +282 -282
- package/dist/common/generated/GPv2Settlement.d.ts +107 -107
- package/dist/common/generated/TWAP.d.ts +141 -141
- package/dist/common/generated/common.d.ts +21 -21
- package/dist/common/generated/factories/CoWShedFactory__factory.d.ts +250 -250
- package/dist/common/generated/factories/CoWShed__factory.d.ts +254 -254
- package/dist/common/generated/factories/ComposableCoW__factory.d.ts +475 -475
- package/dist/common/generated/factories/EthFlow__factory.d.ts +124 -124
- package/dist/common/generated/factories/ExtensibleFallbackHandler__factory.d.ts +389 -389
- package/dist/common/generated/factories/GPv2Settlement__factory.d.ts +81 -81
- package/dist/common/generated/factories/TWAP__factory.d.ts +260 -260
- package/dist/common/generated/factories/index.d.ts +7 -7
- package/dist/common/generated/index.d.ts +15 -15
- package/dist/common/index.d.ts +12 -10
- package/dist/common/types/config.d.ts +70 -70
- package/dist/common/types/cow-error.d.ts +4 -4
- package/dist/common/types/ethereum.d.ts +5 -5
- package/dist/common/types/tokens.d.ts +12 -12
- package/dist/common/types/wallets.d.ts +5 -5
- package/dist/common/utils/common.d.ts +1 -0
- package/dist/common/utils/config.d.ts +4 -4
- package/dist/common/utils/log.d.ts +2 -0
- package/dist/common/utils/math.d.ts +19 -0
- package/dist/common/utils/order.d.ts +4 -0
- package/dist/common/utils/serialize.d.ts +1 -1
- package/dist/common/utils/wallet.d.ts +3 -3
- package/dist/composable/ConditionalOrder.d.ts +206 -206
- package/dist/composable/ConditionalOrderFactory.d.ts +19 -19
- package/dist/composable/Multiplexer.d.ts +174 -174
- package/dist/composable/contracts.d.ts +6 -6
- package/dist/composable/generated/ComposableCoW.d.ts +340 -340
- package/dist/composable/generated/ExtensibleFallbackHandler.d.ts +282 -282
- package/dist/composable/generated/TWAP.d.ts +141 -141
- package/dist/composable/generated/common.d.ts +21 -21
- package/dist/composable/generated/factories/ComposableCoW__factory.d.ts +475 -475
- package/dist/composable/generated/factories/ExtensibleFallbackHandler__factory.d.ts +389 -389
- package/dist/composable/generated/factories/TWAP__factory.d.ts +260 -260
- package/dist/composable/generated/factories/index.d.ts +3 -3
- package/dist/composable/generated/index.d.ts +7 -7
- package/dist/composable/index.d.ts +6 -6
- package/dist/composable/orderTypes/Twap.d.ts +242 -242
- package/dist/composable/orderTypes/index.d.ts +3 -3
- package/dist/composable/orderTypes/test/TestConditionalOrder.d.ts +25 -25
- package/dist/composable/types.d.ts +133 -133
- package/dist/composable/utils.d.ts +37 -37
- package/dist/cow-shed/CowShedSdk.d.ts +74 -69
- package/dist/cow-shed/contracts/CoWShedHooks.d.ts +47 -45
- package/dist/cow-shed/contracts/utils.d.ts +4 -4
- package/dist/cow-shed/index.d.ts +3 -2
- package/dist/cow-shed/types.d.ts +17 -17
- package/dist/hooks/utils.d.ts +3 -2
- package/dist/index-847d9333.js +29 -0
- package/dist/index-847d9333.js.map +1 -0
- package/dist/index.d.ts +11 -10
- 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 +235 -235
- package/dist/order-book/generated/index.d.ts +55 -55
- package/dist/order-book/generated/models/Address.d.ts +4 -4
- package/dist/order-book/generated/models/AppData.d.ts +7 -7
- package/dist/order-book/generated/models/AppDataHash.d.ts +6 -6
- package/dist/order-book/generated/models/AppDataObject.d.ts +7 -7
- package/dist/order-book/generated/models/Auction.d.ts +30 -30
- package/dist/order-book/generated/models/AuctionOrder.d.ts +92 -92
- package/dist/order-book/generated/models/AuctionPrices.d.ts +6 -6
- package/dist/order-book/generated/models/BigUint.d.ts +4 -4
- package/dist/order-book/generated/models/BuyTokenDestination.d.ts +7 -7
- package/dist/order-book/generated/models/CallData.d.ts +4 -4
- package/dist/order-book/generated/models/CompetitionAuction.d.ts +14 -14
- package/dist/order-book/generated/models/CompetitionOrderStatus.d.ts +29 -29
- package/dist/order-book/generated/models/EcdsaSignature.d.ts +4 -4
- package/dist/order-book/generated/models/EcdsaSigningScheme.d.ts +7 -7
- package/dist/order-book/generated/models/EthflowData.d.ts +20 -20
- package/dist/order-book/generated/models/ExecutedAmounts.d.ts +5 -5
- package/dist/order-book/generated/models/ExecutedProtocolFee.d.ts +8 -8
- package/dist/order-book/generated/models/FeePolicy.d.ts +7 -7
- package/dist/order-book/generated/models/InteractionData.d.ts +11 -11
- package/dist/order-book/generated/models/NativePriceResponse.d.ts +10 -10
- package/dist/order-book/generated/models/OnchainOrderData.d.ts +24 -24
- package/dist/order-book/generated/models/Order.d.ts +3 -3
- package/dist/order-book/generated/models/OrderCancellation.d.ts +14 -14
- package/dist/order-book/generated/models/OrderCancellationError.d.ts +15 -15
- package/dist/order-book/generated/models/OrderCancellations.d.ts +18 -18
- package/dist/order-book/generated/models/OrderClass.d.ts +8 -8
- package/dist/order-book/generated/models/OrderCreation.d.ts +80 -80
- package/dist/order-book/generated/models/OrderKind.d.ts +7 -7
- package/dist/order-book/generated/models/OrderMetaData.d.ts +100 -100
- package/dist/order-book/generated/models/OrderParameters.d.ts +53 -53
- package/dist/order-book/generated/models/OrderPostError.d.ts +35 -35
- package/dist/order-book/generated/models/OrderQuoteRequest.d.ts +58 -58
- package/dist/order-book/generated/models/OrderQuoteResponse.d.ts +27 -27
- package/dist/order-book/generated/models/OrderQuoteSide.d.ts +26 -26
- package/dist/order-book/generated/models/OrderQuoteSideKindBuy.d.ts +3 -3
- package/dist/order-book/generated/models/OrderQuoteSideKindSell.d.ts +3 -3
- package/dist/order-book/generated/models/OrderQuoteValidity.d.ts +14 -14
- package/dist/order-book/generated/models/OrderStatus.d.ts +10 -10
- package/dist/order-book/generated/models/PreSignature.d.ts +4 -4
- package/dist/order-book/generated/models/PriceEstimationError.d.ts +12 -12
- package/dist/order-book/generated/models/PriceImprovement.d.ts +12 -12
- package/dist/order-book/generated/models/PriceQuality.d.ts +16 -16
- package/dist/order-book/generated/models/Quote.d.ts +19 -19
- package/dist/order-book/generated/models/SellTokenSource.d.ts +8 -8
- package/dist/order-book/generated/models/Signature.d.ts +6 -6
- package/dist/order-book/generated/models/SigningScheme.d.ts +9 -9
- package/dist/order-book/generated/models/SolverCompetitionResponse.d.ts +30 -30
- package/dist/order-book/generated/models/SolverSettlement.d.ts +47 -47
- package/dist/order-book/generated/models/Surplus.d.ts +7 -7
- package/dist/order-book/generated/models/TokenAmount.d.ts +4 -4
- package/dist/order-book/generated/models/TotalSurplus.d.ts +10 -10
- package/dist/order-book/generated/models/Trade.d.ts +57 -57
- package/dist/order-book/generated/models/TransactionHash.d.ts +4 -4
- package/dist/order-book/generated/models/UID.d.ts +8 -8
- package/dist/order-book/generated/models/Volume.d.ts +6 -6
- package/dist/order-book/index.d.ts +5 -5
- package/dist/order-book/mock.d.ts +63 -63
- package/dist/order-book/quoteAmountsAndCostsUtils.d.ts +35 -22
- package/dist/order-book/request.d.ts +49 -49
- package/dist/order-book/transformOrder.d.ts +10 -10
- package/dist/order-book/types.d.ts +74 -74
- package/dist/order-signing/index.d.ts +2 -2
- package/dist/order-signing/orderSigningUtils.d.ts +97 -97
- package/dist/order-signing/types.d.ts +55 -55
- package/dist/order-signing/utils.d.ts +49 -49
- package/dist/package.json +31 -32
- package/dist/schemas/trading/LimitOrderAdvancedSettings.ts +151 -12
- package/dist/schemas/trading/LimitTradeParameters.ts +136 -15
- package/dist/schemas/trading/QuoteResultsSerialized.ts +292 -27
- package/dist/schemas/trading/QuoterParameters.ts +10 -0
- package/dist/schemas/trading/SwapAdvancedSettings.ts +331 -12
- package/dist/schemas/trading/TradeParameters.ts +136 -15
- package/dist/src/trading/README.md +99 -7
- package/dist/subgraph/api.d.ts +77 -77
- package/dist/subgraph/graphql.d.ts +3203 -3203
- package/dist/subgraph/index.d.ts +1 -1
- package/dist/subgraph/queries.d.ts +14 -14
- package/dist/test/utils.d.ts +1 -0
- package/dist/trading/appDataUtils.d.ts +5 -4
- package/dist/trading/calculateUniqueOrderId.d.ts +5 -5
- package/dist/trading/consts.d.ts +6 -14
- package/dist/trading/getEthFlowTransaction.d.ts +12 -7
- package/dist/trading/getOrderToSign.d.ts +11 -8
- package/dist/trading/getOrderTypedData.d.ts +4 -4
- package/dist/trading/getPreSignTransaction.d.ts +4 -4
- package/dist/trading/getQuote.d.ts +26 -14
- package/dist/trading/index.d.ts +21 -19
- package/dist/trading/postCoWProtocolTrade.d.ts +4 -4
- package/dist/trading/postLimitOrder.d.ts +3 -3
- package/dist/trading/postSellNativeCurrencyOrder.d.ts +4 -7
- package/dist/trading/postSwapOrder.d.ts +5 -5
- package/dist/trading/suggestSlippageBps.d.ts +13 -0
- package/dist/trading/suggestSlippageFromFee.d.ts +19 -0
- package/dist/trading/suggestSlippageFromVolume.d.ts +10 -0
- package/dist/trading/tradingSdk.d.ts +26 -26
- package/dist/trading/types.d.ts +221 -190
- package/dist/trading/utils/getPartnerFeeBps.d.ts +2 -0
- package/dist/trading/{utils.d.ts → utils/misc.d.ts} +27 -27
- package/dist/trading/utils/slippage.d.ts +16 -0
- package/dist/utils-09dadb80.js +2 -0
- package/dist/utils-09dadb80.js.map +1 -0
- package/dist/utils-0ff3f95e.js +2 -0
- package/dist/utils-0ff3f95e.js.map +1 -0
- package/dist/utils-ddcfac77.js +2 -0
- package/dist/utils-ddcfac77.js.map +1 -0
- package/dist/utils.d.ts +3 -3
- package/dist/weiroll/index.d.ts +23 -23
- package/package.json +31 -32
- package/dist/bridging/BridgingSdk/getErc20Decimals.d.ts +0 -4
- package/dist/bridging/BridgingSdk/getQuoteWithBridging.d.ts +0 -9
- package/dist/index-317c25f1.js +0 -29
- package/dist/index-317c25f1.js.map +0 -1
- package/dist/utils-204a9cbe.js +0 -2
- package/dist/utils-204a9cbe.js.map +0 -1
- package/dist/utils-762ee9c3.js +0 -2
- package/dist/utils-762ee9c3.js.map +0 -1
- package/dist/utils-de2eb543.js +0 -2
- package/dist/utils-de2eb543.js.map +0 -1
|
@@ -127,6 +127,51 @@ if (confirm(`You will get at least: ${buyAmount}, ok?`)) {
|
|
|
127
127
|
}
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
#### Slippage
|
|
131
|
+
|
|
132
|
+
Considering the market volatility, order needs to have a proper slippage value.
|
|
133
|
+
You can manually specify a slippage:
|
|
134
|
+
```typescript
|
|
135
|
+
const parameters: TradeParameters = {
|
|
136
|
+
kind: OrderKind.BUY,
|
|
137
|
+
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
138
|
+
sellTokenDecimals: 18,
|
|
139
|
+
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
140
|
+
buyTokenDecimals: 18,
|
|
141
|
+
amount: '120000000000000000',
|
|
142
|
+
slippageBps: 100 // 1%
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const { quoteResults, postSwapOrderFromQuote } = await sdk.getQuote(parameters)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**OR, `TradingSDK` can suggest you slippage specifically for you trade.**
|
|
149
|
+
In that case you should not specify `slippageBps` in the quote request.
|
|
150
|
+
The slippage will be calculated automatically taking into account current network fees, trade amounts, and other conditions.
|
|
151
|
+
The suggested slippage value will be returned as `suggestedSlippageBps` parameter in the quote response.
|
|
152
|
+
If you post an order using `postSwapOrderFromQuote()`, then you don't need to specify any parameters, everything will happen automatically.
|
|
153
|
+
|
|
154
|
+
> Note: Suggested slippage might be 100% in some cases.
|
|
155
|
+
> This can happen, for example, if the order size is very small.
|
|
156
|
+
> Please verify thise value on your side before posting an order!
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const parameters: TradeParameters = {
|
|
160
|
+
kind: OrderKind.BUY,
|
|
161
|
+
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
162
|
+
sellTokenDecimals: 18,
|
|
163
|
+
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
164
|
+
buyTokenDecimals: 18,
|
|
165
|
+
amount: '120000000000000000'
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const { quoteResults: { suggestedSlippageBps }, postSwapOrderFromQuote } = await sdk.getQuote(parameters)
|
|
169
|
+
|
|
170
|
+
console.log(`Suggested slippage is ${suggestedSlippageBps} BPS`)
|
|
171
|
+
|
|
172
|
+
postSwapOrderFromQuote() // Order will be posted to order-book with the suggested slippage
|
|
173
|
+
```
|
|
174
|
+
|
|
130
175
|
### postSwapOrder
|
|
131
176
|
|
|
132
177
|
This function fetches a quote for a swap order and just creates the order.
|
|
@@ -166,7 +211,7 @@ const parameters: TradeParameters = {
|
|
|
166
211
|
amount: '120000000000000000'
|
|
167
212
|
}
|
|
168
213
|
|
|
169
|
-
const orderId = await sdk.postSwapOrder(parameters)
|
|
214
|
+
const { orderId } = await sdk.postSwapOrder(parameters)
|
|
170
215
|
|
|
171
216
|
console.log('Order created, id: ', orderId)
|
|
172
217
|
```
|
|
@@ -212,7 +257,7 @@ const limitOrderParameters: LimitTradeParameters = {
|
|
|
212
257
|
buyAmount: '66600000000000000000',
|
|
213
258
|
}
|
|
214
259
|
|
|
215
|
-
const orderId = await sdk.postLimitOrder(limitOrderParameters)
|
|
260
|
+
const { orderId } = await sdk.postLimitOrder(limitOrderParameters)
|
|
216
261
|
|
|
217
262
|
console.log('Order created, id: ', orderId)
|
|
218
263
|
```
|
|
@@ -249,7 +294,7 @@ const parameters: TradeParameters = {
|
|
|
249
294
|
amount: '120000000000000000'
|
|
250
295
|
}
|
|
251
296
|
|
|
252
|
-
const orderId = await sdk.postSellNativeCurrencyOrder(parameters)
|
|
297
|
+
const { orderId } = await sdk.postSellNativeCurrencyOrder(parameters)
|
|
253
298
|
|
|
254
299
|
console.log('Order created, id: ', orderId)
|
|
255
300
|
```
|
|
@@ -304,7 +349,7 @@ console.log('Quote:', quoteResults)
|
|
|
304
349
|
If you want to create an order with a smart-contract wallet, you should specify the `signingScheme` parameter in the `postSwapOrder` function.
|
|
305
350
|
And then you need to send a transaction from `getPreSignTransaction` result in order to sign the order.
|
|
306
351
|
|
|
307
|
-
#### Example
|
|
352
|
+
#### Example of Swap order
|
|
308
353
|
|
|
309
354
|
```typescript
|
|
310
355
|
import {
|
|
@@ -337,13 +382,60 @@ const advancedParameters: SwapAdvancedSettings = {
|
|
|
337
382
|
}
|
|
338
383
|
|
|
339
384
|
const smartContractWalletAddress = '0x<smartContractWalletAddress>'
|
|
340
|
-
const orderId = await sdk.postSwapOrder(parameters, advancedParameters)
|
|
385
|
+
const { orderId } = await sdk.postSwapOrder(parameters, advancedParameters)
|
|
386
|
+
const preSignTransaction = await sdk.getPreSignTransaction({ orderId, account: smartContractWalletAddress })
|
|
387
|
+
|
|
388
|
+
console.log('Order created with "pre-sign" state, id: ', orderId)
|
|
389
|
+
console.log('Execute the transaction to sign the order', preSignTransaction)
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
#### Example of Limit order
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
import {
|
|
396
|
+
SupportedChainId,
|
|
397
|
+
OrderKind,
|
|
398
|
+
LimitTradeParameters,
|
|
399
|
+
LimitOrderAdvancedSettings,
|
|
400
|
+
SigningScheme,
|
|
401
|
+
TradingSdk
|
|
402
|
+
} from '@cowprotocol/cow-sdk'
|
|
403
|
+
|
|
404
|
+
const sdk = new TradingSdk({
|
|
405
|
+
chainId: SupportedChainId.SEPOLIA,
|
|
406
|
+
signer: '<privateKeyOrEthersSigner>',
|
|
407
|
+
appCode: '<YOUR_APP_CODE>',
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
const smartContractWalletAddress = '0x<smartContractWalletAddress>'
|
|
411
|
+
|
|
412
|
+
const limitOrderParameters: LimitTradeParameters = {
|
|
413
|
+
kind: OrderKind.BUY,
|
|
414
|
+
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
415
|
+
sellTokenDecimals: 18,
|
|
416
|
+
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
417
|
+
buyTokenDecimals: 18,
|
|
418
|
+
sellAmount: '120000000000000000',
|
|
419
|
+
buyAmount: '66600000000000000000',
|
|
420
|
+
owner: smartContractWalletAddress // See note bellow why you need to specify the parameter
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const advancedParameters: LimitOrderAdvancedSettings = {
|
|
424
|
+
additionalParams: {
|
|
425
|
+
signingScheme: SigningScheme.PRESIGN
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const { orderId } = await sdk.postLimitOrder(limitOrderParameters, advancedParameters)
|
|
341
430
|
const preSignTransaction = await sdk.getPreSignTransaction({ orderId, account: smartContractWalletAddress })
|
|
342
431
|
|
|
343
432
|
console.log('Order created with "pre-sign" state, id: ', orderId)
|
|
344
433
|
console.log('Execute the transaction to sign the order', preSignTransaction)
|
|
345
434
|
```
|
|
346
435
|
|
|
436
|
+
> **Note:** it's important to specify the `owner` parameter if you create an order with a smart-contract wallet, and it differs from the signer (for example Safe).
|
|
437
|
+
> CoW Protocol will use `owner` in order to check the order owner balance, allowance and other things.
|
|
438
|
+
|
|
347
439
|
### Optional parameters
|
|
348
440
|
|
|
349
441
|
Both `postSwapOrder` and `postLimitOrder` functions have optional parameters.
|
|
@@ -382,7 +474,7 @@ const parameters: TradeParameters = {
|
|
|
382
474
|
receiver: '0xdef1ca1fb7f1232777520aa7f396b4e015f497ab' // Just a random address, don't use it!
|
|
383
475
|
}
|
|
384
476
|
|
|
385
|
-
const orderId = await sdk.postSwapOrder(parameters)
|
|
477
|
+
const { orderId } = await sdk.postSwapOrder(parameters)
|
|
386
478
|
|
|
387
479
|
console.log('Order created, id: ', orderId)
|
|
388
480
|
```
|
|
@@ -442,7 +534,7 @@ const advancedSettings: SwapAdvancedSettings = {
|
|
|
442
534
|
}
|
|
443
535
|
},
|
|
444
536
|
}
|
|
445
|
-
const orderId = await sdk.postSwapOrder(parameters, advancedSettings)
|
|
537
|
+
const { orderId } = await sdk.postSwapOrder(parameters, advancedSettings)
|
|
446
538
|
|
|
447
539
|
console.log('Order created, id: ', orderId)
|
|
448
540
|
```
|
package/dist/subgraph/api.d.ts
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { Variables } from 'graphql-request';
|
|
2
|
-
import { DocumentNode } from 'graphql/index';
|
|
3
|
-
import { SupportedChainId } from '../chains/types';
|
|
4
|
-
import { ApiContext } from '../common/types/config';
|
|
5
|
-
import { LastDaysVolumeQuery, LastHoursVolumeQuery, TotalsQuery } from './graphql';
|
|
6
|
-
type SubgraphApiBaseUrls = Record<SupportedChainId, string | null>;
|
|
7
|
-
interface SubgraphApiContext extends Omit<ApiContext, 'baseUrls'> {
|
|
8
|
-
baseUrls?: SubgraphApiBaseUrls;
|
|
9
|
-
}
|
|
10
|
-
type PartialSubgraphApiContext = Partial<SubgraphApiContext>;
|
|
11
|
-
/**
|
|
12
|
-
* CoW Protocol Production Subgraph API configuration.
|
|
13
|
-
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow}
|
|
14
|
-
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc}
|
|
15
|
-
*/
|
|
16
|
-
export declare const SUBGRAPH_PROD_CONFIG: SubgraphApiBaseUrls;
|
|
17
|
-
/**
|
|
18
|
-
* CoW Protocol Staging Subgraph API configuration.
|
|
19
|
-
* @deprecated
|
|
20
|
-
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow-staging}
|
|
21
|
-
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc-staging}
|
|
22
|
-
*/
|
|
23
|
-
export declare const SUBGRAPH_STAGING_CONFIG: SubgraphApiBaseUrls;
|
|
24
|
-
/**
|
|
25
|
-
* TheGraph API client for CoW Protocol.
|
|
26
|
-
*/
|
|
27
|
-
export declare class SubgraphApi {
|
|
28
|
-
API_NAME: string;
|
|
29
|
-
context: SubgraphApiContext;
|
|
30
|
-
/**
|
|
31
|
-
* Create a new CoW Protocol API instance.
|
|
32
|
-
* @param context Any properties of the {@link SubgraphApiContext} may be overridden by passing a {@link PartialSubgraphApiContext}.
|
|
33
|
-
*/
|
|
34
|
-
constructor(context?: PartialSubgraphApiContext);
|
|
35
|
-
/**
|
|
36
|
-
* Query the totals from TheGraph for the CoW Protocol.
|
|
37
|
-
* @param contextOverride Override the context for this call only.
|
|
38
|
-
* @returns The totals for the CoW Protocol.
|
|
39
|
-
*/
|
|
40
|
-
getTotals(contextOverride?: PartialSubgraphApiContext): Promise<TotalsQuery['totals'][0]>;
|
|
41
|
-
/**
|
|
42
|
-
* Query the volume over the last N days from TheGraph for the CoW Protocol.
|
|
43
|
-
* @param {number} days The number of days to query.
|
|
44
|
-
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
45
|
-
* @returns The volume for the last N days.
|
|
46
|
-
*/
|
|
47
|
-
getLastDaysVolume(days: number, contextOverride?: PartialSubgraphApiContext): Promise<LastDaysVolumeQuery>;
|
|
48
|
-
/**
|
|
49
|
-
* Query the volume over the last N hours from TheGraph for the CoW Protocol.
|
|
50
|
-
* @param {number} hours The number of hours to query.
|
|
51
|
-
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
52
|
-
* @returns The volume for the last N hours.
|
|
53
|
-
*/
|
|
54
|
-
getLastHoursVolume(hours: number, contextOverride?: PartialSubgraphApiContext): Promise<LastHoursVolumeQuery>;
|
|
55
|
-
/**
|
|
56
|
-
* Run a query against the CoW Protocol Subgraph.
|
|
57
|
-
* @param {string | DocumentNode} query GQL query string or DocumentNode.
|
|
58
|
-
* @param {Variables | undefined} variables To be passed to the query.
|
|
59
|
-
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
60
|
-
* @returns Results of the query.
|
|
61
|
-
* @throws {@link CowError} if the query fails.
|
|
62
|
-
*/
|
|
63
|
-
runQuery<T>(query: string | DocumentNode, variables?: Variables | undefined, contextOverride?: PartialSubgraphApiContext): Promise<T>;
|
|
64
|
-
/**
|
|
65
|
-
* Override parts of the context for a specific call.
|
|
66
|
-
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
67
|
-
* @returns {SubgraphApiContext} The context with the override applied.
|
|
68
|
-
*/
|
|
69
|
-
private getContextWithOverride;
|
|
70
|
-
/**
|
|
71
|
-
* Get the base URLs for the given environment.
|
|
72
|
-
* @param {CowEnv} env The environment to get the base URLs for.
|
|
73
|
-
* @returns {ApiBaseUrls} The base URLs for the given environment.
|
|
74
|
-
*/
|
|
75
|
-
private getEnvConfigs;
|
|
76
|
-
}
|
|
77
|
-
export {};
|
|
1
|
+
import { Variables } from 'graphql-request';
|
|
2
|
+
import { DocumentNode } from 'graphql/index';
|
|
3
|
+
import { SupportedChainId } from '../chains/types';
|
|
4
|
+
import { ApiContext } from '../common/types/config';
|
|
5
|
+
import { LastDaysVolumeQuery, LastHoursVolumeQuery, TotalsQuery } from './graphql';
|
|
6
|
+
type SubgraphApiBaseUrls = Record<SupportedChainId, string | null>;
|
|
7
|
+
interface SubgraphApiContext extends Omit<ApiContext, 'baseUrls'> {
|
|
8
|
+
baseUrls?: SubgraphApiBaseUrls;
|
|
9
|
+
}
|
|
10
|
+
type PartialSubgraphApiContext = Partial<SubgraphApiContext>;
|
|
11
|
+
/**
|
|
12
|
+
* CoW Protocol Production Subgraph API configuration.
|
|
13
|
+
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow}
|
|
14
|
+
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc}
|
|
15
|
+
*/
|
|
16
|
+
export declare const SUBGRAPH_PROD_CONFIG: SubgraphApiBaseUrls;
|
|
17
|
+
/**
|
|
18
|
+
* CoW Protocol Staging Subgraph API configuration.
|
|
19
|
+
* @deprecated
|
|
20
|
+
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow-staging}
|
|
21
|
+
* @see {@link https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc-staging}
|
|
22
|
+
*/
|
|
23
|
+
export declare const SUBGRAPH_STAGING_CONFIG: SubgraphApiBaseUrls;
|
|
24
|
+
/**
|
|
25
|
+
* TheGraph API client for CoW Protocol.
|
|
26
|
+
*/
|
|
27
|
+
export declare class SubgraphApi {
|
|
28
|
+
API_NAME: string;
|
|
29
|
+
context: SubgraphApiContext;
|
|
30
|
+
/**
|
|
31
|
+
* Create a new CoW Protocol API instance.
|
|
32
|
+
* @param context Any properties of the {@link SubgraphApiContext} may be overridden by passing a {@link PartialSubgraphApiContext}.
|
|
33
|
+
*/
|
|
34
|
+
constructor(context?: PartialSubgraphApiContext);
|
|
35
|
+
/**
|
|
36
|
+
* Query the totals from TheGraph for the CoW Protocol.
|
|
37
|
+
* @param contextOverride Override the context for this call only.
|
|
38
|
+
* @returns The totals for the CoW Protocol.
|
|
39
|
+
*/
|
|
40
|
+
getTotals(contextOverride?: PartialSubgraphApiContext): Promise<TotalsQuery['totals'][0]>;
|
|
41
|
+
/**
|
|
42
|
+
* Query the volume over the last N days from TheGraph for the CoW Protocol.
|
|
43
|
+
* @param {number} days The number of days to query.
|
|
44
|
+
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
45
|
+
* @returns The volume for the last N days.
|
|
46
|
+
*/
|
|
47
|
+
getLastDaysVolume(days: number, contextOverride?: PartialSubgraphApiContext): Promise<LastDaysVolumeQuery>;
|
|
48
|
+
/**
|
|
49
|
+
* Query the volume over the last N hours from TheGraph for the CoW Protocol.
|
|
50
|
+
* @param {number} hours The number of hours to query.
|
|
51
|
+
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
52
|
+
* @returns The volume for the last N hours.
|
|
53
|
+
*/
|
|
54
|
+
getLastHoursVolume(hours: number, contextOverride?: PartialSubgraphApiContext): Promise<LastHoursVolumeQuery>;
|
|
55
|
+
/**
|
|
56
|
+
* Run a query against the CoW Protocol Subgraph.
|
|
57
|
+
* @param {string | DocumentNode} query GQL query string or DocumentNode.
|
|
58
|
+
* @param {Variables | undefined} variables To be passed to the query.
|
|
59
|
+
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
60
|
+
* @returns Results of the query.
|
|
61
|
+
* @throws {@link CowError} if the query fails.
|
|
62
|
+
*/
|
|
63
|
+
runQuery<T>(query: string | DocumentNode, variables?: Variables | undefined, contextOverride?: PartialSubgraphApiContext): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Override parts of the context for a specific call.
|
|
66
|
+
* @param {PartialSubgraphApiContext} contextOverride Override the context for this call only.
|
|
67
|
+
* @returns {SubgraphApiContext} The context with the override applied.
|
|
68
|
+
*/
|
|
69
|
+
private getContextWithOverride;
|
|
70
|
+
/**
|
|
71
|
+
* Get the base URLs for the given environment.
|
|
72
|
+
* @param {CowEnv} env The environment to get the base URLs for.
|
|
73
|
+
* @returns {ApiBaseUrls} The base URLs for the given environment.
|
|
74
|
+
*/
|
|
75
|
+
private getEnvConfigs;
|
|
76
|
+
}
|
|
77
|
+
export {};
|