@polymarket/relayer-client 0.0.4 → 0.0.6
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/dist/auth/handler.d.ts +4 -2
- package/dist/auth/handler.js +4 -3
- package/dist/builder/index.d.ts +1 -0
- package/dist/builder/index.js +1 -0
- package/dist/builder/utils.js +1 -2
- package/dist/client.d.ts +3 -0
- package/dist/client.js +13 -6
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +2 -1
- package/dist/http-helpers/index.d.ts +5 -11
- package/dist/http-helpers/index.js +42 -57
- package/package.json +4 -4
package/dist/auth/handler.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { AxiosRequestHeaders } from "axios";
|
|
2
|
-
import {
|
|
2
|
+
import { HttpClient } from "../http-helpers";
|
|
3
|
+
import { AuthArgs } from "../types";
|
|
3
4
|
export declare class AuthHandler {
|
|
4
5
|
readonly url: string;
|
|
6
|
+
readonly httpClient: HttpClient;
|
|
5
7
|
readonly token?: string;
|
|
6
8
|
private cookie?;
|
|
7
|
-
constructor(args: AuthArgs);
|
|
9
|
+
constructor(httpClient: HttpClient, args: AuthArgs);
|
|
8
10
|
login(): Promise<void>;
|
|
9
11
|
isLoggedIn(): boolean;
|
|
10
12
|
getAuthHeader(): Promise<AxiosRequestHeaders>;
|
package/dist/auth/handler.js
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthHandler = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const http_helpers_1 = require("
|
|
5
|
+
const http_helpers_1 = require("../http-helpers");
|
|
6
6
|
const POLYMARKET_COOKIE_NAME = "polymarket";
|
|
7
7
|
class AuthHandler {
|
|
8
|
-
constructor(args) {
|
|
8
|
+
constructor(httpClient, args) {
|
|
9
9
|
if (args.token == undefined && args.cookie == undefined) {
|
|
10
10
|
throw new Error("invalid authorization arguments");
|
|
11
11
|
}
|
|
12
12
|
this.url = args.authUrl.endsWith("/") ? args.authUrl.slice(0, -1) : args.authUrl;
|
|
13
13
|
;
|
|
14
|
+
this.httpClient = httpClient;
|
|
14
15
|
if (args.token !== undefined) {
|
|
15
16
|
this.token = args.token;
|
|
16
17
|
}
|
|
@@ -23,7 +24,7 @@ class AuthHandler {
|
|
|
23
24
|
if (this.token == undefined) {
|
|
24
25
|
throw new Error("authorization token missing");
|
|
25
26
|
}
|
|
26
|
-
const resp = yield
|
|
27
|
+
const resp = yield this.httpClient.send(`${this.url}/login`, http_helpers_1.GET, { Authorization: `Bearer ${this.token}` });
|
|
27
28
|
const cookies = resp.headers['set-cookie'];
|
|
28
29
|
let aggregatedCookie = "";
|
|
29
30
|
for (const cookie of cookies) {
|
package/dist/builder/index.d.ts
CHANGED
package/dist/builder/index.js
CHANGED
package/dist/builder/utils.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deriveSafe = exports.deriveProxyWallet = void 0;
|
|
4
|
-
const sdk_1 = require("@polymarket/sdk");
|
|
5
4
|
const ethers_1 = require("ethers");
|
|
6
5
|
const constants_1 = require("../constants");
|
|
7
6
|
exports.deriveProxyWallet = (address) => {
|
|
8
|
-
return
|
|
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);
|
|
9
8
|
};
|
|
10
9
|
exports.deriveSafe = (address) => {
|
|
11
10
|
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);
|
package/dist/client.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Wallet } from "@ethersproject/wallet";
|
|
2
2
|
import { JsonRpcSigner } from "@ethersproject/providers";
|
|
3
|
+
import { HttpClient } from "./http-helpers";
|
|
3
4
|
import { AddressPayload, AuthArgs, NoncePayload, ProxyTransaction, RelayPayload, SafeTransaction } from "./types";
|
|
4
5
|
export declare class RelayClient {
|
|
5
6
|
readonly relayerUrl: string;
|
|
6
7
|
readonly chainId: number;
|
|
8
|
+
readonly httpClient: HttpClient;
|
|
7
9
|
readonly signer?: Wallet | JsonRpcSigner;
|
|
8
10
|
private authHandler?;
|
|
9
11
|
constructor(relayerUrl: string, chainId: number, signer?: Wallet | JsonRpcSigner, authArgs?: AuthArgs);
|
|
@@ -12,6 +14,7 @@ export declare class RelayClient {
|
|
|
12
14
|
getNonce(signerAddress: string, signerType: string): Promise<NoncePayload>;
|
|
13
15
|
getRelayPayload(signerAddress: string, signerType: string): Promise<RelayPayload>;
|
|
14
16
|
getTransaction(transactionId: string): Promise<RelayPayload>;
|
|
17
|
+
getTransactions(): Promise<RelayPayload>;
|
|
15
18
|
executeProxyTransactions(txns: ProxyTransaction[]): Promise<any>;
|
|
16
19
|
executeSafeTransactions(txns: SafeTransaction[]): Promise<any>;
|
|
17
20
|
deploySafe(): Promise<any>;
|
package/dist/client.js
CHANGED
|
@@ -8,12 +8,14 @@ const types_1 = require("./types");
|
|
|
8
8
|
const endpoints_1 = require("./endpoints");
|
|
9
9
|
const builder_1 = require("./builder");
|
|
10
10
|
const encode_1 = require("./encode");
|
|
11
|
-
const
|
|
11
|
+
const builder_2 = require("./builder");
|
|
12
12
|
const auth_1 = require("./auth");
|
|
13
|
+
const browser_or_node_1 = require("browser-or-node");
|
|
13
14
|
class RelayClient {
|
|
14
15
|
constructor(relayerUrl, chainId, signer, authArgs) {
|
|
15
16
|
this.relayerUrl = relayerUrl.endsWith("/") ? relayerUrl.slice(0, -1) : relayerUrl;
|
|
16
17
|
this.chainId = chainId;
|
|
18
|
+
this.httpClient = new http_helpers_1.HttpClient();
|
|
17
19
|
if (signer !== undefined) {
|
|
18
20
|
this.signer = signer;
|
|
19
21
|
if (signer.provider == undefined) {
|
|
@@ -21,7 +23,7 @@ class RelayClient {
|
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
if (authArgs !== undefined) {
|
|
24
|
-
this.authHandler = new auth_1.AuthHandler(authArgs);
|
|
26
|
+
this.authHandler = new auth_1.AuthHandler(this.httpClient, authArgs);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
getOk() {
|
|
@@ -49,6 +51,11 @@ class RelayClient {
|
|
|
49
51
|
return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}?id=${transactionId}`, http_helpers_1.GET);
|
|
50
52
|
});
|
|
51
53
|
}
|
|
54
|
+
getTransactions() {
|
|
55
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}s`, http_helpers_1.GET);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
52
59
|
executeProxyTransactions(txns) {
|
|
53
60
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
61
|
if (this.signer == undefined) {
|
|
@@ -104,7 +111,7 @@ class RelayClient {
|
|
|
104
111
|
payment: "0",
|
|
105
112
|
paymentReceiver: ethers_1.ethers.constants.AddressZero,
|
|
106
113
|
};
|
|
107
|
-
const request = yield
|
|
114
|
+
const request = yield builder_2.buildSafeCreateTransactionRequest(this.signer, args);
|
|
108
115
|
console.log(`Client side request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
109
116
|
return this.postTransactionRequest(request);
|
|
110
117
|
});
|
|
@@ -118,7 +125,7 @@ class RelayClient {
|
|
|
118
125
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
119
126
|
// If client is instantiated locally/not on the browser, inject authorization cookies
|
|
120
127
|
// this is to ensure examples still run locally
|
|
121
|
-
if (this.authHandler != undefined) {
|
|
128
|
+
if (!browser_or_node_1.isBrowser && this.authHandler != undefined) {
|
|
122
129
|
const cookie = yield this.authHandler.getPolymarketCookies();
|
|
123
130
|
if (headers != undefined) {
|
|
124
131
|
headers["Cookie"] = cookie;
|
|
@@ -126,11 +133,11 @@ class RelayClient {
|
|
|
126
133
|
else {
|
|
127
134
|
headers = { "Cookie": cookie };
|
|
128
135
|
}
|
|
129
|
-
const resp = yield
|
|
136
|
+
const resp = yield this.httpClient.send(endpoint, method, headers, data, params);
|
|
130
137
|
return resp.data;
|
|
131
138
|
}
|
|
132
139
|
// If the client is instantiated on the browser, do not inject cookies
|
|
133
|
-
const resp = yield
|
|
140
|
+
const resp = yield this.httpClient.send(endpoint, method, headers, data, params);
|
|
134
141
|
return resp.data;
|
|
135
142
|
});
|
|
136
143
|
}
|
|
@@ -2,5 +2,6 @@ export declare const RELAY_HUB_ADDRESS = "0xD216153c06E857cD7f72665E0aF1d7D82172
|
|
|
2
2
|
export declare const PROXY_WALLET_FACTORY_ADDRESS = "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052";
|
|
3
3
|
export declare const SAFE_FACTORY_ADDRESS = "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b";
|
|
4
4
|
export declare const SAFE_MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761";
|
|
5
|
+
export declare const PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
|
|
5
6
|
export declare const SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
|
|
6
7
|
export declare const SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
|
package/dist/constants/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SAFE_FACTORY_NAME = exports.SAFE_INIT_CODE_HASH = exports.SAFE_MULTISEND_ADDRESS = exports.SAFE_FACTORY_ADDRESS = exports.PROXY_WALLET_FACTORY_ADDRESS = exports.RELAY_HUB_ADDRESS = void 0;
|
|
3
|
+
exports.SAFE_FACTORY_NAME = exports.SAFE_INIT_CODE_HASH = exports.PROXY_INIT_CODE_HASH = exports.SAFE_MULTISEND_ADDRESS = exports.SAFE_FACTORY_ADDRESS = exports.PROXY_WALLET_FACTORY_ADDRESS = exports.RELAY_HUB_ADDRESS = void 0;
|
|
4
4
|
exports.RELAY_HUB_ADDRESS = "0xD216153c06E857cD7f72665E0aF1d7D82172F494";
|
|
5
5
|
exports.PROXY_WALLET_FACTORY_ADDRESS = "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052";
|
|
6
6
|
exports.SAFE_FACTORY_ADDRESS = "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b";
|
|
7
7
|
exports.SAFE_MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761";
|
|
8
|
+
exports.PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
|
|
8
9
|
exports.SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
|
|
9
10
|
exports.SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosInstance, Method } from "axios";
|
|
2
2
|
export declare const GET = "GET";
|
|
3
3
|
export declare const POST = "POST";
|
|
4
4
|
export declare const DELETE = "DELETE";
|
|
5
5
|
export declare const PUT = "PUT";
|
|
6
|
-
export declare
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
headers?:
|
|
10
|
-
data?: any;
|
|
11
|
-
params?: QueryParams;
|
|
6
|
+
export declare class HttpClient {
|
|
7
|
+
readonly instance: AxiosInstance;
|
|
8
|
+
constructor();
|
|
9
|
+
send(endpoint: string, method: Method, headers?: any, data?: any, params?: any): Promise<any>;
|
|
12
10
|
}
|
|
13
|
-
export declare const post: (endpoint: string, options?: RequestOptions | undefined) => Promise<any>;
|
|
14
|
-
export declare const raw_get: (endpoint: string, options?: RequestOptions | undefined) => Promise<any>;
|
|
15
|
-
export declare const get: (endpoint: string, options?: RequestOptions | undefined) => Promise<any>;
|
|
16
|
-
export declare const del: (endpoint: string, options?: RequestOptions | undefined) => Promise<any>;
|
|
@@ -1,69 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.HttpClient = exports.PUT = exports.DELETE = exports.POST = exports.GET = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
6
|
exports.GET = "GET";
|
|
7
7
|
exports.POST = "POST";
|
|
8
8
|
exports.DELETE = "DELETE";
|
|
9
9
|
exports.PUT = "PUT";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const resp = yield axios_1.default({
|
|
15
|
-
withCredentials: true,
|
|
16
|
-
method,
|
|
17
|
-
url: endpoint,
|
|
18
|
-
headers,
|
|
19
|
-
data,
|
|
20
|
-
params
|
|
21
|
-
});
|
|
22
|
-
return resp;
|
|
10
|
+
class HttpClient {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.instance = axios_1.default.create({ withCredentials: true });
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
statusText: (_b = err.response) === null || _b === void 0 ? void 0 : _b.statusText,
|
|
31
|
-
data: (_c = err.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
32
|
-
};
|
|
33
|
-
console.error("request error", errPayload);
|
|
34
|
-
throw new Error(JSON.stringify(errPayload));
|
|
14
|
+
send(endpoint, method, headers, data, params) {
|
|
15
|
+
var _a, _b, _c;
|
|
16
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
console.log(`In HttpClient send`);
|
|
18
|
+
if (headers != undefined) {
|
|
19
|
+
headers["Access-Control-Allow-Credentials"] = true;
|
|
35
20
|
}
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
try {
|
|
22
|
+
const resp = yield this.instance.request({
|
|
23
|
+
method,
|
|
24
|
+
url: endpoint,
|
|
25
|
+
headers,
|
|
26
|
+
data,
|
|
27
|
+
params
|
|
28
|
+
});
|
|
29
|
+
return resp;
|
|
40
30
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
exports.del = (endpoint, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
-
const resp = yield exports.request(endpoint, exports.DELETE, options === null || options === void 0 ? void 0 : options.headers, options === null || options === void 0 ? void 0 : options.data, options === null || options === void 0 ? void 0 : options.params);
|
|
65
|
-
if ("error" in resp) {
|
|
66
|
-
throw new Error(resp);
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (axios_1.default.isAxiosError(err)) {
|
|
33
|
+
if (err.response) {
|
|
34
|
+
const errPayload = {
|
|
35
|
+
error: "request error",
|
|
36
|
+
status: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
37
|
+
statusText: (_b = err.response) === null || _b === void 0 ? void 0 : _b.statusText,
|
|
38
|
+
data: (_c = err.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
39
|
+
};
|
|
40
|
+
console.error("request error", errPayload);
|
|
41
|
+
throw new Error(JSON.stringify(errPayload));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const errPayload = { error: "connection error" };
|
|
45
|
+
console.error("connection error", errPayload);
|
|
46
|
+
throw new Error(JSON.stringify(errPayload));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw new Error(JSON.stringify({ error: err }));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
67
52
|
}
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
}
|
|
54
|
+
exports.HttpClient = HttpClient;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymarket/relayer-client",
|
|
3
3
|
"description": "Client for Polymarket relayers",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"clean": "rm -rf ./dist"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@polymarket/sdk": "^5.0.3",
|
|
16
15
|
"axios": "^0.27.2",
|
|
16
|
+
"browser-or-node": "^3.0.0",
|
|
17
17
|
"ethers": "^5.7.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"@typescript-eslint/eslint-plugin": "^5.37.0",
|
|
25
25
|
"@typescript-eslint/parser": "^5.37.0",
|
|
26
26
|
"chai": "^4.3.6",
|
|
27
|
+
"dotenv": "^16.0.2",
|
|
27
28
|
"eslint": "^8.23.1",
|
|
28
29
|
"eslint-config-prettier": "^8.5.0",
|
|
29
30
|
"eslint-config-standard-with-typescript": "^23.0.0",
|
|
@@ -33,10 +34,9 @@
|
|
|
33
34
|
"eslint-plugin-promise": "^6.0.1",
|
|
34
35
|
"eslint-plugin-unused-imports": "^2.0.0",
|
|
35
36
|
"esm": "^3.2.25",
|
|
36
|
-
"dotenv": "^16.0.2",
|
|
37
|
-
"path": "^0.12.7",
|
|
38
37
|
"mocha": "^10.0.0",
|
|
39
38
|
"nyc": "^15.1.0",
|
|
39
|
+
"path": "^0.12.7",
|
|
40
40
|
"prettier": "^2.7.1",
|
|
41
41
|
"ts-mocha": "^10.0.0",
|
|
42
42
|
"ts-node": "^9.1.1",
|