-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnectors.ts
46 lines (41 loc) · 1.16 KB
/
connectors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {
ProviderConnector,
EIP712TypedData,
AbiItem,
} from "@1inch/limit-order-protocol";
import { ethers, VoidSigner } from "ethers";
export class EthersSignerConnector implements ProviderConnector {
// eslint-disable-next-line no-useless-constructor
constructor(protected readonly _signer: VoidSigner) {}
contractEncodeABI(
abi: AbiItem[],
address: string | null,
methodName: string,
methodParams: unknown[]
): string {
const iface = new ethers.utils.Interface(abi);
return iface.encodeFunctionData(methodName, methodParams);
}
signTypedData(
walletAddress: string,
typedData: EIP712TypedData,
_typedDataHash: string
): Promise<string> {
delete typedData.types.EIP712Domain;
return this._signer._signTypedData(
typedData.domain,
typedData.types,
typedData.message
);
}
ethCall(contractAddress: string, callData: string): Promise<string> {
return this._signer.call({
to: contractAddress,
data: callData,
});
}
decodeABIParameter<T>(type: string, hex: string): T {
const abiCoder = new ethers.utils.AbiCoder();
return abiCoder.decode([type], hex)[0];
}
}