@cowprotocol/sdk-viem-adapter 0.2.0-beta.0 → 0.2.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 +14 -10
- package/dist/index.d.mts +28 -46
- package/dist/index.d.ts +28 -46
- package/dist/index.js +18 -10
- package/dist/index.mjs +23 -13
- package/package.json +12 -13
package/README.md
CHANGED
|
@@ -24,15 +24,17 @@ pnpm add @cowprotocol/sdk-viem-adapter
|
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
|
|
27
|
-
import { http,
|
|
27
|
+
import { http, createPublicClient, privateKeyToAccount } from 'viem'
|
|
28
28
|
import { sepolia } from 'viem/chains'
|
|
29
29
|
|
|
30
30
|
// Create account and transport
|
|
31
31
|
const account = privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
32
32
|
const transport = http('YOUR_RPC_URL')
|
|
33
|
+
const provider = createPublicClient({ chain: sepolia, transport })
|
|
33
34
|
|
|
34
35
|
// Initialize the adapter
|
|
35
|
-
|
|
36
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
37
|
+
const adapter = new ViemAdapter({ provider, signer: account })
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
### Using with CoW SDK
|
|
@@ -40,13 +42,15 @@ const adapter = new ViemAdapter({ chain: sepolia, transport, account })
|
|
|
40
42
|
```typescript
|
|
41
43
|
import { CowSdk, SupportedChainId } from '@cowprotocol/cow-sdk'
|
|
42
44
|
import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
|
|
43
|
-
import { http, privateKeyToAccount } from 'viem'
|
|
45
|
+
import { http, createPublicClient, privateKeyToAccount } from 'viem'
|
|
44
46
|
import { sepolia } from 'viem/chains'
|
|
45
47
|
|
|
46
48
|
// Configure the adapter
|
|
47
49
|
const account = privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
48
50
|
const transport = http('YOUR_RPC_URL')
|
|
49
|
-
const
|
|
51
|
+
const provider = createPublicClient({ chain: sepolia, transport })
|
|
52
|
+
// You also can set `walletClient` instead of `signer` using `useWalletClient` from wagmi
|
|
53
|
+
const adapter = new ViemAdapter({ provider, signer: account })
|
|
50
54
|
|
|
51
55
|
// Initialize the unified SDK
|
|
52
56
|
const sdk = new CowSdk({
|
|
@@ -72,12 +76,13 @@ const orders = await sdk.orderBook.getOrders({ owner: address })
|
|
|
72
76
|
```typescript
|
|
73
77
|
import { TradingSdk } from '@cowprotocol/sdk-trading'
|
|
74
78
|
import { ViemAdapter } from '@cowprotocol/sdk-viem-adapter'
|
|
75
|
-
import { http, privateKeyToAccount } from 'viem'
|
|
79
|
+
import { http, createPublicClient, privateKeyToAccount } from 'viem'
|
|
76
80
|
import { sepolia } from 'viem/chains'
|
|
77
81
|
|
|
78
82
|
const account = privateKeyToAccount('YOUR_PRIVATE_KEY' as `0x${string}`)
|
|
79
83
|
const transport = http('YOUR_RPC_URL')
|
|
80
|
-
const
|
|
84
|
+
const provider = createPublicClient({ chain: sepolia, transport })
|
|
85
|
+
const adapter = new ViemAdapter({ provider, signer: account })
|
|
81
86
|
|
|
82
87
|
const trading = new TradingSdk({ appCode: 'YOUR_APP_CODE' }, { chainId: SupportedChainId.SEPOLIA }, adapter)
|
|
83
88
|
|
|
@@ -89,14 +94,13 @@ const orderId = await trading.postSwapOrder(parameters)
|
|
|
89
94
|
### Constructor
|
|
90
95
|
|
|
91
96
|
```typescript
|
|
92
|
-
new ViemAdapter({
|
|
97
|
+
new ViemAdapter({ provider, signer })
|
|
93
98
|
```
|
|
94
99
|
|
|
95
100
|
#### Parameters
|
|
96
101
|
|
|
97
|
-
- `
|
|
98
|
-
- `
|
|
99
|
-
- `account` - A viem account instance
|
|
102
|
+
- `provider` - A viem PublicClient instance
|
|
103
|
+
- `signer` - A viem account instance or private key
|
|
100
104
|
|
|
101
105
|
### Methods
|
|
102
106
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
|
-
import { Abi, Address, Hex,
|
|
3
|
-
import { GenericContractInterface, Log, AdapterUtils, AbstractSigner, TransactionParams, TransactionResponse, AdapterTypes, PrivateKey, AbstractProviderAdapter, TransactionReceipt, GenericContract } from '@cowprotocol/sdk-common';
|
|
2
|
+
import { Abi, Address, Hex, PublicClient, WalletClient, Account, Transport, TypedDataDomain as TypedDataDomain$1, TypedDataParameter, BlockTag, Block } from 'viem';
|
|
3
|
+
import { GenericContractInterface, ContractValue, Log, AdapterUtils, TypedDataDomain, ParamType, AbstractSigner, TransactionParams, TransactionResponse, AdapterTypes, PrivateKey, AbstractProviderAdapter, TransactionReceipt, GenericContract } from '@cowprotocol/sdk-common';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Interface wrapper that makes viem interfaces behave exactly like ethers v5 interfaces
|
|
@@ -20,7 +20,7 @@ declare class ViemInterfaceWrapper implements GenericContractInterface {
|
|
|
20
20
|
/**
|
|
21
21
|
* Encode function data using viem
|
|
22
22
|
*/
|
|
23
|
-
encodeFunctionData(name: string, args:
|
|
23
|
+
encodeFunctionData(name: string, args: ContractValue[]): string;
|
|
24
24
|
parseLog(event: Log): {
|
|
25
25
|
args: unknown;
|
|
26
26
|
} | null;
|
|
@@ -37,21 +37,7 @@ declare class ViemInterfaceWrapper implements GenericContractInterface {
|
|
|
37
37
|
* Get ABI
|
|
38
38
|
*/
|
|
39
39
|
get abi(): any[];
|
|
40
|
-
decodeFunctionData(functionName: string, data: string):
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
declare class ViemParamType {
|
|
44
|
-
name: string;
|
|
45
|
-
type: string;
|
|
46
|
-
baseType: string;
|
|
47
|
-
indexed: boolean;
|
|
48
|
-
components: ViemParamType[];
|
|
49
|
-
arrayLength: number;
|
|
50
|
-
arrayChildren: ViemParamType | null;
|
|
51
|
-
constructor(type: string);
|
|
52
|
-
private normalizeType;
|
|
53
|
-
private parseBaseType;
|
|
54
|
-
private getArrayElementType;
|
|
40
|
+
decodeFunctionData(functionName: string, data: string): ContractValue[];
|
|
55
41
|
}
|
|
56
42
|
|
|
57
43
|
declare class ViemUtils implements AdapterUtils {
|
|
@@ -66,17 +52,19 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
66
52
|
hexZeroPad(value: Hex, length: number): string;
|
|
67
53
|
arrayify(hexString: string): Uint8Array;
|
|
68
54
|
hexlify(value: `0x${string}` | Uint8Array): string;
|
|
69
|
-
solidityPack(types: string[], values:
|
|
55
|
+
solidityPack(types: string[], values: ContractValue[]): string;
|
|
70
56
|
hashTypedData(domain: TypedDataDomain, types: Record<string, unknown>, data: Record<string, unknown>): string;
|
|
71
57
|
getChecksumAddress(address: Address): Address;
|
|
72
58
|
encodeAbi(types: {
|
|
73
59
|
type: string;
|
|
74
60
|
name: string;
|
|
75
|
-
}[] | string[], values:
|
|
76
|
-
decodeAbi(types:
|
|
61
|
+
}[] | string[], values: ContractValue[]): `0x${string}`;
|
|
62
|
+
decodeAbi(types: (string | {
|
|
63
|
+
type: string;
|
|
64
|
+
name: string;
|
|
65
|
+
})[], data: `0x${string}`): unknown[];
|
|
77
66
|
id(text: string): `0x${string}`;
|
|
78
67
|
toBigIntish(value: `0x${string}` | string | number): bigint;
|
|
79
|
-
newBigintish(value: number | string): bigint;
|
|
80
68
|
hexDataSlice(data: `0x${string}`, offset: number, endOffset?: number): `0x${string}`;
|
|
81
69
|
joinSignature(signature: {
|
|
82
70
|
r: string;
|
|
@@ -93,13 +81,7 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
93
81
|
name: string;
|
|
94
82
|
type: string;
|
|
95
83
|
}>>, value: Record<string, unknown>, signature: `0x${string}`): Promise<`0x${string}`>;
|
|
96
|
-
encodeFunction(abi:
|
|
97
|
-
name: string;
|
|
98
|
-
inputs: Array<{
|
|
99
|
-
type: string;
|
|
100
|
-
}>;
|
|
101
|
-
type: string;
|
|
102
|
-
}>, functionName: string, args: unknown[]): string;
|
|
84
|
+
encodeFunction(abi: Abi, functionName: string, args: ContractValue[]): string;
|
|
103
85
|
decodeFunctionData(abi: Array<{
|
|
104
86
|
name: string;
|
|
105
87
|
inputs: Array<{
|
|
@@ -108,18 +90,21 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
108
90
|
type: string;
|
|
109
91
|
}>, functionName: string, data: string): any;
|
|
110
92
|
toNumber(value: bigint): number;
|
|
111
|
-
solidityKeccak256(types:
|
|
93
|
+
solidityKeccak256(types: (string | {
|
|
94
|
+
type: string;
|
|
95
|
+
name: string;
|
|
96
|
+
})[], values: ContractValue[]): string;
|
|
112
97
|
createInterface(abi: string[] | any): ViemInterfaceWrapper;
|
|
113
98
|
hashDomain(domain: TypedDataDomain): string;
|
|
114
|
-
grantRequiredRoles(authorizerAddress: string, authorizerAbi: Abi, vaultAddress: string, vaultRelayerAddress: string, contractCall: (address: string, abi: Abi, functionName: string, args:
|
|
115
|
-
readStorage(baseAddress: Address, baseAbi: Abi, readerAddress: Address, readerAbi: Abi, client: PublicClient, method: string, parameters:
|
|
99
|
+
grantRequiredRoles(authorizerAddress: string, authorizerAbi: Abi, vaultAddress: string, vaultRelayerAddress: string, contractCall: (address: string, abi: Abi, functionName: string, args: ContractValue[]) => Promise<void>): Promise<void>;
|
|
100
|
+
readStorage(baseAddress: Address, baseAbi: Abi, readerAddress: Address, readerAbi: Abi, client: PublicClient, method: string, parameters: ContractValue[]): Promise<unknown>;
|
|
116
101
|
randomBytes(length: number): string;
|
|
117
102
|
isAddress(address: string): boolean;
|
|
118
103
|
isHexString(value: string): boolean;
|
|
119
104
|
hexDataLength(data: string): number;
|
|
120
105
|
parseUnits(value: string, decimals: number): bigint;
|
|
121
|
-
getParamType(type: string):
|
|
122
|
-
getParamTypeFromString(type: string):
|
|
106
|
+
getParamType(type: string): ParamType;
|
|
107
|
+
getParamTypeFromString(type: string): ParamType;
|
|
123
108
|
isInterface(value: any): boolean;
|
|
124
109
|
}
|
|
125
110
|
|
|
@@ -133,7 +118,7 @@ declare class ViemSignerAdapter extends AbstractSigner<PublicClient> {
|
|
|
133
118
|
getAddress(): Promise<string>;
|
|
134
119
|
signMessage(message: string | Uint8Array): Promise<string>;
|
|
135
120
|
signTransaction(txParams: TransactionParams): Promise<string>;
|
|
136
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
121
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
137
122
|
sendTransaction(txParams: TransactionParams): Promise<TransactionResponse>;
|
|
138
123
|
estimateGas(txParams: TransactionParams): Promise<bigint>;
|
|
139
124
|
private _formatTxParams;
|
|
@@ -144,8 +129,8 @@ declare class ViemSignerAdapter extends AbstractSigner<PublicClient> {
|
|
|
144
129
|
*/
|
|
145
130
|
declare class TypedDataVersionedSigner extends ViemSignerAdapter {
|
|
146
131
|
protected getTypedDataVersion(): string;
|
|
147
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
148
|
-
protected modifyDomain(domain: TypedDataDomain): TypedDataDomain;
|
|
132
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
133
|
+
protected modifyDomain(domain: TypedDataDomain$1): TypedDataDomain$1;
|
|
149
134
|
}
|
|
150
135
|
/**
|
|
151
136
|
* Signer for EIP-712 typed data version 3
|
|
@@ -153,7 +138,7 @@ declare class TypedDataVersionedSigner extends ViemSignerAdapter {
|
|
|
153
138
|
*/
|
|
154
139
|
declare class TypedDataV3Signer extends TypedDataVersionedSigner {
|
|
155
140
|
protected getTypedDataVersion(): string;
|
|
156
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
141
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
157
142
|
}
|
|
158
143
|
/**
|
|
159
144
|
* Signer for EIP-712 typed data version 4 with integer chain ID handling
|
|
@@ -161,24 +146,21 @@ declare class TypedDataV3Signer extends TypedDataVersionedSigner {
|
|
|
161
146
|
*/
|
|
162
147
|
declare class IntChainIdTypedDataV4Signer extends TypedDataVersionedSigner {
|
|
163
148
|
protected getTypedDataVersion(): string;
|
|
164
|
-
protected modifyDomain(domain: TypedDataDomain): TypedDataDomain;
|
|
165
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
149
|
+
protected modifyDomain(domain: TypedDataDomain$1): TypedDataDomain$1;
|
|
150
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
166
151
|
}
|
|
167
152
|
|
|
168
153
|
interface ViemTypes extends AdapterTypes {
|
|
169
154
|
Abi: Abi;
|
|
170
|
-
Address: Address;
|
|
171
155
|
Bytes: `0x${string}`;
|
|
172
|
-
|
|
173
|
-
ContractInterface: unknown;
|
|
156
|
+
ContractInterface: Abi;
|
|
174
157
|
Provider: PublicClient;
|
|
175
158
|
Signer: WalletClient;
|
|
176
|
-
TypedDataDomain: TypedDataDomain;
|
|
177
|
-
TypedDataTypes: Record<string, unknown>;
|
|
178
159
|
}
|
|
179
160
|
interface ViemAdapterOptions {
|
|
180
161
|
provider: PublicClient;
|
|
181
162
|
signer?: Account | PrivateKey;
|
|
163
|
+
walletClient?: WalletClient;
|
|
182
164
|
}
|
|
183
165
|
declare class ViemAdapter extends AbstractProviderAdapter<ViemTypes> {
|
|
184
166
|
private _publicClient;
|
|
@@ -204,7 +186,7 @@ declare class ViemAdapter extends AbstractProviderAdapter<ViemTypes> {
|
|
|
204
186
|
address: string;
|
|
205
187
|
abi: Abi;
|
|
206
188
|
functionName: string;
|
|
207
|
-
args?:
|
|
189
|
+
args?: ContractValue[];
|
|
208
190
|
}, provider?: PublicClient): Promise<unknown>;
|
|
209
191
|
getBlock(blockTag: BlockTag, provider?: PublicClient): Promise<Block>;
|
|
210
192
|
getContract(address: string, abi: Abi): GenericContract;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
|
-
import { Abi, Address, Hex,
|
|
3
|
-
import { GenericContractInterface, Log, AdapterUtils, AbstractSigner, TransactionParams, TransactionResponse, AdapterTypes, PrivateKey, AbstractProviderAdapter, TransactionReceipt, GenericContract } from '@cowprotocol/sdk-common';
|
|
2
|
+
import { Abi, Address, Hex, PublicClient, WalletClient, Account, Transport, TypedDataDomain as TypedDataDomain$1, TypedDataParameter, BlockTag, Block } from 'viem';
|
|
3
|
+
import { GenericContractInterface, ContractValue, Log, AdapterUtils, TypedDataDomain, ParamType, AbstractSigner, TransactionParams, TransactionResponse, AdapterTypes, PrivateKey, AbstractProviderAdapter, TransactionReceipt, GenericContract } from '@cowprotocol/sdk-common';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Interface wrapper that makes viem interfaces behave exactly like ethers v5 interfaces
|
|
@@ -20,7 +20,7 @@ declare class ViemInterfaceWrapper implements GenericContractInterface {
|
|
|
20
20
|
/**
|
|
21
21
|
* Encode function data using viem
|
|
22
22
|
*/
|
|
23
|
-
encodeFunctionData(name: string, args:
|
|
23
|
+
encodeFunctionData(name: string, args: ContractValue[]): string;
|
|
24
24
|
parseLog(event: Log): {
|
|
25
25
|
args: unknown;
|
|
26
26
|
} | null;
|
|
@@ -37,21 +37,7 @@ declare class ViemInterfaceWrapper implements GenericContractInterface {
|
|
|
37
37
|
* Get ABI
|
|
38
38
|
*/
|
|
39
39
|
get abi(): any[];
|
|
40
|
-
decodeFunctionData(functionName: string, data: string):
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
declare class ViemParamType {
|
|
44
|
-
name: string;
|
|
45
|
-
type: string;
|
|
46
|
-
baseType: string;
|
|
47
|
-
indexed: boolean;
|
|
48
|
-
components: ViemParamType[];
|
|
49
|
-
arrayLength: number;
|
|
50
|
-
arrayChildren: ViemParamType | null;
|
|
51
|
-
constructor(type: string);
|
|
52
|
-
private normalizeType;
|
|
53
|
-
private parseBaseType;
|
|
54
|
-
private getArrayElementType;
|
|
40
|
+
decodeFunctionData(functionName: string, data: string): ContractValue[];
|
|
55
41
|
}
|
|
56
42
|
|
|
57
43
|
declare class ViemUtils implements AdapterUtils {
|
|
@@ -66,17 +52,19 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
66
52
|
hexZeroPad(value: Hex, length: number): string;
|
|
67
53
|
arrayify(hexString: string): Uint8Array;
|
|
68
54
|
hexlify(value: `0x${string}` | Uint8Array): string;
|
|
69
|
-
solidityPack(types: string[], values:
|
|
55
|
+
solidityPack(types: string[], values: ContractValue[]): string;
|
|
70
56
|
hashTypedData(domain: TypedDataDomain, types: Record<string, unknown>, data: Record<string, unknown>): string;
|
|
71
57
|
getChecksumAddress(address: Address): Address;
|
|
72
58
|
encodeAbi(types: {
|
|
73
59
|
type: string;
|
|
74
60
|
name: string;
|
|
75
|
-
}[] | string[], values:
|
|
76
|
-
decodeAbi(types:
|
|
61
|
+
}[] | string[], values: ContractValue[]): `0x${string}`;
|
|
62
|
+
decodeAbi(types: (string | {
|
|
63
|
+
type: string;
|
|
64
|
+
name: string;
|
|
65
|
+
})[], data: `0x${string}`): unknown[];
|
|
77
66
|
id(text: string): `0x${string}`;
|
|
78
67
|
toBigIntish(value: `0x${string}` | string | number): bigint;
|
|
79
|
-
newBigintish(value: number | string): bigint;
|
|
80
68
|
hexDataSlice(data: `0x${string}`, offset: number, endOffset?: number): `0x${string}`;
|
|
81
69
|
joinSignature(signature: {
|
|
82
70
|
r: string;
|
|
@@ -93,13 +81,7 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
93
81
|
name: string;
|
|
94
82
|
type: string;
|
|
95
83
|
}>>, value: Record<string, unknown>, signature: `0x${string}`): Promise<`0x${string}`>;
|
|
96
|
-
encodeFunction(abi:
|
|
97
|
-
name: string;
|
|
98
|
-
inputs: Array<{
|
|
99
|
-
type: string;
|
|
100
|
-
}>;
|
|
101
|
-
type: string;
|
|
102
|
-
}>, functionName: string, args: unknown[]): string;
|
|
84
|
+
encodeFunction(abi: Abi, functionName: string, args: ContractValue[]): string;
|
|
103
85
|
decodeFunctionData(abi: Array<{
|
|
104
86
|
name: string;
|
|
105
87
|
inputs: Array<{
|
|
@@ -108,18 +90,21 @@ declare class ViemUtils implements AdapterUtils {
|
|
|
108
90
|
type: string;
|
|
109
91
|
}>, functionName: string, data: string): any;
|
|
110
92
|
toNumber(value: bigint): number;
|
|
111
|
-
solidityKeccak256(types:
|
|
93
|
+
solidityKeccak256(types: (string | {
|
|
94
|
+
type: string;
|
|
95
|
+
name: string;
|
|
96
|
+
})[], values: ContractValue[]): string;
|
|
112
97
|
createInterface(abi: string[] | any): ViemInterfaceWrapper;
|
|
113
98
|
hashDomain(domain: TypedDataDomain): string;
|
|
114
|
-
grantRequiredRoles(authorizerAddress: string, authorizerAbi: Abi, vaultAddress: string, vaultRelayerAddress: string, contractCall: (address: string, abi: Abi, functionName: string, args:
|
|
115
|
-
readStorage(baseAddress: Address, baseAbi: Abi, readerAddress: Address, readerAbi: Abi, client: PublicClient, method: string, parameters:
|
|
99
|
+
grantRequiredRoles(authorizerAddress: string, authorizerAbi: Abi, vaultAddress: string, vaultRelayerAddress: string, contractCall: (address: string, abi: Abi, functionName: string, args: ContractValue[]) => Promise<void>): Promise<void>;
|
|
100
|
+
readStorage(baseAddress: Address, baseAbi: Abi, readerAddress: Address, readerAbi: Abi, client: PublicClient, method: string, parameters: ContractValue[]): Promise<unknown>;
|
|
116
101
|
randomBytes(length: number): string;
|
|
117
102
|
isAddress(address: string): boolean;
|
|
118
103
|
isHexString(value: string): boolean;
|
|
119
104
|
hexDataLength(data: string): number;
|
|
120
105
|
parseUnits(value: string, decimals: number): bigint;
|
|
121
|
-
getParamType(type: string):
|
|
122
|
-
getParamTypeFromString(type: string):
|
|
106
|
+
getParamType(type: string): ParamType;
|
|
107
|
+
getParamTypeFromString(type: string): ParamType;
|
|
123
108
|
isInterface(value: any): boolean;
|
|
124
109
|
}
|
|
125
110
|
|
|
@@ -133,7 +118,7 @@ declare class ViemSignerAdapter extends AbstractSigner<PublicClient> {
|
|
|
133
118
|
getAddress(): Promise<string>;
|
|
134
119
|
signMessage(message: string | Uint8Array): Promise<string>;
|
|
135
120
|
signTransaction(txParams: TransactionParams): Promise<string>;
|
|
136
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
121
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
137
122
|
sendTransaction(txParams: TransactionParams): Promise<TransactionResponse>;
|
|
138
123
|
estimateGas(txParams: TransactionParams): Promise<bigint>;
|
|
139
124
|
private _formatTxParams;
|
|
@@ -144,8 +129,8 @@ declare class ViemSignerAdapter extends AbstractSigner<PublicClient> {
|
|
|
144
129
|
*/
|
|
145
130
|
declare class TypedDataVersionedSigner extends ViemSignerAdapter {
|
|
146
131
|
protected getTypedDataVersion(): string;
|
|
147
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
148
|
-
protected modifyDomain(domain: TypedDataDomain): TypedDataDomain;
|
|
132
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
133
|
+
protected modifyDomain(domain: TypedDataDomain$1): TypedDataDomain$1;
|
|
149
134
|
}
|
|
150
135
|
/**
|
|
151
136
|
* Signer for EIP-712 typed data version 3
|
|
@@ -153,7 +138,7 @@ declare class TypedDataVersionedSigner extends ViemSignerAdapter {
|
|
|
153
138
|
*/
|
|
154
139
|
declare class TypedDataV3Signer extends TypedDataVersionedSigner {
|
|
155
140
|
protected getTypedDataVersion(): string;
|
|
156
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
141
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
157
142
|
}
|
|
158
143
|
/**
|
|
159
144
|
* Signer for EIP-712 typed data version 4 with integer chain ID handling
|
|
@@ -161,24 +146,21 @@ declare class TypedDataV3Signer extends TypedDataVersionedSigner {
|
|
|
161
146
|
*/
|
|
162
147
|
declare class IntChainIdTypedDataV4Signer extends TypedDataVersionedSigner {
|
|
163
148
|
protected getTypedDataVersion(): string;
|
|
164
|
-
protected modifyDomain(domain: TypedDataDomain): TypedDataDomain;
|
|
165
|
-
signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
149
|
+
protected modifyDomain(domain: TypedDataDomain$1): TypedDataDomain$1;
|
|
150
|
+
signTypedData(domain: TypedDataDomain$1, types: Record<string, TypedDataParameter>, value: Record<string, unknown>): Promise<string>;
|
|
166
151
|
}
|
|
167
152
|
|
|
168
153
|
interface ViemTypes extends AdapterTypes {
|
|
169
154
|
Abi: Abi;
|
|
170
|
-
Address: Address;
|
|
171
155
|
Bytes: `0x${string}`;
|
|
172
|
-
|
|
173
|
-
ContractInterface: unknown;
|
|
156
|
+
ContractInterface: Abi;
|
|
174
157
|
Provider: PublicClient;
|
|
175
158
|
Signer: WalletClient;
|
|
176
|
-
TypedDataDomain: TypedDataDomain;
|
|
177
|
-
TypedDataTypes: Record<string, unknown>;
|
|
178
159
|
}
|
|
179
160
|
interface ViemAdapterOptions {
|
|
180
161
|
provider: PublicClient;
|
|
181
162
|
signer?: Account | PrivateKey;
|
|
163
|
+
walletClient?: WalletClient;
|
|
182
164
|
}
|
|
183
165
|
declare class ViemAdapter extends AbstractProviderAdapter<ViemTypes> {
|
|
184
166
|
private _publicClient;
|
|
@@ -204,7 +186,7 @@ declare class ViemAdapter extends AbstractProviderAdapter<ViemTypes> {
|
|
|
204
186
|
address: string;
|
|
205
187
|
abi: Abi;
|
|
206
188
|
functionName: string;
|
|
207
|
-
args?:
|
|
189
|
+
args?: ContractValue[];
|
|
208
190
|
}, provider?: PublicClient): Promise<unknown>;
|
|
209
191
|
getBlock(blockTag: BlockTag, provider?: PublicClient): Promise<Block>;
|
|
210
192
|
getContract(address: string, abi: Abi): GenericContract;
|
package/dist/index.js
CHANGED
|
@@ -309,8 +309,9 @@ var ViemUtils = class {
|
|
|
309
309
|
if (!primaryType) {
|
|
310
310
|
throw new Error("No primary type found in types");
|
|
311
311
|
}
|
|
312
|
+
const domainTypedDataDomain = domain;
|
|
312
313
|
return (0, import_viem2.hashTypedData)({
|
|
313
|
-
domain,
|
|
314
|
+
domain: domainTypedDataDomain,
|
|
314
315
|
types,
|
|
315
316
|
primaryType,
|
|
316
317
|
message: data
|
|
@@ -334,7 +335,7 @@ var ViemUtils = class {
|
|
|
334
335
|
return (0, import_viem2.decodeAbiParameters)(types, data);
|
|
335
336
|
}
|
|
336
337
|
id(text) {
|
|
337
|
-
return (0, import_viem2.keccak256)((0, import_viem2.
|
|
338
|
+
return (0, import_viem2.keccak256)((0, import_viem2.toBytes)(text));
|
|
338
339
|
}
|
|
339
340
|
toBigIntish(value) {
|
|
340
341
|
if (typeof value === "number")
|
|
@@ -346,9 +347,6 @@ var ViemUtils = class {
|
|
|
346
347
|
}
|
|
347
348
|
return (0, import_viem2.hexToBigInt)(value);
|
|
348
349
|
}
|
|
349
|
-
newBigintish(value) {
|
|
350
|
-
return BigInt(value);
|
|
351
|
-
}
|
|
352
350
|
hexDataSlice(data, offset, endOffset) {
|
|
353
351
|
return (0, import_viem2.sliceHex)(data, offset, endOffset);
|
|
354
352
|
}
|
|
@@ -381,8 +379,9 @@ var ViemUtils = class {
|
|
|
381
379
|
if (!primaryType) {
|
|
382
380
|
throw new Error("No primary type found in types");
|
|
383
381
|
}
|
|
382
|
+
const domainTypedDataDomain = domain;
|
|
384
383
|
return (0, import_viem2.recoverTypedDataAddress)({
|
|
385
|
-
domain,
|
|
384
|
+
domain: domainTypedDataDomain,
|
|
386
385
|
types,
|
|
387
386
|
primaryType,
|
|
388
387
|
message: value,
|
|
@@ -431,11 +430,12 @@ var ViemUtils = class {
|
|
|
431
430
|
return new ViemInterfaceWrapper(abi);
|
|
432
431
|
}
|
|
433
432
|
hashDomain(domain) {
|
|
433
|
+
const domainTypedDataDomain = domain;
|
|
434
434
|
const EIP712_DOMAIN_TYPEHASH = (0, import_viem2.keccak256)(
|
|
435
435
|
(0, import_viem2.toHex)("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
|
|
436
436
|
);
|
|
437
|
-
const nameHash =
|
|
438
|
-
const versionHash =
|
|
437
|
+
const nameHash = domainTypedDataDomain.name ? (0, import_viem2.keccak256)((0, import_viem2.toHex)(domainTypedDataDomain.name)) : "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
438
|
+
const versionHash = domainTypedDataDomain.version ? (0, import_viem2.keccak256)((0, import_viem2.toHex)(domainTypedDataDomain.version)) : "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
439
439
|
const encodedDomain = (0, import_viem2.encodeAbiParameters)(
|
|
440
440
|
[
|
|
441
441
|
{ type: "bytes32" },
|
|
@@ -453,8 +453,8 @@ var ViemUtils = class {
|
|
|
453
453
|
EIP712_DOMAIN_TYPEHASH,
|
|
454
454
|
nameHash,
|
|
455
455
|
versionHash,
|
|
456
|
-
BigInt(
|
|
457
|
-
|
|
456
|
+
BigInt(domainTypedDataDomain.chainId || 0),
|
|
457
|
+
domainTypedDataDomain.verifyingContract || "0x0000000000000000000000000000000000000000"
|
|
458
458
|
]
|
|
459
459
|
);
|
|
460
460
|
return (0, import_viem2.keccak256)(encodedDomain);
|
|
@@ -605,6 +605,8 @@ var ViemSignerAdapter = class extends import_sdk_common3.AbstractSigner {
|
|
|
605
605
|
confirmations
|
|
606
606
|
});
|
|
607
607
|
return {
|
|
608
|
+
from: receipt.from,
|
|
609
|
+
to: receipt.to,
|
|
608
610
|
transactionHash: receipt.transactionHash,
|
|
609
611
|
blockNumber: BigInt(receipt.blockNumber),
|
|
610
612
|
blockHash: receipt.blockHash,
|
|
@@ -729,6 +731,12 @@ var ViemAdapter = class extends import_sdk_common4.AbstractProviderAdapter {
|
|
|
729
731
|
if (options.signer) {
|
|
730
732
|
this.setSigner(options.signer);
|
|
731
733
|
}
|
|
734
|
+
if (options.walletClient) {
|
|
735
|
+
this._walletClient = options.walletClient;
|
|
736
|
+
const signerAdapter = new ViemSignerAdapter(this._walletClient);
|
|
737
|
+
signerAdapter.connect(this._publicClient);
|
|
738
|
+
this._signerAdapter = signerAdapter;
|
|
739
|
+
}
|
|
732
740
|
this.utils = new ViemUtils();
|
|
733
741
|
}
|
|
734
742
|
get signer() {
|
package/dist/index.mjs
CHANGED
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
} from "@cowprotocol/sdk-common";
|
|
15
15
|
|
|
16
16
|
// src/ViemUtils.ts
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
CowError as CowError2
|
|
19
|
+
} from "@cowprotocol/sdk-common";
|
|
18
20
|
import {
|
|
19
21
|
encodeDeployData,
|
|
20
22
|
getCreate2Address,
|
|
@@ -28,7 +30,6 @@ import {
|
|
|
28
30
|
getAddress,
|
|
29
31
|
encodeAbiParameters,
|
|
30
32
|
decodeAbiParameters as decodeAbiParameters2,
|
|
31
|
-
stringToHex,
|
|
32
33
|
hexToBigInt,
|
|
33
34
|
slice,
|
|
34
35
|
parseAbi as parseAbi2,
|
|
@@ -42,7 +43,8 @@ import {
|
|
|
42
43
|
isAddress,
|
|
43
44
|
isHex,
|
|
44
45
|
parseUnits,
|
|
45
|
-
sliceHex
|
|
46
|
+
sliceHex,
|
|
47
|
+
toBytes
|
|
46
48
|
} from "viem";
|
|
47
49
|
|
|
48
50
|
// src/ViemInterfaceWrapper.ts
|
|
@@ -328,8 +330,9 @@ var ViemUtils = class {
|
|
|
328
330
|
if (!primaryType) {
|
|
329
331
|
throw new Error("No primary type found in types");
|
|
330
332
|
}
|
|
333
|
+
const domainTypedDataDomain = domain;
|
|
331
334
|
return hashTypedData({
|
|
332
|
-
domain,
|
|
335
|
+
domain: domainTypedDataDomain,
|
|
333
336
|
types,
|
|
334
337
|
primaryType,
|
|
335
338
|
message: data
|
|
@@ -353,7 +356,7 @@ var ViemUtils = class {
|
|
|
353
356
|
return decodeAbiParameters2(types, data);
|
|
354
357
|
}
|
|
355
358
|
id(text) {
|
|
356
|
-
return keccak256(
|
|
359
|
+
return keccak256(toBytes(text));
|
|
357
360
|
}
|
|
358
361
|
toBigIntish(value) {
|
|
359
362
|
if (typeof value === "number")
|
|
@@ -365,9 +368,6 @@ var ViemUtils = class {
|
|
|
365
368
|
}
|
|
366
369
|
return hexToBigInt(value);
|
|
367
370
|
}
|
|
368
|
-
newBigintish(value) {
|
|
369
|
-
return BigInt(value);
|
|
370
|
-
}
|
|
371
371
|
hexDataSlice(data, offset, endOffset) {
|
|
372
372
|
return sliceHex(data, offset, endOffset);
|
|
373
373
|
}
|
|
@@ -400,8 +400,9 @@ var ViemUtils = class {
|
|
|
400
400
|
if (!primaryType) {
|
|
401
401
|
throw new Error("No primary type found in types");
|
|
402
402
|
}
|
|
403
|
+
const domainTypedDataDomain = domain;
|
|
403
404
|
return recoverTypedDataAddress({
|
|
404
|
-
domain,
|
|
405
|
+
domain: domainTypedDataDomain,
|
|
405
406
|
types,
|
|
406
407
|
primaryType,
|
|
407
408
|
message: value,
|
|
@@ -450,11 +451,12 @@ var ViemUtils = class {
|
|
|
450
451
|
return new ViemInterfaceWrapper(abi);
|
|
451
452
|
}
|
|
452
453
|
hashDomain(domain) {
|
|
454
|
+
const domainTypedDataDomain = domain;
|
|
453
455
|
const EIP712_DOMAIN_TYPEHASH = keccak256(
|
|
454
456
|
toHex("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
|
|
455
457
|
);
|
|
456
|
-
const nameHash =
|
|
457
|
-
const versionHash =
|
|
458
|
+
const nameHash = domainTypedDataDomain.name ? keccak256(toHex(domainTypedDataDomain.name)) : "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
459
|
+
const versionHash = domainTypedDataDomain.version ? keccak256(toHex(domainTypedDataDomain.version)) : "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
458
460
|
const encodedDomain = encodeAbiParameters(
|
|
459
461
|
[
|
|
460
462
|
{ type: "bytes32" },
|
|
@@ -472,8 +474,8 @@ var ViemUtils = class {
|
|
|
472
474
|
EIP712_DOMAIN_TYPEHASH,
|
|
473
475
|
nameHash,
|
|
474
476
|
versionHash,
|
|
475
|
-
BigInt(
|
|
476
|
-
|
|
477
|
+
BigInt(domainTypedDataDomain.chainId || 0),
|
|
478
|
+
domainTypedDataDomain.verifyingContract || "0x0000000000000000000000000000000000000000"
|
|
477
479
|
]
|
|
478
480
|
);
|
|
479
481
|
return keccak256(encodedDomain);
|
|
@@ -627,6 +629,8 @@ var ViemSignerAdapter = class extends AbstractSigner {
|
|
|
627
629
|
confirmations
|
|
628
630
|
});
|
|
629
631
|
return {
|
|
632
|
+
from: receipt.from,
|
|
633
|
+
to: receipt.to,
|
|
630
634
|
transactionHash: receipt.transactionHash,
|
|
631
635
|
blockNumber: BigInt(receipt.blockNumber),
|
|
632
636
|
blockHash: receipt.blockHash,
|
|
@@ -751,6 +755,12 @@ var ViemAdapter = class extends AbstractProviderAdapter {
|
|
|
751
755
|
if (options.signer) {
|
|
752
756
|
this.setSigner(options.signer);
|
|
753
757
|
}
|
|
758
|
+
if (options.walletClient) {
|
|
759
|
+
this._walletClient = options.walletClient;
|
|
760
|
+
const signerAdapter = new ViemSignerAdapter(this._walletClient);
|
|
761
|
+
signerAdapter.connect(this._publicClient);
|
|
762
|
+
this._signerAdapter = signerAdapter;
|
|
763
|
+
}
|
|
754
764
|
this.utils = new ViemUtils();
|
|
755
765
|
}
|
|
756
766
|
get signer() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-viem-adapter",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Viem adapter for CoW Protocol SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -12,24 +12,23 @@
|
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
17
|
-
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
18
|
-
"lint": "eslint src/**/*.ts",
|
|
19
|
-
"typecheck": "tsc --noEmit",
|
|
20
|
-
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
|
21
|
-
"prepublishOnly": "npm run build"
|
|
22
|
-
},
|
|
23
15
|
"dependencies": {
|
|
24
|
-
"@cowprotocol/sdk-common": "
|
|
16
|
+
"@cowprotocol/sdk-common": "0.3.0"
|
|
25
17
|
},
|
|
26
18
|
"peerDependencies": {
|
|
27
19
|
"viem": "^2.28.4"
|
|
28
20
|
},
|
|
29
21
|
"devDependencies": {
|
|
30
|
-
"@cow-sdk/typescript-config": "workspace:*",
|
|
31
22
|
"@types/node": "^20.5.2",
|
|
32
23
|
"tsup": "^7.2.0",
|
|
33
|
-
"typescript": "^5.2.2"
|
|
24
|
+
"typescript": "^5.2.2",
|
|
25
|
+
"@cow-sdk/typescript-config": "0.0.0-beta.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
29
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
30
|
+
"lint": "eslint src/**/*.ts",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
34
33
|
}
|
|
35
|
-
}
|
|
34
|
+
}
|