@polymarket/relayer-client 0.0.2 → 0.0.4
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.js +1 -5
- package/dist/client.d.ts +4 -5
- package/dist/client.js +30 -51
- package/dist/endpoints.d.ts +0 -1
- package/dist/endpoints.js +1 -2
- package/dist/http-helpers/index.js +19 -8
- package/package.json +1 -1
package/dist/auth/handler.js
CHANGED
|
@@ -23,11 +23,7 @@ class AuthHandler {
|
|
|
23
23
|
if (this.token == undefined) {
|
|
24
24
|
throw new Error("authorization token missing");
|
|
25
25
|
}
|
|
26
|
-
const resp = yield http_helpers_1.
|
|
27
|
-
headers: {
|
|
28
|
-
Authorization: `Bearer ${this.token}`
|
|
29
|
-
},
|
|
30
|
-
});
|
|
26
|
+
const resp = yield http_helpers_1.request(`${this.url}/login`, http_helpers_1.GET, { Authorization: `Bearer ${this.token}` });
|
|
31
27
|
const cookies = resp.headers['set-cookie'];
|
|
32
28
|
let aggregatedCookie = "";
|
|
33
29
|
for (const cookie of cookies) {
|
package/dist/client.d.ts
CHANGED
|
@@ -5,9 +5,8 @@ export declare class RelayClient {
|
|
|
5
5
|
readonly relayerUrl: string;
|
|
6
6
|
readonly chainId: number;
|
|
7
7
|
readonly signer?: Wallet | JsonRpcSigner;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(relayerUrl: string, chainId: number, authArgs: AuthArgs, signer?: Wallet | JsonRpcSigner, wsRelayerUrl?: string);
|
|
8
|
+
private authHandler?;
|
|
9
|
+
constructor(relayerUrl: string, chainId: number, signer?: Wallet | JsonRpcSigner, authArgs?: AuthArgs);
|
|
11
10
|
getOk(): Promise<any>;
|
|
12
11
|
getRelayAddress(): Promise<AddressPayload>;
|
|
13
12
|
getNonce(signerAddress: string, signerType: string): Promise<NoncePayload>;
|
|
@@ -16,6 +15,6 @@ export declare class RelayClient {
|
|
|
16
15
|
executeProxyTransactions(txns: ProxyTransaction[]): Promise<any>;
|
|
17
16
|
executeSafeTransactions(txns: SafeTransaction[]): Promise<any>;
|
|
18
17
|
deploySafe(): Promise<any>;
|
|
19
|
-
|
|
20
|
-
private
|
|
18
|
+
private postTransactionRequest;
|
|
19
|
+
private send;
|
|
21
20
|
}
|
package/dist/client.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RelayClient = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
|
-
const ws_1 = require("ws");
|
|
7
6
|
const http_helpers_1 = require("./http-helpers");
|
|
8
7
|
const types_1 = require("./types");
|
|
9
8
|
const endpoints_1 = require("./endpoints");
|
|
@@ -12,43 +11,42 @@ const encode_1 = require("./encode");
|
|
|
12
11
|
const create_1 = require("./builder/create");
|
|
13
12
|
const auth_1 = require("./auth");
|
|
14
13
|
class RelayClient {
|
|
15
|
-
constructor(relayerUrl, chainId,
|
|
14
|
+
constructor(relayerUrl, chainId, signer, authArgs) {
|
|
16
15
|
this.relayerUrl = relayerUrl.endsWith("/") ? relayerUrl.slice(0, -1) : relayerUrl;
|
|
17
16
|
this.chainId = chainId;
|
|
18
|
-
this.authHandler = new auth_1.AuthHandler(authArgs);
|
|
19
17
|
if (signer !== undefined) {
|
|
20
18
|
this.signer = signer;
|
|
21
19
|
if (signer.provider == undefined) {
|
|
22
20
|
throw new Error("signer must have provider attached");
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
|
-
if (
|
|
26
|
-
this.
|
|
23
|
+
if (authArgs !== undefined) {
|
|
24
|
+
this.authHandler = new auth_1.AuthHandler(authArgs);
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
getOk() {
|
|
30
28
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
return
|
|
29
|
+
return this.send(`${this.relayerUrl}/`, http_helpers_1.GET);
|
|
32
30
|
});
|
|
33
31
|
}
|
|
34
32
|
getRelayAddress() {
|
|
35
33
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
return
|
|
34
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_ADDRESS}`, http_helpers_1.GET);
|
|
37
35
|
});
|
|
38
36
|
}
|
|
39
37
|
getNonce(signerAddress, signerType) {
|
|
40
38
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
return
|
|
39
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_NONCE}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
|
|
42
40
|
});
|
|
43
41
|
}
|
|
44
42
|
getRelayPayload(signerAddress, signerType) {
|
|
45
43
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
return
|
|
44
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_RELAY_PAYLOAD}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
|
|
47
45
|
});
|
|
48
46
|
}
|
|
49
47
|
getTransaction(transactionId) {
|
|
50
48
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
return
|
|
49
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}?id=${transactionId}`, http_helpers_1.GET);
|
|
52
50
|
});
|
|
53
51
|
}
|
|
54
52
|
executeProxyTransactions(txns) {
|
|
@@ -68,7 +66,7 @@ class RelayClient {
|
|
|
68
66
|
};
|
|
69
67
|
const request = yield builder_1.buildProxyTransactionRequest(this.signer, args);
|
|
70
68
|
console.log(`Client side request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
71
|
-
return this.
|
|
69
|
+
return this.postTransactionRequest(request);
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
72
|
executeSafeTransactions(txns) {
|
|
@@ -88,7 +86,7 @@ class RelayClient {
|
|
|
88
86
|
};
|
|
89
87
|
const request = yield builder_1.buildSafeTransactionRequest(this.signer, args);
|
|
90
88
|
console.log(`Client side request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
91
|
-
return this.
|
|
89
|
+
return this.postTransactionRequest(request);
|
|
92
90
|
});
|
|
93
91
|
}
|
|
94
92
|
deploySafe() {
|
|
@@ -108,51 +106,32 @@ class RelayClient {
|
|
|
108
106
|
};
|
|
109
107
|
const request = yield create_1.buildSafeCreateTransactionRequest(this.signer, args);
|
|
110
108
|
console.log(`Client side request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
111
|
-
return this.
|
|
109
|
+
return this.postTransactionRequest(request);
|
|
112
110
|
});
|
|
113
111
|
}
|
|
114
|
-
|
|
112
|
+
postTransactionRequest(req) {
|
|
115
113
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
|
|
117
|
-
throw new Error("missing signer");
|
|
118
|
-
}
|
|
119
|
-
if (this.wsRelayerUrl == undefined) {
|
|
120
|
-
throw new Error("missing websocket url");
|
|
121
|
-
}
|
|
122
|
-
const from = yield this.signer.getAddress();
|
|
123
|
-
const txns = [];
|
|
124
|
-
if (transactionId !== undefined) {
|
|
125
|
-
txns.push(transactionId);
|
|
126
|
-
}
|
|
127
|
-
const authCookies = yield this.authHandler.getPolymarketCookies();
|
|
128
|
-
const req = {
|
|
129
|
-
address: from,
|
|
130
|
-
transactions: txns,
|
|
131
|
-
cookies: authCookies,
|
|
132
|
-
};
|
|
133
|
-
const ws = new ws_1.WebSocket(`${this.wsRelayerUrl}${endpoints_1.WS_CONNECTION}`);
|
|
134
|
-
ws.on("open", function () {
|
|
135
|
-
ws.send(JSON.stringify(req));
|
|
136
|
-
setInterval(() => {
|
|
137
|
-
ws.send("PING");
|
|
138
|
-
}, 5000);
|
|
139
|
-
});
|
|
140
|
-
ws.onmessage = function (msg) {
|
|
141
|
-
console.log(`Received ws message:`);
|
|
142
|
-
console.log(msg.data);
|
|
143
|
-
};
|
|
144
|
-
ws.on("close", function (e) {
|
|
145
|
-
console.log("WS Connection closed, reason: " + e);
|
|
146
|
-
return;
|
|
147
|
-
});
|
|
114
|
+
return this.send(`${this.relayerUrl}${endpoints_1.SUBMIT_TRANSACTION}`, http_helpers_1.POST, undefined, req);
|
|
148
115
|
});
|
|
149
116
|
}
|
|
150
|
-
|
|
117
|
+
send(endpoint, method, headers, data, params) {
|
|
151
118
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
119
|
+
// If client is instantiated locally/not on the browser, inject authorization cookies
|
|
120
|
+
// this is to ensure examples still run locally
|
|
121
|
+
if (this.authHandler != undefined) {
|
|
122
|
+
const cookie = yield this.authHandler.getPolymarketCookies();
|
|
123
|
+
if (headers != undefined) {
|
|
124
|
+
headers["Cookie"] = cookie;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
headers = { "Cookie": cookie };
|
|
128
|
+
}
|
|
129
|
+
const resp = yield http_helpers_1.request(endpoint, method, headers, data, params);
|
|
130
|
+
return resp.data;
|
|
131
|
+
}
|
|
132
|
+
// If the client is instantiated on the browser, do not inject cookies
|
|
133
|
+
const resp = yield http_helpers_1.request(endpoint, method, headers, data, params);
|
|
134
|
+
return resp.data;
|
|
156
135
|
});
|
|
157
136
|
}
|
|
158
137
|
}
|
package/dist/endpoints.d.ts
CHANGED
package/dist/endpoints.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SUBMIT_TRANSACTION = exports.GET_TRANSACTION = exports.GET_RELAY_PAYLOAD = exports.GET_NONCE = exports.GET_ADDRESS = void 0;
|
|
4
4
|
exports.GET_ADDRESS = "/address";
|
|
5
5
|
exports.GET_NONCE = "/nonce";
|
|
6
6
|
exports.GET_RELAY_PAYLOAD = "/relay-payload";
|
|
7
7
|
exports.GET_TRANSACTION = "/transaction";
|
|
8
8
|
exports.SUBMIT_TRANSACTION = "/submit";
|
|
9
|
-
exports.WS_CONNECTION = "/ws";
|
|
@@ -7,28 +7,39 @@ exports.GET = "GET";
|
|
|
7
7
|
exports.POST = "POST";
|
|
8
8
|
exports.DELETE = "DELETE";
|
|
9
9
|
exports.PUT = "PUT";
|
|
10
|
+
axios_1.default.defaults.withCredentials = true;
|
|
10
11
|
exports.request = (endpoint, method, headers, data, params) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
-
var _a, _b, _c
|
|
12
|
+
var _a, _b, _c;
|
|
12
13
|
try {
|
|
13
|
-
const
|
|
14
|
-
|
|
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;
|
|
15
23
|
}
|
|
16
24
|
catch (err) {
|
|
17
25
|
if (axios_1.default.isAxiosError(err)) {
|
|
18
26
|
if (err.response) {
|
|
19
|
-
|
|
27
|
+
const errPayload = {
|
|
20
28
|
error: "request error",
|
|
21
29
|
status: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
22
30
|
statusText: (_b = err.response) === null || _b === void 0 ? void 0 : _b.statusText,
|
|
23
31
|
data: (_c = err.response) === null || _c === void 0 ? void 0 : _c.data,
|
|
24
|
-
}
|
|
25
|
-
|
|
32
|
+
};
|
|
33
|
+
console.error("request error", errPayload);
|
|
34
|
+
throw new Error(JSON.stringify(errPayload));
|
|
26
35
|
}
|
|
27
36
|
else {
|
|
28
|
-
|
|
37
|
+
const errPayload = { error: "connection error" };
|
|
38
|
+
console.error("connection error", errPayload);
|
|
39
|
+
throw new Error(JSON.stringify(errPayload));
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
|
-
|
|
42
|
+
throw new Error(JSON.stringify({ error: err }));
|
|
32
43
|
}
|
|
33
44
|
});
|
|
34
45
|
exports.post = (endpoint, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|