@polymarket/relayer-client 0.0.13 → 1.0.1
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/client.d.ts +8 -7
- package/dist/client.js +27 -4
- package/dist/types.d.ts +26 -0
- package/dist/types.js +9 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +7 -0
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Wallet } from "@ethersproject/wallet";
|
|
2
2
|
import { JsonRpcSigner } from "@ethersproject/providers";
|
|
3
3
|
import { HttpClient } from "./http-helpers";
|
|
4
|
-
import { AddressPayload, AuthArgs, NoncePayload, ProxyTransaction, RelayPayload, SafeTransaction } from "./types";
|
|
4
|
+
import { AddressPayload, AuthArgs, NoncePayload, ProxyTransaction, RelayerTransaction, RelayerTransactionResponse, RelayPayload, SafeTransaction } from "./types";
|
|
5
5
|
import { AuthHandler } from "./auth";
|
|
6
6
|
export declare class RelayClient {
|
|
7
7
|
readonly relayerUrl: string;
|
|
@@ -13,11 +13,12 @@ export declare class RelayClient {
|
|
|
13
13
|
getRelayAddress(): Promise<AddressPayload>;
|
|
14
14
|
getNonce(signerAddress: string, signerType: string): Promise<NoncePayload>;
|
|
15
15
|
getRelayPayload(signerAddress: string, signerType: string): Promise<RelayPayload>;
|
|
16
|
-
getTransaction(transactionId: string): Promise<
|
|
17
|
-
getTransactions(): Promise<
|
|
18
|
-
executeProxyTransactions(txns: ProxyTransaction[]): Promise<
|
|
19
|
-
executeSafeTransactions(txns: SafeTransaction[]): Promise<
|
|
20
|
-
deploySafe(): Promise<
|
|
21
|
-
|
|
16
|
+
getTransaction(transactionId: string): Promise<RelayerTransaction[]>;
|
|
17
|
+
getTransactions(): Promise<RelayerTransaction[]>;
|
|
18
|
+
executeProxyTransactions(txns: ProxyTransaction[]): Promise<RelayerTransactionResponse>;
|
|
19
|
+
executeSafeTransactions(txns: SafeTransaction[]): Promise<RelayerTransactionResponse>;
|
|
20
|
+
deploySafe(): Promise<RelayerTransactionResponse>;
|
|
21
|
+
pollUntilState(transactionId: string, states: string[], maxPolls?: number): Promise<RelayerTransaction | undefined>;
|
|
22
|
+
private submitTransaction;
|
|
22
23
|
private send;
|
|
23
24
|
}
|
package/dist/client.js
CHANGED
|
@@ -11,6 +11,7 @@ const builder_1 = require("./builder");
|
|
|
11
11
|
const encode_1 = require("./encode");
|
|
12
12
|
const builder_2 = require("./builder");
|
|
13
13
|
const auth_1 = require("./auth");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
14
15
|
class RelayClient {
|
|
15
16
|
constructor(relayerUrl, chainId, signer, authArgs) {
|
|
16
17
|
this.relayerUrl = relayerUrl.endsWith("/") ? relayerUrl.slice(0, -1) : relayerUrl;
|
|
@@ -68,7 +69,7 @@ class RelayClient {
|
|
|
68
69
|
};
|
|
69
70
|
const request = yield builder_1.buildProxyTransactionRequest(this.signer, args);
|
|
70
71
|
console.log(`Client side request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
71
|
-
return this.
|
|
72
|
+
return this.submitTransaction(request);
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
executeSafeTransactions(txns) {
|
|
@@ -88,7 +89,7 @@ class RelayClient {
|
|
|
88
89
|
};
|
|
89
90
|
const request = yield builder_1.buildSafeTransactionRequest(this.signer, args);
|
|
90
91
|
console.log(`Client side request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
91
|
-
return this.
|
|
92
|
+
return this.submitTransaction(request);
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
95
|
deploySafe() {
|
|
@@ -108,10 +109,32 @@ class RelayClient {
|
|
|
108
109
|
};
|
|
109
110
|
const request = yield builder_2.buildSafeCreateTransactionRequest(this.signer, args);
|
|
110
111
|
console.log(`Client side request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
111
|
-
return this.
|
|
112
|
+
return this.submitTransaction(request);
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
+
// Periodically polls the transaction id until it reaches a desired state
|
|
116
|
+
// Returns the relayer transaction if it does each the desired state
|
|
117
|
+
// Times out after 10s
|
|
118
|
+
pollUntilState(transactionId, states, maxPolls) {
|
|
119
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
console.log(`Waiting for transaction ${transactionId} matching states: ${states}...`);
|
|
121
|
+
const maxPollCount = maxPolls != undefined ? maxPolls : 10;
|
|
122
|
+
let pollCount = 0;
|
|
123
|
+
while (pollCount < maxPollCount) {
|
|
124
|
+
const txns = yield this.getTransaction(transactionId);
|
|
125
|
+
if (txns.length > 0) {
|
|
126
|
+
const txn = txns[0];
|
|
127
|
+
if (states.includes(txn.state)) {
|
|
128
|
+
return txn;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
pollCount++;
|
|
132
|
+
yield utils_1.sleep(1000);
|
|
133
|
+
}
|
|
134
|
+
console.log(`Transaction not found or not in given states, timing out`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
submitTransaction(req) {
|
|
115
138
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
116
139
|
return this.send(`${this.relayerUrl}${endpoints_1.SUBMIT_TRANSACTION}`, http_helpers_1.POST, undefined, req);
|
|
117
140
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -80,6 +80,17 @@ export interface SafeCreateTransactionArgs {
|
|
|
80
80
|
payment: string;
|
|
81
81
|
paymentReceiver: string;
|
|
82
82
|
}
|
|
83
|
+
export declare enum RelayerTransactionState {
|
|
84
|
+
STATE_NEW = "STATE_NEW",
|
|
85
|
+
STATE_EXECUTED = "STATE_EXECUTED",
|
|
86
|
+
STATE_INVALID = "STATE_INVALID",
|
|
87
|
+
STATE_CONFIRMED = "STATE_CONFIRMED",
|
|
88
|
+
STATE_FAILED = "STATE_FAILED"
|
|
89
|
+
}
|
|
90
|
+
export interface RelayerTransactionResponse {
|
|
91
|
+
transactionID: string;
|
|
92
|
+
state: string;
|
|
93
|
+
}
|
|
83
94
|
export interface RelayerSubRequest {
|
|
84
95
|
address: string;
|
|
85
96
|
transactions: string[];
|
|
@@ -89,3 +100,18 @@ export interface AuthArgs {
|
|
|
89
100
|
authUrl: string;
|
|
90
101
|
authToken: string;
|
|
91
102
|
}
|
|
103
|
+
export interface RelayerTransaction {
|
|
104
|
+
transactionID: string;
|
|
105
|
+
transactionHash: string;
|
|
106
|
+
from: string;
|
|
107
|
+
to: string;
|
|
108
|
+
proxyAddress: string;
|
|
109
|
+
data: string;
|
|
110
|
+
nonce: string;
|
|
111
|
+
value: string;
|
|
112
|
+
state: string;
|
|
113
|
+
type: string;
|
|
114
|
+
metadata: string;
|
|
115
|
+
createdAt: Date;
|
|
116
|
+
updatedAt: Date;
|
|
117
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OperationType = exports.CallType = exports.TransactionType = void 0;
|
|
3
|
+
exports.RelayerTransactionState = exports.OperationType = exports.CallType = exports.TransactionType = void 0;
|
|
4
4
|
var TransactionType;
|
|
5
5
|
(function (TransactionType) {
|
|
6
6
|
TransactionType["PROXY"] = "PROXY";
|
|
@@ -19,3 +19,11 @@ var OperationType;
|
|
|
19
19
|
OperationType[OperationType["Call"] = 0] = "Call";
|
|
20
20
|
OperationType[OperationType["DelegateCall"] = 1] = "DelegateCall";
|
|
21
21
|
})(OperationType = exports.OperationType || (exports.OperationType = {}));
|
|
22
|
+
var RelayerTransactionState;
|
|
23
|
+
(function (RelayerTransactionState) {
|
|
24
|
+
RelayerTransactionState["STATE_NEW"] = "STATE_NEW";
|
|
25
|
+
RelayerTransactionState["STATE_EXECUTED"] = "STATE_EXECUTED";
|
|
26
|
+
RelayerTransactionState["STATE_INVALID"] = "STATE_INVALID";
|
|
27
|
+
RelayerTransactionState["STATE_CONFIRMED"] = "STATE_CONFIRMED";
|
|
28
|
+
RelayerTransactionState["STATE_FAILED"] = "STATE_FAILED";
|
|
29
|
+
})(RelayerTransactionState = exports.RelayerTransactionState || (exports.RelayerTransactionState = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number): Promise<unknown>;
|