@cowprotocol/sdk-trading 0.1.0-monorepo.2 → 0.2.0-beta.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 CHANGED
@@ -64,13 +64,19 @@ You need:
64
64
 
65
65
  ```typescript
66
66
  import { SupportedChainId, OrderKind, TradeParameters, TradingSdk } from '@cowprotocol/sdk-trading'
67
- import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
68
- import { JsonRpcProvider, Wallet } from 'ethers'
69
-
70
- // Configure the adapter
71
- const provider = new JsonRpcProvider('YOUR_RPC_URL')
72
- const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
73
- const adapter = new EthersV6Adapter({ provider, signer: wallet })
67
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
68
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
69
+ import { sepolia } from 'viem/chains'
70
+
71
+ // There are EthersV5Adapter and EthersV6Adapter as well
72
+ // @cowprotocol/sdk-ethers-v5-adapter, @cowprotocol/sdk-ethers-v6-adapter
73
+ const adapter = new ViemAdapter({
74
+ provider: createPublicClient({
75
+ chain: sepolia,
76
+ transport: http('YOUR_RPC_URL')
77
+ }),
78
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
79
+ })
74
80
 
75
81
  // Initialize the SDK
76
82
  const sdk = new TradingSdk(
@@ -102,13 +108,17 @@ console.log('Order created, id: ', orderId)
102
108
 
103
109
  ```typescript
104
110
  import { CowSdk, SupportedChainId, OrderKind, TradeParameters } from '@cowprotocol/cow-sdk'
105
- import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
106
- import { JsonRpcProvider, Wallet } from 'ethers'
107
-
108
- // Configure the adapter
109
- const provider = new JsonRpcProvider('YOUR_RPC_URL')
110
- const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
111
- const adapter = new EthersV6Adapter({ provider, signer: wallet })
111
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
112
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
113
+ import { sepolia } from 'viem/chains'
114
+
115
+ const adapter = new ViemAdapter({
116
+ provider: createPublicClient({
117
+ chain: sepolia,
118
+ transport: http('YOUR_RPC_URL')
119
+ }),
120
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
121
+ })
112
122
 
113
123
  // Initialize the unified SDK
114
124
  const sdk = new CowSdk({
@@ -148,15 +158,26 @@ const sdk = new CowSdk({
148
158
  // Other file:
149
159
  import { TradingSdk } from '@cowprotocol/cow-sdk'
150
160
  // parameters without passing the adapter. the adapter will be controlled by the umbrella
151
- const trading = TradingSdk(...)
161
+ const trading = new TradingSdk(...)
152
162
  ```
153
163
 
154
164
  ### Options
155
165
 
156
- For detailed information about trading steps you can enable the SDK logging and configure UTM tracking:
166
+ For detailed information about trading steps you can enable the SDK logging:
157
167
 
158
168
  ```typescript
159
169
  import { SupportedChainId, TradingSdk, TradingSdkOptions } from '@cowprotocol/cow-sdk'
170
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
171
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
172
+ import { sepolia } from 'viem/chains'
173
+
174
+ const adapter = new ViemAdapter({
175
+ provider: createPublicClient({
176
+ chain: sepolia,
177
+ transport: http('YOUR_RPC_URL')
178
+ }),
179
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
180
+ })
160
181
 
161
182
  const traderParams = {
162
183
  chainId: SupportedChainId.SEPOLIA,
@@ -166,11 +187,10 @@ const traderParams = {
166
187
 
167
188
  const sdkOptions: TradingSdkOptions = {
168
189
  enableLogging: true, // enables detailed logging of trading steps
169
- utmContent: '🐮 moo-ving to defi 🐮', // custom UTM content for tracking
170
190
  disableUtm: false, // set to true to disable UTM tracking completely
171
191
  }
172
192
 
173
- const sdk = new TradingSdk(traderParams, sdkOptions)
193
+ const sdk = new TradingSdk(traderParams, sdkOptions, adapter)
174
194
  ```
175
195
 
176
196
  ### getQuote
@@ -195,12 +215,23 @@ It can be used to create an order from the received quote.
195
215
 
196
216
  ```typescript
197
217
  import { SupportedChainId, OrderKind, TradeParameters, TradingSdk } from '@cowprotocol/cow-sdk'
218
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
219
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
220
+ import { sepolia } from 'viem/chains'
221
+
222
+ const adapter = new ViemAdapter({
223
+ provider: createPublicClient({
224
+ chain: sepolia,
225
+ transport: http('YOUR_RPC_URL')
226
+ }),
227
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
228
+ })
198
229
 
199
230
  // Proper adapter initialization (see setup example above)
200
231
  const sdk = new TradingSdk({
201
232
  chainId: SupportedChainId.SEPOLIA,
202
233
  appCode: '<YOUR_APP_CODE>',
203
- })
234
+ }, {}, adapter)
204
235
 
205
236
  const parameters: TradeParameters = {
206
237
  kind: OrderKind.BUY,
@@ -241,12 +272,23 @@ The parameters required are:
241
272
 
242
273
  ```typescript
243
274
  import { SupportedChainId, OrderKind, TradeParameters, TradingSdk } from '@cowprotocol/cow-sdk'
275
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
276
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
277
+ import { sepolia } from 'viem/chains'
278
+
279
+ const adapter = new ViemAdapter({
280
+ provider: createPublicClient({
281
+ chain: sepolia,
282
+ transport: http('YOUR_RPC_URL')
283
+ }),
284
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
285
+ })
244
286
 
245
287
  // Proper adapter initialization (see setup example above)
246
288
  const sdk = new TradingSdk({
247
289
  chainId: SupportedChainId.SEPOLIA,
248
290
  appCode: '<YOUR_APP_CODE>',
249
- })
291
+ }, {}, adapter)
250
292
 
251
293
  const parameters: TradeParameters = {
252
294
  kind: OrderKind.BUY,
@@ -283,12 +325,23 @@ And optional parameters:
283
325
 
284
326
  ```typescript
285
327
  import { SupportedChainId, OrderKind, LimitTradeParameters, TradingSdk } from '@cowprotocol/cow-sdk'
328
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
329
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
330
+ import { sepolia } from 'viem/chains'
331
+
332
+ const adapter = new ViemAdapter({
333
+ provider: createPublicClient({
334
+ chain: sepolia,
335
+ transport: http('YOUR_RPC_URL')
336
+ }),
337
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
338
+ })
286
339
 
287
340
  // Proper adapter initialization (see setup example above)
288
341
  const sdk = new TradingSdk({
289
342
  chainId: SupportedChainId.SEPOLIA,
290
343
  appCode: '<YOUR_APP_CODE>',
291
- })
344
+ }, {}, adapter)
292
345
 
293
346
  const limitOrderParameters: LimitTradeParameters = {
294
347
  kind: OrderKind.BUY,
@@ -316,12 +369,23 @@ But if you need more flexible way to create an order to sell native token, you c
316
369
 
317
370
  ```typescript
318
371
  import { SupportedChainId, OrderKind, TradeParameters, TradingSdk } from '@cowprotocol/cow-sdk'
372
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
373
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
374
+ import { sepolia } from 'viem/chains'
375
+
376
+ const adapter = new ViemAdapter({
377
+ provider: createPublicClient({
378
+ chain: sepolia,
379
+ transport: http('YOUR_RPC_URL')
380
+ }),
381
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
382
+ })
319
383
 
320
384
  // Proper adapter initialization (see setup example above)
321
385
  const sdk = new TradingSdk({
322
386
  chainId: SupportedChainId.SEPOLIA,
323
387
  appCode: '<YOUR_APP_CODE>',
324
- })
388
+ }, {}, adapter)
325
389
 
326
390
  const parameters: TradeParameters = {
327
391
  kind: OrderKind.BUY,
@@ -353,12 +417,23 @@ import {
353
417
  SigningScheme,
354
418
  TradingSdk,
355
419
  } from '@cowprotocol/cow-sdk'
420
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
421
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
422
+ import { sepolia } from 'viem/chains'
423
+
424
+ const adapter = new ViemAdapter({
425
+ provider: createPublicClient({
426
+ chain: sepolia,
427
+ transport: http('YOUR_RPC_URL')
428
+ }),
429
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
430
+ })
356
431
 
357
432
  // Proper adapter initialization (see setup example above)
358
433
  const sdk = new TradingSdk({
359
434
  chainId: SupportedChainId.SEPOLIA,
360
435
  appCode: '<YOUR_APP_CODE>',
361
- })
436
+ }, {}, adapter)
362
437
 
363
438
  const parameters: TradeParameters = {
364
439
  kind: OrderKind.BUY,
@@ -390,12 +465,23 @@ And then you need to send a transaction from `getPreSignTransaction` result in o
390
465
 
391
466
  ```typescript
392
467
  import { SupportedChainId, OrderKind, TradeParameters, TradingSdk } from '@cowprotocol/cow-sdk'
468
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
469
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
470
+ import { sepolia } from 'viem/chains'
471
+
472
+ const adapter = new ViemAdapter({
473
+ provider: createPublicClient({
474
+ chain: sepolia,
475
+ transport: http('YOUR_RPC_URL')
476
+ }),
477
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
478
+ })
393
479
 
394
480
  // Proper adapter initialization (see setup example above)
395
481
  const sdk = new TradingSdk({
396
482
  chainId: SupportedChainId.SEPOLIA,
397
483
  appCode: '<YOUR_APP_CODE>',
398
- })
484
+ }, {}, adapter)
399
485
 
400
486
  const parameters: TradeParameters = {
401
487
  kind: OrderKind.BUY,
@@ -432,12 +518,23 @@ import {
432
518
  SigningScheme,
433
519
  TradingSdk,
434
520
  } from '@cowprotocol/cow-sdk'
521
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
522
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
523
+ import { sepolia } from 'viem/chains'
524
+
525
+ const adapter = new ViemAdapter({
526
+ provider: createPublicClient({
527
+ chain: sepolia,
528
+ transport: http('YOUR_RPC_URL')
529
+ }),
530
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
531
+ })
435
532
 
436
533
  // Proper adapter initialization (see setup example above)
437
534
  const sdk = new TradingSdk({
438
535
  chainId: SupportedChainId.SEPOLIA,
439
536
  appCode: '<YOUR_APP_CODE>',
440
- })
537
+ }, {}, adapter)
441
538
 
442
539
  const smartContractWalletAddress = '0x<smartContractWalletAddress>'
443
540
 
@@ -486,12 +583,23 @@ See `TradeOptionalParameters` type for more details.
486
583
 
487
584
  ```typescript
488
585
  import { SupportedChainId, OrderKind, TradeParameters, TradingSdk } from '@cowprotocol/cow-sdk'
586
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
587
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
588
+ import { sepolia } from 'viem/chains'
589
+
590
+ const adapter = new ViemAdapter({
591
+ provider: createPublicClient({
592
+ chain: sepolia,
593
+ transport: http('YOUR_RPC_URL')
594
+ }),
595
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
596
+ })
489
597
 
490
598
  // Proper adapter initialization (see setup example above)
491
599
  const sdk = new TradingSdk({
492
600
  chainId: SupportedChainId.SEPOLIA,
493
601
  appCode: '<YOUR_APP_CODE>',
494
- })
602
+ }, {}, adapter)
495
603
 
496
604
  const parameters: TradeParameters = {
497
605
  kind: OrderKind.BUY,
@@ -532,12 +640,23 @@ import {
532
640
  SwapAdvancedSettings,
533
641
  PriceQuality,
534
642
  } from '@cowprotocol/cow-sdk'
643
+ import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
644
+ import { createPublicClient, http, privateKeyToAccount } from 'viem'
645
+ import { sepolia } from 'viem/chains'
646
+
647
+ const adapter = new ViemAdapter({
648
+ provider: createPublicClient({
649
+ chain: sepolia,
650
+ transport: http('YOUR_RPC_URL')
651
+ }),
652
+ signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
653
+ })
535
654
 
536
655
  // Proper adapter initialization (see setup example above)
537
656
  const sdk = new TradingSdk({
538
657
  chainId: SupportedChainId.SEPOLIA,
539
658
  appCode: '<YOUR_APP_CODE>',
540
- })
659
+ }, {}, adapter)
541
660
 
542
661
  const parameters: TradeParameters = {
543
662
  kind: OrderKind.BUY,
package/dist/index.js CHANGED
@@ -836,7 +836,10 @@ var TradingSdk = class {
836
836
  tradeParameters: getTradeParametersAfterQuote({
837
837
  quoteParameters: quoteResults.result.tradeParameters,
838
838
  sellToken: params.sellToken
839
- })
839
+ }),
840
+ // It's important to get a fresh instance of the signer
841
+ // Because quote might be called with another signer
842
+ signer: (0, import_sdk_common12.getGlobalAdapter)().signer
840
843
  }
841
844
  },
842
845
  advancedSettings2
package/dist/index.mjs CHANGED
@@ -801,7 +801,10 @@ var TradingSdk = class {
801
801
  tradeParameters: getTradeParametersAfterQuote({
802
802
  quoteParameters: quoteResults.result.tradeParameters,
803
803
  sellToken: params.sellToken
804
- })
804
+ }),
805
+ // It's important to get a fresh instance of the signer
806
+ // Because quote might be called with another signer
807
+ signer: getGlobalAdapter6().signer
805
808
  }
806
809
  },
807
810
  advancedSettings2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/sdk-trading",
3
- "version": "0.1.0-monorepo.2",
3
+ "version": "0.2.0-beta.0",
4
4
  "description": "CowProtocol trading",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -21,7 +21,8 @@
21
21
  "test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
22
22
  "test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
23
23
  "typecheck": "tsc --noEmit",
24
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
24
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
25
+ "prepublishOnly": "npm run build"
25
26
  },
26
27
  "devDependencies": {
27
28
  "@cow-sdk/typescript-config": "workspace:*",