@polymarket/relayer-client 1.0.18 → 2.0.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 +30 -0
- package/dist/auth/handler.js +24 -25
- package/dist/builder/create.d.ts +3 -2
- package/dist/builder/create.js +44 -47
- package/dist/builder/derive.d.ts +2 -0
- package/dist/builder/derive.js +21 -0
- package/dist/builder/index.d.ts +1 -1
- package/dist/builder/index.js +1 -1
- package/dist/builder/proxy.d.ts +3 -2
- package/dist/builder/proxy.js +64 -83
- package/dist/builder/safe.d.ts +4 -3
- package/dist/builder/safe.js +52 -77
- package/dist/client.d.ts +10 -8
- package/dist/client.js +119 -133
- package/dist/config/index.d.ts +13 -0
- package/dist/config/index.js +35 -0
- package/dist/constants/index.d.ts +0 -4
- package/dist/constants/index.js +1 -5
- package/dist/encode/index.d.ts +0 -1
- package/dist/encode/index.js +0 -1
- package/dist/encode/proxy.d.ts +1 -1
- package/dist/encode/proxy.js +12 -7
- package/dist/encode/safe.d.ts +1 -1
- package/dist/encode/safe.js +11 -9
- package/dist/http-helpers/index.js +33 -35
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/manual/index.d.ts +4 -4
- package/dist/manual/index.js +36 -17
- package/dist/response/index.d.ts +21 -2
- package/dist/response/index.js +41 -3
- package/dist/types.d.ts +8 -3
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +28 -0
- package/package.json +21 -28
- package/dist/builder/utils.d.ts +0 -2
- package/dist/builder/utils.js +0 -13
- package/dist/encode/utils.d.ts +0 -6
- package/dist/encode/utils.js +0 -46
- package/dist/response/relayer.d.ts +0 -12
- package/dist/response/relayer.js +0 -28
- package/dist/response/viem.d.ts +0 -8
- package/dist/response/viem.js +0 -19
- package/dist/signeradapter/adapter.d.ts +0 -20
- package/dist/signeradapter/adapter.js +0 -188
- package/dist/signeradapter/index.d.ts +0 -2
- package/dist/signeradapter/index.js +0 -5
- package/dist/signeradapter/interfaces.d.ts +0 -8
- package/dist/signeradapter/interfaces.js +0 -2
package/dist/response/index.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { RelayClient } from "../client";
|
|
2
|
+
import { IManualTransactionResponse, RelayerTransaction, RelayerTransactionResponse } from "../types";
|
|
3
|
+
export declare class ClientRelayerTransactionResponse implements RelayerTransactionResponse {
|
|
4
|
+
readonly client: RelayClient;
|
|
5
|
+
readonly transactionID: string;
|
|
6
|
+
readonly transactionHash: string;
|
|
7
|
+
readonly hash: string;
|
|
8
|
+
readonly state: string;
|
|
9
|
+
constructor(transactionID: string, state: string, transactionHash: string, client: RelayClient);
|
|
10
|
+
getTransaction(): Promise<RelayerTransaction[]>;
|
|
11
|
+
wait(): Promise<RelayerTransaction | undefined>;
|
|
12
|
+
}
|
|
13
|
+
type WaitUntilMinedFunction = (transactionHash: string) => Promise<any>;
|
|
14
|
+
export declare class ManualTransactionResponse implements IManualTransactionResponse {
|
|
15
|
+
readonly hash: string;
|
|
16
|
+
readonly transactionHash: string;
|
|
17
|
+
private waitTillMined;
|
|
18
|
+
constructor(transactionHash: string, waitTillMinedFunc: WaitUntilMinedFunction);
|
|
19
|
+
wait(): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/dist/response/index.js
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
exports.ManualTransactionResponse = exports.ClientRelayerTransactionResponse = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class ClientRelayerTransactionResponse {
|
|
6
|
+
client;
|
|
7
|
+
transactionID;
|
|
8
|
+
transactionHash;
|
|
9
|
+
hash;
|
|
10
|
+
state;
|
|
11
|
+
constructor(transactionID, state, transactionHash, client) {
|
|
12
|
+
this.transactionID = transactionID;
|
|
13
|
+
this.state = state;
|
|
14
|
+
this.transactionHash = transactionHash;
|
|
15
|
+
this.hash = transactionHash;
|
|
16
|
+
this.client = client;
|
|
17
|
+
}
|
|
18
|
+
async getTransaction() {
|
|
19
|
+
return this.client.getTransaction(this.transactionID);
|
|
20
|
+
}
|
|
21
|
+
async wait() {
|
|
22
|
+
return this.client.pollUntilState(this.transactionID, [
|
|
23
|
+
types_1.RelayerTransactionState.STATE_MINED,
|
|
24
|
+
types_1.RelayerTransactionState.STATE_CONFIRMED,
|
|
25
|
+
types_1.RelayerTransactionState.STATE_FAILED,
|
|
26
|
+
], 30);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ClientRelayerTransactionResponse = ClientRelayerTransactionResponse;
|
|
30
|
+
class ManualTransactionResponse {
|
|
31
|
+
hash;
|
|
32
|
+
transactionHash;
|
|
33
|
+
waitTillMined;
|
|
34
|
+
constructor(transactionHash, waitTillMinedFunc) {
|
|
35
|
+
this.transactionHash = transactionHash;
|
|
36
|
+
this.hash = transactionHash;
|
|
37
|
+
this.waitTillMined = waitTillMinedFunc;
|
|
38
|
+
}
|
|
39
|
+
async wait() {
|
|
40
|
+
return this.waitTillMined(this.hash);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ManualTransactionResponse = ManualTransactionResponse;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BigNumberish } from "ethers";
|
|
2
1
|
export declare enum TransactionType {
|
|
3
2
|
PROXY = "PROXY",
|
|
4
3
|
SAFE = "SAFE",
|
|
@@ -65,6 +64,7 @@ export interface ProxyTransactionArgs {
|
|
|
65
64
|
from: string;
|
|
66
65
|
nonce: string;
|
|
67
66
|
gasPrice: string;
|
|
67
|
+
gasLimit?: string;
|
|
68
68
|
data: string;
|
|
69
69
|
relay: string;
|
|
70
70
|
}
|
|
@@ -113,6 +113,11 @@ export interface RelayerTransaction {
|
|
|
113
113
|
createdAt: Date;
|
|
114
114
|
updatedAt: Date;
|
|
115
115
|
}
|
|
116
|
+
export interface IManualTransactionResponse {
|
|
117
|
+
hash: string;
|
|
118
|
+
transactionHash: string;
|
|
119
|
+
wait: () => Promise<any>;
|
|
120
|
+
}
|
|
116
121
|
export interface RelayerTransactionResponse {
|
|
117
122
|
transactionID: string;
|
|
118
123
|
state: string;
|
|
@@ -122,6 +127,6 @@ export interface RelayerTransactionResponse {
|
|
|
122
127
|
wait: () => Promise<RelayerTransaction | undefined>;
|
|
123
128
|
}
|
|
124
129
|
export interface ManualOverrides {
|
|
125
|
-
gasLimit?:
|
|
126
|
-
gasPrice?:
|
|
130
|
+
gasLimit?: bigint;
|
|
131
|
+
gasPrice?: bigint;
|
|
127
132
|
}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitAndPackSig = splitAndPackSig;
|
|
3
4
|
exports.sleep = sleep;
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
function splitAndPackSig(sig) {
|
|
7
|
+
const splitSig = splitSignature(sig);
|
|
8
|
+
const packedSig = (0, viem_1.encodePacked)(["uint256", "uint256", "uint8"], [BigInt(splitSig.r), BigInt(splitSig.s), parseInt(splitSig.v)]);
|
|
9
|
+
return packedSig;
|
|
10
|
+
}
|
|
11
|
+
function splitSignature(sig) {
|
|
12
|
+
let sigV = parseInt(sig.slice(-2), 16);
|
|
13
|
+
switch (sigV) {
|
|
14
|
+
case 0:
|
|
15
|
+
case 1:
|
|
16
|
+
sigV += 31;
|
|
17
|
+
break;
|
|
18
|
+
case 27:
|
|
19
|
+
case 28:
|
|
20
|
+
sigV += 4;
|
|
21
|
+
break;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("Invalid signature");
|
|
24
|
+
}
|
|
25
|
+
sig = sig.slice(0, -2) + sigV.toString(16);
|
|
26
|
+
return {
|
|
27
|
+
r: (0, viem_1.hexToBigInt)('0x' + sig.slice(2, 66)).toString(),
|
|
28
|
+
s: (0, viem_1.hexToBigInt)('0x' + sig.slice(66, 130)).toString(),
|
|
29
|
+
v: (0, viem_1.hexToBigInt)('0x' + sig.slice(130, 132)).toString(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
4
32
|
function sleep(ms) {
|
|
5
33
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
6
34
|
}
|
package/package.json
CHANGED
|
@@ -1,49 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymarket/relayer-client",
|
|
3
3
|
"description": "Client for Polymarket relayers",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"/dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
-
"clean": "rm -rf ./dist"
|
|
13
|
-
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"@walletconnect/encoding": "^1.0.2",
|
|
16
|
-
"axios": "^0.27.2",
|
|
17
|
-
"browser-or-node": "^3.0.0",
|
|
18
|
-
"ethers": "^5.7.1",
|
|
19
|
-
"viem": "1.9.2"
|
|
11
|
+
"build": "make build",
|
|
12
|
+
"clean": "rm -rf ./dist",
|
|
13
|
+
"test": "make test"
|
|
20
14
|
},
|
|
21
15
|
"devDependencies": {
|
|
22
|
-
"@types/chai": "
|
|
23
|
-
"@types/mocha": "
|
|
16
|
+
"@types/chai": "5.2.2",
|
|
17
|
+
"@types/mocha": "10.0.10",
|
|
24
18
|
"@types/node": "^18.7.18",
|
|
25
19
|
"@types/ws": "^8.5.3",
|
|
26
|
-
"
|
|
27
|
-
"@typescript-eslint/parser": "^5.37.0",
|
|
28
|
-
"chai": "^4.3.6",
|
|
20
|
+
"chai": "5.2.0",
|
|
29
21
|
"dotenv": "^16.0.2",
|
|
30
|
-
"eslint": "^8.23.1",
|
|
31
|
-
"eslint-config-prettier": "^8.5.0",
|
|
32
|
-
"eslint-config-standard-with-typescript": "^23.0.0",
|
|
33
|
-
"eslint-plugin-import": "^2.26.0",
|
|
34
|
-
"eslint-plugin-n": "^15.2.5",
|
|
35
|
-
"eslint-plugin-node": "^11.1.0",
|
|
36
|
-
"eslint-plugin-promise": "^6.0.1",
|
|
37
|
-
"eslint-plugin-unused-imports": "^2.0.0",
|
|
38
22
|
"esm": "^3.2.25",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
23
|
+
"jsdom": "^20.0.0",
|
|
24
|
+
"jsdom-global": "^3.0.2",
|
|
25
|
+
"mocha": "9.2.2",
|
|
41
26
|
"path": "^0.12.7",
|
|
42
27
|
"prettier": "^2.7.1",
|
|
43
|
-
"ts-mocha": "^10.0.0",
|
|
44
28
|
"ts-node": "^9.1.1",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
29
|
+
"tsconfig-paths": "^4.2.0",
|
|
30
|
+
"tslib": "^2.8.1",
|
|
47
31
|
"ws": "^8.11.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@polymarket/abstract-signer": "0.0.5",
|
|
35
|
+
"axios": "^0.27.2",
|
|
36
|
+
"browser-or-node": "^3.0.0",
|
|
37
|
+
"ethers": "5.7.2",
|
|
38
|
+
"tsx": "^4.20.3",
|
|
39
|
+
"typescript": "^5.8.3",
|
|
40
|
+
"viem": "^2.31.4"
|
|
48
41
|
}
|
|
49
42
|
}
|
package/dist/builder/utils.d.ts
DELETED
package/dist/builder/utils.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deriveSafe = exports.deriveProxyWallet = void 0;
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const deriveProxyWallet = (address) => {
|
|
7
|
-
return ethers_1.ethers.utils.getCreate2Address(constants_1.PROXY_WALLET_FACTORY_ADDRESS, ethers_1.ethers.utils.solidityKeccak256(["address"], [address]), constants_1.PROXY_INIT_CODE_HASH);
|
|
8
|
-
};
|
|
9
|
-
exports.deriveProxyWallet = deriveProxyWallet;
|
|
10
|
-
const deriveSafe = (address) => {
|
|
11
|
-
return ethers_1.ethers.utils.getCreate2Address(constants_1.SAFE_FACTORY_ADDRESS, ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(["address"], [address])), constants_1.SAFE_INIT_CODE_HASH);
|
|
12
|
-
};
|
|
13
|
-
exports.deriveSafe = deriveSafe;
|
package/dist/encode/utils.d.ts
DELETED
package/dist/encode/utils.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.joinHexData = joinHexData;
|
|
4
|
-
exports.abiEncodePacked = abiEncodePacked;
|
|
5
|
-
exports.getHexDataLength = getHexDataLength;
|
|
6
|
-
const abi_1 = require("@ethersproject/abi");
|
|
7
|
-
function joinHexData(hexData) {
|
|
8
|
-
return `0x${hexData
|
|
9
|
-
.map((hex) => {
|
|
10
|
-
const stripped = hex.replace(/^0x/, '');
|
|
11
|
-
return stripped.length % 2 === 0 ? stripped : '0' + stripped;
|
|
12
|
-
})
|
|
13
|
-
.join('')}`;
|
|
14
|
-
}
|
|
15
|
-
function abiEncodePacked(...params) {
|
|
16
|
-
return joinHexData(params.map(({ type, value }) => {
|
|
17
|
-
const encoded = abi_1.defaultAbiCoder.encode([type], [value]);
|
|
18
|
-
if (type === 'bytes' || type === 'string') {
|
|
19
|
-
const bytesLength = parseInt(encoded.slice(66, 130), 16);
|
|
20
|
-
return encoded.slice(130, 130 + 2 * bytesLength);
|
|
21
|
-
}
|
|
22
|
-
let typeMatch = type.match(/^(?:u?int\d*|bytes\d+|address)\[\]$/);
|
|
23
|
-
if (typeMatch) {
|
|
24
|
-
return encoded.slice(130);
|
|
25
|
-
}
|
|
26
|
-
if (type.startsWith('bytes')) {
|
|
27
|
-
const bytesLength = parseInt(type.slice(5));
|
|
28
|
-
return encoded.slice(2, 2 + 2 * bytesLength);
|
|
29
|
-
}
|
|
30
|
-
typeMatch = type.match(/^u?int(\d*)$/);
|
|
31
|
-
if (typeMatch) {
|
|
32
|
-
if (typeMatch[1] !== '') {
|
|
33
|
-
const bytesLength = parseInt(typeMatch[1]) / 8;
|
|
34
|
-
return encoded.slice(-2 * bytesLength);
|
|
35
|
-
}
|
|
36
|
-
return encoded.slice(-64);
|
|
37
|
-
}
|
|
38
|
-
if (type === 'address') {
|
|
39
|
-
return encoded.slice(-40);
|
|
40
|
-
}
|
|
41
|
-
throw new Error(`unsupported type ${type}`);
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
function getHexDataLength(hexData) {
|
|
45
|
-
return Math.ceil((hexData.startsWith("0x") ? hexData.length - 2 : hexData.length) / 2);
|
|
46
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { RelayClient } from "../client";
|
|
2
|
-
import { RelayerTransaction, RelayerTransactionResponse } from "../types";
|
|
3
|
-
export declare class ClientRelayerTransactionResponse implements RelayerTransactionResponse {
|
|
4
|
-
readonly client: RelayClient;
|
|
5
|
-
readonly transactionID: string;
|
|
6
|
-
readonly transactionHash: string;
|
|
7
|
-
readonly hash: string;
|
|
8
|
-
readonly state: string;
|
|
9
|
-
constructor(transactionID: string, state: string, transactionHash: string, client: RelayClient);
|
|
10
|
-
getTransaction(): Promise<RelayerTransaction[]>;
|
|
11
|
-
wait(): Promise<RelayerTransaction | undefined>;
|
|
12
|
-
}
|
package/dist/response/relayer.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientRelayerTransactionResponse = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
class ClientRelayerTransactionResponse {
|
|
7
|
-
constructor(transactionID, state, transactionHash, client) {
|
|
8
|
-
this.transactionID = transactionID;
|
|
9
|
-
this.state = state;
|
|
10
|
-
this.transactionHash = transactionHash;
|
|
11
|
-
this.hash = transactionHash;
|
|
12
|
-
this.client = client;
|
|
13
|
-
}
|
|
14
|
-
getTransaction() {
|
|
15
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
return this.client.getTransaction(this.transactionID);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
wait() {
|
|
20
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
return this.client.pollUntilState(this.transactionID, [
|
|
22
|
-
types_1.RelayerTransactionState.STATE_MINED,
|
|
23
|
-
types_1.RelayerTransactionState.STATE_CONFIRMED,
|
|
24
|
-
], 30);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.ClientRelayerTransactionResponse = ClientRelayerTransactionResponse;
|
package/dist/response/viem.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PublicClient, TransactionReceipt } from "viem";
|
|
2
|
-
export declare class ViemTransactionResponse {
|
|
3
|
-
readonly publicClient: PublicClient;
|
|
4
|
-
readonly transactionHash: string;
|
|
5
|
-
readonly hash: string;
|
|
6
|
-
constructor(transactionHash: string, publicClient: PublicClient);
|
|
7
|
-
wait(): Promise<TransactionReceipt>;
|
|
8
|
-
}
|
package/dist/response/viem.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ViemTransactionResponse = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
class ViemTransactionResponse {
|
|
6
|
-
constructor(transactionHash, publicClient) {
|
|
7
|
-
this.transactionHash = transactionHash;
|
|
8
|
-
this.hash = transactionHash;
|
|
9
|
-
this.publicClient = publicClient;
|
|
10
|
-
}
|
|
11
|
-
wait() {
|
|
12
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
return this.publicClient.waitForTransactionReceipt({
|
|
14
|
-
hash: this.hash,
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.ViemTransactionResponse = ViemTransactionResponse;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Provider, TransactionResponse as EthersTransactionResponse } from "@ethersproject/providers";
|
|
2
|
-
import { ManualOverrides } from "../types";
|
|
3
|
-
import { EthersSigner, ViemSigner } from "./interfaces";
|
|
4
|
-
import { ViemTransactionResponse } from "../response";
|
|
5
|
-
export declare class SignerAdapter {
|
|
6
|
-
readonly ethersSigner?: EthersSigner;
|
|
7
|
-
readonly viemSigner?: ViemSigner;
|
|
8
|
-
constructor(ethersSigner?: EthersSigner, viemSigner?: ViemSigner);
|
|
9
|
-
getAddress(): Promise<string>;
|
|
10
|
-
ethersSignMessage(message: string): Promise<string>;
|
|
11
|
-
viemSignMessage(message: string): Promise<string>;
|
|
12
|
-
ethersSignTypedData(domain: any, types: any, values: any): Promise<string>;
|
|
13
|
-
viemSignTypedData(domain: any, types: any, values: any): Promise<string>;
|
|
14
|
-
signMessage(message: string): Promise<string>;
|
|
15
|
-
signTypedData(domain: any, types: any, values: any): Promise<string>;
|
|
16
|
-
getProvider(): Promise<Provider>;
|
|
17
|
-
writeContract(address: string, abi: any, overrides: ManualOverrides, functionName: string, ...args: any[]): Promise<EthersTransactionResponse | ViemTransactionResponse>;
|
|
18
|
-
private ethersWriteContract;
|
|
19
|
-
private viemWriteContract;
|
|
20
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SignerAdapter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const providers_1 = require("@ethersproject/providers");
|
|
6
|
-
const ethers_1 = require("ethers");
|
|
7
|
-
const encoding = tslib_1.__importStar(require("@walletconnect/encoding"));
|
|
8
|
-
const response_1 = require("../response");
|
|
9
|
-
class SignerAdapter {
|
|
10
|
-
constructor(ethersSigner, viemSigner) {
|
|
11
|
-
if (ethersSigner == undefined && viemSigner == undefined) {
|
|
12
|
-
throw new Error("must provide an ethers signer OR viem WalletClient");
|
|
13
|
-
}
|
|
14
|
-
if (ethersSigner != undefined && viemSigner != undefined) {
|
|
15
|
-
throw new Error("must provide an ethers signer OR viem WalletClient");
|
|
16
|
-
}
|
|
17
|
-
if (ethersSigner != undefined) {
|
|
18
|
-
if (ethersSigner.provider == undefined) {
|
|
19
|
-
throw new Error("signer must have provider attached");
|
|
20
|
-
}
|
|
21
|
-
this.ethersSigner = ethersSigner;
|
|
22
|
-
}
|
|
23
|
-
if (viemSigner != undefined) {
|
|
24
|
-
if (viemSigner.publicClient == undefined) {
|
|
25
|
-
throw new Error("viem signer must have public client");
|
|
26
|
-
}
|
|
27
|
-
if (viemSigner.walletClient == undefined) {
|
|
28
|
-
throw new Error("viem signer must have wallet client");
|
|
29
|
-
}
|
|
30
|
-
this.viemSigner = viemSigner;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
getAddress() {
|
|
34
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
var _a, _b;
|
|
36
|
-
if (this.ethersSigner != undefined) {
|
|
37
|
-
return this.ethersSigner.getAddress();
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return ((_b = (_a = this.viemSigner) === null || _a === void 0 ? void 0 : _a.walletClient.account) === null || _b === void 0 ? void 0 : _b.address) || "";
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
ethersSignMessage(message) {
|
|
45
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (this.ethersSigner == undefined) {
|
|
47
|
-
throw new Error("must provide an ethers Wallet or Signer");
|
|
48
|
-
}
|
|
49
|
-
return this.ethersSigner.signMessage(ethers_1.ethers.utils.arrayify(message));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
viemSignMessage(message) {
|
|
53
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
var _a, _b, _c;
|
|
55
|
-
if (this.viemSigner == undefined) {
|
|
56
|
-
throw new Error("must provide viem WalletClient");
|
|
57
|
-
}
|
|
58
|
-
console.log(`StructHash: `);
|
|
59
|
-
console.log(message);
|
|
60
|
-
// force to walletconnect signable hex
|
|
61
|
-
const msg = encoding.utf8ToHex(message);
|
|
62
|
-
console.log(`Struct Hash after wc specific encoding:`);
|
|
63
|
-
console.log(msg);
|
|
64
|
-
const account = (_b = (_a = this.viemSigner) === null || _a === void 0 ? void 0 : _a.walletClient.account) === null || _b === void 0 ? void 0 : _b.address;
|
|
65
|
-
return (_c = this.viemSigner) === null || _c === void 0 ? void 0 : _c.walletClient.signMessage({
|
|
66
|
-
account: account,
|
|
67
|
-
message: msg.slice(0, 2) == "0x" ? { raw: msg } : msg,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
ethersSignTypedData(domain, types, values) {
|
|
72
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
if (this.ethersSigner == undefined) {
|
|
74
|
-
throw new Error("ethers signer must be present");
|
|
75
|
-
}
|
|
76
|
-
return this.ethersSigner._signTypedData(domain, types, values);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
viemSignTypedData(domain, types, values) {
|
|
80
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
var _a, _b;
|
|
82
|
-
if (this.viemSigner == undefined) {
|
|
83
|
-
throw new Error("viem signer must be present");
|
|
84
|
-
}
|
|
85
|
-
const account = (_b = (_a = this.viemSigner) === null || _a === void 0 ? void 0 : _a.walletClient.account) === null || _b === void 0 ? void 0 : _b.address;
|
|
86
|
-
const keys = Object.keys(types);
|
|
87
|
-
if (keys.length > 1) {
|
|
88
|
-
throw new Error("multiple types in types array");
|
|
89
|
-
}
|
|
90
|
-
const primaryType = keys[0];
|
|
91
|
-
return this.viemSigner.walletClient.signTypedData({ account, domain, types, primaryType, message: values });
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
signMessage(message) {
|
|
95
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
if (this.ethersSigner != undefined) {
|
|
97
|
-
return this.ethersSignMessage(message);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return this.viemSignMessage(message);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
signTypedData(domain, types, values) {
|
|
105
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
if (this.ethersSigner != undefined) {
|
|
107
|
-
return this.ethersSignTypedData(domain, types, values);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
return this.viemSignTypedData(domain, types, values);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
getProvider() {
|
|
115
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
var _a, _b;
|
|
117
|
-
if (this.ethersSigner != undefined) {
|
|
118
|
-
return this.ethersSigner.provider;
|
|
119
|
-
}
|
|
120
|
-
const chain = (_a = this.viemSigner) === null || _a === void 0 ? void 0 : _a.publicClient.chain;
|
|
121
|
-
const transport = (_b = this.viemSigner) === null || _b === void 0 ? void 0 : _b.publicClient.transport;
|
|
122
|
-
const network = {
|
|
123
|
-
chainId: (chain === null || chain === void 0 ? void 0 : chain.id) || 137,
|
|
124
|
-
name: (chain === null || chain === void 0 ? void 0 : chain.name) || "",
|
|
125
|
-
};
|
|
126
|
-
return new providers_1.JsonRpcProvider(transport === null || transport === void 0 ? void 0 : transport.url, network);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
writeContract(address, abi, overrides, functionName, ...args) {
|
|
130
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
if (this.ethersSigner != undefined) {
|
|
132
|
-
return this.ethersWriteContract(address, abi, overrides, functionName, args);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
return this.viemWriteContract(address, abi, overrides, functionName, args);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
ethersWriteContract(address, abi, overrides, functionName, ...args) {
|
|
140
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
if (this.ethersSigner != undefined) {
|
|
142
|
-
throw new Error("ethers signer must be defined");
|
|
143
|
-
}
|
|
144
|
-
const contract = new ethers_1.Contract(address, abi, this.ethersSigner);
|
|
145
|
-
if (overrides.gasLimit == undefined) {
|
|
146
|
-
const gasLimit = yield contract.estimateGas[functionName](...args);
|
|
147
|
-
console.log(`Estimated gas Limit: ${gasLimit}`);
|
|
148
|
-
overrides.gasLimit = gasLimit;
|
|
149
|
-
}
|
|
150
|
-
const argsWithOverrides = args.map(a => a);
|
|
151
|
-
argsWithOverrides.push(overrides);
|
|
152
|
-
return contract.functions[functionName](...argsWithOverrides);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
viemWriteContract(address, abi, overrides, functionName, ...args) {
|
|
156
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
var _a, _b, _c;
|
|
158
|
-
if (this.viemSigner == undefined) {
|
|
159
|
-
throw new Error("viem signer must be defined");
|
|
160
|
-
}
|
|
161
|
-
let addr = address;
|
|
162
|
-
const account = (_b = (_a = this.viemSigner) === null || _a === void 0 ? void 0 : _a.walletClient.account) === null || _b === void 0 ? void 0 : _b.address;
|
|
163
|
-
const chain = (_c = this.viemSigner) === null || _c === void 0 ? void 0 : _c.publicClient.chain;
|
|
164
|
-
let gas = undefined;
|
|
165
|
-
let gasPrice = undefined;
|
|
166
|
-
if (overrides.gasLimit != undefined) {
|
|
167
|
-
let gasLimit = ethers_1.ethers.BigNumber.from(overrides.gasLimit).toBigInt();
|
|
168
|
-
gas = gasLimit;
|
|
169
|
-
}
|
|
170
|
-
if (overrides.gasPrice != undefined) {
|
|
171
|
-
let gasPrice = ethers_1.ethers.BigNumber.from(overrides.gasPrice).toBigInt();
|
|
172
|
-
gasPrice = gasPrice;
|
|
173
|
-
}
|
|
174
|
-
const txnHash = yield this.viemSigner.walletClient.writeContract({
|
|
175
|
-
account: account,
|
|
176
|
-
address: addr,
|
|
177
|
-
abi: abi,
|
|
178
|
-
functionName: functionName,
|
|
179
|
-
args: args,
|
|
180
|
-
gas,
|
|
181
|
-
gasPrice,
|
|
182
|
-
chain,
|
|
183
|
-
});
|
|
184
|
-
return new response_1.ViemTransactionResponse(txnHash, this.viemSigner.publicClient);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
exports.SignerAdapter = SignerAdapter;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { JsonRpcSigner } from "@ethersproject/providers";
|
|
2
|
-
import { Wallet } from "ethers";
|
|
3
|
-
import { PublicClient, WalletClient } from "viem";
|
|
4
|
-
export interface ViemSigner {
|
|
5
|
-
walletClient: WalletClient;
|
|
6
|
-
publicClient: PublicClient;
|
|
7
|
-
}
|
|
8
|
-
export type EthersSigner = Wallet | JsonRpcSigner;
|