@cowprotocol/sdk-trading 0.2.6-beta.0 → 0.3.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 +5 -57
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +9 -1
- package/dist/index.mjs +9 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -75,6 +75,7 @@ const adapter = new ViemAdapter({
|
|
|
75
75
|
chain: sepolia,
|
|
76
76
|
transport: http('YOUR_RPC_URL')
|
|
77
77
|
}),
|
|
78
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
78
79
|
signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
79
80
|
})
|
|
80
81
|
|
|
@@ -104,63 +105,6 @@ const orderId = await sdk.postSwapOrder(parameters)
|
|
|
104
105
|
console.log('Order created, id: ', orderId)
|
|
105
106
|
```
|
|
106
107
|
|
|
107
|
-
### Usage with Umbrella SDK
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
import { CowSdk, SupportedChainId, OrderKind, TradeParameters } from '@cowprotocol/cow-sdk'
|
|
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
|
-
})
|
|
122
|
-
|
|
123
|
-
// Initialize the unified SDK
|
|
124
|
-
const sdk = new CowSdk({
|
|
125
|
-
chainId: SupportedChainId.SEPOLIA,
|
|
126
|
-
adapter,
|
|
127
|
-
tradingOptions: {
|
|
128
|
-
traderParams: {
|
|
129
|
-
appCode: 'YOUR_APP_CODE',
|
|
130
|
-
},
|
|
131
|
-
options: {
|
|
132
|
-
chainId: SupportedChainId.SEPOLIA,
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
// Define trade parameters
|
|
138
|
-
const parameters: TradeParameters = {
|
|
139
|
-
kind: OrderKind.BUY,
|
|
140
|
-
sellToken: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14',
|
|
141
|
-
sellTokenDecimals: 18,
|
|
142
|
-
buyToken: '0x0625afb445c3b6b7b929342a04a22599fd5dbb59',
|
|
143
|
-
buyTokenDecimals: 18,
|
|
144
|
-
amount: '120000000000000000',
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Post the order
|
|
148
|
-
const orderId = await sdk.trading.postSwapOrder(parameters)
|
|
149
|
-
console.log('Order created, id: ', orderId)
|
|
150
|
-
|
|
151
|
-
// Or you can just initialize the SDK and import the trading class in another file:
|
|
152
|
-
// you don't necessarily need to use the trading from inside of CowSdk:
|
|
153
|
-
//...
|
|
154
|
-
const sdk = new CowSdk({
|
|
155
|
-
chainId: SupportedChainId.SEPOLIA,
|
|
156
|
-
adapter,
|
|
157
|
-
})
|
|
158
|
-
// Other file:
|
|
159
|
-
import { TradingSdk } from '@cowprotocol/cow-sdk'
|
|
160
|
-
// parameters without passing the adapter. the adapter will be controlled by the umbrella
|
|
161
|
-
const trading = new TradingSdk(...)
|
|
162
|
-
```
|
|
163
|
-
|
|
164
108
|
### Options
|
|
165
109
|
|
|
166
110
|
For detailed information about trading steps you can enable the SDK logging:
|
|
@@ -176,6 +120,7 @@ const adapter = new ViemAdapter({
|
|
|
176
120
|
chain: sepolia,
|
|
177
121
|
transport: http('YOUR_RPC_URL')
|
|
178
122
|
}),
|
|
123
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
179
124
|
signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
180
125
|
})
|
|
181
126
|
|
|
@@ -224,6 +169,7 @@ const adapter = new ViemAdapter({
|
|
|
224
169
|
chain: sepolia,
|
|
225
170
|
transport: http('YOUR_RPC_URL')
|
|
226
171
|
}),
|
|
172
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
227
173
|
signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
228
174
|
})
|
|
229
175
|
|
|
@@ -281,6 +227,7 @@ const adapter = new ViemAdapter({
|
|
|
281
227
|
chain: sepolia,
|
|
282
228
|
transport: http('YOUR_RPC_URL')
|
|
283
229
|
}),
|
|
230
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
284
231
|
signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
285
232
|
})
|
|
286
233
|
|
|
@@ -334,6 +281,7 @@ const adapter = new ViemAdapter({
|
|
|
334
281
|
chain: sepolia,
|
|
335
282
|
transport: http('YOUR_RPC_URL')
|
|
336
283
|
}),
|
|
284
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
337
285
|
signer: privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
338
286
|
})
|
|
339
287
|
|
package/dist/index.d.mts
CHANGED
|
@@ -240,8 +240,6 @@ type WithPartialTraderParams<T> = T & Partial<TraderParameters>;
|
|
|
240
240
|
interface TradingSdkOptions {
|
|
241
241
|
enableLogging: boolean;
|
|
242
242
|
orderBookApi: OrderBookApi;
|
|
243
|
-
utmContent?: string;
|
|
244
|
-
disableUtm?: boolean;
|
|
245
243
|
}
|
|
246
244
|
declare class TradingSdk {
|
|
247
245
|
traderParams: Partial<TraderParameters>;
|
package/dist/index.d.ts
CHANGED
|
@@ -240,8 +240,6 @@ type WithPartialTraderParams<T> = T & Partial<TraderParameters>;
|
|
|
240
240
|
interface TradingSdkOptions {
|
|
241
241
|
enableLogging: boolean;
|
|
242
242
|
orderBookApi: OrderBookApi;
|
|
243
|
-
utmContent?: string;
|
|
244
|
-
disableUtm?: boolean;
|
|
245
243
|
}
|
|
246
244
|
declare class TradingSdk {
|
|
247
245
|
traderParams: Partial<TraderParameters>;
|
package/dist/index.js
CHANGED
|
@@ -820,6 +820,14 @@ var TradingSdk = class {
|
|
|
820
820
|
}
|
|
821
821
|
setTraderParams(params) {
|
|
822
822
|
this.traderParams = { ...this.traderParams, ...params };
|
|
823
|
+
if (this.options.orderBookApi) {
|
|
824
|
+
if (params.chainId) {
|
|
825
|
+
this.options.orderBookApi.context.chainId = params.chainId;
|
|
826
|
+
}
|
|
827
|
+
if (params.env) {
|
|
828
|
+
this.options.orderBookApi.context.env = params.env;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
823
831
|
return this;
|
|
824
832
|
}
|
|
825
833
|
async getQuote(params, advancedSettings) {
|
|
@@ -909,7 +917,7 @@ var TradingSdk = class {
|
|
|
909
917
|
const { chainId, signer, appCode, env } = params;
|
|
910
918
|
const traderParams = {
|
|
911
919
|
chainId: chainId || this.traderParams.chainId,
|
|
912
|
-
signer: signer || this.traderParams.signer,
|
|
920
|
+
signer: signer || this.traderParams.signer || (0, import_sdk_common12.getGlobalAdapter)().signer,
|
|
913
921
|
appCode: appCode || this.traderParams.appCode,
|
|
914
922
|
env: env || this.traderParams.env
|
|
915
923
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -785,6 +785,14 @@ var TradingSdk = class {
|
|
|
785
785
|
}
|
|
786
786
|
setTraderParams(params) {
|
|
787
787
|
this.traderParams = { ...this.traderParams, ...params };
|
|
788
|
+
if (this.options.orderBookApi) {
|
|
789
|
+
if (params.chainId) {
|
|
790
|
+
this.options.orderBookApi.context.chainId = params.chainId;
|
|
791
|
+
}
|
|
792
|
+
if (params.env) {
|
|
793
|
+
this.options.orderBookApi.context.env = params.env;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
788
796
|
return this;
|
|
789
797
|
}
|
|
790
798
|
async getQuote(params, advancedSettings) {
|
|
@@ -874,7 +882,7 @@ var TradingSdk = class {
|
|
|
874
882
|
const { chainId, signer, appCode, env } = params;
|
|
875
883
|
const traderParams = {
|
|
876
884
|
chainId: chainId || this.traderParams.chainId,
|
|
877
|
-
signer: signer || this.traderParams.signer,
|
|
885
|
+
signer: signer || this.traderParams.signer || getGlobalAdapter6().signer,
|
|
878
886
|
appCode: appCode || this.traderParams.appCode,
|
|
879
887
|
env: env || this.traderParams.env
|
|
880
888
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-trading",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-beta.0",
|
|
4
4
|
"description": "CowProtocol trading",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -28,19 +28,19 @@
|
|
|
28
28
|
"viem": "^2.28.4",
|
|
29
29
|
"ts-jest": "^29.0.0",
|
|
30
30
|
"tsx": "^4.19.4",
|
|
31
|
-
"@cowprotocol/sdk-ethers-v5-adapter": "0.2.2-beta.0",
|
|
32
31
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
33
|
-
"@cowprotocol/sdk-ethers-
|
|
34
|
-
"@cowprotocol/sdk-viem-adapter": "0.
|
|
32
|
+
"@cowprotocol/sdk-ethers-v5-adapter": "0.2.3-beta.0",
|
|
33
|
+
"@cowprotocol/sdk-viem-adapter": "0.3.0-beta.0",
|
|
34
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "0.2.3-beta.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"deepmerge": "^4.3.1",
|
|
38
|
-
"@cowprotocol/sdk-config": "0.3.
|
|
39
|
-
"@cowprotocol/sdk-
|
|
40
|
-
"@cowprotocol/sdk-
|
|
41
|
-
"@cowprotocol/sdk-order-signing": "0.2.
|
|
42
|
-
"@cowprotocol/sdk-contracts-ts": "2.
|
|
43
|
-
"@cowprotocol/sdk-
|
|
38
|
+
"@cowprotocol/sdk-config": "0.3.3-beta.0",
|
|
39
|
+
"@cowprotocol/sdk-app-data": "4.1.5-beta.0",
|
|
40
|
+
"@cowprotocol/sdk-order-book": "0.3.0-beta.0",
|
|
41
|
+
"@cowprotocol/sdk-order-signing": "0.2.6-beta.0",
|
|
42
|
+
"@cowprotocol/sdk-contracts-ts": "2.2.0-beta.0",
|
|
43
|
+
"@cowprotocol/sdk-common": "0.4.0-beta.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|