@cowprotocol/sdk-viem-adapter 0.2.2-beta.0 → 0.3.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/index.d.mts +5 -8
- package/dist/index.d.ts +5 -8
- package/dist/index.js +15 -1
- package/dist/index.mjs +19 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ const transport = http('YOUR_RPC_URL')
|
|
|
33
33
|
const provider = createPublicClient({ chain: sepolia, transport })
|
|
34
34
|
|
|
35
35
|
// Initialize the adapter
|
|
36
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
36
37
|
const adapter = new ViemAdapter({ provider, signer: account })
|
|
37
38
|
```
|
|
38
39
|
|
|
@@ -48,6 +49,7 @@ import { sepolia } from 'viem/chains'
|
|
|
48
49
|
const account = privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
49
50
|
const transport = http('YOUR_RPC_URL')
|
|
50
51
|
const provider = createPublicClient({ chain: sepolia, transport })
|
|
52
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
51
53
|
const adapter = new ViemAdapter({ provider, signer: account })
|
|
52
54
|
|
|
53
55
|
// Initialize the unified SDK
|
package/dist/index.d.mts
CHANGED
|
@@ -46,7 +46,8 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
46
46
|
getCreate2Address(from: Address, salt: Hex, bytecodeHash: Hex): `0x${string}`;
|
|
47
47
|
hexConcat(items: ReadonlyArray<Hex | number[]>): string;
|
|
48
48
|
formatBytes32String(text: string): string;
|
|
49
|
-
keccak256(data: Hex): string
|
|
49
|
+
keccak256(data: Hex): `0x${string}`;
|
|
50
|
+
sha256(data: Hex): Hex;
|
|
50
51
|
private bytesToHex;
|
|
51
52
|
private padBytes;
|
|
52
53
|
hexZeroPad(value: Hex, length: number): string;
|
|
@@ -55,6 +56,7 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
55
56
|
solidityPack(types: string[], values: ContractValue[]): string;
|
|
56
57
|
hashTypedData(domain: TypedDataDomain, types: Record<string, unknown>, data: Record<string, unknown>): string;
|
|
57
58
|
getChecksumAddress(address: Address): Address;
|
|
59
|
+
recoverAddress(hash: Hex, signature: Hex): Promise<Hex>;
|
|
58
60
|
encodeAbi(types: {
|
|
59
61
|
type: string;
|
|
60
62
|
name: string;
|
|
@@ -81,13 +83,7 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
81
83
|
name: string;
|
|
82
84
|
type: string;
|
|
83
85
|
}>>, value: Record<string, unknown>, signature: `0x${string}`): Promise<`0x${string}`>;
|
|
84
|
-
encodeFunction(abi:
|
|
85
|
-
name: string;
|
|
86
|
-
inputs: Array<{
|
|
87
|
-
type: string;
|
|
88
|
-
}>;
|
|
89
|
-
type: string;
|
|
90
|
-
}>, functionName: string, args: ContractValue[]): string;
|
|
86
|
+
encodeFunction(abi: Abi, functionName: string, args: ContractValue[]): string;
|
|
91
87
|
decodeFunctionData(abi: Array<{
|
|
92
88
|
name: string;
|
|
93
89
|
inputs: Array<{
|
|
@@ -166,6 +162,7 @@ interface ViemTypes extends AdapterTypes {
|
|
|
166
162
|
interface ViemAdapterOptions {
|
|
167
163
|
provider: PublicClient;
|
|
168
164
|
signer?: Account | PrivateKey;
|
|
165
|
+
walletClient?: WalletClient;
|
|
169
166
|
}
|
|
170
167
|
declare class ViemAdapter extends AbstractProviderAdapter<ViemTypes> {
|
|
171
168
|
private _publicClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,8 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
46
46
|
getCreate2Address(from: Address, salt: Hex, bytecodeHash: Hex): `0x${string}`;
|
|
47
47
|
hexConcat(items: ReadonlyArray<Hex | number[]>): string;
|
|
48
48
|
formatBytes32String(text: string): string;
|
|
49
|
-
keccak256(data: Hex): string
|
|
49
|
+
keccak256(data: Hex): `0x${string}`;
|
|
50
|
+
sha256(data: Hex): Hex;
|
|
50
51
|
private bytesToHex;
|
|
51
52
|
private padBytes;
|
|
52
53
|
hexZeroPad(value: Hex, length: number): string;
|
|
@@ -55,6 +56,7 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
55
56
|
solidityPack(types: string[], values: ContractValue[]): string;
|
|
56
57
|
hashTypedData(domain: TypedDataDomain, types: Record<string, unknown>, data: Record<string, unknown>): string;
|
|
57
58
|
getChecksumAddress(address: Address): Address;
|
|
59
|
+
recoverAddress(hash: Hex, signature: Hex): Promise<Hex>;
|
|
58
60
|
encodeAbi(types: {
|
|
59
61
|
type: string;
|
|
60
62
|
name: string;
|
|
@@ -81,13 +83,7 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
81
83
|
name: string;
|
|
82
84
|
type: string;
|
|
83
85
|
}>>, value: Record<string, unknown>, signature: `0x${string}`): Promise<`0x${string}`>;
|
|
84
|
-
encodeFunction(abi:
|
|
85
|
-
name: string;
|
|
86
|
-
inputs: Array<{
|
|
87
|
-
type: string;
|
|
88
|
-
}>;
|
|
89
|
-
type: string;
|
|
90
|
-
}>, functionName: string, args: ContractValue[]): string;
|
|
86
|
+
encodeFunction(abi: Abi, functionName: string, args: ContractValue[]): string;
|
|
91
87
|
decodeFunctionData(abi: Array<{
|
|
92
88
|
name: string;
|
|
93
89
|
inputs: Array<{
|
|
@@ -166,6 +162,7 @@ interface ViemTypes extends AdapterTypes {
|
|
|
166
162
|
interface ViemAdapterOptions {
|
|
167
163
|
provider: PublicClient;
|
|
168
164
|
signer?: Account | PrivateKey;
|
|
165
|
+
walletClient?: WalletClient;
|
|
169
166
|
}
|
|
170
167
|
declare class ViemAdapter extends AbstractProviderAdapter<ViemTypes> {
|
|
171
168
|
private _publicClient;
|
package/dist/index.js
CHANGED
|
@@ -282,6 +282,9 @@ var ViemUtils = class {
|
|
|
282
282
|
keccak256(data) {
|
|
283
283
|
return (0, import_viem2.keccak256)(data);
|
|
284
284
|
}
|
|
285
|
+
sha256(data) {
|
|
286
|
+
return (0, import_viem2.sha256)(data);
|
|
287
|
+
}
|
|
285
288
|
bytesToHex(bytes) {
|
|
286
289
|
return `0x${Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
287
290
|
}
|
|
@@ -320,6 +323,9 @@ var ViemUtils = class {
|
|
|
320
323
|
getChecksumAddress(address) {
|
|
321
324
|
return (0, import_viem2.getAddress)(address);
|
|
322
325
|
}
|
|
326
|
+
recoverAddress(hash, signature) {
|
|
327
|
+
return (0, import_viem2.recoverAddress)({ hash, signature });
|
|
328
|
+
}
|
|
323
329
|
encodeAbi(types, values) {
|
|
324
330
|
if (typeof types[0] === "string") {
|
|
325
331
|
return (0, import_viem2.encodeAbiParameters)(
|
|
@@ -335,7 +341,7 @@ var ViemUtils = class {
|
|
|
335
341
|
return (0, import_viem2.decodeAbiParameters)(types, data);
|
|
336
342
|
}
|
|
337
343
|
id(text) {
|
|
338
|
-
return (0, import_viem2.keccak256)((0, import_viem2.
|
|
344
|
+
return (0, import_viem2.keccak256)((0, import_viem2.toBytes)(text));
|
|
339
345
|
}
|
|
340
346
|
toBigIntish(value) {
|
|
341
347
|
if (typeof value === "number")
|
|
@@ -605,6 +611,8 @@ var ViemSignerAdapter = class extends import_sdk_common3.AbstractSigner {
|
|
|
605
611
|
confirmations
|
|
606
612
|
});
|
|
607
613
|
return {
|
|
614
|
+
from: receipt.from,
|
|
615
|
+
to: receipt.to,
|
|
608
616
|
transactionHash: receipt.transactionHash,
|
|
609
617
|
blockNumber: BigInt(receipt.blockNumber),
|
|
610
618
|
blockHash: receipt.blockHash,
|
|
@@ -729,6 +737,12 @@ var ViemAdapter = class extends import_sdk_common4.AbstractProviderAdapter {
|
|
|
729
737
|
if (options.signer) {
|
|
730
738
|
this.setSigner(options.signer);
|
|
731
739
|
}
|
|
740
|
+
if (options.walletClient) {
|
|
741
|
+
this._walletClient = options.walletClient;
|
|
742
|
+
const signerAdapter = new ViemSignerAdapter(this._walletClient);
|
|
743
|
+
signerAdapter.connect(this._publicClient);
|
|
744
|
+
this._signerAdapter = signerAdapter;
|
|
745
|
+
}
|
|
732
746
|
this.utils = new ViemUtils();
|
|
733
747
|
}
|
|
734
748
|
get signer() {
|
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,6 @@ import {
|
|
|
30
30
|
getAddress,
|
|
31
31
|
encodeAbiParameters,
|
|
32
32
|
decodeAbiParameters as decodeAbiParameters2,
|
|
33
|
-
stringToHex,
|
|
34
33
|
hexToBigInt,
|
|
35
34
|
slice,
|
|
36
35
|
parseAbi as parseAbi2,
|
|
@@ -44,7 +43,10 @@ import {
|
|
|
44
43
|
isAddress,
|
|
45
44
|
isHex,
|
|
46
45
|
parseUnits,
|
|
47
|
-
sliceHex
|
|
46
|
+
sliceHex,
|
|
47
|
+
toBytes,
|
|
48
|
+
sha256,
|
|
49
|
+
recoverAddress
|
|
48
50
|
} from "viem";
|
|
49
51
|
|
|
50
52
|
// src/ViemInterfaceWrapper.ts
|
|
@@ -303,6 +305,9 @@ var ViemUtils = class {
|
|
|
303
305
|
keccak256(data) {
|
|
304
306
|
return keccak256(data);
|
|
305
307
|
}
|
|
308
|
+
sha256(data) {
|
|
309
|
+
return sha256(data);
|
|
310
|
+
}
|
|
306
311
|
bytesToHex(bytes) {
|
|
307
312
|
return `0x${Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
308
313
|
}
|
|
@@ -341,6 +346,9 @@ var ViemUtils = class {
|
|
|
341
346
|
getChecksumAddress(address) {
|
|
342
347
|
return getAddress(address);
|
|
343
348
|
}
|
|
349
|
+
recoverAddress(hash, signature) {
|
|
350
|
+
return recoverAddress({ hash, signature });
|
|
351
|
+
}
|
|
344
352
|
encodeAbi(types, values) {
|
|
345
353
|
if (typeof types[0] === "string") {
|
|
346
354
|
return encodeAbiParameters(
|
|
@@ -356,7 +364,7 @@ var ViemUtils = class {
|
|
|
356
364
|
return decodeAbiParameters2(types, data);
|
|
357
365
|
}
|
|
358
366
|
id(text) {
|
|
359
|
-
return keccak256(
|
|
367
|
+
return keccak256(toBytes(text));
|
|
360
368
|
}
|
|
361
369
|
toBigIntish(value) {
|
|
362
370
|
if (typeof value === "number")
|
|
@@ -629,6 +637,8 @@ var ViemSignerAdapter = class extends AbstractSigner {
|
|
|
629
637
|
confirmations
|
|
630
638
|
});
|
|
631
639
|
return {
|
|
640
|
+
from: receipt.from,
|
|
641
|
+
to: receipt.to,
|
|
632
642
|
transactionHash: receipt.transactionHash,
|
|
633
643
|
blockNumber: BigInt(receipt.blockNumber),
|
|
634
644
|
blockHash: receipt.blockHash,
|
|
@@ -753,6 +763,12 @@ var ViemAdapter = class extends AbstractProviderAdapter {
|
|
|
753
763
|
if (options.signer) {
|
|
754
764
|
this.setSigner(options.signer);
|
|
755
765
|
}
|
|
766
|
+
if (options.walletClient) {
|
|
767
|
+
this._walletClient = options.walletClient;
|
|
768
|
+
const signerAdapter = new ViemSignerAdapter(this._walletClient);
|
|
769
|
+
signerAdapter.connect(this._publicClient);
|
|
770
|
+
this._signerAdapter = signerAdapter;
|
|
771
|
+
}
|
|
756
772
|
this.utils = new ViemUtils();
|
|
757
773
|
}
|
|
758
774
|
get signer() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-viem-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Viem adapter for CoW Protocol SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@cowprotocol/sdk-common": "0.
|
|
16
|
+
"@cowprotocol/sdk-common": "0.4.0"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"viem": "^2.28.4"
|