@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/client.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RelayClient = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const ethers_1 = require("ethers");
|
|
6
5
|
const browser_or_node_1 = tslib_1.__importDefault(require("browser-or-node"));
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const abstract_signer_1 = require("@polymarket/abstract-signer");
|
|
7
8
|
const http_helpers_1 = require("./http-helpers");
|
|
8
9
|
const types_1 = require("./types");
|
|
9
10
|
const endpoints_1 = require("./endpoints");
|
|
@@ -13,116 +14,107 @@ const auth_1 = require("./auth");
|
|
|
13
14
|
const utils_1 = require("./utils");
|
|
14
15
|
const manual_1 = require("./manual");
|
|
15
16
|
const response_1 = require("./response");
|
|
17
|
+
const config_1 = require("./config");
|
|
16
18
|
class RelayClient {
|
|
19
|
+
relayerUrl;
|
|
20
|
+
chainId;
|
|
21
|
+
contractConfig;
|
|
22
|
+
httpClient;
|
|
23
|
+
signer;
|
|
24
|
+
authHandler;
|
|
17
25
|
constructor(relayerUrl, chainId, signer, authArgs) {
|
|
18
26
|
this.relayerUrl = relayerUrl.endsWith("/") ? relayerUrl.slice(0, -1) : relayerUrl;
|
|
19
27
|
this.chainId = chainId;
|
|
28
|
+
this.contractConfig = (0, config_1.getContractConfig)(chainId);
|
|
20
29
|
this.httpClient = new http_helpers_1.HttpClient();
|
|
21
30
|
if (signer != undefined) {
|
|
22
|
-
this.signer = signer;
|
|
31
|
+
this.signer = (0, abstract_signer_1.createAbstractSigner)(chainId, signer);
|
|
23
32
|
}
|
|
24
33
|
if (authArgs !== undefined) {
|
|
25
34
|
this.authHandler = new auth_1.AuthHandler(this.httpClient, authArgs);
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
|
-
getRelayAddress() {
|
|
29
|
-
return
|
|
30
|
-
return this.send(`${this.relayerUrl}${endpoints_1.GET_ADDRESS}`, http_helpers_1.GET);
|
|
31
|
-
});
|
|
37
|
+
async getRelayAddress() {
|
|
38
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_ADDRESS}`, http_helpers_1.GET);
|
|
32
39
|
}
|
|
33
|
-
getNonce(signerAddress, signerType) {
|
|
34
|
-
return
|
|
35
|
-
return this.send(`${this.relayerUrl}${endpoints_1.GET_NONCE}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
|
|
36
|
-
});
|
|
40
|
+
async getNonce(signerAddress, signerType) {
|
|
41
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_NONCE}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
|
|
37
42
|
}
|
|
38
|
-
getRelayPayload(signerAddress, signerType) {
|
|
39
|
-
return
|
|
40
|
-
return this.send(`${this.relayerUrl}${endpoints_1.GET_RELAY_PAYLOAD}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
|
|
41
|
-
});
|
|
43
|
+
async getRelayPayload(signerAddress, signerType) {
|
|
44
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_RELAY_PAYLOAD}?address=${signerAddress}&type=${signerType}`, http_helpers_1.GET);
|
|
42
45
|
}
|
|
43
|
-
getTransaction(transactionId) {
|
|
44
|
-
return
|
|
45
|
-
return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}?id=${transactionId}`, http_helpers_1.GET);
|
|
46
|
-
});
|
|
46
|
+
async getTransaction(transactionId) {
|
|
47
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}?id=${transactionId}`, http_helpers_1.GET);
|
|
47
48
|
}
|
|
48
|
-
getTransactions() {
|
|
49
|
-
return
|
|
50
|
-
return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}s`, http_helpers_1.GET);
|
|
51
|
-
});
|
|
49
|
+
async getTransactions() {
|
|
50
|
+
return this.send(`${this.relayerUrl}${endpoints_1.GET_TRANSACTION}s`, http_helpers_1.GET);
|
|
52
51
|
}
|
|
53
|
-
executeProxyTransactions(txns, metadata) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
52
|
+
async executeProxyTransactions(txns, metadata) {
|
|
53
|
+
if (this.signer == undefined) {
|
|
54
|
+
throw new Error("missing signer");
|
|
55
|
+
}
|
|
56
|
+
const start = Date.now();
|
|
57
|
+
const from = await this.signer.getAddress();
|
|
58
|
+
const rp = await this.getRelayPayload(from, types_1.TransactionType.PROXY);
|
|
59
|
+
const args = {
|
|
60
|
+
from: from,
|
|
61
|
+
gasPrice: "0",
|
|
62
|
+
data: (0, encode_1.encodeProxyTransactionData)(txns),
|
|
63
|
+
relay: rp.address,
|
|
64
|
+
nonce: rp.nonce,
|
|
65
|
+
};
|
|
66
|
+
const proxyContractConfig = this.contractConfig.ProxyContracts;
|
|
67
|
+
const request = await (0, builder_1.buildProxyTransactionRequest)(this.signer, args, proxyContractConfig, metadata);
|
|
68
|
+
console.log(`Client side proxy request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
69
|
+
const resp = await this.submitTransaction(request);
|
|
70
|
+
return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
73
71
|
}
|
|
74
|
-
executeSafeTransactions(txns, metadata) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
93
|
-
});
|
|
72
|
+
async executeSafeTransactions(txns, metadata) {
|
|
73
|
+
if (this.signer == undefined) {
|
|
74
|
+
throw new Error("missing signer");
|
|
75
|
+
}
|
|
76
|
+
const start = Date.now();
|
|
77
|
+
const from = await this.signer.getAddress();
|
|
78
|
+
const noncePayload = await this.getNonce(from, types_1.TransactionType.SAFE);
|
|
79
|
+
const args = {
|
|
80
|
+
transactions: txns,
|
|
81
|
+
from,
|
|
82
|
+
nonce: noncePayload.nonce,
|
|
83
|
+
chainId: this.chainId,
|
|
84
|
+
};
|
|
85
|
+
const safeContractConfig = this.contractConfig.SafeContracts;
|
|
86
|
+
const request = await (0, builder_1.buildSafeTransactionRequest)(this.signer, args, safeContractConfig, metadata);
|
|
87
|
+
console.log(`Client side safe request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
88
|
+
const resp = await this.submitTransaction(request);
|
|
89
|
+
return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
94
90
|
}
|
|
95
|
-
executeManualTransactions(txns, overrides) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return (0, manual_1.executeManualTransactions)(this.signer, txns, overrides);
|
|
104
|
-
});
|
|
91
|
+
async executeManualTransactions(txns, overrides) {
|
|
92
|
+
if (overrides == undefined) {
|
|
93
|
+
overrides = {};
|
|
94
|
+
}
|
|
95
|
+
if (this.signer == undefined) {
|
|
96
|
+
throw new Error("missing signer");
|
|
97
|
+
}
|
|
98
|
+
return (0, manual_1.executeManualTransactions)(this.signer, this.contractConfig.SafeContracts, txns, overrides);
|
|
105
99
|
}
|
|
106
|
-
deploySafe() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
125
|
-
});
|
|
100
|
+
async deploySafe() {
|
|
101
|
+
if (this.signer == undefined) {
|
|
102
|
+
throw new Error("missing signer");
|
|
103
|
+
}
|
|
104
|
+
const start = Date.now();
|
|
105
|
+
const from = await this.signer?.getAddress();
|
|
106
|
+
const args = {
|
|
107
|
+
from: from,
|
|
108
|
+
chainId: this.chainId,
|
|
109
|
+
paymentToken: viem_1.zeroAddress,
|
|
110
|
+
payment: "0",
|
|
111
|
+
paymentReceiver: viem_1.zeroAddress,
|
|
112
|
+
};
|
|
113
|
+
const safeContractConfig = this.contractConfig.SafeContracts;
|
|
114
|
+
const request = await (0, builder_1.buildSafeCreateTransactionRequest)(this.signer, safeContractConfig, args);
|
|
115
|
+
console.log(`Client side deploy request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
116
|
+
const resp = await this.submitTransaction(request);
|
|
117
|
+
return new response_1.ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
126
118
|
}
|
|
127
119
|
/**
|
|
128
120
|
* Periodically polls the transaction id until it reaches a desired state
|
|
@@ -134,53 +126,47 @@ class RelayClient {
|
|
|
134
126
|
* @param pollFrequency
|
|
135
127
|
* @returns
|
|
136
128
|
*/
|
|
137
|
-
pollUntilState(transactionId, states, maxPolls, pollFrequency) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (pollFrequency
|
|
143
|
-
|
|
144
|
-
pollFreq = pollFrequency;
|
|
145
|
-
}
|
|
129
|
+
async pollUntilState(transactionId, states, maxPolls, pollFrequency) {
|
|
130
|
+
console.log(`Waiting for transaction ${transactionId} matching states: ${states}...`);
|
|
131
|
+
const maxPollCount = maxPolls != undefined ? maxPolls : 10;
|
|
132
|
+
let pollFreq = 2000; // Default to polling every 2 seconds
|
|
133
|
+
if (pollFrequency != undefined) {
|
|
134
|
+
if (pollFrequency >= 1000) {
|
|
135
|
+
pollFreq = pollFrequency;
|
|
146
136
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
137
|
+
}
|
|
138
|
+
let pollCount = 0;
|
|
139
|
+
while (pollCount < maxPollCount) {
|
|
140
|
+
const txns = await this.getTransaction(transactionId);
|
|
141
|
+
if (txns.length > 0) {
|
|
142
|
+
const txn = txns[0];
|
|
143
|
+
if (states.includes(txn.state)) {
|
|
144
|
+
return txn;
|
|
155
145
|
}
|
|
156
|
-
pollCount++;
|
|
157
|
-
yield (0, utils_1.sleep)(pollFreq);
|
|
158
146
|
}
|
|
159
|
-
|
|
160
|
-
|
|
147
|
+
pollCount++;
|
|
148
|
+
await (0, utils_1.sleep)(pollFreq);
|
|
149
|
+
}
|
|
150
|
+
console.log(`Transaction not found or not in given states, timing out`);
|
|
161
151
|
}
|
|
162
|
-
submitTransaction(req) {
|
|
163
|
-
return
|
|
164
|
-
return this.send(`${this.relayerUrl}${endpoints_1.SUBMIT_TRANSACTION}`, http_helpers_1.POST, undefined, req);
|
|
165
|
-
});
|
|
152
|
+
async submitTransaction(req) {
|
|
153
|
+
return this.send(`${this.relayerUrl}${endpoints_1.SUBMIT_TRANSACTION}`, http_helpers_1.POST, undefined, req);
|
|
166
154
|
}
|
|
167
|
-
send(endpoint, method, headers, data, params) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
headers["Cookie"] = cookie;
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
headers = { "Cookie": cookie };
|
|
179
|
-
}
|
|
155
|
+
async send(endpoint, method, headers, data, params) {
|
|
156
|
+
// Explicitly inject the polymarket session cookies
|
|
157
|
+
// In prod environments, this will be unnecessary as the browser will have the needed cookies
|
|
158
|
+
// Needed only for local testing
|
|
159
|
+
if (!browser_or_node_1.default && this.authHandler !== undefined) {
|
|
160
|
+
const cookie = await this.authHandler.getPolymarketCookies();
|
|
161
|
+
if (headers != undefined) {
|
|
162
|
+
headers["Cookie"] = cookie;
|
|
180
163
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
164
|
+
else {
|
|
165
|
+
headers = { "Cookie": cookie };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const resp = await this.httpClient.send(endpoint, method, headers, data, params);
|
|
169
|
+
return resp.data;
|
|
184
170
|
}
|
|
185
171
|
}
|
|
186
172
|
exports.RelayClient = RelayClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ProxyContractConfig {
|
|
2
|
+
RelayHub: string;
|
|
3
|
+
ProxyFactory: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SafeContractConfig {
|
|
6
|
+
SafeFactory: string;
|
|
7
|
+
SafeMultisend: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ContractConfig {
|
|
10
|
+
ProxyContracts: ProxyContractConfig;
|
|
11
|
+
SafeContracts: SafeContractConfig;
|
|
12
|
+
}
|
|
13
|
+
export declare const getContractConfig: (chainId: number) => ContractConfig;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContractConfig = void 0;
|
|
4
|
+
;
|
|
5
|
+
const AMOY = {
|
|
6
|
+
ProxyContracts: {
|
|
7
|
+
ProxyFactory: "",
|
|
8
|
+
RelayHub: ""
|
|
9
|
+
},
|
|
10
|
+
SafeContracts: {
|
|
11
|
+
SafeFactory: "",
|
|
12
|
+
SafeMultisend: "",
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const POL = {
|
|
16
|
+
ProxyContracts: {
|
|
17
|
+
ProxyFactory: "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052",
|
|
18
|
+
RelayHub: "0xD216153c06E857cD7f72665E0aF1d7D82172F494"
|
|
19
|
+
},
|
|
20
|
+
SafeContracts: {
|
|
21
|
+
SafeFactory: "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b",
|
|
22
|
+
SafeMultisend: "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const getContractConfig = (chainId) => {
|
|
26
|
+
switch (chainId) {
|
|
27
|
+
case 137:
|
|
28
|
+
return POL;
|
|
29
|
+
case 80002:
|
|
30
|
+
return AMOY;
|
|
31
|
+
default:
|
|
32
|
+
throw new Error("Invalid network");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.getContractConfig = getContractConfig;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export declare const RELAY_HUB_ADDRESS = "0xD216153c06E857cD7f72665E0aF1d7D82172F494";
|
|
2
|
-
export declare const PROXY_WALLET_FACTORY_ADDRESS = "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052";
|
|
3
|
-
export declare const SAFE_FACTORY_ADDRESS = "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b";
|
|
4
|
-
export declare const SAFE_MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761";
|
|
5
1
|
export declare const PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
|
|
6
2
|
export declare const SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
|
|
7
3
|
export declare const SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
|
package/dist/constants/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SAFE_FACTORY_NAME = exports.SAFE_INIT_CODE_HASH = exports.PROXY_INIT_CODE_HASH =
|
|
4
|
-
exports.RELAY_HUB_ADDRESS = "0xD216153c06E857cD7f72665E0aF1d7D82172F494";
|
|
5
|
-
exports.PROXY_WALLET_FACTORY_ADDRESS = "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052";
|
|
6
|
-
exports.SAFE_FACTORY_ADDRESS = "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b";
|
|
7
|
-
exports.SAFE_MULTISEND_ADDRESS = "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761";
|
|
3
|
+
exports.SAFE_FACTORY_NAME = exports.SAFE_INIT_CODE_HASH = exports.PROXY_INIT_CODE_HASH = void 0;
|
|
8
4
|
exports.PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
|
|
9
5
|
exports.SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
|
|
10
6
|
exports.SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
|
package/dist/encode/index.d.ts
CHANGED
package/dist/encode/index.js
CHANGED
package/dist/encode/proxy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ProxyTransaction } from "../types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function encodeProxyTransactionData(txns: ProxyTransaction[]): string;
|
package/dist/encode/proxy.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeProxyTransactionData = void 0;
|
|
4
|
-
const utils_1 = require("ethers/lib/utils");
|
|
5
|
-
const abis_1 = require("../abis");
|
|
6
|
-
const factoryInterface = new utils_1.Interface(abis_1.proxyWalletFactory);
|
|
7
|
-
const encodeProxyTransactionData = (txns) => {
|
|
8
|
-
return factoryInterface.encodeFunctionData("proxy((uint8,address,uint256,bytes)[])", [txns]);
|
|
9
|
-
};
|
|
10
3
|
exports.encodeProxyTransactionData = encodeProxyTransactionData;
|
|
4
|
+
const abis_1 = require("../abis");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const proxy = (0, viem_1.prepareEncodeFunctionData)({
|
|
7
|
+
abi: abis_1.proxyWalletFactory,
|
|
8
|
+
functionName: 'proxy',
|
|
9
|
+
});
|
|
10
|
+
function encodeProxyTransactionData(txns) {
|
|
11
|
+
return (0, viem_1.encodeFunctionData)({
|
|
12
|
+
...proxy,
|
|
13
|
+
args: [txns],
|
|
14
|
+
});
|
|
15
|
+
}
|
package/dist/encode/safe.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { SafeTransaction } from "../types";
|
|
2
|
-
export declare const createSafeMultisendTransaction: (txns: SafeTransaction[]) => SafeTransaction;
|
|
2
|
+
export declare const createSafeMultisendTransaction: (txns: SafeTransaction[], safeMultisendAddress: string) => SafeTransaction;
|
package/dist/encode/safe.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSafeMultisendTransaction = void 0;
|
|
4
|
-
const
|
|
5
|
-
const constants_1 = require("../constants");
|
|
4
|
+
const viem_1 = require("viem");
|
|
6
5
|
const abis_1 = require("../abis");
|
|
7
6
|
const types_1 = require("../types");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const multisend = (0, viem_1.prepareEncodeFunctionData)({
|
|
8
|
+
abi: abis_1.multisendAbi,
|
|
9
|
+
functionName: "multiSend",
|
|
10
|
+
});
|
|
11
|
+
const createSafeMultisendTransaction = (txns, safeMultisendAddress) => {
|
|
12
|
+
const args = [
|
|
13
|
+
(0, viem_1.concatHex)(txns.map(tx => (0, viem_1.encodePacked)(["uint8", "address", "uint256", "uint256", "bytes"], [tx.operation, tx.to, BigInt(tx.value), BigInt((0, viem_1.size)(tx.data)), tx.data]))),
|
|
14
|
+
];
|
|
15
|
+
const data = (0, viem_1.encodeFunctionData)({ ...multisend, args: args });
|
|
14
16
|
return {
|
|
15
|
-
to:
|
|
17
|
+
to: safeMultisendAddress,
|
|
16
18
|
value: "0",
|
|
17
19
|
data: data,
|
|
18
20
|
operation: types_1.OperationType.DelegateCall,
|
|
@@ -8,46 +8,44 @@ exports.POST = "POST";
|
|
|
8
8
|
exports.DELETE = "DELETE";
|
|
9
9
|
exports.PUT = "PUT";
|
|
10
10
|
class HttpClient {
|
|
11
|
+
instance;
|
|
11
12
|
constructor() {
|
|
12
13
|
this.instance = axios_1.default.create({ withCredentials: true });
|
|
13
14
|
}
|
|
14
|
-
send(endpoint, method, headers, data, params) {
|
|
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
|
-
console.error("connection error", errPayload);
|
|
45
|
-
throw new Error(JSON.stringify(errPayload));
|
|
46
|
-
}
|
|
15
|
+
async send(endpoint, method, headers, data, params) {
|
|
16
|
+
if (headers != undefined) {
|
|
17
|
+
headers["Access-Control-Allow-Credentials"] = true;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const resp = await this.instance.request({
|
|
21
|
+
method,
|
|
22
|
+
url: endpoint,
|
|
23
|
+
headers,
|
|
24
|
+
data,
|
|
25
|
+
params
|
|
26
|
+
});
|
|
27
|
+
return resp;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (axios_1.default.isAxiosError(err)) {
|
|
31
|
+
if (err.response) {
|
|
32
|
+
const errPayload = {
|
|
33
|
+
error: "request error",
|
|
34
|
+
status: err.response?.status,
|
|
35
|
+
statusText: err.response?.statusText,
|
|
36
|
+
data: err.response?.data,
|
|
37
|
+
};
|
|
38
|
+
console.error("request error", errPayload);
|
|
39
|
+
throw new Error(JSON.stringify(errPayload));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const errPayload = { error: "connection error" };
|
|
43
|
+
console.error("connection error", errPayload);
|
|
44
|
+
throw new Error(JSON.stringify(errPayload));
|
|
47
45
|
}
|
|
48
|
-
throw new Error(JSON.stringify({ error: err }));
|
|
49
46
|
}
|
|
50
|
-
|
|
47
|
+
throw new Error(JSON.stringify({ error: err }));
|
|
48
|
+
}
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
51
|
exports.HttpClient = HttpClient;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./client"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./encode"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./types"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./signeradapter"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./response"), exports);
|
package/dist/manual/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAbstractSigner } from "@polymarket/abstract-signer";
|
|
2
|
+
import { SafeContractConfig } from "../config";
|
|
2
3
|
import { SafeTransaction, ManualOverrides } from "../types";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare function executeManualTransactions(signer: SignerAdapter, transactions: SafeTransaction[], overrides: ManualOverrides): Promise<TransactionResponse | ViemTransactionResponse>;
|
|
4
|
+
import { ManualTransactionResponse } from "../response";
|
|
5
|
+
export declare function executeManualTransactions(signer: IAbstractSigner, safeContractConfig: SafeContractConfig, transactions: SafeTransaction[], overrides: ManualOverrides): Promise<ManualTransactionResponse>;
|
package/dist/manual/index.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeManualTransactions = executeManualTransactions;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const builder_1 = require("../builder");
|
|
7
|
-
const encode_1 = require("../encode");
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const viem_2 = require("viem");
|
|
8
6
|
const abis_1 = require("../abis");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
const builder_1 = require("../builder");
|
|
8
|
+
const response_1 = require("../response");
|
|
9
|
+
const safeExecTransaction = (0, viem_2.prepareEncodeFunctionData)({
|
|
10
|
+
abi: abis_1.safeAbi,
|
|
11
|
+
functionName: 'execTransaction',
|
|
12
|
+
});
|
|
13
|
+
async function executeManualTransactions(signer, safeContractConfig, transactions, overrides) {
|
|
14
|
+
const from = await signer.getAddress();
|
|
15
|
+
const aggTxn = (0, builder_1.aggregateTransaction)(transactions, safeContractConfig.SafeMultisend);
|
|
16
|
+
const sig = (0, viem_1.encodePacked)(["uint256", "uint256", "uint8"], [BigInt((0, viem_1.hexToBigInt)(from)), BigInt(0), 1]);
|
|
17
|
+
const safeAddress = (0, builder_1.deriveSafe)(from, safeContractConfig.SafeFactory);
|
|
18
|
+
// calldata
|
|
19
|
+
const data = (0, viem_2.encodeFunctionData)({ ...safeExecTransaction, args: [
|
|
18
20
|
aggTxn.to,
|
|
19
21
|
aggTxn.value,
|
|
20
22
|
aggTxn.data,
|
|
@@ -22,10 +24,27 @@ function executeManualTransactions(signer, transactions, overrides) {
|
|
|
22
24
|
0,
|
|
23
25
|
0,
|
|
24
26
|
0,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
viem_1.zeroAddress,
|
|
28
|
+
viem_1.zeroAddress,
|
|
27
29
|
sig,
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
+
] });
|
|
31
|
+
if (overrides.gasLimit == undefined) {
|
|
32
|
+
const gasLimit = await signer.estimateGas({
|
|
33
|
+
to: safeAddress,
|
|
34
|
+
data: data,
|
|
35
|
+
from: from,
|
|
36
|
+
});
|
|
37
|
+
console.log(`Estimated gas Limit: ${gasLimit}`);
|
|
38
|
+
overrides.gasLimit = gasLimit;
|
|
39
|
+
}
|
|
40
|
+
const txHash = await signer.sendTransaction({
|
|
41
|
+
data: data,
|
|
42
|
+
to: safeAddress,
|
|
43
|
+
gasPrice: overrides.gasPrice,
|
|
44
|
+
gasLimit: overrides.gasLimit,
|
|
30
45
|
});
|
|
46
|
+
const waitFunc = (txHash) => {
|
|
47
|
+
return signer.waitTillMined(txHash);
|
|
48
|
+
};
|
|
49
|
+
return new response_1.ManualTransactionResponse(txHash, waitFunc);
|
|
31
50
|
}
|